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

fix for time units attribute when IAU used with netcdf format #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions io/module_write_netcdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ subroutine write_netcdf(fieldbundle, wrtfb, filename, mpi_comm, mype, im, jm, rc
real(8) :: varr8val
character(len=ESMF_MAXSTR) :: varcval

character(128) :: time_units

integer :: ncerr
integer :: ncid
integer :: oldMode
Expand Down Expand Up @@ -520,6 +518,10 @@ subroutine add_dim(ncid, dim_name, dimid, grid, rc)
real(ESMF_KIND_R4), allocatable :: valueListR4(:)
real(ESMF_KIND_R8), allocatable :: valueListR8(:)
character(len=ESMF_MAXSTR), allocatable :: valueListC(:)
character(nf90_max_name) :: time_units
integer idate(6)
real(8) rinc(5)
integer idat(8),jdat(8)
!
call ESMF_AttributeGet(grid, convention="NetCDF", purpose="FV3", &
attnestflag=ESMF_ATTNEST_OFF, name=dim_name, &
Expand Down Expand Up @@ -555,8 +557,9 @@ subroutine add_dim(ncid, dim_name, dimid, grid, rc)
end if

call get_grid_attr(grid, dim_name, ncid, dim_varid, rc)

end subroutine add_dim

!
!----------------------------------------------------------------------------------------
subroutine nccheck(status)
Expand Down
36 changes: 27 additions & 9 deletions module_fcst_grid_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module module_fcst_grid_comp

!----- coupled model data -----

integer :: date_init(6)
integer :: date_init(6), date_init2(6)
integer :: numLevels = 0
integer :: numSoilLayers = 0
integer :: numTracers = 0
Expand Down Expand Up @@ -210,6 +210,8 @@ subroutine fcst_initialize(fcst_comp, importState, exportState, clock, rc)
integer :: globalTileLayout(2)
integer :: nestRootPet, peListSize(1)
integer, allocatable :: petMap(:)
real(8) rinc(5)
integer idat(8),jdat(8)
!
!-----------------------------------------------------------------------
!***********************************************************************
Expand Down Expand Up @@ -536,20 +538,36 @@ subroutine fcst_initialize(fcst_comp, importState, exportState, clock, rc)
name="time", value=real(0,ESMF_KIND_R8), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

write(dateSY,'(I4.4)')date_init(1)
write(dateSM,'(I2.2)')date_init(2)
write(dateSD,'(I2.2)')date_init(3)
write(dateSH,'(I2.2)')date_init(4)
write(dateSN,'(I2.2)')date_init(5)
write(dateSS,'(I2.2)')date_init(6)
! update date_init with iau_offset
date_init2 = date_init
if (atm_int_state%Atm%iau_offset > 0) then
! date_init: year,month,day,hour,minute,second
! idat: year,month,day,time zone,hour,minute,second,millsecond
idat = 0
idat(1:3) = date_init2(1:3)
idat(5:7) = date_init2(4:6)
! rinc: days,hours,minutes,seconds,milliseconds
rinc = 0; rinc(2) = iau_offset
call w3movdat(rinc,idat,jdat)
! update date_init using iau_offset
date_init2(1:3)=jdat(1:3)
date_init2(4:6)=jdat(5:7)
endif

! time:units attribute uses date_init modified by iau_offset
write(dateSY,'(I4.4)')date_init2(1)
write(dateSM,'(I2.2)')date_init2(2)
write(dateSD,'(I2.2)')date_init2(3)
write(dateSH,'(I2.2)')date_init2(4)
write(dateSN,'(I2.2)')date_init2(5)
write(dateSS,'(I2.2)')date_init2(6)

dateS="hours since "//dateSY//'-'//dateSM//'-'//dateSD//' '//dateSH//':'// &
dateSN//":"//dateSS
if (mype == 0) write(0,*)'dateS=',trim(dateS),'date_init=',date_init
if (mype == 0) write(0,*)'dateS=',trim(dateS),'date_init=',date_init2

call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:units", value=trim(dateS), rc=rc)
! name="time:units", value="hours since 2016-10-03 00:00:00", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
Expand Down