aboutsummaryrefslogtreecommitdiff
path: root/src/H5IO.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5IO.cc')
-rw-r--r--src/H5IO.cc108
1 files changed, 69 insertions, 39 deletions
diff --git a/src/H5IO.cc b/src/H5IO.cc
index 117b17d..e457f99 100644
--- a/src/H5IO.cc
+++ b/src/H5IO.cc
@@ -5,6 +5,10 @@
#include "H5IO.hh"
+#ifdef WITH_HDF5WRAP
+#include <hdf5wrap/HDF5Open.h>
+#endif
+
hid_t H5IO::DataType2H5(IObase::DataType nt){
switch(nt){
case Int8:
@@ -37,14 +41,14 @@ hid_t H5IO::DataType2H5(IObase::DataType nt){
}
}
-IObase::DataType H5IO::H5DataType2DataType(hid_t nt){
+IObase::DataType H5IO::H5DataType2DataType(hid_t nt){
H5T_class_t typeclass;
size_t typesize;
-
+
typeclass = H5Tget_class(nt);
typesize = H5Tget_size(nt);
//fprintf(stderr,"class=%d size=%d\n",typeclass,typesize);
-
+
switch(typeclass){
case H5T_INTEGER:
// printf("Int %d bytes\n",typesize);
@@ -98,7 +102,7 @@ IObase::DataType H5IO::H5DataType2DataType(hid_t nt){
case H5T_OPAQUE:
puts("Cannot convert type Opaque");
break;
- case H5T_COMPOUND:
+ case H5T_COMPOUND:
default:
puts("Cannot convert type Unknown");
break;
@@ -136,7 +140,7 @@ IObase::DataType H5IO::H52DataType(hid_t &nt){
fprintf(stderr,"H5IO::H52DataType(): Don't recognize type %d\n",(int)nt);
return Error;
}
-#endif
+#endif
int H5IO::createdataspace(int rank,CONST int *dims){
if(dataspacevalid && rankf==(hsize_t) rank){
// lets compare dims
@@ -170,8 +174,8 @@ int H5IO::createdatatype(IObase::DataType dt){
int H5IO::selectdataset(int i){
// printf("datasetvalid=%u i=%d index=%d nitems=%d\n",datasetvalid,i,index,nitems);
-
- if(index==i && datasetvalid)
+
+ if(index==i && datasetvalid)
return index;
index=i;
if(index>=nitems) index=nitems-1;
@@ -201,23 +205,23 @@ int H5IO::selectdataset(int i){
}
herr_t H5IOcounter(hid_t group_id,
- const char *member_name,
- void *operator_data){
+ const char *member_name,
+ void *operator_data){
int *count = (int*)operator_data;
/* typedef struct H5G_stat_t {
unsigned long fileno[2];
- unsigned long objno[2];
- unsigned nlink;
- int type;
- time_t mtime;
+ unsigned long objno[2];
+ unsigned nlink;
+ int type;
+ time_t mtime;
size_t linklen;
} H5G_stat_t */
H5G_stat_t objinfo;
// request info about the type of objects in root group
- if(H5Gget_objinfo(group_id,
- member_name,
- 1 /* follow links */,
- &objinfo)<0) {
+ if(H5Gget_objinfo(group_id,
+ member_name,
+ 1 /* follow links */,
+ &objinfo)<0) {
//fprintf(stderr,"\tcounter: Bad Info [%s] count=%u\n",member_name,*count);
return 0; // error (probably bad symlink)
}
@@ -247,7 +251,7 @@ herr_t H5IOgetname(hid_t group_id,
1 /* follow links */,
&objinfo)<0) return 0; // error (probably bad symlink)
// only count objects that are datasets (not subgroups)
- if(objinfo.type!=H5G_DATASET)
+ if(objinfo.type!=H5G_DATASET)
return 0; // do not increment count if it isn't a dataset.
if(getn->index==getn->count){
strcpy(getn->name,member_name);
@@ -355,7 +359,16 @@ H5IO::H5IO(CONST char *fname,AccessMode access):IObase(fname,access),filevalid(0
nitems = 0;
switch(accessmode){
case Read:
+#ifdef WITH_HDF5WRAP
+ {
+hid_t proplist = H5Pcreate (H5P_FILE_ACCESS);
+ HDF5Open(filename, proplist);
+ file = H5Fopen(filename, H5F_ACC_RDONLY, proplist);
+ H5Pclose (proplist);
+ }
+#else
file=H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
+#endif
if (file >= 0) nitems = getndatasets();
break;
case Write:
@@ -402,7 +415,7 @@ int H5IO::write(IObase::DataType typeID,int rank,CONST int *dims,const void *dat
//}
int H5IO::readInfo(char *name,IObase::DataType &typeID,int &rank,int *dims,int maxdims){
-
+
// name shouls be attribute "long_name");
if(hasread){
//printf("hasread=1, so get next dataset index %u\n",index+1);
@@ -494,7 +507,7 @@ int H5IO::readAnnotation(int number,char *annotation,int maxlen){
#endif
if(maxlen>30)
sprintf(annotation,"not-implemented");
- else if(annotation)
+ else if(annotation)
*annotation=0;
return 1;
}
@@ -505,7 +518,7 @@ int H5IO::nAnnotations(){
select(index);
int32 ref=SDidtoref(sid);
if(DFANgetlablen(filename,DFTAG_NDG,ref)<=0) return 0; // no labels found
- return 1; // always 1 annotation per object limit for H5 is appears
+ return 1; // always 1 annotation per object limit for H5 is appears
#endif
return 0;
}
@@ -515,6 +528,15 @@ int H5IO::writeAttribute(CONST char *name,IObase::DataType typeID,Long length,co
selectdataset(index); // make sure it is selected
//printf("\tindex=%u\n",index);
// create a datashape
+#if 0
+ hsize_t dimsa[2]={0,0};
+ dimsa[0]=length;
+ hid_t shape = H5Screate_simple(1, dimsa, NULL);
+ hid_t attrib = H5Acreate(dataset,name,DataType2H5(typeID),shape,H5P_DEFAULT);
+ H5Awrite(attrib, DataType2H5(typeID), const_cast<void*>(data) );
+ H5Aclose(attrib);
+ H5Sclose(shape);
+#else
hid_t datatype = DataType2H5(typeID);
int is_string = datatype == H5T_NATIVE_CHAR;
if (is_string)
@@ -535,6 +557,7 @@ int H5IO::writeAttribute(CONST char *name,IObase::DataType typeID,Long length,co
{
H5Tclose (datatype);
}
+#endif
return 1;
}
@@ -544,6 +567,19 @@ int H5IO::readAttributeInfo(int number,char *name,IObase::DataType &typeID,Long
hid_t atype = H5Aget_type(attrib);
hid_t ashape = H5Aget_space(attrib);
H5Aget_name(attrib,maxnamelen,name);
+#if 0
+ /* hsize_t ranka = */ H5Sget_simple_extent_ndims(ashape);
+ // rank should always be 1;
+ hsize_t dimsa[5]={0,0,0,0,0},ndimsa=0,npointsa;
+ if(H5Sget_simple_extent_dims(ashape,dimsa,NULL)<0) dimsa[0]=0;
+ ndimsa=H5Sget_simple_extent_ndims(ashape);
+ npointsa=H5Sget_simple_extent_npoints(ashape);
+ // fprintf(stderr,"dimsa[0]=%d ndimsa=%d npoints=%u\n",dimsa[0],ndimsa,npointsa);
+ typeID = H5DataType2DataType(atype);
+ if(typeID==Char8 && dimsa[0]==0) // special case for strings
+ dimsa[0] = H5Tget_size(atype);
+ nelem = dimsa[0]; // single-dimensional array for attributes
+#else
// rank should always be 0 for scalars and 1 for arrays;
hsize_t arank = H5Sget_simple_extent_ndims(ashape);
hsize_t adims;
@@ -558,7 +594,7 @@ int H5IO::readAttributeInfo(int number,char *name,IObase::DataType &typeID,Long
{
nelem = H5Tget_size(atype);
}
-
+#endif
H5Tclose(atype);
H5Sclose(ashape);
H5Aclose(attrib);
@@ -574,7 +610,7 @@ herr_t H5IOattr_name2index(hid_t group_id,
void *operator_data){
H5IOatt_name2index_t *s=(H5IOatt_name2index_t*)operator_data;
s->count++;
- if(!strcmp(member_name,s->name))
+ if(!strcmp(member_name,s->name))
return s->count;
else{
return 0;
@@ -602,21 +638,15 @@ int H5IO::readAttributeInfo(CONST char *name,IObase::DataType &typeID,Long &nele
hid_t attrib = H5Aopen_name(dataset,name);
hid_t atype = H5Aget_type(attrib);
hid_t ashape = H5Aget_space(attrib);
- // rank should always be 0 for scalars and 1 for arrays;
- hsize_t arank = H5Sget_simple_extent_ndims(ashape);
- hsize_t adims;
- if ((arank != 0 && arank != 1) ||
- H5Sget_simple_extent_dims (ashape, &adims, NULL) < 0)
- {
- return (0);
- }
+ /* hsize_t ranka = */ H5Sget_simple_extent_ndims(ashape);
+ // rank should always be 1;
+ hsize_t dimsa[5];
+ H5Sget_simple_extent_dims(ashape,dimsa,NULL);
typeID = H5DataType2DataType(atype);
- nelem = arank ? adims : 1; // single-dimensional array for attributes
- if (H5Tget_class (atype) == H5T_STRING)
- {
- nelem = H5Tget_size(atype);
- }
-
+ if(typeID==Char8 && dimsa[0]==0) // special case for strings
+ dimsa[0] = H5Tget_size(atype);
+ nelem = dimsa[0]; // single-dimensional array for attributes
+
H5Tclose(atype);
H5Sclose(ashape);
H5Aclose(attrib);
@@ -655,7 +685,7 @@ int H5IO::reserveChunk(IObase::DataType typeID,int rank,CONST int *dims){
create(rank,dims,typeID);
current_rank=rank;
return 1;
-#endif
+#endif
return 1;
}
@@ -703,7 +733,7 @@ Long8 f_h5_open (char *file,char *accessname,int flen,int alen){
return 0;
}
IObase *fid=new H5IO(file,mode);
- if(fid->isValid())
+ if(fid->isValid())
return (Long8)fid;
else
delete fid; // file open failed