Skip to content

Commit

Permalink
Changed funcs to open files RDONLY (#42)
Browse files Browse the repository at this point in the history
* Changed funcs to open files RDONLY (#42)

Helps multithreaded. Changed
.hdf5.fileSize
.hdf5.dataSize
.hdf5.isAttr
.hdf5.isObject
.hdf5.getDataShape
.hdf5.getAttrShape
.hdf5.readData
.hdf5.readAttrDataset

* Update copyObject to open source read only.

Switched around dst/src, since if they are the same file it'll error as an
already open file will opened readonly causing read/write to fail
  • Loading branch information
sshanks-kx authored Sep 21, 2022
1 parent 1a5eb07 commit e912005
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/hdf5_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ EXP K hdf5fileSize(K fname){
return KNL;
hsize_t fsize;
hid_t file;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
H5Fget_filesize(file, &fsize);
Expand All @@ -61,7 +61,7 @@ EXP K hdf5dataSize(K fname, K dname){
return KNL;
hsize_t dsize;
hid_t file, data;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
data = kdbH5Dopen(file, dname);
Expand All @@ -78,7 +78,7 @@ EXP K hdf5getDataShape(K fname, K dname){
return KNL;
K kdims;
hid_t file, data, space;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
data = kdbH5Dopen(file, dname);
Expand All @@ -99,7 +99,7 @@ EXP K hdf5getAttrShape(K fname, K dname, K aname){
return KNL;
K kdims;
hid_t file, data, attr, space;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
data = kdbH5Oopen(file, dname);
Expand Down Expand Up @@ -137,7 +137,7 @@ EXP K hdf5isObject(K fname, K oname){
htri_t oexists;
hid_t file;
char *objname;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
objname = kdbGetString(oname);
Expand All @@ -154,7 +154,7 @@ EXP K hdf5isAttr(K fname, K dname, K aname){
htri_t aexists;
hid_t file, data;
char *attrname;
file = kdbH5Fopen(fname, H5F_ACC_RDWR);
file = kdbH5Fopen(fname, H5F_ACC_RDONLY);
if(file < 0)
return krr((S)"error opening file");
data = kdbH5Oopen(file, dname);
Expand All @@ -173,14 +173,15 @@ EXP K hdf5copyObject(K srcfile, K src_obj, K dstfile, K dst_obj){
return KNL;
hid_t src, dst, status;
char *src_objname, *dst_objname;
src = kdbH5Fopen(srcfile, H5F_ACC_RDWR);
if(src < 0)
return krr((S)"error opening source file");
dst = kdbH5Fopen(dstfile, H5F_ACC_RDWR);
if(dst < 0){
H5Fclose(src);
return krr((S)"error opening destination file");
}
src = kdbH5Fopen(srcfile, H5F_ACC_RDONLY);
if(src < 0){
H5Fclose(dst);
return krr((S)"error opening source file");
}
src_objname = kdbGetString(src_obj);
dst_objname = kdbGetString(dst_obj);
status = H5Ocopy(src, src_objname, dst, dst_objname, H5P_DEFAULT, H5P_DEFAULT);
Expand Down

0 comments on commit e912005

Please sign in to comment.