diff --git a/diag_manager/fms_diag_file_object.F90 b/diag_manager/fms_diag_file_object.F90 index f72f1d7ef..612e080db 100644 --- a/diag_manager/fms_diag_file_object.F90 +++ b/diag_manager/fms_diag_file_object.F90 @@ -1007,7 +1007,7 @@ 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 @@ -1015,7 +1015,8 @@ subroutine add_start_time(this, start_time) 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") diff --git a/test_fms/diag_manager/test_prepend_date.F90 b/test_fms/diag_manager/test_prepend_date.F90 index 393406d94..24a5ae298 100644 --- a/test_fms/diag_manager/test_prepend_date.F90 +++ b/test_fms/diag_manager/test_prepend_date.F90 @@ -25,13 +25,13 @@ 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 @@ -39,12 +39,25 @@ program test_prepend_date 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 @@ -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 diff --git a/test_fms/diag_manager/test_prepend_date.sh b/test_fms/diag_manager/test_prepend_date.sh index 49a2b21c0..13bbf7c77 100755 --- a/test_fms/diag_manager/test_prepend_date.sh +++ b/test_fms/diag_manager/test_prepend_date.sh @@ -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