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

Add 'valid time' variable using ISO string format #492

Merged
merged 15 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions io/module_write_netcdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ subroutine write_netcdf(wrtfb, filename, &
integer :: ncerr,ierr
integer :: ncid
integer :: oldMode
integer :: im_dimid, jm_dimid, tile_dimid, pfull_dimid, phalf_dimid, time_dimid
integer :: im_varid, jm_varid, tile_varid, lon_varid, lat_varid
integer :: im_dimid, jm_dimid, tile_dimid, pfull_dimid, phalf_dimid, time_dimid, ch_dimid
integer :: im_varid, jm_varid, tile_varid, lon_varid, lat_varid, timeiso_varid
integer, dimension(:), allocatable :: dimids_2d, dimids_3d
integer, dimension(:), allocatable :: varids
logical shuffle
Expand Down Expand Up @@ -213,6 +213,7 @@ subroutine write_netcdf(wrtfb, filename, &
! define dimensions [grid_xt, grid_yta ,(pfull/phalf), (tile), time]
ncerr = nf90_def_dim(ncid, "grid_xt", im, im_dimid); NC_ERR_STOP(ncerr)
ncerr = nf90_def_dim(ncid, "grid_yt", jm, jm_dimid); NC_ERR_STOP(ncerr)
ncerr = nf90_def_dim(ncid, "nchars", 20, ch_dimid); NC_ERR_STOP(ncerr)
if (lm > 1) then
call add_dim(ncid, "pfull", pfull_dimid, wrtgrid, rc)
call add_dim(ncid, "phalf", phalf_dimid, wrtgrid, rc)
Expand All @@ -229,9 +230,13 @@ subroutine write_netcdf(wrtfb, filename, &
ncerr = nf90_put_att(ncid, jm_varid, "cartesian_axis", "Y"); NC_ERR_STOP(ncerr)
if (is_cubed_sphere) then
ncerr = nf90_def_var(ncid, "tile", NF90_INT, tile_dimid, tile_varid); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, tile_varid, "long_name", "cubed-spehere face"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, tile_varid, "long_name", "cubed-sphere face"); NC_ERR_STOP(ncerr)
end if

ncerr = nf90_def_var(ncid, "time_iso", NF90_CHAR, [ch_dimid,time_dimid], timeiso_varid); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, timeiso_varid, "long_name", "valid time"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, timeiso_varid, "description", "ISO 8601 datetime string"); NC_ERR_STOP(ncerr)

! coordinate variable attributes based on output_grid type
if (trim(output_grid(grid_id)) == 'gaussian_grid' .or. &
trim(output_grid(grid_id)) == 'global_latlon' .or. &
Expand Down Expand Up @@ -275,6 +280,7 @@ subroutine write_netcdf(wrtfb, filename, &
ncerr = nf90_var_par_access(ncid, lon_varid, NF90_INDEPENDENT); NC_ERR_STOP(ncerr)
ncerr = nf90_var_par_access(ncid, jm_varid, NF90_INDEPENDENT); NC_ERR_STOP(ncerr)
ncerr = nf90_var_par_access(ncid, lat_varid, NF90_INDEPENDENT); NC_ERR_STOP(ncerr)
ncerr = nf90_var_par_access(ncid, timeiso_varid, NF90_INDEPENDENT); NC_ERR_STOP(ncerr)
if (is_cubed_sphere) then
ncerr = nf90_var_par_access(ncid, tile_varid, NF90_INDEPENDENT); NC_ERR_STOP(ncerr)
end if
Expand Down Expand Up @@ -560,6 +566,13 @@ subroutine write_netcdf(wrtfb, filename, &
ncerr = nf90_put_var(ncid, tile_varid, values=[1,2,3,4,5,6]); NC_ERR_STOP(ncerr)
end if

! write time_iso (timeiso_varid)
if (do_io) then
call ESMF_AttributeGet(wrtgrid, convention="NetCDF", purpose="FV3", &
name="time_iso", value=varcval, rc=rc); ESMF_ERR_RETURN(rc)
ncerr = nf90_put_var(ncid, timeiso_varid, values=[trim(varcval)]); NC_ERR_STOP(ncerr)
end if

! write variables (fields)
do i=1, fieldCount

Expand Down
19 changes: 11 additions & 8 deletions io/module_wrt_grid_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ subroutine wrt_run(wrt_comp, imp_state_write, exp_state_write,clock,rc)
!
character(esmf_maxstr) :: filename,compname
character(40) :: cfhour, cform
character(20) :: time_iso
real(ESMF_KIND_R8) :: time
!
real(kind=8) :: MPI_Wtime
Expand Down Expand Up @@ -1475,25 +1476,22 @@ subroutine wrt_run(wrt_comp, imp_state_write, exp_state_write,clock,rc)
!*** get current time and elapsed forecast time

call ESMF_ClockGet(clock=CLOCK, currTime=CURRTIME, rc=rc)

if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_TimeGet(time=currTime,yy=date(1),mm=date(2),dd=date(3),h=date(4), &
m=date(5),s=date(6),rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

wrt_int_state%fdate(7) = 1
wrt_int_state%fdate(1:6) = date(1:6)
write(time_iso,'(I4,"-",I2.2,"-",I2.2,"T",I2.2,":",I2.2,":",I2.2,"Z")') date(1:6)

if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! if(mype == lead_write_task) print *,'in wrt run, curr time=',date
!
call ESMF_TimeGet(time=wrt_int_state%IO_BASETIME,yy=date(1),mm=date(2),dd=date(3),h=date(4), &
m=date(5),s=date(6),rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! print *,'in wrt run, io_baseline time=',date
!
wrt_int_state%IO_CURRTIMEDIFF = CURRTIME-wrt_int_state%IO_BASETIME
!

call ESMF_TimeIntervalGet(timeinterval=wrt_int_state%IO_CURRTIMEDIFF &
,h =nf_hours & !<-- Hours of elapsed time
,m =nf_minutes & !<-- Minutes of elapsed time
Expand Down Expand Up @@ -1653,6 +1651,11 @@ subroutine wrt_run(wrt_comp, imp_state_write, exp_state_write,clock,rc)

if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_AttributeSet(fbgrid, convention="NetCDF", purpose="FV3", &
name="time_iso", value=trim(time_iso), rc=rc)

if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

!*** write out grid bundle:
! Provide log message indicating which wrtComp is active
call ESMF_LogWrite("before Write component before gridFB ", ESMF_LOGMSG_INFO, rc=rc)
Expand Down
21 changes: 20 additions & 1 deletion module_fcst_grid_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,26 @@ subroutine fcst_initialize(fcst_comp, importState, exportState, clock, rc)
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:calendar", value=uppercase(trim(calendar)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!

! Add time_iso Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/ "time_iso ", &
"time_iso:long_name ", &
"time_iso:description " /), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time_iso", value="yyyy-mm-ddThh:mm:ssZ", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time_iso:description", value="ISO 8601 Date String", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time_iso:long_name", value="valid time", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

! Create FieldBundle for Fields that need to be regridded bilinear
if( quilting ) then

Expand Down