From 546f41ba07bbab27d60287da52b7d84bb4357438 Mon Sep 17 00:00:00 2001 From: David Clemens-Sewall Date: Wed, 25 Jan 2023 16:41:36 -0700 Subject: [PATCH 1/3] Trial fix for netCDF start time problem --- configuration/driver/icedrv_calendar.F90 | 2 +- configuration/driver/icedrv_history.F90 | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/configuration/driver/icedrv_calendar.F90 b/configuration/driver/icedrv_calendar.F90 index 3575cf390..70c5b7e12 100644 --- a/configuration/driver/icedrv_calendar.F90 +++ b/configuration/driver/icedrv_calendar.F90 @@ -167,7 +167,7 @@ subroutine init_calendar tday = (time-sec)/secday + c1 ! absolute day number ! Convert the current timestep into a calendar date - call sec2time(nyr,month,mday,basis_seconds+sec) + call sec2time(nyr,month,mday,basis_seconds+time) yday = mday + daycal(month) ! day of the year nyr = nyr - year_init + 1 ! year number diff --git a/configuration/driver/icedrv_history.F90 b/configuration/driver/icedrv_history.F90 index e6abdae32..af3c10e53 100644 --- a/configuration/driver/icedrv_history.F90 +++ b/configuration/driver/icedrv_history.F90 @@ -68,7 +68,10 @@ subroutine history_write() count1(1), count2(2), count3(3), count4(4), & ! cdf start/count arrays varid, & ! cdf varid status, & ! cdf status flag - iflag ! history file attributes + iflag, & ! history file attributes + h0, & ! start hour + m0, & ! start minute + s0 ! start second character (len=8) :: & cdate ! date string @@ -158,6 +161,9 @@ subroutine history_write() endif ! time dimension + h0 = sec / 3600 ! Get the current hour + m0 = mod(sec, 3600) / 60 ! Get the current minute + s0 = mod(sec, 60) ! Get the current seconds status = nf90_def_dim(ncid,'time',NF90_UNLIMITED,timid) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: def_dim time') status = nf90_def_var(ncid,'time',NF90_DOUBLE,timid,varid) @@ -165,8 +171,8 @@ subroutine history_write() status = nf90_put_att(ncid,varid,'long_name','model time') if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: put_att time long_name') write(cdate,'(i8.8)') idate0 - write(tmpstr,'(a,a,a,a,a,a,a,a)') 'days since ', & - cdate(1:4),'-',cdate(5:6),'-',cdate(7:8),' 00:00:00' + write(tmpstr,'(a,a,a,a,a,a,a,i2.2,a,i2.2,a,i2.2)') 'days since ', & + cdate(1:4),'-',cdate(5:6),'-',cdate(7:8),' ',h0,':',m0,':',s0 status = nf90_put_att(ncid,varid,'units',trim(tmpstr)) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: put_att time units') if (days_per_year == 360) then From 238481f1499f936f0ce9b922dbb4e589ce6d29a8 Mon Sep 17 00:00:00 2001 From: David Clemens-Sewall Date: Wed, 25 Jan 2023 17:18:39 -0700 Subject: [PATCH 2/3] driver: icedrv_history: fix start time for NetCDF history output The start time for netCDF output was hardcoded to be at 00:00:00 and there was a bug in icedrv_calendar such that idate0 was fixed at Jan. 1. Both bugs are fixed. NOTE: if dt and istep0 are set such that the start time contains fractional seconds, they will be rounded down in the NetCDF output to the nearest integer. --- configuration/driver/icedrv_history.F90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configuration/driver/icedrv_history.F90 b/configuration/driver/icedrv_history.F90 index af3c10e53..ae8150eef 100644 --- a/configuration/driver/icedrv_history.F90 +++ b/configuration/driver/icedrv_history.F90 @@ -69,6 +69,7 @@ subroutine history_write() varid, & ! cdf varid status, & ! cdf status flag iflag, & ! history file attributes + sec0, & ! number of seconds into the day at istep0 h0, & ! start hour m0, & ! start minute s0 ! start second @@ -161,9 +162,10 @@ subroutine history_write() endif ! time dimension - h0 = sec / 3600 ! Get the current hour - m0 = mod(sec, 3600) / 60 ! Get the current minute - s0 = mod(sec, 60) ! Get the current seconds + sec0 = int(mod(time0, secday)) + h0 = sec0 / 3600 ! Get the current hour + m0 = mod(sec0, 3600) / 60 ! Get the current minute + s0 = mod(sec0, 60) ! Get the current seconds status = nf90_def_dim(ncid,'time',NF90_UNLIMITED,timid) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: def_dim time') status = nf90_def_var(ncid,'time',NF90_DOUBLE,timid,varid) From e0560169c439a9aaf3a3f2024e42f7d6a009fd1f Mon Sep 17 00:00:00 2001 From: David Clemens-Sewall Date: Thu, 26 Jan 2023 14:27:47 -0700 Subject: [PATCH 3/3] driver: icedrv_history: fix start time for NetCDF History output Start of netCDF time axis is fixed at Jan. 01 00:00:00 of init_year and time value calculation is now fixed. --- configuration/driver/icedrv_calendar.F90 | 3 --- configuration/driver/icedrv_history.F90 | 13 ++++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/configuration/driver/icedrv_calendar.F90 b/configuration/driver/icedrv_calendar.F90 index 70c5b7e12..6713c4794 100644 --- a/configuration/driver/icedrv_calendar.F90 +++ b/configuration/driver/icedrv_calendar.F90 @@ -61,7 +61,6 @@ module icedrv_calendar year_init, & ! initial year nyr , & ! year number idate , & ! date (yyyymmdd) - idate0 , & ! initial date (yyyymmdd) sec , & ! elapsed seconds into date npt , & ! total number of time steps (dt) ndtd , & ! number of dynamics subcycles: dt_dyn=dt/ndtd @@ -172,8 +171,6 @@ subroutine init_calendar yday = mday + daycal(month) ! day of the year nyr = nyr - year_init + 1 ! year number - idate0 = (nyr+year_init-1)*10000 + month*100 + mday ! date (yyyymmdd) - end subroutine init_calendar !======================================================================= diff --git a/configuration/driver/icedrv_history.F90 b/configuration/driver/icedrv_history.F90 index ae8150eef..1f284d4c7 100644 --- a/configuration/driver/icedrv_history.F90 +++ b/configuration/driver/icedrv_history.F90 @@ -40,7 +40,7 @@ module icedrv_history subroutine history_write() - use icedrv_calendar, only: idate0, days_per_year, use_leap_years + use icedrv_calendar, only: days_per_year, use_leap_years, year_init use icedrv_calendar, only: time, time0, secday, istep1, idate, sec use icedrv_state, only: aice, vice, vsno, uvel, vvel, divu, shear, strength use icedrv_state, only: trcr, trcrn @@ -162,19 +162,14 @@ subroutine history_write() endif ! time dimension - sec0 = int(mod(time0, secday)) - h0 = sec0 / 3600 ! Get the current hour - m0 = mod(sec0, 3600) / 60 ! Get the current minute - s0 = mod(sec0, 60) ! Get the current seconds status = nf90_def_dim(ncid,'time',NF90_UNLIMITED,timid) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: def_dim time') status = nf90_def_var(ncid,'time',NF90_DOUBLE,timid,varid) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: def_var time') status = nf90_put_att(ncid,varid,'long_name','model time') if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: put_att time long_name') - write(cdate,'(i8.8)') idate0 - write(tmpstr,'(a,a,a,a,a,a,a,i2.2,a,i2.2,a,i2.2)') 'days since ', & - cdate(1:4),'-',cdate(5:6),'-',cdate(7:8),' ',h0,':',m0,':',s0 + write(tmpstr,'(a,i0,a)') 'days since ', & + year_init,'-01-01 00:00:00' status = nf90_put_att(ncid,varid,'units',trim(tmpstr)) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: put_att time units') if (days_per_year == 360) then @@ -290,7 +285,7 @@ subroutine history_write() status = nf90_inq_varid(ncid,'time',varid) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: inq_var '//'time') - value = (time-time0)/secday + value = time/secday status = nf90_put_var(ncid,varid,value,start=(/timcnt/)) if (status /= nf90_noerr) call icedrv_system_abort(string=subname//' ERROR: put_var '//'time')