Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
File.hh
Go to the documentation of this file.
1// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2023, 2024 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#ifndef _PISM_FILE_ACCESS_H_
20#define _PISM_FILE_ACCESS_H_
21
22#include <vector>
23#include <string>
24#include <mpi.h>
25
26#include "pism/util/Units.hh"
27
28namespace pism {
29
30enum AxisType : int;
31
32namespace io {
33enum Type : int;
34enum Backend : int;
35enum Mode : int;
36} // namespace io
37
38class Grid;
39
40/*!
41 * Convert a string to PISM's backend type.
42 */
43io::Backend string_to_backend(const std::string &backend);
44
46 bool exists;
47 std::string name;
48};
49
50//! \brief High-level PISM I/O class.
51/*!
52 * Hides the low-level NetCDF wrapper.
53 */
54class File
55{
56public:
57 File(MPI_Comm com, const std::string &filename, io::Backend backend, io::Mode mode);
58 ~File();
59
60 MPI_Comm com() const;
61
62 void close();
63
64 void redef() const;
65
66 void enddef() const;
67
68 void sync() const;
69
70 std::string name() const;
71
72 unsigned int nrecords() const;
73
74 unsigned int nrecords(const std::string &name, const std::string &std_name,
75 units::System::Ptr unit_system) const;
76
77 unsigned int nvariables() const;
78
79 unsigned int nattributes(const std::string &var_name) const;
80
81 // dimensions
82
83 void define_dimension(const std::string &name, size_t length) const;
84
85 unsigned int dimension_length(const std::string &name) const;
86
87 std::vector<std::string> dimensions(const std::string &variable_name) const;
88
89 bool dimension_exists(const std::string &name) const;
90
91 AxisType dimension_type(const std::string &name,
92 units::System::Ptr unit_system) const;
93
94 // variables
95
96 std::string variable_name(unsigned int id) const;
97
98 void define_variable(const std::string &name, io::Type nctype,
99 const std::vector<std::string> &dims) const;
100
101 VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const;
102
103 bool variable_exists(const std::string &short_name) const;
104
105 void read_variable(const std::string &variable_name,
106 const std::vector<unsigned int> &start,
107 const std::vector<unsigned int> &count,
108 double *ip) const;
109
110 void write_variable(const std::string &variable_name,
111 const std::vector<unsigned int> &start,
112 const std::vector<unsigned int> &count,
113 const double *op) const;
114
115 void set_variable_was_written(const std::string &name) const;
116 bool get_variable_was_written(const std::string &name) const;
117
118 void write_distributed_array(const std::string &variable_name,
119 const Grid &grid,
120 unsigned int z_count,
121 bool time_dependent,
122 const double *input) const;
123
124 void set_compression_level(int level) const;
125
126 // attributes
127
128 void remove_attribute(const std::string &variable_name, const std::string &att_name) const;
129
130 std::string attribute_name(const std::string &var_name, unsigned int n) const;
131
132 io::Type attribute_type(const std::string &var_name, const std::string &att_name) const;
133
134 void write_attribute(const std::string &var_name, const std::string &att_name,
135 io::Type nctype, const std::vector<double> &values) const;
136
137 void write_attribute(const std::string &var_name, const std::string &att_name,
138 const std::string &value) const;
139
140 std::vector<double> read_double_attribute(const std::string &var_name,
141 const std::string &att_name) const;
142
143 std::string read_text_attribute(const std::string &var_name, const std::string &att_name) const;
144
145 void append_history(const std::string &history) const;
146private:
147 struct Impl;
149
150 void open(const std::string &filename, io::Mode mode);
151
152 // disable copying and assignments
153 File(const File &other);
154 File & operator=(const File &);
155};
156
157} // end of namespace pism
158
159#endif /* _PISM_FILE_ACCESS_H_ */
bool dimension_exists(const std::string &name) const
Checks if a dimension exists.
Definition File.cc:404
unsigned int nvariables() const
Definition File.cc:742
Impl * m_impl
Definition File.hh:148
void write_distributed_array(const std::string &variable_name, const Grid &grid, unsigned int z_count, bool time_dependent, const double *input) const
Definition File.cc:725
void read_variable(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, double *ip) const
Definition File.cc:699
void define_dimension(const std::string &name, size_t length) const
Definition File.cc:532
std::string attribute_name(const std::string &var_name, unsigned int n) const
Definition File.cc:675
File & operator=(const File &)
AxisType dimension_type(const std::string &name, units::System::Ptr unit_system) const
Get the "type" of a dimension.
Definition File.cc:460
void set_compression_level(int level) const
Definition File.cc:189
void open(const std::string &filename, io::Mode mode)
Definition File.cc:193
void set_variable_was_written(const std::string &name) const
Definition File.cc:767
void redef() const
Definition File.cc:255
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
Definition File.cc:328
void enddef() const
Definition File.cc:265
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
Definition File.cc:280
MPI_Comm com() const
Definition File.cc:185
std::string variable_name(unsigned int id) const
Definition File.cc:755
bool variable_exists(const std::string &short_name) const
Checks if a variable exists.
Definition File.cc:378
void write_variable(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, const double *op) const
Definition File.cc:712
void sync() const
Definition File.cc:246
void close()
Definition File.cc:237
void define_variable(const std::string &name, io::Type nctype, const std::vector< std::string > &dims) const
Define a variable.
Definition File.cc:543
io::Type attribute_type(const std::string &var_name, const std::string &att_name) const
Definition File.cc:687
void remove_attribute(const std::string &variable_name, const std::string &att_name) const
Definition File.cc:228
std::string name() const
Definition File.cc:274
void write_attribute(const std::string &var_name, const std::string &att_name, io::Type nctype, const std::vector< double > &values) const
Write a multiple-valued double attribute.
Definition File.cc:590
std::vector< double > read_double_attribute(const std::string &var_name, const std::string &att_name) const
Get a double attribute.
Definition File.cc:617
bool get_variable_was_written(const std::string &name) const
Definition File.cc:771
unsigned int nattributes(const std::string &var_name) const
Definition File.cc:663
void append_history(const std::string &history) const
Append to the history global attribute.
Definition File.cc:578
unsigned int dimension_length(const std::string &name) const
Get the length of a dimension.
Definition File.cc:420
File(const File &other)
std::vector< std::string > dimensions(const std::string &variable_name) const
Definition File.cc:390
std::string read_text_attribute(const std::string &var_name, const std::string &att_name) const
Get a text attribute.
Definition File.cc:645
High-level PISM I/O class.
Definition File.hh:55
Describes the PISM grid and the distribution of data across processors.
Definition Grid.hh:290
std::shared_ptr< System > Ptr
Definition Units.hh:47
#define n
Definition exactTestM.c:37
AxisType
Definition IO_Flags.hh:33
io::Backend string_to_backend(const std::string &backend)
Definition File.cc:56
std::string name
Definition File.hh:47
int count
Definition test_cube.c:16