Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NP_TMcode
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Mulas
NP_TMcode
Commits
27a5b3b9
Commit
27a5b3b9
authored
1 year ago
by
Giovanni La Mura
Browse files
Options
Downloads
Patches
Plain Diff
Set up binary wrapper for HDF5
parent
40ed5118
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/file_io.h
+76
-0
76 additions, 0 deletions
src/include/file_io.h
src/libnptm/file_io.cpp
+33
-0
33 additions, 0 deletions
src/libnptm/file_io.cpp
with
109 additions
and
0 deletions
src/include/file_io.h
0 → 100644
+
76
−
0
View file @
27a5b3b9
/*! \file file_io.h
*
* \brief Library to handle I/O operations with files.
*/
#ifndef INCLUDE_FILE_IO_H_
#define INCLUDE_FILE_IO_H_
/*! \class FileSchema
*
* \brief File content descriptor.
*
* Accessing binary files requires detailed knowledge of their contents. The `FileSchema`
* class is intended to encapsulate this information and use it as a wrapper to control
* I/O operations towards different file formats. Any file can be thought of as a sequence
* of records, which may further contain arbitrarily complex structures. By describing the
* structure of records, it is possible to support virtually any type of format.
*/
class
FileSchema
{
protected:
//! \brief Number of records conained in the file.
int
num_records
;
//! \brief Array of record descriptors.
std
::
string
*
record_types
;
public:
/*! \brief FileSchema instance constructor.
*
* \param num_rec: `int` Number of records in the file.
* \param rec_types: `string *` Description of the records in the file.
*/
FileSchema
(
int
num_rec
,
std
::
string
*
rec_types
);
/*! \brief FileSchema instance destroyer.
*/
~
FileSchema
();
};
/*! \class HDFFile
*
* \brief HDF5 I/O wrapper class.
*
* This class manages I/O operations toward HDF5 format files.
*/
class
HDFFile
{
protected:
std
::
string
file_name
;
bool
file_open_flag
;
hid_t
file_id
;
herr_t
status
;
public:
/*! \brief HDFFile instance constructor.
*
* \param name: `string` Name of the file.
* \param flags: `unsigned int` File access flags.
* \param fcpl_id: `hid_t` File creation property list identifier.
* \param fapl_id: `hid_t` File access property list identifier.
*/
HDFFile
(
std
::
string
name
,
unsigned
int
flags
=
H5F_ACC_EXCL
,
hid_t
fcpl_id
=
H5P_DEFAULT
,
hid_t
fapl_id
=
H5P_DEFAULT
);
/*! \brief Close the current file.
*/
herr_t
close
();
/*! \brief Get current status.
*/
herr_t
get_status
()
{
return
status
;
}
/*! \brief Check whether the attached file is currently open.
*/
bool
is_open
()
{
return
file_open_flag
;
}
};
#endif
This diff is collapsed.
Click to expand it.
src/libnptm/file_io.cpp
0 → 100644
+
33
−
0
View file @
27a5b3b9
/*! \file file_io.cpp
*
* \brief Implementation of file I/O operations.
*/
#include
<string>
#include
"hdf5.h"
#ifndef INCLUDE_FILE_IO_H_
#include
"../include/file_io.h"
#endif
using
namespace
std
;
FileSchema
::
FileSchema
(
int
num_rec
,
string
*
rec_types
)
{
num_records
=
num_rec
;
record_types
=
new
string
[
num_rec
];
for
(
int
i
=
0
;
i
<
num_rec
;
i
++
)
record_types
[
i
]
=
rec_types
[
i
];
}
FileSchema
::~
FileSchema
()
{
delete
[]
record_types
;
}
HDFFile
::
HDFFile
(
string
name
,
unsigned
int
flags
,
hid_t
fcpl_id
,
hid_t
fapl_id
)
{
file_name
=
name
;
file_id
=
H5Fcreate
(
name
.
c_str
(),
flags
,
fcpl_id
,
fapl_id
);
if
(
file_id
!=
H5I_INVALID_HID
)
file_open_flag
=
true
;
status
=
(
herr_t
)
0
;
}
herr_t
HDFFile
::
close
()
{
status
=
H5Fclose
(
file_id
);
if
(
status
==
0
)
file_open_flag
=
false
;
return
status
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment