From ccc61328d45173341a2f29299139b4ac4f68814c Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Mon, 11 Dec 2017 15:28:50 +0100
Subject: [PATCH] Bug fix in test_set_outermost_contour. e%ssh_extremum must be
 defined. Also, allow test_set_outermost_contour to read ssh from a NetCDF
 variable with a degenerate time coordinate or with no time coordinante.

"stdout" key became optional in "tests.json" and "directory" key
became "title", with no indication of directory.
---
 Tests/examine_ssh_values.py        |   1 +
 Tests/plot_snapshot.py             |  12 +++-
 Tests/test_set_outermost_contour.f |  29 +++++---
 Tests/tests.json                   | 104 ++++++++++++++---------------
 depend.mk                          |   2 +-
 5 files changed, 79 insertions(+), 69 deletions(-)

diff --git a/Tests/examine_ssh_values.py b/Tests/examine_ssh_values.py
index 48b50ef6..084d2b5e 100755
--- a/Tests/examine_ssh_values.py
+++ b/Tests/examine_ssh_values.py
@@ -7,6 +7,7 @@ import numpy as np
 with netCDF4.Dataset("h.nc") as f:
     ssh = f.variables["adt"][:].squeeze()
 
+print("Give base 0 indices below:")
 i_min = int(input("imin = ? "))
 i_max = int(input("imax = ? "))
 j_min = int(input("jmin = ? "))
diff --git a/Tests/plot_snapshot.py b/Tests/plot_snapshot.py
index 826913ae..23325455 100755
--- a/Tests/plot_snapshot.py
+++ b/Tests/plot_snapshot.py
@@ -1,8 +1,14 @@
 #!/usr/bin/env python3
 
-"""Red for anti-cyclones, blue for cyclones. Squares for insufficient
-amplitudes, crosses for sufficient amplitude but no max-speed contour,
-circles for sufficient amplitude with max-speed contour."""
+"""Plots outermost contours and max-speed contours.
+
+Red for anti-cyclones, blue for cyclones. Squares for an outermost
+contour of insufficient amplitudes. Crosses for an outermost contour
+of sufficient amplitude but with no associated max-speed
+contour. Filled circles for sufficient amplitude with max-speed
+contour.
+
+"""
 
 import argparse
 import shapefile
diff --git a/Tests/test_set_outermost_contour.f b/Tests/test_set_outermost_contour.f
index 90bb100e..415e1e7d 100644
--- a/Tests/test_set_outermost_contour.f
+++ b/Tests/test_set_outermost_contour.f
@@ -31,8 +31,9 @@ program test_set_outermost_contour
   type(eddy) e
   TYPE(shpfileobject) shphandle
   integer field_number, shape_number
+  real:: ssh_extremum = 0.2759
 
-  namelist /main_nml/ ind_targ_extr, innermost_level, cyclone
+  namelist /main_nml/ ind_targ_extr, ssh_extremum, innermost_level, cyclone
 
   !----------------------------------------------------------------
 
@@ -44,6 +45,17 @@ program test_set_outermost_contour
   read(unit = *, nml = main_nml)
   write(unit = *, nml = main_nml)
 
+  ! No problem of degenerate time coordinate with extr_map-file so
+  ! read it first:
+  call get_command_arg_dyn(2, filename)
+  print *, "Reading from ", filename, "..."
+  call nf95_open(filename, nf90_nowrite, ncid)
+
+  call nf95_inq_varid(ncid, "extr_map", varid)
+  call nf95_gw_var(ncid, varid, extr_map)
+
+  call nf95_close(ncid)
+
   call get_command_arg_dyn(1, filename)
   print *, "Reading from ", filename, "..."
   call nf95_open(filename, nf90_nowrite, ncid)
@@ -57,22 +69,17 @@ program test_set_outermost_contour
   latitude = latitude / 180. * pi ! degrees north to rad
 
   call nf95_inq_varid(ncid, "adt", varid)
