URI: 
       tFile.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
  HTML git clone git://src.adamsgaard.dk/pism
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tFile.hh (4948B)
       ---
            1 // Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 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 #include "pism/util/io/IO_Flags.hh"
           28 
           29 namespace pism {
           30 
           31 enum AxisType {X_AXIS, Y_AXIS, Z_AXIS, T_AXIS, UNKNOWN_AXIS};
           32 
           33 class IceGrid;
           34 
           35 /*!
           36  * Convert a string to PISM's backend type.
           37  */
           38 IO_Backend string_to_backend(const std::string &backend);
           39 
           40 struct VariableLookupData {
           41   bool exists;
           42   bool found_using_standard_name;
           43   std::string name;
           44 };
           45 
           46 //! \brief High-level PISM I/O class.
           47 /*!
           48  * Hides the low-level NetCDF wrapper.
           49  */
           50 class File
           51 {
           52 public:
           53   File(MPI_Comm com, const std::string &filename, IO_Backend backend, IO_Mode mode,
           54        int iosysid = -1);
           55   ~File();
           56 
           57   IO_Backend backend() const;
           58 
           59   MPI_Comm com() const;
           60 
           61   void close();
           62 
           63   void redef() const;
           64 
           65   void enddef() const;
           66 
           67   void sync() const;
           68 
           69   std::string filename() const;
           70 
           71   unsigned int nrecords() const;
           72 
           73   unsigned int nrecords(const std::string &name, const std::string &std_name,
           74                         units::System::Ptr unit_system) const;
           75 
           76   unsigned int nvariables() const;
           77 
           78   unsigned int nattributes(const std::string &var_name) const;
           79 
           80   // dimensions
           81 
           82   void define_dimension(const std::string &name, size_t length) const;
           83 
           84   unsigned int dimension_length(const std::string &name) const;
           85 
           86   std::vector<std::string> dimensions(const std::string &variable_name) const;
           87 
           88   bool find_dimension(const std::string &name) const;
           89 
           90   AxisType dimension_type(const std::string &name,
           91                           units::System::Ptr unit_system) const;
           92 
           93   std::vector<double> read_dimension(const std::string &name) const;
           94 
           95   // variables
           96 
           97   std::string variable_name(unsigned int id) const;
           98 
           99   void define_variable(const std::string &name, IO_Type nctype,
          100                        const std::vector<std::string> &dims) const;
          101 
          102   VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const;
          103 
          104   bool find_variable(const std::string &short_name) const;
          105 
          106   void read_variable(const std::string &variable_name,
          107                        const std::vector<unsigned int> &start,
          108                        const std::vector<unsigned int> &count,
          109                        double *ip) const;
          110 
          111   void read_variable_transposed(const std::string &variable_name,
          112                                 const std::vector<unsigned int> &start,
          113                                 const std::vector<unsigned int> &count,
          114                                 const std::vector<unsigned int> &imap, double *ip) const;
          115 
          116   void write_variable(const std::string &variable_name,
          117                       const std::vector<unsigned int> &start,
          118                       const std::vector<unsigned int> &count,
          119                       const double *op) const;
          120 
          121   void write_distributed_array(const std::string &variable_name,
          122                                const IceGrid &grid,
          123                                unsigned int z_count,
          124                                const double *input) 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;
          146 private:
          147   struct Impl;
          148   Impl *m_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_ */