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