diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-07-06 19:45:35 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-07-06 19:45:35 (GMT) |
commit | 98754fa9d12090f5e048fdb05cc5e9ce9111676f (patch) | |
tree | 407e611b19ee551d8153779104022dd886a467e5 /hl/src | |
parent | 29321bcafa9f1c6108bb92b5a844a9d4d9c2c8e7 (diff) | |
download | hdf5-98754fa9d12090f5e048fdb05cc5e9ce9111676f.zip hdf5-98754fa9d12090f5e048fdb05cc5e9ce9111676f.tar.gz hdf5-98754fa9d12090f5e048fdb05cc5e9ce9111676f.tar.bz2 |
[svn-r19050] Description:
Bring r18704:19049 from trunk to revise_chunks branch.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in debug mode
Mac OS X/32 10.6.3 (amazon) in debug mode
Mac OS X/32 10.6.3 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Diffstat (limited to 'hl/src')
-rw-r--r-- | hl/src/CMakeLists.txt | 67 | ||||
-rw-r--r-- | hl/src/H5DS.c | 303 | ||||
-rw-r--r-- | hl/src/H5DSprivate.h | 1 | ||||
-rw-r--r-- | hl/src/Makefile.in | 4 |
4 files changed, 218 insertions, 157 deletions
diff --git a/hl/src/CMakeLists.txt b/hl/src/CMakeLists.txt new file mode 100644 index 0000000..6042853 --- /dev/null +++ b/hl/src/CMakeLists.txt @@ -0,0 +1,67 @@ +cmake_minimum_required (VERSION 2.8) +PROJECT (HDF5_HL_SRC) + +#----------------------------------------------------------------------------- +# Shared Libs +#----------------------------------------------------------------------------- +IF (BUILD_SHARED_LIBS) + SET (HL_BUILT_AS_DYNAMIC_LIB 1) +ENDIF (BUILD_SHARED_LIBS) + +#----------------------------------------------------------------------------- +# List Source files +#----------------------------------------------------------------------------- +INCLUDE_DIRECTORIES (${HDF5_HL_SOURCE_DIR}/src) + +SET (HL_SRCS + ${HDF5_HL_SRC_SOURCE_DIR}/H5DS.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5IM.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5LT.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5LTanalyze.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5LTparse.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5PT.c + ${HDF5_HL_SRC_SOURCE_DIR}/H5TB.c +) + +SET (HL_HEADERS + ${HDF5_HL_SRC_SOURCE_DIR}/H5DSpublic.h + ${HDF5_HL_SRC_SOURCE_DIR}/H5IMpublic.h + ${HDF5_HL_SRC_SOURCE_DIR}/H5LTparse.h + ${HDF5_HL_SRC_SOURCE_DIR}/H5LTpublic.h + ${HDF5_HL_SRC_SOURCE_DIR}/H5PTpublic.h + ${HDF5_HL_SRC_SOURCE_DIR}/H5TBpublic.h + ${HDF5_HL_SRC_SOURCE_DIR}/hdf5_hl.h +) + +ADD_LIBRARY (${HDF5_HL_LIB_TARGET} ${LIB_TYPE} ${HL_SRCS} ${HL_HEADERS}) +SET_TARGET_PROPERTIES(${HDF5_HL_LIB_TARGET} PROPERTIES DEFINE_SYMBOL ${HDF5_HL_LIB_CORENAME}_EXPORTS) +TARGET_LINK_LIBRARIES (${HDF5_HL_LIB_TARGET} ${HDF5_LIB_TARGET}) +SET_GLOBAL_VARIABLE (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_HL_LIB_TARGET}") +H5_SET_LIB_OPTIONS (${HDF5_HL_LIB_TARGET} ${HDF5_HL_LIB_NAME} ${LIB_TYPE}) + +#----------------------------------------------------------------------------- +# Add file(s) to CMake Install +#----------------------------------------------------------------------------- +INSTALL ( + FILES + ${HL_HEADERS} + DESTINATION + include + COMPONENT + hlheaders +) + +#----------------------------------------------------------------------------- +# Add Target(s) to CMake Install for import into other projects +#----------------------------------------------------------------------------- +IF (HDF5_EXPORTED_TARGETS) + INSTALL ( + TARGETS + ${HDF5_HL_LIB_TARGET} + EXPORT + ${HDF5_EXPORTED_TARGETS} + LIBRARY DESTINATION lib COMPONENT hllibraries + ARCHIVE DESTINATION lib COMPONENT hllibraries + RUNTIME DESTINATION bin COMPONENT hllibraries + ) +ENDIF (HDF5_EXPORTED_TARGETS) diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 245a2c5..faa6d30 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -132,7 +132,7 @@ herr_t H5DSattach_scale(hid_t did, hid_t ntid = -1; /* attribute native type ID */ hid_t aid = -1; /* attribute ID */ int rank; /* rank of dataset */ - hsize_t *dims=NULL; /* dimension of the "REFERENCE_LIST" array */ + hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */ ds_list_t dsl; /* attribute data in the DS pointing to the dataset */ ds_list_t *dsbuf=NULL; /* array of attribute data in the DS pointing to the dataset */ hobj_ref_t ref_to_ds; /* reference to the DS */ @@ -238,11 +238,6 @@ herr_t H5DSattach_scale(hid_t did, */ if (has_dimlist == 0) { - /* create one entry array */ - dims = (hsize_t*) malloc (1 * sizeof (hsize_t)); - - if(dims == NULL) - return FAIL; dims[0] = rank; @@ -288,11 +283,6 @@ herr_t H5DSattach_scale(hid_t did, if (H5Aclose(aid) < 0) goto out; - if (dims) - { - free(dims); - dims = NULL; - } if (buf) { free(buf); @@ -411,11 +401,6 @@ herr_t H5DSattach_scale(hid_t did, */ if (has_reflist == 0) { - /* create one entry array */ - dims = (hsize_t*) malloc (1 * sizeof (hsize_t)); - - if (dims == NULL) - goto out; dims[0] = 1; @@ -454,11 +439,6 @@ herr_t H5DSattach_scale(hid_t did, if(H5Aclose(aid) < 0) goto out; - if(dims) - { - free(dims); - dims = NULL; - } } /*------------------------------------------------------------------------- @@ -474,7 +454,8 @@ herr_t H5DSattach_scale(hid_t did, if((tid = H5Aget_type(aid)) < 0) goto out; - if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0) + /* get native type to read attribute REFERENCE_LIST */ + if((ntid = H5DS_get_REFLIST_type()) < 0) goto out; /* get and save the old reference(s) */ @@ -499,8 +480,6 @@ herr_t H5DSattach_scale(hid_t did, goto out; if (H5Aclose(aid) < 0) goto out; - if (H5Tclose(ntid) < 0) - goto out; /*------------------------------------------------------------------------- * create a new attribute @@ -516,26 +495,17 @@ herr_t H5DSattach_scale(hid_t did, dsbuf[nelmts-1] = dsl; /* create a new data space for the new references array */ - dims = (hsize_t *)malloc((size_t)nelmts * sizeof(hsize_t)); - if(dims == NULL) - goto out; dims[0] = nelmts; if((sid = H5Screate_simple(1, dims, NULL)) < 0) goto out; - if (dims) - { - free(dims); - dims = NULL; - } - /* create the attribute again with the changes of space */ if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; /* write the attribute with the new references */ - if(H5Awrite(aid, tid, dsbuf) < 0) + if(H5Awrite(aid, ntid, dsbuf) < 0) goto out; /* close */ @@ -545,6 +515,8 @@ herr_t H5DSattach_scale(hid_t did, goto out; if(H5Aclose(aid) < 0) goto out; + if (H5Tclose(ntid) < 0) + goto out; if (dsbuf) { @@ -573,11 +545,6 @@ herr_t H5DSattach_scale(hid_t did, /* error zone */ out: - if (dims) - { - free(dims); - dims = NULL; - } if (buf) { free(buf); @@ -620,9 +587,11 @@ out: * * Date: December 20, 2004 * -* Comments: +* Comments: * -* Modifications: +* Modifications: Function didn't delete DIMENSION_LIST attribute, when +* all dimension scales were detached from a dataset; added. +* 2010/05/13 EIP * *------------------------------------------------------------------------- */ @@ -642,14 +611,15 @@ herr_t H5DSdetach_scale(hid_t did, hid_t aid = -1; /* attribute ID */ int rank; /* rank of dataset */ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */ - ds_list_t *dsbufn = NULL; /* array of attribute data in the DS pointing to the dataset */ - hsize_t *dims = NULL; /* dimension of the "REFERENCE_LIST" array */ + hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */ hobj_ref_t ref; /* reference to the DS */ hvl_t *buf = NULL; /* VL buffer to store in the attribute */ - unsigned i, j, jj; - H5O_info_t oi1, oi2, oi3, oi4; + int i; + size_t j; + hssize_t ii; + H5O_info_t did_oi, dsid_oi, tmp_oi; int found_dset = 0, found_ds = 0; - H5I_type_t it1, it2; + int have_ds = 0; htri_t is_scale; /*------------------------------------------------------------------------- @@ -657,32 +627,28 @@ herr_t H5DSdetach_scale(hid_t did, *------------------------------------------------------------------------- */ - if ((is_scale = H5DSis_scale(did)) < 0) + /* check for valid types of identifiers */ + + if(H5I_DATASET!=H5Iget_type(did) || H5I_DATASET!=H5Iget_type(dsid)) + return FAIL; + + if((is_scale = H5DSis_scale(did)) < 0) return FAIL; /* the dataset cannot be a DS dataset */ - if ( is_scale == 1) + if( is_scale == 1) return FAIL; /* get info for the dataset in the parameter list */ - if(H5Oget_info(did, &oi1) < 0) + if(H5Oget_info(did, &did_oi) < 0) return FAIL; /* get info for the scale in the parameter list */ - if(H5Oget_info(dsid, &oi2) < 0) + if(H5Oget_info(dsid, &dsid_oi) < 0) return FAIL; /* same object, not valid */ - if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr) - return FAIL; - - /* get ID type */ - if ((it1 = H5Iget_type(did)) < 0) - return FAIL; - if ((it2 = H5Iget_type(dsid)) < 0) - return FAIL; - - if (H5I_DATASET!=it1 || H5I_DATASET!=it2) + if(did_oi.fileno == dsid_oi.fileno && did_oi.addr == dsid_oi.addr) return FAIL; @@ -761,46 +727,62 @@ herr_t H5DSdetach_scale(hid_t did, if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref)) < 0) goto out; - /* get info for DS in the parameter list */ - if(H5Oget_info(dsid, &oi1) < 0) + /* get info for this DS */ + if(H5Oget_info(dsid_j, &tmp_oi) < 0) goto out; - /* get info for this DS */ - if(H5Oget_info(dsid_j, &oi2) < 0) + /* Close the dereferenced dataset */ + if (H5Dclose(dsid_j) < 0) goto out; /* same object, reset */ - if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr) + if(dsid_oi.fileno == tmp_oi.fileno && dsid_oi.addr == tmp_oi.addr) { - size_t len; - - for(jj=j; jj<buf[idx].len-1; jj++) - { - ((hobj_ref_t *)buf[idx].p)[jj] = ((hobj_ref_t *)buf[idx].p)[jj+1]; + /* If there are more than one reference in the VL element + and the reference we found is not the last one, + copy the last one to replace the found one since the order + of the references doesn't matter according to the spec; + reduce the size of the VL element by 1; + if the length of the element becomes 0, free the pointer + and reset to NULL */ + + size_t len = buf[idx].len; + if(j<len-1) + ((hobj_ref_t *)buf[idx].p)[j] = ((hobj_ref_t *)buf[idx].p)[len-1]; + len = --buf[idx].len; + if(len == 0) { + free(buf[idx].p); + buf[idx].p = NULL; } - - buf[idx].len--; - len = buf[idx].len; - buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t)); - + /* Since a reference to a dim. scale can be inserted only once, + we do not need to continue the search if it is found */ found_ds = 1; - - /* close the dereferenced dataset and break */ - if (H5Dclose(dsid_j) < 0) - goto out; break; } - - /* close the dereferenced dataset */ - if (H5Dclose(dsid_j) < 0) - goto out; } /* j */ } /* if */ - /* write the attribute */ - if (H5Awrite(aid,tid,buf) < 0) + /* the scale must be present to continue */ + if(found_ds == 0) goto out; + /* Write the attribute, but check first, if we have any scales left, + because if not, we should delete the attribute according to the spec */ + for(i=0; i < rank; i++) { + if(buf[i].len > 0) { + have_ds = 1; + break; + } + } + if(have_ds) { + if(H5Awrite(aid,tid,buf) < 0) + goto out; + } + else { + if(H5Adelete(did,DIMENSION_LIST) < 0) + goto out; + } + /* close */ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0) goto out; @@ -817,9 +799,6 @@ herr_t H5DSdetach_scale(hid_t did, buf = NULL; } - /* the scale must be present */ - if(found_ds == 0) - goto out; /*------------------------------------------------------------------------- * the "REFERENCE_LIST" array exists, update @@ -832,7 +811,8 @@ herr_t H5DSdetach_scale(hid_t did, if((tid = H5Aget_type(aid)) < 0) goto out; - if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0) + /* get native type to read attribute REFERENCE_LIST */ + if((ntid = H5DS_get_REFLIST_type()) < 0) goto out; /* get and save the old reference(s) */ @@ -849,49 +829,42 @@ herr_t H5DSdetach_scale(hid_t did, if (H5Aread(aid,ntid,dsbuf) < 0) goto out; - for(i=0; i<nelmts; i++) - { - /* get the reference to the dataset */ - ref = dsbuf[i].ref; - - /* get the dataset id */ - if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0) - goto out; - - /* get info for dataset in the parameter list */ - if(H5Oget_info(did, &oi3) < 0) - goto out; - - /* get info for this dataset */ - if(H5Oget_info(did_i, &oi4) < 0) - goto out; + for(ii=0; ii<nelmts; ii++) { + /* First check if we have the same dimension index */ + if((int)idx == dsbuf[ii].dim_idx) { + /* get the reference to the dataset */ + ref = dsbuf[ii].ref; - /* same object, reset. we want to detach only for this DIM */ - if(oi3.fileno == oi4.fileno && oi3.addr == oi4.addr && (int)idx == dsbuf[i].dim_idx) { - for(jj=i; jj<nelmts-1; jj++) - dsbuf[jj] = dsbuf[jj+1]; - nelmts--; - found_dset=1; + /* get the dataset id */ + if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0) + goto out; - /* close the dereferenced dataset and break */ - if (H5Dclose(did_i) < 0) + /* get info for this dataset */ + if(H5Oget_info(did_i, &tmp_oi) < 0) goto out; - break; - } /* if */ - /* close the dereferenced dataset */ - if (H5Dclose(did_i) < 0) - goto out; + /* close the dereferenced dataset */ + if(H5Dclose(did_i) < 0) + goto out; - } /* i */ + /* same object, reset. we want to detach only for this DIM */ + if(did_oi.fileno == tmp_oi.fileno && did_oi.addr == tmp_oi.addr) { + /* if we found not the last one, copy the last one to replace + the one which is found */ + if(i < nelmts-1) + dsbuf[ii] = dsbuf[nelmts-1]; + nelmts--; + found_dset=1; + break; + } /* if */ + } /* if we have the same dimension index */ + } /* ii */ /* close space and attribute */ if (H5Sclose(sid) < 0) goto out; if (H5Aclose(aid) < 0) goto out; - if (H5Tclose(ntid) < 0) - goto out; /*------------------------------------------------------------------------- * check if we found the pointed dataset @@ -915,19 +888,8 @@ herr_t H5DSdetach_scale(hid_t did, if(nelmts) { /* create a new data space for the new references array */ - dims = (hsize_t*)malloc((size_t)nelmts * sizeof (hsize_t)); - if(dims == NULL) - goto out; dims[0] = nelmts; - dsbufn = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t)); - if(dsbufn == NULL) - goto out; - - /* store the new information */ - for(i = 0; i < nelmts; i++) - dsbufn[i] = dsbuf[i]; - if((sid = H5Screate_simple(1, dims, NULL)) < 0) goto out; @@ -936,7 +898,7 @@ herr_t H5DSdetach_scale(hid_t did, goto out; /* write the new attribute with the new references */ - if(H5Awrite(aid, tid, dsbufn) < 0) + if(H5Awrite(aid, ntid, dsbuf) < 0) goto out; /* close space and attribute */ @@ -949,22 +911,14 @@ herr_t H5DSdetach_scale(hid_t did, /* close type */ if (H5Tclose(tid) < 0) goto out; + if (H5Tclose(ntid) < 0) + goto out; if (dsbuf) { free(dsbuf); dsbuf=NULL; } - if (dsbufn) - { - free(dsbufn); - dsbufn=NULL; - } - if (dims) - { - free(dims); - dims=NULL; - } return SUCCEED; @@ -982,18 +936,14 @@ out: free(dsbuf); dsbuf=NULL; } - if (dsbufn) - { - free(dsbufn); - dsbufn=NULL; - } - if (dims) - { - free(dims); - dims=NULL; - } if (buf) { + /* Failure occured before H5Dvlen_reclaim was called; + free the pointers allocated when we read data in */ + for(i=0; i<rank; i++) { + if(buf[i].p) + free(buf[i].p); + } free(buf); buf=NULL; } @@ -1203,7 +1153,8 @@ htri_t H5DSis_attached(hid_t did, if((tid = H5Aget_type(aid)) < 0) goto out; - if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0) + /* get native type to read REFERENCE_LIST attribute */ + if((ntid = H5DS_get_REFLIST_type()) < 0) goto out; /* get and save the old reference(s) */ @@ -1218,7 +1169,7 @@ htri_t H5DSis_attached(hid_t did, if (dsbuf == NULL) goto out; - if (H5Aread(aid,ntid,dsbuf) < 0) + if (H5Aread(aid,ntid,dsbuf) < 0) goto out; /*------------------------------------------------------------------------- @@ -1284,6 +1235,7 @@ out: H5Sclose(sid); H5Aclose(aid); H5Tclose(tid); + H5Tclose(ntid); } H5E_END_TRY; if (buf) @@ -2269,6 +2221,47 @@ out: return FAIL; } +/*------------------------------------------------------------------------- +* Function: H5DS_get_REFLIST_type +* +* Purpose: This is a helper function to return a native type for +* the REFERENCE_LIST attribute. +* +* Return: Type identifier on success and negative on failure +* +* Programmer: epourmal@hdfgroup.org +* +* Date: May 22, 2010 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ +hid_t H5DS_get_REFLIST_type(void) +{ + hid_t ntid_t = -1; + + /* Build native type that corresponds to compound datatype + used to store ds_list_t structure in the REFERENCE_LIST + attribute */ + + if((ntid_t = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0) + goto out; + if(H5Tinsert(ntid_t, "dataset", HOFFSET(ds_list_t,ref), H5T_STD_REF_OBJ) < 0) + goto out; + + if(H5Tinsert(ntid_t, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_INT) < 0) + goto out; + + return ntid_t; +out: + H5E_BEGIN_TRY { + H5Tclose(ntid_t); + } H5E_END_TRY; + return FAIL; +} diff --git a/hl/src/H5DSprivate.h b/hl/src/H5DSprivate.h index 9d921b3..5094208 100644 --- a/hl/src/H5DSprivate.h +++ b/hl/src/H5DSprivate.h @@ -38,6 +38,7 @@ typedef struct ds_list_t { */ H5_HLDLL herr_t H5DS_is_reserved( hid_t did); +H5_HLDLL hid_t H5DS_get_REFLIST_type(void); #endif diff --git a/hl/src/Makefile.in b/hl/src/Makefile.in index 10027e3..e22494e 100644 --- a/hl/src/Makefile.in +++ b/hl/src/Makefile.in @@ -211,12 +211,12 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTRUMENT = @INSTRUMENT@ INSTRUMENT_LIBRARY = @INSTRUMENT_LIBRARY@ +LARGEFILE = @LARGEFILE@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ -LINUX_LFS = @LINUX_LFS@ LIPO = @LIPO@ LL_PATH = @LL_PATH@ LN_S = @LN_S@ @@ -380,7 +380,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Add libtool shared library version numbers to the HDF5 library # See libtool versioning documentation online. LT_VERS_INTERFACE = 6 -LT_VERS_REVISION = 59 +LT_VERS_REVISION = 63 LT_VERS_AGE = 0 # This library is our main target. |