OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimH5Info.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: David Burken
8 //
9 // Description: HDF5 Info class.
10 //
11 //----------------------------------------------------------------------------
12 // $Id$
13 
14 #include "ossimH5Info.h"
15 #include "ossimH5Util.h"
16 
17 #include <ossim/base/ossimCommon.h>
18 #include <ossim/base/ossimEndian.h>
19 #include <ossim/base/ossimNotify.h>
20 #include <ossim/base/ossimTrace.h>
21 
22 //---
23 // This includes everything! Note the H5 includes are order dependent; hence,
24 // the mongo include.
25 //---
26 #include <hdf5.h>
27 #include <H5Cpp.h>
28 
29 #include <fstream>
30 #include <iostream>
31 #include <iomanip>
32 #include <sstream>
33 
34 static ossimTrace traceDebug("ossimH5Info:debug");
35 
37  : ossimInfoBase(),
38  m_file()
39 {
40 }
41 
43 {
44 }
45 
47 {
48  bool result = false;
49 
50  // Check for empty filename.
51  if (file.size())
52  {
53  try
54  {
55  //--
56  // Turn off the auto-printing when failure occurs so that we can
57  // handle the errors appropriately
58  //---
59  H5::Exception::dontPrint();
60 
61  if ( H5::H5File::isHdf5( file.string() ) )
62  {
63  m_file = file;
64  result = true;
65  }
66  }
67  catch( const H5::Exception& e )
68  {
69  e.getDetailMsg();
70  }
71  catch( ... )
72  {
73  if ( traceDebug() )
74  {
76  << "ossimH5Info::open WARNING Caught unhandled exception for file:\n"
77  << file.c_str() << std::endl;
78  }
79  }
80  }
81 
82  return result;
83 }
84 
86 {
87  static const char MODULE[] = "ossimH5Info::open";
88 
89  if ( traceDebug() )
90  {
92  << MODULE << " entered..."
93  << "File: " << m_file.c_str()
94  << std::endl;
95  }
96 
97  // Check for empty filename.
98  if (m_file.size())
99  {
100  try
101  {
102  //--
103  // Turn off the auto-printing when failure occurs so that we can
104  // handle the errors appropriately
105  //---
106  H5::Exception::dontPrint();
107 
108  H5::H5File* h5File = new H5::H5File();
109 
110  H5::FileAccPropList access_plist = H5::FileAccPropList::DEFAULT;
111 
112  h5File->openFile( m_file.string(), H5F_ACC_RDONLY, access_plist );
113 
114  // std::vector<std::string> names;
115  // ossim_hdf5::getDatasetNames( h5File, names );
116  ossim_hdf5::print( h5File, out );
117 
118  // cleanup...
119  h5File->close();
120  delete h5File;
121  h5File = 0;
122 
123  } // End: try block
124  catch( const H5::Exception& e )
125  {
126  e.getDetailMsg();
127  }
128  catch( ... )
129  {
130  if ( traceDebug() )
131  {
133  << "ossimH5Info::print WARNIN: Caught unhandled exception!"
134  << std::endl;
135  }
136  }
137  }
138 
139  return out;
140 }
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
std::string::size_type size() const
Definition: ossimString.h:405
Info Base.
Definition: ossimInfoBase.h:32
virtual ~ossimH5Info()
virtual destructor
Definition: ossimH5Info.cpp:42
virtual std::ostream & print(std::ostream &out) const
Print method.
Definition: ossimH5Info.cpp:85
ossimFilename m_file
Definition: ossimH5Info.h:59
virtual bool open(const ossimFilename &file)
open method.
Definition: ossimH5Info.cpp:46
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
ossimH5Info()
default constructor
Definition: ossimH5Info.cpp:36
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const std::string & string() const
Definition: ossimString.h:414