Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bennett & Uriel data_override mini assignment for YAML and data tables #1382

Merged
merged 10 commits into from
Nov 9, 2023
26 changes: 17 additions & 9 deletions data_override/include/data_override.inc
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ real(FMS_DATA_OVERRIDE_KIND_) :: min_glo_lon_lnd, max_glo_lon_lnd
real(FMS_DATA_OVERRIDE_KIND_) :: min_glo_lon_ice, max_glo_lon_ice
integer :: num_fields = 0 !< number of fields in override_array already processed

#ifdef use_yaml
type(data_type), dimension(:), allocatable :: data_table !< user-provided data table
#else
type(data_type), dimension(max_table) :: data_table !< user-provided data table
#endif

type(data_type) :: default_table
type(override_type), dimension(max_array) :: override_array !< to store processed fields
Expand All @@ -118,8 +114,9 @@ logical :: reproduce_null_char_bug = .false.
!! to reproduce the mpp_io bug where lat/lon_bnd were
!! not read correctly if null characters are present in
!! the netcdf file
logical :: use_data_table_yaml = .false.

namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug
namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug, use_data_table_yaml

public :: DATA_OVERRIDE_INIT_IMPL_, DATA_OVERRIDE_UNSET_ATM_, DATA_OVERRIDE_UNSET_OCN_, &
& DATA_OVERRIDE_UNSET_LND_, DATA_OVERRIDE_UNSET_ICE_, DATA_OVERRIDE_0D_, &
Expand Down Expand Up @@ -166,6 +163,12 @@ if (grid_center_bug) then
"that is no longer supported. Please remove this namelist variable.")
endif

if (use_yaml) then
call mpp_error(NOTE, "You are using YAML.")
else
call mpp_error(NOTE, "You are using the legacy table.")
end if

atm_on = PRESENT(Atm_domain_in)
ocn_on = PRESENT(Ocean_domain_in)
lnd_on = PRESENT(Land_domain_in)
Expand Down Expand Up @@ -199,10 +202,15 @@ endif
#ifdef use_yaml
call read_table_yaml(data_table)
bcc2761 marked this conversation as resolved.
Show resolved Hide resolved
#else
do i = 1,max_table
data_table(i) = default_table
enddo
call read_table(data_table)
if (use_data_table_yaml) then
call mpp_error(FATAL, "compilation error, need to compile with `-Duse_yaml`")
else
allocate(data_table(max_table))
do i = 1, max_table
data_table(i) = default_table
enddo
call read_table(data_table)
end if
#endif

! Initialize override array
Expand Down
2 changes: 2 additions & 0 deletions test_fms/data_override/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ LDADD = $(top_builddir)/libFMS/libFMS.la

# Build this test program.
check_PROGRAMS = \
test_data_override_init \
test_get_grid_v1_r4 \
test_get_grid_v1_r8 \
test_data_override_r4 \
Expand All @@ -38,6 +39,7 @@ check_PROGRAMS = \
test_data_override_ongrid_r8

# This is the source code for the test.
test_data_override_init_SOURCES = test_data_override_init.F90
test_data_override_r4_SOURCES = test_data_override.F90
test_data_override_r8_SOURCES = test_data_override.F90

Expand Down
37 changes: 37 additions & 0 deletions test_fms/data_override/test_data_override2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,41 @@ fi

done

# data_override with the default table (not setting namelist)
cat <<_EOF > data_table
"ICE", "sst_obs", "SST", "INPUT/sst_ice_clim.nc", .false., 300.0
_EOF

test_expect_success "data_override_init with the default table" '
mpirun -n 1 ./test_data_override_init
'
# data_override with yaml table (setting namelist to .True.)
cat <<_EOF > input.nml
&data_override_nml
use_data_table_yaml=.true.
/
_EOF

cat <<_EOF > data_table.yaml
data_table:
- gridname : OCN
fieldname_code : runoff
fieldname_file : runoff
file_name : INPUT/runoff.daitren.clim.1440x1080.v20180328.nc
interpol_method : none
factor : 1.0
_EOF

test_expect_success "data_override_init with the yaml table" '
mpirun -n 1 ./test_data_override_init
'
bcc2761 marked this conversation as resolved.
Show resolved Hide resolved
#data_override with default table (setting namelist to .True.)
bcc2761 marked this conversation as resolved.
Show resolved Hide resolved
cat <<_EOF > data_table
"ICE", "sst_obs", "SST", "INPUT/sst_ice_clim.nc", .true., 300.0
_EOF

test_expect_success "data_override_init with the default table" '
mpirun -n 1 ./test_data_override_init
'

test_done
2 changes: 2 additions & 0 deletions test_fms/field_manager/test_field_manager2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ _EOF
test_expect_success "field manager functional r4" 'mpirun -n 2 ./test_field_manager_r4'
test_expect_success "field manager functional r8" 'mpirun -n 2 ./test_field_manager_r8'

data_override_init
bcc2761 marked this conversation as resolved.
Show resolved Hide resolved

test_done