NOAA-GFDL / FMS

GFDL's Flexible Modeling System
Other
87 stars 128 forks source link

Modern diag manager: Wrong time and time_bnds when only writing 1 time dimension #1522

Closed uramirez8707 closed 1 month ago

uramirez8707 commented 1 month ago

Describe the bug The time and time_bnds data of the ocean_annual.nc file for my 1 year SPEAR run are not correct. They are off by one year.

00010101.ocean_annual.nc
DIFFER : VARIABLE : time : POSITION : [0] : VALUES : 182.5 <> 547.5
DIFFER : VARIABLE : time_bnds : POSITION : [0,0] : VALUES : 0 <> 365

To Reproduce The issue can actually be reproduce by running the test_var_masks test because you are writing daily data but only running for 1 day.

make check TESTS="test_var_masks"

If you look at the time and time_bnds variable you would see

ncdump test_var_masks-files/test_var_masks.nc -v time,time_bnds | less
 time = 36 ;

 time_bnds =
  24, 48 ;

which is not correct.

Expected behavior The time and time_bnds variables should be correct. The test should have checked the actual time data :/

This is the line that is causing the issue: https://github.com/NOAA-GFDL/FMS/blob/42f8506512e1b5b43982320f5b9d4ca1ca9cbebd/diag_manager/fms_diag_file_object.F90#L1476-L1479 At the end of the run, for these files data_has_been_written will be .False. but the unlim_dimension_level is equal to 1, so it won't leave that subroutine and basically rewrite the time and time_bnds with the next time

The diag_file%unlim_dimension_level check is no longer needed because at the end of run, this is called which sets data_has_been_written and unlim_dimension_level to 1 (if data has never received for the file), which prevents issues with the combiner.

https://github.com/NOAA-GFDL/FMS/blob/42f8506512e1b5b43982320f5b9d4ca1ca9cbebd/diag_manager/fms_diag_file_object.F90#L1558-L1565

System Environment N/A

Additional context N/A