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
pism_type_conversion.hh
Go to the documentation of this file.
1// Copyright (C) 2012, 2014, 2015, 2016, 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#include <netcdf.h>
20
21#include "pism/util/io/IO_Flags.hh"
22
23//! Convert PISM's IO types into NetCDF types and back. Note that NC_* may be
24//! macros, so you need to include the appropriate NetCDF header first.
25namespace pism {
26
27static nc_type pism_type_to_nc_type(pism::io::Type input) {
28 switch (input) {
29 case io::PISM_BYTE:
30 return NC_BYTE;
31 case io::PISM_CHAR:
32 return NC_CHAR;
33 case io::PISM_SHORT:
34 return NC_SHORT;
35 case io::PISM_INT:
36 return NC_INT;
37 case io::PISM_FLOAT:
38 return NC_FLOAT;
39 case io::PISM_DOUBLE:
40 return NC_DOUBLE;
41 default:
42 return NC_NAT;
43 }
44}
45
47 switch (input) {
48 case NC_BYTE:
49 return io::PISM_BYTE;
50 case NC_CHAR:
51 case NC_STRING: // treat NC_CHAR and NC_STRING as equivalent
52 return io::PISM_CHAR;
53 case NC_SHORT:
54 return io::PISM_SHORT;
55 case NC_INT:
56 return io::PISM_INT;
57 case NC_FLOAT:
58 return io::PISM_FLOAT;
59 case NC_DOUBLE:
60 return io::PISM_DOUBLE;
61 default:
62 return io::PISM_NAT;
63 }
64}
65
66} // end of namespace pism
@ PISM_SHORT
Definition IO_Flags.hh:49
@ PISM_FLOAT
Definition IO_Flags.hh:51
@ PISM_DOUBLE
Definition IO_Flags.hh:52
@ PISM_BYTE
Definition IO_Flags.hh:47
@ PISM_CHAR
Definition IO_Flags.hh:48
static pism::io::Type nc_type_to_pism_type(int input)
static nc_type pism_type_to_nc_type(pism::io::Type input)