ReFRACtor
FullPhysics::HdfFile Class Reference

This class reads and writes a HDF5 file. More...

#include <hdf_file.h>

+ Inheritance diagram for FullPhysics::HdfFile:
+ Collaboration diagram for FullPhysics::HdfFile:

Public Types

enum  Mode { READ, CREATE, READ_WRITE }
 

Public Member Functions

 HdfFile (const std::string &Fname, Mode M=READ)
 Open the given file with the given mode. More...
 
virtual ~HdfFile ()
 
void close ()
 Close the underlying file. More...
 
void dimension_metadata (const std::string &Name, const std::string &Description, int Size)
 The SDOS products have a particular metadata convention where the information about each of the Dimensions that appear in the file are documented. More...
 
const std::string & file_name () const
 File name. More...
 
H5::H5File & h5_file ()
 
const H5::H5File & h5_file () const
 
bool has_attribute (const std::string &Aname) const
 Check to see if a attribute is in the file. More...
 
bool has_object (const std::string &Objname) const
 Check to see if an object (such as a Dataset) is in the file. More...
 
Mode mode () const
 Mode file was opened with. More...
 
template<class T >
H5::PredType pred_arr () const
 
template<>
H5::PredType pred_arr () const
 
template<>
H5::PredType pred_arr () const
 
template<>
H5::PredType pred_arr () const
 
template<>
H5::PredType pred_arr () const
 
template<class T >
H5::PredType pred_data () const
 
template<>
H5::PredType pred_data () const
 
template<>
H5::PredType pred_data () const
 
template<>
H5::PredType pred_data () const
 
template<>
H5::PredType pred_data () const
 
void print (std::ostream &Os) const
 
std::string print_to_string () const
 Print to string. More...
 
template<class T , int D>
blitz::Array< T, D > read_attribute (const std::string &Aname) const
 Read the given attribute attached to a group or dataset. More...
 
template<class T >
read_attribute (const std::string &Aname) const
 Read the given attribute attached to a group or dataset. More...
 
template<class T , int D>
blitz::Array< T, D > read_field (const std::string &Dataname) const
 Read a given field. More...
 
