tio_helpers.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
 (HTM) git clone git://src.adamsgaard.dk/pism
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tio_helpers.hh (5053B)
       ---
            1 /* Copyright (C) 2015, 2016, 2017, 2018, 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 
           20 #ifndef _IO_HELPERS_H_
           21 #define _IO_HELPERS_H_
           22 
           23 #include <string>
           24 #include <vector>
           25 #include <mpi.h>
           26 
           27 #include "IO_Flags.hh"
           28 #include "pism/util/Units.hh"
           29 #include "pism/util/interpolation.hh"
           30 
           31 namespace pism {
           32 
           33 class VariableMetadata;
           34 class SpatialVariableMetadata;
           35 class TimeseriesMetadata;
           36 class TimeBoundsMetadata;
           37 class IceGrid;
           38 class File;
           39 class Time;
           40 class Logger;
           41 class Context;
           42 class Config;
           43 
           44 namespace io {
           45 
           46 void regrid_spatial_variable(SpatialVariableMetadata &var,
           47                              const IceGrid& grid, const File &nc,
           48                              RegriddingFlag flag, bool do_report_range,
           49                              bool allow_extrapolation,
           50                              double default_value,
           51                              InterpolationType type,
           52                              double *output);
           53 
           54 void regrid_spatial_variable(SpatialVariableMetadata &var,
           55                              const IceGrid& grid, const File &nc,
           56                              unsigned int t_start,
           57                              RegriddingFlag flag, bool do_report_range,
           58                              bool allow_extrapolation,
           59                              double default_value,
           60                              InterpolationType type,
           61                              double *output);
           62 
           63 void read_spatial_variable(const SpatialVariableMetadata &var,
           64                            const IceGrid& grid, const File &nc,
           65                            unsigned int time, double *output);
           66 
           67 void write_spatial_variable(const SpatialVariableMetadata &var,
           68                             const IceGrid& grid, const File &nc,
           69                             const double *input);
           70 
           71 void define_dimension(const File &nc, unsigned long int length,
           72                       const VariableMetadata &metadata);
           73 
           74 void define_time(const File &file, const Context &ctx);
           75 
           76 void define_time(const File &nc, const std::string &name, const std::string &calendar,
           77                  const std::string &units, units::System::Ptr unit_system);
           78 
           79 void append_time(const File &file, const Config &ctx, double time_seconds);
           80 void append_time(const File &nc, const std::string &name, double time_seconds);
           81 
           82 void define_spatial_variable(const SpatialVariableMetadata &var,
           83                              const IceGrid &grid, const File &nc,
           84                              IO_Type nctype);
           85 
           86 void define_timeseries(const TimeseriesMetadata& var,
           87                        const File &nc, IO_Type nctype);
           88 
           89 void define_time_bounds(const TimeBoundsMetadata& var,
           90                         const File &nc, IO_Type nctype = PISM_DOUBLE);
           91 
           92 void read_timeseries(const File &nc, const TimeseriesMetadata &metadata,
           93                      const Time &time, const Logger &log, std::vector<double> &data);
           94 
           95 void write_timeseries(const File &nc, const TimeseriesMetadata &metadata,
           96                       size_t t_start, const std::vector<double> &data,
           97                       IO_Type nctype = PISM_DOUBLE);
           98 
           99 void write_timeseries(const File &nc, const TimeseriesMetadata &metadata,
          100                       size_t t_start, double data,
          101                       IO_Type nctype = PISM_DOUBLE);
          102 
          103 void read_time_bounds(const File &nc,
          104                       const TimeBoundsMetadata &metadata,
          105                       const Time &time, const Logger &log, std::vector<double> &data);
          106 
          107 void write_time_bounds(const File &nc, const TimeBoundsMetadata &metadata,
          108                        size_t t_start, const std::vector<double> &data,
          109                        IO_Type nctype = PISM_DOUBLE);
          110 
          111 std::string time_dimension(units::System::Ptr unit_system,
          112                            const File &file,
          113                            const std::string &variable_name);
          114 
          115 void read_attributes(const File &nc, const std::string &variable_name, VariableMetadata &variable);
          116 
          117 void write_attributes(const File &nc, const VariableMetadata &variable, IO_Type nctype);
          118 
          119 void read_valid_range(const File &nc, const std::string &name, VariableMetadata &variable);
          120 
          121 bool file_exists(MPI_Comm com, const std::string &filename);
          122 
          123 void move_if_exists(MPI_Comm com, const std::string &file_to_move, int rank_to_use = 0);
          124 
          125 void remove_if_exists(MPI_Comm com, const std::string &file_to_remove, int rank_to_use = 0);
          126 
          127 } // end of namespace io
          128 } // end of namespace pism
          129 
          130 #endif /* _IO_HELPERS_H_ */