Skip to content

Commit

Permalink
Merge branch 'NOAA-GFDL:main' into markdown-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rem1776 authored Apr 24, 2024
2 parents e349409 + cb0c48a commit 0b44f9b
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 23 deletions.
24 changes: 10 additions & 14 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# These owners will be the default owners for all the files in the
# repository. Unless a later match is found, these owners
# will be requested for a review when a PR is opened.
* @thomas-robinson @bensonr @rem1776 @scitech777
* @thomas-robinson @bensonr @rem1776

# GNU autotools files
Makefile.am @uramirez8707 @rem1776
Expand All @@ -34,15 +34,13 @@ Makefile.am @uramirez8707 @rem1776
*.m4 @uramirez8707 @rem1776

# cmake files
CM* @mlee03 @ngs333
cmake @mlee03 @ngs333
CM* @mlee03
cmake @mlee03

# Files specific to GitHub or GitLab
/.github/ @GFDL-Eric @rem1776
/.gitlab/ @GFDL-Eric @rem1776
/.github/ @rem1776

# Testing files
/.gitlab-ci.yml @uramirez8707 @mlee03 @bensonr @thomas-robinson @rem1776
/test_fms/ @uramirez8707 @mlee03 @bensonr @thomas-robinson @rem1776

# Specific component directories
Expand All @@ -52,18 +50,16 @@ cmake @mlee03 @ngs333
/block_control/ @bensonr
/test_fms/block_control/ @bensonr @rem1776

/data_override/ @GFDL-Eric
/test_fms/data_override/ @GFDL-Eric @rem1776
#/data_override/ Currently no code owner
/test_fms/data_override/ @rem1776

/diag_manager @thomas-robinson @ngs333
/test_fms/diag_manager/ @thomas-robinson @ngs333

/fv3gfs/ @bensonr
/diag_manager @thomas-robinson
/test_fms/diag_manager/ @thomas-robinson

/fms/ @thomas-robinson @rem1776
/test_fms/fms/ @thomas-robinson @rem1776
/fms2/ @uramirez8707 @GFDL-Eric
/test_fms/fms2/ @uramirez8707 @GFDL-Eric
/fms2/ @uramirez8707
/test_fms/fms2/ @uramirez8707

/libFMS/ @thomas-robinson @rem1776

Expand Down
18 changes: 11 additions & 7 deletions data_override/include/data_override.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ type data_type
logical :: multifile = .false.
character(len=512) :: prev_file_name !< name of netCDF data file for previous segment
character(len=512) :: next_file_name !< name of netCDF data file for next segment
type(time_type), dimension(:), pointer :: time_records => NULL()
type(time_type), dimension(:), pointer :: time_prev_records => NULL()
type(time_type), dimension(:), pointer :: time_next_records => NULL()
type(time_type), dimension(:), allocatable :: time_records
type(time_type), dimension(:), allocatable :: time_prev_records
type(time_type), dimension(:), allocatable :: time_next_records
end type data_type

