PISM, A Parallel Ice Sheet Model 2.3.3-d9dd21c10 committed by Constantine Khrulev on 2026-10-13
Loading...
Searching...
No Matches
io_helpers.hh
Go to the documentation of this file.
1/* Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2023, 2024, 2025, 2026 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef PISM_IO_HELPERS_H
21#define PISM_IO_HELPERS_H
22
23#include <set>
24#include <memory>
25#include <string>
26#include <vector>
27#include <mpi.h>
28
29namespace pism {
30
31namespace units {
32class Unit;
33class System;
34}
35
36class Config;
37class VariableMetadata;
38class Grid;
39class File;
40class Logger;
41
42namespace grid {
43class InputGridInfo;
44class DistributedGridInfo;
45}
46
47class LocalInterpCtx;
48
49class OutputFile;
50
51namespace io {
52
53std::string time_dimension(std::shared_ptr<units::System> unit_system,
54 const File &file,
55 const std::string &variable_name);
56
57void check_input_grid(const grid::InputGridInfo &input_grid,
58 const grid::DistributedGridInfo& internal_grid,
59 const std::vector<double> &internal_z_levels,
60 bool allow_extrapolation);
61
62void regrid_spatial_variable(const VariableMetadata &variable,
63 const Grid& internal_grid,
64 const LocalInterpCtx &lic,
65 const File &file,
66 const Logger &log,
67 double *output);
68
69void read_spatial_variable(const VariableMetadata &variable,
70 const Grid& grid, const File &file,
71 unsigned int time, double *output);
72
73/*!
74 * Read a 1D variable `name` from a `file`, converting data from units in the file to
75 * `units` using `unit_system`.
76 */
77std::vector<double> read_1d_variable(const File &file, const std::string &name,
78 const std::string &units,
79 std::shared_ptr<units::System> unit_system);
80
81std::vector<double> read_timeseries_variable(const File &file, const std::string &variable_name,
82 const std::string &units,
83 std::shared_ptr<units::System> unit_system,
84 size_t start, size_t count);
85
86std::vector<double> read_bounds(const File &file, const std::string &bounds_variable_name,
87 const std::string &units,
88 std::shared_ptr<units::System> unit_system);
89
90struct TimeInfo {
91 std::vector<double> times, bounds;
92};
93
94TimeInfo read_time_info(const units::Unit &time_units, const std::string &calendar, const File &file,
95 const std::string &time_name);
96
97VariableMetadata read_attributes(const File &file, const std::string &variable_name,
98 std::shared_ptr<units::System> unit_system);
99
100void define_variables(const OutputFile &file,
101 const std::set<VariableMetadata> &variables,
102 const VariableMetadata &mapping,
103 bool use_internal_units);
104
105// writing utilities
106
107void write_config(const Config &config, const std::string &variable_name, const OutputFile &file);
108
109void move_if_exists(MPI_Comm com, const std::string &file_to_move, int rank_to_use = 0);
110
111void remove_if_exists(MPI_Comm com, const std::string &file_to_remove, int rank_to_use = 0);
112
113} // end of namespace io
114} // end of namespace pism
115
116#endif /* PISM_IO_HELPERS_H */
A class for storing and accessing PISM configuration flags and parameters.
Definition Config.hh:56
High-level PISM I/O class.
Definition File.hh:57
Describes the PISM grid and the distribution of data across processors.
Definition Grid.hh:285
A basic logging class.
Definition Logger.hh:40
std::vector< double > read_timeseries_variable(const File &file, const std::string &variable_name, const std::string &units, std::shared_ptr< units::System > unit_system, size_t start, size_t count)
void read_spatial_variable(const VariableMetadata &variable, const Grid &grid, const File &file, unsigned int time, double *output)
Read a variable from a file into an array output.
VariableMetadata read_attributes(const File &file, const std::string &variable_name, std::shared_ptr< units::System > unit_system)
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.
std::vector< double > read_1d_variable(const File &file, const std::string &variable_name, const std::string &units, std::shared_ptr< units::System > unit_system)
void write_config(const Config &config, const std::string &variable_name, const OutputFile &file)
void move_if_exists(MPI_Comm com, const std::string &file_to_move, int rank_to_use=0)
Moves the file aside (file.nc -> file.nc~).
void define_variables(const OutputFile &file, const std::set< VariableMetadata > &variables, const VariableMetadata &mapping, bool use_internal_units)
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.
std::vector< double > read_bounds(const File &file, const std::string &bounds_variable_name, const std::string &internal_units, std::shared_ptr< units::System > unit_system)
void remove_if_exists(MPI_Comm com, const std::string &file_to_remove, int rank_to_use=0)
Check if a file is present are remove it.
std::string time_dimension(units::System::Ptr unit_system, const File &file, const std::string &variable_name)
TimeInfo read_time_info(const units::Unit &time_units, const std::string &calendar, const File &file, const std::string &time_name)
static std::string calendar(const File *input_file, const Config &config, const Logger &log)
Definition Time.cc:158
std::shared_ptr< Grid > grid(std::shared_ptr< Context > ctx)
Definition pism.cc:173
std::vector< double > times
Definition io_helpers.hh:91
std::vector< double > bounds
Definition io_helpers.hh:91
int count
Definition test_cube.c:16