APPEND open mode

Why APPEND mode is not available in list of open modes for H5File object? This mode is default mode in h5py and in many modern databases.
In many cases it is useful to create file if it is not exist.

Only small change must be done in H5File.cpp:

void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist)
{
// These bits only set for creation, so if any of them are set,
// Open the file if none of the bits below are set.
if( !(flags & (H5F_ACC_CREAT|H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG)))
{
hid_t access_plist_id = access_plist.getId();
id = H5Fopen( name, flags, access_plist_id );
if( id < 0 ) // throw an exception when open/create fail and it is not append mode
{
if(! (flags & H5F_ACC_APPEND))
{
throw FileIException("H5File constructor", "H5Fopen failed");
}
else
{
flags = H5F_ACC_EXCL;
}
}
else
{
return;
}
}
// create the file.
hid_t create_plist_id = create_plist.getId();
hid_t access_plist_id = access_plist.getId();
id = H5Fcreate( name, flags, create_plist_id, access_plist_id );
if( id < 0 ) // throw an exception when open/create fail
{
throw FileIException("H5File constructor", "H5Fcreate failed");
}
}

and in H5Fpublic.h

#define H5F_ACC_RDONLY (H5CHECK 0x0000u) /*absence of rdwr => rd-only */
#define H5F_ACC_RDWR (H5CHECK 0x0001u) /*open for read and write */
#define H5F_ACC_TRUNC (H5CHECK 0x0002u) /*overwrite existing files */
#define H5F_ACC_EXCL (H5CHECK 0x0004u) /*fail if file already exists*/
#define H5F_ACC_DEBUG (H5CHECK 0x0008u) /*print debug info */
#define H5F_ACC_CREAT (H5CHECK 0x0010u) /*create non-existing files */
#define H5F_ACC_APPEND (H5CHECK 0x0020u) /*create non-existing files RDWR if exist*/

···

--
Андрей Семенов

I will enter a bug report for this. We will investigate it and fix it if appropriate.

Thanks!
-Barbara
help@hdfgroup.org

···

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of ??? ???
Sent: Sunday, June 22, 2014 1:25 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] APPEND open mode

Why APPEND mode is not available in list of open modes for H5File object? This mode is default mode in h5py and in many modern databases.
In many cases it is useful to create file if it is not exist.

Only small change must be done in H5File.cpp:

void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist)
{
// These bits only set for creation, so if any of them are set,
// Open the file if none of the bits below are set.
if( !(flags & (H5F_ACC_CREAT|H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG)))
{
hid_t access_plist_id = access_plist.getId();
id = H5Fopen( name, flags, access_plist_id );
if( id < 0 ) // throw an exception when open/create fail and it is not append mode
{
if(! (flags & H5F_ACC_APPEND))
{
throw FileIException("H5File constructor", "H5Fopen failed");
}
else
{
flags = H5F_ACC_EXCL;
}
}
else
{
return;
}
}

// create the file.
hid_t create_plist_id = create_plist.getId();
hid_t access_plist_id = access_plist.getId();
id = H5Fcreate( name, flags, create_plist_id, access_plist_id );
if( id < 0 ) // throw an exception when open/create fail
{
throw FileIException("H5File constructor", "H5Fcreate failed");
}
}

and in H5Fpublic.h

#define H5F_ACC_RDONLY (H5CHECK 0x0000u) /*absence of rdwr => rd-only */
#define H5F_ACC_RDWR (H5CHECK 0x0001u) /*open for read and write */
#define H5F_ACC_TRUNC (H5CHECK 0x0002u) /*overwrite existing files */
#define H5F_ACC_EXCL (H5CHECK 0x0004u) /*fail if file already exists*/
#define H5F_ACC_DEBUG (H5CHECK 0x0008u) /*print debug info */
#define H5F_ACC_CREAT (H5CHECK 0x0010u) /*create non-existing files */
#define H5F_ACC_APPEND (H5CHECK 0x0020u) /*create non-existing files RDWR if exist*/

--
Андрей Семенов