-  call nf95_gw_var(ncid, varid, ssh)
-
-  call nf95_close(ncid)
-
-  call get_command_arg_dyn(2, filename)
-  print *, "Reading from ", filename, "..."
-  call nf95_open(filename, nf90_nowrite, ncid)
-
-  call nf95_inq_varid(ncid, "extr_map", varid)
-  call nf95_gw_var(ncid, varid, extr_map)
+  ! Do not use nf95_gw_var so that the program also works with a
+  ! degenerate time coordinate:
+  allocate(ssh(size(extr_map, 1), size(extr_map, 2)))
+  call nf95_get_var(ncid, varid, ssh)
 
   call nf95_close(ncid)
 
   step = [longitude(2) - longitude(1), latitude(2) - latitude(1)]
   e%coord_extr = [longitude(1), latitude(1)] + (ind_targ_extr - 1) * step
   e%cyclone = cyclone
+  e%ssh_extremum = ssh_extremum
   call set_outermost_contour(e, ind_targ_extr, innermost_level, extr_map, &
        ssh, corner = [longitude(1), latitude(1)], step = step)
 
diff --git a/Tests/tests.json b/Tests/tests.json
index 6508519f..98bf5e66 100644
--- a/Tests/tests.json
+++ b/Tests/tests.json
@@ -3,98 +3,85 @@
 	"stdin" : "$stdin_dir/good_contour_in.txt",
 	"args" : ["$compil_prod_dir/test_good_contour",
 		  "$input_dir/example.nc"],
-	"stdout" : "test_good_contour_stdout.txt",
-	"directory" : "Tests_new/Good_contour"
+	"title" : "Good_contour"
     },
     {
 	"stdin" : "$stdin_dir/good_contour_in2.txt",
 	"args" : ["$compil_prod_dir/test_good_contour",
 		  "$input_dir/example.nc"],
-	"stdout" : "test_good_contour_stdout.txt",
-	"directory" : "Tests_new/Good_contour_2"
+	"title" : "Good_contour_2"
     },
     {
 	"stdin" : "$stdin_dir/no_good_contour_in.txt",
 	"args" : ["$compil_prod_dir/test_good_contour",
 		  "$input_dir/example.nc"],
-	"stdout" : "test_good_contour_stdout.txt",
-	"directory" : "Tests_new/No_good_contour"
+	"title" : "No_good_contour"
     },
     {
 	"args" : ["$compil_prod_dir/test_local_extrema",
 		  "$input_dir/h_test_region.nc"],
-	"stdout" : "test_local_extrema_stdout.txt",
-	"directory" : "Tests_new/Local_extrema"
+	"title" : "Local_extrema"
     },
     {
 	"args" : ["$compil_prod_dir/test_local_extrema",
 		  "$input_dir/h_test_get_snapshot_larger.nc"],
-	"stdout" : "test_local_extrema_stdout.txt",
-	"directory" : "Tests_new/Local_extrema_larger"
+	"title" : "Local_extrema_larger"
     },
     {
 	"args" : ["$compil_prod_dir/test_set_outermost_contour",
 		  "$input_dir/h_test_region.nc",
 		  "$tests_old_dir/Local_extrema/test_local_extrema.nc"],
-	"stdout" : "test_set_outermost_contour_stdout.txt",
-	"directory" : "Tests_new/Set_outermost_contour",
+	"title" : "Set_outermost_contour",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_set_outermost_contour",
 		  "$input_dir/h_test_region.nc",
 		  "$input_dir/extr_map_negative_2_8.nc"],
-	"stdout" : "test_set_outermost_contour_stdout.txt",
-	"directory" : "Tests_new/Set_outermost_contour_noise_2_8",
+	"title" : "Set_outermost_contour_noise_2_8",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_set_outermost_contour",
 		  "$input_dir/h_test_region.nc",
 		  "$input_dir/extr_map_negative_2.nc"],
-	"stdout" : "test_set_outermost_contour_stdout.txt",
-	"directory" : "Tests_new/Set_outermost_contour_noise_2",
+	"title" : "Set_outermost_contour_noise_2",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_max_speed_contour_ssh",
 		  "$input_dir/h_2006_01_01.nc", "$input_dir/uv_2006_01_01.nc"],
-	"stdout" : "test_max_speed_contour_ssh_stdout.txt",
-	"directory" : "Tests_new/Max_speed_contour_ssh",
+	"title" : "Max_speed_contour_ssh",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_max_speed_contour_ssh",
 		  "$input_dir/h_2006_01_01.nc", "$input_dir/uv_2006_01_01.nc"],