template<class T , int D>
blitz::Array< T, D > read_field (const std::string &Dataname, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const
 Read a given field. More...
 
template<class T >
read_field (const std::string &Dataname) const
 Read a given scalar field. More...
 
template<>
std::string read_field (const std::string &Dataname) const
 
template<class T , int D>
ArrayWithUnit< T, D > read_field_with_unit (const std::string &Dataname) const
 Read a given field, along with metadata describing the units. More...
 
template<class T , int D>
ArrayWithUnit< T, D > read_field_with_unit (const std::string &Dataname, const Unit &Default_unit) const
 Read a given field, along with metadata describing the units. More...
 
template<class T , int D>
ArrayWithUnit< T, D > read_field_with_unit (const std::string &Dataname, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const
 Read a given field, along with metadata describing the units. More...
 
template<class T , int D>
ArrayWithUnit< T, D > read_field_with_unit (const std::string &Dataname, const Unit &Default_unit, const blitz::TinyVector< int, D > &Start, const blitz::TinyVector< int, D > &Size) const
 Adds ability to specify Start and Size along with default units. More...
 
template<int D>
blitz::TinyVector< int, D > read_shape (const std::string &Dataname) const
 Reads the shape of a dataset. More...
 
Unit read_units (const std::string &Dataname) const
 Read the units for a dataset. More...
 
void shape_metadata (const std::string &Name, const std::string &Dim1)
 The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More...
 
void shape_metadata (const std::string &Name, const std::string &Dim1, const std::string &Dim2)
 The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More...
 
void shape_metadata (const std::string &Name, const std::string &Dim1, const std::string &Dim2, const std::string &Dim3)
 The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented. More...
 
template<class T , int D>
void write_attribute (const std::string &Aname, const blitz::Array< T, D > &Data)
 Write attribute to file. More...
 
template<class T >
void write_attribute (const std::string &Aname, const T &Data)
 Write attribute to file. More...
 
void write_attribute (const std::string &Aname, const char *Data)
 
template<class T , int D>
void write_field (const std::string &Dataname, const blitz::Array< T, D > &Data)
 Write a given field. More...
 
template<int D>
void write_field (const std::string &Dataname, const blitz::Array< std::string, D > &Data)
 
template<int D>
void write_field (const std::string &Dataname, const blitz::Array< const char *, D > &Data)
 
template<class T >
void write_field (const std::string &Dataname, const T &Data)
 Write a given field. More...
 
void write_field (const std::string &Dataname, const std::string &Data)
 
void write_field (const std::string &Dataname, const char *Data)
 
template<class T >
void write_field (const std::string &Dataname, const T &Data, H5::DataType P)
 Write a given field. More...
 
template<class T , int D>
void write_field (const std::string &Dataname, const blitz::Array< T, D > &Data, H5::DataType P)
 Write a given field. More...
 

Static Public Member Functions

static bool is_hdf (const std::string &Fname)
 Return true if the given file is an HDF file. More...
 

Detailed Description

This class reads and writes a HDF5 file.

Note that this is just a thin layer on top of the HDF 5 libraries to make the file operations we need to do in Level 2 Full Physics easier. There are many other things that can be done with a HDF 5 than what this class exposes.

Note that because it is what is used by Level 2 product, we produce data in 32 bit (either 32 bit integer or 32 bit floating point). On a 64 bit system, the underlying double and int are larger. We map between these types as needed transparently.

HDF supports both fixed length strings and variable length strings. We have the need to write both variable length strings and fixed length strings. As a convention, if std::string are passed we write as variable length. If const char* is passed, we determine the fixed length needed to accommodate the largest string passed and write the data as fixed strings of that length (padding shorter strings with spaces). This is an arbitrary decision, but it allows us to write both types.

Note that in what is a fairly odd convention, we add a trailing '\0' in our fixed length string, so there is one extra character.

Definition at line 39 of file hdf_file.h.

Member Enumeration Documentation

◆ Mode

Enumerator
READ 
CREATE 
READ_WRITE 

Definition at line 41 of file hdf_file.h.

Constructor & Destructor Documentation

◆ HdfFile()

HdfFile::HdfFile ( const std::string &  Fname,
Mode  M = READ 
)

Open the given file with the given mode.

Definition at line 261 of file hdf_file.cc.

◆ ~HdfFile()

virtual FullPhysics::HdfFile::~HdfFile ( )
inlinevirtual

Definition at line 43 of file hdf_file.h.

Member Function Documentation

◆ close()

void FullPhysics::HdfFile::close ( )
inline

Close the underlying file.

This is automatically done by the destructor, so you only need to call this if you want to force a close (e.g., for a unit test)

Definition at line 126 of file hdf_file.h.

◆ dimension_metadata()

void HdfFile::dimension_metadata ( const std::string &  Name,
const std::string &  Description,
int  Size 
)

The SDOS products have a particular metadata convention where the information about each of the Dimensions that appear in the file are documented.

This function takes this metadata for dimension and puts it into the file.

Definition at line 463 of file hdf_file.cc.

◆ file_name()

const std::string& FullPhysics::HdfFile::file_name ( ) const
inline

File name.

Definition at line 131 of file hdf_file.h.

◆ h5_file() [1/2]

H5::H5File& FullPhysics::HdfFile::h5_file ( )
inline

Definition at line 155 of file hdf_file.h.

◆ h5_file() [2/2]

const H5::H5File& FullPhysics::HdfFile::h5_file ( ) const
inline

Definition at line 156 of file hdf_file.h.

◆ has_attribute()

bool HdfFile::has_attribute ( const std::string &  Aname) const

Check to see if a attribute is in the file.

Determine if attribute is present.

Definition at line 363 of file hdf_file.cc.

◆ has_object()

bool FullPhysics::HdfFile::has_object ( const std::string &  Objname) const
inline

Check to see if an object (such as a Dataset) is in the file.

Definition at line 48 of file hdf_file.h.

◆ is_hdf()

static bool FullPhysics::HdfFile::is_hdf ( const std::string &  Fname)
inlinestatic

Return true if the given file is an HDF file.

Definition at line 137 of file hdf_file.h.

◆ mode()

Mode FullPhysics::HdfFile::mode ( ) const
inline

Mode file was opened with.

Definition at line 118 of file hdf_file.h.

◆ pred_arr() [1/5]

template<class T >
H5::PredType FullPhysics::HdfFile::pred_arr ( ) const

◆ pred_arr() [2/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_arr ( ) const
inline

Definition at line 184 of file hdf_file.h.

◆ pred_arr() [3/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_arr ( ) const
inline

Definition at line 186 of file hdf_file.h.

◆ pred_arr() [4/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_arr ( ) const
inline

Definition at line 188 of file hdf_file.h.

◆ pred_arr() [5/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_arr ( ) const
inline

Definition at line 190 of file hdf_file.h.

◆ pred_data() [1/5]

template<class T >
H5::PredType FullPhysics::HdfFile::pred_data ( ) const

◆ pred_data() [2/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_data ( ) const
inline

Definition at line 192 of file hdf_file.h.

◆ pred_data() [3/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_data ( ) const
inline

Definition at line 194 of file hdf_file.h.

◆ pred_data() [4/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_data ( ) const
inline

Definition at line 196 of file hdf_file.h.

◆ pred_data() [5/5]

template<>
H5::PredType FullPhysics::HdfFile::pred_data ( ) const
inline

Definition at line 198 of file hdf_file.h.

◆ print()

void HdfFile::print ( std::ostream &  Os) const

Definition at line 539 of file hdf_file.cc.

◆ print_to_string()

std::string FullPhysics::Printable< HdfFile >::print_to_string ( ) const
inlineinherited

Print to string.

This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.

Definition at line 31 of file printable.h.

◆ read_attribute() [1/2]

template<class T , int D>
blitz::Array< T, D > FullPhysics::HdfFile::read_attribute ( const std::string &  Aname) const
inline

Read the given attribute attached to a group or dataset.

Definition at line 206 of file hdf_file.h.

◆ read_attribute() [2/2]

template<class T >
T FullPhysics::HdfFile::read_attribute ( const std::string &  Aname) const
inline

Read the given attribute attached to a group or dataset.

Definition at line 241 of file hdf_file.h.

◆ read_field() [1/4]

template<class T , int D>
blitz::Array< T, D > FullPhysics::HdfFile::read_field ( const std::string &  Dataname) const
inline

Read a given field.

Definition at line 564 of file hdf_file.h.

◆ read_field() [2/4]

template<class T , int D>
blitz::Array< T, D > FullPhysics::HdfFile::read_field ( const std::string &  Dataname,
const blitz::TinyVector< int, D > &  Start,
const blitz::TinyVector< int, D > &  Size 
) const

Read a given field.

This reads a subset of the data, given by Start and Size.

Definition at line 646 of file hdf_file.h.

◆ read_field() [3/4]

template<class T >
T FullPhysics::HdfFile::read_field ( const std::string &  Dataname) const
inline

Read a given scalar field.

This is a array of size 1, which we return just the value in.

Definition at line 664 of file hdf_file.h.

◆ read_field() [4/4]

template<>
std::string FullPhysics::HdfFile::read_field ( const std::string &  Dataname) const
inline

Definition at line 684 of file hdf_file.h.

◆ read_field_with_unit() [1/4]

template<class T , int D>
ArrayWithUnit< T, D > FullPhysics::HdfFile::read_field_with_unit ( const std::string &  Dataname) const
inline

Read a given field, along with metadata describing the units.

Definition at line 575 of file hdf_file.h.

◆ read_field_with_unit() [2/4]

template<class T , int D>
ArrayWithUnit< T, D > FullPhysics::HdfFile::read_field_with_unit ( const std::string &  Dataname,
const Unit Default_unit 
) const
inline

Read a given field, along with metadata describing the units.

Some data might be missing the units metadata field. For this variant of read_field_with_unit, this won't be treated as an error, but rather we will use the given default units instead.

Definition at line 608 of file hdf_file.h.

◆ read_field_with_unit() [3/4]

template<class T , int D>
ArrayWithUnit< T, D > FullPhysics::HdfFile::read_field_with_unit ( const std::string &  Dataname,
const blitz::TinyVector< int, D > &  Start,
const blitz::TinyVector< int, D > &  Size 
) const
inline

Read a given field, along with metadata describing the units.

Definition at line 589 of file hdf_file.h.

◆ read_field_with_unit() [4/4]

template<class T , int D>
ArrayWithUnit< T, D > FullPhysics::HdfFile::read_field_with_unit ( const std::string &  Dataname,
const Unit Default_unit,
const blitz::TinyVector< int, D > &  Start,
const blitz::TinyVector< int, D > &  Size 
) const
inline

Adds ability to specify Start and Size along with default units.

Definition at line 626 of file hdf_file.h.

◆ read_shape()

template<int D>
blitz::TinyVector< int, D > FullPhysics::HdfFile::read_shape ( const std::string &  Dataname) const
inline

Reads the shape of a dataset.

Definition at line 553 of file hdf_file.h.

◆ read_units()

Unit HdfFile::read_units ( const std::string &  Dataname) const

Read the units for a dataset.

Definition at line 401 of file hdf_file.cc.

◆ shape_metadata() [1/3]

void HdfFile::shape_metadata ( const std::string &  Name,
const std::string &  Dim1 
)

The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.

This function takes this metadata for Shape and puts it into the file.

Definition at line 478 of file hdf_file.cc.

◆ shape_metadata() [2/3]

void HdfFile::shape_metadata ( const std::string &  Name,
const std::string &  Dim1,
const std::string &  Dim2 
)

The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.

This function takes this metadata for Shape and puts it into the file.

Definition at line 491 of file hdf_file.cc.

◆ shape_metadata() [3/3]

void HdfFile::shape_metadata ( const std::string &  Name,
const std::string &  Dim1,
const std::string &  Dim2,
const std::string &  Dim3 
)

The SDOS products have a particular metadata convention where the information about each of the Shapes that appear in the file are documented.

This function takes this metadata for Shape and puts it into the file.

Definition at line 508 of file hdf_file.cc.

◆ write_attribute() [1/3]

template<class T , int D>
void FullPhysics::HdfFile::write_attribute ( const std::string &  Aname,
const blitz::Array< T, D > &  Data 
)
inline

Write attribute to file.

Definition at line 694 of file hdf_file.h.

◆ write_attribute() [2/3]

template<class T >
void FullPhysics::HdfFile::write_attribute ( const std::string &  Aname,
const T &  Data 
)
inline

Write attribute to file.

Definition at line 721 of file hdf_file.h.

◆ write_attribute() [3/3]

void FullPhysics::HdfFile::write_attribute ( const std::string &  Aname,
const char *  Data 
)
inline

Definition at line 888 of file hdf_file.h.

◆ write_field() [1/8]

template<class T , int D>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const blitz::Array< T, D > &  Data 
)
inline

Write a given field.

If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.

Definition at line 800 of file hdf_file.h.

◆ write_field() [2/8]

template<int D>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const blitz::Array< std::string, D > &  Data 
)
inline

Definition at line 807 of file hdf_file.h.

◆ write_field() [3/8]

template<int D>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const blitz::Array< const char *, D > &  Data 
)
inline

Definition at line 838 of file hdf_file.h.

◆ write_field() [4/8]

template<class T>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const T &  Data 
)
inline

Write a given field.

If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.

This is a shortcut for writing an array that is exactly 1 element long, this is the same as calling write_field with a blitz::Array<T, 1> of size 1.

Definition at line 934 of file hdf_file.h.

◆ write_field() [5/8]

void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const std::string &  Data 
)
inline

Definition at line 940 of file hdf_file.h.

◆ write_field() [6/8]

void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const char *  Data 
)
inline

Definition at line 963 of file hdf_file.h.

◆ write_field() [7/8]

template<class T>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const T &  Data,
H5::DataType  P 
)
inline

Write a given field.

If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.

This is a shortcut for writing an array that is exactly 1 element long, this is the same as calling write_field with a blitz::Array<T, 1> of size 1.

Definition at line 996 of file hdf_file.h.

◆ write_field() [8/8]

template<class T, int D>
void FullPhysics::HdfFile::write_field ( const std::string &  Dataname,
const blitz::Array< T, D > &  Data,
H5::DataType  P 
)
inline

Write a given field.

If you give a group (e.g., "Group1/Field1"), then we automatically create the group if it doesn't already exist.

This version lets you override the default type of the output data.

Definition at line 900 of file hdf_file.h.


The documentation for this class was generated from the following files:

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:12