#include "H5ATTR.h" #include "tables.h" #include "utils.h" #include "H5Zlzo.h" /* Import FILTER_LZO */ #include "H5Zbzip2.h" /* Import FILTER_BZIP2 */ #include "../blosc/blosc_filter.h" /* Import FILTER_BLOSC */ #include #include /*------------------------------------------------------------------------- * * Public functions * *------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- * Function: H5ARRAYmake * * Purpose: Creates and writes a dataset of a type type_id * * Return: Success: 0, Failure: -1 * * Programmer: F. Alted. October 21, 2002 * * Date: March 19, 2001 * * Comments: Modified by F. Alted. November 07, 2003 * *------------------------------------------------------------------------- */ herr_t H5ARRAYmake( hid_t loc_id, const char *dset_name, const char *obversion, const int rank, const hsize_t *dims, int extdim, hid_t type_id, hsize_t *dims_chunk, void *fill_data, int compress, char *complib, int shuffle, int fletcher32, const void *data) { hid_t dataset_id, space_id; hsize_t *maxdims = NULL; hid_t plist_id = 0; unsigned int cd_values[6]; int chunked = 0; int i; /* Check whether the array has to be chunked or not */ if (dims_chunk) { chunked = 1; } if(chunked) { maxdims = malloc(rank*sizeof(hsize_t)); if(!maxdims) return -1; for(i=0;i dims[_extdim] ) { printf("Asking for a range of rows exceeding the available ones!.\n"); goto out; } /* Define a hyperslab in the dataset of the size of the records */ for (i=0; i dims[i] ) { printf("Asking for a range of rows exceeding the available ones!.\n"); goto out; } } /* Define a hyperslab in the dataset of the size of the records */ if ( H5Sselect_hyperslab( space_id, H5S_SELECT_SET, offset, stride, count, NULL) < 0 ) goto out; /* Create a memory dataspace handle */ if ( (mem_space_id = H5Screate_simple( rank, count, NULL )) < 0 ) goto out; /* Read */ if ( H5Dread( dataset_id, type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0 ) goto out; /* Release resources */ free(dims); free(count); /* Terminate access to the memory dataspace */ if ( H5Sclose( mem_space_id ) < 0 ) goto out; } else { /* Scalar case */ /* Read all the dataset */ if (H5Dread(dataset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) goto out; } /* Terminate access to the dataspace */ if ( H5Sclose( space_id ) < 0 ) goto out; return 0; out: /* H5Dclose( dataset_id ); */ if (dims) free(dims); if (count) free(count); return -1; } /* The next represents a try to implement getCoords for != operator */ /* but it turned out to be too difficult, well, at least to me :( */ /* 2004-06-22 */ /*------------------------------------------------------------------------- * Function: H5ARRAYreadIndex * * Purpose: Reads a slice of array from disk for indexing purposes. * * Return: Success: 0, Failure: -1 * * Programmer: Francesc Alted, faltet@pytables.com * * Date: June 21, 2004 * *------------------------------------------------------------------------- */ herr_t H5ARRAYreadIndex( hid_t dataset_id, hid_t type_id, int notequal, hsize_t *start, hsize_t *stop, hsize_t *step, void *data ) { hid_t mem_space_id; hid_t space_id; hsize_t *dims = NULL; hsize_t *count = NULL; hsize_t *count2 = NULL; hsize_t *offset2 = NULL; hsize_t *stride = (hsize_t *)step; hsize_t *offset = (hsize_t *)start; int rank; int i; /* Get the dataspace handle */ if ( (space_id = H5Dget_space( dataset_id )) < 0 ) goto out; /* Get the rank */ if ( (rank = H5Sget_simple_extent_ndims(space_id)) < 0 ) goto out; if (rank) { /* Array case */ /* Book some memory for the selections */ dims = (hsize_t *)malloc(rank*sizeof(hsize_t)); count = (hsize_t *)malloc(rank*sizeof(hsize_t)); count2 = (hsize_t *)malloc(rank*sizeof(hsize_t)); offset2 = (hsize_t *)malloc(rank*sizeof(hsize_t)); /* Get dataset dimensionality */ if ( H5Sget_simple_extent_dims( space_id, dims, NULL) < 0 ) goto out; for(i=0;i dims[i] ) { printf("Asking for a range of rows exceeding the available ones!.\n"); goto out; } } /* Define a hyperslab in the dataset of the size of the records */ if ( H5Sselect_hyperslab( space_id, H5S_SELECT_SET, offset, stride, count, NULL) < 0 ) goto out; /* If we want the complementary, do a NOTA against all the row */ if (notequal) { offset2[0] = offset[0]; count2[0] = count[0]; offset2[1] = 0; count2[1] = dims[1]; /* All the row */ count[0] = 1; count[1] = dims[1] - count[1]; /* For memory dataspace */ if ( H5Sselect_hyperslab( space_id, H5S_SELECT_NOTA, offset2, stride, count2, NULL) < 0 ) goto out; } /* Create a memory dataspace handle */ if ( (mem_space_id = H5Screate_simple( rank, count, NULL )) < 0 ) goto out; /* Read */ if ( H5Dread( dataset_id, type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0 ) goto out; /* Release resources */ free(dims); free(count); free(offset2); free(count2); /* Terminate access to the memory dataspace */ if ( H5Sclose( mem_space_id ) < 0 ) goto out; } else { /* Scalar case */ /* Read all the dataset */ if (H5Dread(dataset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) goto out; } /* Terminate access to the dataspace */ if ( H5Sclose( space_id ) < 0 ) goto out; return 0; out: if (dims) free(dims); if (count) free(count); return -1; } /*------------------------------------------------------------------------- * Function: H5ARRAYget_ndims * * Purpose: Gets the dimensionality of an array. * * Return: Success: 0, Failure: -1 * * Programmer: Francesc Alted * * Date: October 22, 2002 * * Modification: October 13, 2008 * This routine not longer returns the dimensionality of data types * in case they are H5T_ARRAY. * *------------------------------------------------------------------------- */ herr_t H5ARRAYget_ndims( hid_t dataset_id, int *rank ) { hid_t space_id; /* Get the dataspace handle */ if ( (space_id = H5Dget_space( dataset_id )) < 0 ) goto out; /* Get rank */ if ( (*rank = H5Sget_simple_extent_ndims( space_id )) < 0 ) goto out; /* Terminate access to the dataspace */ if ( H5Sclose( space_id ) < 0 ) goto out; return 0; out: return -1; } /* Modified version of H5LTget_dataset_info. */ herr_t H5ARRAYget_info( hid_t dataset_id, hid_t type_id, hsize_t *dims, hsize_t *maxdims, H5T_class_t *class_id, char *byteorder) { hid_t space_id; /* Get the class. */ *class_id = H5Tget_class( type_id ); /* Get the dataspace handle */ if ( (space_id = H5Dget_space( dataset_id )) < 0 ) goto out; /* Get dimensions */ if ( H5Sget_simple_extent_dims( space_id, dims, maxdims) < 0 ) goto out; /* Terminate access to the dataspace */ if ( H5Sclose( space_id ) < 0 ) goto out; /* Get the byteorder */ /* Only integer, float, time, enumerate and array classes can be byteordered */ if ((*class_id == H5T_INTEGER) || (*class_id == H5T_FLOAT) || (*class_id == H5T_BITFIELD) || (*class_id == H5T_COMPOUND) || (*class_id == H5T_TIME) || (*class_id == H5T_ENUM) || (*class_id == H5T_ARRAY)) { get_order(type_id, byteorder); } else { strcpy(byteorder, "irrelevant"); } return 0; out: return -1; } /*------------------------------------------------------------------------- * Function: H5ARRAYget_chunkshape * * Purpose: Gets the chunkshape of a dataset. * * Return: Success: 0, Failure: -1 * * Programmer: Francesc Alted * * Date: May 20, 2004 * *------------------------------------------------------------------------- */ herr_t H5ARRAYget_chunkshape( hid_t dataset_id, int rank, hsize_t *dims_chunk) { hid_t plist_id; H5D_layout_t layout; /* Get creation properties list */ if ( (plist_id = H5Dget_create_plist( dataset_id )) < 0 ) goto out; /* Get the dataset layout */ layout = H5Pget_layout(plist_id); if (layout != H5D_CHUNKED) { H5Pclose( plist_id ); return -1; } /* Get the chunkshape for all dimensions */ if (H5Pget_chunk(plist_id, rank, dims_chunk ) < 0 ) goto out; /* Terminate access to the datatype */ if ( H5Pclose( plist_id ) < 0 ) goto out; return 0; out: if (dims_chunk) free(dims_chunk); return -1; } /*------------------------------------------------------------------------- * Function: H5ARRAYget_fill_value * * Purpose: Gets the fill value of a dataset. * * Return: Success: 0, Failure: -1 * * Programmer: Francesc Alted * * Date: Mar 03, 2009 * *------------------------------------------------------------------------- */ herr_t H5ARRAYget_fill_value( hid_t dataset_id, hid_t type_id, int *status, void *value) { hid_t plist_id; /* Get creation properties list */ if ( (plist_id = H5Dget_create_plist(dataset_id)) < 0 ) goto out; /* How the fill value is defined? */ if ( (H5Pfill_value_defined(plist_id, status)) < 0 ) goto out; if ( *status == H5D_FILL_VALUE_USER_DEFINED ) { if ( H5Pget_fill_value(plist_id, type_id, value) < 0 ) goto out; } /* Terminate access to the datatype */ if ( H5Pclose( plist_id ) < 0 ) goto out; return 0; out: return -1; }