Skip to content

Commit

Permalink
Add a test that fails when the time init is not the same for all vari…
Browse files Browse the repository at this point in the history
…ables in the file
  • Loading branch information
uramirez8707 committed Jun 11, 2024
1 parent e8c20c2 commit 2241a89
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 3 additions & 2 deletions diag_manager/fms_diag_file_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1007,15 +1007,16 @@ end subroutine define_new_subaxis
!! So it needs to make sure that the start_time is the same for each variable. The initial value is the base_time
subroutine add_start_time(this, start_time)
class(fmsDiagFile_type), intent(inout) :: this !< The file object
TYPE(time_type), intent(in) :: start_time !< Start time to add to the fileobj
TYPE(time_type), intent(in) :: start_time !< Start time passed into register_diag_field

!< If the start_time sent in is equal to the diag_init_time return because
!! this%start_time was already set to the diag_init_time
if (start_time .eq. diag_init_time) return

if (this%start_time .ne. diag_init_time) then
!> If the this%start_time is not equal to the diag_init_time from the diag_table
!! this%start_time was already updated so make sure it is the same or error out
!! this%start_time was already updated so make sure it is the same for the current variable
!! or error out
if (this%start_time .ne. start_time)&
call mpp_error(FATAL, "The variables associated with the file:"//this%get_file_fname()//" have"&
&" different start_time")
Expand Down
22 changes: 19 additions & 3 deletions test_fms/diag_manager/test_prepend_date.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,39 @@ program test_prepend_date
register_diag_field, diag_manager_init, diag_manager_end, register_static_field, &
diag_axis_init
use time_manager_mod, only: time_type, operator(+), JULIAN, set_time, set_calendar_type, set_date
use mpp_mod, only: FATAL, mpp_error
use mpp_mod, only: FATAL, mpp_error, input_nml_file
use fms2_io_mod, only: FmsNetcdfFile_t, open_file, close_file, read_data, get_dimension_size
use platform_mod, only: r4_kind

implicit none

integer :: id_var0, id_var2 !< diag field ids
integer :: id_var0, id_var2, id_var1 !< diag field ids
integer :: id_axis1 !< Id for axis
logical :: used !< for send_data calls
integer :: ntimes = 48 !< Number of time steps
real :: vdata !< Buffer to store the data
type(time_type) :: Time !< "Model" time
type(time_type) :: Time_step !< Time step for the "simulation"
integer :: i !< For do loops
logical :: pass_diag_time = .True. !< .True. if passing the time to diag_manager_init

integer :: io_status !< Status when reading the namelist

namelist / test_prepend_date_nml / pass_diag_time

call fms_init

read (input_nml_file, test_prepend_date_nml, iostat=io_status)
if (io_status > 0) call mpp_error(FATAL,'=>test_prepend_date: Error reading input.nml')

call set_calendar_type(JULIAN)

! This is going to be different from the base_date
call diag_manager_init(time_init=(/2, 1, 1, 0, 0, 0/))
if (pass_diag_time) then
call diag_manager_init(time_init=(/2, 1, 1, 0, 0, 0/))
else
call diag_manager_init()
endif

Time = set_date(2,1,1,0,0,0)
Time_step = set_time (3600,0) !< 1 hour
Expand All @@ -54,6 +67,9 @@ program test_prepend_date
id_var0 = register_diag_field ('ocn_mod', 'var0', Time)
id_var2 = register_static_field ('ocn_mod', 'var2', (/id_axis1/))

! This is a different start_time, should lead to a crash if the variable is in the diag table yaml
id_var1 = register_diag_field ('ocn_mod', 'var1', set_date(2,1,6,0,0,0))

used = send_data(id_var2, real(123.456))
do i = 1, ntimes
Time = Time + Time_step
Expand Down
25 changes: 25 additions & 0 deletions test_fms/diag_manager/test_prepend_date.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,30 @@ test_expect_success "Running diag_manager and checking that the date was prepend
mpirun -n 1 ../test_prepend_date
'

cat <<_EOF > diag_table.yaml
title: test_prepend_date
base_date: 1 1 1 0 0 0
diag_files:
- file_name: test_non_static
time_units: hours
unlimdim: time
freq: 1 hours
varlist:
- module: ocn_mod
var_name: var0
reduction: average
kind: r4
- module: ocn_mod
var_name: var1
reduction: average
kind: r4
_EOF

printf "&diag_manager_nml \n use_modern_diag=.true. \n/ \n &test_prepend_date_nml \n pass_diag_time=.false. \n /" | cat > input.nml

test_expect_failure "Running diag_manager with fields that have a different start time (test $my_test_count)" '
mpirun -n 1 ../test_prepend_date
'

fi
test_done

0 comments on commit 2241a89

Please sign in to comment.