Repository navigation
Expand file tree
/
Copy pathimagetest.java
More file actions
201 lines (177 loc) · 4.14 KB
/
Copy pathimagetest.java
File metadata and controls
201 lines (177 loc) · 4.14 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
import ncsa.hdf.h4toh5lib.*;
import ncsa.hdf.h4toh5lib.exceptions.*;
import ncsa.hdf.hdflib.*;
import ncsa.hdf.hdf5lib.*;
public class imagetest {
private int file_id = -1;
private int gr_id = -1;
private int h4toh5id = -1;
private boolean initialized = false;
public imagetest() {};
static public void main( String []args )
{
imagetest it = new imagetest();
it.setup();
boolean r1 = it.test1();
boolean r2 = it.test2();
it.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("image_lib_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 {
gr_id = HDFLibrary.GRstart(file_id);
} catch (HDFException he5) {
System.err.println("Setup: open GR interface exception: "+he5);
try {
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.Hclose(file_id);
} catch (HDFException he8) {}
System.exit( -1);
}
try {
h4toh5id= h4toh5.H4toh5open("image_lib_test.hdf",
"image_lib_test.h5");
} catch (H45Exception h45e1) {
System.err.println("Setup: H4toh5open exception "+h45e1);
try {
HDFLibrary.GRend(gr_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.GRend(gr_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.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( )
{
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 1: FAIL");
test1_cleanup();
return(false);
}
try {
HDFLibrary.GRendaccess(image_id);
} catch (HDFException he7_1) {
System.err.println("Test 1: FAIL after test");
return(false);
}
System.out.print("Test image conversion using default name generation: ");
System.out.println("PASS");
return(true);
}
/*
* Test batch II: Test API with user-defined name for HDF5 objects
*/
public boolean test2( )
{
int image_id = -1;
try {
image_id = HDFLibrary.GRselect(gr_id,1);
} catch (HDFException he2) {
System.err.println("GRselect exception "+he2);
System.err.println("Test 2: FAIL");
test2_cleanup();
return(false);
}
try {
h4toh5.H4toh5image(h4toh5id,image_id,"/group1",
"myimage","/mypalg","mypal",0,1);
} catch (H45Exception h45e2_1) {
System.err.println("h4toh5image exception "+h45e2_1);
System.err.println("Test 2: FAIL");
test2_cleanup();
return(false);
}
try {
HDFLibrary.GRendaccess(image_id);
} catch (HDFException he7_1) {
System.err.println("Test 2: FAIL after test");
return(false);
}
System.out.print("Test image conversion using user name generation: ");
System.out.println("PASS");
return(true);
}
}