From 7b7ddbb5191c36f6a645589e66b3f3734112b346 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ipsl.fr>
Date: Thu, 4 Jul 2024 18:45:17 +0200
Subject: [PATCH] Pass `corner_proj` to `set_contours`

Instead of corner.
---
 Inst_eddies/Tests/examine_eddy.f90 |  2 +-
 Inst_eddies/inst_eddies.f90        |  2 +-
 Inst_eddies/set_contours.f90       | 16 +++++++---------
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/Inst_eddies/Tests/examine_eddy.f90 b/Inst_eddies/Tests/examine_eddy.f90
index ae5d1949..24163c6a 100644
--- a/Inst_eddies/Tests/examine_eddy.f90
+++ b/Inst_eddies/Tests/examine_eddy.f90
@@ -190,7 +190,7 @@ program examine_eddy
   call set_contours(e%out_cont, e%speed_cont, e%max_speed, cyclone, e%extr, &
        e%innermost_level, step, ssh(llc(1):urc(1), llc(2):urc(2)), &
        u(llc(1):urc(1), llc(2):urc(2)), v(llc(1):urc(1), llc(2):urc(2)), &
-       corner_window, outside_points)
+       (corner_window - corner) / step + 1., outside_points)
   call close_cont_list
   call shpc_create(hshpc, shpc_dir = "SHPC", cyclone = cyclone, slice = 0, &
        grid_lon_lat = .true.)
diff --git a/Inst_eddies/inst_eddies.f90 b/Inst_eddies/inst_eddies.f90
index b6c4cb93..04e17cfa 100644
--- a/Inst_eddies/inst_eddies.f90
+++ b/Inst_eddies/inst_eddies.f90
@@ -172,7 +172,7 @@ program inst_eddies
           s%list(i)%max_speed, s%list(i)%cyclone, s%list(i)%extr, &
           s%list(i)%innermost_level, step, ssh(llc(1):urc(1), llc(2):urc(2)), &
           u(llc(1):urc(1), llc(2):urc(2)), v(llc(1):urc(1), llc(2):urc(2)), &
-          corner_window, outside_points)
+          (corner_window - corner) / step + 1., outside_points)
   end do
 
   call cpu_time(t1)
diff --git a/Inst_eddies/set_contours.f90 b/Inst_eddies/set_contours.f90
index bab8c704..d20ebc3f 100644
--- a/Inst_eddies/set_contours.f90
+++ b/Inst_eddies/set_contours.f90
@@ -5,7 +5,7 @@ module set_contours_m
 contains
 
   subroutine set_contours(out_cont, speed_cont, max_speed, cyclone, extr, &
-       innermost_level, step, ssh, u, v, corner, outside_points)
+       innermost_level, step, ssh, u, v, corner_proj, outside_points)
 
     ! This procedure sets contours in an eddy.
 
@@ -15,7 +15,6 @@ contains
     use config_m, only: min_amp
     use derived_types, only: extremum, ssh_contour
     use get_1_outerm_m, only: get_1_outerm
-    use input_ssh_m, only: corner_whole => corner
     use set_max_speed_m, only: set_max_speed
 
     type(ssh_contour), intent(out):: out_cont ! outermost contour
@@ -42,8 +41,8 @@ contains
     real, intent(in), dimension(:, :):: ssh, u, v
     ! sea-surface height, in m, and wind, in m s-1
 
-    real, intent(in):: corner(:) ! (2)
-    ! Longitude and latitude of the corner of the grid, in rad,
+    real, intent(in):: corner_proj(:) ! (2)
+    ! Coordinates in projection space of the corner of the grid,
     ! corresponding to ssh(1, 1). A priori, this is not the corner of
     ! the grid of the NetCDF file.
 
@@ -96,7 +95,7 @@ contains
 
     call get_1_outerm(out_cont, cont_list, cont_list_proj, n_cont, cyclone, &
          real(extr%coord_proj), innermost_level_2, outside_points, ssh, &
-         (corner - corner_whole) / step + 1., step)
+         corner_proj, step)
 
     ! Done with outermost contour, now let us take care of the
     ! max-speed contour.
@@ -105,10 +104,9 @@ contains
        ! {begin} Restrict the field to the outermost contour:
 
        corner_window = floor(minval(cont_list_proj(n_cont)%points, dim = 2))
-       llc = nint((corner_whole - corner) / step) &
-            + corner_window
-       urc = nint((corner_whole - corner) / step) &
-            + ceiling(maxval(cont_list_proj(n_cont)%points, dim = 2))
+       llc = corner_window - nint(corner_proj) + 1
+       urc = ceiling(maxval(cont_list_proj(n_cont)%points, dim = 2)) &
+            - nint(corner_proj) + 1
 
        ! Should have no effect except because of roundup error:
        urc(2) = min(urc(2), size(ssh, 2))
-- 
GitLab