Skip to content

Commit ea8c29c

Browse files
authored
add a test to test the multi-file capability in data_override (#1745)
1 parent 51b3199 commit ea8c29c

File tree

6 files changed

+193
-2
lines changed

6 files changed

+193
-2
lines changed

test_fms/data_override/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ TESTS_ENVIRONMENT= test_input_path="@TEST_INPUT_PATH@" \
7171
# Run the test program.
7272

7373
TESTS = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh \
74-
test_data_override2_scalar.sh test_data_override_weights.sh test_data_override_ensembles.sh
74+
test_data_override2_scalar.sh test_data_override_weights.sh test_data_override_ensembles.sh \
75+
test_multi_file.sh
7576

7677
# Include these files with the distribution.
7778
EXTRA_DIST = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh \
78-
test_data_override2_scalar.sh test_data_override_weights.sh test_data_override_ensembles.sh
79+
test_data_override2_scalar.sh test_data_override_weights.sh test_data_override_ensembles.sh \
80+
test_multi_file.sh
7981

8082
# Clean up
8183
CLEANFILES = input.nml *.nc* *.out diag_table data_table data_table.yaml INPUT/* *.dpi *.spi *.dyn *.spl *-files/*

test_fms/data_override/include/test_data_override_ongrid.inc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,38 @@ subroutine ENSEMBLE_TEST_
222222

223223
deallocate(runoff)
224224
end subroutine ENSEMBLE_TEST_
225+
226+
subroutine MULTI_FILE_TESTS_
227+
integer, parameter :: lkind = DO_TEST_KIND_ !< Real precision of the test
228+
real(lkind) :: expected_result !< Expected result from data_override
229+
type(time_type) :: Time !< Time
230+
real(lkind), allocatable, dimension(:,:) :: runoff !< Data to be written
231+
logical :: sucessful !< .True. if the data_override was sucessful
232+
233+
allocate(runoff(is:ie,js:je))
234+
235+
!< Run it when time=3, this is going to use the previous file and the current file
236+
Time = set_date(1,1,4,0,0,0)
237+
runoff = 999._lkind
238+
call data_override('OCN','runoff',runoff, Time, override=sucessful)
239+
if (.not. sucessful) call mpp_error(FATAL, "The data was not overridden correctly")
240+
expected_result = 3._lkind
241+
call COMPARE_DATA_ (Domain, runoff, expected_result)
242+
243+
!< Run it when time=4, this is going to use the current file
244+
Time = set_date(1,1,5,0,0,0)
245+
runoff = 999._lkind
246+
call data_override('OCN','runoff',runoff, Time, override=sucessful)
247+
if (.not. sucessful) call mpp_error(FATAL, "The data was not overridden correctly")
248+
expected_result = 4._lkind
249+
call COMPARE_DATA_ (Domain, runoff, expected_result)
250+
251+
!< Run it when time=5, this is going to use the current file and the next file
252+
Time = set_date(1,1,6,0,0,0)
253+
runoff = 999._lkind
254+
call data_override('OCN','runoff',runoff, Time, override=sucessful)
255+
if (.not. sucessful) call mpp_error(FATAL, "The data was not overridden correctly")
256+
expected_result = 5._lkind
257+
call COMPARE_DATA_ (Domain, runoff, expected_result)
258+
259+
end subroutine MULTI_FILE_TESTS_

test_fms/data_override/include/test_data_override_ongrid_r4.fh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#undef WEIGHT_FILE_TEST_
2525
#undef SCALAR_TEST_
2626
#undef ENSEMBLE_TEST_
27+
#undef MULTI_FILE_TESTS_
2728

2829
#define DO_TEST_KIND_ r4_kind
2930
#define COMPARE_DATA_ compare_data_r4
@@ -32,5 +33,6 @@
3233
#define WEIGHT_FILE_TEST_ weight_file_test_r4
3334
#define SCALAR_TEST_ scalar_test_r4
3435
#define ENSEMBLE_TEST_ ensemble_test_r4
36+
#define MULTI_FILE_TESTS_ multi_file_r4
3537

3638
#include "test_data_override_ongrid.inc"

test_fms/data_override/include/test_data_override_ongrid_r8.fh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#undef WEIGHT_FILE_TEST_
2525
#undef SCALAR_TEST_
2626
#undef ENSEMBLE_TEST_
27+
#undef MULTI_FILE_TESTS_
2728

2829
#define DO_TEST_KIND_ r8_kind
2930
#define COMPARE_DATA_ compare_data_r8
@@ -32,5 +33,6 @@
3233
#define WEIGHT_FILE_TEST_ weight_file_test_r8
3334
#define SCALAR_TEST_ scalar_test_r8
3435
#define ENSEMBLE_TEST_ ensemble_test_r8
36+
#define MULTI_FILE_TESTS_ multi_file_r8
3537

3638
#include "test_data_override_ongrid.inc"

test_fms/data_override/test_data_override_ongrid.F90

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ program test_data_override_ongrid
5555
integer, parameter :: weight_file = 4
5656
integer, parameter :: ensemble_case = 5
5757
integer, parameter :: ensemble_same_yaml = 6
58+
integer, parameter :: multi_file = 7
5859
integer :: test_case = ongrid
5960
logical :: init_with_mode = .false.
6061
integer :: npes
@@ -112,6 +113,8 @@ program test_data_override_ongrid
112113
call generate_weight_input_file ()
113114
case (ensemble_case, ensemble_same_yaml)
114115
call generate_ensemble_input_file()
116+
case (multi_file)
117+
call generate_multi_file_input_file()
115118
end select
116119

117120
call mpp_sync()
@@ -150,6 +153,9 @@ program test_data_override_ongrid
150153
call ensemble_test_r4
151154
call ensemble_test_r8
152155
call mpp_set_current_pelist(pelist)
156+
case (multi_file)
157+
call multi_file_r4
158+
call multi_file_r8
153159
end select
154160
endif
155161

@@ -288,6 +294,63 @@ subroutine create_ongrid_data_file(is_ensemble)
288294
deallocate(runoff_in)
289295
end subroutine create_ongrid_data_file
290296

297+
subroutine create_multi_file_data_file
298+
type(FmsNetcdfFile_t) :: fileobj
299+
character(len=10) :: dimnames(3)
300+
real(r4_kind), allocatable, dimension(:,:,:) :: runoff_in
301+
real(r4_kind), allocatable, dimension(:) :: time_data
302+
integer :: i
303+
304+
integer, parameter :: ntimes = 9
305+
integer, parameter :: nfiles = 3
306+
integer :: starting
307+
integer :: ending
308+
309+
allocate(runoff_in(nlon, nlat, ntimes))
310+
allocate(time_data(ntimes))
311+
312+
time_data = (/1_r4_kind, 2_r4_kind, 3_r4_kind, &
313+
4_r4_kind, 5_r4_kind, 6_r4_kind, &
314+
7_r4_kind, 7_r4_kind, 9_r4_kind /)
315+
316+
do i = 1, ntimes
317+
runoff_in(:,:,i) = real(i, r4_kind)
318+
enddo
319+
320+
dimnames(1) = 'i'
321+
dimnames(2) = 'j'
322+
dimnames(3) = 'time'
323+
324+
do i = 1, nfiles
325+
if (open_file(fileobj, "INPUT/hadisst_ice.data_yr"//string(i-1)//".nc", "overwrite")) then
326+
call register_axis(fileobj, "i", nlon)
327+
call register_axis(fileobj, "j", nlat)
328+
call register_axis(fileobj, "time", unlimited)
329+
330+
call register_field(fileobj, "i", "float", (/"i"/))
331+
call register_variable_attribute(fileobj, "i", "cartesian_axis", "x", str_len=1)
332+
333+
call register_field(fileobj, "j", "float", (/"j"/))
334+
call register_variable_attribute(fileobj, "j", "cartesian_axis", "y", str_len=1)
335+
336+
call register_field(fileobj, "time", "float", (/"time"/))
337+
call register_variable_attribute(fileobj, "time", "cartesian_axis", "T", str_len=1)
338+
call register_variable_attribute(fileobj, "time", "calendar", "noleap", str_len=6)
339+
call register_variable_attribute(fileobj, "time", "units", "days since 0001-01-01 00:00:00", str_len=30)
340+
341+
call register_field(fileobj, "runoff", "float", dimnames)
342+
343+
starting = 2 * (i - 1) + 1
344+
ending = starting + 1
345+
346+
call write_data(fileobj, "runoff", runoff_in(:,:, starting:ending))
347+
call write_data(fileobj, "time", time_data(starting:ending))
348+
call close_file(fileobj)
349+
endif
350+
enddo
351+
352+
end subroutine create_multi_file_data_file
353+
291354
subroutine generate_ongrid_input_file
292355
!< Create some files needed by data_override!
293356
if (mpp_pe() .eq. mpp_root_pe()) then
@@ -299,6 +362,17 @@ subroutine generate_ongrid_input_file
299362
call mpp_sync()
300363
end subroutine generate_ongrid_input_file
301364

365+
subroutine generate_multi_file_input_file
366+
if (mpp_pe() .eq. mpp_root_pe()) then
367+
call create_grid_spec_file()
368+
call create_ocean_mosaic_file()
369+
call create_ocean_hgrid_file()
370+
call create_multi_file_data_file()
371+
endif
372+
373+
call mpp_sync()
374+
end subroutine generate_multi_file_input_file
375+
302376
!> @brief Creates an input netcdf data file to use for the ongrid data_override test case
303377
!! with either an increasing or decreasing lat, lon grid
304378
subroutine create_bilinear_data_file(increasing_grid)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
3+
#***********************************************************************
4+
#* GNU Lesser General Public License
5+
#*
6+
#* This file is part of the GFDL Flexible Modeling System (FMS).
7+
#*
8+
#* FMS is free software: you can redistribute it and/or modify it under
9+
#* the terms of the GNU Lesser General Public License as published by
10+
#* the Free Software Foundation, either version 3 of the License, or (at
11+
#* your option) any later version.
12+
#*
13+
#* FMS is distributed in the hope that it will be useful, but WITHOUT
14+
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
#* for more details.
17+
#*
18+
#* You should have received a copy of the GNU Lesser General Public
19+
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
20+
#***********************************************************************
21+
#
22+
# Copyright (c) 2019-2021 Ed Hartnett, Uriel Ramirez, Seth Underwood
23+
24+
# Set common test settings.
25+
. ../test-lib.sh
26+
27+
output_dir
28+
rm -rf data_table data_table.yaml input.nml input_base.nml
29+
30+
if [ -z $parser_skip ]; then
31+
32+
cat <<_EOF > input_base.nml
33+
&data_override_nml
34+
use_data_table_yaml=.True.
35+
/
36+
&test_data_override_ongrid_nml
37+
test_case = 7
38+
nlon = 5
39+
nlat = 6
40+
layout = 1, 2
41+
write_only = .False.
42+
/
43+
_EOF
44+
45+
cat <<_EOF > data_table.yaml
46+
data_table:
47+
- grid_name : OCN
48+
fieldname_in_model : runoff
49+
override_file:
50+
- file_name : INPUT/hadisst_ice.data_yr1.nc
51+
fieldname_in_file : runoff
52+
interp_method : none
53+
multi_file:
54+
- next_file_name: INPUT/hadisst_ice.data_yr2.nc
55+
prev_file_name: INPUT/hadisst_ice.data_yr0.nc
56+
factor : 1
57+
_EOF
58+
59+
[ ! -d "INPUT" ] && mkdir -p "INPUT"
60+
rm -rf INPUT/*
61+
62+
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
63+
test_expect_success "Creating input files" '
64+
mpirun -n 2 ../test_data_override_ongrid
65+
'
66+
67+
cp input_base.nml input.nml
68+
test_expect_success "data_override multi_file" '
69+
mpirun -n 2 ../test_data_override_ongrid
70+
'
71+
72+
rm -rf INPUT *.nc # remove any leftover files to reduce size
73+
74+
fi
75+
76+
test_done

0 commit comments

Comments
 (0)