File handling functions

nexus::is_nexus_file()

PNINEXUS_EXPORT bool pni::nexus::is_nexus_file(const fs::path &path)

checks if a file is a NeXus file

Predicate function checking if the given path references a NeXus file. For this to be true the path has to first refer to an HDF5 file. If this is the case the file will be opened and checked for the attributes required by the NeXus standard.

Parameters:

path – reference to the path of a particular file system object

Returns:

true if the reference object is a NeXus file, flase otherwise

nexus::create_file()

PNINEXUS_EXPORT hdf5::file::File pni::nexus::create_file(const fs::path &path, hdf5::file::AccessFlags flags = hdf5::file::AccessFlags::Exclusive, const hdf5::property::FileCreationList &fcpl = hdf5::property::FileCreationList(), const hdf5::property::FileAccessList &fapl = hdf5::property::FileAccessList())

create a new NeXus file

This function is basically an enhancement of the standard hdf5::file::create function. In addition of creating a new HDF5 file it also adds all the attributes to the root group of the file required by the NeXus standard. The arguments are the same as for hdf5::file::create.

The only mandatory argument is the path to the new file. By default, an exception will be thrown if the file already exists in order to prohibit the user from accidentally overwriting an existing file. To change this behavior the AccessFlags must be passed as a second argument. References to file creation and file access property lists can be passed as third and fourth argument.

For more detailed information see the h5cpp documentation.

Throws:

std::runtime_error – in case of a failure

Parameters:
  • path – reference to the path ot the new file

  • flags – access flags for the new file

  • fcpl – reference to a file creation property list

  • fapl – reference to a file access property list

Returns:

instance of hdf5::file::File

nexus::open_file()

PNINEXUS_EXPORT hdf5::file::File pni::nexus::open_file(const fs::path &path, hdf5::file::AccessFlags flags = hdf5::file::AccessFlags::ReadOnly, const hdf5::property::FileAccessList &fapl = hdf5::property::FileAccessList())

open an existing NeXus file

Function opening an existing NeXus file. This functions checks whether or not a file is a valid NeXus file. If this is not the case an exception will be thrown. In order to open a file without this check just use the hdf5::file::open function from the h5cpp library.

Throws:

std::runtime_error – in case of a failure

Parameters:
  • path – reference to the file’s path

  • flags – access flags for the file

  • fapl – reference to the file access property list

Returns:

instance of hdf5::file::File