src/hdf5/H5ecloud/ORG/H5Part++.hh

Go to the documentation of this file.
00001 #ifndef _H5Part_HH_
00002 #define _H5Part_HH_
00003 
00004 extern "C" {
00005 #include "H5Part.h"
00006 #ifdef PARALLEL_IO
00007 #include <mpi.h>
00008 #endif
00009 }
00010 
00011 /* Add any C++ specific extensions/implementations/wrappers here */
00012 
00013 /* here is a sample class wrapping of H5Part for C++ usage */
00014 
00015 class H5ParticleFile {
00016   H5PartFile *file;
00017   long long np;
00018 public:
00019   H5ParticleFile(const char *filename,const int flags):np(0){
00020     this->file=H5PartOpenFile(filename,flags);
00021   }
00022 
00023   //  H5ParticleFile(const std::string fn,const int flags):np(0){
00024   //  this->file=H5PartOpenFile(fn.cstr(),flags);
00025   //}
00026 
00027 #ifdef PARALLEL_IO  
00028   H5ParticleFile(const char *filename,const int flags,const MPI_Comm comm):np(0){
00029     this->file=H5PartOpenFileParallel(filename,flags,comm);
00030   }
00031   //  H5ParticleFile(const string fn,const int flags,const MPI_Comm comm):np(0){
00032   //  this->file=H5PartOpenFile(fn.cstr(),flags,comm);
00033   //}
00034 #endif
00035   inline int isValid() { return H5PartFileIsValid(this->file);}
00036 
00037   ~H5ParticleFile(){H5PartCloseFile(this->file);}
00038   
00039   inline void setNumParticles(long long nparticles){
00040     np=nparticles;
00041     H5PartSetNumParticles(file,nparticles);
00042   }
00043   // get the current step (-1 means step is invalid)
00044   inline int step(){ return file->timestep; }
00045   // set the current step
00046   inline int step(int s){ H5PartSetStep(this->file,s); return file->timestep; }
00047   inline int nSteps(){ return H5PartGetNumSteps(this->file);}
00048   inline int nFields(){ return H5PartGetNumDatasets(file);}
00049   inline int fieldName(int index,char *name,int maxlen){H5PartGetDatasetName(file,index,name,maxlen);}
00050   inline long long nParticles(){return H5PartGetNumParticles(file);}
00051   inline int write(char *name,double *array){
00052     return H5PartWriteDataFloat64(this->file,name,array);
00053   }
00054   inline int write(char *name,long long *array){
00055     return H5PartWriteDataInt64(this->file,name,array);
00056   }
00057   inline int read(char *name,double *array){
00058     return H5PartReadDataFloat64(this->file,name,array);
00059   }
00060   inline int read(char *name,long long *array){
00061     return H5PartReadDataInt64(this->file,name,array);
00062   }
00063   inline int readStep(int step,
00064                double *x,double *y,double *z,
00065                double *px,double *py,double *pz,
00066                long long *id){
00067     return H5PartReadParticleStep(file,step,
00068                                   x,y,z,
00069                                   px,py,pz,
00070                                   id);
00071   }
00072 
00073   // Attribute stuff
00074   // Info on attributes
00075   inline int nStepAttribs(){ return H5PartGetNumStepAttribs(file);}
00076   inline void getStepAttribInfo(int idx,char *name,size_t maxsize,
00077                          hid_t &type,int &nelem){
00078     H5PartGetStepAttribInfo(file,idx,name,maxsize,&type,&nelem);
00079   }
00080   inline int nFileAttribs(){ return H5PartGetNumFileAttribs(file);}
00081   inline void getFileAttribInfo(int idx,char *name,size_t maxsize,
00082                          hid_t &type,int &nelem){
00083     H5PartGetFileAttribInfo(file,idx,name,maxsize,&type,&nelem);
00084   }
00085   // step attribs
00086   // int writeStepAttrib(char *key,string *valuestring){
00087   //   return H5PartWriteStepAttribString(file,key,valuestring.c_str());
00088   //}
00089   inline int writeStepAttrib(char *key,char *valuestring){
00090     return H5PartWriteStepAttribString(file,key,valuestring);
00091   }
00092   inline int writeStepAttrib(char *key,double *value,int nelem=1){
00093     return H5PartWriteStepAttrib(file,key,H5T_NATIVE_DOUBLE,value,nelem);
00094   }
00095   inline int writeStepAttrib(char *key,float *value,int nelem=1){
00096     return H5PartWriteStepAttrib(file,key,H5T_NATIVE_FLOAT,value,nelem);}
00097   inline int writeStepAttrib(char *key,int *value,int nelem=1){
00098     return H5PartWriteStepAttrib(file,key,H5T_NATIVE_INT,value,nelem);}
00099   inline int writeStepAttrib(char *key,long long *value,int nelem=1){
00100     return H5PartWriteStepAttrib(file,key,H5T_NATIVE_INT64,value,nelem);}
00101   inline void readStepAttrib(char *key,void *value){
00102     H5PartReadStepAttrib(file,key,value);
00103   }
00104   // FileAttribs
00105     // Attribute stuff
00106   //  int writeFileAttrib(char *key,string *valuestring){
00107   //  return H5PartWriteFileAttribString(file,key,valuestring.c_str());
00108   //}
00109   inline int writeFileAttrib(char *key,char *valuestring){
00110     return H5PartWriteFileAttribString(file,key,valuestring);
00111   }
00112   inline int writeFileAttrib(char *key,double *value,int nelem=1){
00113     return H5PartWriteFileAttrib(file,key,H5T_NATIVE_DOUBLE,value,nelem);
00114   }
00115   inline int writeFileAttrib(char *key,float *value,int nelem=1){
00116     return H5PartWriteFileAttrib(file,key,H5T_NATIVE_FLOAT,value,nelem);}
00117   inline int writeFileAttrib(char *key,int *value,int nelem=1){
00118     return H5PartWriteFileAttrib(file,key,H5T_NATIVE_INT,value,nelem);}
00119   inline int writeFileAttrib(char *key,long long *value,int nelem=1){
00120     return H5PartWriteFileAttrib(file,key,H5T_NATIVE_INT64,value,nelem);}  
00121   // read file attribs
00122   inline int readFileAttrib(char *key,void *valuestring){
00123     H5PartReadFileAttrib(file,key,valuestring);
00124   }
00125 };
00126 
00127 /*
00128   An even wackier idea
00129   file.datasets[0:ndatasets-1]
00130   file.attributes[0:nfileattribs-1]
00131   file.datasets.attributes[0:ndatasetattribs-1]
00132   file.datasets.size()
00133   
00134   operators
00135   .size()
00136   .name()
00137   [idx]
00138   ["name" or "keyname"]
00139   
00140 */
00141 #if 0
00142 
00143 class H5Dataset {
00144   const hid_t dataset;
00145   char *n; // return as const
00146   int d[5]; // simple start
00147   int nd;
00148 public:
00149   H5Dataset(const hid_t ds_handle):dataset(ds_handle){}
00150   const char *name() {return n;}
00151   int nDims(){ return nd; }
00152   const int *dims(){return d;}
00153 };
00154 
00155 class H5Attribute{
00156   char *n;
00157   int sz;
00158 public:
00159   const char *name(){return n;}
00160   int size(){return sz;}
00161 }
00162 
00163 
00164 class H5Group {
00165   hid_t gid;
00166   int sz;
00167 protected:
00168   virtual int computesize(){}
00169   void setGroup(gid_t g){
00170     if(gid>0) H5close(gid);
00171     gid=g;
00172     // must compute size if available
00173     if(gid>0) computesize();
00174     else sz=0;
00175   }
00176 public:
00177     // const hid_t gid;
00178   H5Group(hid_t g):gid(g){}
00179   H5Group():gid(-1){}
00180   ~H5Group(){if(gid>0) H5Gclose(gid);}
00181   int size(){return sz;}
00182 };
00183 
00184 class H5AttribGroup : public H5Group{
00185   int size;
00186   virtual void computesize(){
00187     // compute the number of items in this group
00188   }
00189 public:
00190   const H5Attribute &operator[](char *name);
00191   const H5Attribute &operator[](int idx);
00192 };
00193 
00194 class H5DataGroup : public H5Group {
00195   int size;
00196 public:
00197   const H5Dataset &operator[](int idx);
00198   const H5Dataset &operator[](char *name);
00199   // no name here??
00200 };
00201 
00202 class H5FancyParticles {
00203   char *n;
00204   hid_t file;
00205 public:
00206   hid_t mygroup;
00207   const H5AttribGroup attributes;
00208   const H5DataGroup datasets;
00209   H5FancyParticles(char *filename,int readwriteflag);
00210   ~H5FancyParticles();
00211   // int size();// return the number of datasets in file
00212   // const char *name(); // return the name of the file?
00213   // const H5Dataset &operator[](int idx); // index dataset by integer
00214   // const H5Dataset &operator[](char *n); // index dataset by name
00215 };
00216 
00217 #endif
00218 
00219 #endif

Generated on Mon Jan 16 13:23:47 2006 for IPPL by  doxygen 1.4.6