From 44f6a3df3291a764e4cf781f637bb7f3fbd0d25e Mon Sep 17 00:00:00 2001 From: tradke Date: Wed, 16 Jul 2003 12:25:20 +0000 Subject: Sync with cvs.cactuscode.org:/packages/FlexIO. Mainly adding debug statements. One important fix for AMRwriter.cc to get the min_ext[] and grid_placement_refinement[] attributes right again. git-svn-id: http://svn.cactuscode.org/arrangements/CactusExternal/FlexIO/trunk@46 21a6bef8-4479-4f54-8f8d-0db94a2919ef --- src/AMRwriter.cc | 16 +++++---- src/AmrFileReader.cc | 2 ++ src/AmrGridReader.cc | 2 +- src/H5IO.cc | 91 ++++++++++++++++++++++++++++++++++++++++------------ src/IEEEIO.cc | 39 ++++++++++++++++++---- src/IO.cc | 26 +++++++++++++++ 6 files changed, 140 insertions(+), 36 deletions(-) diff --git a/src/AMRwriter.cc b/src/AMRwriter.cc index d46b57a..3f76648 100644 --- a/src/AMRwriter.cc +++ b/src/AMRwriter.cc @@ -20,6 +20,7 @@ void AMRwriter::writeAMRattributes(){ // compute persistence persistence = levels[levels.getSize()-currentlevel-1].trefine; + if(persistence<=0) { fprintf(stderr,"Refinement *must* be >1... this isn't right!!!\n"); persistence=1;} level_timestep = currentstep/persistence; // compute from min-ext... // y-know... there is more point density near 0 in the float @@ -36,7 +37,7 @@ void AMRwriter::writeAMRattributes(){ for(int i=0;isetType(IObase::Int2DataType(numbertype)); } -void AMRsetToplevelParameters(AMRFile afile,int rank, double *origin, +void AMRsetTopLevelParameters(AMRFile afile,int rank, double *origin, double *delta, double timestep,int maxdepth){ AMRwriter *w = (AMRwriter*)afile; w->setTopLevelParameters(rank,origin,delta,timestep,maxdepth); @@ -302,12 +304,12 @@ void AMRsetScalarLevelRefinement(AMRFile afile,int level, w->setLevelRefinement(level,timerefinement,spatialrefinement,gridplacementrefinement); } -void AMRlevel(AMRFile afile,int level){ +void AMRsetLevel(AMRFile afile,int level){ AMRwriter *w = (AMRwriter*)afile; w->setLevel(level); } -void AMRtime(AMRFile afile,int time){ +void AMRsetTime(AMRFile afile,int time){ AMRwriter *w = (AMRwriter*)afile; w->setTime(time); } diff --git a/src/AmrFileReader.cc b/src/AmrFileReader.cc index 6047ce0..4207210 100644 --- a/src/AmrFileReader.cc +++ b/src/AmrFileReader.cc @@ -47,7 +47,9 @@ void AmrFileReader::buildInfoTable(){ grids.append(g); if(g.level>maxlevel) maxlevel=g.level; + printf("Gridnum[%u] timestep=%u\n",i,g.timestep); if(!i){ + printf("i=%u INITIALIZE TIME*********************\n",i); mintime = g.timestep; maxtime = g.timestep; maxtimeres = g.timerefinement; diff --git a/src/AmrGridReader.cc b/src/AmrGridReader.cc index 3ea8f90..a7eba1e 100644 --- a/src/AmrGridReader.cc +++ b/src/AmrGridReader.cc @@ -77,7 +77,7 @@ AmrGrid *AmrGridReader::getGridInfo(AmrGrid &g,int index){ AmrGrid *AmrGridReader::getGridData(AmrGrid &g,int index){ IObase::DataType atype; - // if(data) free(data); data=0; // make certain it is empty first + if(g.data) free(g.data); g.data=0; // make certain it is empty first g.data = malloc(g.nbytes); file.seek(index); file.readInfo(atype,g.rank,g.dims); 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; diff --git a/src/IEEEIO.cc b/src/IEEEIO.cc index a71e381..c36751e 100644 --- a/src/IEEEIO.cc +++ b/src/IEEEIO.cc @@ -5,7 +5,7 @@ #ifdef WIN32 // Are we Microsoft VC++ 5.0 or 6.0? -#if defined(_MSC_VER) && ( (_MSC_VER == 1100) || (_MSC_VER == 1200) ) // yes we are +#if defined(_MSC_VER) && ( (_MSC_VER == 1100) || (_MSC_VER == 1200) || (_MSC_VER == 1300)) // yes we are #include #ifdef O_RDONLY #undef O_RDONLY @@ -1374,19 +1374,44 @@ Long8 f_ieee_open (char *file,char *accessname,int flen,int alen){ return 0; } +/* + Fortran passes strings without 0-bytes. + C requires a 0-byte at the end of a string. + We may not modify the passed string, because it + might reside in a read only text segment, thus + we need a local copy to append a 0-byte. + Performance is not an issue here, because file access + is much slower than this little memory shifting anyway. + */ + Long8 f_ieee_openr(char *filename,int namelen){ - filename[namelen]='\0'; - return (Long8)(new IEEEIO(filename,IObase::Read)); + +char*fn = new char[namelen+1]; + strncpy(fn, filename, namelen); + fn[namelen]='\0'; +Long8 ID = (Long8)(new IEEEIO(filename,IObase::Read)); + delete fn; + return ID; } Long8 f_ieee_openw(char *filename,int namelen){ - filename[namelen]='\0'; - return (Long8)(new IEEEIO(filename,IObase::Write)); + +char*fn = new char[namelen+1]; + strncpy(fn, filename, namelen); + fn[namelen]='\0'; +Long8 ID = (Long8)(new IEEEIO(filename,IObase::Write)); + delete fn; + return ID; } Long8 f_ieee_opena(char *filename,int namelen){ - filename[namelen]='\0'; - return (Long8)(new IEEEIO(filename,IObase::Append)); + +char*fn = new char[namelen+1]; + strncpy(fn, filename, namelen); + fn[namelen]='\0'; +Long8 ID = (Long8)(new IEEEIO(filename,IObase::Append)); + delete fn; + return ID; } void ieee_bufon(Long8 *fileID,int bufsize){ diff --git a/src/IO.cc b/src/IO.cc index c0860c1..622f2cd 100644 --- a/src/IO.cc +++ b/src/IO.cc @@ -126,8 +126,19 @@ int f_io_seek(Long8 *deviceID,int *dataset_index){ //--------------Annotations int f_io_writenote(Long8 *deviceID,char *annotation,int size){ IObase *dev=(IObase*)(*deviceID); +#if 0 annotation[size]='\0'; // Yeah! its unsafe I know..!! (but it works!) return dev->writeAnnotation(annotation); +#else + // well, the problem is that it does not work if the annotation + // string resides in a readonly text segment... (Werner) +char*ann = new char[size+1]; + strncpy(ann, annotation, size); + ann[size] = '\0'; +int i = dev->writeAnnotation(ann); + delete ann; + return i; +#endif } int f_io_readnote(Long8 *deviceID,int *idx,char *annotation,int maxsize){ @@ -149,10 +160,25 @@ int f_io_numnote(Long8 *deviceID){ int f_io_writeatt(Long8 *deviceID,char *name, int *datatype,Long *nelements,const void *data,int namesize){ IObase *dev=(IObase*)(*deviceID); +#if 0 name[namesize]='\0'; // cap name (to be certain).. unsafe but it works // should copy into a flexarray which will be destroyed on return IObase::DataType typeID = IObase::Int2DataType(*datatype); return dev->writeAttribute(name,typeID,*nelements,data); + +#else + // well, the problem is that it does not work if the annotation + // string resides in a readonly text segment... (Werner) +char*tmp = new char[namesize+1]; + strncpy(tmp, name, namesize); + tmp[namesize] = '\0'; + IObase::DataType typeID = IObase::Int2DataType(*datatype); +int i = dev->writeAttribute(tmp,typeID,*nelements,data); + delete tmp; + return i; +#endif + + } int f_io_attinfo(Long8 *deviceID,char *name, -- cgit v1.2.3