From 3f26602c9e83c756115e9b2270bc8c1af5eaed0a Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Mon, 1 Dec 2008 15:58:00 -0500 Subject: [svn-r16145] Merging with trunk regarding revisions 16132 some chunks were not deleted for some cases, the comparison to check for chunk offsets outside of the new dimensions was chunk_offset[ i ] > dimension [ i ] and it must be chunk_offset[ i ] >= dimension [ i ] 16133 H5TBdelete_record was not handlong correctly records at the end of the table added a ckeck that avoids to read these records if they are not needed (for pushing down the table) 16143 add a test for recent fixes of H5Dset_extent tested: windows, linux --- hl/src/H5TB.c | 130 +++--- hl/test/test_table.c | 16 + src/H5Dchunk.c | 2 +- test/set_extent.c | 1166 +++++++++++++++++++++++--------------------------- 4 files changed, 632 insertions(+), 682 deletions(-) diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c index bdf4cad..30a8490 100644 --- a/hl/src/H5TB.c +++ b/hl/src/H5TB.c @@ -1294,20 +1294,19 @@ herr_t H5TBdelete_record( hid_t loc_id, hsize_t ntotal_records; hsize_t read_start; hsize_t read_nrecords; - hid_t did; - hid_t tid; + hid_t did=-1; + hid_t tid=-1; + hid_t sid=-1; + hid_t m_sid=-1; hsize_t count[1]; hsize_t offset[1]; - hid_t sid; - hid_t m_sid; hsize_t mem_size[1]; - unsigned char *tmp_buf; + unsigned char *tmp_buf=NULL; size_t src_size; size_t *src_offset; size_t *src_sizes; hsize_t dims[1]; - /*------------------------------------------------------------------------- * first we get information about type size and offsets on disk *------------------------------------------------------------------------- @@ -1322,10 +1321,16 @@ herr_t H5TBdelete_record( hid_t loc_id, if (src_offset == NULL ) return -1; + if (src_sizes == NULL ) + return -1; /* get field info */ if (H5TBget_field_info( loc_id, dset_name, NULL, src_sizes, src_offset, &src_size ) < 0) return -1; + + /* open the dataset. */ + if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) + return -1; /*------------------------------------------------------------------------- * read the records after the deleted one(s) @@ -1334,53 +1339,54 @@ herr_t H5TBdelete_record( hid_t loc_id, read_start = start + nrecords; read_nrecords = ntotal_records - read_start; - tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, src_size ); - - if (tmp_buf == NULL ) - return -1; - - /* read the records after the deleted one(s) */ - if (H5TBread_records( loc_id, dset_name, read_start, read_nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0) - return -1; - - /*------------------------------------------------------------------------- - * write the records in another position - *------------------------------------------------------------------------- - */ - - /* open the dataset. */ - if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) - return -1; - - /* get the datatype */ - if ((tid = H5Dget_type( did )) < 0) - goto out; - - /* get the dataspace handle */ - if ((sid = H5Dget_space( did )) < 0) - goto out; - - /* define a hyperslab in the dataset of the size of the records */ - offset[0] = start; - count[0] = read_nrecords; - if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) - goto out; - - /* create a memory dataspace handle */ - mem_size[0] = count[0]; - if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) - goto out; - - if (H5Dwrite( did, tid, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0) - goto out; - - /* close */ - if (H5Sclose( m_sid ) < 0) - goto out; - if (H5Sclose( sid ) < 0) - goto out; - if (H5Tclose( tid ) < 0) - goto out; + + if ( read_nrecords ) + { + tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, src_size ); + + if (tmp_buf == NULL ) + return -1; + + /* read the records after the deleted one(s) */ + if (H5TBread_records( loc_id, dset_name, read_start, read_nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0) + return -1; + + /*------------------------------------------------------------------------- + * write the records in another position + *------------------------------------------------------------------------- + */ + + /* get the datatype */ + if ((tid = H5Dget_type( did )) < 0) + goto out; + + /* get the dataspace handle */ + if ((sid = H5Dget_space( did )) < 0) + goto out; + + /* define a hyperslab in the dataset of the size of the records */ + offset[0] = start; + count[0] = read_nrecords; + if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) + goto out; + + /* create a memory dataspace handle */ + mem_size[0] = count[0]; + if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) + goto out; + + if (H5Dwrite( did, tid, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0) + goto out; + + /* close */ + if (H5Sclose( m_sid ) < 0) + goto out; + if (H5Sclose( sid ) < 0) + goto out; + if (H5Tclose( tid ) < 0) + goto out; + + } /* read_nrecords */ /*------------------------------------------------------------------------- @@ -1395,16 +1401,28 @@ herr_t H5TBdelete_record( hid_t loc_id, if (H5Dclose( did ) < 0) return -1; - free( tmp_buf ); + if (tmp_buf !=NULL) + free( tmp_buf ); free( src_offset ); free( src_sizes ); return 0; - + + /* error zone */ out: - H5Dclose( did ); + + if (tmp_buf !=NULL ) + free( tmp_buf ); + H5E_BEGIN_TRY + { + H5Dclose(did); + H5Tclose(tid); + H5Sclose(sid); + } H5E_END_TRY; return -1; + + } /*------------------------------------------------------------------------- diff --git a/hl/test/test_table.c b/hl/test/test_table.c index 85fc70d..bd8dd79 100644 --- a/hl/test/test_table.c +++ b/hl/test/test_table.c @@ -818,6 +818,22 @@ int test_table(hid_t fid, int write) goto out; } } + + /*------------------------------------------------------------------------- + * Delete records, start at 0, delete 1 + * pos = 0 + * data= empty + *------------------------------------------------------------------------- + */ + dstart=0; drecords=1; + if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) + goto out; + + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) + goto out; + + if (rrecords) + goto out; PASSED(); } diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index d8e13a5..6058e16 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -3483,7 +3483,7 @@ H5D_chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dims) /* Check for chunk offset outside of new dimensions */ for(u = 0; u < rank; u++) - if((hsize_t)ent->offset[u] > curr_dims[u]) { + if((hsize_t)ent->offset[u] >= curr_dims[u]) { /* Evict the entry from the cache, but do not flush it to disk */ if(H5D_chunk_cache_evict(dset, dxpl_id, dxpl_cache, ent, FALSE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTREMOVE, FAIL, "unable to evict chunk") diff --git a/test/set_extent.c b/test/set_extent.c index 4bb324f..3cf2095 100644 --- a/test/set_extent.c +++ b/test/set_extent.c @@ -33,41 +33,30 @@ *------------------------------------------------------------------------- */ -#define RANK 2 -#define ISTORE_IK 64 +#define RANK 2 +#define DIM0 4 +#define DIM1 4 +#define DIMS0 2 +#define DIMS1 2 +#define DIME0 7 +#define DIME1 7 +#define ISTORE_IK 64 +static int test( hid_t fid, int do_compress, int do_fill_value ); + + +/*------------------------------------------------------------------------- + * main + *------------------------------------------------------------------------- + */ int main( void ) { hid_t fid; - hid_t did=(-1); - hid_t sid=(-1); - hid_t dcpl=(-1); - hid_t fcpl; - hsize_t dims[RANK] = { 90, 90 }; - hsize_t dims_new[RANK] = { 70, 70 }; - hsize_t dims_chunk[RANK] = { 20, 20 }; - hsize_t dims_out[RANK]; - hsize_t dims3[RANK]; - hsize_t maxdims[RANK] = { H5S_UNLIMITED, H5S_UNLIMITED }; - int data[ 90 ][ 90 ]; - int buf1[ 70 ][ 70 ]; - int buf2[ 90 ][ 90 ]; - int i, j, n = 0; - int fillvalue = 1; /* Fill value for the dataset */ -#ifdef H5_HAVE_FILTER_DEFLATE - hbool_t do_compress; /* Iterator for looping over compress/no compress */ -#endif /* H5_HAVE_FILTER_DEFLATE */ - + hid_t fcpl; + hbool_t do_compress; /* iterator for looping over compress/no compress */ + - for( i = 0; i < 90; i++ ) - for( j = 0; j < 90; j++ ) - data[i][j] = n++; - - /*------------------------------------------------------------------------- - * Test H5Dset_extent with chunks on the raw data cache - *------------------------------------------------------------------------- - */ #ifdef H5_HAVE_FILTER_DEFLATE for (do_compress = FALSE; do_compress <= TRUE; do_compress++) { @@ -76,645 +65,572 @@ int main( void ) else puts("Testing with NO compression on chunks."); #else /* H5_HAVE_FILTER_DEFLATE */ - puts("** deflate filter nor available - Skipping tests for compression on chunks. **"); + puts("** deflate filter nor available - Skipping tests for compression on chunks. **"); #endif /* H5_HAVE_FILTER_DEFLATE */ - - TESTING("extend dataset create with fill value"); - - /* Create a new file using default properties. */ - if((fid = H5Fcreate("set_extent_create.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Create the data space with unlimited dimensions. */ - if((sid = H5Screate_simple(RANK, dims, maxdims)) < 0) - TEST_ERROR; - - /* Modify dataset creation properties, i.e. enable chunking. */ - if((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) - TEST_ERROR; - if(H5Pset_chunk(dcpl, RANK, dims_chunk) < 0) - TEST_ERROR; - if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillvalue) < 0) - TEST_ERROR; -#ifdef H5_HAVE_FILTER_DEFLATE - if(do_compress) + + /* create a file creation property list */ + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { - if(H5Pset_deflate(dcpl, 9) < 0) - FAIL_STACK_ERROR + goto error; } -#endif /* H5_HAVE_FILTER_DEFLATE */ - - - /*------------------------------------------------------------------------- - * Create and write one dataset - *------------------------------------------------------------------------- - */ - - /* Create a new dataset */ - if((did = H5Dcreate2(fid , "Dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Write the data. */ - if(H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, data) < 0) - TEST_ERROR; - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; shrink it - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if(H5Dset_extent(did , dims_new) < 0) - TEST_ERROR; - - /* Get the space. */ - if((sid = H5Dget_space(did)) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if(H5Sget_simple_extent_dims(sid, dims_out, NULL) < 0) - TEST_ERROR; - - if(dims_out[0] != dims_new[0]) - TEST_ERROR; - if(dims_out[1] != dims_new[1]) - TEST_ERROR; - - - /*------------------------------------------------------------------------- - * Read - *------------------------------------------------------------------------- - */ - - /* Read the new dataset. */ - if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 ) < 0) - TEST_ERROR; - - - /* Compare the read array with the original array */ - for( i = 0; i < (int)dims_out[0]; i++ ) + + if ( do_compress ) { - for( j = 0; j < (int)dims_out[1]; j++ ) + + /* set non-default indexed storage B-tree internal 'K' value */ + if (H5Pset_istore_k(fcpl,ISTORE_IK) < 0) { - if ( buf1[i][j] != data[i][j] ) - { - printf("buf1[%d][%d] = %d\n", i, j, buf1[i][j]); - printf("data[%d][%d] = %d\n", i, j, data[i][j]); - TEST_ERROR; - } + goto error; } } - - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; expand it back to original size - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if(H5Dset_extent(did, dims) < 0) - TEST_ERROR; - - /* Get the space. */ - if((sid = H5Dget_space(did)) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if(H5Sget_simple_extent_dims(sid, dims_out, NULL) < 0) - TEST_ERROR; - - if(dims_out[0] != dims[0]) - TEST_ERROR; - if(dims_out[1] != dims[1]) - TEST_ERROR; - - - /*------------------------------------------------------------------------- - * Read - *------------------------------------------------------------------------- - */ - - /* Read the new dataset. */ - if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0) - TEST_ERROR; - - /* Compare the read array with the original array */ - for(i = 0; i < (int)dims_out[0]; i++ ) + + + /* create a new file */ + if ((fid = H5Fcreate("set_extent1.h5", H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0) { - for(j = 0; j < (int)dims_out[1]; j++ ) - { - if(i >= 70 || j >= 70) - { - if(buf2[i][j] != fillvalue) { - printf("buf1[%d][%d] = %d\n", i, j, buf1[i][j]); - printf("fillvalue = %d\n", fillvalue); - TEST_ERROR; - } /* end if */ - } /* end if */ - else - { - if(buf2[i][j] != data[i][j]) - TEST_ERROR; - } - } + goto error; } - - - /*------------------------------------------------------------------------- - * Close/release resources - *------------------------------------------------------------------------- - */ - - if(H5Dclose(did) < 0) - TEST_ERROR - if(H5Sclose(sid) < 0) - TEST_ERROR - if(H5Pclose(dcpl) < 0) - TEST_ERROR - + + + /* close property list */ + if(H5Pclose(fcpl) < 0) + { + goto error; + } + + + + TESTING("extend dataset created with fill value"); + + + if (test( fid, do_compress, 1 ) < 0) + { + goto error; + } + PASSED(); - - - TESTING("extend dataset create without fill value"); - - /* Create the data space with unlimited dimensions. */ - if((sid = H5Screate_simple(RANK, dims, maxdims)) < 0) - TEST_ERROR; - - /* Modify dataset creation properties, i.e. enable chunking. */ - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - TEST_ERROR; - if(H5Pset_chunk(dcpl, RANK, dims_chunk) < 0) - TEST_ERROR; - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) - TEST_ERROR; -#ifdef H5_HAVE_FILTER_DEFLATE - if(do_compress) - if(H5Pset_deflate(dcpl, 9) < 0) - FAIL_STACK_ERROR -#endif /* H5_HAVE_FILTER_DEFLATE */ - - /*------------------------------------------------------------------------- - * Create and write one dataset - *------------------------------------------------------------------------- - */ - - /* Create a new dataset */ - if((did = H5Dcreate2(fid , "Dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Write the data. */ - if(H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, data) < 0) - TEST_ERROR; - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; shrink it - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if(H5Dset_extent(did , dims_new) < 0) - TEST_ERROR; - - /* Get the space. */ - if((sid = H5Dget_space(did)) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if(H5Sget_simple_extent_dims(sid, dims_out, NULL) < 0) - TEST_ERROR; - - if(dims_out[0] != dims_new[0]) - TEST_ERROR; - - - /*------------------------------------------------------------------------- - * Read - *------------------------------------------------------------------------- - */ - - /* Read the new dataset. */ - if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1 ) < 0) - TEST_ERROR; - - - /* Compare the read array with the original array */ - for( i = 0; i < (int)dims_out[0]; i++ ) + + TESTING("extend dataset created without fill value"); + + if (test( fid, do_compress, 0 ) < 0) { - for( j = 0; j < (int)dims_out[1]; j++ ) - { - if ( buf1[i][j] != data[i][j] ) - TEST_ERROR; - } + goto error; } - - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; expand it again - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if (H5Dset_extent( did , dims ) < 0) - TEST_ERROR; - - /* Get the space. */ - if ((sid = H5Dget_space( did )) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if (H5Sget_simple_extent_dims( sid, dims_out, NULL ) < 0) - TEST_ERROR; - - if ( dims_out[0] != dims[0] ) - TEST_ERROR; - - - /*------------------------------------------------------------------------- - * Read - *------------------------------------------------------------------------- - */ - - /* Read the new dataset. */ - if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 ) < 0) - TEST_ERROR; - - /* Compare the read array with the original array */ - for( i = 0; i < (int)dims_out[0]; i++ ) + + + if (H5Fclose( fid ) < 0) { - for( j = 0; j < (int)dims_out[1]; j++ ) - { - if ( i >= 70 || j >= 70 ) { - if ( buf2[i][j] != 0 ) - TEST_ERROR; - } - else { - if ( buf2[i][j] != data[i][j] ) - TEST_ERROR; - } - } + goto error; } - - - /*------------------------------------------------------------------------- - * Close/release resources - *------------------------------------------------------------------------- - */ - - if (H5Dclose(did) < 0) - TEST_ERROR - if (H5Sclose(sid) < 0) - TEST_ERROR - if (H5Pclose(dcpl) < 0) - TEST_ERROR - if (H5Fclose( fid ) < 0) - TEST_ERROR - + PASSED(); - - - - /*------------------------------------------------------------------------- - * Test H5Dset_extent with chunks written to file - *------------------------------------------------------------------------- - */ - - /* Create a file creation property list */ - if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) - TEST_ERROR; - - /* Set non-default indexed storage B-tree internal 'K' value */ - if(H5Pset_istore_k(fcpl,ISTORE_IK) < 0) - TEST_ERROR; - - /* Create a new file using properties. */ - if((fid = H5Fcreate("set_extent_read.h5", H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Close property list */ - if(H5Pclose(fcpl) < 0) - TEST_ERROR; - - TESTING("extend dataset read with fill value"); - - /* Create the data space with unlimited dimensions. */ - if((sid = H5Screate_simple(RANK, dims, maxdims)) < 0) - TEST_ERROR; - - /* Modify dataset creation properties, i.e. enable chunking. */ - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - TEST_ERROR; - if(H5Pset_chunk(dcpl, RANK, dims_chunk) < 0) - TEST_ERROR; - if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillvalue) < 0) - TEST_ERROR; + + + #ifdef H5_HAVE_FILTER_DEFLATE - if(do_compress) - if(H5Pset_deflate(dcpl, 9) < 0) - FAIL_STACK_ERROR + } /* end for */ #endif /* H5_HAVE_FILTER_DEFLATE */ + + puts("All set_extent tests passed."); + return 0; + + +error: + + H5E_BEGIN_TRY + { + H5Fclose( fid ); + } H5E_END_TRY; + + H5_FAILED(); + return 1; +} - /* Create a new dataset within the file using cparms creation properties. */ - if((did = H5Dcreate2(fid , "Dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Write the data. */ - if(H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, data) < 0) - TEST_ERROR; - - /* Close/release resources. */ - if(H5Dclose(did) < 0) FAIL_STACK_ERROR - if(H5Sclose(sid) < 0) FAIL_STACK_ERROR - if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR - if(H5Fclose(fid) < 0) FAIL_STACK_ERROR - - - /* Open the file */ - if((fid = H5Fopen("set_extent_read.h5", H5F_ACC_RDWR, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Open the dataset */ - if((did = H5Dopen2(fid , "Dataset1", H5P_DEFAULT)) < 0) - TEST_ERROR; - /* Set new dimensions for the array. */ - if(H5Dset_extent(did, dims_new) < 0) - TEST_ERROR; - /* Get the space. */ - if((sid = H5Dget_space(did)) < 0) - TEST_ERROR; - /* Get dimensions. */ - if(H5Sget_simple_extent_dims(sid, dims_out, NULL) < 0) - TEST_ERROR; +/*------------------------------------------------------------------------- + * test + *------------------------------------------------------------------------- + */ - if(dims_out[0] != dims_new[0]) - TEST_ERROR; +static int test( hid_t fid, int do_compress, int do_fill_value ) +{ - /* Read the new dataset. */ - if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1) < 0) - TEST_ERROR; + hid_t did; + hid_t sid; + hid_t dcpl; + hsize_t dims_o[RANK] = {DIM0,DIM1}; + hsize_t dims_s[RANK] = {DIMS0,DIMS1}; + hsize_t dims_e[RANK] = {DIME0,DIME1}; + hsize_t dims_c[RANK] = {2,2}; + hsize_t dims_r[RANK]; + hsize_t maxdims[RANK] = {H5S_UNLIMITED,H5S_UNLIMITED}; + int buf_o[DIM0][DIM1]; + int buf_s[DIMS0][DIMS1]; + int buf_e[DIME0][DIME1]; + int buf_r[DIM0][DIM1]; + int i, j; + int fillvalue = 1; + int comp_value; + char dset_name[255]; + char dset_name2[255]; + + if ( do_fill_value ) + { + comp_value = fillvalue; + strcpy(dset_name,"dset_fill"); + strcpy(dset_name2,"dset_fill_noinit"); + } + else + { + comp_value = 0; + strcpy(dset_name,"dset_nofill"); + strcpy(dset_name2,"dset_nofill_noinit"); + } - /* Compare the read array with the original array */ - for(i = 0; i < (int)dims_out[0]; i++) + + for( i = 0; i < DIM0; i++ ) + { + for( j = 0; j < DIM1; j++ ) { - for(j = 0; j < (int)dims_out[1]; j++) - { - if(buf1[i][j] != data[i][j]) - TEST_ERROR; - } + buf_o[i][j] = 2; } - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; expand it again - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if (H5Dset_extent( did , dims ) < 0) - TEST_ERROR; - - /* Get the space. */ - if ((sid = H5Dget_space( did )) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if (H5Sget_simple_extent_dims( sid, dims_out, NULL ) < 0) - TEST_ERROR; - - if ( dims_out[0] != dims[0] ) - TEST_ERROR; - - /* Read the new dataset. */ - if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 ) < 0) - TEST_ERROR; - - /* Compare the read array with the original array */ - for( i = 0; i < (int)dims_out[0]; i++ ) + } + + /* create the data space with unlimited dimensions. */ + if ((sid = H5Screate_simple(RANK, dims_o, maxdims)) < 0) + { + goto error; + } + + /* modify dataset creation properties, i.e. enable chunking. */ + if ((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) + { + goto error; + } + if (H5Pset_chunk(dcpl, RANK, dims_c) < 0) + { + goto error; + } + if ( do_fill_value ) + { + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillvalue) < 0) { - for( j = 0; j < (int)dims_out[1]; j++ ) - { - if ( i >= 70 || j >= 70 ) - { - if ( buf2[i][j] != fillvalue ) - TEST_ERROR; - } - else - { - if ( buf2[i][j] != data[i][j] ) - TEST_ERROR; - } - } + goto error; } - - - /*------------------------------------------------------------------------- - * Close/release resources - *------------------------------------------------------------------------- - */ - - if (H5Dclose(did) < 0) - TEST_ERROR - if (H5Sclose(sid) < 0) - TEST_ERROR - - PASSED(); - - - TESTING("extend dataset read without fill value"); - - /* Create the data space with unlimited dimensions. */ - if((sid = H5Screate_simple(RANK, dims, maxdims)) < 0) - TEST_ERROR; - - /* Modify dataset creation properties, i.e. enable chunking. */ - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - TEST_ERROR; - if(H5Pset_chunk(dcpl, RANK, dims_chunk) < 0) - TEST_ERROR; + } + else + { + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) - TEST_ERROR; + { + goto error; + } + + } #ifdef H5_HAVE_FILTER_DEFLATE - if(do_compress) - if(H5Pset_deflate(dcpl, 9) < 0) - FAIL_STACK_ERROR + if(do_compress) + { + if(H5Pset_deflate(dcpl, 9) < 0) + { + goto error; + } + } #endif /* H5_HAVE_FILTER_DEFLATE */ - - /* Create a new dataset within the file using cparms creation properties. */ - if((did = H5Dcreate2(fid , "Dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Write the data. */ - if(H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, data) < 0) - TEST_ERROR; - - /* Close/release resources. */ - if(H5Dclose(did) < 0) FAIL_STACK_ERROR - if(H5Sclose(sid) < 0) FAIL_STACK_ERROR - if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR - if(H5Fclose(fid) < 0) FAIL_STACK_ERROR - - - /* Open the file */ - if((fid = H5Fopen("set_extent_read.h5", H5F_ACC_RDWR, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Open the dataset */ - if((did = H5Dopen2(fid , "Dataset2", H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* Set new dimensions for the array. */ - if(H5Dset_extent(did, dims_new) < 0) - TEST_ERROR; - - /* Get the space. */ - if((sid = H5Dget_space(did)) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if(H5Sget_simple_extent_dims(sid, dims_out, NULL) < 0) - TEST_ERROR; - - if(dims_out[0] != dims_new[0]) - TEST_ERROR; - - /* Read the new dataset. */ - if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1) < 0) - TEST_ERROR; - - /* Compare the read array with the original array */ - for(i = 0; i < (int)dims_out[0]; i++) + + + + /*------------------------------------------------------------------------- + * create and write one dataset + *------------------------------------------------------------------------- + */ + + /* create a dataset */ + if ((did = H5Dcreate2(fid , dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + { + goto error; + } + + /* write */ + if (H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, buf_o) < 0) + { + goto error; + } + + +#if defined (H5_SET_EXTENT_DEBUG) + printf("\n"); + for (i = 0; i < (int)dims_o[0]; i++ ) + { + for (j = 0; j < (int)dims_o[1]; j++ ) { - for(j = 0; j < (int)dims_out[1]; j++) - { - if(buf1[i][j] != data[i][j]) - TEST_ERROR; - } + printf("%d ", buf_o[i][j]); } - - /*------------------------------------------------------------------------- - * Set new dimensions for the array; expand it again - *------------------------------------------------------------------------- - */ - - /* Set new dimensions for the array. */ - if (H5Dset_extent( did , dims ) < 0) - TEST_ERROR; - - /* Get the space. */ - if ((sid = H5Dget_space( did )) < 0) - TEST_ERROR; - - /* Get dimensions. */ - if (H5Sget_simple_extent_dims( sid, dims_out, NULL ) < 0) - TEST_ERROR; - - if ( dims_out[0] != dims[0] ) - TEST_ERROR; - - /* Read the new dataset. */ - if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2 ) < 0) - TEST_ERROR; - - /* Compare the read array with the original array */ - for( i = 0; i < (int)dims_out[0]; i++ ) + printf("\n"); + } +#endif + + if (H5Sclose(sid) < 0) + { + goto error; + } + + /*------------------------------------------------------------------------- + * set new dimensions for the array; expand it + *------------------------------------------------------------------------- + */ + + /* set new dimensions for the array. */ + if (H5Dset_extent(did , dims_e) < 0) + { + goto error; + } + + /* get the space */ + if ((sid = H5Dget_space(did)) < 0) + { + goto error; + } + + /* get dimensions */ + if (H5Sget_simple_extent_dims(sid, dims_r, NULL) < 0) + { + goto error; + } + + if (H5Sclose(sid) < 0) + { + goto error; + } + + + /* check dimensions */ + for( i = 0; i < RANK; i++ ) + { + if (dims_r[i] != dims_e[i]) + goto error; + } + + /* read */ + if (H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_e) < 0) + goto error; + +#if defined (H5_SET_EXTENT_DEBUG) + printf("\n"); + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) { - for( j = 0; j < (int)dims_out[1]; j++ ) + printf("%d ", buf_e[i][j]); + } + printf("\n"); + } +#endif + + + + /* compare the read array with the expanded array */ + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) + { + if (i >= DIM0 || j >= DIM1) { - if ( i >= 70 || j >= 70 ) + if(buf_e[i][j] != comp_value) { - if ( buf2[i][j] != 0 ) - TEST_ERROR; - } - else - { - if ( buf2[i][j] != data[i][j] ) - TEST_ERROR; - } + printf("buf_e[%d][%d] = %d\n", i, j, buf_e[i][j]); + printf("value = %d\n", comp_value); + goto error; + } + } + else + { + if(buf_e[i][j] != buf_o[i][j]) + goto error; } } - - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - if (H5Dclose(did) < 0) - TEST_ERROR - if (H5Sclose(sid) < 0) - TEST_ERROR - if (H5Fclose( fid ) < 0) - TEST_ERROR - - PASSED(); - - - - /*------------------------------------------------------------------------- - * test a dataset with non initialized chunks - *------------------------------------------------------------------------- - */ - - TESTING("non initialized chunks"); - - dims3[ 0 ] = 90; - dims3[ 1 ] = 90; - - if ((fid = H5Fopen("set_extent_create.h5", H5F_ACC_RDWR, H5P_DEFAULT)) < 0) - TEST_ERROR; - if ((sid = H5Screate_simple(RANK, dims3, maxdims)) < 0) - TEST_ERROR; - if ((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) - TEST_ERROR; - if (H5Pset_chunk(dcpl, RANK, dims_chunk) < 0) - TEST_ERROR; -#ifdef H5_HAVE_FILTER_DEFLATE - if(do_compress) + } + + + /*------------------------------------------------------------------------- + * write to the expanded array. fill the space with fill value with other value + *------------------------------------------------------------------------- + */ + + for( i = 0; i < DIME0; i++ ) + { + for( j = 0; j < DIME1; j++ ) { - if(H5Pset_deflate(dcpl, 9) < 0) - FAIL_STACK_ERROR + buf_e[i][j] = 2; } -#endif /* H5_HAVE_FILTER_DEFLATE */ - - /* create a new dataset */ - if((did = H5Dcreate2(fid , "Dataset3", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - TEST_ERROR; - - /* set new dimensions for the array */ - dims3[ 0 ] = 0; - dims3[ 1 ] = 0; - if (H5Dset_extent( did , dims3 ) < 0) - TEST_ERROR; - - - if (H5Dclose(did) < 0) - TEST_ERROR - if (H5Sclose(sid) < 0) - TEST_ERROR - if (H5Pclose(dcpl) < 0) - TEST_ERROR - if (H5Fclose( fid ) < 0) - TEST_ERROR - - PASSED(); - + } + + /* get the space */ + if ((sid = H5Dget_space(did)) < 0) + { + goto error; + } + + /* write */ + if (H5Dwrite(did , H5T_NATIVE_INT, sid, H5S_ALL, H5P_DEFAULT, buf_e) < 0) + { + goto error; + } + + /* read */ + if (H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_e) < 0) + goto error; + + + /* close space */ + if (H5Sclose(sid) < 0) + { + goto error; + } + + +#if defined (H5_SET_EXTENT_DEBUG) + printf("\n"); + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) + { + printf("%d ", buf_e[i][j]); + } + printf("\n"); + } +#endif + + + + + /*------------------------------------------------------------------------- + * set new dimensions for the array; shrink it + *------------------------------------------------------------------------- + */ + + /* set new dimensions for the array. */ + if (H5Dset_extent(did , dims_s) < 0) + { + goto error; + } + + /* get the space */ + if ((sid = H5Dget_space(did)) < 0) + { + goto error; + } + + /* get dimensions */ + if (H5Sget_simple_extent_dims(sid, dims_r, NULL) < 0) + { + goto error; + } + + if (H5Sclose(sid) < 0) + { + goto error; + } + + /* check dimensions */ + for( i = 0; i < RANK; i++ ) + { + if (dims_r[i] != dims_s[i]) + goto error; + } + + + /*------------------------------------------------------------------------- + * read + *------------------------------------------------------------------------- + */ + + /* read */ + if (H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_s ) < 0) + { + goto error; + } + +#if defined (H5_SET_EXTENT_DEBUG) + printf("\n"); + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) + { + printf("%d ", buf_s[i][j]); + } + printf("\n"); + } +#endif + + + /* compare the read array with the shrinked array */ + for( i = 0; i < (int)dims_r[0]; i++ ) + { + for( j = 0; j < (int)dims_r[1]; j++ ) + { + if ( buf_s[i][j] != buf_o[i][j] ) + { + printf("buf_r[%d][%d] = %d\n", i, j, buf_r[i][j]); + printf("buf_o[%d][%d] = %d\n", i, j, buf_o[i][j]); + goto error; + } + } + } + + + /*------------------------------------------------------------------------- + * set new dimensions for the array; expand it back to original size + *------------------------------------------------------------------------- + */ + + /* set new dimensions for the array */ + if (H5Dset_extent(did, dims_o) < 0) + { + goto error; + } + + /* get the space */ + if ((sid = H5Dget_space(did)) < 0) + { + goto error; + } + + /* get dimensions. */ + if (H5Sget_simple_extent_dims(sid, dims_r, NULL) < 0) + { + goto error; + } + + /* check dimensions */ + for( i = 0; i < RANK; i++ ) + { + if (dims_r[i] != dims_o[i]) + goto error; + } + + + /*------------------------------------------------------------------------- + * read + *------------------------------------------------------------------------- + */ + + /* read */ + if (H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_r) < 0) + goto error; + +#if defined (H5_SET_EXTENT_DEBUG) + printf("\n"); + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) + { + printf("%d ", buf_r[i][j]); + } + printf("\n"); + } +#endif + + /* compare the read array with the original array */ + for (i = 0; i < (int)dims_r[0]; i++ ) + { + for (j = 0; j < (int)dims_r[1]; j++ ) + { + if (i >= DIMS0 || j >= DIMS1) + { + if(buf_r[i][j] != comp_value) + { + printf("buf_r[%d][%d] = %d\n", i, j, buf_r[i][j]); + printf("value = %d\n", comp_value); + goto error; + } + } + else + { + if(buf_r[i][j] != buf_o[i][j]) + goto error; + } + } + } + + + /*------------------------------------------------------------------------- + * close dataset and space + *------------------------------------------------------------------------- + */ + + if (H5Dclose(did) < 0) + { + goto error; + } + if (H5Sclose(sid) < 0) + { + goto error; + } + + + + /*------------------------------------------------------------------------- + * test a dataset with non initialized chunks + *------------------------------------------------------------------------- + */ + -#ifdef H5_HAVE_FILTER_DEFLATE - } /* end for */ -#endif /* H5_HAVE_FILTER_DEFLATE */ - - puts("All set_extent tests passed."); - return 0; + if ((sid = H5Screate_simple(RANK, dims_o, maxdims)) < 0) + { + goto error; + } + if ((did = H5Dcreate2(fid , dset_name2, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + { + goto error; + } + /* set new dimensions for the array */ + dims_o[ 0 ] = 0; + dims_o[ 1 ] = 0; + if (H5Dset_extent( did , dims_o ) < 0) + { + goto error; + } + if (H5Dclose(did) < 0) + { + goto error; + } + if (H5Sclose(sid) < 0) + { + goto error; + } + + + + + /*------------------------------------------------------------------------- + * close property list + *------------------------------------------------------------------------- + */ + + + if (H5Pclose(dcpl) < 0) + { + goto error; + } + return 0; + + + error: - H5Dclose( did ); - H5Sclose( sid ); - H5Pclose( dcpl ); - H5Fclose( fid ); - H5_FAILED(); - return 1; + + H5E_BEGIN_TRY + { + H5Dclose( did ); + H5Sclose( sid ); + H5Pclose( dcpl ); + } H5E_END_TRY; + return -1; + } + + -- cgit v0.12