1 | function test_put_get_var_double ( ncfile ) |
---|
2 | % TEST_GET_PUT_VAR_DOUBLE |
---|
3 | % |
---|
4 | % Tests expected to succeed. |
---|
5 | % Test 001: write to a singleton value, read them back using [put/get]_var_double |
---|
6 | % Test 002: write to a singleton value, read them back using [put/get]_var1_double |
---|
7 | % Test 003: write to an entire value, read them back using [put/get]_var_double |
---|
8 | % Test 004: write to an single value, read them back using [put/get]_var1_double |
---|
9 | % Test 005: write to an single value, read them back using [put/get]_vara_double |
---|
10 | % Test 006: write to an single value, read them back using [put/get]_vars_double |
---|
11 | % Test 007: write to an single value, read them back using [put/get]_varm_double |
---|
12 | % |
---|
13 | % [PUT,GET]_VAR_DOUBLE: Write a 6x4 array of monotonically increasing values, read them back. |
---|
14 | % [PUT,GET]_VAR1_DOUBLE: write and read 255 to disk |
---|
15 | % [PUT,GET]_VARA_DOUBLE: write and read a 3x3 chunk |
---|
16 | % [PUT,GET]_VARS_DOUBLE: write and read the 6x4 array, subset by factor of 2, stride of 2 |
---|
17 | % [PUT,GET]_VARM_DOUBLE: normally we want to transpose the data before writing with |
---|
18 | % mexnc. However, this is makes for a good test of the VARM_XXX |
---|
19 | % routine, as that routine can actually handle the transpose for us. |
---|
20 | % So this test writes the same array of data as [put,get]_var_xxx, |
---|
21 | % but we don't bother to transpose the array. Yes, these routines |
---|
22 | % really are that hard to wrap one's head around. |
---|
23 | % |
---|
24 | |
---|
25 | if ( nargin == 0 ) |
---|
26 | ncfile = 'foo.nc'; |
---|
27 | end |
---|
28 | |
---|
29 | create_test_ncfile ( ncfile ); |
---|
30 | |
---|
31 | test_001 ( ncfile ); |
---|
32 | test_002 ( ncfile ); |
---|
33 | test_003 ( ncfile ); |
---|
34 | test_004 ( ncfile ); |
---|
35 | test_005 ( ncfile ); |
---|
36 | test_006 ( ncfile ); |
---|
37 | test_007 ( ncfile ); |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | function test_003 ( ncfile ) |
---|
42 | |
---|
43 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
44 | if ( status ~= 0 ) |
---|
45 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
46 | error ( msg ); |
---|
47 | end |
---|
48 | |
---|
49 | |
---|
50 | [y_dimid,status] = mexnc ( 'inq_dimid', ncid, 'y' ); |
---|
51 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
52 | |
---|
53 | [len_y,status] = mexnc ( 'inq_dimlen', ncid, y_dimid ); |
---|
54 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
55 | |
---|
56 | [x_dimid,status] = mexnc ( 'inq_dimid', ncid, 'x' ); |
---|
57 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
58 | |
---|
59 | [len_x,status] = mexnc ( 'inq_dimlen', ncid, x_dimid ); |
---|
60 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
61 | |
---|
62 | |
---|
63 | [varid, status] = mexnc('INQ_VARID', ncid, 'z_double'); |
---|
64 | if ( status ~= 0 ) |
---|
65 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
66 | error ( msg ); |
---|
67 | end |
---|
68 | |
---|
69 | [varname,xtype,ndims,dimids,natts,status] = mexnc('INQ_VAR',ncid,varid); |
---|
70 | for j = 1:ndims |
---|
71 | dimlen(j) = mexnc('INQ_DIMLEN',ncid,dimids(j)); |
---|
72 | end |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | input_data = [1:1:prod(dimlen)]; |
---|
78 | input_data = reshape ( input_data, dimlen(1), dimlen(2) ); |
---|
79 | |
---|
80 | status = mexnc ( 'PUT_VAR_DOUBLE', ncid, varid, input_data' ); |
---|
81 | if ( status ~= 0 ) |
---|
82 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
83 | msg = sprintf ( '%s: PUT_VAR_DOUBLE failed, (%s)\n', mfilename, ncerr_msg ); |
---|
84 | error ( msg ); |
---|
85 | end |
---|
86 | |
---|
87 | |
---|
88 | [output_data, status] = mexnc ( 'GET_VAR_DOUBLE', ncid, varid ); |
---|
89 | if ( status ~= 0 ) |
---|
90 | msg = sprintf ( '%s: GET_VAR_DOUBLE failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
91 | error ( msg ); |
---|
92 | end |
---|
93 | |
---|
94 | |
---|
95 | d = max(abs(output_data-input_data'))'; |
---|
96 | if (any(d)) |
---|
97 | msg = sprintf ( '%s: values written by PUT_VAR_DOUBLE do not match what was retrieved by GET_VAR_DOUBLE\n', mfilename ); |
---|
98 | error ( msg ); |
---|
99 | end |
---|
100 | |
---|
101 | fprintf ( 1, 'PUT_VAR_DOUBLE succeeded\n' ); |
---|
102 | fprintf ( 1, 'GET_VAR_DOUBLE succeeded\n' ); |
---|
103 | |
---|
104 | status = mexnc ( 'close', ncid ); |
---|
105 | if ( status ~= 0 ) |
---|
106 | error ( 'CLOSE failed' ); |
---|
107 | end |
---|
108 | |
---|
109 | return |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | function test_004 ( ncfile ) |
---|
117 | |
---|
118 | |
---|
119 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
120 | if ( status ~= 0 ) |
---|
121 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
122 | error ( msg ); |
---|
123 | end |
---|
124 | |
---|
125 | |
---|
126 | [y_dimid,status] = mexnc ( 'inq_dimid', ncid, 'y' ); |
---|
127 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
128 | |
---|
129 | [len_y,status] = mexnc ( 'inq_dimlen', ncid, y_dimid ); |
---|
130 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
131 | |
---|
132 | [x_dimid,status] = mexnc ( 'inq_dimid', ncid, 'x' ); |
---|
133 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
134 | |
---|
135 | [len_x,status] = mexnc ( 'inq_dimlen', ncid, x_dimid ); |
---|
136 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
137 | |
---|
138 | |
---|
139 | [varid, status] = mexnc('INQ_VARID', ncid, 'z_double'); |
---|
140 | if ( status ~= 0 ) |
---|
141 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
142 | error ( msg ); |
---|
143 | end |
---|
144 | |
---|
145 | |
---|
146 | % |
---|
147 | % Test PUT/GET_VAR1 |
---|
148 | input_data = 255; |
---|
149 | status = mexnc ( 'PUT_VAR1_DOUBLE', ncid, varid, [2 2], input_data ); |
---|
150 | if ( status < 0 ) |
---|
151 | msg = sprintf ( '%s: PUT_VAR1_DOUBLE failed\n', mfilename ); |
---|
152 | error ( msg ); |
---|
153 | end |
---|
154 | |
---|
155 | |
---|
156 | status = mexnc ( 'SYNC', ncid ); |
---|
157 | if ( status < 0 ) |
---|
158 | msg = sprintf ( '%s: SYNC failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
159 | error ( msg ); |
---|
160 | end |
---|
161 | |
---|
162 | |
---|
163 | [output_data, status] = mexnc ( 'GET_VAR1_DOUBLE', ncid, varid, [2 2] ); |
---|
164 | if ( status < 0 ) |
---|
165 | msg = sprintf ( '%s: GET_VAR1_DOUBLE failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
166 | error ( msg ); |
---|
167 | end |
---|
168 | |
---|
169 | d = max(abs(double(output_data)-double(input_data))); |
---|
170 | if (d > 0) |
---|
171 | msg = sprintf ( '%s: values written by PUT_VAR1_DOUBLE do not match what was retrieved by GET_VAR_DOUBLE\n', mfilename ); |
---|
172 | error ( msg ); |
---|
173 | end |
---|
174 | |
---|
175 | status = mexnc ( 'close', ncid ); |
---|
176 | if ( status ~= 0 ) |
---|
177 | error ( 'CLOSE failed' ); |
---|
178 | end |
---|
179 | |
---|
180 | fprintf ( 1, 'PUT_VAR1_DOUBLE succeeded\n' ); |
---|
181 | fprintf ( 1, 'GET_VAR1_DOUBLE succeeded\n' ); |
---|
182 | return |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | function test_005 ( ncfile ) |
---|
194 | |
---|
195 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
196 | if ( status ~= 0 ) |
---|
197 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
198 | error ( msg ); |
---|
199 | end |
---|
200 | |
---|
201 | |
---|
202 | [y_dimid,status] = mexnc ( 'inq_dimid', ncid, 'y' ); |
---|
203 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
204 | |
---|
205 | [len_y,status] = mexnc ( 'inq_dimlen', ncid, y_dimid ); |
---|
206 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
207 | |
---|
208 | [x_dimid,status] = mexnc ( 'inq_dimid', ncid, 'x' ); |
---|
209 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
210 | |
---|
211 | [len_x,status] = mexnc ( 'inq_dimlen', ncid, x_dimid ); |
---|
212 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
213 | |
---|
214 | |
---|
215 | [varid, status] = mexnc('INQ_VARID', ncid, 'z_double'); |
---|
216 | if ( status ~= 0 ) |
---|
217 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
218 | error ( msg ); |
---|
219 | end |
---|
220 | |
---|
221 | [varname,xtype,ndims,dimids,natts,status] = mexnc('INQ_VAR',ncid,varid); |
---|
222 | for j = 1:ndims |
---|
223 | dimlen(j) = mexnc('INQ_DIMLEN',ncid,dimids(j)); |
---|
224 | end |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | input_data = [1:1:prod(dimlen)]; |
---|
230 | input_data = reshape ( input_data, dimlen(1), dimlen(2) ); |
---|
231 | |
---|
232 | input_data = input_data(2:4,1:3); |
---|
233 | input_data = input_data'; |
---|
234 | start = [1 0]; count = [3 3]; |
---|
235 | |
---|
236 | |
---|
237 | status = mexnc ( 'PUT_VARA_DOUBLE', ncid, varid, start, count, input_data ); |
---|
238 | if ( status < 0 ) |
---|
239 | msg = sprintf ( '%s: PUT_VARA_DOUBLE failed\n', mfilename ); |
---|
240 | error ( msg ); |
---|
241 | end |
---|
242 | |
---|
243 | |
---|
244 | status = mexnc ( 'SYNC', ncid ); |
---|
245 | if ( status < 0 ) |
---|
246 | msg = sprintf ( '%s: SYNC failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
247 | error ( msg ); |
---|
248 | end |
---|
249 | |
---|
250 | |
---|
251 | [output_data, status] = mexnc ('GET_VARA_DOUBLE',ncid,varid,start,count); |
---|
252 | if ( status < 0 ) |
---|
253 | msg = sprintf ( '%s: GET_VARA_DOUBLE failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
254 | error ( msg ); |
---|
255 | end |
---|
256 | |
---|
257 | d = max(abs(output_data-input_data))'; |
---|
258 | if (any(d)) |
---|
259 | msg = sprintf ( '%s: values written by PUT_VARA_DOUBLE do not match what was retrieved by GET_VARA_DOUBLE\n', mfilename ); |
---|
260 | error ( msg ); |
---|
261 | end |
---|
262 | |
---|
263 | status = mexnc ( 'close', ncid ); |
---|
264 | if ( status ~= 0 ) |
---|
265 | error ( 'CLOSE failed' ); |
---|
266 | end |
---|
267 | |
---|
268 | fprintf ( 1, 'PUT_VARA_DOUBLE succeeded\n' ); |
---|
269 | fprintf ( 1, 'GET_VARA_DOUBLE succeeded\n' ); |
---|
270 | |
---|
271 | return |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | |
---|
277 | |
---|
278 | |
---|
279 | |
---|
280 | |
---|
281 | function test_006 ( ncfile ) |
---|
282 | |
---|
283 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
284 | if ( status ~= 0 ) |
---|
285 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
286 | error ( msg ); |
---|
287 | end |
---|
288 | |
---|
289 | [varid, status] = mexnc('INQ_VARID', ncid, 'z_double'); |
---|
290 | if ( status ~= 0 ) |
---|
291 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
292 | error ( msg ); |
---|
293 | end |
---|
294 | |
---|
295 | [varname,xtype,ndims,dimids,natts,status] = mexnc('INQ_VAR',ncid,varid); |
---|
296 | for j = 1:ndims |
---|
297 | dimlen(j) = mexnc('INQ_DIMLEN',ncid,dimids(j)); |
---|
298 | end |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | input_data = [1:1:prod(dimlen)]; |
---|
304 | input_data = reshape ( input_data, dimlen(1), dimlen(2) ); |
---|
305 | input_data = input_data(1:2:end,1:2:end); |
---|
306 | [r,c] = size(input_data); |
---|
307 | |
---|
308 | status = mexnc ( 'PUT_VARS_DOUBLE', ncid, varid, [0 0], [r c], [2 2], input_data' ); |
---|
309 | if ( status < 0 ) |
---|
310 | msg = sprintf ( '%s: PUT_VARS_DOUBLE failed\n', mfilename ); |
---|
311 | error ( msg ); |
---|
312 | end |
---|
313 | |
---|
314 | |
---|
315 | status = mexnc ( 'SYNC', ncid ); |
---|
316 | if ( status < 0 ) |
---|
317 | msg = sprintf ( '%s: SYNC failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
318 | error ( msg ); |
---|
319 | end |
---|
320 | |
---|
321 | |
---|
322 | [output_data, status] = mexnc ( 'GET_VARS_DOUBLE', ncid, varid, [0 0], [r c], [2 2] ); |
---|
323 | if ( status < 0 ) |
---|
324 | msg = sprintf ( '%s: GET_VARS_DOUBLE failed, msg ''%s''\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
325 | error ( msg ); |
---|
326 | end |
---|
327 | |
---|
328 | |
---|
329 | d = max(abs(output_data-input_data'))'; |
---|
330 | if (any(d)) |
---|
331 | msg = sprintf ( '%s: values written by PUT_VARS_DOUBLE do not match what was retrieved by GET_VARS_DOUBLE\n', mfilename ); |
---|
332 | error ( msg ); |
---|
333 | end |
---|
334 | |
---|
335 | fprintf ( 1, 'PUT_VARS_DOUBLE succeeded\n' ); |
---|
336 | fprintf ( 1, 'GET_VARS_DOUBLE succeeded\n' ); |
---|
337 | |
---|
338 | status = mexnc ( 'close', ncid ); |
---|
339 | if ( status ~= 0 ) |
---|
340 | error ( 'CLOSE failed' ); |
---|
341 | end |
---|
342 | |
---|
343 | return |
---|
344 | |
---|
345 | |
---|
346 | |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | |
---|
351 | |
---|
352 | |
---|
353 | function test_007 ( ncfile ) |
---|
354 | |
---|
355 | if mexnc_use_tmw |
---|
356 | warning('GET_VARM and PUT_VARM operations are not supported in the netCDF package'); |
---|
357 | return |
---|
358 | end |
---|
359 | |
---|
360 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
361 | if ( status ~= 0 ) |
---|
362 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
363 | error ( msg ); |
---|
364 | end |
---|
365 | |
---|
366 | |
---|
367 | [y_dimid,status] = mexnc ( 'inq_dimid', ncid, 'y' ); |
---|
368 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
369 | |
---|
370 | [len_y,status] = mexnc ( 'inq_dimlen', ncid, y_dimid ); |
---|
371 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
372 | |
---|
373 | [x_dimid,status] = mexnc ( 'inq_dimid', ncid, 'x' ); |
---|
374 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
375 | |
---|
376 | [len_x,status] = mexnc ( 'inq_dimlen', ncid, x_dimid ); |
---|
377 | if status, error ( mexnc ( 'strerror', status ) ), end |
---|
378 | |
---|
379 | |
---|
380 | [varid, status] = mexnc('INQ_VARID', ncid, 'z_double'); |
---|
381 | if ( status ~= 0 ) |
---|
382 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
383 | error ( msg ); |
---|
384 | end |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | % |
---|
389 | % Test PUT/GET_VARM |
---|
390 | input_data = [1:1:len_y*len_x]; |
---|
391 | input_data = reshape ( input_data, len_y, len_x ); |
---|
392 | |
---|
393 | start_coord = [0 0]; |
---|
394 | count_coord = [6 4]; |
---|
395 | stride_coord = [1 1]; |
---|
396 | |
---|
397 | % |
---|
398 | % This is the tricky part. When the matrix arrives in the mex file, it |
---|
399 | % arrives essentially transposed, as a 4x6 array, monotonically increasing |
---|
400 | % across the columns instead of rows. But in the netcdf file, we want the |
---|
401 | % dataset to increase monotonically by rows. This is an inter-element |
---|
402 | % distance of 1 for the rows. So the first column should consist of |
---|
403 | % [1 2 3 4 5 6], and the 2nd row starts at 7. That inter-element distance |
---|
404 | % is then 6. In the imap vector, you start with the slowest varying FILE |
---|
405 | % dimension and proceed out to the most rapidly varying. This means imap |
---|
406 | % should be 6 and then 1. |
---|
407 | % |
---|
408 | % NetCDF dimension inter-element distance |
---|
409 | % most rapidly varying 6 |
---|
410 | % most slowly varying 1 |
---|
411 | % |
---|
412 | imap_coord = [1 6]; |
---|
413 | |
---|
414 | % |
---|
415 | % Write without transposing first. |
---|
416 | status = mexnc ( 'put_varm_double', ncid, varid, start_coord, count_coord, stride_coord, imap_coord, input_data ); |
---|
417 | if ( status ~= 0 ) |
---|
418 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
419 | msg = sprintf ( '%s: ''put_varm_double'' failed on var rh, file %s, error message '' %s ''\n', mfilename, ncfile, ncerr_msg ); |
---|
420 | error ( msg ); |
---|
421 | end |
---|
422 | |
---|
423 | status = mexnc ( 'sync', ncid ); |
---|
424 | if ( status ~= 0 ) |
---|
425 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
426 | msg = sprintf ( '%s: ''sync'' failed on file %s, error message '' %s ''\n', mfilename, ncfile, ncerr_msg ); |
---|
427 | error ( msg ); |
---|
428 | end |
---|
429 | |
---|
430 | |
---|
431 | % |
---|
432 | % Now read it back. |
---|
433 | % |
---|
434 | % This is the tricky part. When the matrix arrives from the mexfile, |
---|
435 | % one has to remember that it arrives transposed. So what we want is |
---|
436 | % to choose imap so that it yields the transpose of what we really want. |
---|
437 | % Then we get the transpose of a transpose, which would be the data arranged |
---|
438 | % in rows and columns in matlab exactly as it is in the netcdf file. |
---|
439 | % |
---|
440 | % The NetCDF file has the data stored as |
---|
441 | % |
---|
442 | % | 1 7 13 19 | |
---|
443 | % | 2 8 14 20 | |
---|
444 | % | 3 9 15 21 | |
---|
445 | % | 4 10 16 22 | |
---|
446 | % | 5 11 17 23 | |
---|
447 | % | 6 12 18 24 | |
---|
448 | % |
---|
449 | % The transpose of what we want would be |
---|
450 | % |
---|
451 | % | 1 2 3 4 5 6 | |
---|
452 | % | 7 8 9 10 11 12 | |
---|
453 | % | 13 14 15 16 17 18 | |
---|
454 | % | 19 20 21 22 23 24 | |
---|
455 | % |
---|
456 | % Start with the end of imap, which is the most rapidly varying NetCDF |
---|
457 | % dimension. That's the column. In the internal array (that's the 2nd |
---|
458 | % array above), how far between elements? In the NetCDF file file, 1 and 7 |
---|
459 | % are next to each other across the row, but in the internal array (which |
---|
460 | % is still inside the mex file and therefore in C, so row major order) |
---|
461 | % they have a distance of 6. The first element of imap corresponds to |
---|
462 | % the slowest varying NetCDF dimension, the rows. In the internal array, |
---|
463 | % how far between row elements? In the NetCDF file, 1 and 2 are next to |
---|
464 | % each other across rows, but in the internal array, they have a distance |
---|
465 | % of 1 across columns. So imap is the same as above, [1 6]. |
---|
466 | [output_data,status] = mexnc ( 'get_varm_double', ncid, varid, start_coord, count_coord, stride_coord, imap_coord ); |
---|
467 | if ( status ~= 0 ) |
---|
468 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
469 | msg = sprintf ( '%s: ''get_varm_double'' failed on var rh, file %s, error message '' %s ''\n', mfilename, ncfile, ncerr_msg ); |
---|
470 | error ( msg ); |
---|
471 | end |
---|
472 | |
---|
473 | d = max(abs(output_data-input_data))'; |
---|
474 | if (any(d)) |
---|
475 | msg = sprintf ( '%s: values written by PUT_VARM_DOUBLE do not match what was retrieved by GET_VARM_DOUBLE\n', mfilename ); |
---|
476 | error ( msg ); |
---|
477 | end |
---|
478 | |
---|
479 | |
---|
480 | |
---|
481 | fprintf ( 1, 'PUT_VARM_DOUBLE succeeded\n' ); |
---|
482 | fprintf ( 1, 'GET_VARM_DOUBLE succeeded\n' ); |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | % |
---|
487 | % CLOSE |
---|
488 | status = mexnc ( 'close', ncid ); |
---|
489 | if ( status ~= 0 ) |
---|
490 | error ( 'CLOSE failed' ); |
---|
491 | end |
---|
492 | |
---|
493 | |
---|
494 | return |
---|
495 | |
---|
496 | |
---|
497 | |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | function test_001 ( ncfile ) |
---|
502 | |
---|
503 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
504 | if ( status ~= 0 ) |
---|
505 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
506 | error ( msg ); |
---|
507 | end |
---|
508 | |
---|
509 | fprintf ( 1, 'a\n' ); |
---|
510 | |
---|
511 | % |
---|
512 | % Test 1: singleton |
---|
513 | [varid, status] = mexnc('INQ_VARID', ncid, 'double_singleton'); |
---|
514 | if ( status ~= 0 ) |
---|
515 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
516 | error ( msg ); |
---|
517 | end |
---|
518 | |
---|
519 | fprintf ( 1, 'b\n' ); |
---|
520 | |
---|
521 | input_data = 3.14; |
---|
522 | status = mexnc ( 'PUT_VAR_DOUBLE', ncid, varid, input_data ); |
---|
523 | if status |
---|
524 | error ( mexnc('strerror',status) ); |
---|
525 | end |
---|
526 | |
---|
527 | fprintf ( 1, 'c\n' ); |
---|
528 | |
---|
529 | [output_data, status] = mexnc ( 'GET_VAR_DOUBLE', ncid, varid ); |
---|
530 | if status |
---|
531 | error ( mexnc('strerror',status) ); |
---|
532 | end |
---|
533 | |
---|
534 | fprintf ( 1, 'd\n' ); |
---|
535 | |
---|
536 | d = max(abs(output_data-input_data))'; |
---|
537 | if (any(d)) |
---|
538 | msg = sprintf ( '%s: values written by PUT_VAR_DOUBLE do not match what was retrieved by GET_VAR_DOUBLE\n', mfilename ); |
---|
539 | error ( msg ); |
---|
540 | end |
---|
541 | |
---|
542 | fprintf ( 1, 'GET_VAR_DOUBLE succeeded on a singleton\n' ); |
---|
543 | fprintf ( 1, 'PUT_VAR_DOUBLE succeeded on a singleton\n' ); |
---|
544 | |
---|
545 | status = mexnc ( 'close', ncid ); |
---|
546 | if status, error ( mexnc('strerror',status) ), end |
---|
547 | |
---|
548 | return |
---|
549 | |
---|
550 | |
---|
551 | |
---|
552 | |
---|
553 | |
---|
554 | |
---|
555 | function test_002 ( ncfile ) |
---|
556 | |
---|
557 | [ncid, status] = mexnc ( 'open', ncfile, nc_write_mode ); |
---|
558 | if ( status ~= 0 ) |
---|
559 | msg = sprintf ( '%s: %s\n', mfilename, mexnc ( 'strerror', status ) ); |
---|
560 | error ( msg ); |
---|
561 | end |
---|
562 | |
---|
563 | |
---|
564 | % |
---|
565 | % Test 1: singleton |
---|
566 | [varid, status] = mexnc('INQ_VARID', ncid, 'double_singleton'); |
---|
567 | if ( status ~= 0 ) |
---|
568 | msg = sprintf ( '%s: INQ_VARID failed\n', mfilename ); |
---|
569 | error ( msg ); |
---|
570 | end |
---|
571 | |
---|
572 | input_data = 3.14; |
---|
573 | status = mexnc ( 'PUT_VAR1_DOUBLE', ncid, varid, 0, input_data ); |
---|
574 | if status |
---|
575 | error ( mexnc('strerror',status) ); |
---|
576 | end |
---|
577 | |
---|
578 | [output_data, status] = mexnc ( 'GET_VAR1_DOUBLE', ncid, varid, 0 ); |
---|
579 | if status |
---|
580 | error ( mexnc('strerror',status) ); |
---|
581 | end |
---|
582 | |
---|
583 | d = max(abs(output_data-input_data))'; |
---|
584 | if (any(d)) |
---|
585 | msg = sprintf ( '%s: values written by PUT_VAR1_DOUBLE do not match what was retrieved by GET_VAR1_DOUBLE\n', mfilename ); |
---|
586 | error ( msg ); |
---|
587 | end |
---|
588 | |
---|
589 | |
---|
590 | fprintf ( 1, 'GET_VAR1_DOUBLE succeeded on a singleton\n' ); |
---|
591 | fprintf ( 1, 'PUT_VAR1_DOUBLE succeeded on a singleton\n' ); |
---|
592 | |
---|
593 | status = mexnc ( 'close', ncid ); |
---|
594 | if status, error ( mexnc('strerror',status) ), end |
---|
595 | |
---|
596 | return |
---|