moab
|
00001 #ifndef READGCRM_HPP 00002 #define READGCRM_HPP 00003 00004 #ifndef IS_BUILDING_MB 00005 //#error "ReadNC.hpp isn't supposed to be included into an application" 00006 #endif 00007 00008 #include <vector> 00009 #include <map> 00010 #include <string> 00011 00012 #include "moab/Forward.hpp" 00013 #include "moab/ReaderIface.hpp" 00014 #include "moab/Range.hpp" 00015 #include "moab/ScdInterface.hpp" 00016 #include "DebugOutput.hpp" 00017 00018 #ifdef USE_MPI 00019 # include "moab_mpi.h" 00020 # include "moab/ParallelComm.hpp" 00021 #endif 00022 00023 #ifdef PNETCDF_FILE 00024 # include "pnetcdf.h" 00025 # define NCFUNC(func) ncmpi_ ## func 00026 # define NCFUNCA(func) ncmpi_ ## func ## _all 00027 // keep it this way , introduce another macro, used so far only for ucd mesh 00028 //# define NCASYNCH 00029 # ifdef NCASYNCH 00030 # define NCREQ , &requests[j] 00031 # define NCFUNCAG(func) ncmpi_iget ## func 00032 # define NCWAIT 00033 # else 00034 # define NCREQ2 , &requests[idxReq++] 00035 # define NCFUNCAG2(func) ncmpi_iget ## func 00036 # define NCREQ 00037 # define NCFUNCAG(func) ncmpi_get ## func ## _all 00038 # endif 00039 # define NCDF_SIZE MPI_Offset 00040 # define NCDF_DIFF MPI_Offset 00041 #else 00042 # include "netcdf.h" 00043 #define NCREQ 00044 #define NCGET get 00045 # define NCFUNC(func) nc_ ## func 00046 # define NCFUNCA(func) nc_ ## func 00047 # define NCFUNCAG(func) nc_get ## func 00048 # define NCDF_SIZE size_t 00049 # define NCDF_DIFF ptrdiff_t 00050 #endif 00051 00052 namespace moab { 00053 00054 class ReadUtilIface; 00055 00066 class ReadGCRM : public ReaderIface 00067 { 00068 00069 public: 00070 00072 static ReaderIface* factory( Interface* ); 00073 00074 virtual ErrorCode load_file( const char* file_name, 00075 const EntityHandle* file_set, 00076 const FileOptions& opts, 00077 const SubsetList* subset_list = 0, 00078 const Tag* file_id_tag = 0 ); 00079 00080 virtual ErrorCode read_tag_values( const char* file_name, 00081 const char* tag_name, 00082 const FileOptions& opts, 00083 std::vector<int>& tag_values_out, 00084 const SubsetList* subset_list = 0 ); 00085 00087 ReadGCRM(Interface* impl = NULL); 00088 00090 virtual ~ReadGCRM(); 00091 00092 // ENTLOCNSEDGE for north/south edge 00093 // ENTLOCWEEDGE for west/east edge 00094 enum EntityLocation {ENTLOCNODE=0, ENTLOCNSEDGE, ENTLOCEWEDGE, ENTLOCQUAD, ENTLOCSET}; 00095 00096 private: 00097 00103 ErrorCode read_vertices(int num_verts, EntityHandle &start_vertex, Range &read_ents); 00104 00111 ErrorCode read_elements(int num_elems, EntityHandle start_vertex, 00112 EntityHandle &start_elem, Range &read_ents); 00113 00122 ErrorCode create_sets(int num_sets, EntityHandle start_vertex, int num_verts, 00123 EntityHandle start_elem, int num_elems, Range &read_ents); 00124 00125 00129 ErrorCode process_options(const FileOptions &opts); 00130 00131 void reset(); 00132 00134 ErrorCode read_header(); 00135 00136 class AttData 00137 { 00138 public: 00139 AttData() : attId(-1), attLen(0), attVarId(-2) {} 00140 int attId; 00141 NCDF_SIZE attLen; 00142 int attVarId; 00143 nc_type attDataType; 00144 std::string attName; 00145 }; 00146 00147 class VarData 00148 { 00149 public: 00150 VarData() : varId(-1), numAtts(-1), read(false), entLoc(ENTLOCSET), numLev(1), sz(0), has_t(false) {} 00151 int varId; 00152 int numAtts; 00153 nc_type varDataType; 00154 std::vector<int> varDims; // the dimension indices making up this multi-dimensional variable 00155 std::map<std::string,AttData> varAtts; 00156 std::string varName; 00157 bool read; 00158 std::vector<Tag> varTags; // one tag for each timestep, varTags[t] 00159 std::vector<void*> varDatas; 00160 std::vector<std::vector<NCDF_SIZE> > readDims; // start value for this [t][dim] 00161 std::vector<std::vector<NCDF_SIZE> > readCounts; // number of data values for this [t][dim] 00162 int entLoc; 00163 int numLev; 00164 int sz; 00165 bool has_t; 00166 }; 00167 00169 ErrorCode get_attributes(int var_id, int num_atts, std::map<std::string,AttData> &atts, 00170 const char *prefix=""); 00171 00173 ErrorCode get_dimensions(int file_id, std::vector<std::string> &dim_names, std::vector<int> &dim_vals); 00174 00176 ErrorCode get_variables(); 00177 00179 unsigned int number_dimensions(); 00180 00181 ErrorCode get_tag(VarData &var_data, int tstep_num, Tag &tagh, int num_lev); 00182 00188 ErrorCode create_attrib_string(const std::map<std::string, AttData>& attMap, 00189 std::string& attString, 00190 std::vector<int>& attLen); 00191 00192 ErrorCode create_tags(ScdInterface *scdi, EntityHandle file_set, const std::vector<int>& tstep_nums); 00193 00194 ReadUtilIface* readMeshIface; 00195 00196 int CPU_WORD_SIZE; 00197 int IO_WORD_SIZE; 00198 00200 Interface* mbImpl; 00201 00202 const char *fileName; 00203 00205 int fileId, connectId; 00206 00208 std::vector<std::string> dimNames; 00209 std::vector<int> dimVals; 00210 00212 std::map<std::string,AttData> globalAtts; 00213 00215 std::map<std::string,VarData> varInfo; 00216 00217 int tMin, tMax; 00218 00220 std::vector<double> tVals; 00221 00223 int tDim; 00224 00226 int numUnLim; 00227 00229 EntityHandle mCurrentMeshHandle; 00230 00232 EntityHandle startVertex, startElem; 00233 00236 Tag mGlobalIdTag; 00237 00238 int max_line_length, max_str_length; 00239 00241 Range initRange; 00242 00244 int vertexOffset; 00245 00247 DebugOutput dbgOut; 00248 00250 int partMethod; 00251 00253 bool isParallel; 00254 00255 #ifdef USE_MPI 00256 ParallelComm *myPcomm; 00257 #endif 00258 00259 }; 00260 00261 inline unsigned int ReadGCRM::number_dimensions() 00262 { 00263 return dimVals.size(); 00264 } 00265 00266 } // namespace moab 00267 00268 #endif