From 9947fc37f3a10f1d7097b6c6b84ae385e6dfa644 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 26 Jul 2022 14:39:33 +0200
Subject: [PATCH] Polish

---
 Common/shpc_create.f90      | 14 +++++++++-----
 Common/shpc_open.f90        | 10 +++++-----
 Inst_eddies/inst_eddies.f90 | 24 +++++++++++-------------
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/Common/shpc_create.f90 b/Common/shpc_create.f90
index c637d17c..ae702247 100644
--- a/Common/shpc_create.f90
+++ b/Common/shpc_create.f90
@@ -22,7 +22,10 @@ contains
 
     !---------------------------------------------------------------------
 
-    call shp_create_03(shpc_dir // "/extremum", shpt_point, &
+    hshp%dir = shpc_dir
+
+    ! extremum shapefile:
+    call shp_create_03(hshp%dir // "/extremum", shpt_point, &
          hshp%extremum)
     call dbf_add_field_03(hshp%extr_ssh, hshp%extremum, 'ssh', ftdouble, &
          nwidth = 13, ndecimals = 6)
@@ -35,7 +38,8 @@ contains
     call dbf_add_field_03(hshp%extr_speed, hshp%extremum, 'speed', ftdouble, &
          nwidth = 13, ndecimals = 6)
 
-    call shp_create_03(shpc_dir // "/outermost_contour", shpt_polygon, &
+    ! outermost_contour shapefile:
+    call shp_create_03(hshp%dir // "/outermost_contour", shpt_polygon, &
          hshp%outermost)
     call dbf_add_field_03(hshp%out_r_eq_area, hshp%outermost, &
          'r_eq_area', ftdouble, nwidth = 10, ndecimals = 4)
@@ -48,7 +52,8 @@ contains
     call dbf_add_field_03(hshp%out_radius4, hshp%outermost, 'radius4', &
          ftinteger, nwidth = 2, ndecimals = 0)
 
-    call shp_create_03(shpc_dir // "/max_speed_contour", shpt_polygon, &
+    ! max_speed_contour shapefile:
+    call shp_create_03(hshp%dir // "/max_speed_contour", shpt_polygon, &
          hshp%max_speed)
     call dbf_add_field_03(hshp%max_speed_r_eq_area, hshp%max_speed, &
          'r_eq_area', ftdouble, nwidth = 10, ndecimals = 4)
@@ -64,7 +69,7 @@ contains
          action = "write")
     hshp%cyclone = cyclone
     call new_unit(unit)
-    open(unit, file  = shpc_dir // "/orientation.txt", status = "replace", &
+    open(unit, file  = hshp%dir // "/orientation.txt", status = "replace", &
          action  = "write")
 
     if (cyclone) then
@@ -74,7 +79,6 @@ contains
     end if
     
     close(unit)
-    hshp%dir = shpc_dir
 
   end subroutine shpc_create
 
diff --git a/Common/shpc_open.f90 b/Common/shpc_open.f90
index b0d5e0f4..33883292 100644
--- a/Common/shpc_open.f90
+++ b/Common/shpc_open.f90
@@ -24,23 +24,23 @@ contains
 
     !--------------------------------------------------------------------
 
-    call shp_open_03(hshp%extremum, shpc_dir // "/extremum", pszaccess, &
+    hshp%dir = shpc_dir
+    call shp_open_03(hshp%extremum, hshp%dir // "/extremum", pszaccess, &
          iostat_extr)
     if (present(iostat)) iostat = iostat_extr
 
     if (iostat_extr == 0) then
-       call shp_open_03(hshp%outermost, shpc_dir // "/outermost_contour", &
+       call shp_open_03(hshp%outermost, hshp%dir // "/outermost_contour", &
             pszaccess)
-       call shp_open_03(hshp%max_speed, shpc_dir // "/max_speed_contour", &
+       call shp_open_03(hshp%max_speed, hshp%dir // "/max_speed_contour", &
             pszaccess)
        call read_field_indices(hshp)
        call new_unit(unit)
-       open(unit, file = shpc_dir // "/orientation.txt", status = "old", &
+       open(unit, file = hshp%dir // "/orientation.txt", status = "old", &
             action = "read", position = "rewind")
        read(unit, fmt = *) orientation
        close(unit)
        hshp%cyclone = trim(adjustl(orientation)) == "cyclones"
-       hshp%dir = shpc_dir
        call new_unit(hshp%unit)
 
        if (pszaccess == "rb") then
diff --git a/Inst_eddies/inst_eddies.f90 b/Inst_eddies/inst_eddies.f90
index 4bf367db..7544abb6 100644
--- a/Inst_eddies/inst_eddies.f90
+++ b/Inst_eddies/inst_eddies.f90
@@ -31,6 +31,10 @@ program inst_eddies
   ! size of ssh array in input NetCDF, assuming no repeated point if
   ! the grid is global
 
+  real corner_deg(2), corner(2)
+  ! longitude and latitude of the corner of the whole grid, in degrees
+  ! and in rad
+
   real step_deg(2), step(2) ! longitude and latitude steps, in degrees and rad
   logical periodic ! grid is periodic in longitude
 
@@ -42,10 +46,6 @@ program inst_eddies
   ! (1 - max_radius(1):nlon + max_radius(1), nlat) if periodic, else
   ! (nlon, nlat) wind, in m s-1
 
-  real corner_deg(2), corner(2)
-  ! longitude and latitude of the corner of the whole grid, in degrees
-  ! and in rad
-
   ! Window around each extremum:
 
   integer llc(2) ! indices in global grid of lower left corner
@@ -65,6 +65,8 @@ program inst_eddies
 
   !--------------------------------------------------------------
 
+  call assert(IEEE_SUPPORT_DATATYPE(0.), ieee_support_nan(0.), &
+       "inst_eddies: not enough IEEE support")
   call new_unit(unit)
   inquire(file = "timings.txt", exist = exist)
 
@@ -76,13 +78,10 @@ program inst_eddies
   end if
 
   call cpu_time(t0)
-  call assert(IEEE_SUPPORT_DATATYPE(0.), ieee_support_nan(0.), &
-       "inst_eddies: not enough IEEE support")
-  inquire(file = "SHPC_cyclo/extremum.shp", exist = exist)
-  call config(exist) ! We need main_nml before looking at the input files.
   print *, "inst_eddies: Enter dates_nml:"
   read(unit = *, nml = dates_nml)
-
+  inquire(file = "SHPC_cyclo/extremum.shp", exist = exist)
+  call config(exist) ! We need main_nml before looking at the input files.
   call input_ssh(corner, step, nlon, nlat, periodic, ssh, u, v, corner_deg, &
        step_deg)
 
@@ -98,7 +97,8 @@ program inst_eddies
   end if
 
   call cpu_time(t1)
-  write(unit, fmt = *) "CPU time for input, before computation:", t1 - t0, "s"
+  write(unit, fmt = *) "CPU time for preamble, before computation:", t1 - t0, &
+       "s"
   t0 = t1
   call set_all_outerm(s, step, periodic, ssh, corner, &
        min_area = pi * (min_radius * 1e3)**2)
@@ -145,15 +145,13 @@ program inst_eddies
   call cpu_time(t1)
   write(unit, fmt = *) "CPU time for computation, before output:", t1 - t0, "s"
   t0 = t1
-
-  ! Write snapshot:
   call write_snapshot(s, hshpc_cyclo, hshpc_anti, date)
   call write_aux(corner_deg, step_deg, nlon, nlat, hshpc_cyclo, exist)
   call write_aux(corner_deg, step_deg, nlon, nlat, hshpc_anti, exist)
   CALL shpc_close(hshpc_cyclo)
   CALL shpc_close(hshpc_anti)
 
-  if (exist) then
+  if (iostat == 0) then
      print *, 'inst_eddies: Appended to shapefile collections in SHPC_cyclo ', &
           'and SHPC_anti.'
   else
-- 
GitLab