Skip to content

Commit

Permalink
Add Time coordinate
Browse files Browse the repository at this point in the history
This variable has CF-compliant units and calendar.  To accommodate
the CF-compliant units, a new config option has been added to
supply the reference time, 0001-01-01 by default.
  • Loading branch information
xylar committed May 17, 2022
1 parent 04c0376 commit 83d0c89
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions components/mpas-ocean/src/Registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
description="Selection of the type of calendar that should be used in the simulation."
possible_values="'gregorian', 'gregorian_noleap'"
/>
<nml_option name="config_output_reference_time" type="character" default_value="0001-01-01_00:00:00" units="unitless"
description="Reference time used in the units attribute of Time in output files."
possible_values="'YYYY-MM-DD_HH:MM:SS'"
/>
</nml_record>
<nml_record name="io" mode="forward;analysis">
<nml_option name="config_write_output_on_startup" type="logical" default_value=".true." units="unitless"
Expand Down Expand Up @@ -2432,6 +2436,9 @@
<var name="xtime" type="text" dimensions="Time" units="unitless"
description="model time, with format 'YYYY-MM-DD_HH:MM:SS'"
/>
<var name="Time" type="real" dimensions="Time"
description="time"
/>
<var name="simulationStartTime" type="text" dimensions="" units="unitless" default_value="'no_date_available'"
description="start time of first simulation, with format 'YYYY-MM-DD_HH:MM:SS'"
/>
Expand Down
26 changes: 24 additions & 2 deletions components/mpas-ocean/src/mode_forward/mpas_ocn_forward_mode.F
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,23 @@ function ocn_forward_mode_init(domain, startTimeStamp) result(ierr)!{{{
block ! structure with all data for a given block

type (mpas_pool_type), pointer :: &
meshPool ! structure containing mesh data
diagnosticsPool ! structure containing diagnostics data

type (MPAS_Time_type) :: &
xtime_timeType, &! current time
simulationStartTime_timeType, &! start time whole simulation
referenceTime_timeType, &! reference time for Time coordinate
startTime, &! start time this run
alarmTime ! alarm for salinity restoring

type (field0DReal), pointer :: TimeField ! to add units

type (MPAS_TimeInterval_type) :: &
timeStep, &! time step in time manager form
alarmTimeStep ! alarm interval in time manager form

character (len=StrKIND) :: units

! End preamble
!-------------
! Begin code
Expand Down Expand Up @@ -315,9 +320,26 @@ function ocn_forward_mode_init(domain, startTimeStamp) result(ierr)!{{{
! compute time since start of simulation, in days
call mpas_set_time(xtime_timeType, dateTimeString=xtime)
call mpas_set_time(simulationStartTime_timeType, dateTimeString=simulationStartTime)
call mpas_get_timeInterval(xtime_timeType - simulationStartTime_timeType,dt=daysSinceStartOfSim)
call mpas_get_timeInterval(xtime_timeType - simulationStartTime_timeType, dt=daysSinceStartOfSim)
daysSinceStartOfSim = daysSinceStartOfSim*days_per_second

call mpas_pool_get_subpool(block % structs, 'diagnostics', diagnosticsPool)

! add units of "days since <ref_date>" to Time
write(units, '(a10,a20)') 'days since', &
config_output_reference_time(1:10)//" "//config_output_reference_time(12:19)
call mpas_pool_get_Field(diagnosticsPool, 'Time', TimeField)
call mpas_add_att(TimeField % attLists(1) % attList, 'units', units)

! Add calendar attribute to Time
call mpas_pool_get_config(domain % configs, 'config_calendar_type', config_calendar_type)
call mpas_add_att(TimeField % attLists(1) % attList, 'calendar', config_calendar_type)

! compute Time as days since config_output_reference_time
call mpas_set_time(referenceTime_timeType, dateTimeString=config_output_reference_time)
call mpas_get_timeInterval(xtime_timeType - referenceTime_timeType, dt=Time)
Time = Time*days_per_second

! Update any mesh fields that may have been modified during init
call ocn_meshUpdateFields(domain)

Expand Down
13 changes: 11 additions & 2 deletions components/mpas-ocean/src/mode_forward/mpas_ocn_time_integration.F
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ subroutine ocn_timestep(domain, dt, timeStamp)!{{{
!-----------------------------------------------------------------

type (MPAS_Time_type) :: &
xtime_timeType, &! current time in time type
simulationStartTime_timeType ! start time in time type
xtime_timeType, &! current time in time type
simulationStartTime_timeType, &! start time in time type
referenceTime_timeType ! reference time for Time coordinate

! End preamble
!-------------
Expand Down Expand Up @@ -143,6 +144,14 @@ subroutine ocn_timestep(domain, dt, timeStamp)!{{{

daysSinceStartOfSim = daysSinceStartOfSim*days_per_second

call mpas_set_time(referenceTime_timeType, &
dateTimeString=config_output_reference_time)
call mpas_get_timeInterval( &
xtime_timeType - referenceTime_timeType, &
dt=Time)

Time = Time*days_per_second

!--------------------------------------------------------------------

end subroutine ocn_timestep!}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ module ocn_diagnostics_variables
activeTracerVertMixTendency

real (kind=RKIND), pointer :: daysSinceStartOfSim
real (kind=RKIND), pointer :: Time
character (len=StrKIND), pointer :: xtime, simulationStartTime

real (kind=RKIND), dimension(:,:), pointer :: bulkRichardsonNumber
Expand Down Expand Up @@ -538,6 +539,7 @@ subroutine ocn_diagnostics_variables_init(domain, jenkinsOn, hollandJenkinsOn, e
call mpas_pool_get_array(diagnosticsPool, &
"daysSinceStartOfSim", &
daysSinceStartOfSim)
call mpas_pool_get_array(diagnosticsPool, 'Time', Time)
call mpas_pool_get_array(diagnosticsPool, 'xtime', xtime)
call mpas_pool_get_array(diagnosticsPool, 'simulationStartTime', &
simulationStartTime)
Expand Down Expand Up @@ -824,6 +826,7 @@ subroutine ocn_diagnostics_variables_init(domain, jenkinsOn, hollandJenkinsOn, e
!$acc pressureAdjustedSSH, &
!$acc tracersSurfaceValue, &
!$acc daysSinceStartOfSim, &
!$acc Time, &
!$acc simulationStartTime, &
!$acc boundaryLayerDepthSmooth, &
!$acc surfaceFluxAttenuationCoefficientRunoff &
Expand Down Expand Up @@ -1063,6 +1066,7 @@ subroutine ocn_diagnostics_variables_destroy(err) !{{{
!$acc pressureAdjustedSSH, &
!$acc tracersSurfaceValue, &
!$acc daysSinceStartOfSim, &
!$acc Time, &
!$acc simulationStartTime, &
!$acc boundaryLayerDepthSmooth, &
!$acc surfaceFluxAttenuationCoefficientRunoff &
Expand Down Expand Up @@ -1251,6 +1255,7 @@ subroutine ocn_diagnostics_variables_destroy(err) !{{{
pressureAdjustedSSH, &
tracersSurfaceValue, &
daysSinceStartOfSim, &
Time, &
simulationStartTime, &
boundaryLayerDepthSmooth, &
surfaceFluxAttenuationCoefficientRunoff)
Expand Down

0 comments on commit 83d0c89

Please sign in to comment.