1 /*******************************************************************/ 2 /* XDMF */ 3 /* eXtensible Data Model and Format */ 4 /* */ 5 /* Id : Id */ 6 /* Date : $Date$ */ 7 /* Version : $Revision$ */ 8 /* */ 9 /* Author: */ 10 /* Jerry A. Clarke */ 11 /* clarke@arl.army.mil */ 12 /* US Army Research Laboratory */ 13 /* Aberdeen Proving Ground, MD */ 14 /* */ 15 /* Copyright @ 2002 US Army Research Laboratory */ 16 /* All Rights Reserved */ 17 /* See Copyright.txt or http://www.arl.hpc.mil/ice for details */ 18 /* */ 19 /* This software is distributed WITHOUT ANY WARRANTY; without */ 20 /* even the implied warranty of MERCHANTABILITY or FITNESS */ 21 /* FOR A PARTICULAR PURPOSE. See the above copyright notice */ 22 /* for more information. */ 23 /* */ 24 /*******************************************************************/ 25 #ifndef __XdmfHDF_h 26 #define __XdmfHDF_h 27 28 #include "XdmfHeavyData.h" 29 30 #define XDMF_H5_DIRECTORY H5G_GROUP 31 #define XDMF_H5_DATASET H5G_DATASET 32 #define XDMF_H5_UNKNOWN H5G_UNKNOWN 33 #define XDMF_H5_OTHER 0xFF 34 35 namespace xdmf2 36 { 37 38 class XdmfArray; 39 40 //! Class for Accessing HDF5 Data 41 /*! 42 This is a convenience object for reading and writing 43 HDF5 Files. Use this to remain XDMF compliant. 44 Datasets in HDF5 are specified by : 45 Domain:Filename:Pathname 46 where 47 Domain = NDGM | FILE | CORE | GASS 48 if Domain is not specified, 49 FILE is assumed 50 Filename = UNIX style Pathname of HDF5 file 51 Pathname = HDF5 Pathname inside HDF5 File 52 53 XdmfHDF confines HDF5 to using only HDF5 Groups and 54 HDF5 Datasets. HDF5 Attributes (Name=Value pairs) are 55 not used (that function is served by XML). HDF5 Groups 56 are treated like "Directories" on a UNIX filesystem. 57 HDF5 Datasets are treated like "Files" on a UNIX 58 Filesystem. 59 60 Example of Createing an HDF5 File : 61 \code 62 XdmfHDF *H5 = new XdmfHDF(); 63 XdmfArray *MyData = new XdmfArray(); 64 XdmfConstString DataSetNameConst; 65 66 MyData->SetNumberType(XDMF_FLOAT32_TYPE); 67 MyData->SetNumberOfElements(100); 68 MyData->Generate(0, 99); 69 DataSetNameConst = "FILE:TestFile.h5:/TestDataSets/Values1"; 70 H5->CopyType( MyData ); 71 H5->CopyShape( MyData ); 72 H5->Open( DataSetName, "rw" ); 73 H5->Write( MyData ); 74 H5->Close(); 75 76 \endcode 77 78 This would create an HDF5 file with one Group (TestDataSets) and one Dataset in 79 that Group (Values1). The Dataset would be 100 32 bit floating point values 80 ranging from 0-99. 81 */ 82 83 84 class XDMF_EXPORT XdmfHDF : public XdmfHeavyData { 85 86 public: 87 XdmfHDF(); 88 ~XdmfHDF(); 89 GetClassName()90 XdmfConstString GetClassName() { return ( "XdmfHDF" ) ; }; 91 92 //! Set Compression Level to 0 - 9 . Level <= 0 is Off 93 /*! 94 Compression level refers to the next dataset that is 95 created. Once a dataset is created, the compression 96 level does not change. 97 98 Compression Levels 1-9 are progressively slower but 99 result in much smaller HDF5 files. Compression uses 100 the libz compression and "CHUNKS" the HDF5 file 101 in the major dimension. 102 */ 103 XdmfSetValueMacro(Compression, XdmfInt32); 104 //! Get Compression Level 105 XdmfGetValueMacro(Compression, XdmfInt32); 106 //! Use Serial File Interface even if Parallel is Available 107 XdmfSetValueMacro(UseSerialFile, XdmfInt32); 108 //! Get Value of Use Serial 109 XdmfGetValueMacro(UseSerialFile, XdmfInt32); 110 //! Set the current internal HDF "Group" for creation 111 XdmfInt32 SetCwdName( XdmfConstString Directory ); 112 //! Get the current internal HDF "Group" 113 XdmfGetValueMacro(CwdName, XdmfString ); 114 //! Go to another HDF5 "Group" 115 XdmfInt32 Cd( XdmfConstString Directory = "/" ) { 116 return( this->SetCwdName( Directory ) ); 117 }; 118 //! Create an HDF5 Gourp 119 XdmfInt32 Mkdir( XdmfString Name ); 120 //! Get the number of members in the current HDF5 Group 121 XdmfGetValueMacro( NumberOfChildren, XdmfInt64); 122 //! Get the HDF5 Library Version as Major.Minor.Release 123 XdmfConstString GetHDFVersion(void); 124 //! Get the n'th child in the current group GetChild(XdmfInt64 Index)125 XdmfConstString GetChild( XdmfInt64 Index ) { 126 if ( Index >= this->NumberOfChildren ) { 127 return( "" ); 128 } 129 return( this->Child[ Index ] ); 130 }; 131 132 //! Internal Call to set the name of the next child in the list 133 void SetNextChild( XdmfConstString Name ); 134 135 //! Internal HDF5 info 136 XdmfInt32 Info( hid_t Group, XdmfConstString Name ); 137 138 //! Get The Type of the Child : Directory, Dataset, ot Other GetChildType(XdmfInt64 Index)139 XdmfInt32 GetChildType( XdmfInt64 Index ) { 140 switch( this->Info( this->Cwd, this->GetChild( Index ) ) ) { 141 case H5G_GROUP : 142 return ( XDMF_H5_DIRECTORY ); 143 case H5G_DATASET : 144 return ( XDMF_H5_DATASET ); 145 case XDMF_FAIL : 146 return( XDMF_H5_UNKNOWN ); 147 default : 148 break; 149 } 150 return( XDMF_H5_OTHER ); 151 }; 152 //! Get The Type of the Child as a String GetChildTypeAsString(XdmfInt64 Index)153 XdmfConstString GetChildTypeAsString( XdmfInt64 Index ) { 154 switch( this->GetChildType( Index ) ) { 155 case XDMF_H5_DIRECTORY : 156 return("XDMF_H5_DIRECTORY"); 157 case XDMF_H5_DATASET : 158 return("XDMF_H5_DATASET"); 159 case XDMF_H5_UNKNOWN : 160 return("XDMF_H5_UNKNOWN"); 161 } 162 return("XDMF_H5_OTHER"); 163 }; 164 //! Create a new dataset in the current Group 165 XdmfInt32 CreateDataset( XdmfConstString Path = NULL ); 166 167 //! Open an existing Dataset in a currently open HDF5 file 168 XdmfInt32 OpenDataset(); 169 //! Open an HDF5 file and OpenDataset = DataSetName 170 /*! 171 \verbatim 172 Access is one of : 173 "rw" | "wr" - Open for reading and writing. Create if necessary. 174 "r+" - Open for reading and writing. 175 "w" - Open for Writing. Create if necessary. This will truncate the file. 176 "w+" - Open for Writing. This will truncate the file. 177 "r" - Open for Read Only. 178 \endverbatim 179 */ 180 virtual XdmfInt32 DoOpen( 181 XdmfConstString DataSetName, 182 XdmfConstString Access ); 183 /*! 184 Read the curently open dataset into and Array. 185 */ 186 virtual XdmfArray* DoRead( XdmfArray *Array ); 187 /*! 188 Write to the curently open dataset from and Array. 189 */ 190 virtual XdmfInt32 DoWrite( XdmfArray *Array ); 191 192 //! Close the HDF5 File 193 virtual XdmfInt32 DoClose(); 194 195 protected: 196 hid_t File; 197 hid_t Cwd; 198 hid_t Dataset; 199 hid_t CreatePlist; 200 hid_t AccessPlist; 201 202 char CwdName[XDMF_MAX_STRING_LENGTH]; 203 XdmfInt32 Compression; 204 XdmfInt32 UseSerialFile; 205 XdmfInt64 NumberOfChildren; 206 XdmfString Child[1024]; 207 }; 208 209 /* 210 extern XdmfArray *CreateArrayFromType( XdmfType *Type, 211 XdmfInt64 NumberOfElements = 10 ); 212 */ 213 extern XDMF_EXPORT XdmfArray *CopyArray( XdmfArray *Source, XdmfArray *Target = NULL ); 214 215 } 216 #endif // __XdmfHDF_h 217