Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open files in read-only mode when they should only be read from. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions h5read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ the appropriate size for the given HDF5 type.\n\
return octave_value_list ();

//open the hdf5 file
H5File file (filename.c_str (), false);
H5File file (filename.c_str (), false, false);
if (error_state)
return octave_value_list ();

Expand Down Expand Up @@ -244,7 +244,7 @@ is to read.\n\
return octave_value_list ();

//open the hdf5 file
H5File file (filename.c_str (), false);
H5File file (filename.c_str (), false, false);
if (error_state)
return octave_value_list ();

Expand Down Expand Up @@ -318,7 +318,7 @@ the appropriate size for the given Octave type.\n\
if (nargin == 3)
{
//open the hdf5 file, create it if it does not exist
H5File file (filename.c_str (), true);
H5File file (filename.c_str (), true, true);
if (error_state)
return octave_value_list ();
file.write_dset (location.c_str (),
Expand All @@ -327,7 +327,7 @@ the appropriate size for the given Octave type.\n\
else
{
//open the hdf5 file, complain if it does not exist
H5File file (filename.c_str (), false);
H5File file (filename.c_str (), false, true);
if (error_state)
return octave_value_list ();

Expand Down Expand Up @@ -397,7 +397,7 @@ the object named @var{objectname} in the HDF5 file specified by @var{filename}.\
return octave_value_list ();

//open the hdf5 file
H5File file (filename.c_str (), false);
H5File file (filename.c_str (), false, true);
if (error_state)
return octave_value_list ();

Expand Down Expand Up @@ -513,7 +513,7 @@ setting is not @sc{matlab} compatible.\n\


//open the hdf5 file
H5File file (filename.c_str (), true);
H5File file (filename.c_str (), true, true);
if (error_state)
return octave_value_list ();
file.create_dset (location.c_str (), size, datatype.c_str (), chunksize);
Expand Down Expand Up @@ -568,7 +568,7 @@ Note that this function is not @sc{matlab} compliant.\n\
return octave_value_list ();

//open the hdf5 file
H5File file (filename.c_str (), true);
H5File file (filename.c_str (), true, true);
if (error_state)
return octave_value_list ();
if (nargin == 2)
Expand All @@ -586,7 +586,8 @@ Note that this function is not @sc{matlab} compliant.\n\

#if defined (HAVE_HDF5) && defined (HAVE_HDF5_18)

H5File::H5File (const char *filename, const bool create_if_nonexisting)
H5File::H5File (const char *filename, const bool create_if_nonexisting,
const bool write_access)
{
H5E_auto_t oef;
void *olderr;
Expand All @@ -606,7 +607,9 @@ H5File::H5File (const char *filename, const bool create_if_nonexisting)
error ("The file is not in the HDF5 format, %s: %s", filename, strerror (errno));
else
{
file = H5Fopen (filename, H5F_ACC_RDWR, H5P_DEFAULT);
file = H5Fopen (filename,
write_access ? H5F_ACC_RDWR : H5F_ACC_RDONLY,
H5P_DEFAULT);
if (file < 0)
error ("Opening the file failed, %s: %s", filename, strerror (errno));
}
Expand Down
3 changes: 2 additions & 1 deletion h5read.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class H5File

public:

H5File (const char *filename, const bool create_if_nonexisting);
H5File (const char *filename, const bool create_if_nonexisting,
const bool write_access);

~H5File ();

Expand Down