-	"stdout" : "test_max_speed_contour_ssh_stdout.txt",
-	"directory" : "Tests_new/Max_speed_contour_ssh_north",
+	"title" : "Max_speed_contour_ssh_north",
 	"stdin" : "$stdin_dir/max_speed_contour_ssh_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_mean_speed",
 		  "$input_dir/uv_test_region.nc",
 		  "$tests_old_dir/Set_outermost_contour/test_set_outermost_contour"],
-	"stdout" : "test_mean_speed_stdout.txt",
-	"directory" : "Tests_new/Mean_speed",
+	"title" : "Mean_speed",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args" : ["$compil_prod_dir/test_mean_speed",
 		  "$input_dir/uv_test_region.nc",
 		  "$input_dir/outermost_contour_alt"],
-	"stdout" : "test_mean_speed_stdout.txt",
-	"directory" : "Tests_new/Mean_speed_alt",
+	"title" : "Mean_speed_alt",
 	"stdin" : "$stdin_dir/default_main_nml.txt"
     },
     {
 	"args": ["$compil_prod_dir/test_set_max_speed",
 		 "$input_dir/h_outermost.nc", "$input_dir/uv_outermost.nc",
 		 "$input_dir/extr_map_outermost.nc"],
-	"directory": "Tests_new/Set_max_speed",
-	"stdout" : "test_set_max_speed_stdout.txt",
-	"required": ["Tests_old/Set_outermost_contour/test_set_outermost_contour.shp",
-		     "Tests_old/Set_outermost_contour/test_set_outermost_contour.shx",
-		     "Tests_old/Set_outermost_contour/test_set_outermost_contour.dbf"],
+	"title": "Set_max_speed",
+	"required": ["$tests_old_dir/Set_outermost_contour/test_set_outermost_contour.shp",
+		     "$tests_old_dir/Set_outermost_contour/test_set_outermost_contour.shx",
+		     "$tests_old_dir/Set_outermost_contour/test_set_outermost_contour.dbf"],
 	"stdin": "$stdin_dir/default_main_nml.txt"
     },
     {
@@ -102,55 +89,64 @@
 		 "$input_dir/h_test_region.nc",
 		 "$input_dir/uv_test_region.nc",
 		 "$input_dir/extr_map_negative_2_8.nc"],
