From f9164351d71b456c8d1e8ff401a3a7cd92982ec9 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Wed, 27 Jul 2022 10:29:05 +0200
Subject: [PATCH] Bug fix: read `dist_lim` before using it

The bug existed since commit 627df95.
---
 Overlap/Tests/test_read_snapshot.f90 | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Overlap/Tests/test_read_snapshot.f90 b/Overlap/Tests/test_read_snapshot.f90
index ab020605..ff036c95 100644
--- a/Overlap/Tests/test_read_snapshot.f90
+++ b/Overlap/Tests/test_read_snapshot.f90
@@ -62,14 +62,6 @@ program test_read_snapshot
   read(unit, nml = grid_nml)
   close(unit)
 
-  ! As we are requiring the grid spacing to be uniform, the value of
-  ! "periodic" may be deduced from the values of step_deg(1) and nlon:
-  periodic = nint(360. / step_deg(1)) == nlon
-  print *, "periodic = ", periodic
-  if (periodic) call assert(2 * dist_lim * step_deg(1) < 180., &
-       "test_read_snapshot dist_lim")
-  copy = merge(dist_lim, 0, periodic)
-
   ! main_nml:
   k = ssm(1)%d0
   write(unit = error_unit, nml = main_nml)
@@ -77,6 +69,14 @@ program test_read_snapshot
   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_deg(1) and nlon:
+  periodic = nint(360. / step_deg(1)) == nlon
+  print *, "test_read_snapshot: periodic = ", periodic
+  if (periodic) call assert(2 * dist_lim * step_deg(1) < 180., &
+       "test_read_snapshot dist_lim")
+  copy = merge(dist_lim, 0, periodic)
+
   call read_snapshot(s, hshp, ssm, nlon, nlat, k, &
        corner = corner_deg * deg_to_rad, step = step_deg * deg_to_rad, &
        copy = copy)
-- 
GitLab