Repository navigation
Expand file tree
/
Copy pathvgrouptest.java
More file actions
367 lines (322 loc) · 7.83 KB
/
Copy pathvgrouptest.java
File metadata and controls
367 lines (322 loc) · 7.83 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
import ncsa.hdf.h4toh5lib.*;
import ncsa.hdf.h4toh5lib.exceptions.*;
import ncsa.hdf.hdflib.*;
import ncsa.hdf.hdf5lib.*;
public class vgrouptest {
private int file_id = -1;
private int h4toh5id = -1;
private boolean initialized = false;
public vgrouptest() {};
static public void main( String []args )
{
vgrouptest vgt = new vgrouptest();
vgt.setup();
boolean r1 = vgt.test1();
boolean r2 = vgt.test2();
vgt.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("testallvgroup.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);
}
boolean status = false;
try {
status = HDFLibrary.Vstart(file_id);
} catch (HDFException he9) {
System.err.println("Setup: open V interface exception: "+he9);
try {
HDFLibrary.Hclose(file_id);
} catch (HDFException he10) {}
System.exit( -1);
}
if(status == false) {
System.err.println("Setup: open V interface error");
try {
HDFLibrary.Hclose(file_id);
} catch (HDFException he12) {}
System.exit( -1);
}
try {
h4toh5id= h4toh5.H4toh5open("testallvgroup.hdf",
"testallvgroup.h5");
} catch (H45Exception h45e1) {
System.err.println("Setup: H4toh5open exception "+h45e1);
try {
HDFLibrary.Vend(file_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.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.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 conversion of all lone vgroups
* Need to skip special groups such as "CDF0.0"
*/
public boolean test1( )
{
int num_lonevg = -1;
try {
num_lonevg = HDFLibrary.Vlone(file_id,null,0);
} catch (HDFException he1) {
System.err.println("Vlone exception "+he1);
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
if (num_lonevg < 0) {
System.err.println("Vlone error ");
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
if (num_lonevg == 0) {
System.err.println("Vlone: no groups found?");
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
int [] ref_array = new int[num_lonevg];
try {
num_lonevg = HDFLibrary.Vlone(file_id,ref_array,num_lonevg);
} catch (HDFException he1) {
System.err.println("Vlone exception "+he1);
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
if (num_lonevg < 0) {
System.err.println("Vlone error ");
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
for (int lone_vg_number = 0; lone_vg_number < num_lonevg;
lone_vg_number++) {
int vgroup_id = -1;
try {
vgroup_id = HDFLibrary.Vattach(file_id,
ref_array[lone_vg_number],"r");
} catch (HDFException he2) {
System.err.println("Vattach exception "+he2);
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
if (vgroup_id < 0) {
System.err.println("Vattach error ");
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
String vgroup_class[] = new String[1];
vgroup_class[0] = new String("");
try {
HDFLibrary.Vgetclass(vgroup_id,vgroup_class);
} catch (HDFException he3) {
System.err.println("Vgetclass exception "+he3);
System.err.println("Test I.1: FAIL");
test1_cleanup();
return(false);
}
if (vgroup_class[0].equals("CDF0.0")) {
try {
HDFLibrary.Vdetach(vgroup_id);
} catch (HDFException he4) {}
continue;
}
if (vgroup_class[0].equals("RIG0.0")) {
try {
HDFLibrary.Vdetach(vgroup_id);
} catch (HDFException he4) {}
continue;
}
try {
h4toh5.H4toh5advgroup(h4toh5id,vgroup_id,
"/",null);
} catch (H45Exception h45e1) {
System.err.println("h4toh5advgroup exception "+h45e1);
System.err.println("Test I.4: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.Vdetach(vgroup_id);
} catch (HDFException he5) {}
}
System.out.print("Test conversion of lone Vgroups: ");
System.out.println("PASS");
return(true);
}
/*
* Test batch II: test conversion of all lone vdatas
* Need to skip special groups such as "ATTR0.0"
*/
public boolean test2( )
{
/* II.1. Test lone vdatas
*
* vgroup itself and vgroup with non-vgroup members will be converted.
*
*/
int num_lonevd = -1;
try {
num_lonevd = HDFLibrary.VSlone(file_id,null,0);
} catch (HDFException he1) {
System.err.println("VSlone exception "+he1);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (num_lonevd < 0) {
System.err.println("VSlone error ");
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (num_lonevd == 0) {
System.err.println("VSlone: no groups found?");
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
int [] ref_array = new int[num_lonevd];
try {
num_lonevd = HDFLibrary.VSlone(file_id,ref_array,num_lonevd);
} catch (HDFException he1) {
System.err.println("VSlone exception "+he1);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (num_lonevd < 0) {
System.err.println("VSlone error ");
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
for (int lone_vd_number = 0; lone_vd_number < num_lonevd;
lone_vd_number++) {
int vdata_id = -1;
try {
vdata_id = HDFLibrary.VSattach(file_id,
ref_array[lone_vd_number],"r");
} catch (HDFException he2) {
System.err.println("VSattach exception "+he2);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (vdata_id < 0) {
System.err.println("VSattach error ");
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
boolean isA = false;
try {
isA = HDFLibrary.VSisattr(vdata_id);
} catch (HDFException he3) {
System.err.println("VSisattr exception "+he3);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (isA) {
try {
HDFLibrary.VSdetach(vdata_id);
} catch (HDFException he5) {}
continue;
}
String vdata_class[] = new String[1];
vdata_class[0] = new String("");
try {
HDFLibrary.VSgetclass(vdata_id,vdata_class);
} catch (HDFException he4) {
System.err.println("VSgetclass exception "+he4);
System.err.println("Test II.1: FAIL");
test2_cleanup();
return(false);
}
if (vdata_class[0].equals("_HDF_CHK_TBL_")) {
try {
HDFLibrary.VSdetach(vdata_id);
} catch (HDFException he5) {}
continue;
}
try {
h4toh5.H4toh5vdata(h4toh5id,vdata_id,
"/",null,1);
} catch (H45Exception h45e1) {
System.err.println("h4toh5vdata exception "+h45e1);
System.err.println("Test II.4: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.VSdetach(vdata_id);
} catch (HDFException he6) {}
}
System.out.print("Test conversion of lone Vdatas: ");
System.out.println("PASS");
return(true);
}
}