From 63016959cd7478a212b3431947a2f5bfb697ca4f Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 24 Sep 2019 18:44:03 +0200
Subject: [PATCH] Add tests for program `test_write_overlap`

Change the order of dummy arguments of `write_overlap`.

Add tests for program `test_write_overlap`. In program
`test_write_overlap`, make the eddy identifiers distinct.
---
 Analysis/triplet_dump.sh                   |  6 +++++-
 Tests/Input/write_overlap_delta_3_nml.txt  |  4 ++++
 Tests/Input/write_overlap_shifting_nml.txt |  4 ++++
 Tests/short_tests.json                     | 12 ++++++++++++
 Tests/test_write_overlap.f90               | 12 ++++++------
 overlap.f90                                |  4 ++--
 write_overlap.f90                          | 16 ++++++++--------
 7 files changed, 41 insertions(+), 17 deletions(-)
 create mode 100644 Tests/Input/write_overlap_delta_3_nml.txt
 create mode 100644 Tests/Input/write_overlap_shifting_nml.txt

diff --git a/Analysis/triplet_dump.sh b/Analysis/triplet_dump.sh
index ba45bda8..8f0adb3b 100755
--- a/Analysis/triplet_dump.sh
+++ b/Analysis/triplet_dump.sh
@@ -4,10 +4,14 @@ then
     exit 1
 fi
 
-set -xe
+set -e
 
 for shapefile in extremum outermost_contour max_speed_contour
 do
+    echo
+    echo "dbfdump $1/$shapefile:"
     dbfdump $1/$shapefile
+    echo
+    echo "shpdump $1/$shapefile:"
     shpdump $1/$shapefile
 done
diff --git a/Tests/Input/write_overlap_delta_3_nml.txt b/Tests/Input/write_overlap_delta_3_nml.txt
new file mode 100644
index 00000000..c8bfe992
--- /dev/null
+++ b/Tests/Input/write_overlap_delta_3_nml.txt
@@ -0,0 +1,4 @@
+&main_nml k = 4, delta = 3,
+COORD_EXTR_1(1) = 6.2,
+coord_extr_2 = 0.1, 1.,
+ssh_extr_2 = 1., m = 1 /
diff --git a/Tests/Input/write_overlap_shifting_nml.txt b/Tests/Input/write_overlap_shifting_nml.txt
new file mode 100644
index 00000000..7d50d9af
--- /dev/null
+++ b/Tests/Input/write_overlap_shifting_nml.txt
@@ -0,0 +1,4 @@
+&main_nml k = 3, delta = 2,
+COORD_EXTR_1(1) = 6.2,
+coord_extr_2 = 0.1, 1.,
+ssh_extr_2 = 1., m = 1 /
diff --git a/Tests/short_tests.json b/Tests/short_tests.json
index 509d57ab..5726d34e 100644
--- a/Tests/short_tests.json
+++ b/Tests/short_tests.json
@@ -333,5 +333,17 @@
 	"title": "Write_overlap_different",
 	"stdin_filename" : "$src_dir/Tests/Input/write_overlap_different_nml.txt",
 	"description" : "Non-successive overlap with different coordinates and ssh."
+    },
+    {
+	"args": ["$src_dir/mkdir_run.sh", "$build_dir/test_write_overlap"],
+	"title": "Write_overlap_shifting",
+	"stdin_filename" : "$src_dir/Tests/Input/write_overlap_shifting_nml.txt",
+	"description" : "Non-successive overlap with different coordinates and ssh, and shifting in longitude."
+    },
+    {
+	"args": ["$src_dir/mkdir_run.sh", "$build_dir/test_write_overlap"],
+	"title": "Write_overlap_delta_3",
+	"stdin_filename" : "$src_dir/Tests/Input/write_overlap_delta_3_nml.txt",
+	"description" : "Different coordinates and ssh, shifting in longitude, delta = 3."
     }
 ]
diff --git a/Tests/test_write_overlap.f90 b/Tests/test_write_overlap.f90
index 2f6e4bba..c3107561 100644
--- a/Tests/test_write_overlap.f90
+++ b/Tests/test_write_overlap.f90
@@ -12,13 +12,13 @@ program test_write_overlap
   implicit none
 
   integer unit_edgelist, j_interp
-  integer:: k = 2, delta = 1
+  integer:: k = 2, delta = 1, m = 0
   real:: coord_extr_1(2) = [0., 0.], coord_extr_2(2) = [0., 0.] ! in rad
   real:: ssh_extr_1 = 0., ssh_extr_2 = 0.
   TYPE(shpfileobject) hshp_extremum ! shapefile extremum
   TYPE(shpfileobject) hshp_outermost ! shapefile outermost_contour
   TYPE(shpfileobject) hshp_max_speed ! shapefile max_speed_contour
