20#include "pism/util/InputInterpolation.hh"
21#include "pism/util/Interpolation1D.hh"
22#include "pism/util/io/LocalInterpCtx.hh"
23#include "pism/pism_config.hh"
24#include "pism/util/Context.hh"
25#include "pism/util/Grid.hh"
26#include "pism/util/VariableMetadata.hh"
27#include "pism/util/io/File.hh"
28#include "pism/util/io/IO_Flags.hh"
29#include "pism/util/io/io_helpers.hh"
30#include "pism/util/petscwrappers/Vec.hh"
31#include "pism/util/pism_utilities.hh"
32#include "pism/util/projection.hh"
33#include "pism/util/Logger.hh"
35#if (Pism_USE_YAC_INTERPOLATION == 1)
45 if (record_index == -1) {
49 record_index = (
int)nrecords - 1;
52 return regrid_impl(metadata, file, record_index, grid, output);
60 const std::vector<double> &levels,
61 const File &input_file,
const std::string &variable_name,
64 auto log = target_grid.
ctx()->log();
65 auto unit_system = target_grid.
ctx()->unit_system();
67 auto name =
grid_name(input_file, variable_name, unit_system,
70 log->message(2,
"* Initializing bi- or tri-linear interpolation from '%s' to the internal grid...\n",
76 input_grid.
report(*log, 4, unit_system);
80 m_interp_context = std::make_shared<LocalInterpCtx>(input_grid, target_grid, levels, type);
87 const Grid &target_grid,
95 context.start[
T_AXIS] = record_index;
106std::shared_ptr<InputInterpolation>
108 const std::vector<double> &levels,
const File &input_file,
111#if (Pism_USE_YAC_INTERPOLATION == 1)
113 auto source_projection =
120 (levels.size() < 2 and (not source_projection.empty()) and (not target_projection.empty()));
124 if (source_projection == target_projection) {
129 (source_grid.
x.size() == target_grid.
Mx() and source_grid.
y.size() == target_grid.
My());
131 bool center_matches =
132 (source_grid.
x0 == target_grid.
x0() and source_grid.
y0 == target_grid.
y0());
134 bool extent_matches =
135 (source_grid.
Lx == target_grid.
Lx() and source_grid.
Ly == target_grid.
Ly());
137 if (size_matches and center_matches and extent_matches) {
141 double dx_source = source_grid.
x[1] - source_grid.
x[0];
142 double dy_source = source_grid.
y[1] - source_grid.
y[0];
145 if (dx_source < 0 or dy_source < 0) {
151 return std::make_shared<InputInterpolationYAC>(target_grid, input_file, variable_name, type);
156 return std::make_shared<InputInterpolation3D>(target_grid, levels, input_file, variable_name,
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
High-level PISM I/O class.
double y0() const
Y-coordinate of the center of the domain.
double Ly() const
Half-width of the computational domain.
double Lx() const
Half-width of the computational domain.
unsigned int My() const
Total grid size in the Y direction.
double x0() const
X-coordinate of the center of the domain.
grid::Registration registration() const
std::shared_ptr< const Context > ctx() const
Return execution context this grid corresponds to.
unsigned int Mx() const
Total grid size in the X direction.
const MappingInfo & get_mapping_info() const
Describes the PISM grid and the distribution of data across processors.
std::string proj_string
a projection definition string in a format recognized by PROJ 6.x+
static MappingInfo FromFile(const File &input_file, const std::string &variable_name, units::System::Ptr unit_system)
Get projection info from a file.
Wrapper around VecGetArray and VecRestoreArray.
void check_input_grid(const grid::InputGridInfo &input_grid, const Grid &internal_grid, const std::vector< double > &internal_z_levels)
Check that x, y, and z coordinates of the input grid are strictly increasing.
void regrid_spatial_variable(const SpatialVariableMetadata &variable, const Grid &target_grid, const LocalInterpCtx &interp_context, const File &file, double *output)
Regrid from a NetCDF file into a distributed array output.
double get_time(MPI_Comm comm)
std::string grid_name(const pism::File &file, const std::string &variable_name, pism::units::System::Ptr sys, bool piecewise_constant)