XMLIOSERVER 0.4
Serveur d'Entrées/Sorties parallèles
|
00001 /* ************************************************************************** * 00002 * Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011 * 00003 * ************************************************************************** */ 00004 00005 #ifndef __ONETCDF4_HPP__ 00006 #define __ONETCDF4_HPP__ 00007 00008 #ifndef __XIOS_NO_EXTERN 00009 00010 // M(essage) P(assing) I(nterface) headers 00011 #include <mpi.h> 00012 00013 // NetCDF headers 00014 #define MPI_INCLUDED 00015 #include <netcdf.h> 00016 extern "C" { 00017 #include <netcdf_par.h> 00018 } 00019 00020 // C++ standard headers 00021 #include <vector> 00022 00023 // boost Headers 00024 #include <boost/multi_array.hpp> 00025 #include <boost/optional.hpp> 00026 00027 #endif // __XIOS_NO_EXTERN 00028 00029 // XMLIOServer headers 00030 #include "xmlioserver_spl.hpp" 00031 00032 #ifndef UNLIMITED_DIM 00033 #define UNLIMITED_DIM (size_t)(-1) 00034 #endif //UNLIMITED_DIM 00035 00036 // ////////////////////////////// Déclarations ///////////////////////////// // 00037 00038 namespace xmlioserver 00039 { 00040 namespace io 00041 { 00046 class CONetCDF4 00047 { 00048 public : // Définition de type 00049 00051 typedef std::vector<std::string> CNetCDF4Path; 00052 00053 public : // Constructeurs 00054 00056 CONetCDF4(void); // NIY 00057 00062 explicit CONetCDF4(const std::string & _filename, bool exist = false, 00063 const MPI_Comm * _comm_server = NULL); 00064 00069 CONetCDF4(const CONetCDF4 & _onetcdf4);// NIY 00070 00075 CONetCDF4(const CONetCDF4 * const _onetcdf4_ptr); // NIY 00076 00077 public : // Destructeur 00078 00080 virtual ~CONetCDF4(void); 00081 00082 public : // Mutateur 00083 00084 void setCurrentPath(const CNetCDF4Path & _path); 00085 00086 int addDimension(const std::string & _name, std::size_t _size = UNLIMITED_DIM); 00087 int addVariable (const std::string & _name, nc_type _type, 00088 const std::vector<std::string> & _dims); 00089 int addGroup (const std::string & _name); 00090 00091 public : // Accesseurs 00092 00093 const CNetCDF4Path & getCurrentPath(void) const; 00094 00095 std::string getUnlimitedDimensionName(void); 00096 std::vector<std::string> getDimensionsIdList (const std::string * _varname); 00097 00098 protected : // Accesseurs protégés 00099 00106 int getCurrentGroup(void); 00107 00122 int getGroup(const CNetCDF4Path & _path); 00123 00129 int getVariable(const std::string & _varname); 00130 00136 int getDimension(const std::string & _dimname); 00137 00143 std::vector<std::size_t> getDimensions(const std::string & _varname); 00144 00149 int getUnlimitedDimension(void); 00150 00156 bool varExist(const std::string & _varname); 00157 00158 public : // Ecriture 00159 00160 template <class DataType> 00161 void writeAttribute 00162 (const std::string & _attname, 00163 const std::vector<DataType> & _value, 00164 const std::string * _varname = NULL); 00165 00166 void writeAttribute 00167 (const std::string & _attname, 00168 const std::string & _value, 00169 const std::string * _varname = NULL); 00170 00171 template <class DataType, std::size_t ndim> 00172 void writeData( const boost::multi_array<DataType, ndim> & _data, 00173 const std::string & _varname, 00174 std::size_t _record = 0, 00175 bool _collective = true, 00176 const std::vector<std::size_t> * _start = NULL, 00177 const std::vector<std::size_t> * _count = NULL); 00178 00179 private : // Ecriture privée 00180 00181 template <class DataType> 00182 void writeData_(int _grpid, 00183 int _varid, 00184 const std::vector<std::size_t> & _sstart, 00185 const std::vector<std::size_t> & _scount, 00186 const DataType * _data); 00187 00188 template <class DataType> 00189 void writeAttribute_ 00190 (const std::string & _attname, 00191 const DataType * _value, 00192 std::size_t _size, 00193 int _grpid, 00194 int _varid = NC_GLOBAL); 00195 00196 private : // Obtention des informations d'écriture 00197 00198 void getWriteDataInfos(const std::string & _varname, 00199 std::size_t _record, 00200 std::size_t & _array_size, 00201 std::vector<std::size_t> & _sstart, 00202 std::vector<std::size_t> & _scount, 00203 const std::vector<std::size_t> * _start, 00204 const std::vector<std::size_t> * _count); 00205 00206 public : // Début/Fin de définition 00207 00208 void definition_start(void); 00209 void definition_end(void); 00210 00211 private : // Vérification des erreurs NetCDF 00212 00213 static void CheckError(int _status) throw (CException); 00214 00215 public : // Propriétés privées 00216 00217 boost::optional<MPI_Comm> comm_server; 00218 std::vector<std::string> path; 00219 int ncidp; 00220 00221 }; // class CONetCDF4 00222 00223 } // namespace io 00224 00225 } // namespace xmlioserver 00226 00227 #endif// __ONETCDF4_HPP__