source: trunk/bindings/idl/write_test.pro @ 1822

Revision 1168, 9.9 KB checked in by Freddie Akeroyd, 3 years ago (diff)

Add in automatic running of IDL test
HDF5 test runs OK, HDF4 and XML fail
Refs #151

Line 
1pro write_test, argument
2
3        new_dlm_file = 'NeXusIDL-API.dlm'
4        DLM_REGISTER, new_dlm_file
5
6        print, 'NeXus IDL Api Write test'
7        access_method = 'nothing'
8
9        if (N_PARAMS() GE 1) then begin
10
11                if(strcmp(argument, 'hdf5') EQ 1) then begin
12                        print, 'Using HDF5'
13                        access_method = 'NXACC_CREATE5'
14                        filename = 'NXtest.h5'
15                        extfile = 'nxext.h5'
16                        link_external_path = 'nxfile://data/dmc01.h5#/entry1'
17                        endif
18
19                if(strcmp(argument, 'hdf4') EQ 1) then begin
20                        print, 'Using HDF4'
21                        access_method = 'NXACC_CREATE'
22                        filename = 'NXtest.hdf'
23                        extfile = 'nxext.hdf'
24                        link_external_path = 'nxfile://data/dmc01.hdf#/entry1'
25                endif
26
27                if(strcmp(argument, 'xml') EQ 1) then begin
28                        access_method = 'NXACC_CREATEXML'
29                        print, 'Using XML'
30                        filename = 'NXtest.xml'
31                        extfile = 'nxext.xml'
32                        link_external_path = 'nxfile://data/dmc01.xml#/entry1'
33                endif
34        endif
35
36        if (strcmp(access_method, 'nothing') EQ 1) then begin
37                print, 'Using Default Access Method: HDF5'
38                access_method = 'NXACC_CREATE5'
39                filename = 'NXtest.h5'
40                extfile = 'nxext.h5'
41                link_external_path = 'nxfile://data/dmc01.h5#/entry1'
42        endif
43
44        ; Windows (set correct path)
45        ;link_external_path = 'nxfile://C:\temp\dlm\dlm\data\dmc01.hdf#/entry1'
46
47        ; Linux
48
49
50        ; nxdatatypes:
51        nx_int16 = 22
52        nx_int32 = 24
53        nx_float32 = 5
54        nx_float64 = 6
55        nx_uint16 = 22
56
57        ;access_method = 'NXACC_CREATE5'
58        ;access_method = 'NXACC_CREATE'
59
60        ; Only type LONG arrays are accepted in dimensions and chunck size.
61        array_dims =[4L,4L]
62        chunk_size =[4L,4L]
63
64        rank = 2
65
66        nx_uint8_array = BytArr(4, 4)
67        v1 = [0B,1B,2B,4B]
68        v2 = [4B,5B,6B,7B]
69        v3 = [8B,9B,10B,11B]
70        v4 = [12B,13B,14B,15B]
71        nx_uint8_array =[[v1],[v2],[v3],[v4]]
72
73        nx_int16_array = IntArr(4, 4)
74        v1 = [0S,1S,2S,4S]
75        v2 = [4S,5S,6S,7S]
76        v3 = [-8S,-9S,-10S,-11S]
77        v4 = [-12S,-13S,-14S,-15S]
78        nx_int16_array =[[v1],[v2],[v3],[v4]]
79
80        nx_int16_array = UIntArr(4, 4)
81        v1 = [0U,1U,2U,4U]
82        v2 = [4U,5U,6U,7U]
83        v3 = [-8U,-9U,-10U,-11U]
84        v4 = [-12U,-13U,-14U,-15U]
85        nx_int16_array =[[v1],[v2],[v3],[v4]]
86
87        nx_int32_array = LonArr(4, 4)
88        v1 = [0L,1L,2L,3L]
89        v2 = [4L,5L,6L,7L]
90        v3 = [8L,9L,10L,11L]
91        v4 = [12L,13L,14L,15L]
92        nx_int32_array =[[v1],[v2],[v3],[v4]]
93
94        nx_uint32_array = ULonArr(4, 4)
95        v1 = [0UL,1UL,2UL,3UL]
96        v2 = [4UL,5UL,6UL,7UL]
97        v3 = [-8UL,-9UL,-10UL,-11UL]
98        v4 = [-12UL,-13UL,-14UL,-15UL]
99        nx_uint32_array =[[v1],[v2],[v3],[v4]]
100
101        nx_float32_array = FltArr(4, 4)
102        v1 = [0.0111112,0.02122222,0.233333333,0.34444444]
103        v2 = [0.3443333,0.55555554,0.666666667,0.77777333]
104        v3 = [0.6666689,0.99999977,10.10000023,11.2222209]
105        v4 = [-12.20002,-13.444442,-14.2222223,-15.444444]
106        nx_float32_array =[[v1],[v2],[v3],[v4]]
107
108        nx_float64_array = ULonArr(4, 4)
109        v1 = [0.0111112D,0.02122222D,0.233333333D,0.34444444D]
110        v2 = [0.3443333D,0.55555554D,0.666666667D,0.77777333D]
111        v3 = [0.6666689D,0.99999977D,10.10000023D,11.2222209D]
112        v4 = [-12.20002D,-13.444442D,-14.2222223D,-15.444444D]
113        nx_float64_array =[[v1],[v2],[v3],[v4]]
114
115        S = nxopen(filename, access_method, fileid)
116        print, 'nxopen status: ', S
117        S = nxsetnumberformat(fileid,"NX_FLOAT32",'%9.3f')
118        print, 'nxsetnumberformat status: ', S
119
120        S = nxmakegroup(fileid, "entry", "NXentry")
121        print, 'nxmakegroup status: ', S
122        S = nxopengroup(fileid, "entry", "NXentry")
123        print, 'nxopengroup status: ', S
124;        S = nxmakegroup(fileid, "anothergroup", "NXentry")
125;       print, 'nxmakegroup status: ', S
126        S = nxputattr(fileid, "hugo", "namenlos",strlen('namenlos'), 'NX_CHAR')
127        print, 'nxputattr status: ', S
128        S = nxputattr(fileid, "cucumber", "passion",strlen('passion'), 'NX_CHAR')
129        print, 'nxputattr status: ', S
130
131        ; needs to be an array?
132        nxlen = [10L]
133
134        S = nxmakedata(fileid, 'ch_data','NX_CHAR', 1, nxlen)
135        print, 'nxmakedata status: ', S
136        S = nxopendata(fileid, "ch_data")
137        print, "opendata status: ", S
138        S = nxputdata(fileid, 'NeXus Data')
139        print, 'nxputdata status:', S
140        S = nxclosedata(fileid)
141        print, "nxclosedata status: ", S
142
143        S = nxmakedata(fileid, 'i1_data','NX_UINT8', 2, array_dims)
144        print, 'nxmakedata status: ', S
145        S = nxopendata(fileid, "i1_data")
146        print, "opendata status: ", S
147        S = nxputdata(fileid, nx_uint8_array)
148        print, 'nxputdata status:', S
149        S = nxclosedata(fileid)
150        print, "nxclosedata status: ", S
151
152        S = nxmakedata(fileid, 'i4_data','NX_INT32', 2, array_dims)
153        print, 'nxmakedata status: ', S
154        S = nxopendata(fileid, "i4_data")
155        print, "opendata status: ", S
156        S = nxputdata(fileid, nx_int32_array)
157        print, 'nxputdata status:', S
158        S = nxclosedata(fileid)
159        print, "nxclosedata status: ", S
160
161        S = nxcompmakedata(fileid, 'r4_data','NX_FLOAT32', 2, array_dims, 'NX_COMP_LZW', chunk_size)
162        print, 'nxmakedata status: ', S
163        S = nxopendata(fileid, "r4_data")
164        print, "opendata status: ", S
165        S = nxputdata(fileid, nx_float32_array)
166        print, 'nxputdata status:', S
167        S = nxclosedata(fileid)
168        print, "nxclosedata status: ", S
169
170
171
172        S = nxmakedata(fileid, 'r8_data','NX_FLOAT64', 2, array_dims)
173        print, 'nxmakedata status: ', S
174        S = nxopendata(fileid, "r8_data")
175        print, "opendata status: ", S
176
177                slab_start = [2L,0L]
178                slab_size = [1L,4L]
179                S = nxputslab(fileid, nx_float64_array, slab_start, slab_size)
180                print, 'nxputslab status:', S
181
182                S = nxputattr(fileid,'ch_attribute', 'NeXus', strlen ('NeXus'), 'NX_CHAR')
183                print, 'nxputattr status : ',S
184
185                i = 42L
186                S = nxputattr(fileid,'i4_attribute', i, 1, 'NX_INT32')
187                print, 'nxputattr status : ',S
188
189                r = 3.14159265
190                S = nxputattr(fileid,'r4_attribute', r, 1, 'NX_FLOAT32')
191                print, 'nxputattr status : ',S
192                S = nxgetdataid(fileid, dataid)
193                print, 'nxgetdataid status: ', S
194                ;print, 'dataid handle: ', dataid
195
196
197        S = nxclosedata(fileid)
198        print, "nxclosedata status: ", S
199
200        S = nxmakegroup(fileid, 'data', 'NXdata')
201        print, 'nxmakegroup status: ', S
202
203        S = nxopengroup(fileid, 'data', 'NXdata')
204        print, 'nxopengroup status: ', S
205
206        S = nxmakelink(fileid, dataid)
207        print, 'nxmakelink status: ', S
208
209        dims = [100L,20L]
210        ; indexed array of longs
211        comp_array = lindgen(100,20)
212        cdims = [20L,20L]
213        rank = 2
214
215        S = nxcompmakedata(fileid, 'comp_data', 'NX_INT32', rank, dims, 'NX_COMP_LZW', cdims)
216        print, 'nxmakecompdata status:', S
217
218        S = nxopendata(fileid, "comp_data")
219        print, 'opendata status: ', S
220
221                S = nxputdata(fileid, comp_array)
222                print, 'nxputdata status:', S
223
224        S = nxclosedata(fileid)
225        print, 'nxclosedata status: ', S
226
227        S = nxflush(fileid)
228        print, 'nxflush status: ', S
229
230        S = nxmakedata(fileid, 'flush_data','NX_INT32', 1, 'NX_UNLIMITED')
231        print, 'nxmakedata status: ', S
232
233        data = [0L]
234        slab_size = [1L]
235        for i = 1L, 7L, 1L do begin
236                slab_start[0] = i
237
238                ; Maybe the putslab/putdata should accept single variables also,
239                ; easy to implement..
240
241                data[0] = long(i)
242                S = nxopendata(fileid, "flush_data")
243                print, 'opendata status: ', S
244
245                S = nxputslab(fileid, data, slab_start, slab_size)
246                print, 'nxputslab ', i,' status:', S
247                S = nxflush(fileid)
248                print, 'nxflush status: ', S
249        endfor
250
251        S = nxclosegroup(fileid)
252        print, 'nxclosegroup status: ', S
253
254        S = nxmakegroup(fileid, 'sample', 'NXsample')
255        print, 'nxmakegroup status: ', S
256
257        S = nxopengroup(fileid, 'sample', 'NXsample')
258        print, 'nxopengroup status: ', S
259        nxlen = [12L]
260        S = nxmakedata(fileid, 'ch_data', 'NX_CHAR', 1, nxlen)
261        print, 'nxmakedata status: ', S
262
263        S = nxopendata(fileid, "ch_data")
264        print, 'opendata status: ', S
265
266                S = nxputdata(fileid, 'NeXus sample')
267                print, 'nxputdata status:', S
268
269        S = nxclosedata(fileid)
270        print, 'nxclosedata status: ', S
271
272        S = nxgetgroupid(fileid, groupid)
273        print, 'nxgetgroupid status: ', S
274        print, 'groupid handle: ', groupid
275
276        S = nxclosegroup(fileid)
277        print, 'nxclosegroup status: ', S
278
279        S = nxclosegroup(fileid)
280        print, 'nxclosegroup status: ', S
281
282        S = nxmakegroup(fileid, 'link', 'NXentry')
283        print, 'nxmakegroup status: ', S
284
285        S = nxopengroup(fileid, 'link', 'NXentry')
286        print, 'nxopengroup status: ', S
287
288        S = nxmakelink(fileid, groupid)
289        print, 'nxmakelink status: ', S
290
291        print, 'groupid handle', groupid
292        S = nxmakenamedlink(fileid, 'renLinkGroup', groupid)
293        print, 'nxmakenamedlink status : ', S
294
295        print, 'dataid handle', dataid
296
297        S = nxmakenamedlink(fileid, 'renLinkData', dataid)
298        print, 'nxmakenamedlink status : ', S
299
300        S = nxclosegroup(fileid)
301        print, 'nxclosegroup status: ', S
302
303        S = nxclose(fileid)
304        print, 'nxclose status: ', S
305
306
307        access_method = 'NXACC_CREATE'
308
309        print, ''
310        print, ' ####################  Test external linking  ######################'
311        print, ''
312
313
314        ; Create the test file
315        S = nxopen(extfile, access_method, fileid)
316        print, 'nxopen status: ', S
317
318        S = nxmakegroup(fileid, 'entry1', 'NXentry')
319        print, 'nxmakegroup status: ', S
320
321        S = nxlinkexternal(fileid, 'entry1','NXentry',link_external_path)
322        print, 'nxlinkexternal: ', S
323
324        S = nxmakegroup(fileid, 'entry2', 'NXentry')
325        print, 'nxmakegroup status: ', S
326
327        S = nxlinkexternal(fileid, 'entry2','NXentry',link_external_path)
328        print, 'nxlinkexternal: ', S
329
330        S = nxclose(fileid)
331        print, 'nxclose status: ', S
332
333        ; Actual link testing begins
334
335        access_method = 'NXACC_RDWR'
336        S = nxopen(extfile, access_method, fileid)
337        print, 'nxopen status: ', S
338        S = nxopenpath(fileid, '/entry1/start_time')
339        print, 'nxopenpath status', S
340        print, ''
341
342        S = nxgetdata(fileid, data)
343                print, 'nxget data status: ', S
344                print, 'First file time :'
345                print,  data
346                print, ''
347
348        S = nxinquirefile(fileid, filename, 256)
349        print, 'nxinquirefile status: ', S
350        print, 'current file: ', filename
351
352        S = nxopenpath(fileid, '/entry2/sample/sample_name')
353        print, 'nxopenpath status', S
354        S = nxgetdata(fileid, data)
355                print, 'nxget data status: ', S
356                print, 'Second file sample :'
357                print,  data
358                print, ''
359
360        S = nxinquirefile(fileid, filename, 256)
361        print, 'nxinquirefile status: ', S
362        print, 'current file: ', filename
363
364        S = nxopenpath(fileid, '/entry2/start_time')
365        print, 'nxopenpath status', S
366        S = nxgetdata(fileid, data)
367                print, 'nxget data status: ', S
368                print, 'Second file time :'
369                print,  data
370                print, ''
371
372        S = nxopenpath(fileid, '/')
373        S = nxisexternalgroup(fileid, 'entry1', 'NXentry', filename, 255)
374        print, 'nxisexternalgroup status', S
375        print, 'entry1 external URL =', filename
376
377        S = nxclose(fileid)
378        print, 'nxclose status: ', S
379end
Note: See TracBrowser for help on using the repository browser.