aboutsummaryrefslogtreecommitdiff
path: root/src/H5IO.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5IO.cc')
-rw-r--r--src/H5IO.cc91
1 files changed, 70 insertions, 21 deletions
diff --git a/src/H5IO.cc b/src/H5IO.cc
index c611f0b..b4fd238 100644
--- a/src/H5IO.cc
+++ b/src/H5IO.cc
@@ -43,10 +43,11 @@ IObase::DataType H5IO::H5DataType2DataType(hid_t nt){
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);
+ // printf("Int %d bytes\n",typesize);
switch(typesize){
case 1:
return Int8;
@@ -78,17 +79,18 @@ IObase::DataType H5IO::H5DataType2DataType(hid_t nt){
puts("Cannot convert type Time");
break;
case H5T_STRING:
+ return Char8;
//puts("String");
- switch(typesize){
- case 1:
- return Char8;
- case 2:
- return Char16;
- default:
- printf("Cannot convert type for string element with %d bytes\n",
- typesize);
- break;
- }
+ //switch(typesize){
+ //case 1:
+ // return Char8;
+ //case 2:
+ // return Char16;
+ //default:
+ // printf("Cannot convert type for string element with %d bytes\n",
+ // typesize);
+ // break;
+ //}
break;
case H5T_BITFIELD:
puts("Cannot convert type Bitfield");
@@ -177,9 +179,9 @@ int H5IO::selectdataset(int i){
// must iterate to select or for now just
char dataname[128];
//char dataname2[128];
- sprintf(dataname,"H5IO-Dataset%09u",index); // was a KLUDGE!
- //getdatasetname(index,dataname2);
- //printf("Datasetname for dataset[%u]=[%s] [%s]\n",index,dataname,dataname2);
+ //sprintf(dataname,"H5IO-Dataset%09u",index); // was a KLUDGE!
+ getdatasetname(index,dataname);
+ //fprintf(stderr,"Datasetname for dataset[%u]=[%s] [%s]\n",index,dataname,dataname2);
enddataset(); // close current dataset
dataset = H5Dopen(file,dataname); // open a dataset
if(!dataset) puts("error no dataset");
@@ -202,7 +204,30 @@ herr_t H5IOcounter(hid_t group_id,
const char *member_name,
void *operator_data){
int *count = (int*)operator_data;
- (*count)++;
+ /* typedef struct H5G_stat_t {
+ unsigned long fileno[2];
+ 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) {
+ //fprintf(stderr,"\tcounter: Bad Info [%s] count=%u\n",member_name,*count);
+ return 0; // error (probably bad symlink)
+ }
+ // only count objects that are datasets (not subgroups)
+ if(objinfo.type==H5G_DATASET){
+ // fprintf(stderr,"\tcounter: This is a dataset [%s] count=%u\n",member_name,*count);
+ (*count)++;
+ }
+ else
+ // fprintf(stderr,"\tcounter: **reject dataset [%s] count=%u\n",member_name,*count);
return 0;
}
@@ -214,6 +239,16 @@ herr_t H5IOgetname(hid_t group_id,
const char *member_name,
void *operator_data){
H5IO_getname_t *getn = (H5IO_getname_t*)operator_data;
+ // check type first (only respond if it is a dataset)
+ 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) return 0; // error (probably bad symlink)
+ // only count objects that are datasets (not subgroups)
+ 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);
return 1; // success
@@ -234,6 +269,7 @@ int H5IO::getndatasets(){
//printf("getndatasets: nitems{%d}!=count{%d}\n",
// nitems,count);
//}
+ //fprintf(stderr,"getndatasets:=%u\n",count);
nitems = count; // just for internal bookkeeping
return count;
}
@@ -442,7 +478,9 @@ int H5IO::readAnnotationInfo(int number,int &length){
length=(int)DFANgetlablen(filename,DFTAG_NDG,ref);
return length;
#endif
- return 1;
+ // sprintf(annotation,"not-implemented");
+ length=0;
+ return 0;
}
int H5IO::readAnnotation(int number,char *annotation,int maxlen){
@@ -454,6 +492,10 @@ int H5IO::readAnnotation(int number,char *annotation,int maxlen){
int32 ref=SDidtoref(sid);
return (int)DFANgetlabel(filename,DFTAG_NDG,ref,annotation,maxlen);
#endif
+ if(maxlen>30)
+ sprintf(annotation,"not-implemented");
+ else if(annotation)
+ *annotation=0;
return 1;
}
@@ -465,7 +507,7 @@ int H5IO::nAnnotations(){
if(DFANgetlablen(filename,DFTAG_NDG,ref)<=0) return 0; // no labels found
return 1; // always 1 annotation per object limit for H5 is appears
#endif
- return 1;
+ return 0;
}
int H5IO::writeAttribute(CONST char *name,IObase::DataType typeID,Long length,const void *data){
@@ -491,9 +533,14 @@ int H5IO::readAttributeInfo(int number,char *name,IObase::DataType &typeID,Long
H5Aget_name(attrib,maxnamelen,name);
/* 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);
+ 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
H5Tclose(atype);
@@ -544,6 +591,8 @@ int H5IO::readAttributeInfo(CONST char *name,IObase::DataType &typeID,Long &nele
hsize_t dimsa[5];
H5Sget_simple_extent_dims(ashape,dimsa,NULL);
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
H5Tclose(atype);
@@ -557,7 +606,7 @@ int H5IO::readAttribute(int number,void *data){
selectdataset(index); // just to be sure we've got data
hid_t attrib = H5Aopen_idx(dataset,number);
hid_t atype = H5Aget_type(attrib);
- H5Aread(attrib,DataType2H5(H5DataType2DataType(atype)),data);
+ H5Aread(attrib,atype /*DataType2H5(H5DataType2DataType(atype))*/ ,data);
H5Tclose(atype);
H5Aclose(attrib);
return 1;