REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_NCFile.cpp File Reference
#include <string>
#include "REMORA_NCFile.H"
#include "REMORA_NCInterface.H"
#include "REMORA_TimeUnits.H"
Include dependency graph for REMORA_NCFile.cpp:

Go to the source code of this file.

Functions

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 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.
 
bool QueryNetCDFHasVars (const std::string &fname, const amrex::Vector< std::string > &var_names)
 Helper function for testing whether a file carries every named variable.
 

Function Documentation

◆ QueryNetCDFHasVars()

bool QueryNetCDFHasVars ( const std::string &  fname,
const amrex::Vector< std::string > &  var_names 
)

Helper function for testing whether a file carries every named variable.

Parameters
fnameName of NetCDF file
var_namesNames of the variables to test for
Returns
whether every named variable is present in the file

Use this before calling BuildFABsFromNetCDFFile() on optional variables: ReadNetCDFFile() calls ncf.var(name) unconditionally, so a missing variable is a hard failure rather than a recoverable one. The answer is broadcast so every rank agrees before any collective read is attempted.

Definition at line 150 of file REMORA_NCFile.cpp.

Referenced by REMORA::init_only(), NCTimeSeriesBoundary::Initialize(), read_clim_nudg_coeff_from_netcdf(), and read_spherical_grid_vars_from_netcdf().

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

◆ QueryNetCDFVarAttrStr()

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.

Parameters
fnameName of NetCDF file
var_nameName of variable
attr_nameName of attribute to read
Returns
whether attribute was found

Definition at line 41 of file REMORA_NCFile.cpp.

Here is the call graph for this function:

◆ ReadNetCDFTimeOffsetDays()

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.

Reads the units attribute of time_name, which must count days, and its calendar attribute if it has one. A days since <date> reference date is converted to days since the date remora.time_ref names, so a file whose epoch differs from the run's is still read at the right time; the offset is zero when the two dates agree. A time variable with no reference date is taken to be on the model clock already. A calendar that disagrees with time_ref is an error, since the two would count days differently.

Collective: the attributes are read on the I/O processor and the result is broadcast. The mapping applied is printed, so a reader of the log can see it.

Parameters
[in]fnameNetCDF file
[in]time_namename of the time variable
[in]time_refremora.time_ref
[in]units_requiredabort when the time variable has no units attribute; otherwise warn and assume days on the model clock
[in]announceprint the mapping; false for a series that is set up but will never be read

Definition at line 61 of file REMORA_NCFile.cpp.

Referenced by NCTimeSeries::Initialize(), NCTimeSeriesBoundary::Initialize(), and NCTimeSeriesRiver::Initialize().

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

◆ ReadNetCDFVarAttrStr()

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.

Parameters
fnameName of NetCDF file
var_nameName of variable
attr_nameName of attribute to read
Returns
attribute value

Definition at line 14 of file REMORA_NCFile.cpp.

Here is the call graph for this function: