Repository navigation
Expand file tree
/
Copy pathapitest.java
More file actions
651 lines (572 loc) · 16 KB
/
Copy pathapitest.java
File metadata and controls
651 lines (572 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
import ncsa.hdf.h4toh5lib.*;
import ncsa.hdf.h4toh5lib.exceptions.*;
import ncsa.hdf.hdflib.*;
import ncsa.hdf.hdf5lib.*;
public class apitest {
private int file_id = -1;
private int sd_id = -1;
private int gr_id = -1;
private int h4toh5id = -1;
private boolean initialized = false;
public apitest() {};
static public void main( String []args )
{
apitest a = new apitest();
a.setup();
boolean r1 = a.test1();
boolean r2 = a.test2();
a.cleanup();
if (r1 && r2) {
System.exit(0);
} else {
System.exit(-1);
}
}
/*
* Set up the testfiles and library interfaces.
*
* These are used by all the tests.
*/
public void setup( )
{
try {
file_id = HDFLibrary.Hopen("vg_all_test.hdf",
HDFConstants.DFACC_READ);
} catch (HDFException he1) {
System.err.println("Setup: open H interface exception: "+he1);
System.exit( -1);
}
if (file_id == -1) {
System.err.println("Setup: cannot open H interface: "+file_id);
System.exit( -1);
}
try {
sd_id = HDFLibrary.SDstart("vg_all_test.hdf",
HDFConstants.DFACC_READ);
} catch (HDFException he2) {
System.err.println("Setup: open SD interface exception: "+he2);
try {
HDFLibrary.Hclose(file_id);
} catch (HDFException he3) {}
System.exit( -1);
}
if(sd_id == -1) {
System.err.println("Setup: cannot start SD interface: "+sd_id);
try {
HDFLibrary.Hclose(file_id);
} catch (HDFException he4) {}
System.exit( -1);
}
try {
gr_id = HDFLibrary.GRstart(file_id);
} catch (HDFException he5) {
System.err.println("Setup: open GR interface exception: "+he5);
try {
HDFLibrary.SDend(sd_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he6) {}
System.exit( -1);
}
if(gr_id == -1) {
System.err.println("Setup: open GR interface error: "+gr_id);
try {
HDFLibrary.SDend(sd_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he8) {}
System.exit( -1);
}
boolean status = false;
try {
status = HDFLibrary.Vstart(file_id);
} catch (HDFException he9) {
System.err.println("Setup: open V interface exception: "+he9);
try {
HDFLibrary.GRend(gr_id);
HDFLibrary.SDend(sd_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he10) {}
System.exit( -1);
}
if(status == false) {
System.err.println("Setup: open V interface error");
try {
HDFLibrary.GRend(gr_id);
HDFLibrary.SDend(sd_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he12) {}
System.exit( -1);
}
try {
h4toh5id= h4toh5.H4toh5open("vg_all_test.hdf","vg_all_test.h5");
} catch (H45Exception h45e1) {
System.err.println("Setup: H4toh5open exception "+h45e1);
try {
HDFLibrary.Vend(file_id);
HDFLibrary.GRend(gr_id);
HDFLibrary.SDend(sd_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he13) {}
System.exit( -1);
}
if(h4toh5id < 0) {
System.err.println("Setup: error returned by H4toh5open: "+h4toh5id);
try {
HDFLibrary.SDend(sd_id);
HDFLibrary.GRend(gr_id);
HDFLibrary.Vend(file_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he14) {}
System.exit( -1);
}
initialized = true;
}
/*
* Clean up of global objects.
*/
public void cleanup()
{
if (initialized) {
try {
h4toh5.H4toh5close(h4toh5id);
HDFLibrary.GRend(gr_id);
HDFLibrary.SDend(sd_id);
HDFLibrary.Vend(file_id);
HDFLibrary.Hclose(file_id);
} catch (HDFException he) {}
catch (H45Exception h45e) {}
initialized = false;
}
}
private void test1_cleanup() {
// clean up for test 1 here?
// vdata_id
// vgroup_id
// etc.
// VSdetach(vdata_id);
// Vdetach(vgroup_id);
// SDendaccess(sds_id);
// GRendaccess(image_id);
}
private void test2_cleanup() {
// clean up for test 1 here?
// vdata_id
// vgroup_id
// etc.
}
/*
* Test batch I: test all API using the default name generation
* for the HDF5 objects.
*/
public boolean test1( )
{
/* 1. Test SDS conversion; choose the SDS object with index 0;
all attributes and dimensional scales of this SDS will
be converted. */
int sds_id = -1;
try {
sds_id = HDFLibrary.SDselect(sd_id,0);
} catch (HDFException he1) {
System.err.println("SDselect failed");
System.err.println("Test I.1: FAIL");
return(false);
}
try {
h4toh5.H4toh5sds(h4toh5id,sds_id,"/group1",null,null,1,1);
} catch (H45Exception h45e1) {
System.err.println("H4toh5sds exception "+h45e1);
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
/* 2. Testing GR conversion. */
int image_id = -1;
try {
image_id = HDFLibrary.GRselect(gr_id,0);
} catch (HDFException he2) {
System.err.println("GRselect exception "+he2);
System.err.println("Test I.2: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5image(h4toh5id,image_id,"/group1",
null,null,null,1,1);
} catch (H45Exception h45e2) {
System.err.println("h4toh5image exception "+h45e2);
System.err.println("Test I.2: FAIL");
test1_cleanup();
return(false);
}
/*
* 3. Test independent vdata conversion API.
*
* Since Vdata may be attributes, in order to avoid converting attributes;
* we use hdp to find the reference number of an independent vdata in this
* file and obtain vdata id later.
*/
int vdata_ref = 9;
int vdata_id = -1;
try {
vdata_id = HDFLibrary.VSattach(file_id,vdata_ref,"r");
} catch (HDFException he3) {
System.err.println("VSgetid exception "+he3);
System.err.println("Test I.3: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5vdata(h4toh5id,vdata_id,"/group1",null,1);
} catch (H45Exception h45e3) {
System.err.println("h4toh5vdata exception "+h45e3);
System.err.println("Test I.3: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.VSdetach(vdata_id);
} catch (HDFException he3_4) {
System.err.println("VSdetach error ");
System.err.println("Test I.3: FAIL after test");
return(false);
}
/* I.4. Test partial vgroup API.
*
* vgroup itself and vgroup with non-vgroup members will be converted.
*
*/
int vgroup_ref = -1;
int vgroup_id = -1;
try {
vgroup_ref = HDFLibrary.Vgetid(file_id,-1);
vgroup_id = HDFLibrary.Vattach(file_id,vgroup_ref,"r");
} catch (HDFException he4) {
System.err.println("Vget or Vattach exception "+he4);
System.err.println("Test I.4: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5basvgroup(h4toh5id,vgroup_id,
"/gpartial",null,1,1);
} catch (H45Exception h45e4) {
System.err.println("h4toh5vgroup exception "+h45e4);
System.err.println("Test I.4: FAIL");
test1_cleanup();
return(false);
}
/* Test I.5. Test the whole vgroup API.
* Everything under this vgroup is converted.
*/
try {
h4toh5.H4toh5advgroup(h4toh5id,vgroup_id,
"/gwhole",null);
} catch (H45Exception h45e5) {
System.err.println("h4toh5vgroup exception "+h45e5);
System.err.println("Test I.5: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.Vdetach(vgroup_id);
} catch (HDFException he5_1) {
System.err.println("Vdetach error ");
System.err.println("Test I.5: FAIL after test");
return(false);
}
/* Test I.6. Test annotation API. */
try {
h4toh5.H4toh5annofil_alllabels(h4toh5id);
} catch (H45Exception h45e6) {
System.err.println("h4toh5annofil_alllabels exception "+h45e6);
System.err.println("Test I.6: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5annofil_alldescs(h4toh5id);
} catch (H45Exception h45e6_1) {
System.err.println("h4toh5annofilr_alldescs exception "+h45e6_1);
System.err.println("Test I.6: FAIL");
test1_cleanup();
return(false);
}
/***** object annotations testing, we have to provide the object reference
number and object tag that have annotations associate with it.
we will use hdp to check the reference of such object. In this
example, vgroup is used. vgroup tag is 1965. vgroup reference is 4.
*****/
int anno_objref = 4;
int anno_objtag = 1965;
try {
h4toh5.H4toh5annoobj_label(h4toh5id,"/","/group1",
anno_objref, anno_objtag, null,0);
} catch (H45Exception h45e6_2) {
System.err.println("h4toh5annoobj_label exception "+h45e6_2);
System.err.println("Test I.6: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5annoobj_desc(h4toh5id,"/","/group1",
anno_objref, anno_objtag, null,0);
} catch (H45Exception h45e6_3) {
System.err.println("h4toh5annoobj_desc exception "+h45e6_3);
System.err.println("Test I.6: FAIL");
test1_cleanup();
return(false);
}
/* Test I.7. Test palette conversion.
Note: We only tested default parameters;
since we already used a default palette group
"/HDF4_PALGROUP" when converting the image; so
we made another palette group for this test.*/
try {
h4toh5.H4toh5pal(h4toh5id,image_id,null,null,
"/paltestgroup",null,1,0);
} catch (H45Exception h45e7) {
System.err.println("h4toh5pal exception "+h45e7);
System.err.println("Test I.7: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.GRendaccess(image_id);
} catch (HDFException he7_1) {
System.err.println("Test I.7: FAIL after test");
return(false);
}
/* Test I.8. Test dimensional scale dataset API. */
try {
h4toh5.H4toh5alldimscale(h4toh5id,sds_id,"/group1",
"sds","/dimtestgroup",1,0);
} catch (H45Exception h45e8) {
System.err.println("h4toh5alldimscale exception "+h45e8);
System.err.println("Test I.8: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.SDendaccess(sds_id);
} catch (HDFException he8_1) {
System.err.println("Test I.8: FAIL after test");
return(false);
}
try {
h4toh5.H4toh5_glosdsattr(h4toh5id);
} catch (H45Exception h45e38) {
System.err.println("h4toh5allglosdsattr exception "+h45e38);
System.err.println("Test I.8: FAIL");
test1_cleanup();
return(false);
}
try {
h4toh5.H4toh5_glograttr(h4toh5id);
} catch (H45Exception h45e41) {
System.err.println("h4toh5glograttr exception "+h45e41);
System.err.println("Test I.8: FAIL");
test1_cleanup();
return(false);
}
System.out.print("Test API using the default name generation: ");
System.out.println("PASS");
return(true);
}
/*
* Test batch II: Test API with user-defined name for HDF5 objects
*/
public boolean test2( )
{
/* Test II.1. Testing SDS API; choose the SDS object with index 0;
all attributes and dimensional scales of this SDS will
be converted. */
int sds_id = -1;
try {
sds_id = HDFLibrary.SDselect(sd_id,0);
} catch (HDFException he1) {
System.err.println("SDselect failed");
System.err.println("Test II.II: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5sds(h4toh5id,sds_id,"/group1u",
"mysds","/mydimgroup",1,1);
} catch (H45Exception h45e1) {
System.err.println("H4toh5sds exception "+h45e1);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
/* Test II.2. Test GR conversion. */
int image_id = -1;
try {
image_id = HDFLibrary.GRselect(gr_id,0);
} catch (HDFException he2) {
System.err.println("GRselect exception "+he2);
System.err.println("Test II.2: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5image(h4toh5id,image_id,"/group1u",
"myimage","/mypalgroup","mypal",1,1);
} catch (H45Exception h45e2_1) {
System.err.println("h4toh5image exception "+h45e2_1);
System.err.println("Test II.2: FAIL");
test2_cleanup();
return(false);
}
/* Test II.3. Test independent vdata conversion API.
Since Vdata may be attributes, in order to avoid converting attributes;
we use hdp to find the reference number of an independent vdata in this
file and obtain vdata id later. */
int vdata_ref = 9;
int vdata_id = -1;
try {
vdata_id = HDFLibrary.VSattach(file_id,vdata_ref,"r");
} catch (HDFException he3) {
System.err.println("VSgetid exception "+he3);
System.err.println("Test II.3: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5vdata(h4toh5id,vdata_id,"/group1u",
"myvdata",1);
} catch (H45Exception h45e3) {
System.err.println("h4toh5vdata exception "+h45e3);
System.err.println("Test II.3: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.VSdetach(vdata_id);
} catch (HDFException he3_1) {
System.err.println("Test II.3: FAIL after test");
return(false);
}
/* Test II.4. Test partial vgroup API.
vgroup itself and vgroup with non-vgroup members will be converted. */
/* Convert vgroup with an image object. */
int vgroup_ref = -1;
int vgroup_id = -1;
try {
vgroup_ref = HDFLibrary.Vgetid(file_id,-1);
vgroup_id = HDFLibrary.Vattach(file_id,vgroup_ref,"r");
} catch (HDFException he4) {
System.err.println("Vget exception "+he4);
System.err.println("Test II.4: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5basvgroup(h4toh5id,vgroup_id,
"/gpartial", "myvgroup",1,1);
} catch (H45Exception h45e4) {
System.err.println("h4toh5vgroup exception "+h45e4);
System.err.println("Test II.4: FAIL");
test2_cleanup();
return(false);
}
/* Test II.5. Test the whole vgroup API.
Everything under this vgroup is converted.*/
try {
h4toh5.H4toh5advgroup(h4toh5id,vgroup_id,"/gwhole",
"myallvgroup");
} catch (H45Exception h45e5) {
System.err.println("h4toh5vgroup exception "+h45e5);
System.err.println("Test II.5: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.Vdetach(vgroup_id);
} catch (HDFException he5_1) {
System.err.println("Vdetach error ");
System.err.println("Test II.5: FAIL after test");
return(false);
}
/* Test II.6. Test annotation API. */
/***** object annotations testing, we have to provide the object reference
number and object tag that have annotations associate with it.
we will use hdp to check the reference of such object. In this
example, vgroup is used. vgroup tag is 1965. vgroup reference is 4.
*****/
int anno_objref = 4;
int anno_objtag = 1965;
try {
h4toh5.H4toh5annoobj_label(h4toh5id,"/","/group1",
anno_objref, anno_objtag, "myobjlabel",0);
} catch (H45Exception h45e6) {
System.err.println("h4toh5annoobj_label exception "+h45e6);
System.err.println("Test II.6: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5annoobj_desc(h4toh5id,"/","/group1",
anno_objref, anno_objtag,"myobjdesc",0);
} catch (H45Exception h45e6_1) {
System.err.println("h4toh5annoobj_desc exception "+h45e6_1);
System.err.println("Test II.6: FAIL");
test2_cleanup();
return(false);
}
/* Test II.7. Test palette conversion.
Note: We only tested default parameters;
since we already used a default palette group
"/HDF4_PALGROUP" when converting the image; so
we made another palette group for this test.*/
try {
h4toh5.H4toh5pal(h4toh5id,image_id,"/group1","image",
"/paltestgroup","myownpal",1,0);
} catch (H45Exception h45e7) {
System.err.println("h4toh5pal exception "+h45e7);
System.err.println("Test II.7: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.GRendaccess(image_id);
} catch (HDFException he7_1) {
System.err.println("Test II.7: FAIL after test");
return(false);
}
/* Test II.8. Test one dimensional scale dataset API. */
try {
h4toh5.H4toh5onedimscale(h4toh5id,sds_id,"/group1",
"sds","/mydimtestgroup","myowndim_ofindex0",1,1,0);
} catch (H45Exception h45e8) {
System.err.println("h4toh5onedimscale exception "+h45e8);
System.err.println("Test II.8: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.SDendaccess(sds_id);
} catch (HDFException he8_1) {
System.err.println("Test II.8: FAIL after test");
return(false);
}
/* Test II.9. Testing file annotation label and description. */
try {
h4toh5.H4toh5annofil_label(h4toh5id,"myfilelabel",0);
} catch (H45Exception h45e41) {
System.err.println("h4toh5annofil_lable exception "+h45e41);
System.err.println("Test II.9: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5annofil_desc(h4toh5id,"myfiledesc",0);
} catch (H45Exception h45e44) {
System.err.println("h4toh5annofil_desc exception "+h45e44);
System.err.println("Test II.9: FAIL");
test2_cleanup();
return(false);
}
System.out.print("Test API using the user name generation: ");
System.out.println("PASS");
return(true);
}
}