From 2ab9042fcd22cf60ed3b5bf5cb9597e60d52837d Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Tue, 18 Jan 2022 22:02:07 +0100 Subject: [PATCH] Generalize `test_read_snapshot` to several SHPC Generalize `test_read_snapshot` to accept several SHPC onthe command line. --- Overlap/Tests/test_read_snapshot.f90 | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Overlap/Tests/test_read_snapshot.f90 b/Overlap/Tests/test_read_snapshot.f90 index 3002eda8..ef7107c7 100644 --- a/Overlap/Tests/test_read_snapshot.f90 +++ b/Overlap/Tests/test_read_snapshot.f90 @@ -16,8 +16,9 @@ program test_read_snapshot character(len = :), allocatable:: shpc_dir type(snapshot) s - TYPE(shpc) hshp - integer copy, unit, k + TYPE(shpc), allocatable:: hshp(:) ! (n_shpc) + integer copy, unit, k, i + integer n_shpc ! number of input SHPC directories real:: corner_deg(2) = [0.125, - 59.875] ! longitude and latitude of the corner of the whole grid in input @@ -39,10 +40,19 @@ program test_read_snapshot !------------------------------------------------------------------------- - call get_command_arg_dyn(1, shpc_dir, "Required argument: SHPC-directory") + n_shpc = COMMAND_ARGUMENT_COUNT() + call assert(n_shpc /= 0, & + "Required arguments: SHPC-directory [SHPC-directory] ...") + allocate(hshp(n_shpc)) + do i = 1, n_shpc + call get_command_arg_dyn(i, shpc_dir) + call shpc_open(hshp(i), trim(shpc_dir), pszaccess = "rb") + end do + + ! Assuming grid_nml.txt is the same in all input SHPC: call new_unit(unit) - open(unit, file = shpc_dir // "/grid_nml.txt", status = "old", & + open(unit, file = hshp(1)%dir // "/grid_nml.txt", status = "old", & action = "read", position = "rewind") read(unit, nml = grid_nml) close(unit) @@ -55,19 +65,20 @@ program test_read_snapshot "test_read_snapshot dist_lim") copy = merge(dist_lim, 0, periodic) - call shpc_open(hshp, trim(shpc_dir), pszaccess = "rb") - ! main_nml: - k = hshp%d0 + k = hshp(1)%d0 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) - call read_snapshot(s, [hshp], nlon, nlat, k, & + call read_snapshot(s, hshp, nlon, nlat, k, & corner = corner_deg * deg_to_rad, step = step_deg * deg_to_rad, & copy = copy) - CALL shpc_close(hshp) + + do i = 1, n_shpc + CALL shpc_close(hshp(i)) + end do call write_snapshot(s, corner_deg, step_deg, nlon, nlat, copy, k) -- GitLab