-	"directory": "Tests_new/Set_max_speed_noise",
-	"stdout" : "test_set_max_speed_stdout.txt",
-	"required": ["Tests_old/Set_outermost_contour_noise_2_8/test_set_outermost_contour.shp",
-		     "Tests_old/Set_outermost_contour_noise_2_8/test_set_outermost_contour.shx",
-		     "Tests_old/Set_outermost_contour_noise_2_8/test_set_outermost_contour.dbf"],
+	"title": "Set_max_speed_noise",
+	"required": ["$tests_old_dir/Set_outermost_contour_noise_2_8/test_set_outermost_contour.shp",
+		     "$tests_old_dir/Set_outermost_contour_noise_2_8/test_set_outermost_contour.shx",
+		     "$tests_old_dir/Set_outermost_contour_noise_2_8/test_set_outermost_contour.dbf"],
 	"stdin": "$stdin_dir/set_max_speed_noise_nml.txt"
     },
     {
 	"args": "$compil_prod_dir/test_get_snapshot",
-	"directory": "Tests_new/Get_snapshot",
-	"stdout" : "test_get_snapshot_stdout.txt",
-	"required": [["Input/h_test_get_snapshot.nc", "h.nc"],
-		     ["Input/uv_test_get_snapshot.nc", "uv.nc"]],
+	"title": "Get_snapshot",
+	"required": [["$input_dir/h_test_get_snapshot.nc", "h.nc"],
+		     ["$input_dir/uv_test_get_snapshot.nc", "uv.nc"]],
 	"stdin": "$stdin_dir/get_snaphot_stdin.txt"
     },
     {
 	"args": "$compil_prod_dir/test_get_snapshot",
-	"directory": "Tests_new/Get_snapshot_noise",
-	"stdout" : "test_get_snapshot_stdout.txt",
-	"required": [["Input/h_test_get_snapshot.nc", "h.nc"],
-		     ["Input/uv_test_get_snapshot.nc", "uv.nc"]],
+	"title": "Get_snapshot_noise",
+	"required": [["$input_dir/h_test_get_snapshot.nc", "h.nc"],
+		     ["$input_dir/uv_test_get_snapshot.nc", "uv.nc"]],
 	"stdin": "$stdin_dir/get_snaphot_noise_stdin.txt"
     },
     {
 	"args": "$compil_prod_dir/test_get_snapshot",
-	"directory": "Tests_new/Get_snapshot_larger",
-	"stdout" : "test_get_snapshot_stdout.txt",
-	"required": [["Input/h_test_get_snapshot_larger.nc", "h.nc"],
-		     ["Input/uv_test_get_snapshot_larger.nc", "uv.nc"]],
+	"title": "Get_snapshot_larger",
+	"required": [["$input_dir/h_test_get_snapshot_larger.nc", "h.nc"],
+		     ["$input_dir/uv_test_get_snapshot_larger.nc", "uv.nc"]],
 	"stdin": "$stdin_dir/get_snaphot_stdin.txt"
     },
     {
 	"args": "$compil_prod_dir/test_get_snapshot",
-	"directory": "Tests_new/Get_snapshot_larger_noise",
-	"stdout" : "test_get_snapshot_stdout.txt",
-	"required": [["Input/h_test_get_snapshot_larger.nc", "h.nc"],
-		     ["Input/uv_test_get_snapshot_larger.nc", "uv.nc"]],
+	"title": "Get_snapshot_larger_noise",
+	"required": [["$input_dir/h_test_get_snapshot_larger.nc", "h.nc"],
+		     ["$input_dir/uv_test_get_snapshot_larger.nc", "uv.nc"]],
 	"stdin": "$stdin_dir/get_snaphot_noise_stdin.txt"
     },
     {
 	"args": ["$compil_prod_dir/test_inside_4", "$input_dir/outermost_5"],
-	"directory": "Tests_new/Inside_4_true",
-	"stdout": "test_inside_4_stdout.txt",
+	"title": "Inside_4_true",
 	"stdin": "$stdin_dir/inside_4_true_nml.txt"
     },
     {
 	"args": ["$compil_prod_dir/test_inside_4", "$input_dir/outermost_5"],
-	"directory": "Tests_new/Inside_4_false",
-	"stdout": "test_inside_4_stdout.txt",
+	"title": "Inside_4_false",
 	"stdin": "$stdin_dir/inside_4_false_nml.txt"
+    },
+    {
+	"args": "$compil_prod_dir/test_get_snapshot",
+	"title": "Get_snapshot_120",
+	"required": [["$input_dir/h_comparison_region.nc", "h.nc"],
+		     ["$input_dir/uv_comparison_region.nc", "uv.nc"]],
+	"stdin": "$stdin_dir/get_snaphot_stdin.txt",
+	"description": "Larger region, 120 x 120. Includes degenerate extrema."
+    },
+    {
+	"args": "$compil_prod_dir/test_get_snapshot",
+	"title": "Get_snapshot_120_min",
+	"required": [["$input_dir/h_comparison_region.nc", "h.nc"],
+		     ["$input_dir/uv_comparison_region.nc", "uv.nc"]],
+	"stdin": "$stdin_dir/get_snaphot_noise_stdin.txt",
+	"description": "Same as Get_snapshot_120 except with 1 mm minimum amplitude."
     }
 ]
diff --git a/depend.mk b/depend.mk
index bb3646d1..8beaebf4 100644
--- a/depend.mk
+++ b/depend.mk
@@ -4,7 +4,7 @@ receive_snapshot.o : derived_types.o
 send_snapshot.o : derived_types.o 
 set_max_speed.o : spherical_polygon_area.o mean_speed.o max_speed_contour_ssh.o inside_4.o good_contour.o derived_types.o 
 set_outermost_contour.o : spherical_polygon_area.o outermost_possible_level.o good_contour.o derived_types.o 
-test_get_snapshot.o : local_extrema.o get_snapshot.o dispatch_snapshot.o derived_types.o 
+test_get_snapshot.o : get_snapshot.o dispatch_snapshot.o derived_types.o 
 test_good_contour.o : good_contour.o 
 test_inside_4.o : inside_4.o 
 test_local_extrema.o : local_extrema.o 
-- 
GitLab