21 if (amrex::ParallelDescriptor::IOProcessor())
24 amrex::Print() <<
"Trying to read attribute " <<
attr_name <<
" from variable " <<
var_name <<
" that does not exist!" << std::endl;
27 amrex::Print() <<
"Trying to read attribute " <<
attr_name <<
" that does not exist from variable " <<
var_name <<
"!" << std::endl;
48 if (amrex::ParallelDescriptor::IOProcessor())
51 amrex::Print() <<
"Trying to check for attribute " <<
attr_name <<
" from variable " <<
var_name <<
" that does not exist!" << std::endl;
56 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
57 amrex::ParallelDescriptor::Bcast(&has_var, 1,
ioproc);
58 return (has_var != 0);
62 const std::string& time_name,
70 if (amrex::ParallelDescriptor::IOProcessor())
72 if (!
ncf.has_var(time_name)) {
73 amrex::Abort(
"Time variable '" + time_name +
"' not found in " +
fname);
76 const std::string
where =
"time variable '" + time_name +
"' in " +
fname;
81 amrex::Abort(
"No units attribute on " +
where +
82 ". Expected 'days since yyyy-mm-dd hh:mm:ss'.");
84 amrex::Warning(
"Units attribute not found on time variable " + time_name +
85 ". Assuming days on the model clock");
91 amrex::Abort(
"Could not read units '" +
units +
"' of " +
where +
": " +
error);
94 amrex::Print() <<
"Units of " << time_name <<
" given as: " <<
units << std::endl;
95 amrex::Abort(
"Units must be in days.");
100 if (
time_var.has_attr(
"calendar")) {
103 amrex::Abort(
"The calendar of " +
where +
" is '" +
calendar +
104 "', but remora.time_ref selects the " +
106 "file, or choose a remora.time_ref on its calendar.");
110 if (
parsed.has_reference) {
113 amrex::Print() <<
"Time variable '" << time_name <<
"' in " <<
fname
114 <<
" counts days since "
117 amrex::Print() <<
", the remora.time_ref reference date" << std::endl;
120 <<
" days to count from the remora.time_ref reference date "
125 amrex::Print() <<
"Time variable '" << time_name <<
"' in " <<
fname
126 <<
" has units '" <<
units <<
"' with no reference date;"
127 <<
" taking its times as days since the remora.time_ref"
128 <<
" reference date " <<
ref_date << std::endl;
135 const int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
151 const amrex::Vector<std::string>&
var_names)
156 if (amrex::ParallelDescriptor::IOProcessor())
163 amrex::ParallelDescriptor::Bcast(&
has_all, 1, amrex::ParallelDescriptor::IOProcessorNumber());
AMREX_FORCE_INLINE std::string remora_ref_date_string(double time_ref)
Reference date as YYYY-MM-DD hh:mm:ss. ROMS ref_clock's Rclockstring.
AMREX_FORCE_INLINE std::string remora_ref_calendar(double time_ref)
CF calendar name for time_ref. ROMS ref_clock's Rclockcalendar.
mf_h setVal(geomdata.ProbHi(2))
bool QueryNetCDFHasVars(const std::string &fname, const amrex::Vector< std::string > &var_names)
Helper function for testing whether a file carries every named variable.
bool QueryNetCDFVarAttrStr(const std::string &fname, const std::string &var_name, const std::string &attr_name)
Helper function for testing for the presence of a single variable attribute.
double ReadNetCDFTimeOffsetDays(const std::string &fname, const std::string &time_name, double time_ref, bool units_required, bool announce)
Offset, in days, that puts a file's time variable onto the model clock.
std::string ReadNetCDFVarAttrStr(const std::string &fname, const std::string &var_name, const std::string &attr_name)
Helper function for reading a single variable attribute.
bool remora_calendar_matches_time_ref(const std::string &calendar, double time_ref)
Whether a CF calendar attribute names the calendar time_ref selects.
bool remora_parse_time_units(const std::string &units, REMORATimeUnits &out, std::string &error)
Parse a CF time-units attribute.
std::string remora_time_units_date_string(const REMORATimeUnits &units)
The reference date of units as YYYY-MM-DD hh:mm:ss.
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 ins...
static NCFile open(const std::string &name, const int cmode=NC_NOWRITE, MPI_Comm comm=MPI_COMM_WORLD, MPI_Info info=MPI_INFO_NULL)
Open an existing file.
A parsed CF time-units attribute.