1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF. The full HDF copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /* $Id$ */
15
16 /*
17 * This file tests the Special Chunking Element(HMCxxx) layer of the HDF library.
18 *
19 * NOTE: No failure conditions are tested yet....
20 *
21 * Outline of Tests done:
22 * 1. First test simple writing of 2-D element with no ghost/partial chunks.
23 * 4x4 array of uint8, each chunk 2x2(4 bytes) -> 4 chunks(16 bytes).
24 * Write out 12 bytes to all 4 chunks with only partial writes
25 * to the last 2 chunks..
26 * Write again to last 2 chunks with whole data chunks
27 *
28 * 2. Now create a new chunked 2-D element with same parameters
29 * before but write to 2 chunks of element using whole chunks.
30 * The rest of he data should contain fill values.
31 *
32 * 3. Create a new element but now there will be partial chunks
33 * because chunk lengths are not an even multiple of dimesion lengths.
34 * Set dimension to 4x4 array with 4 chunks where each chunk is
35 * 3x2 = 6 bytes. Real data size is 16 bytes, size with chunks is
36 * 6 bytes x 4 chunks = 24 bytes
37 *
38 * 4. Now create 3-D chunked element with no partial chunks.
39 * Write to only part of the chunked element. The rest
40 * should be filled with fill values.
41 * Set dimension to 4x6x8 array with 8 chunks
42 * where each chunk is 2x3x4= 24 bytes , read data size 192 bytes
43 * data size with chunks is 192 bytes also.
44 *
45 * 5. Now create another 3-D chunked element with partial chunks.
46 * Write to part of element, rest is filled with fill value.
47 * Set dimension to 4x6x8 array with 8 chunks , real data 192 bytes
48 * where each chunk is 3x4x5= 60 bytes ,
49 * data size with chunks is 60 bytes x 8 chunks = 480 bytes
50 *
51 * 6. Now create 3-D chunked element with no partial chunks.
52 * Write using HMCwriteChunk(). Read data back in first
53 * using Hread() and verify. Then read data back in using
54 * HMCreadChunk() and verify.
55 * Set dimension to 2x3x4 array with 6 chunks
56 * where each chunk is 1x1x4= 4 bytes , total data size 24 bytes
57 *
58 * 7. Now create 3-D chunked element with no partial chunks.
59 * Set dimension to 2x3x4 array with 6 chunks. Number type is uint16
60 * where each chunk is 1x1x4= 4x2(nt_size) = 8 bytes ,
61 * total data size 48 bytes
62 *
63 * 8. Now create 3-D chunked element with no partial chunks.
64 * Set dimension to 2x3x4 array with 6 chunks. Numbertype is float32
65 * where each chunk is 1x1x4= 4x4(nt_size) = 16 bytes ,
66 * total data size 96 bytes .
67 *
68 * 9. Create 4-D element with partial chunks.
69 * Write only half the data out(5,000 bytes)
70 * Set dimension to 10x10x10x10 array -> real data 10,000 bytes .
71 * 120 chunks with chunks of 2x3x4x5 = 120 bytes,
72 * data size with chunks is 120 bytes x 120 chunks = 14,400 bytes
73 *
74 * 10. *NOT ENABLED*
75 * The rest of the tests here are commented out
76 * They are some extra high order tests to replicate
77 * some test done on EOS-DEM data
78 * Set dimension to 12000x12000 array with 2,500 chunks
79 * whith chunk of 240x240 = 57,600 bytes
80 *
81 * 11. Create a new element but now there will be partial chunks and Compression.
82 * Set dimension to 4x4 array with 4 chunks where each chunk is 3x2 = 6 bytes.
83 * Real data size is 16 bytes, size with chunks is
84 * 6 bytes x 4 chunks = 24 bytes.
85 * The element will be compressed with RLE scheme.
86 *
87 * 12. Now create 3-D chunked, Compressed element with no partial chunks.
88 * Write using HMCwriteChunk(). Read data back in first
89 * using Hread() and verify. Then read data back in using
90 * HMCreadChunk() and verify.
91 * Set dimension to 2x3x4 array with 6 chunks
92 * where each chunk is 1x1x4= 4 bytes , total data size 24 bytes
93 * The element is compressed using RLE scheme.
94 *
95 * For all the tests the data is read back in and verified.
96 *
97 * Routines tested using User level H-level calls:
98 * Hstartread() -> HMCPstread()
99 * Hstartwrite() -> HMCPstwrite()
100 * Hread() -> HMCPread()
101 * Hwrite() -> HMCPwrite()
102 * Hseek() -> HMCPseek()
103 * Hendaccess() -> HMCPendaccess()
104 * Hinquire() -> HMCPinquire()
105 * HDget_special_info() -> HMCPinfo()
106 *
107 * Routines test by direct calling of Chunking routines:
108 * HMCcreate()
109 * HMCsetMaxCache()
110 * HMCwriteChunk()
111 * HMCreadChunk()
112 *
113 *
114 * Author -GeorgeV
115 *
116 */
117
118 #include "tproto.h"
119 #include "hchunks.h"
120
121 #define TESTFILE_NAME "tchunks.hdf"
122 #define BUFSIZE 12288
123
124 /* Some static data buffers */
125 static uint8 outbuf[BUFSIZE], /* output data buffer */
126 inbuf[BUFSIZE]; /* input data buffer */
127
128 /* used to verify data in Test 2. */
129 static uint8 outbuf_2[16] = {0,0,2,3,0,0,6,7,8,9,0,0,12,13,0,0};
130
131 /* used to in Tests 1,2 */
132 static uint8 cptr3[4] = {10,11,14,15};
133 static uint8 cptr2[4] = {8,9,12,13};
134 static uint8 cptr1[4] = {2,3,6,7};
135
136 /* for writing/verifying some chunks used in Test 6*/
137 static uint8 chunk1[4] = { 0, 1, 2, 3};
138
139 static uint8 chunk2[4] = { 10, 11, 12, 13};
140
141 static uint8 chunk3[4] = { 20, 21, 22, 23};
142
143 static uint8 chunk4[4] = { 100, 101, 102, 103};
144
145 static uint8 chunk5[4] = { 110, 111, 112, 113};
146
147 static uint8 chunk6[4] = { 120, 121, 122, 123};
148
149 /* datay layout of arrays in memory */
150 /* for comparison in Test 8 */
151 static float32 f32_data[2][3][4] =
152 {
153 {
154 {(float32) 0.0, (float32) 1.0, (float32) 2.0, (float32) 3.0},
155 {(float32) 10.0, (float32) 11.0, (float32) 12.0, (float32) 13.0},
156 {(float32) 20.0, (float32) 21.0, (float32) 22.0, (float32) 23.0}},
157 {
158 {(float32) 100.0, (float32) 101.0, (float32) 102.0, (float32) 103.0},
159 {(float32) 110.0, (float32) 111.0, (float32) 112.0, (float32) 113.0},
160 {(float32) 120.0, (float32) 121.0, (float32) 122.0, (float32) 123.0}}};
161
162 /* for comparison in Test 7 */
163 static uint16 u16_data[2][3][4] =
164 {
165 {
166 { 0, 1, 2, 3},
167 { 10, 11, 12, 13},
168 { 20, 21, 22, 23}},
169 {
170 { 100, 101, 102, 103},
171 { 110, 111, 112, 113},
172 { 120, 121, 122, 123}}};
173
174 /* for comparison in Test 6 */
175 static uint8 u8_data[2][3][4] =
176 {
177 {
178 { 0, 1, 2, 3},
179 { 10, 11, 12, 13},
180 { 20, 21, 22, 23}},
181 {
182 { 100, 101, 102, 103},
183 { 110, 111, 112, 113},
184 { 120, 121, 122, 123}}};
185
186 /*
187 * main entry point to tests the Special Chunking layer...
188 *
189 * -GeorgeV
190 */
191 void
test_chunks(void)192 test_chunks(void)
193 {
194 int32 fid;
195 int32 aid1, aid2;
196 int32 fileid, length, offset, posn;
197 uint16 tag, ref;
198 int16 acc_mode, special;
199 register int i, j, k;
200 #ifdef BIG_TEST
201 int32 x,y;
202 int32 nseek = 0;
203 #endif
204 int32 ret;
205 HCHUNK_DEF chunk[1]; /* Chunk definition, see 'hchunks.h' */
206 int32 dims[5];
207 int32 fill_val_len = 1;
208 uint8 fill_val_u8 = 0; /* test 6 */
209 uint16 fill_val_u16 = 0; /* test 7 */
210 float32 fill_val_f32 = (float32)0.0; /* test 8 */
211 uint8 inbuf_u8[2][3][4];
212 uint16 inbuf_u16[2][3][4]; /* input data buffer */
213 float32 inbuf_f32[2][3][4]; /* input data buffer */
214 sp_info_block_t info_block; /* special info block */
215 comp_info cinfo;
216 model_info minfo;
217 intn errors = 0;
218
219 /* intialize out buffer */
220 for (i = 0; i < BUFSIZE; i++)
221 outbuf[i] = (char) (i % 256);
222
223 /* allocate space for chunk dimensions */
224 if ((chunk[0].pdims = (DIM_DEF *)HDmalloc(5*sizeof(DIM_DEF))) == NULL)
225 {
226 printf("test_chunks: error allocatin space for chunk dims\n");
227 errors++;
228 goto done;
229 }
230
231 /* Create file first */
232 MESSAGE(5, printf("Creating a file %s\n", TESTFILE_NAME); );
233 fid = Hopen(TESTFILE_NAME, DFACC_CREATE, 0);
234 CHECK_VOID(fid, FAIL, "Hopen");
235
236
237 /*
238 1.First test simple writing of 2-D element with no ghost/partial chunks.
239 Set dimension to 4x4 array with 4 chunks
240 where each chunk is 2x2.
241 Write out 12 bytes to all 4 chunks with only partial writes
242 to the last 2 chunks..
243 Write again to last 2 chunks with whole data chunks
244 */
245 chunk[0].num_dims = 2; /* 2-D */
246 chunk[0].chunk_size = 4; /* 2x2 = 4 bytes */
247 chunk[0].nt_size = 1; /* number type size */
248 chunk[0].chunk_flag = 0; /* nothing set */
249 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
250 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
251 chunk[0].cinfo = NULL; /* nothing set */
252 chunk[0].minfo = NULL; /* nothing set */
253
254 chunk[0].pdims[0].dim_length = 4;
255 chunk[0].pdims[0].chunk_length = 2;
256 chunk[0].pdims[0].distrib_type = 1;
257
258 chunk[0].pdims[1].dim_length = 4;
259 chunk[0].pdims[1].chunk_length = 2;
260 chunk[0].pdims[1].distrib_type = 1;
261
262 MESSAGE(5, printf("Test 1. Create a new element as a 2-D, uint8 chunked element\n"););
263 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
264 0,(int)chunk[0].pdims[0].dim_length,
265 0,(int)chunk[0].pdims[0].chunk_length););
266 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
267 1,(int)chunk[0].pdims[1].dim_length,
268 1,(int)chunk[0].pdims[1].chunk_length););
269
270 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
271 aid1 = HMCcreate(fid, 1020, 2, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
272 CHECK_VOID(aid1, FAIL, "HMCcreate");
273
274 #if 0
275 /* write 16 bytes out */
276 ret = Hwrite(aid1, 16, outbuf);
277 if (ret != 16)
278 {
279 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
280 errors++;
281 goto done;
282 }
283
284 MESSAGE(5, printf("Wrote first 16 bytes to 2-D, uint8 chunked element to file\n"); );
285 /* end access */
286 ret = Hendaccess(aid1);
287 CHECK_VOID(ret, FAIL, "Hendaccess");
288
289 MESSAGE(5, printf("Closing the file\n"););
290
291 ret = Hclose(fid);
292 CHECK_VOID(ret, FAIL, "Hclose");
293
294 #endif
295
296 /* write 12 bytes out */
297 ret = Hwrite(aid1, 12, outbuf);
298 if (ret != 12)
299 {
300 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
301 errors++;
302 goto done;
303 }
304
305 MESSAGE(5, printf("Wrote first 12 bytes to 2-D, uint8 chunked element to file\n"); );
306 /* end access */
307 ret = Hendaccess(aid1);
308 CHECK_VOID(ret, FAIL, "Hendaccess");
309
310 MESSAGE(5, printf("Closing the file\n"););
311
312 ret = Hclose(fid);
313 CHECK_VOID(ret, FAIL, "Hclose");
314
315 MESSAGE(5, printf("Open 2-D chunked element again for writing\n"); );
316
317 /* Open file for writing last 2 chunks now */
318 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
319 CHECK_VOID(fid, FAIL, "Hopen");
320
321 /* start write access tag, ref */
322 aid1 = Hstartwrite(fid, 1020, 2, 16);
323 CHECK_VOID(aid1, FAIL, "Hstartwrite");
324
325 /* Try writing to last chunk in the element */
326 dims[0] = 1;
327 dims[1] = 1;
328 ret = HMCwriteChunk(aid1, dims, cptr3);
329 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
330
331 MESSAGE(5, printf("Wrote to 4th chunk(4of4 chunks) in file\n"););
332
333 /* Try writing to 2nd to last chunk in the element */
334 dims[0] = 1;
335 dims[1] = 0;
336 ret = HMCwriteChunk(aid1, dims, cptr2);
337 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
338
339 MESSAGE(5, printf("Wrote to 3 chunk (3of4 chunks) in file\n"););
340 /* end access */
341 ret = Hendaccess(aid1);
342 CHECK_VOID(ret, FAIL, "Hendaccess");
343
344 MESSAGE(5, printf("Closing the file\n"););
345 ret = Hclose(fid);
346 CHECK_VOID(ret, FAIL, "Hclose");
347
348 MESSAGE(5, printf("Open 2-D, uint8 chunked element again for reading \n"); );
349 /* Open file for reading now */
350 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
351 CHECK_VOID(fid, FAIL, "Hopen");
352
353 /* start read access tag, ref */
354 aid1 = Hstartread(fid, 1020, 2);
355 CHECK_VOID(aid1, FAIL, "Hstartread");
356
357 /* inquire about element */
358 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
359 &acc_mode, &special);
360
361 CHECK_VOID(ret, FAIL, "Hinquire");
362 if (!special)
363 {
364 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
365 __LINE__);
366 errors++;
367 goto done;
368 }
369 /* Check values from Hinquire */
370 if (ref != 2 || length != 16)
371 {
372 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
373 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
374 errors++;
375 goto done;
376 }
377
378 MESSAGE(5, printf("Get/Check special info data\n"); );
379
380 /* get special info about element */
381 ret = HDget_special_info(aid1, &info_block);
382 CHECK_VOID(aid1, FAIL, "HDget_special_info");
383
384 /* check special info */
385 if (info_block.ndims != chunk[0].num_dims /* 2-D */)
386 {
387 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
388 errors++;
389 goto done;
390 }
391
392 /* check chunk_lengths */
393 if (info_block.cdims != NULL)
394 {
395 if ((info_block.cdims[0] != 2) || (info_block.cdims[1] != 2))
396 {
397 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
398 errors++;
399 goto done;
400 }
401
402 /* free allocated space by routine */
403 HDfree(info_block.cdims);
404 }
405 else
406 {
407 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
408 errors++;
409 goto done;
410 }
411
412
413 /* read back in buffer */
414 ret = Hread(aid1, 16, inbuf);
415 VERIFY_VOID(ret, 16, "Hread");
416 if (ret != 16)
417 {
418 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
419 errors++;
420 goto done;
421 }
422
423 /* verify the data */
424 MESSAGE(5, printf("Verifying 16 bytes of data\n"); );
425 for (i = 0; i < ret; i++)
426 {
427 if (inbuf[i] != outbuf[i])
428 {
429 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
430 errors++;
431 }
432
433 }
434 if (errors)
435 goto done;
436
437 /* end access and close file */
438 ret = Hendaccess(aid1);
439 CHECK_VOID(ret, FAIL, "Hendaccess");
440
441 MESSAGE(5, printf("Closing the file\n"););
442 ret = Hclose(fid);
443 CHECK_VOID(ret, FAIL, "Hclose");
444
445 /*
446 2. Now create a new chunked 2-D element with same parameters
447 before but write to 2 chunks of element using whole chunks.
448 The rest of he data should contain fill values.
449 */
450
451 /* Open file for writing again */
452 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
453 CHECK_VOID(fid, FAIL, "Hopen");
454
455 MESSAGE(5, printf("Test 2. Create another new element as a 2-D, uint8 chunked element\n"););
456 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
457 0,(int)chunk[0].pdims[0].dim_length,
458 0,(int)chunk[0].pdims[0].chunk_length););
459 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
460 1,(int)chunk[0].pdims[1].dim_length,
461 1,(int)chunk[0].pdims[1].chunk_length););
462
463 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
464 aid1 = HMCcreate(fid, 1020, 3, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
465 CHECK_VOID(aid1, FAIL, "HMCcreate");
466
467 /* Try writing to 2 chunk in the element */
468 dims[0] = 1;
469 dims[1] = 0;
470 ret = HMCwriteChunk(aid1, dims, cptr2);
471 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
472
473 MESSAGE(5, printf("Wrote to 3 chunk (3of4) in file\n"); );
474
475 /* Try writing to 1 chunk in the element */
476 dims[0] = 0;
477 dims[1] = 1;
478 ret = HMCwriteChunk(aid1, dims, cptr1);
479 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
480
481 MESSAGE(5, printf("Wrote to 2nd chunk (2of4 chunks) in file\n"); );
482
483 /* end access and close file */
484 ret = Hendaccess(aid1);
485 CHECK_VOID(ret, FAIL, "Hendaccess");
486
487 MESSAGE(5, printf("Closing the file\n"); );
488 ret = Hclose(fid);
489 CHECK_VOID(ret, FAIL, "Hclose");
490
491 /* Now reopen and read back 16 bytes */
492 MESSAGE(5, printf("Open 2-D, uint8 chunked element again for reading \n"); );
493 /* Open file for reading now */
494 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
495 CHECK_VOID(fid, FAIL, "Hopen");
496
497 /* start read access tag, ref */
498 aid1 = Hstartread(fid, 1020, 3);
499 CHECK_VOID(aid1, FAIL, "Hstartread");
500
501 /* inquire about element */
502 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
503 &acc_mode, &special);
504
505 CHECK_VOID(ret, FAIL, "Hinquire");
506 if (!special)
507 {
508 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
509 __LINE__);
510 errors++;
511 goto done;
512 }
513
514 /* Check values from Hinquire */
515 if ( ref != 3 || length != 16)
516 {
517 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
518 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
519 errors++;
520 goto done;
521 }
522
523 /* read back in buffer */
524 ret = Hread(aid1, 16, inbuf);
525 VERIFY_VOID(ret, 16, "Hread");
526 if (ret != 16)
527 {
528 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
529 errors++;
530 goto done;
531 }
532
533 /* verify the data, check against 'outbuf_2'
534 some of the data should be filled with fill value of 0 */
535 MESSAGE(5, printf("Verifying 16 bytes of data, there will be some fill values\n"); );
536 for (i = 0; i < ret; i++)
537 {
538 if (inbuf[i] != outbuf_2[i])
539 {
540 printf("Wrong data at %d, out %d in %d\n", i, outbuf_2[i], inbuf[i]);
541 errors++;
542 }
543 }
544 if (errors)
545 goto done;
546
547 /* end access and close file */
548 ret = Hendaccess(aid1);
549 CHECK_VOID(ret, FAIL, "Hendaccess");
550
551 MESSAGE(5, printf("Closing the file\n"); );
552 ret = Hclose(fid);
553 CHECK_VOID(ret, FAIL, "Hclose");
554
555
556 /*
557 3. Create a new element but now there will be partial chunks
558 because chunk lengths are not an even multiple of dimesion lengths.
559 Set dimension to 4x4 array with 4 chunks where each chunk is 3x2 = 6 bytes.
560 Real data size is 16 bytes, size with chunks is
561 6 bytes x 4 chunks = 24 bytes
562 */
563 chunk[0].num_dims = 2;
564 chunk[0].chunk_size = 6; /* 3x2 = 6 bytes */
565 chunk[0].nt_size = 1; /* number type size */
566 chunk[0].chunk_flag = 0; /* nothing set */
567 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
568 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
569 chunk[0].cinfo = NULL; /* nothing set */
570 chunk[0].minfo = NULL; /* nothing set */
571
572 chunk[0].pdims[0].dim_length = 4;
573 chunk[0].pdims[0].chunk_length = 3; /* made this 3 */
574 chunk[0].pdims[0].distrib_type = 1;
575
576 chunk[0].pdims[1].dim_length = 4;
577 chunk[0].pdims[1].chunk_length = 2;
578 chunk[0].pdims[1].distrib_type = 1;
579
580 /* Open file for writing odd size chunks now */
581 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
582 CHECK_VOID(fid, FAIL, "Hopen");
583
584 MESSAGE(5, printf("Test 3. Create another new element as a 2-D, uint8 chunked element\n"););
585 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
586 0,(int)chunk[0].pdims[0].dim_length,
587 0,(int)chunk[0].pdims[0].chunk_length););
588 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
589 1,(int)chunk[0].pdims[1].dim_length,
590 1,(int)chunk[0].pdims[1].chunk_length););
591
592 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
593 aid1 = HMCcreate(fid, 1020, 5, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
594 CHECK_VOID(aid1, FAIL, "HMCcreate");
595
596 /* write 16 bytes out */
597 ret = Hwrite(aid1, 16, outbuf);
598 VERIFY_VOID(ret, 16, "Hwrite");
599 if (ret != 16)
600 {
601 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
602 errors++;
603 goto done;
604 }
605
606 MESSAGE(5, printf("Wrote to 4of4 chunks (16 bytes) in file\n"););
607 /* end access */
608 ret = Hendaccess(aid1);
609 CHECK_VOID(ret, FAIL, "Hendaccess");
610
611 MESSAGE(5, printf("Closing the file\n"); );
612 ret = Hclose(fid);
613 CHECK_VOID(ret, FAIL, "Hclose");
614
615 MESSAGE(5, printf("Open 2-D, uint8 chunked element again for reading\n"); );
616
617 /* Open file for reading now */
618 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
619 CHECK_VOID(fid, FAIL, "Hopen");
620
621 /* start read access tag, ref */
622 aid1 = Hstartread(fid, 1020, 5);
623 CHECK_VOID(aid1, FAIL, "Hstartread");
624
625 /* inquire about element */
626 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
627 &acc_mode, &special);
628
629 CHECK_VOID(ret, FAIL, "Hinquire");
630 if (!special)
631 {
632 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
633 __LINE__);
634 errors++;
635 goto done;
636 }
637
638 /* Check values from Hinquire */
639 if ( ref != 5 || length != 16)
640 {
641 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
642 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
643 errors++;
644 goto done;
645 }
646
647 /* read back in buffer */
648 ret = Hread(aid1, 16, inbuf);
649 VERIFY_VOID(ret, 16, "Hread");
650 if (ret != 16)
651 {
652 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
653 errors++;
654 goto done;
655 }
656
657 /* verify the data */
658 MESSAGE(5, printf("Verifying 16 bytes of data\n"); );
659 for (i = 0; i < ret; i++)
660 {
661 if (inbuf[i] != outbuf[i])
662 {
663 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
664 errors++;
665 }
666 inbuf[i] = '\0';
667 }
668 if (errors)
669 goto done;
670
671 /* end access and close file */
672 ret = Hendaccess(aid1);
673 CHECK_VOID(ret, FAIL, "Hendaccess");
674
675 MESSAGE(5, printf("Closing the file\n"); );
676 ret = Hclose(fid);
677 CHECK_VOID(ret, FAIL, "Hclose");
678
679
680 /*
681 4. Now create 3-D chunked element with no partial chunks.
682 Write to only part of the chunked element. The rest
683 should be filled with fill values.
684 Set dimension to 4x6x8 array with 8 chunks
685 where each chunk is 2x3x4= 24 bytes , total data size 192 bytes
686 */
687 chunk[0].num_dims = 3;
688 chunk[0].chunk_size = 24; /* 2x3x4 bytes */
689 chunk[0].nt_size = 1; /* number type size */
690 chunk[0].chunk_flag = 0; /* nothing set */
691 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
692 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
693 chunk[0].cinfo = NULL; /* nothing set */
694 chunk[0].minfo = NULL; /* nothing set */
695
696 chunk[0].pdims[0].dim_length = 4;
697 chunk[0].pdims[0].chunk_length = 2;
698 chunk[0].pdims[0].distrib_type = 1;
699
700 chunk[0].pdims[1].dim_length = 6;
701 chunk[0].pdims[1].chunk_length = 3;
702 chunk[0].pdims[1].distrib_type = 1;
703
704 chunk[0].pdims[2].dim_length = 8;
705 chunk[0].pdims[2].chunk_length = 4;
706 chunk[0].pdims[2].distrib_type = 1;
707
708 /* Open file for writing last odd size chunks now */
709 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
710 CHECK_VOID(fid, FAIL, "Hopen");
711 MESSAGE(5, printf("Test 4. Create another new element as a 3-D, uint8 chunked element(192 bytes)\n"););
712 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
713 0,(int)chunk[0].pdims[0].dim_length,
714 0,(int)chunk[0].pdims[0].chunk_length););
715 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
716 1,(int)chunk[0].pdims[1].dim_length,
717 1,(int)chunk[0].pdims[1].chunk_length););
718 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
719 2,(int)chunk[0].pdims[2].dim_length,
720 2,(int)chunk[0].pdims[2].chunk_length););
721
722 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
723 aid1 = HMCcreate(fid, 1020, 6, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
724 CHECK_VOID(aid1, FAIL, "HMCcreate");
725
726 /* write only 112 bytes out */
727 ret = Hwrite(aid1, 112, outbuf);
728 VERIFY_VOID(ret, 112, "Hwrite");
729 if (ret != 112)
730 {
731 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
732 errors++;
733 goto done;
734 }
735
736 MESSAGE(5, printf("Wrote 112of192 bytes to 3-D, uint8 chunked element \n"); );
737 /* end access */
738 ret = Hendaccess(aid1);
739 CHECK_VOID(ret, FAIL, "Hendaccess");
740
741 MESSAGE(5, printf("Closing the files\n");
742 );
743 ret = Hclose(fid);
744 CHECK_VOID(ret, FAIL, "Hclose");
745
746 MESSAGE(5, printf("Open 3-D, uint8 chunked element again for reading\n"); );
747 /* Open file for reading now */
748 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
749 CHECK_VOID(fid, FAIL, "Hopen");
750
751 /* start read access tag, ref */
752 aid1 = Hstartread(fid, 1020, 6);
753 CHECK_VOID(aid1, FAIL, "Hstartread");
754
755 /* inquire about element */
756 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
757 &acc_mode, &special);
758
759 CHECK_VOID(ret, FAIL, "Hinquire");
760 if (!special)
761 {
762 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
763 __LINE__);
764 errors++;
765 goto done;
766 }
767
768 /* Check values from Hinquire */
769 if ( ref != 6 || length != 192)
770 {
771 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
772 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
773 errors++;
774 goto done;
775 }
776
777 MESSAGE(5, printf("Get/Check special info data\n"); );
778
779 /* get special info about element */
780 ret = HDget_special_info(aid1, &info_block);
781 CHECK_VOID(aid1, FAIL, "HDget_special_info");
782
783 /* check special info */
784 if (info_block.ndims != chunk[0].num_dims /* 2-D */)
785 {
786 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
787 errors++;
788 goto done;
789 }
790
791 /* check chunk_lengths */
792 if (info_block.cdims != NULL)
793 {
794 if ((info_block.cdims[0] != 2)
795 || (info_block.cdims[1] != 3)
796 || (info_block.cdims[2] != 4))
797 {
798 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
799 errors++;
800 goto done;
801 }
802
803 /* free allocated space by routine */
804 HDfree(info_block.cdims);
805 }
806 else
807 {
808 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
809 errors++;
810 goto done;
811 }
812
813
814 /* read back in buffer */
815 ret = Hread(aid1, 112, inbuf);
816 VERIFY_VOID(ret, 112, "Hread");
817 if (ret != 112)
818 {
819 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
820 errors++;
821 goto done;
822 }
823
824 /* verify the data */
825 MESSAGE(5, printf("Verifying first 112 bytes data\n"); );
826 for (i = 0; i < ret; i++)
827 {
828 if (inbuf[i] != outbuf[i])
829 {
830 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
831 errors++;
832 }
833 inbuf[i] = '\0';
834 }
835 if (errors)
836 goto done;
837
838 /* end access and close file */
839 ret = Hendaccess(aid1);
840 CHECK_VOID(ret, FAIL, "Hendaccess");
841
842 MESSAGE(5, printf("Closing the file\n"););
843 ret = Hclose(fid);
844 CHECK_VOID(ret, FAIL, "Hclose");
845
846
847 /*
848 5. Now create another 3-D chunked element with partial chunks.
849 Write to part of element, rest is filled with fill value.
850 Set dimension to 4x6x8 array with 8 chunks , real data 192 bytes
851 where each chunk is 3x4x5= 60 bytes ,
852 data size with chunks is 60 bytes x 8 chunks = 480 bytes
853 */
854 chunk[0].num_dims = 3;
855 chunk[0].chunk_size = 60; /* 3x4x5 = 60 bytes */
856 chunk[0].nt_size = 1; /* number type size */
857 chunk[0].chunk_flag = 0; /* nothing set */
858 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
859 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
860 chunk[0].cinfo = NULL; /* nothing set */
861 chunk[0].minfo = NULL; /* nothing set */
862
863 chunk[0].pdims[0].dim_length = 4;
864 chunk[0].pdims[0].chunk_length = 3;
865 chunk[0].pdims[0].distrib_type = 1;
866
867 chunk[0].pdims[1].dim_length = 6;
868 chunk[0].pdims[1].chunk_length = 4;
869 chunk[0].pdims[1].distrib_type = 1;
870
871 chunk[0].pdims[2].dim_length = 8;
872 chunk[0].pdims[2].chunk_length = 5;
873 chunk[0].pdims[2].distrib_type = 1;
874
875 /* set fill value to 1 */
876 fill_val_u8 = 1;
877 fill_val_len = 1;
878
879 /* Open file for writing last odd size chunks now */
880 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
881 CHECK_VOID(fid, FAIL, "Hopen");
882
883 MESSAGE(5, printf("Test 5. Create another new element as a 3-D, uint8 chunked element(192bytes)\n"););
884 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
885 0,(int)chunk[0].pdims[0].dim_length,
886 0,(int)chunk[0].pdims[0].chunk_length););
887 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
888 1,(int)chunk[0].pdims[1].dim_length,
889 1,(int)chunk[0].pdims[1].chunk_length););
890 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
891 2,(int)chunk[0].pdims[2].dim_length,
892 2,(int)chunk[0].pdims[2].chunk_length););
893
894 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
895 aid1 = HMCcreate(fid, 1020, 7, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
896 CHECK_VOID(aid1, FAIL, "HMCcreate");
897
898 /* Set max chunks to cache to 3x4 = 12 chunks */
899 MESSAGE(5, printf("Set max # of chunks to cache for chunked element to 12 \n"); );
900 ret = HMCsetMaxcache(aid1, 12, 0);
901 VERIFY_VOID(ret, 12, "HMCsetMaxcache");
902
903 /* write 112 bytes out */
904 ret = Hwrite(aid1, 112, outbuf);
905 VERIFY_VOID(ret, 112, "Hwrite");
906 if (ret != 112)
907 {
908 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
909 errors++;
910 goto done;
911 }
912
913 MESSAGE(5, printf("Wrote 112of192 bytes to 3-D, uint8 chunked element \n"); );
914
915 /* end access */
916 ret = Hendaccess(aid1);
917 CHECK_VOID(ret, FAIL, "Hendaccess");
918
919 MESSAGE(5, printf("Closing the file\n"););
920 ret = Hclose(fid);
921 CHECK_VOID(ret, FAIL, "Hclose");
922
923 MESSAGE(5, printf("Open 3-D, uint8 chunked element again for reading\n"); );
924 /* Open file for reading now */
925 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
926 CHECK_VOID(fid, FAIL, "Hopen");
927
928 /* start read access tag, ref */
929 aid1 = Hstartread(fid, 1020, 7);
930 CHECK_VOID(aid1, FAIL, "Hstartread");
931
932 /* inquire about element */
933 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
934 &acc_mode, &special);
935
936 CHECK_VOID(ret, FAIL, "Hinquire");
937 if (!special)
938 {
939 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
940 __LINE__);
941 errors++;
942 goto done;
943 }
944
945 /* Check values from Hinquire */
946 if ( ref != 7 || length != 192)
947 {
948 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
949 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
950 errors++;
951 goto done;
952 }
953
954 /* read back in buffer */
955 ret = Hread(aid1, 112, inbuf);
956 VERIFY_VOID(ret, 112, "Hread");
957 if (ret != 112)
958 {
959 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
960 errors++;
961 goto done;
962 }
963
964 /* verify the data */
965 MESSAGE(5, printf("Verifying data\n"););
966 for (i = 0; i < ret; i++)
967 {
968 if (inbuf[i] != outbuf[i])
969 {
970 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
971 errors++;
972 }
973 inbuf[i] = '\0';
974 }
975 if (errors)
976 goto done;
977
978 /* read back 20 bytes now, they should be filled with fill values */
979 MESSAGE(5, printf("reading some more data\n"););
980 ret = Hread(aid1, 20, inbuf);
981 VERIFY_VOID(ret, 20, "Hread");
982 if (ret != 20)
983 {
984 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
985 errors++;
986 goto done;
987 }
988
989 /* verify the data */
990 MESSAGE(5, printf("Verifying data, should be full of fill values\n"); );
991 for (i = 0; i < ret; i++)
992 {
993 if (inbuf[i] != fill_val_u8)
994 {
995 printf("Wrong data at %d, out %d in %d\n", i, fill_val_u8, inbuf[i]);
996 errors++;
997 }
998 }
999 if (errors)
1000 goto done;
1001
1002 /* end access and close file */
1003 ret = Hendaccess(aid1);
1004 CHECK_VOID(ret, FAIL, "Hendaccess");
1005
1006 MESSAGE(5, printf("Closing the file\n"); );
1007 ret = Hclose(fid);
1008 CHECK_VOID(ret, FAIL, "Hclose");
1009
1010
1011 /*
1012 6. Now create 3-D chunked element with no partial chunks.
1013 Write using HMCwriteChunk(). Read data back in first
1014 using Hread() and verify. Then read data back in using
1015 HMCreadChunk() and verify.
1016 Set dimension to 2x3x4 array with 6 chunks
1017 where each chunk is 1x1x4= 4 bytes , total data size 24 bytes
1018 */
1019 chunk[0].num_dims = 3;
1020 chunk[0].chunk_size = 4; /* 1x1x4 bytes */
1021 chunk[0].nt_size = 1; /* number type size */
1022 chunk[0].chunk_flag = 0; /* nothing set */
1023 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
1024 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
1025 chunk[0].cinfo = NULL; /* nothing set */
1026 chunk[0].minfo = NULL; /* nothing set */
1027 #if 0
1028 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
1029 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
1030 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
1031 chunk[0].cinfo = &cinfo; /* nothing set */
1032 chunk[0].minfo = &minfo; /* nothing set */
1033 #endif
1034
1035 chunk[0].pdims[0].dim_length = 2;
1036 chunk[0].pdims[0].chunk_length = 1;
1037 chunk[0].pdims[0].distrib_type = 1;
1038
1039 chunk[0].pdims[1].dim_length = 3;
1040 chunk[0].pdims[1].chunk_length = 1;
1041 chunk[0].pdims[1].distrib_type = 1;
1042
1043 chunk[0].pdims[2].dim_length = 4;
1044 chunk[0].pdims[2].chunk_length = 4;
1045 chunk[0].pdims[2].distrib_type = 0; /* NONE */
1046
1047 /* set fill value to 1 */
1048 fill_val_u8 = 1;
1049 fill_val_len = 1;
1050
1051 /* Open file for writing last odd size chunks now */
1052 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1053 CHECK_VOID(fid, FAIL, "Hopen");
1054 MESSAGE(5, printf("Test 6. Create another new element as a 3-D, uint8 chunked element(192 bytes)\n"););
1055 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1056 0,(int)chunk[0].pdims[0].dim_length,
1057 0,(int)chunk[0].pdims[0].chunk_length););
1058 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1059 1,(int)chunk[0].pdims[1].dim_length,
1060 1,(int)chunk[0].pdims[1].chunk_length););
1061 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1062 2,(int)chunk[0].pdims[2].dim_length,
1063 2,(int)chunk[0].pdims[2].chunk_length););
1064
1065 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1066 aid1 = HMCcreate(fid, 1020, 12, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
1067 CHECK_VOID(aid1, FAIL, "HMCcreate");
1068
1069 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1070 aid2 = HMCcreate(fid, 1020, 18, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
1071 CHECK_VOID(aid1, FAIL, "HMCcreate");
1072
1073 /* write 24 bytes out */
1074 ret = Hwrite(aid2, 24, u8_data);
1075 if (ret != 24)
1076 {
1077 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
1078 errors++;
1079 goto done;
1080 }
1081
1082 /* write data out as chunks */
1083 MESSAGE(5, printf("Writing to 3-D, uint8 chunked element using HMCwriteChunk\n"); );
1084
1085 /* Write data use SDwriteChunk */
1086 dims[0] = 0;
1087 dims[1] = 0;
1088 dims[2] = 0;
1089 ret = HMCwriteChunk(aid1, dims, chunk1);
1090 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1091
1092 dims[0] = 1;
1093 dims[1] = 0;
1094 dims[2] = 0;
1095 ret = HMCwriteChunk(aid1, dims, chunk4);
1096 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1097
1098 dims[0] = 0;
1099 dims[1] = 1;
1100 dims[2] = 0;
1101 ret = HMCwriteChunk(aid1, dims, chunk2);
1102 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1103
1104 dims[0] = 1;
1105 dims[1] = 1;
1106 dims[2] = 0;
1107 ret = HMCwriteChunk(aid1, dims, chunk5);
1108 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1109
1110 dims[0] = 0;
1111 dims[1] = 2;
1112 dims[2] = 0;
1113 ret = HMCwriteChunk(aid1, dims, chunk3);
1114 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1115
1116 dims[0] = 1;
1117 dims[1] = 2;
1118 dims[2] = 0;
1119 ret = HMCwriteChunk(aid1, dims, chunk6);
1120 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
1121
1122 /* end access */
1123 ret = Hendaccess(aid1);
1124 CHECK_VOID(ret, FAIL, "Hendaccess");
1125
1126 /* end access */
1127 ret = Hendaccess(aid2);
1128 CHECK_VOID(ret, FAIL, "Hendaccess");
1129
1130 MESSAGE(5, printf("Closing the files\n"););
1131 ret = Hclose(fid);
1132 CHECK_VOID(ret, FAIL, "Hclose");
1133
1134 MESSAGE(5, printf("Open 3-D, uint8 chunked element again for reading\n"); );
1135 /* Open file for reading now */
1136 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1137 CHECK_VOID(fid, FAIL, "Hopen");
1138
1139 /* start read access tag, ref */
1140 aid1 = Hstartread(fid, 1020, 12);
1141 CHECK_VOID(aid1, FAIL, "Hstartread");
1142
1143 /* start read access tag, ref */
1144 aid2 = Hstartread(fid, 1020, 18);
1145 CHECK_VOID(aid1, FAIL, "Hstartread");
1146
1147 /* inquire about element */
1148 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
1149 &acc_mode, &special);
1150
1151 CHECK_VOID(ret, FAIL, "Hinquire");
1152 if (!special)
1153 {
1154 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
1155 __LINE__);
1156 errors++;
1157 goto done;
1158 }
1159
1160 /* Check values from Hinquire */
1161 if ( ref != 12 || length != 24)
1162 {
1163 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
1164 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
1165 errors++;
1166 goto done;
1167 }
1168
1169 MESSAGE(5, printf("Get/Check special info data\n"); );
1170
1171 /* get special info about element */
1172 ret = HDget_special_info(aid1, &info_block);
1173 CHECK_VOID(aid1, FAIL, "HDget_special_info");
1174
1175 /* check special info */
1176 if (info_block.ndims != chunk[0].num_dims /* 2-D */)
1177 {
1178 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
1179 errors++;
1180 goto done;
1181 }
1182
1183 /* check chunk_lengths */
1184 if (info_block.cdims != NULL)
1185 {
1186 if ((info_block.cdims[0] != 1)
1187 || (info_block.cdims[1] != 1)
1188 || (info_block.cdims[2] != 4))
1189 {
1190 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
1191 errors++;
1192 goto done;
1193 }
1194
1195 /* free allocated space by routine */
1196 HDfree(info_block.cdims);
1197 }
1198 else
1199 {
1200 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
1201 errors++;
1202 goto done;
1203 }
1204
1205
1206 /* read back in buffer */
1207 ret = Hread(aid1, 24, inbuf_u8);
1208 VERIFY_VOID(ret, 24, "Hread");
1209 if (ret != 24)
1210 {
1211 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1212 errors++;
1213 goto done;
1214 }
1215
1216 /* verify the data */
1217 MESSAGE(5, printf("Verifying 24 bytes data from Hread\n"); );
1218 for (i = 0; i < 2; i++)
1219 {
1220 for (j = 0; j < 3; j++)
1221 {
1222 for (k = 0; k < 4; k++)
1223 {
1224 if (inbuf_u8[i][j][k] != u8_data[i][j][k])
1225 {
1226 printf("Wrong data at inbuf_u8[%d][%d][%d], out %d in %d\n",
1227 i,j,k, u8_data[i][j][k], inbuf_u8[i][j][k]);
1228 errors++;
1229 }
1230 }
1231 }
1232 }
1233
1234 if (errors)
1235 goto done;
1236
1237 MESSAGE(5, printf("Verifying 24 bytes using HMCreadChunk\n"); );
1238 /* read data back as chunks */
1239 dims[0] = 0;
1240 dims[1] = 0;
1241 dims[2] = 0;
1242 ret = HMCreadChunk(aid2, dims, inbuf);
1243 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1244 if (ret != 4)
1245 {
1246 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1247 errors++;
1248 goto done;
1249 }
1250
1251 MESSAGE(5, printf("Verifying chunk1 4 bytes data\n"); );
1252 for (i = 0; i < ret; i++)
1253 {
1254 if (inbuf[i] != chunk1[i])
1255 {
1256 printf("Wrong data at %d, out %d in %d\n", i, chunk1[i], inbuf[i]);
1257 errors++;
1258 }
1259 }
1260
1261 dims[0] = 0;
1262 dims[1] = 1;
1263 dims[2] = 0;
1264 ret = HMCreadChunk(aid2, dims, inbuf);
1265 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1266 if (ret != 4)
1267 {
1268 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1269 errors++;
1270 goto done;
1271 }
1272
1273 MESSAGE(5, printf("Verifying chunk2 4 bytes data\n"); );
1274 for (i = 0; i < ret; i++)
1275 {
1276 if (inbuf[i] != chunk2[i])
1277 {
1278 printf("Wrong data at %d, out %d in %d\n", i, chunk2[i], inbuf[i]);
1279 errors++;
1280 }
1281 }
1282
1283 dims[0] = 0;
1284 dims[1] = 2;
1285 dims[2] = 0;
1286 ret = HMCreadChunk(aid2, dims, inbuf);
1287 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1288 if (ret != 4)
1289 {
1290 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1291 errors++;
1292 goto done;
1293 }
1294
1295 MESSAGE(5, printf("Verifying chunk3 4 bytes data\n"); );
1296 for (i = 0; i < ret; i++)
1297 {
1298 if (inbuf[i] != chunk3[i])
1299 {
1300 printf("Wrong data at %d, out %d in %d\n", i, chunk3[i], inbuf[i]);
1301 errors++;
1302 }
1303 }
1304
1305 dims[0] = 1;
1306 dims[1] = 0;
1307 dims[2] = 0;
1308 ret = HMCreadChunk(aid2, dims, inbuf);
1309 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1310 if (ret != 4)
1311 {
1312 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1313 errors++;
1314 goto done;
1315 }
1316
1317 MESSAGE(5, printf("Verifying chunk4 4 bytes data\n"); );
1318 for (i = 0; i < ret; i++)
1319 {
1320 if (inbuf[i] != chunk4[i])
1321 {
1322 printf("Wrong data at %d, out %d in %d\n", i, chunk4[i], inbuf[i]);
1323 errors++;
1324 }
1325 }
1326
1327 dims[0] = 1;
1328 dims[1] = 1;
1329 dims[2] = 0;
1330 ret = HMCreadChunk(aid2, dims, inbuf);
1331 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1332 if (ret != 4)
1333 {
1334 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1335 errors++;
1336 goto done;
1337 }
1338
1339 MESSAGE(5, printf("Verifying chunk5 4 bytes data\n"); );
1340 for (i = 0; i < ret; i++)
1341 {
1342 if (inbuf[i] != chunk5[i])
1343 {
1344 printf("Wrong data at %d, out %d in %d\n", i, chunk5[i], inbuf[i]);
1345 errors++;
1346 }
1347 }
1348
1349 dims[0] = 1;
1350 dims[1] = 2;
1351 dims[2] = 0;
1352 ret = HMCreadChunk(aid2, dims, inbuf);
1353 CHECK_VOID(ret, FAIL, "HMCreadChunk");
1354 if (ret != 4)
1355 {
1356 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
1357 errors++;
1358 goto done;
1359 }
1360
1361 MESSAGE(5, printf("Verifying chunk6 4 bytes data\n"); );
1362 for (i = 0; i < ret; i++)
1363 {
1364 if (inbuf[i] != chunk6[i])
1365 {
1366 printf("Wrong data at %d, out %d in %d\n", i, chunk6[i], inbuf[i]);
1367 errors++;
1368 }
1369 }
1370
1371 /* end access and close file */
1372 ret = Hendaccess(aid1);
1373 CHECK_VOID(ret, FAIL, "Hendaccess");
1374
1375 /* end access and close file */
1376 ret = Hendaccess(aid2);
1377 CHECK_VOID(ret, FAIL, "Hendaccess");
1378
1379 MESSAGE(5, printf("Closing the file\n"););
1380 ret = Hclose(fid);
1381 CHECK_VOID(ret, FAIL, "Hclose");
1382
1383
1384 /* The following tests will work if Number type conversion
1385 is done on the ouput data, punt for now since 'hdftest'
1386 tests these same tests with number type conversion */
1387
1388 /*
1389 7. Now create 3-D chunked element with no partial chunks.
1390 Set dimension to 2x3x4 array with 6 chunks. Number type is uint16
1391 where each chunk is 1x1x4= 4x2(nt_size) = 8 bytes ,
1392 total data size 48 bytes
1393 */
1394 chunk[0].num_dims = 3;
1395 chunk[0].chunk_size = 4; /* 1x1x4 bytes, logical */
1396 chunk[0].nt_size = 2; /* number type size, uint16 */
1397 chunk[0].chunk_flag = 0; /* nothing set */
1398 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
1399 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
1400 chunk[0].cinfo = NULL; /* nothing set */
1401 chunk[0].minfo = NULL; /* nothing set */
1402 #if 0
1403 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
1404 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
1405 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
1406 chunk[0].cinfo = &cinfo; /* nothing set */
1407 chunk[0].minfo = &minfo; /* nothing set */
1408 #endif
1409
1410 chunk[0].pdims[0].dim_length = 2;
1411 chunk[0].pdims[0].chunk_length = 1;
1412 chunk[0].pdims[0].distrib_type = 1;
1413
1414 chunk[0].pdims[1].dim_length = 3;
1415 chunk[0].pdims[1].chunk_length = 1;
1416 chunk[0].pdims[1].distrib_type = 1;
1417
1418 chunk[0].pdims[2].dim_length = 4;
1419 chunk[0].pdims[2].chunk_length = 4;
1420 chunk[0].pdims[2].distrib_type = 0; /* NONE */
1421
1422 fill_val_len = 2;
1423 fill_val_u16 = 0;
1424
1425 /* Open file for writing last odd size chunks now */
1426 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1427 CHECK_VOID(fid, FAIL, "Hopen");
1428 MESSAGE(5, printf("Test 7. Create another new element as a 3-D, uint16 chunked element(48 bytes)\n"););
1429 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1430 0,(int)chunk[0].pdims[0].dim_length,
1431 0,(int)chunk[0].pdims[0].chunk_length););
1432 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1433 1,(int)chunk[0].pdims[1].dim_length,
1434 1,(int)chunk[0].pdims[1].chunk_length););
1435 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1436 2,(int)chunk[0].pdims[2].dim_length,
1437 2,(int)chunk[0].pdims[2].chunk_length););
1438
1439 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1440 aid1 = HMCcreate(fid, 1020, 14, 1, fill_val_len, &fill_val_u16, (HCHUNK_DEF *)chunk);
1441 CHECK_VOID(aid1, FAIL, "HMCcreate");
1442
1443 /* write 48 bytes out */
1444 ret = Hwrite(aid1, 48, u16_data);
1445 VERIFY_VOID(ret, 48, "Hwrite");
1446 if (ret != 48)
1447 {
1448 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
1449 errors++;
1450 goto done;
1451 }
1452
1453 MESSAGE(5, printf("Wrote 48 bytes to 3-D, uint16 chunked element \n"); );
1454
1455 /* end access */
1456 ret = Hendaccess(aid1);
1457 CHECK_VOID(ret, FAIL, "Hendaccess");
1458
1459 MESSAGE(5, printf("Closing the files\n");
1460 );
1461 ret = Hclose(fid);
1462 CHECK_VOID(ret, FAIL, "Hclose");
1463
1464 MESSAGE(5, printf("Open 3-D, uint16 chunked element again for reading\n"); );
1465 /* Open file for reading now */
1466 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1467 CHECK_VOID(fid, FAIL, "Hopen");
1468
1469 /* start read access tag, ref */
1470 aid1 = Hstartread(fid, 1020, 14);
1471 CHECK_VOID(aid1, FAIL, "Hstartread");
1472
1473 /* read back in buffer */
1474 ret = Hread(aid1, 48, inbuf_u16);
1475 VERIFY_VOID(ret, 48, "Hread");
1476 if (ret != 48)
1477 {
1478 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1479 errors++;
1480 goto done;
1481 }
1482
1483 /* verify the data */
1484 MESSAGE(5, printf("Verifying 48 bytes data\n"); );
1485 for (i = 0; i < 2; i++)
1486 {
1487 for (j = 0; j < 3; j++)
1488 {
1489 for (k = 0; k < 4; k++)
1490 {
1491 if (inbuf_u16[i][j][k] != u16_data[i][j][k])
1492 {
1493 printf("Wrong data at inbuf_u16[%d][%d][%d], out %d in %d\n",
1494 i,j,k, u16_data[i][j][k], inbuf_u16[i][j][k]);
1495 errors++;
1496 }
1497 }
1498 }
1499 }
1500
1501 if (errors)
1502 goto done;
1503
1504 /* end access and close file */
1505 ret = Hendaccess(aid1);
1506 CHECK_VOID(ret, FAIL, "Hendaccess");
1507
1508 MESSAGE(5, printf("Closing the file\n"););
1509 ret = Hclose(fid);
1510 CHECK_VOID(ret, FAIL, "Hclose");
1511
1512
1513 /*
1514 8. Now create 3-D chunked element with no partial chunks.
1515 Set dimension to 2x3x4 array with 6 chunks. Numbertype is float32
1516 where each chunk is 1x1x4= 4x4(nt_size) = 16 bytes ,
1517 total data size 96 bytes
1518 */
1519 chunk[0].num_dims = 3;
1520 chunk[0].chunk_size = 4; /* 1x1x4 bytes, logical */
1521 chunk[0].nt_size = 4; /* number type size, float32 */
1522 chunk[0].chunk_flag = 0; /* nothing set */
1523 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
1524 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
1525 chunk[0].cinfo = NULL; /* nothing set */
1526 chunk[0].minfo = NULL; /* nothing set */
1527 #if 0
1528 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
1529 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
1530 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
1531 chunk[0].cinfo = &cinfo; /* nothing set */
1532 chunk[0].minfo = &minfo; /* nothing set */
1533 #endif
1534
1535 chunk[0].pdims[0].dim_length = 2;
1536 chunk[0].pdims[0].chunk_length = 1;
1537 chunk[0].pdims[0].distrib_type = 1;
1538
1539 chunk[0].pdims[1].dim_length = 3;
1540 chunk[0].pdims[1].chunk_length = 1;
1541 chunk[0].pdims[1].distrib_type = 1;
1542
1543 chunk[0].pdims[2].dim_length = 4;
1544 chunk[0].pdims[2].chunk_length = 4;
1545 chunk[0].pdims[2].distrib_type = 0; /* NONE */
1546
1547 fill_val_len = 4;
1548 fill_val_f32 = (float32)0.0;
1549
1550 /* Open file for writing last odd size chunks now */
1551 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1552 CHECK_VOID(fid, FAIL, "Hopen");
1553
1554 MESSAGE(5, printf("Test 8. Create another new element as a 3-D, float32 chunked element(96 bytes)\n"););
1555 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1556 0,(int)chunk[0].pdims[0].dim_length,
1557 0,(int)chunk[0].pdims[0].chunk_length););
1558 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1559 1,(int)chunk[0].pdims[1].dim_length,
1560 1,(int)chunk[0].pdims[1].chunk_length););
1561 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1562 2,(int)chunk[0].pdims[2].dim_length,
1563 2,(int)chunk[0].pdims[2].chunk_length););
1564
1565 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1566 aid1 = HMCcreate(fid, 1020, 15, 1, fill_val_len, &fill_val_f32, (HCHUNK_DEF *)chunk);
1567 CHECK_VOID(aid1, FAIL, "HMCcreate");
1568
1569 if (aid1 == FAIL)
1570 {
1571 HEprint(stderr,0);
1572 errors++;
1573 goto done;
1574 }
1575
1576 /* write 96 bytes out */
1577 ret = Hwrite(aid1, 96, f32_data);
1578 VERIFY_VOID(ret, 96, "Hwrite");
1579 if (ret != 96)
1580 {
1581 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
1582 errors++;
1583 goto done;
1584 }
1585
1586 MESSAGE(5, printf("Wrote 96 bytes to 3-D, float32 chunked element \n"); );
1587
1588 /* end access */
1589 ret = Hendaccess(aid1);
1590 CHECK_VOID(ret, FAIL, "Hendaccess");
1591
1592 MESSAGE(5, printf("Closing the files\n");
1593 );
1594 ret = Hclose(fid);
1595 CHECK_VOID(ret, FAIL, "Hclose");
1596
1597 MESSAGE(5, printf("Open 3-D, float32 chunked element again for reading\n"); );
1598 /* Open file for reading now */
1599 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1600 CHECK_VOID(fid, FAIL, "Hopen");
1601
1602 /* start read access tag, ref */
1603 aid1 = Hstartread(fid, 1020, 15);
1604 CHECK_VOID(aid1, FAIL, "Hstartread");
1605
1606 /* read back in buffer */
1607 ret = Hread(aid1, 96, inbuf_f32);
1608 VERIFY_VOID(ret, 96, "Hread");
1609 if (ret != 96)
1610 {
1611 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1612 errors++;
1613 goto done;
1614 }
1615
1616 /* verify the data */
1617 MESSAGE(5, printf("Verifying 96 bytes data\n"); );
1618 for (i = 0; i < 2; i++)
1619 {
1620 for (j = 0; j < 3; j++)
1621 {
1622 for (k = 0; k < 4; k++)
1623 {
1624 if (inbuf_f32[i][j][k] != f32_data[i][j][k])
1625 {
1626 printf("Wrong data at inbuf_f32[%d][%d][%d], out %f in %f\n",
1627 i,j,k, f32_data[i][j][k], inbuf_f32[i][j][k]);
1628 errors++;
1629 }
1630 }
1631 }
1632 }
1633
1634 if (errors)
1635 goto done;
1636
1637
1638 /* end access and close file */
1639 ret = Hendaccess(aid1);
1640 CHECK_VOID(ret, FAIL, "Hendaccess");
1641
1642 MESSAGE(5, printf("Closing the file\n"););
1643 ret = Hclose(fid);
1644 CHECK_VOID(ret, FAIL, "Hclose");
1645
1646 /*
1647 9. Create 4-D element with partial chunks.
1648 Write only half the data out(5,000 bytes)
1649 Set dimension to 10x10x10x10 array real data 10,000 bytes .
1650 120 chunks whit chunks of 2x3x4x5 = 120 bytes,
1651 data size with chunks is 120 bytes x 120 chunks = 14,400 bytes
1652 */
1653 chunk[0].num_dims = 4;
1654 chunk[0].chunk_size = 120;
1655 chunk[0].nt_size = 1; /* number type size */
1656 chunk[0].chunk_flag = 0; /* nothing set */
1657 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
1658 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
1659 chunk[0].cinfo = NULL; /* nothing set */
1660 chunk[0].minfo = NULL; /* nothing set */
1661 #if 0
1662 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
1663 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
1664 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
1665 chunk[0].cinfo = &cinfo; /* nothing set */
1666 chunk[0].minfo = &minfo; /* nothing set */
1667 #endif
1668
1669 chunk[0].pdims[0].dim_length = 10;
1670 chunk[0].pdims[0].chunk_length = 2;
1671 chunk[0].pdims[0].distrib_type = 1;
1672
1673 chunk[0].pdims[1].dim_length = 10;
1674 chunk[0].pdims[1].chunk_length = 3;
1675 chunk[0].pdims[1].distrib_type = 1;
1676
1677 chunk[0].pdims[2].dim_length = 10;
1678 chunk[0].pdims[2].chunk_length = 4;
1679 chunk[0].pdims[2].distrib_type = 1;
1680
1681 chunk[0].pdims[3].dim_length = 10;
1682 chunk[0].pdims[3].chunk_length = 5;
1683 chunk[0].pdims[3].distrib_type = 1;
1684
1685 /* set fill value to 1 */
1686 fill_val_u8 = 1;
1687 fill_val_len = 1;
1688
1689 /* Open file for reading now */
1690 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1691 CHECK_VOID(fid, FAIL, "Hopen");
1692
1693 MESSAGE(5, printf("Test 9. Create another new element as a 4-D, uint8 chunked element\n"););
1694 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1695 0,(int)chunk[0].pdims[0].dim_length,
1696 0,(int)chunk[0].pdims[0].chunk_length););
1697 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1698 1,(int)chunk[0].pdims[1].dim_length,
1699 1,(int)chunk[0].pdims[1].chunk_length););
1700 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1701 2,(int)chunk[0].pdims[2].dim_length,
1702 2,(int)chunk[0].pdims[2].chunk_length););
1703 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
1704 3,(int)chunk[0].pdims[3].dim_length,
1705 3,(int)chunk[0].pdims[3].chunk_length););
1706
1707 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1708 aid1 = HMCcreate(fid, 1020, 9, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
1709 CHECK_VOID(aid1, FAIL, "HMCcreate");
1710
1711 /* write 5000 bytes out */
1712 ret = Hwrite(aid1, 5000, outbuf);
1713 VERIFY_VOID(ret, 5000, "Hwrite");
1714 if (ret != 5000)
1715 {
1716 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
1717 errors++;
1718 goto done;
1719 }
1720
1721 MESSAGE(5, printf("Wrote 5000of10000 bytes to 4-D chunked element \n"); );
1722 /* end access */
1723 ret = Hendaccess(aid1);
1724 CHECK_VOID(ret, FAIL, "Hendaccess");
1725
1726 MESSAGE(5, printf("Closing the file\n"););
1727 ret = Hclose(fid);
1728 CHECK_VOID(ret, FAIL, "Hclose");
1729
1730 /* Open file for reading now */
1731 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1732 CHECK_VOID(fid, FAIL, "Hopen");
1733
1734 MESSAGE(5, printf("Open 4-D chunked element again for reading\n"); );
1735
1736 /* start read access tag, ref */
1737 aid1 = Hstartread(fid, 1020, 9);
1738 CHECK_VOID(aid1, FAIL, "Hstartread");
1739
1740 /* inquire about element */
1741 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
1742 &acc_mode, &special);
1743
1744 CHECK_VOID(ret, FAIL, "Hinquire");
1745 if (!special)
1746 {
1747 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
1748 __LINE__);
1749 errors++;
1750 goto done;
1751 }
1752
1753 /* Check values from Hinquire */
1754 if ( ref != 9 || length != 10000)
1755 {
1756 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
1757 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
1758 errors++;
1759 goto done;
1760 }
1761
1762 /* verify the data */
1763 MESSAGE(5, printf("Verifying 5000 bytes of data\n"); );
1764
1765 /* read back in buffer */
1766 ret = Hread(aid1, 5000, inbuf);
1767 VERIFY_VOID(ret, 5000, "Hread");
1768 if (ret != 5000)
1769 {
1770 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1771 errors++;
1772 goto done;
1773 }
1774
1775 for (i = 0; i < ret; i++)
1776 {
1777 if (inbuf[i] != outbuf[i])
1778 {
1779 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
1780 errors++;
1781 }
1782 }
1783 if (errors)
1784 goto done;
1785
1786 /* verify some more data */
1787 MESSAGE(5, printf("seek to 7000 bytes in element and read 1000 bytes \n"); );
1788
1789 /* seek past initial write buffer */
1790 ret = Hseek(aid1, 7000, 0);
1791 VERIFY_VOID(ret, 0, "Hseek");
1792
1793 /* read back in buffer */
1794 ret = Hread(aid1, 1000, inbuf);
1795 VERIFY_VOID(ret, 1000, "Hread");
1796 if (ret != 1000)
1797 {
1798 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1799 errors++;
1800 goto done;
1801 }
1802
1803 /* verify the data, should be fill values */
1804 MESSAGE(5, printf("Verifying 1000 bytes of data, should be fill values\n"); );
1805
1806 for (i = 0; i < ret; i++)
1807 {
1808 if (inbuf[i] != fill_val_u8)
1809 {
1810 printf("Wrong data at %d, out %d in %d\n", i, fill_val_u8, inbuf[i]);
1811 errors++;
1812 }
1813 }
1814 if (errors)
1815 goto done;
1816
1817 /* end access and close file */
1818 ret = Hendaccess(aid1);
1819 CHECK_VOID(ret, FAIL, "Hendaccess");
1820
1821 MESSAGE(5, printf("Closing the file\n"););
1822 ret = Hclose(fid);
1823 CHECK_VOID(ret, FAIL, "Hclose");
1824
1825 #ifdef BIG_TEST
1826
1827 /*
1828 10. The rest of the tests here are commented out
1829 They are some extra high order tests to replicate
1830 some test done on EOS-DEM data -GV.....
1831 Set dimension to 12000x12000 array with 2,500 chunks
1832 whith chunk of 240x240 = 57,600 bytes
1833 */
1834 chunk[0].num_dims = 2;
1835 chunk[0].chunk_size = 57600;
1836 chunk[0].nt_size = 1; /* number type size */
1837 chunk[0].chunk_flag = 0; /* nothing set */
1838 chunk[0].comp_type = COMP_CODE_NONE; /* nothing set */
1839 chunk[0].model_type = COMP_MODEL_STDIO; /* nothing set */
1840 chunk[0].cinfo = NULL; /* nothing set */
1841 chunk[0].minfo = NULL; /* nothing set */
1842
1843 chunk[0].pdims[0].dim_length = 12000;
1844 chunk[0].pdims[0].chunk_length = 240;
1845 chunk[0].pdims[0].distrib_type = 1;
1846
1847 chunk[0].pdims[1].dim_length = 12000;
1848 chunk[0].pdims[1].chunk_length = 240;
1849 chunk[0].pdims[1].distrib_type = 1;
1850
1851 #if 0
1852 /* Open file for reading now */
1853 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1854 CHECK_VOID(fid, FAIL, "Hopen");
1855 #endif
1856
1857 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
1858 aid1 = HMCcreate(fid, 1020, 10, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
1859 CHECK_VOID(aid1, FAIL, "HMCcreate");
1860
1861 for (j = 0; j < 12000; j++)
1862 {
1863 printf("%d,",j);
1864 /* write 12000 bytes out */
1865 ret = Hwrite(aid1, 12000, outbuf);
1866 if (ret != 12000)
1867 {
1868 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
1869 errors++;
1870 }
1871 }
1872 printf("\n");
1873
1874 /* end access */
1875 ret = Hendaccess(aid1);
1876 CHECK_VOID(ret, FAIL, "Hendaccess");
1877
1878 MESSAGE(5, printf("Closing the files\n");
1879 );
1880 ret = Hclose(fid);
1881 CHECK_VOID(ret, FAIL, "Hclose");
1882
1883
1884 /* Open file for reading now */
1885 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
1886 CHECK_VOID(fid, FAIL, "Hopen");
1887
1888 /* start read access tag, ref */
1889 aid1 = Hstartread(fid, 1020, 10);
1890 CHECK_VOID(aid1, FAIL, "Hstartread");
1891
1892 /* inquire about element */
1893 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
1894 &acc_mode, &special);
1895
1896 CHECK_VOID(ret, FAIL, "Hinquire");
1897 if (!special)
1898 {
1899 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
1900 __LINE__);
1901 errors++;
1902 }
1903
1904 /* verify the data */
1905 MESSAGE(5, printf("Verifying data\n");
1906 );
1907
1908 for (j = 0; j < 12000; j++)
1909 {
1910
1911 if ((j % 1000) == 0)
1912 {
1913 printf("read %d,",j);
1914 /* read back in buffer */
1915 ret = Hread(aid1, 12000, inbuf);
1916
1917 if (ret != 12000)
1918 {
1919 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1920 errors++;
1921 }
1922
1923 for (i = 0; i < ret; i++)
1924 {
1925 if (inbuf[i] != outbuf[i])
1926 {
1927 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
1928 errors++;
1929 }
1930 }
1931 }
1932 else
1933 {
1934 /* seek to next buffer */
1935 ret = Hseek(aid1, 12000, 1);
1936 VERIFY_VOID(ret, 0, "Hseek");
1937 }
1938 }
1939
1940 /* Mimic read pattern of EOS-DEM test behaviour */
1941 x = 1000;
1942 y = 1000;
1943 nseek = (12000 * y) + x;
1944 printf("seek to initial byte postion = %d \n",nseek);
1945 /* seek to next buffer */
1946 ret = Hseek(aid1, nseek, 0);
1947 VERIFY_VOID(ret, 0, "Hseek");
1948
1949 for (j = 0; j < 11; j++)
1950 {
1951 printf("read 2000x2000 square at x=%d,y=%d\n",x,y);
1952
1953 for (k = 0; k < 2000; k++)
1954 {
1955 /* read back in buffer */
1956 ret = Hread(aid1, 2000, inbuf);
1957
1958 if (ret != 2000)
1959 {
1960 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
1961 errors++;
1962 }
1963
1964 /* seek to next buffer */
1965 ret = Hseek(aid1, 10000, 1);
1966 VERIFY_VOID(ret, 0, "Hseek");
1967 }
1968
1969 x = x + 100;
1970 y = y + 1000;
1971 nseek = (12000 * y) + x;
1972 printf("seek to next byte postion = %d\n",nseek);
1973 /* seek to next buffer */
1974 ret = Hseek(aid1, nseek, 0);
1975 VERIFY_VOID(ret, 0, "Hseek");
1976 }
1977
1978 /* end access and close file */
1979 ret = Hendaccess(aid1);
1980 CHECK_VOID(ret, FAIL, "Hendaccess");
1981
1982 MESSAGE(5, printf("Closing the files\n");
1983 );
1984 ret = Hclose(fid);
1985 CHECK_VOID(ret, FAIL, "Hclose");
1986
1987 #endif /* BIG_TEST */
1988
1989 /*
1990 Chunking with Compression testing.....
1991 */
1992
1993 /*
1994 11. Create a new element but now there will be partial chunks and Compression.
1995 Set dimension to 4x4 array with 4 chunks where each chunk is 3x2 = 6 bytes.
1996 Real data size is 16 bytes, size with chunks is
1997 6 bytes x 4 chunks = 24 bytes .
1998
1999 The element will be compressed with RLE scheme.
2000
2001 */
2002 chunk[0].num_dims = 2;
2003 chunk[0].chunk_size = 6; /* 3x2 = 6 bytes */
2004 chunk[0].nt_size = 1; /* number type size */
2005 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
2006 #if 0
2007 chunk[0].comp_type = COMP_CODE_SKPHUFF; /* Skipping Huffman */
2008 cinfo.skphuff.skp_size = sizeof(uint8);
2009
2010 chunk[0].comp_type = COMP_CODE_DEFLATE; /* GZIP */
2011 cinfo.deflate.level = 6;
2012
2013 #endif
2014 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
2015
2016 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
2017 chunk[0].cinfo = &cinfo; /* nothing set */
2018 chunk[0].minfo = &minfo; /* nothing set */
2019
2020 chunk[0].pdims[0].dim_length = 4;
2021 chunk[0].pdims[0].chunk_length = 3; /* made this 3 */
2022 chunk[0].pdims[0].distrib_type = 1;
2023
2024 chunk[0].pdims[1].dim_length = 4;
2025 chunk[0].pdims[1].chunk_length = 2;
2026 chunk[0].pdims[1].distrib_type = 1;
2027
2028 /* Open file for writing odd size chunks now */
2029 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
2030 CHECK_VOID(fid, FAIL, "Hopen");
2031
2032 MESSAGE(5, printf("Test 11. Create another new element as a 2-D, uint8 chunked, RLE Compressed element\n"););
2033 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
2034 0,(int)chunk[0].pdims[0].dim_length,
2035 0,(int)chunk[0].pdims[0].chunk_length););
2036 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
2037 1,(int)chunk[0].pdims[1].dim_length,
2038 1,(int)chunk[0].pdims[1].chunk_length););
2039
2040 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
2041 aid1 = HMCcreate(fid, 1020, 20, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
2042 CHECK_VOID(aid1, FAIL, "HMCcreate");
2043
2044 /* write 16 bytes out */
2045 ret = Hwrite(aid1, 16, outbuf);
2046 VERIFY_VOID(ret, 16, "Hwrite");
2047 if (ret != 16)
2048 {
2049 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
2050 errors++;
2051 goto done;
2052 }
2053
2054 MESSAGE(5, printf("Wrote to 4of4 chunks (16 bytes) in file\n"););
2055 /* end access */
2056 ret = Hendaccess(aid1);
2057 CHECK_VOID(ret, FAIL, "Hendaccess");
2058
2059 MESSAGE(5, printf("Closing the file\n"); );
2060 ret = Hclose(fid);
2061 CHECK_VOID(ret, FAIL, "Hclose");
2062
2063 MESSAGE(5, printf("Open 2-D, uint8 chunked, RLE Compressed element again for reading\n"); );
2064
2065 /* Open file for reading now */
2066 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
2067 CHECK_VOID(fid, FAIL, "Hopen");
2068
2069 /* start read access tag, ref */
2070 aid1 = Hstartread(fid, 1020, 20);
2071 CHECK_VOID(aid1, FAIL, "Hstartread");
2072
2073 /* inquire about element */
2074 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
2075 &acc_mode, &special);
2076
2077 CHECK_VOID(ret, FAIL, "Hinquire");
2078 if (!special)
2079 {
2080 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
2081 __LINE__);
2082 errors++;
2083 goto done;
2084 }
2085
2086 /* Check values from Hinquire */
2087 if ( ref != 20 || length != 16)
2088 {
2089 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
2090 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
2091 errors++;
2092 goto done;
2093 }
2094
2095 /* read back in buffer */
2096 ret = Hread(aid1, 16, inbuf);
2097 VERIFY_VOID(ret, 16, "Hread");
2098 if (ret != 16)
2099 {
2100 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
2101 errors++;
2102 goto done;
2103 }
2104
2105 /* verify the data */
2106 MESSAGE(5, printf("Verifying 16 bytes of data\n"); );
2107 for (i = 0; i < ret; i++)
2108 {
2109 if (inbuf[i] != outbuf[i])
2110 {
2111 printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
2112 errors++;
2113 }
2114 inbuf[i] = '\0';
2115 }
2116 if (errors)
2117 goto done;
2118
2119 /* end access and close file */
2120 ret = Hendaccess(aid1);
2121 CHECK_VOID(ret, FAIL, "Hendaccess");
2122
2123 MESSAGE(5, printf("Closing the file\n"); );
2124 ret = Hclose(fid);
2125 CHECK_VOID(ret, FAIL, "Hclose");
2126
2127 /*
2128 12. Now create 3-D chunked, Compressed element with no partial chunks.
2129 Write using HMCwriteChunk(). Read data back in first
2130 using Hread() and verify. Then read data back in using
2131 HMCreadChunk() and verify.
2132 Set dimension to 2x3x4 array with 6 chunks
2133 where each chunk is 1x1x4= 4 bytes , total data size 24 bytes
2134
2135 The element is compressed using RLE scheme.
2136 */
2137 chunk[0].num_dims = 3;
2138 chunk[0].chunk_size = 4; /* 1x1x4 bytes */
2139 chunk[0].nt_size = 1; /* number type size */
2140 chunk[0].chunk_flag = SPECIAL_COMP; /* compression */
2141 #if 0
2142
2143 chunk[0].comp_type = COMP_CODE_RLE; /* RLE */
2144
2145 chunk[0].comp_type = COMP_CODE_SKPHUFF; /* Skipping Huffman */
2146 cinfo.skphuff.skp_size = sizeof(uint8);
2147 #endif
2148 chunk[0].comp_type = COMP_CODE_DEFLATE; /* GZIP */
2149 cinfo.deflate.level = 6;
2150
2151 chunk[0].model_type = COMP_MODEL_STDIO; /* STDIO */
2152 chunk[0].cinfo = &cinfo; /* nothing set */
2153 chunk[0].minfo = &minfo; /* nothing set */
2154
2155 chunk[0].pdims[0].dim_length = 2;
2156 chunk[0].pdims[0].chunk_length = 1;
2157 chunk[0].pdims[0].distrib_type = 1;
2158
2159 chunk[0].pdims[1].dim_length = 3;
2160 chunk[0].pdims[1].chunk_length = 1;
2161 chunk[0].pdims[1].distrib_type = 1;
2162
2163 chunk[0].pdims[2].dim_length = 4;
2164 chunk[0].pdims[2].chunk_length = 4;
2165 chunk[0].pdims[2].distrib_type = 0; /* NONE */
2166
2167 /* set fill value to 1 */
2168 fill_val_u8 = 1;
2169 fill_val_len = 1;
2170
2171 /* Open file for writing last odd size chunks now */
2172 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
2173 CHECK_VOID(fid, FAIL, "Hopen");
2174 MESSAGE(5, printf("Test 12. Create another new element as a 3-D, uint8 chunked, GZIP Compressed element(192 bytes)\n"););
2175 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
2176 0,(int)chunk[0].pdims[0].dim_length,
2177 0,(int)chunk[0].pdims[0].chunk_length););
2178 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
2179 1,(int)chunk[0].pdims[1].dim_length,
2180 1,(int)chunk[0].pdims[1].chunk_length););
2181 MESSAGE(5, printf(" dim_length[%d]=%d, chunk_length[%d]=%d \n",
2182 2,(int)chunk[0].pdims[2].dim_length,
2183 2,(int)chunk[0].pdims[2].chunk_length););
2184
2185 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
2186 aid1 = HMCcreate(fid, 1020, 21, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
2187 CHECK_VOID(aid1, FAIL, "HMCcreate");
2188
2189 /* Create element tag, ref, nlevels, fill_len, fill, chunk array */
2190 aid2 = HMCcreate(fid, 1020, 22, 1, fill_val_len, &fill_val_u8, (HCHUNK_DEF *)chunk);
2191 CHECK_VOID(aid1, FAIL, "HMCcreate");
2192
2193 /* write 24 bytes out */
2194 ret = Hwrite(aid2, 24, u8_data);
2195 if (ret != 24)
2196 {
2197 fprintf(stderr, "ERROR: Hwrite returned the wrong length: %d\n", (int) ret);
2198 errors++;
2199 goto done;
2200 }
2201
2202 /* write data out as chunks */
2203 MESSAGE(5, printf("Writing to 3-D, uint8 chunked, GZIP Compressed element using HMCwriteChunk\n"); );
2204
2205 /* Write data use SDwriteChunk */
2206 dims[0] = 0;
2207 dims[1] = 0;
2208 dims[2] = 0;
2209 ret = HMCwriteChunk(aid1, dims, chunk1);
2210 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2211
2212 dims[0] = 1;
2213 dims[1] = 0;
2214 dims[2] = 0;
2215 ret = HMCwriteChunk(aid1, dims, chunk4);
2216 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2217
2218 dims[0] = 0;
2219 dims[1] = 1;
2220 dims[2] = 0;
2221 ret = HMCwriteChunk(aid1, dims, chunk2);
2222 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2223
2224 dims[0] = 1;
2225 dims[1] = 1;
2226 dims[2] = 0;
2227 ret = HMCwriteChunk(aid1, dims, chunk5);
2228 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2229
2230 dims[0] = 0;
2231 dims[1] = 2;
2232 dims[2] = 0;
2233 ret = HMCwriteChunk(aid1, dims, chunk3);
2234 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2235
2236 dims[0] = 1;
2237 dims[1] = 2;
2238 dims[2] = 0;
2239 ret = HMCwriteChunk(aid1, dims, chunk6);
2240 CHECK_VOID(ret, FAIL, "HMCwriteChunk");
2241
2242 /* end access */
2243 ret = Hendaccess(aid1);
2244 CHECK_VOID(ret, FAIL, "Hendaccess");
2245
2246 /* end access */
2247 ret = Hendaccess(aid2);
2248 CHECK_VOID(ret, FAIL, "Hendaccess");
2249
2250 MESSAGE(5, printf("Closing the files\n"););
2251 ret = Hclose(fid);
2252 CHECK_VOID(ret, FAIL, "Hclose");
2253
2254 MESSAGE(5, printf("Open 3-D, uint8 chunked, GZIP Compressed element again for reading\n"); );
2255 /* Open file for reading now */
2256 fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
2257 CHECK_VOID(fid, FAIL, "Hopen");
2258
2259 /* start read access tag, ref */
2260 aid1 = Hstartread(fid, 1020, 21);
2261 CHECK_VOID(aid1, FAIL, "Hstartread");
2262
2263 /* start read access tag, ref */
2264 aid2 = Hstartread(fid, 1020, 22);
2265 CHECK_VOID(aid1, FAIL, "Hstartread");
2266
2267 /* inquire about element */
2268 ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
2269 &acc_mode, &special);
2270
2271 CHECK_VOID(ret, FAIL, "Hinquire");
2272 if (!special)
2273 {
2274 fprintf(stderr, "ERROR: Hinquire does not think element is special line %d\n",
2275 __LINE__);
2276 errors++;
2277 goto done;
2278 }
2279
2280 /* Check values from Hinquire */
2281 if ( ref != 21 || length != 24)
2282 {
2283 fprintf(stderr, "ERROR: Hinquire does not return the correct values \n");
2284 fprintf(stderr, " tag =%d, ref=%d, length=%d \n",tag,ref,(int)length);
2285 errors++;
2286 goto done;
2287 }
2288
2289 MESSAGE(5, printf("Get/Check special info data\n"); );
2290
2291 /* get special info about element */
2292 ret = HDget_special_info(aid1, &info_block);
2293 CHECK_VOID(aid1, FAIL, "HDget_special_info");
2294
2295 /* check special info */
2296 if (info_block.ndims != chunk[0].num_dims /* 2-D */)
2297 {
2298 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
2299 errors++;
2300 goto done;
2301 }
2302
2303 /* check chunk_lengths */
2304 if (info_block.cdims != NULL)
2305 {
2306 if ((info_block.cdims[0] != 1)
2307 || (info_block.cdims[1] != 1)
2308 || (info_block.cdims[2] != 4))
2309 {
2310 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
2311 errors++;
2312 goto done;
2313 }
2314
2315 /* free allocated space by routine */
2316 HDfree(info_block.cdims);
2317 }
2318 else
2319 {
2320 fprintf(stderr, "ERROR: HDget_specail_info does not return the correct values \n");
2321 errors++;
2322 goto done;
2323 }
2324
2325
2326 /* read back in buffer */
2327 ret = Hread(aid1, 24, inbuf_u8);
2328 VERIFY_VOID(ret, 24, "Hread");
2329 if (ret != 24)
2330 {
2331 fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", (int) ret);
2332 errors++;
2333 goto done;
2334 }
2335
2336 /* verify the data */
2337 MESSAGE(5, printf("Verifying 24 bytes data from Hread\n"); );
2338 for (i = 0; i < 2; i++)
2339 {
2340 for (j = 0; j < 3; j++)
2341 {
2342 for (k = 0; k < 4; k++)
2343 {
2344 if (inbuf_u8[i][j][k] != u8_data[i][j][k])
2345 {
2346 printf("Wrong data at inbuf_u8[%d][%d][%d], out %d in %d\n",
2347 i,j,k, u8_data[i][j][k], inbuf_u8[i][j][k]);
2348 errors++;
2349 }
2350 }
2351 }
2352 }
2353
2354 if (errors)
2355 goto done;
2356
2357 MESSAGE(5, printf("Verifying 24 bytes from uint8 chunked, GZIP Compressed element using HMCreadChunk\n"); );
2358 /* read data back as chunks */
2359 dims[0] = 0;
2360 dims[1] = 0;
2361 dims[2] = 0;
2362 ret = HMCreadChunk(aid2, dims, inbuf);
2363 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2364 if (ret != 4)
2365 {
2366 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2367 errors++;
2368 goto done;
2369 }
2370
2371 MESSAGE(5, printf("Verifying chunk1 4 bytes data\n"); );
2372 for (i = 0; i < ret; i++)
2373 {
2374 if (inbuf[i] != chunk1[i])
2375 {
2376 printf("Wrong data at %d, out %d in %d\n", i, chunk1[i], inbuf[i]);
2377 errors++;
2378 }
2379 }
2380
2381 dims[0] = 0;
2382 dims[1] = 1;
2383 dims[2] = 0;
2384 ret = HMCreadChunk(aid2, dims, inbuf);
2385 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2386 if (ret != 4)
2387 {
2388 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2389 errors++;
2390 goto done;
2391 }
2392
2393 MESSAGE(5, printf("Verifying chunk2 4 bytes data\n"); );
2394 for (i = 0; i < ret; i++)
2395 {
2396 if (inbuf[i] != chunk2[i])
2397 {
2398 printf("Wrong data at %d, out %d in %d\n", i, chunk2[i], inbuf[i]);
2399 errors++;
2400 }
2401 }
2402
2403 dims[0] = 0;
2404 dims[1] = 2;
2405 dims[2] = 0;
2406 ret = HMCreadChunk(aid2, dims, inbuf);
2407 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2408 if (ret != 4)
2409 {
2410 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2411 errors++;
2412 goto done;
2413 }
2414
2415 MESSAGE(5, printf("Verifying chunk3 4 bytes data\n"); );
2416 for (i = 0; i < ret; i++)
2417 {
2418 if (inbuf[i] != chunk3[i])
2419 {
2420 printf("Wrong data at %d, out %d in %d\n", i, chunk3[i], inbuf[i]);
2421 errors++;
2422 }
2423 }
2424
2425 dims[0] = 1;
2426 dims[1] = 0;
2427 dims[2] = 0;
2428 ret = HMCreadChunk(aid2, dims, inbuf);
2429 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2430 if (ret != 4)
2431 {
2432 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2433 errors++;
2434 goto done;
2435 }
2436
2437 MESSAGE(5, printf("Verifying chunk4 4 bytes data\n"); );
2438 for (i = 0; i < ret; i++)
2439 {
2440 if (inbuf[i] != chunk4[i])
2441 {
2442 printf("Wrong data at %d, out %d in %d\n", i, chunk4[i], inbuf[i]);
2443 errors++;
2444 }
2445 }
2446
2447 dims[0] = 1;
2448 dims[1] = 1;
2449 dims[2] = 0;
2450 ret = HMCreadChunk(aid2, dims, inbuf);
2451 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2452 if (ret != 4)
2453 {
2454 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2455 errors++;
2456 goto done;
2457 }
2458
2459 MESSAGE(5, printf("Verifying chunk5 4 bytes data\n"); );
2460 for (i = 0; i < ret; i++)
2461 {
2462 if (inbuf[i] != chunk5[i])
2463 {
2464 printf("Wrong data at %d, out %d in %d\n", i, chunk5[i], inbuf[i]);
2465 errors++;
2466 }
2467 }
2468
2469 dims[0] = 1;
2470 dims[1] = 2;
2471 dims[2] = 0;
2472 ret = HMCreadChunk(aid2, dims, inbuf);
2473 CHECK_VOID(ret, FAIL, "HMCreadChunk");
2474 if (ret != 4)
2475 {
2476 fprintf(stderr, "ERROR: HMCreadChunk returned the wrong length: %d\n", (int) ret);
2477 errors++;
2478 goto done;
2479 }
2480
2481 MESSAGE(5, printf("Verifying chunk6 4 bytes data\n"); );
2482 for (i = 0; i < ret; i++)
2483 {
2484 if (inbuf[i] != chunk6[i])
2485 {
2486 printf("Wrong data at %d, out %d in %d\n", i, chunk6[i], inbuf[i]);
2487 errors++;
2488 }
2489 }
2490
2491 /* end access and close file */
2492 ret = Hendaccess(aid1);
2493 CHECK_VOID(ret, FAIL, "Hendaccess");
2494
2495 /* end access and close file */
2496 ret = Hendaccess(aid2);
2497 CHECK_VOID(ret, FAIL, "Hendaccess");
2498
2499 MESSAGE(5, printf("Closing the file\n"););
2500 ret = Hclose(fid);
2501 CHECK_VOID(ret, FAIL, "Hclose");
2502
2503
2504 done:
2505 /* Don't forget to free dimensions allocate for chunk definition */
2506 if (chunk[0].pdims != NULL)
2507 HDfree(chunk[0].pdims);
2508
2509 num_errs += errors; /* increment global error count */
2510 } /* test_chunks() */
2511