-  namelist /main_nml/ k, delta, coord_extr_1, ssh_extr_1, coord_extr_2, &
+  namelist /main_nml/ k, delta, m, coord_extr_1, ssh_extr_1, coord_extr_2, &
        ssh_extr_2
 
   !-------------------------------------------------------------------------
@@ -41,10 +41,10 @@ program test_write_overlap
   call init_shapefiles(hshp_extremum, hshp_outermost, hshp_max_speed)
   call init_interpolated_eddy
   call write_overlap(hshp_extremum, hshp_outermost, hshp_max_speed, &
-       unit_edgelist, k, delta, i1 = 1, i2 = 1, &
-       i_interp = [(1, j_interp = 1, delta - 1)], cyclone = .true., &
-       coord_extr_1 = coord_extr_1, ssh_extr_1 = ssh_extr_1, &
-       coord_extr_2 = coord_extr_2, ssh_extr_2 = ssh_extr_2, m = 0, w = 0.)
+       unit_edgelist, k, delta, i1 = 1, i2 = 2, m = m, &
+       i_interp = 10 + [(j_interp, j_interp = 1, delta - 1)], &
+       cyclone = .true., coord_extr_1 = coord_extr_1, ssh_extr_1 = ssh_extr_1, &
+       coord_extr_2 = coord_extr_2, ssh_extr_2 = ssh_extr_2, w = 0.)
   close(unit_edgelist)
   print *, 'Created file "edgelist.csv".'
   CALL shpclose(hshp_extremum)
diff --git a/overlap.f90 b/overlap.f90
index ee2edf08..28082b21 100644
--- a/overlap.f90
+++ b/overlap.f90
@@ -116,13 +116,13 @@ contains
                         = flow(j - delta + 1:j - 1)%number_eddies + 1
 
                    call write_overlap(hshp_extremum, hshp_outermost, &
-                        hshp_max_speed, unit_edgelist, k, delta, i1, i2, &
+                        hshp_max_speed, unit_edgelist, k, delta, i1, i2, m, &
                         flow(j - delta + 1:j - 1)%number_eddies, &
                         flow(j - delta)%list_vis(i1)%cyclone, &
                         flow(j - delta)%list_vis(i1)%coord_extr, &
                         flow(j - delta)%list_vis(i1)%ssh_extr, &
                         flow(j)%list_vis(i2)%coord_extr, &
-                        flow(j)%list_vis(i2)%ssh_extr, m, &
+                        flow(j)%list_vis(i2)%ssh_extr, &
                         weight(flow(j - delta)%list_vis(i1), &
                         flow(j)%list_vis(i2)))
                    flow(j - delta)%list_vis(i1)%delta_out = delta
diff --git a/write_overlap.f90 b/write_overlap.f90
index 4b62eb73..4d3ed219 100644
--- a/write_overlap.f90
+++ b/write_overlap.f90
@@ -10,10 +10,11 @@ module write_overlap_m
 contains
 
   subroutine write_overlap(hshp_extremum, hshp_outermost, hshp_max_speed, &
-       unit_edgelist, k, delta, i1, i2, i_interp, cyclone, coord_extr_1, &
-       ssh_extr_1, coord_extr_2, ssh_extr_2, m, w)
+       unit_edgelist, k, delta, i1, i2, m, i_interp, cyclone, coord_extr_1, &
+       ssh_extr_1, coord_extr_2, ssh_extr_2, w)
 
-    ! Writes edges and interpolated eddy between (k - delta, i1) and (k, i2).
+    ! Writes edges and interpolated eddies between (k - delta, i1) and
+    ! (k, i2).
 
     ! Libraries:
     use nr_util, only: twopi
@@ -26,12 +27,12 @@ contains
     TYPE(shpfileobject), intent(in):: hshp_outermost
     ! shapefile outermost_contour
 
-    TYPE(shpfileobject), intent(in):: hshp_max_speed ! shapefile x_speed_contour
+    TYPE(shpfileobject), intent(in):: hshp_max_speed
+    ! shapefile max_speed_contour
+    
     integer, intent(in):: unit_edgelist ! logical unit for edgelist file
     integer, intent(in):: k ! date index
-    integer, intent(in):: delta
-    integer, intent(in):: i1
-    integer, intent(in):: i2
+    integer, intent(in):: delta, i1, i2, m
     integer, intent(in):: i_interp(:) ! (delta - 1)
     logical, intent(in):: cyclone
     real, intent(in):: coord_extr_1(:) ! (2)
@@ -41,7 +42,6 @@ contains
     ! (Note: value attribute not allowed for an array.)
 
     real, intent(in):: ssh_extr_2
-    integer, intent(in):: m
     real, intent(in):: w
 
     ! Local:
-- 
GitLab