!> Private type for holding various data fields for performing data overrides
Expand Down Expand Up @@ -900,13 +900,17 @@ subroutine DATA_OVERRIDE_0D_(gridname,fieldname_code,data_out,time,override,data

!10 do time interp to get data in compute_domain

first_record = data_table(index1)%time_records(1)
last_record = data_table(index1)%time_records(dims(4))

! if using consecutive files, allow to perform time interpolation between the last record of previous
! file and first record of current file OR between the last record of current file and first record of
! next file hence "bridging" over files.
if_multi2: if (multifile) then
dims = get_external_field_size(id_time)
if (.not. allocated(data_table(index1)%time_records)) allocate(data_table(index1)%time_records(dims(4)))
call get_time_axis(id_time,data_table(index1)%time_records)

first_record = data_table(index1)%time_records(1)
last_record = data_table(index1)%time_records(dims(4))

if_time2: if (time<first_record) then
if (id_time_prev<0) call mpp_error(FATAL,'data_override:previous file needed with multifile')
prev_dims = get_external_field_size(id_time_prev)
Expand Down Expand Up @@ -1438,7 +1442,7 @@ subroutine DATA_OVERRIDE_3D_(gridname,fieldname_code,return_data,time,override,d


dims = get_external_field_size(id_time)
if (.not. associated(data_table(index1)%time_records)) allocate(data_table(index1)%time_records(dims(4)))
if (.not. allocated(data_table(index1)%time_records)) allocate(data_table(index1)%time_records(dims(4)))
call get_time_axis(id_time,data_table(index1)%time_records)

first_record = data_table(index1)%time_records(1)
Expand Down
6 changes: 4 additions & 2 deletions test_fms/data_override/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ TESTS_ENVIRONMENT= test_input_path="@TEST_INPUT_PATH@" \

# Run the test program.

TESTS = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh
TESTS = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh \
test_data_override2_scalar.sh

# Include these files with the distribution.
EXTRA_DIST = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh
EXTRA_DIST = test_data_override2.sh test_data_override_init.sh test_data_override2_mono.sh test_data_override2_ongrid.sh \
test_data_override2_scalar.sh

# Clean up
CLEANFILES = input.nml *.nc* *.out diag_table data_table data_table.yaml INPUT/* *.dpi *.spi *.dyn *.spl *-files/*
71 changes: 71 additions & 0 deletions test_fms/data_override/test_data_override2_scalar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh

#***********************************************************************
#* GNU Lesser General Public License
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* FMS is free software: you can redistribute it and/or modify it under
#* the terms of the GNU Lesser General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or (at
#* your option) any later version.
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
#* for more details.
#*
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************
#
# Copyright (c) 2019-2021 Ed Hartnett, Uriel Ramirez, Seth Underwood

# Set common test settings.
. ../test-lib.sh

output_dir
rm -rf data_table data_table.yaml input.nml input_base.nml

if [ ! -z $parser_skip ]; then
cat <<_EOF > input.nml
&data_override_nml
use_data_table_yaml=.False.
/
&test_data_override_ongrid_nml
test_case = 3
/
_EOF
printf '"OCN", "co2", "co2", "./INPUT/scalar.nc", "none" , 1.0' | cat > data_table
else
cat <<_EOF > input.nml
&data_override_nml
use_data_table_yaml=.True.
/
&test_data_override_ongrid_nml
test_case = 3
/
_EOF
cat <<_EOF > data_table.yaml
data_table:
- gridname : OCN
fieldname_code : co2
fieldname_file : co2
file_name : INPUT/scalar.nc
interpol_method : none
factor : 1.0
_EOF
fi

[ ! -d "INPUT" ] && mkdir -p "INPUT"
for KIND in r4 r8
do
rm -rf INPUT/*
test_expect_success "data_override scalar field (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

done
rm -rf INPUT *.nc # remove any leftover files to reduce size

test_done
75 changes: 75 additions & 0 deletions test_fms/data_override/test_data_override_ongrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ program test_data_override_ongrid
integer :: io_status
integer, parameter :: ongrid = 1
integer, parameter :: bilinear = 2
integer, parameter :: scalar = 3
integer :: test_case = ongrid

namelist / test_data_override_ongrid_nml / nhalox, nhaloy, test_case
Expand Down Expand Up @@ -83,6 +84,8 @@ program test_data_override_ongrid
call generate_ongrid_input_file ()
case (bilinear)
call generate_bilinear_input_file ()
case (scalar)
call generate_scalar_input_file ()
end select

call mpp_sync()
Expand All @@ -96,6 +99,8 @@ program test_data_override_ongrid
call ongrid_test()
case (bilinear)
call bilinear_test()
case (scalar)
call scalar_test()
end select

call mpp_exit
Expand Down Expand Up @@ -437,4 +442,74 @@ subroutine bilinear_test()
enddo
deallocate(runoff_decreasing, runoff_increasing)
end subroutine bilinear_test

!> @brief Generates the input for the bilinear data_override test_case
subroutine generate_scalar_input_file()
if (mpp_pe() .eq. mpp_root_pe()) then
call create_grid_spec_file ()
call create_ocean_mosaic_file()
call create_ocean_hgrid_file()
call create_scalar_data_file()
endif
call mpp_sync()
end subroutine generate_scalar_input_file

subroutine create_scalar_data_file()
type(FmsNetcdfFile_t) :: fileobj
character(len=10) :: dimnames(1)
real(lkind), allocatable, dimension(:) :: co2_in
real(lkind), allocatable, dimension(:) :: time_data
integer :: i

allocate(co2_in(10))
allocate(time_data(10))
do i = 1, 10
co2_in(i) = real(i, lkind)
enddo
time_data = (/1., 2., 3., 5., 6., 7., 8., 9., 10., 11./)

dimnames(1) = 'time'

if (open_file(fileobj, 'INPUT/scalar.nc', 'overwrite')) then
call register_axis(fileobj, "time", unlimited)
call register_field(fileobj, "time", "float", (/"time"/))
call register_variable_attribute(fileobj, "time", "cartesian_axis", "T", str_len=1)
call register_variable_attribute(fileobj, "time", "calendar", "noleap", str_len=6)
call register_variable_attribute(fileobj, "time", "units", "days since 0001-01-01 00:00:00", str_len=30)

call register_field(fileobj, "co2", "float", dimnames)
call write_data(fileobj, "co2", co2_in)
call write_data(fileobj, "time", time_data)
call close_file(fileobj)
else
call mpp_error(FATAL, "Error opening the file: 'INPUT/scalar.nc' to write")
endif
deallocate(co2_in)
end subroutine create_scalar_data_file

subroutine scalar_test()
real(lkind) :: expected_result !< Expected result from data_override
type(time_type) :: Time !< Time
real(lkind) :: co2 !< Data to be written

co2 = 999._lkind
!< Run it when time=3
Time = set_date(1,1,4,0,0,0)
call data_override('OCN','co2',co2, Time)
!< Because you are getting the data when time=3, and this is an "ongrid" case, the expected result is just
!! equal to the data at time=3, which is 3.
expected_result = 3._lkind
if (co2 .ne. expected_result) call mpp_error(FATAL, "co2 was not overriden to the correct value!")

!< Run it when time=4
co2 = 999._lkind
Time = set_date(1,1,5,0,0,0)
call data_override('OCN','co2',co2, Time)
!< You are getting the data when time=4, the data at time=3 is 3. and at time=5 is 4., so the expected result
!! is the average of the 2 (because this is is an "ongrid" case and there is no horizontal interpolation).
expected_result = (3._lkind + 4._lkind) / 2._lkind
if (co2 .ne. expected_result) call mpp_error(FATAL, "co2 was not overriden to the correct value!")

end subroutine scalar_test

end program test_data_override_ongrid

0 comments on commit 0b44f9b

Please sign in to comment.