REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_TimeUnits.H File Reference
#include <cctype>
#include <cstdio>
#include <sstream>
#include <string>
#include <vector>
#include "REMORA_DateClock.H"
Include dependency graph for REMORA_TimeUnits.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  REMORATimeUnits
 A parsed CF time-units attribute. More...
 

Namespaces

namespace  remora_time_units_detail
 

Functions

std::string remora_time_units_detail::lower (std::string s)
 
bool remora_time_units_detail::parse_clock (const std::string &tok, REMORATimeUnits &out)
 hh:mm[:ss[.s]], optionally suffixed z. Fills the time fields on success.
 
bool remora_time_units_detail::parse_date (const std::string &tok, REMORATimeUnits &out)
 
bool remora_time_units_detail::is_utc (const std::string &tok)
 A time-zone designator that means UTC.
 
bool remora_parse_time_units (const std::string &units, REMORATimeUnits &out, std::string &error)
 Parse a CF time-units attribute.
 
double remora_time_units_offset_days (const REMORATimeUnits &units, double time_ref)
 Days to add to a time counted from units' reference date to count it from the date time_ref names instead.
 
bool remora_calendar_matches_time_ref (const std::string &calendar, double time_ref)
 Whether a CF calendar attribute names the calendar time_ref selects.
 
std::string remora_time_units_date_string (const REMORATimeUnits &units)
 The reference date of units as YYYY-MM-DD hh:mm:ss.
 

Detailed Description

The CF units attribute of a NetCDF time variable, and how it maps onto the model clock.

A forcing, boundary, river or climatology file stamps its records with a time variable whose units read days since <date>, or just days. The model clock counts from the date remora.time_ref names (see REMORA_DateClock.H), so a file time is on the model clock only after the difference between the two reference dates is added:

model days = file days + (datenum(file reference) - datenum(time_ref))

remora_time_units_offset_days computes that bracket, in the calendar time_ref selects. It is zero when the file counts from the same date as the run, which is the usual case, and a file with no reference date is taken to be on the model clock already.

remora_parse_time_units reads the attribute. It accepts the CF form, <unit> since YYYY-MM-DD[ hh:mm[:ss[.s]]][ UTC|Z|+00:00], and it skips words between since and the date, so days since initialization, 2020-01-01 00:00:00 reads as 2020-01-01. It does not interpret a time zone other than UTC. Host only: it works on std::string.

Definition in file REMORA_TimeUnits.H.

Function Documentation

◆ remora_calendar_matches_time_ref()

bool remora_calendar_matches_time_ref ( const std::string &  calendar,
double  time_ref 
)
inline

Whether a CF calendar attribute names the calendar time_ref selects.

360_day goes with time_ref = -1 and nothing else. Every other time_ref is Gregorian: gregorian, standard and proleptic_gregorian all agree for dates after 1582, which is where the model clock lives. julian, noleap and the rest count days differently and are rejected.

Definition at line 222 of file REMORA_TimeUnits.H.

Referenced by ReadNetCDFTimeOffsetDays().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remora_parse_time_units()

bool remora_parse_time_units ( const std::string &  units,
REMORATimeUnits &  out,
std::string &  error 
)
inline

Parse a CF time-units attribute.

Parameters
[in]unitsthe attribute text, e.g. days since 2020-01-01 00:00:00
[out]outthe unit word and, if given, the reference date
[out]errorwhy parsing failed, when it did
Returns
whether the attribute parsed. The unit word is not checked here; the caller decides which units it accepts.

Definition at line 135 of file REMORA_TimeUnits.H.

Referenced by ReadNetCDFTimeOffsetDays().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remora_time_units_date_string()

std::string remora_time_units_date_string ( const REMORATimeUnits &  units)
inline

The reference date of units as YYYY-MM-DD hh:mm:ss.

Definition at line 234 of file REMORA_TimeUnits.H.

Referenced by ReadNetCDFTimeOffsetDays().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remora_time_units_offset_days()

double remora_time_units_offset_days ( const REMORATimeUnits &  units,
double  time_ref 
)
inline

Days to add to a time counted from units' reference date to count it from the date time_ref names instead.

Zero for a file with no reference date, which is taken to be on the model clock already, and zero when the two dates agree. The day numbers are both taken in the calendar time_ref selects, as remora_caldate does.

Definition at line 204 of file REMORA_TimeUnits.H.

Referenced by ReadNetCDFTimeOffsetDays().

Here is the call graph for this function:
Here is the caller graph for this function: