PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
IO_Flags.hh
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2018, 2019, 2020, 2023, 2024, 2025 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_FLAGS_H
21#define PISM_IO_FLAGS_H
22
23#include <string>
24
25namespace pism {
26
27/*!
28 * Axis corresponding to dimensions (and coordinate variables) in a NetCDF file.
29 *
30 * Values of T_AXIS, X_AXIS, Y_AXIS, Z_AXIS are also used as indexes
31 * in `start` and `count` arrays -- this is why they have consecutive values
32 * starting from 0.
33 */
34enum AxisType : int { T_AXIS = 0, X_AXIS = 1, Y_AXIS = 2, Z_AXIS = 3, UNKNOWN_AXIS = 4, EXP_ID_AXIS = 5 };
35
36AxisType axis_type_from_string(const std::string &input);
37
38namespace io {
39
40// I/O Flags used by File and NCFile. They are used in both interfaces,
41// but I want to be able to create Python wrappers for File without
42// exposing NCFile, and NCFile should compile without File, so it does
43// not belong in either File.hh or NCFile.hh.
44
45// This is a subset of NetCDF data-types.
46enum Type : int {
47 PISM_NAT = 0, /* NAT = 'Not A Type' (c.f. NaN) */
48 PISM_BYTE = 1, /* signed 1 byte integer */
49 PISM_CHAR = 2, /* ISO/ASCII character */
50 PISM_SHORT = 3, /* signed 2 byte integer */
51 PISM_INT = 4, /* signed 4 byte integer */
52 PISM_FLOAT = 5, /* single precision floating point number */
53 PISM_DOUBLE = 6 /* double precision floating point number */
54};
55
63
64// This is a subset of NetCDF file modes. Use values that don't match
65// NetCDF flags so that we can detect errors caused by passing these
66// straight to NetCDF.
67enum Mode : int {
68 //! open an existing file for reading only
70 //! open an existing file for reading and writing
72 //! create a file for writing, overwrite if present
74 //! create a file for writing, move foo.nc to foo.nc~ if present
76};
77
78// This is the special value corresponding to the "unlimited" dimension length.
79// Gets cast to "int", so it should match the value used by NetCDF.
80enum Dim_Length : int { PISM_UNLIMITED = 0 };
81
82// "Fill" mode. Gets cast to "int", so it should match values used by NetCDF.
83enum Fill_Mode : int { PISM_FILL = 0, PISM_NOFILL = 0x100 };
84
85/*!
86 * Default value to use when a regridding variable is not found.
87 */
88class Default {
89public:
90
91 /*!
92 * No default value: stop if the variable was not found.
93 */
94 static Default Nil() {
95 return {};
96 }
97
98 /*!
99 * Use this default value if the variable was not found.
100 */
101 Default(double v) {
102 m_exists = true;
103 m_value = v;
104 }
105
106 /*!
107 * True if the default value exists.
108 */
109 bool exists() const {
110 return m_exists;
111 }
112
113 /*!
114 * Convert the default value to `double`.
115 */
116 operator double() const {
117 return m_value;
118 }
119
120private:
122 m_exists = false;
123 m_value = 0;
124 }
125 double m_value;
127};
128
129} // namespace io
130
131} // end of namespace pism
132
133#endif /* PISM_IO_FLAGS_H */
static Default Nil()
Definition IO_Flags.hh:94
bool exists() const
Definition IO_Flags.hh:109
Default(double v)
Definition IO_Flags.hh:101
@ PISM_GUESS
Definition IO_Flags.hh:57
@ PISM_NETCDF3
Definition IO_Flags.hh:58
@ PISM_PNETCDF
Definition IO_Flags.hh:61
@ PISM_NETCDF4_PARALLEL
Definition IO_Flags.hh:60
@ PISM_NETCDF4_SERIAL
Definition IO_Flags.hh:59
@ PISM_READWRITE_CLOBBER
create a file for writing, overwrite if present
Definition IO_Flags.hh:73
@ PISM_READWRITE_MOVE
create a file for writing, move foo.nc to foo.nc~ if present
Definition IO_Flags.hh:75
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
@ PISM_READWRITE
open an existing file for reading and writing
Definition IO_Flags.hh:71
@ PISM_UNLIMITED
Definition IO_Flags.hh:80
@ PISM_SHORT
Definition IO_Flags.hh:50
@ PISM_FLOAT
Definition IO_Flags.hh:52
@ PISM_DOUBLE
Definition IO_Flags.hh:53
@ PISM_BYTE
Definition IO_Flags.hh:48
@ PISM_CHAR
Definition IO_Flags.hh:49
@ PISM_FILL
Definition IO_Flags.hh:83
@ PISM_NOFILL
Definition IO_Flags.hh:83
AxisType
Definition IO_Flags.hh:34
@ UNKNOWN_AXIS
Definition IO_Flags.hh:34
@ T_AXIS
Definition IO_Flags.hh:34
@ X_AXIS
Definition IO_Flags.hh:34
@ EXP_ID_AXIS
Definition IO_Flags.hh:34
@ Z_AXIS
Definition IO_Flags.hh:34
@ Y_AXIS
Definition IO_Flags.hh:34
AxisType axis_type_from_string(const std::string &input)
Definition File.cc:436