mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-02-23 16:20:57 +08:00
Merge Binh-Minh's changes for code improvement to chunk_info.c (PR #1942)
to develop branch.
This commit is contained in:
parent
f77d8f04fd
commit
2a4bc8c63e
@ -43,7 +43,9 @@
|
||||
#include "H5Dpkg.h"
|
||||
|
||||
#include "testhdf5.h"
|
||||
#ifdef H5_HAVE_FILTER_DEFLATE
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
/* Test file names, using H5F_libver_t as indices */
|
||||
const char *FILENAME[] = {
|
||||
@ -467,7 +469,7 @@ test_get_chunk_info_highest_v18(hid_t fapl)
|
||||
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
|
||||
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
|
||||
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
|
||||
int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY]; /* Data in chunks */
|
||||
int direct_buf[CHUNK_NX][CHUNK_NY]; /* Data chunk */
|
||||
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* 2 unlimited dims */
|
||||
hsize_t out_offset[2]; /* Buffer to get offset coordinates */
|
||||
hsize_t size = 0; /* Size of an allocated/written chunk */
|
||||
@ -480,11 +482,13 @@ test_get_chunk_info_highest_v18(hid_t fapl)
|
||||
int fillvalue = -1; /* Fill value */
|
||||
int aggression = 9; /* Compression aggression setting */
|
||||
hsize_t offset[2] = {0, 0}; /* Offset coordinates of a chunk */
|
||||
#ifdef H5_HAVE_FILTER_DEFLATE
|
||||
const Bytef *z_src = (const Bytef*)(direct_buf);
|
||||
Bytef *z_dst; /*destination buffer */
|
||||
uLongf z_dst_nbytes = (uLongf)DEFLATE_SIZE_ADJUST(CHK_SIZE);
|
||||
uLong z_src_nbytes = (uLong)CHK_SIZE;
|
||||
void *outbuf = NULL; /* Pointer to new buffer */
|
||||
#endif /* end H5_HAVE_FILTER_DEFLATE */
|
||||
void *inbuf = NULL; /* Pointer to new buffer */
|
||||
hsize_t chunk_size = CHK_SIZE; /* Size of a chunk, can be compressed or not */
|
||||
hsize_t ii, jj; /* Array indices */
|
||||
int n; /* Used as chunk index, but int to avoid conversion warning */
|
||||
@ -523,16 +527,19 @@ test_get_chunk_info_highest_v18(hid_t fapl)
|
||||
dset = H5Dcreate2(chunkfile, SIMPLE_CHUNKED_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
|
||||
if(dset < 0) TEST_ERROR
|
||||
|
||||
/* Initialize the array of chunk data for all NUM_CHUNKS chunks */
|
||||
for(n = 0; n < NUM_CHUNKS; n++)
|
||||
for(ii = 0; ii < CHUNK_NX; ii++)
|
||||
for(jj = 0; jj < CHUNK_NY; jj++)
|
||||
direct_buf[n][ii][jj] = (int)(ii*jj) + 1;
|
||||
/* Initialize a chunk of data */
|
||||
for(ii = 0; ii < CHUNK_NX; ii++)
|
||||
for(jj = 0; jj < CHUNK_NY; jj++)
|
||||
direct_buf[ii][jj] = (int)(ii*jj) + 1;
|
||||
|
||||
#ifdef H5_HAVE_FILTER_DEFLATE
|
||||
/* Allocate output (compressed) buffer */
|
||||
outbuf = malloc(z_dst_nbytes);
|
||||
z_dst = (Bytef *)outbuf;
|
||||
/* Allocate input (compressed) buffer */
|
||||
inbuf = malloc(z_dst_nbytes);
|
||||
|
||||
/* Set chunk size to the compressed chunk size and the chunk point
|
||||
to the compressed data chunk */
|
||||
chunk_size = (hsize_t)z_dst_nbytes;
|
||||
z_dst = (Bytef *)inbuf;
|
||||
|
||||
/* Perform compression from the source to the destination buffer */
|
||||
ret = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression);
|
||||
@ -548,6 +555,10 @@ test_get_chunk_info_highest_v18(hid_t fapl)
|
||||
fprintf(stderr, "other deflate error");
|
||||
TEST_ERROR
|
||||
}
|
||||
#else
|
||||
/* Allocate input (non-compressed) buffer */
|
||||
inbuf = malloc(CHK_SIZE);
|
||||
HDmemcpy(inbuf, direct_buf, CHK_SIZE);
|
||||
#endif /* end H5_HAVE_FILTER_DEFLATE */
|
||||
|
||||
/* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords:
|
||||
@ -555,21 +566,15 @@ test_get_chunk_info_highest_v18(hid_t fapl)
|
||||
n = 0;
|
||||
for(ii = START_CHK_X; ii < END_CHK_X; ii++)
|
||||
for(jj = START_CHK_Y; jj < END_CHK_Y; jj++, n++) {
|
||||
|
||||
#ifdef H5_HAVE_FILTER_DEFLATE
|
||||
/* Set chunk size to the compressed chunk size and the chunk point
|
||||
to the compressed data chunk */
|
||||
chunk_size = (hsize_t)z_dst_nbytes;
|
||||
#endif /* end H5_HAVE_FILTER_DEFLATE */
|
||||
offset[0] = ii * CHUNK_NX;
|
||||
offset[1] = jj * CHUNK_NY;
|
||||
ret = H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, chunk_size, (void*)outbuf);
|
||||
ret = H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, chunk_size, (void*)inbuf);
|
||||
if(ret < 0) TEST_ERROR
|
||||
}
|
||||
|
||||
/* Free the read buffer */
|
||||
if(outbuf)
|
||||
HDfree(outbuf);
|
||||
/* Free the input buffer */
|
||||
if(inbuf)
|
||||
HDfree(inbuf);
|
||||
|
||||
if(H5Fflush(dset, H5F_SCOPE_LOCAL) < 0)
|
||||
TEST_ERROR
|
||||
|
Loading…
Reference in New Issue
Block a user