00001 #ifndef _MY_HDF5Writer_
00002 #define _MY_HDF5Writer_
00003
00004 #include <string>
00005 #include <ext/hash_map>
00006 #include "stringhashfun.h"
00007 #include <grid/tria.h>
00008 #include <hdf5.h>
00009 #include "globals.h"
00010 #include "float.h"
00011 #include "vecdouble.h"
00012
00013
00014
00015
00016 using std::string;
00017
00022 class HDF5Writer
00023 {
00024
00025 protected:
00026 enum TriaType {UNSTRUCTURED_GRID,STRUCTURED_GRID};
00027
00028
00029 struct FieldInformation
00030 {
00031 unsigned refCount;
00032 double min,max;
00033
00034 FieldInformation()
00035 {
00036 min=+DBL_MAX;
00037 max=-DBL_MAX;
00038 refCount=0;
00039 }
00040 void updateMinMaxValues(double newMin,double newMax)
00041 {
00042 if (newMin < min)
00043 min=newMin;
00044 if (newMax > max)
00045 max=newMax;
00046 }
00047 };
00048
00050 struct TriaInformation
00051 {
00052 unsigned n_vertices,n_cells,type;
00053 std::vector<hsize_t> *vI;
00054
00055 TriaInformation(int vert,int cells,int typeId=UNSTRUCTURED_GRID):n_vertices(vert),n_cells(cells),type(typeId),vI(NULL){}
00056 TriaInformation(){vI=NULL;}
00057 void setActiveVertices(std::vector<hsize_t> &p)
00058 {
00059 assert(vI == NULL);
00060 vI=new std::vector<hsize_t>(p);
00061 }
00062 std::vector<hsize_t>& getActiveVertices()
00063 {
00064 assert(vI != NULL);
00065 return *vI;
00066 }
00067 bool isCollapsed()
00068 {
00069 return vI != NULL;
00070 }
00071
00072 };
00073 private:
00074
00075 hid_t m_file;
00077 typedef __gnu_cxx::hash_map<string,struct TriaInformation,StringHashFun,struct eqstr> TriaHeap;
00078 typedef __gnu_cxx::hash_map<string,struct FieldInformation,StringHashFun,struct eqstr> FieldInfoHeap;
00079
00080 Dictionary varsHeap;
00081 TriaHeap triaHeap;
00082 FieldInfoHeap fieldInfo;
00084 string m_strFileName;
00085 string m_lastTriaName;
00088 protected:
00089 TriaInformation& getTriaInformation(string strName);
00090 void writeInChunks(hid_t dataset, hsize_t offset[], hsize_t count[],void *buff);
00091 typedef Dictionary::const_iterator VariableIterator;
00092
00093 FieldInformation& getFieldInfo(std::string fileName) {return fieldInfo[fileName];}
00094 void writeContextVariables(std::string dataSetPath);
00095 void validateField(string triaId, string fieldName);
00096 std::string getNameOfLastRegisteredTriangulation() {return m_lastTriaName;}
00097 int getFieldCount(string fieldName);
00098 void incFieldCount(string fieldName);
00099 VariableIterator getVariablesIterator();
00100 VariableIterator getVariablesEnd();
00101 void appendMeshInfo(string triaId,struct TriaInformation info);
00102 void putMeshIntoDictionary(string triaId,unsigned verts,unsigned cells);
00103 public:
00104 HDF5Writer();
00105 ~HDF5Writer();
00106 hid_t getFile(){assert(m_file != -1);return m_file;}
00107 void setVariable(std::string var, std::string value);
00108 void setVariable(std::string var, double dValue);
00109 void setOutputFile(string strFileName);
00110 void close();
00111 bool existTriaInformation(string strName);
00112 void setAtt(string objPath,string attName,string value);
00113 void setAtt(string objPath,string attName,double dValue);
00114 void writeInt(string objPath,string attName,int i);
00115 void writeGrp(string grpName);
00116 std::string getVariableValue(std::string var);
00117 std::string getFileName(){return m_strFileName;}
00118 };
00119
00120
00121
00122 #endif