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"
34#include "pism/util/Config.hh"
38#if (Pism_USE_YAC == 1)
48 if (record_index == -1) {
50 file.
nrecords(metadata.get_name(), metadata[
"standard_name"], metadata.unit_system());
52 record_index = (
int)nrecords - 1;
55 return regrid_impl(metadata, file, record_index, grid, output);
63 const std::vector<double> &levels,
64 const File &input_file,
const std::string &variable_name,
67 auto log = target_grid.
ctx()->log();
68 auto unit_system = target_grid.
ctx()->unit_system();
70 auto name =
grid_name(input_file, variable_name, unit_system,
73 log->message(2,
"* Initializing bi- or tri-linear interpolation from '%s' to the internal grid...\n",
79 input_grid.
report(*log, 4, unit_system);
81 bool allow_extrapolation = target_grid.
ctx()->config()->get_flag(
"grid.allow_extrapolation");
84 m_interp_context = std::make_shared<LocalInterpCtx>(input_grid, target_grid.
info(), levels, type);
91 const Grid &target_grid,
99 context.start[
T_AXIS] = record_index;
102 *target_grid.
ctx()->log(),
111std::shared_ptr<InputInterpolation>
113 const std::vector<double> &levels,
const File &input_file,
116#if (Pism_USE_YAC == 1)
119 input_file, variable_name, target_grid.
ctx()->unit_system())[
"proj_params"];
121 std::string target_projection = target_grid.
get_mapping_info()[
"proj_params"];
124 (levels.size() < 2 and (not source_projection.empty()) and (not target_projection.empty()));
128 if (source_projection == target_projection) {
133 (source_grid.
x.size() == target_grid.
Mx() and source_grid.
y.size() == target_grid.
My());
135 bool center_matches =
136 (source_grid.
x0 == target_grid.
x0() and source_grid.
y0 == target_grid.
y0());
138 bool extent_matches =
139 (source_grid.
Lx == target_grid.
Lx() and source_grid.
Ly == target_grid.
Ly());
141 if (size_matches and center_matches and extent_matches) {
145 double dx_source = source_grid.
x[1] - source_grid.
x[0];
146 double dy_source = source_grid.
y[1] - source_grid.
y[0];
149 if (dx_source < 0 or dy_source < 0) {
155 return std::make_shared<InputInterpolationYAC>(target_grid, input_file, variable_name, type);
160 std::vector<double> fake_levels = { 0.0 };
161 return std::make_shared<InputInterpolation3D>(target_grid, levels.empty() ? fake_levels : levels,
162 input_file, variable_name, type);
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.
const grid::DistributedGridInfo & info() const
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
const VariableMetadata & get_mapping_info() 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.
Describes the PISM grid and the distribution of data across processors.
double Lx
domain half-width in the X direction
std::vector< double > y
y coordinates
double y0
y-coordinate of the domain center
double x0
x-coordinate of the domain center
std::vector< double > x
x coordinates
double Ly
domain half-width in the Y direction
Wrapper around VecGetArray and VecRestoreArray.
void check_input_grid(const grid::InputGridInfo &input_grid, const grid::DistributedGridInfo &internal_grid, const std::vector< double > &internal_z_levels, bool allow_extrapolation)
Check that x, y, and z coordinates of the input grid are strictly increasing.
void regrid_spatial_variable(const VariableMetadata &variable, const Grid &target_grid, const LocalInterpCtx &interp_context, const File &file, const Logger &log, double *output)
Regrid from a NetCDF file into a distributed array output.
double get_time(MPI_Comm comm)
VariableMetadata mapping_info_from_file(const File &input_file, const std::string &variable_name, units::System::Ptr unit_system)
std::string grid_name(const pism::File &file, const std::string &variable_name, pism::units::System::Ptr sys, bool piecewise_constant)