PyObject *get_filter_names( hid_t loc_id, const char *dset_name) { hid_t dset; hid_t dcpl; /* dataset creation property list */ /* hsize_t chsize[64]; /\* chunk size in elements *\/ */ int i, j; int nf; /* number of filters */ unsigned filt_flags; /* filter flags */ size_t cd_nelmts; /* filter client number of values */ unsigned cd_values[20]; /* filter client data values */ char f_name[256]; /* filter name */ PyObject *filters; PyObject *filter_values; /* Open the dataset. */ if ( (dset = H5Dopen( loc_id, dset_name, H5P_DEFAULT )) < 0 ) { goto out; } /* Get the properties container */ dcpl = H5Dget_create_plist(dset); /* Collect information about filters on chunked storage */ if (H5D_CHUNKED==H5Pget_layout(dcpl)) { filters = PyDict_New(); nf = H5Pget_nfilters(dcpl); if ((nf = H5Pget_nfilters(dcpl))>0) { for (i=0; i<nf; i++) { cd_nelmts = 20; H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts, cd_values, sizeof(f_name), f_name, NULL); filter_values = PyTuple_New(cd_nelmts); for (j=0;j<(long)cd_nelmts;j++) { PyTuple_SetItem(filter_values, j, PyInt_FromLong(cd_values[j])); } PyMapping_SetItemString (filters, f_name, filter_values); } } } else { /* http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52309 */ Py_INCREF(Py_None); filters = Py_None; /* Not chunked, so return None */ } H5Pclose(dcpl); H5Dclose(dset); return filters; out: H5Dclose(dset); Py_INCREF(Py_None); return Py_None; /* Not chunked, so return None */ }
//-------------------------------------------------------------------------- // Function: DSetCreatPropList::getFilter ///\brief Returns information about a filter in a pipeline ///\param filter_number - IN: Filter to get, range [0..N-1], where /// N is returned by H5Pget_nfilters() ///\param flags - OUT: General properties of the filter ///\param cd_nelmts - IN/OUT: Number of elements in \a cd_values /Number /// of values defined by the filter ///\param cd_values - OUT: Array to hold the data; allocated by the user ///\param namelen - OUT: Length of \a name ///\param name - OUT: Name of the filter ///\return Filter id ///\exception H5::PropListIException ///\par Description /// Failure occurs when \a filter_number is out of range. //-------------------------------------------------------------------------- H5Z_filter_t DSetCreatPropList::getFilter(int filter_number, unsigned int &flags, size_t &cd_nelmts, unsigned int* cd_values, size_t namelen, char name[] ) const { H5Z_filter_t filter_id; filter_id = H5Pget_filter( id, filter_number, &flags, &cd_nelmts, cd_values, namelen, name); if( filter_id == H5Z_FILTER_ERROR ) { throw PropListIException("DSetCreatPropList::getFilter", "H5Pget_filter returned H5Z_FILTER_ERROR"); } else return(filter_id); }
int has_filter(hid_t dcpl_id, H5Z_filter_t filtnin) { int nfilters; /* number of filters */ unsigned filt_flags; /* filter flags */ H5Z_filter_t filtn; /* filter identification number */ unsigned cd_values[20]; /* filter client data values */ size_t cd_nelmts; /* filter client number of values */ char f_name[256]; /* filter name */ int have=0; /* flag, filter is present */ int i; /* index */ /* if no information about the input filter is requested return exit */ if (filtnin==-1) return 1; /* get information about filters */ if ((nfilters = H5Pget_nfilters(dcpl_id))<0) return -1; /* if we do not have filters and the requested filter is NONE, return 1 */ if (!nfilters && filtnin==H5Z_FILTER_NONE) return 1; for (i=0; i<nfilters; i++) { cd_nelmts = NELMTS(cd_values); filtn = H5Pget_filter(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, cd_values, sizeof(f_name), f_name); if (filtnin==filtn) have=1; } return have; }
int print_filters(hid_t dcpl_id) { int nfilters; /* number of filters */ unsigned filt_flags; /* filter flags */ H5Z_filter_t filtn; /* filter identification number */ unsigned cd_values[20]; /* filter client data values */ size_t cd_nelmts; /* filter client number of values */ size_t cd_num; /* filter client data counter */ char f_name[256]; /* filter name */ char s[64]; /* temporary string buffer */ int i; /* get information about filters */ if ((nfilters = H5Pget_nfilters(dcpl_id))<0) return -1; for (i=0; i<nfilters; i++) { cd_nelmts = NELMTS(cd_values); filtn = H5Pget_filter(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, cd_values, sizeof(f_name), f_name); f_name[sizeof(f_name)-1] = '\0'; sprintf(s, "Filter-%d:", i); printf(" %-10s %s-%u %s {", s, f_name[0]?f_name:"method", (unsigned)filtn, filt_flags & H5Z_FLAG_OPTIONAL?"OPT":""); for (cd_num=0; cd_num<cd_nelmts; cd_num++) { printf("%s%u", cd_num?", ":"", cd_values[cd_num]); } printf("}\n"); } return 0; }
bool BAGRasterBand::Initialize( hid_t hDatasetID, const char *pszName ) { SetDescription( pszName ); this->hDatasetID = hDatasetID; hid_t datatype = H5Dget_type( hDatasetID ); dataspace = H5Dget_space( hDatasetID ); int n_dims = H5Sget_simple_extent_ndims( dataspace ); native = H5Tget_native_type( datatype, H5T_DIR_ASCEND ); hsize_t dims[3], maxdims[3]; eDataType = GH5_GetDataType( native ); if( n_dims == 2 ) { H5Sget_simple_extent_dims( dataspace, dims, maxdims ); nRasterXSize = (int) dims[1]; nRasterYSize = (int) dims[0]; } else { CPLError( CE_Failure, CPLE_AppDefined, "Dataset not of rank 2." ); return false; } nBlockXSize = nRasterXSize; nBlockYSize = 1; /* -------------------------------------------------------------------- */ /* Check for chunksize, and use it as blocksize for optimized */ /* reading. */ /* -------------------------------------------------------------------- */ hid_t listid = H5Dget_create_plist( hDatasetID ); if (listid>0) { if(H5Pget_layout(listid) == H5D_CHUNKED) { hsize_t panChunkDims[3]; int nDimSize = H5Pget_chunk(listid, 3, panChunkDims); nBlockXSize = (int) panChunkDims[nDimSize-1]; nBlockYSize = (int) panChunkDims[nDimSize-2]; } int nfilters = H5Pget_nfilters( listid ); H5Z_filter_t filter; char name[120]; size_t cd_nelmts = 20; unsigned int cd_values[20]; unsigned int flags; for (int i = 0; i < nfilters; i++) { filter = H5Pget_filter(listid, i, &flags, (size_t *)&cd_nelmts, cd_values, 120, name); if (filter == H5Z_FILTER_DEFLATE) poDS->SetMetadataItem( "COMPRESSION", "DEFLATE", "IMAGE_STRUCTURE" ); else if (filter == H5Z_FILTER_NBIT) poDS->SetMetadataItem( "COMPRESSION", "NBIT", "IMAGE_STRUCTURE" ); else if (filter == H5Z_FILTER_SCALEOFFSET) poDS->SetMetadataItem( "COMPRESSION", "SCALEOFFSET", "IMAGE_STRUCTURE" ); else if (filter == H5Z_FILTER_SZIP) poDS->SetMetadataItem( "COMPRESSION", "SZIP", "IMAGE_STRUCTURE" ); } H5Pclose(listid); } /* -------------------------------------------------------------------- */ /* Load min/max information. */ /* -------------------------------------------------------------------- */ if( EQUAL(pszName,"elevation") && GH5_FetchAttribute( hDatasetID, "Maximum Elevation Value", dfMaximum ) && GH5_FetchAttribute( hDatasetID, "Minimum Elevation Value", dfMinimum ) ) bMinMaxSet = true; else if( EQUAL(pszName,"uncertainty") && GH5_FetchAttribute( hDatasetID, "Maximum Uncertainty Value", dfMaximum ) && GH5_FetchAttribute( hDatasetID, "Minimum Uncertainty Value", dfMinimum ) ) { /* Some products where uncertainty band is completely set to nodata */ /* wrongly declare minimum and maximum to 0.0 */ if( dfMinimum != 0.0 && dfMaximum != 0.0 ) bMinMaxSet = true; } else if( EQUAL(pszName,"nominal_elevation") && GH5_FetchAttribute( hDatasetID, "max_value", dfMaximum ) && GH5_FetchAttribute( hDatasetID, "min_value", dfMinimum ) ) bMinMaxSet = true; return true; }
/*------------------------------------------------------------------------- * Function: h5tools_canreadf * * Purpose: check if the dataset creation property list has filters that * are not registered in the current configuration * 1) the external filters GZIP and SZIP might not be available * 2) the internal filters might be turned off * * Return: 1, can read, 0, cannot, -1 error * * Programmer: Pedro Vicente, [email protected] * * Date: March 1, 2004 * *------------------------------------------------------------------------- */ int h5tools_canreadf(const char* name, /* object name, serves also as boolean print */ hid_t dcpl_id) /* dataset creation property list */ { int nfilters; /* number of filters */ H5Z_filter_t filtn; /* filter identification number */ int i; /* index */ int have_deflate=0; /* assume initially we do not have filters */ int have_szip=0; int have_shuffle=0; int have_fletcher=0; #ifdef H5_HAVE_FILTER_DEFLATE have_deflate=1; #endif #ifdef H5_HAVE_FILTER_SZIP have_szip=1; #endif #ifdef H5_HAVE_FILTER_SHUFFLE have_shuffle=1; #endif #ifdef H5_HAVE_FILTER_FLETCHER32 have_fletcher=1; #endif /* get information about filters */ if ((nfilters = H5Pget_nfilters(dcpl_id))<0) return -1; /* if we do not have filters, we can read the dataset safely */ if (!nfilters) return 1; /* check availability of filters */ for (i=0; i<nfilters; i++) { if ((filtn = H5Pget_filter(dcpl_id,(unsigned)i,0,0,0,0,0))<0) return -1; switch (filtn) { /*------------------------------------------------------------------------- * user defined filter *------------------------------------------------------------------------- */ default: if (name) print_warning(name,"user defined"); return 0; /*------------------------------------------------------------------------- * H5Z_FILTER_DEFLATE 1 , deflation like gzip *------------------------------------------------------------------------- */ case H5Z_FILTER_DEFLATE: if (!have_deflate) { if (name) print_warning(name,"deflate"); return 0; } break; /*------------------------------------------------------------------------- * H5Z_FILTER_SZIP 4 , szip compression *------------------------------------------------------------------------- */ case H5Z_FILTER_SZIP: if (!have_szip) { if (name) print_warning(name,"SZIP"); return 0; } break; /*------------------------------------------------------------------------- * H5Z_FILTER_SHUFFLE 2 , shuffle the data *------------------------------------------------------------------------- */ case H5Z_FILTER_SHUFFLE: if (!have_shuffle) { if (name) print_warning(name,"shuffle"); return 0; } break; /*------------------------------------------------------------------------- * H5Z_FILTER_FLETCHER32 3 , fletcher32 checksum of EDC *------------------------------------------------------------------------- */ case H5Z_FILTER_FLETCHER32: if (!have_fletcher) { if (name) print_warning(name,"fletcher32"); return 0; } break; }/*switch*/ }/*for*/ return 1; }