4#include "AMReX_ParallelDescriptor.H"
8#ifdef REMORA_USE_NETCDF
35 amrex::Print() <<
"Loading " <<
field_name <<
" from rivers NetCDF file(s)" << std::endl;
53 amrex::Vector<NDArray<double>>
array_ts(1);
55 if (amrex::ParallelDescriptor::IOProcessor())
69 if (amrex::ParallelDescriptor::IOProcessor()) {
72 amrex::Error(
"River data must be given at at least two times");
75 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
77 if (!(amrex::ParallelDescriptor::IOProcessor())) {
87 if (amrex::ParallelDescriptor::IOProcessor())
90 if (shape.size() == 2) {
93 }
else if (shape.size() == 3) {
97 amrex::Abort(
"River field shape not 2 or 3");
100 amrex::ParallelDescriptor::Bcast(&
has_z, 1,
ioproc);
101 amrex::ParallelDescriptor::Bcast(&
nriv, 1,
ioproc);
107 amrex::Print() <<
"Warning: " <<
field_name <<
" has no s_rho dimension in "
108 <<
file_names[0] <<
"; the same value will be used at every "
109 <<
"vertical level. ROMS expects river tracers to be given as "
110 <<
"(river_time, s_rho, river)." << std::endl;
115 amrex::Vector<amrex::FArrayBox*>
NC_fabs;
116 amrex::Vector<std::string>
NC_names;
118 amrex::Print() <<
"Reading in river_Vshape from " <<
file_names[0] << std::endl;
157 amrex::Abort(
"Time " + std::to_string(
time) +
" is not spanned by the river time"
158 +
" series for '" +
field_name +
"', which covers ["
161 +
"]. Extend the river file to cover the run. The file's times were"
162 +
" placed on the model clock from the reference date in their units"
163 +
" attribute (the mapping is printed when the series is loaded), so"
164 +
" also check remora.time_ref and remora.start_time.");
195 amrex::Vector<amrex::FArrayBox*>
NC_fabs;
196 amrex::Vector<std::string>
NC_names;
203 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " <<
itime
214 amrex::Box
riv_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nz-1));
mf_h setVal(geomdata.ProbHi(2))
void ReadNetCDFFile(const std::string &fname, amrex::Vector< std::string > names, amrex::Vector< NDArray< DType > > &arrays, bool one_time=false, int fill_time=0)
Read in data from netcdf file and save to data arrays.
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.
NCTimeSeriesRiver(const amrex::Vector< std::string > &a_file_names, const std::string a_field_name, const std::string a_time_name, const int a_nz, double a_time_ref, const int a_use_vert_integ=0, const int a_is_transport=0)
int nriv
Number of rivers.
int nzbox
How many vertical cells there are in the data fabs.
amrex::Vector< int > file_itime_offset
Offset to access a particular time within its file.
amrex::Vector< double > river_times
Time points in netcdf file, in seconds on the model clock.
amrex::Vector< std::string > file_names
File names to read from.
std::string time_name
Field name for time series in netcdf file.
double time_before
Time in ocean_time immediately before the last time interpolated to.
std::string field_name
Field name in netcdf file.
amrex::FArrayBox * fab_vshape
Vshape data if needed.
amrex::FArrayBox * fab_after
double time_after
Time in ocean_time immediately after the last time interpolated to.
int i_time_before
Time index immediately before the last time interpolated to.
void update_interpolated_to_time(double time)
Calculate interpolated values at time, in seconds on the model clock.
void read_in_at_time(amrex::FArrayBox *vec, int itime)
amrex::FArrayBox * fab_before
FABs to pointers of river data.
int nz
Number of vertical points.
amrex::Vector< int > file_for_time
File index to access a particular time.
amrex::FArrayBox * fab_interp
Container for interpolated data; Only used if save_interpolated == true.
int has_z
Whether the field is specified in the z-dimension.
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.