62 out<<
"ossimHdf5Info: No HDF5 file has been opened! Nothing to print."<<endl;
74 catch (H5::Exception& h5x)
92 print(out, groups[i], lm);
101 vector<Attribute> attributes;
105 if (!attributes.empty())
108 print(out, attributes[i], lm);
117 vector<DataSet> datasets;
121 if (!datasets.empty())
124 print(out, datasets[i], lm);
134 out<<lm<<
"GROUP: "<<group.getObjName()<<endl;
148 catch(
const H5::Exception& e )
161 out<<lm<<
"DATASET: "<<dataset.getObjName()<<endl;
164 int set_size = dataset.getSpace().getSimpleExtentNpoints();
166 print(out, dataset.getDataType(), lm2);
167 print(out, dataset.getSpace(), lm2);
170 H5T_class_t class_type = dataset.getDataType().getClass();
171 if ((set_size < 11) && (class_type == H5T_STRING))
174 dataset.read(values, dataset.getDataType());
175 out<<lm<<
" values: "<<values<<endl;
178 catch(
const H5::Exception& e )
191 H5T_class_t class_type = datatype.getClass();
192 size_t size = datatype.getSize();
193 bool isAtomic =
false;
198 out<<lm<<
"DATATYPE: integer, "<<
size<<
" bytes ";
202 out<<lm<<
"DATATYPE: float, "<<
size<<
" bytes ";
205 out<<lm<<
"DATATYPE: date/time, "<<
size<<
" bytes "<<endl;
208 out<<lm<<
"DATATYPE: string, "<<
size<<
" bytes ";
211 out<<lm<<
"DATATYPE: bit-field, "<<
size<<
" bytes "<<endl;
214 out<<lm<<
"DATATYPE: opaque, "<<
size<<
" bytes "<<endl;
217 out<<lm<<
"DATATYPE: compound, "<<
size<<
" bytes "<<endl;
220 out<<lm<<
"DATATYPE: reference, "<<
size<<
" bytes "<<endl;
223 out<<lm<<
"DATATYPE: enumeration, "<<
size<<
" bytes "<<endl;
226 out<<lm<<
"DATATYPE: variable-length, "<<
size<<
" bytes "<<endl;
229 out<<lm<<
"DATATYPE: array, "<<
size<<
" bytes "<<endl;
232 out<<lm<<
"DATATYPE: unknown, "<<
size<<
" bytes "<<endl;
237 H5T_order_t order = ((AtomType&) datatype).getOrder();
241 out<<
"(Little Endian)"<<endl;
244 out<<
"(Big Endian)"<<endl;
252 catch(
const H5::Exception& e )
265 hsize_t* dim_sizes = 0;
269 H5S_class_t classT = dataspace.getSimpleExtentType();
273 out<<lm<<
"DATASPACE: (scalar)"<<endl;
276 rank = dataspace.getSimpleExtentNdims();
277 dim_sizes =
new hsize_t[rank];
278 dataspace.getSimpleExtentDims(dim_sizes);
279 out<<lm<<
"DATASPACE: simple, rank: "<<rank<<
" size: ";
280 for (
int i=0; i<rank; i++)
282 int dim_size = dim_sizes[i];
291 out<<lm<<
"DATASPACE: (NULL)"<<endl;
294 out<<lm<<
"DATASPACE: (Unknown Type)"<<endl;
297 catch(
const H5::Exception& e )
308 out<<lm<<
"ATTRIBUTE: "<<attr.getName();
312 std::string str_value;
320 H5T_class_t class_type = attr.getDataType().getClass();
325 attr.read(attr.getDataType(), str_value);
326 out <<
" = "<<str_value<<endl;
330 std::string strValue;
331 attr.read(attr.getDataType(), buf);
332 ossim_uint32 signType = H5Tget_sign(attr.getDataType().getId());
350 intValue =
reinterpret_cast<ossim_int8*
>(buf);
371 endian.
swap(*intValue);
381 endian.
swap(*intValue);
402 endian.
swap(*intValue);
412 endian.
swap(*intValue);
432 endian.
swap(*intValue);
442 endian.
swap(*intValue);
451 out <<
" = "<<strValue<<endl;
456 std::string strValue;
457 attr.read(attr.getDataType(), buf);
468 endian.
swap(*float_value);
477 endian.
swap(*float_value);
482 out <<
" = "<<strValue<<endl;
486 out <<
" (value not handled type) "<<endl;
487 print(out, attr.getDataType(), lm2);
488 print(out, attr.getSpace(), lm2);
491 catch(
const H5::Exception& e )
508 string groupName =
"/";
509 string prefix =
"hdf5.";
519 vector<DataSet> datasets;
520 vector<std::string> datasetNames;
527 value << datasets[i].getObjName();
529 value <<
", "<< datasets[i].getObjName();
532 m_kwl.
addPair(prefix,
string(
"datasetnames"), value.str());
534 catch(
const H5::Exception& e )
546 bool returnValue =
false;
572 bool returnValue =
false;
599 const string& prefix,
607 m_kwl.
addPair(groupPrefix,
string(
"type"),
string(
"Group"));
613 vector<DataSet> datasets;
621 vector<Group> childGroups;
625 dumpGroup(childGroups[i], groupPrefix, recursedCount);
628 catch(
const H5::Exception& e )
639 vector<ossimString> items;
640 fullPathName.
split(items,
"/");
644 if (objectName.empty())
645 objectPrefix << prefix;
647 objectPrefix << prefix << objectName<<
".";
649 return objectPrefix.str();
656 vector<H5::Attribute> attrList;
661 attrPrefix << prefix;
665 catch(
const H5::Exception& e )
672 const std::string& prefix)
const 674 std::string strValue;
682 H5T_class_t class_type = attr.getDataType().getClass();
688 attr.read(attr.getDataType(), strValue);
693 H5::DataType dataType = attr.getDataType();
694 H5::IntType* dataTypePtr = (H5::IntType*)(&dataType);
696 attr.read(attr.getDataType(), buf);
702 H5::DataType dataType = attr.getDataType();
703 H5::FloatType* dataTypePtr = (H5::FloatType*)(&dataType);
705 attr.read(attr.getDataType(), buf);
728 strValue = tempOut.str();
735 catch(
const H5::Exception& e )
743 const std::string& prefix)
const 746 std::cout <<
"printObject entered..." 747 <<
"\nobjectName: " << objectName
748 <<
"\nprefix: " << prefix
755 m_kwl.
addPair(datasetPrefix,
string(
"type"),
string(
"DataSet"));
761 H5T_class_t type_class = dataset.getTypeClass();
769 H5::CompType compType(dataset);
776 H5::EnumType enumType (dataset);
782 H5::ArrayType arrayType (dataset.getId());
796 string(
"OSSIM_SCALAR_UNKNOWN"));
802 vector<ossim_uint32> extents;
810 value <<
", " << extents[i];
817 int numberOfAttrs = dataset.getNumAttrs();
818 cout <<
"numberOfAttrs: " << numberOfAttrs << endl;
819 for (
ossim_int32 attrIdx = 0; attrIdx < numberOfAttrs; ++attrIdx )
821 H5::Attribute attribute = dataset.openAttribute( attrIdx );
822 cout <<
"attribute.from class: " << attribute.fromClass() << endl;
826 catch(
const H5::Exception& e )
834 const H5::CompType& compound,
835 const std::string& prefix)
const 837 H5::DataSpace dataspace = dataset.getSpace();
838 ossim_uint32 dimensions = dataspace.getSimpleExtentNdims();
839 ossim_uint32 nElements = dataspace.getSimpleExtentNpoints();
844 H5::DataType compType = dataset.getDataType();
845 std::vector<char> compData(
size*nElements);
846 dataset.read((
void*)&compData.front(),compType);
847 char* compDataPtr = &compData.front();
854 for(;elementIdx<nElements;++elementIdx)
856 std::string elementPrefix = prefix;
858 for(memberIdx=0;memberIdx < nMembers;++memberIdx)
860 H5::DataType dataType = compound.getMemberDataType(memberIdx);
861 H5std_string memberName = compound.getMemberName(memberIdx);
862 ossim_uint32 memberOffset = compound.getMemberOffset(memberIdx) ;
863 std::string newPrefix = elementPrefix + memberName;
865 switch(dataType.getClass())
869 H5::CompType compoundType(dataset);
876 H5::IntType dataType = compound.getMemberIntType(memberIdx);
877 dumpIntType(dataType, &compDataPtr[memberOffset], newPrefix);
883 H5::FloatType dataType = compound.getMemberFloatType(memberIdx);
884 dumpFloatType(dataType, &compDataPtr[memberOffset], newPrefix);
890 H5::StrType dataType = compound.getMemberStrType(memberIdx);
912 H5::EnumType dataType = compound.getMemberEnumType(memberIdx);
924 H5::ArrayType dataType = compound.getMemberArrayType(memberIdx);
925 dumpArrayType(dataType, &compDataPtr[memberOffset], newPrefix);
941 const std::string& prefix)
const 950 typePrefix << prefix <<
"compound_type.";
951 m_kwl.
addPair(prefix,
string(
"type"),
string(
"compound"));
953 for(memberIdx=0;memberIdx < nMembers;++memberIdx)
955 H5::DataType dataType (compound.getMemberDataType(memberIdx));
956 H5std_string memberName (compound.getMemberName(memberIdx));
958 newPrefix<<typePrefix.str() <<memberName<<
".";
960 H5T_class_t class_type = dataType.getClass();
967 H5::IntType dataType = compound.getMemberIntType(memberIdx);
974 H5::FloatType dataType = compound.getMemberFloatType(memberIdx);
979 H5::EnumType enudataType = compound.getMemberEnumType(memberIdx);
985 H5::ArrayType arrdataType = compound.getMemberArrayType(memberIdx);
996 catch(
const H5::Exception& e )
1004 const std::string& prefix)
const 1008 ossim_int32 nEnumMembers = enumType.getNmembers();
1010 if (!nEnumMembers || !enumTypeSize)
1013 char* enum_value =
new char [enumTypeSize];
1018 enumType.getMemberValue(i, &enum_value);
1019 H5std_string name = enumType.nameOf(&enum_value, enumTypeSize);
1023 kwl_value <<
", " << name;
1025 m_kwl.
addPair(prefix,
string(
"enumerations"), kwl_value.str());
1026 delete [] enum_value;
1028 catch(
const H5::Exception& e )
1036 const std::string& prefix)
const 1046 std::vector<hsize_t> dims(arrayNdims);
1047 arrayType.getArrayDims(&dims.front());
1052 kwl_value << dims[i];
1054 kwl_value <<
", " << dims[i];
1056 m_kwl.
addPair(prefix,
string(
"dimensions"), kwl_value.str());
1059 catch(
const H5::Exception& e )
1067 const std::string& prefix)
const 1075 std::string byteOrderString =
"little_endian";
1077 byteOrderString =
"big_endian";
1080 catch(
const H5::Exception& e )
1087 const char* dataPtr,
1088 const std::string& prefix)
const 1090 std::string strValue;
1099 const char* dataPtr,
1100 const std::string& prefix)
const 1102 std::string strValue;
1111 const char* dataPtr,
1112 const std::string& prefix)
const 1114 std::string strValue;
1122 const char* dataPtr,
1123 const std::string& prefix)
const 1129 H5::DataType superType = dataType.getSuper();
1133 std::vector<hsize_t> dims(arrayNdims);
1134 dataType.getArrayDims(&dims.front());
1141 std::copy(dims.begin(), --dims.end(),
1142 std::ostream_iterator<hsize_t>(dimOut,
","));
1143 for(;idx<dims.size();++idx)
1145 nArrayElements*=dims[idx];
1152 switch(superType.getClass())
1159 const char* startPtr = 0;
1160 const char* endPtr = 0;
1161 const char* mem = 0;
1164 for(idx=0;idx<nArrayElements;++idx)
1166 mem = ((
const char*)dataPtr) + (idx * typeSize);
1167 if(superType.isVariableStr())
1169 startPtr = *(
char**) mem;
1170 if(startPtr) strSize = std::strlen(startPtr);
1181 for (; ((charIdx < strSize) && (*endPtr)); ++charIdx,++endPtr);
1187 out <<
"\""<<value<<
"\"";
1191 out <<
", \""<<value<<
"\"";
1205 H5::IntType* dataTypePtr = (H5::IntType*)(&superType);
1211 for(idx=0;idx<nArrayElements;++idx)
1215 if((idx + 1) <nArrayElements)
1217 out << value <<
", ";
1233 H5::FloatType* dataTypePtr = (H5::FloatType*)(&superType);
1241 for(idx=0;idx<nArrayElements;++idx)
1245 if((idx + 1) <nArrayElements)
1247 out << value <<
", ";
1273 const char* dataPtr,
1274 const std::string& prefix)
const 1278 H5::IntType dataType = dataset.getIntType();
1357 valueStr =
"<UNHANDLED SCALAR TYPE>";
1364 catch(
const H5::Exception& e )
void dumpGroup(const H5::Group &group, const std::string &prefix, ossim_uint32 &recursedCount) const
static const char * BYTE_ORDER_KW
char ossim_int8
Previous DLL import export section.
std::ostream & printSubGroups(std::ostream &out, const H5::Group &obj, const ossimString &lm=ossimString()) const
void dumpDataset(const H5::DataSet &dataset, const std::string &prefix) const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
virtual std::ostream & print(std::ostream &out) const
std::basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
void dumpArrayTypeInfo(H5::ArrayType datatype, const std::string &prefix) const
bool getRoot(H5::Group &root) const
Assigns the root group.
void dumpCompound(const H5::DataSet &dataset, const H5::CompType &compound, const std::string &prefix) const
void dumpAttribute(const H5::Attribute &attr, const std::string &prefix) const
Represents serializable keyword/value map.
virtual ossimString getEntryString(ossim_int32 entry_number) const
std::ostream & printDatasets(std::ostream &out, const H5::Group &obj, const ossimString &lm=ossimString()) const
static ossimString toString(bool aValue)
Numeric to string methods.
void dumpFloatType(const H5::FloatType &dataType, const char *dataPtr, const std::string &prefix) const
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
OSSIM_DLL ossimByteOrder byteOrder()
void dumpArrayType(H5::ArrayType &dataType, const char *dataPtr, const std::string &prefix) const
ossimHdf5Info()
default constructor
void dumpCompoundTypeInfo(const H5::CompType &compound, const std::string &prefix) const
unsigned short ossim_uint16
ossimString getObjectPrefix(const ossimString &prefix, const ossimString &fullPathName) const
bool open(const ossimFilename &hdf5File)
Opens specified HDF5 file.
void dumpAttributes(const H5::H5Object &container, const std::string &prefix) const
static bool getDatasets(H5::Group group, std::vector< H5::DataSet > &datasetList, bool recursive=false)
Assigns list of datasets under specified group.
ossimRefPtr< ossimHdf5 > m_hdf5
void dumpEnumTypeInfo(H5::EnumType datatype, const std::string &prefix) const
void dumpNumericalTypeInfo(const H5::DataSet &dataset, ossimByteOrder order, const std::string &prefix) const
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
static ossimByteOrder getByteOrder(const H5::AbstractDs *obj)
void dumpIntType(const H5::IntType &dataType, const char *dataPtr, const std::string &prefix) const
virtual bool getKeywordlist(ossimKeywordlist &kwl) const
Method to dump info to a keyword list.
static ossimScalarType getScalarType(const H5::DataSet &dataset)
H5::Group * findGroupByName(const std::string &group_name, const H5::Group *parent_group=0, bool recursive=false) const
Finds a group by name.
static std::string getDatatypeClassType(ossim_int32 type)
unsigned long long ossim_uint64
unsigned int ossim_uint32
static bool getChildGroups(H5::Group group, std::vector< H5::Group > &groupList, bool recursive=false)
Assigns list of groups under specified group.
static bool stringTypeToString(std::string &result, const H5::StrType &dataType, const char *dataPtr)
static bool floatTypeToString(std::string &result, const H5::FloatType &dataType, const char *dataPtr)
virtual ~ossimHdf5Info()
virtual destructor
static bool getAttributes(const H5::H5Object &obj, std::vector< H5::Attribute > &attrList)
Low-level OSSIM interface to HDF5 libraries.
virtual bool getKeywordlistGroup(ossimKeywordlist &kwl, const std::string &groupName) const
H5::DataSet * findDatasetByName(const std::string &dataset_name, const H5::Group *group=0, bool recursive=false) const
Finds a dataset by name.
void dumpStringType(const H5::StrType &dataType, const char *dataPtr, const std::string &prefix) const
std::ostream & printAttributes(std::ostream &out, const H5::H5Object &obj, const ossimString &lm=ossimString()) const
virtual bool getKeywordlistDataset(ossimKeywordlist &kwl, const std::string &datasetName) const
static void getExtents(const H5::DataSet &dataset, std::vector< ossim_uint32 > &extents)
void dumpNumerical(const H5::DataSet &dataset, const char *dataPtr, const std::string &prefix) const
static const char * SCALAR_TYPE_KW
ossimRefPtr< ossimHdf5 > m_hdf5
virtual bool open(const ossimFilename &file)
unsigned char ossim_uint8
static bool intTypeToString(std::string &result, const H5::IntType &dataType, const char *dataPtr)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
const std::string & string() const