From 94c2b939073a8c7dabd660a9b04310a79634fbd6 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 18 Oct 2022 21:58:54 +0200
Subject: [PATCH] Use procedures `config_graph` and `read_grid`

---
 Overlap/Tests/test_get_dispatch_snap.f90 | 46 ++++++------------------
 1 file changed, 10 insertions(+), 36 deletions(-)

diff --git a/Overlap/Tests/test_get_dispatch_snap.f90 b/Overlap/Tests/test_get_dispatch_snap.f90
index eac81030..c44f3bef 100644
--- a/Overlap/Tests/test_get_dispatch_snap.f90
+++ b/Overlap/Tests/test_get_dispatch_snap.f90
@@ -4,15 +4,16 @@ program test_get_dispatch_snap
 
   ! Libraries:
   use ezmpi, only: ezmpi_bcast
-  use jumble, only: get_command_arg_dyn, read_opcol, new_unit, assert, &
-       deg_to_rad
+  use jumble, only: get_command_arg_dyn, read_opcol, new_unit
   use mpi_f08, only: mpi_init, mpi_finalize, MPI_Comm_rank, MPI_Comm_world, &
        MPI_Comm_size, mpi_abort
   use shapelib_03, only: dbf_read_attribute_03
 
+  use config_graph_m, only: config_graph, copy
   use derived_types, only: snapshot, shpc_slice_handler, shpc_slice_meta
   use dispatch_snapshot_m, only: dispatch_snapshot
   use get_snapshot_m, only: get_snapshot
+  use read_grid_m, only: read_grid
   use send_snapshot_m, only: send_snapshot
   use shpc_close_m, only: shpc_close
   use shpc_open_m, only: shpc_open
@@ -24,26 +25,11 @@ program test_get_dispatch_snap
   type(snapshot) s
   TYPE(shpc_slice_handler) hshp
   type(shpc_slice_meta) ssm
-  integer k_begin, copy, rank, n_proc, k_end, n_dates
+  integer k_begin, rank, n_proc, k_end, n_dates
   integer unit_isolated
 
-  real:: corner(2) = [0.125, - 59.875]
-  ! longitude and latitude of the corner of the whole grid in input
-  ! NetCDF, in degrees
-
-  real:: step(2) = [0.25, 0.25] ! longitude and latitude steps, in degrees
-  logical periodic ! grid is periodic in longitude
-
-  integer:: nlon = 120, nlat = 120
-  ! size of ssh array in input NetCDF, assuming no repeated point if
-  ! the grid is global
-
-  integer:: dist_lim = 12
-  ! We look for an overlapping eddy at dist_lim (in grid points) of
-  ! the first extremum.
-
   integer:: k = 0
-  namelist /main_nml/ corner, step, nlon, nlat, dist_lim, k
+  namelist /main_nml/ k
 
   !-------------------------------------------------------------------------
 
@@ -57,20 +43,14 @@ program test_get_dispatch_snap
   end if
 
   call get_command_arg_dyn(1, shpc_dir, "Required argument: SHPC-directory")
+  call read_grid(rank, shpc_dir)
+  call config_graph(rank)
 
   if (rank == 0) then
      write(unit = error_unit, nml = main_nml)
      write(unit = error_unit, fmt = *) "Enter namelist main_nml."
      read(unit = *, nml = main_nml)
      write(unit = *, nml = main_nml)
-
-     ! As we are requiring the grid spacing to be uniform, the value of
-     ! "periodic" may be deduced from the values of step(1) and nlon:
-     periodic = nint(360. / step(1)) == nlon
-     print *, "periodic = ", periodic
-     if (periodic) call assert(2 * dist_lim * step(1) < 180., &
-          "test_get_dispatch_snap dist_lim")
-     copy = merge(dist_lim, 0, periodic)
   end if
 
   call shpc_open(hshp, trim(shpc_dir), cyclone = .true., slice = 0, &
@@ -85,12 +65,7 @@ program test_get_dispatch_snap
           action = "write")
   end if
 
-  call ezmpi_bcast(corner, root = 0)
-  call ezmpi_bcast(step, root = 0)
-  call ezmpi_bcast(nlon, root = 0)
-  call ezmpi_bcast(nlat, root = 0)
   call ezmpi_bcast(k, root = 0)
-  call ezmpi_bcast(copy, root = 0)
   call ezmpi_bcast(n_dates, root = 0)
   k_begin = ssm%d0 + (rank * n_dates) / n_proc
   
@@ -100,13 +75,12 @@ program test_get_dispatch_snap
      k_end = ssm%d0 + n_dates - 1
   end if
   
-  call get_snapshot(s, nlon, nlat, corner * deg_to_rad, step * deg_to_rad, &
-       copy, [hshp], [ssm], k, k_end, rank, n_proc, max_delta = 1)
+  call get_snapshot(s, [hshp], [ssm], k, k_end, rank, n_proc)
   CALL shpc_close(hshp)
-  call dispatch_snapshot(s, unit_isolated, rank, k_begin, max_delta = 1, k = k)
+  call dispatch_snapshot(s, unit_isolated, rank, k_begin, k)
 
   if (rank == 0) then
-     call save_snapshot(s, corner, step, nlon, nlat, copy, d = k)
+     call save_snapshot(s, copy, d = k)
      close(unit_isolated)
   end if
 
-- 
GitLab