1 | function test_nc_varput ( ncfile ) |
---|
2 | % TEST_NC_VARPUT: |
---|
3 | % |
---|
4 | % |
---|
5 | % Generic Tests, should all fail gracefully. |
---|
6 | % Test 001: pass 0 arguments into nc_varput. |
---|
7 | % Test 002: pass 1 arguments into nc_varput. |
---|
8 | % Test 003: pass 2 arguments into nc_varput. |
---|
9 | % Test 004: bad filename into nc_varput. |
---|
10 | % Test 005: bad varname into nc_varput. |
---|
11 | % Test 006: try to write a 2D matrix to a singleton |
---|
12 | % Test 007: try to write a 2D matrix to a 2D var using 'put_var', |
---|
13 | % but having the wrong size |
---|
14 | % Test 008: try to write a 2D matrix to a 2D var using 'put_vara', |
---|
15 | % but having the wrong size |
---|
16 | % Test 009: try to write a 2D matrix to a 2D var using 'put_vars', |
---|
17 | % but having the wrong size |
---|
18 | % Test 010: try to write a 2D matrix to a 2D var using 'put_vara', |
---|
19 | % but with too long of a count argument |
---|
20 | % Test 011: try to write a 2D matrix to a 2D var using 'put_vars', |
---|
21 | % but with too long of a stride argument |
---|
22 | % Test 012: try to write a 2D matrix to a 2D var using 'put_vars', |
---|
23 | % but with too long of a start, count, stride argument |
---|
24 | % Test 013: try a bad start index |
---|
25 | % |
---|
26 | % |
---|
27 | % |
---|
28 | % put_var1 |
---|
29 | % Test 100: write to a singleton variable and read it back. |
---|
30 | % Test 101: write to a 1D variable with just a count |
---|
31 | % Test 102: write to a 1D variable with a bad count |
---|
32 | % Test 103: write to a 1D variable with a good count |
---|
33 | % Test 104: write to a 1D variable with a bad stride |
---|
34 | % Test 105: write to a 1D variable with a good stride. |
---|
35 | % Test 106: write more than 1 datum to a singleton variable. This should fail. |
---|
36 | % Test 107: write 1 datum to a singleton variable, bad start. Should fail. |
---|
37 | % Test 108: write 1 datum to a singleton variable, bad count. Should fail. |
---|
38 | % Test 109: write 1 datum to a singleton variable, give a stride. Should fail. |
---|
39 | % |
---|
40 | % put_var |
---|
41 | % Test 200: using put_var, write all the data to a 2D dataset. |
---|
42 | % Test 201: using put_vara, write a chunk of the data to a 2D dataset. |
---|
43 | % Test 202: using put_vara, write a chunk of data to a 2D dataset. |
---|
44 | % Test 203: using put_vars, write a chunk of data to a 2D dataset. |
---|
45 | % Test 204: write too much to a 2D dataset (using put_var). Should fail. |
---|
46 | % Test 205: write too little to a 2D dataset (using put_var). Should fail. |
---|
47 | % Test 206: use put_vara, write with a bad offset. Should fail. |
---|
48 | % Test 207: use put_vars, write with a bad start. Should fail. |
---|
49 | % Test 208: use put_vara, write with a bad count. Should fail. |
---|
50 | % Test 209: use put_vars, write with a bad stride. Should fail. |
---|
51 | % |
---|
52 | % Test 301: test reading with scale factors, add offsets. |
---|
53 | % Test 302: test writing with scale factors, add offsets. |
---|
54 | % Test 303: test reading with scale factor, no add offset. |
---|
55 | % Test 304: test writing/reading with _FillValue |
---|
56 | % Test 305: test reading with missing_value |
---|
57 | % Test 306: test reading with floating point scale factor |
---|
58 | % Test 307: test with _FillValue and missing_value |
---|
59 | % |
---|
60 | % |
---|
61 | |
---|
62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
63 | % |
---|
64 | % $Id: test_nc_varput.m 2559 2008-11-28 21:53:27Z johnevans007 $ |
---|
65 | % $LastChangedDate: 2008-11-28 16:53:27 -0500 (Fri, 28 Nov 2008) $ |
---|
66 | % $LastChangedRevision: 2559 $ |
---|
67 | % $LastChangedBy: johnevans007 $ |
---|
68 | % |
---|
69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
70 | |
---|
71 | fprintf ( 1, 'NC_VARGET, NC_VARPUT: starting test suite...\n' ); |
---|
72 | if nargin == 0 |
---|
73 | ncfile = 'foo.nc'; |
---|
74 | end |
---|
75 | |
---|
76 | |
---|
77 | create_test_file ( ncfile ); |
---|
78 | |
---|
79 | test_001 ( 'testdata/empty.nc' ); |
---|
80 | test_002 ( 'testdata/empty.nc' ); |
---|
81 | test_003 ( 'testdata/empty.nc' ); |
---|
82 | test_004 ( 'i_do_not_exist.nc' ); |
---|
83 | test_005 ( ncfile ); |
---|
84 | test_006 ( ncfile ); |
---|
85 | test_007 ( ncfile ); |
---|
86 | test_008 ( ncfile ); |
---|
87 | test_009 ( ncfile ); |
---|
88 | test_010 ( ncfile ); |
---|
89 | test_011 ( ncfile ); |
---|
90 | |
---|
91 | test_100 ( ncfile ); |
---|
92 | test_101 ( ncfile ); |
---|
93 | test_102 ( ncfile ); |
---|
94 | test_103 ( ncfile ); |
---|
95 | test_104 ( ncfile ); |
---|
96 | test_105 ( ncfile ); |
---|
97 | |
---|
98 | test_106 ( ncfile ); |
---|
99 | test_107 ( ncfile ); |
---|
100 | test_108 ( ncfile ); |
---|
101 | test_109 ( ncfile ); |
---|
102 | |
---|
103 | |
---|
104 | test_200 ( ncfile ); |
---|
105 | test_201 ( ncfile ); |
---|
106 | test_202 ( ncfile ); |
---|
107 | test_203 ( ncfile ); |
---|
108 | |
---|
109 | test_204 ( ncfile ); |
---|
110 | test_205 ( ncfile ); |
---|
111 | test_206 ( ncfile ); |
---|
112 | |
---|
113 | test_207 ( ncfile ); |
---|
114 | test_208 ( ncfile ); |
---|
115 | test_209 ( ncfile ); |
---|
116 | |
---|
117 | |
---|
118 | test_301 ( ncfile ); |
---|
119 | test_302 ( ncfile ); |
---|
120 | test_303 ( ncfile ); |
---|
121 | test_304 ( ncfile ); |
---|
122 | test_305 ( ncfile ); |
---|
123 | test_306 ( ncfile ); |
---|
124 | test_307 ( ncfile ); |
---|
125 | |
---|
126 | return |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | function create_test_file ( ncfile, arg2 ) |
---|
133 | |
---|
134 | if snctools_use_tmw |
---|
135 | % |
---|
136 | % ok, first create the first file |
---|
137 | ncid_1 = netcdf.create(ncfile, nc_clobber_mode ); |
---|
138 | |
---|
139 | |
---|
140 | % |
---|
141 | % Create a fixed dimension. |
---|
142 | len_x = 4; |
---|
143 | xdimid = netcdf.defDim(ncid_1, 'x', len_x ); |
---|
144 | |
---|
145 | % |
---|
146 | % Create a fixed dimension. |
---|
147 | len_y = 6; |
---|
148 | ydimid = netcdf.defDim(ncid_1, 'y', len_y ); |
---|
149 | |
---|
150 | netcdf.close(ncid_1); |
---|
151 | elseif snctools_use_mexnc |
---|
152 | % |
---|
153 | % ok, first create the first file |
---|
154 | [ncid_1, status] = mexnc ( 'create', ncfile, nc_clobber_mode ); |
---|
155 | if ( status ~= 0 ) |
---|
156 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
157 | msg = sprintf ( '%s: ''create'' failed, error message '' %s ''\n', mfilename, ncerr_msg ); |
---|
158 | error ( msg ); |
---|
159 | end |
---|
160 | |
---|
161 | |
---|
162 | % |
---|
163 | % Create a fixed dimension. |
---|
164 | len_x = 4; |
---|
165 | [xdimid, status] = mexnc ( 'def_dim', ncid_1, 'x', len_x ); |
---|
166 | if ( status ~= 0 ) |
---|
167 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
168 | msg = sprintf ( '%s: ''def_dim'' failed on dim x, file %s, error message '' %s ''\n', mfilename, ncfile, ncerr_msg ); |
---|
169 | error ( msg ); |
---|
170 | end |
---|
171 | |
---|
172 | % |
---|
173 | % Create a fixed dimension. |
---|
174 | len_y = 6; |
---|
175 | [ydimid, status] = mexnc ( 'def_dim', ncid_1, 'y', len_y ); |
---|
176 | if ( status ~= 0 ) |
---|
177 | ncerr_msg = mexnc ( 'strerror', status ); |
---|
178 | msg = sprintf ( '%s: ''def_dim'' failed on dim y, file %s, error message '' %s ''\n', mfilename, ncfile, ncerr_msg ); |
---|
179 | error ( msg ); |
---|
180 | end |
---|
181 | |
---|
182 | |
---|
183 | % |
---|
184 | % CLOSE |
---|
185 | status = mexnc ( 'close', ncid_1 ); |
---|
186 | if ( status ~= 0 ) |
---|
187 | error ( 'CLOSE failed' ); |
---|
188 | end |
---|
189 | else |
---|
190 | error('No mexnc or native matlab support, this test cannot be run.'); |
---|
191 | end |
---|
192 | |
---|
193 | % |
---|
194 | % Add a singleton |
---|
195 | varstruct.Name = 'test_singleton'; |
---|
196 | varstruct.Nctype = 'double'; |
---|
197 | varstruct.Dimension = []; |
---|
198 | |
---|
199 | nc_addvar ( ncfile, varstruct ); |
---|
200 | |
---|
201 | |
---|
202 | clear varstruct; |
---|
203 | varstruct.Name = 'test_1D'; |
---|
204 | varstruct.Nctype = 'double'; |
---|
205 | varstruct.Dimension = { 'y' }; |
---|
206 | |
---|
207 | nc_addvar ( ncfile, varstruct ); |
---|
208 | |
---|
209 | |
---|
210 | clear varstruct; |
---|
211 | varstruct.Name = 'test_2D'; |
---|
212 | varstruct.Nctype = 'double'; |
---|
213 | if getpref('SNCTOOLS','PRESERVE_FVD',false) |
---|
214 | varstruct.Dimension = { 'x', 'y' }; |
---|
215 | else |
---|
216 | varstruct.Dimension = { 'y', 'x' }; |
---|
217 | end |
---|
218 | |
---|
219 | nc_addvar ( ncfile, varstruct ); |
---|
220 | |
---|
221 | |
---|
222 | clear varstruct; |
---|
223 | varstruct.Name = 'test_2D_float'; |
---|
224 | varstruct.Nctype = 'float'; |
---|
225 | if getpref('SNCTOOLS','PRESERVE_FVD',false) |
---|
226 | varstruct.Dimension = { 'x', 'y' }; |
---|
227 | else |
---|
228 | varstruct.Dimension = { 'y', 'x' }; |
---|
229 | end |
---|
230 | |
---|
231 | nc_addvar ( ncfile, varstruct ); |
---|
232 | |
---|
233 | |
---|
234 | clear varstruct; |
---|
235 | varstruct.Name = 'test_var3'; |
---|
236 | varstruct.Nctype = 'double'; |
---|
237 | varstruct.Dimension = { 'x' }; |
---|
238 | |
---|
239 | nc_addvar ( ncfile, varstruct ); |
---|
240 | return |
---|
241 | |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | function test_001 ( ncfile ) |
---|
254 | |
---|
255 | try |
---|
256 | nc_varput; |
---|
257 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
258 | error ( msg ); |
---|
259 | end |
---|
260 | |
---|
261 | return |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | function test_002 ( ncfile ) |
---|
266 | try |
---|
267 | nc_varput ( ncfile ); |
---|
268 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
269 | error ( msg ); |
---|
270 | end |
---|
271 | return |
---|
272 | |
---|
273 | |
---|
274 | function test_003 ( ncfile ) |
---|
275 | |
---|
276 | try |
---|
277 | nc_varput ( ncfile, 'test_2d' ); |
---|
278 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
279 | error ( msg ); |
---|
280 | end |
---|
281 | |
---|
282 | return |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | |
---|
292 | |
---|
293 | |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | function test_106 ( ncfile ) |
---|
303 | |
---|
304 | input_data = [3.14159; 2]; |
---|
305 | nc_varput ( ncfile, 'test_1D', input_data, 0, 2, 2 ); |
---|
306 | output_data = nc_varget ( ncfile, 'test_1D', 0, 2, 2 ); |
---|
307 | |
---|
308 | ddiff = abs(input_data - output_data); |
---|
309 | if any( find(ddiff > eps) ) |
---|
310 | msg = sprintf ( '%s: input data ~= output data.\n', mfilename ); |
---|
311 | error ( msg ); |
---|
312 | end |
---|
313 | |
---|
314 | return |
---|
315 | |
---|
316 | |
---|
317 | |
---|
318 | |
---|
319 | function test_004 ( ncfile ) |
---|
320 | |
---|
321 | try |
---|
322 | nc_varput ( ncfile, 'test_2d' ); |
---|
323 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
324 | error ( msg ); |
---|
325 | end |
---|
326 | |
---|
327 | return |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | |
---|
334 | function test_005 ( ncfile ) |
---|
335 | |
---|
336 | try |
---|
337 | nc_varput ( ncfile, 'bad', 5 ); |
---|
338 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
339 | error ( msg ); |
---|
340 | end |
---|
341 | |
---|
342 | return |
---|
343 | |
---|
344 | |
---|
345 | |
---|
346 | |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | function test_006 ( ncfile ) |
---|
351 | |
---|
352 | try |
---|
353 | nc_varput ( ncfile, 'test_singleton', [2 1] ); |
---|
354 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
355 | error ( msg ); |
---|
356 | end |
---|
357 | |
---|
358 | return |
---|
359 | |
---|
360 | |
---|
361 | |
---|
362 | |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | function test_007 ( ncfile ) |
---|
367 | |
---|
368 | try |
---|
369 | nc_varput ( ncfile, 'test_2D', ones(7,4) ); |
---|
370 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
371 | error ( msg ); |
---|
372 | end |
---|
373 | |
---|
374 | return |
---|
375 | |
---|
376 | |
---|
377 | |
---|
378 | |
---|
379 | |
---|
380 | |
---|
381 | function test_008 ( ncfile ) |
---|
382 | |
---|
383 | try |
---|
384 | nc_varput ( ncfile, 'test_2D', ones(3,4), [0 0], [3 3] ); |
---|
385 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
386 | error ( msg ); |
---|
387 | end |
---|
388 | |
---|
389 | return |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | function test_009 ( ncfile ) |
---|
397 | |
---|
398 | try |
---|
399 | nc_varput ( ncfile, 'test_2D', ones(3,2), [0 0], [3 2], [2 2] ); |
---|
400 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
401 | error ( msg ); |
---|
402 | end |
---|
403 | |
---|
404 | return |
---|
405 | |
---|
406 | |
---|
407 | |
---|
408 | |
---|
409 | |
---|
410 | |
---|
411 | function test_010 ( ncfile ) |
---|
412 | |
---|
413 | try |
---|
414 | nc_varput ( ncfile, 'test_2D', ones(6,4), [0 0], [6 4 1] ); |
---|
415 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
416 | error ( msg ); |
---|
417 | end |
---|
418 | |
---|
419 | return |
---|
420 | |
---|
421 | |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | |
---|
426 | function test_011 ( ncfile ) |
---|
427 | |
---|
428 | try |
---|
429 | nc_varput ( ncfile, 'test_2D', ones(3,2), [0 0], [3 2], [2 2 1] ); |
---|
430 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
431 | error ( msg ); |
---|
432 | end |
---|
433 | |
---|
434 | return |
---|
435 | |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | |
---|
440 | |
---|
441 | function test_012 ( ncfile ) |
---|
442 | |
---|
443 | try |
---|
444 | nc_varput ( ncfile, 'test_2D', ones(3,2), [0 0 0], [3 2 1], [2 2 1] ); |
---|
445 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
446 | error ( msg ); |
---|
447 | end |
---|
448 | |
---|
449 | return |
---|
450 | |
---|
451 | |
---|
452 | |
---|
453 | |
---|
454 | |
---|
455 | function test_013 ( ncfile ) |
---|
456 | |
---|
457 | try |
---|
458 | nc_varput ( ncfile, 'test_2D', ones(6,4), [1 0], [6 4] ); |
---|
459 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
460 | error ( msg ); |
---|
461 | end |
---|
462 | |
---|
463 | return |
---|
464 | |
---|
465 | |
---|
466 | |
---|
467 | |
---|
468 | |
---|
469 | |
---|
470 | function test_021 ( ncfile ) |
---|
471 | |
---|
472 | try |
---|
473 | nc_varput ( ncfile, 'test_2D', ones(3,2), [0 0 0], [3 2], [2 2 1] ); |
---|
474 | msg = sprintf ( '%s: test failed, ''%s''.\n', mfilename, lasterr ); |
---|
475 | error ( msg ); |
---|
476 | end |
---|
477 | |
---|
478 | return |
---|
479 | |
---|
480 | |
---|
481 | |
---|
482 | |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | function test_100 ( ncfile ) |
---|
487 | |
---|
488 | |
---|
489 | input_data = 3.14159; |
---|
490 | nc_varput ( ncfile, 'test_singleton', input_data ); |
---|
491 | output_data = nc_varget ( ncfile, 'test_singleton' ); |
---|
492 | |
---|
493 | ddiff = abs(input_data - output_data); |
---|
494 | if any( find(ddiff > eps) ) |
---|
495 | msg = sprintf ( '%s: input data ~= output data.\n', mfilename ); |
---|
496 | error ( msg ); |
---|
497 | end |
---|
498 | |
---|
499 | return |
---|
500 | |
---|
501 | |
---|
502 | |
---|
503 | |
---|
504 | function test_101 ( ncfile ) |
---|
505 | |
---|
506 | input_data = 3.14159; |
---|
507 | try |
---|
508 | nc_varput ( ncfile, 'test_1D', input_data, 8 ); |
---|
509 | msg = sprintf ( '%s: nc_varput succeeded when it should have failed.\n', mfilename ); |
---|
510 | error ( msg ); |
---|
511 | end |
---|
512 | |
---|
513 | return |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | |
---|
518 | function test_102 ( ncfile ) |
---|
519 | |
---|
520 | input_data = 3.14159; |
---|
521 | try |
---|
522 | nc_varput ( ncfile, 'test_1D', input_data, 4, 2 ); |
---|
523 | msg = sprintf ( '%s: nc_varput succeeded in when it should have failed.\n', mfilename ); |
---|
524 | error ( msg ); |
---|
525 | end |
---|
526 | |
---|
527 | return |
---|
528 | |
---|
529 | |
---|
530 | |
---|
531 | |
---|
532 | |
---|
533 | |
---|
534 | |
---|
535 | function test_103 ( ncfile ) |
---|
536 | |
---|
537 | input_data = 3.14159; |
---|
538 | nc_varput ( ncfile, 'test_1D', input_data, 0, 1 ); |
---|
539 | output_data = nc_varget ( ncfile, 'test_1D', 0, 1 ); |
---|
540 | |
---|
541 | ddiff = abs(input_data - output_data); |
---|
542 | if any( find(ddiff > eps) ) |
---|
543 | msg = sprintf ( '%s: input data ~= output data.\n', mfilename ); |
---|
544 | error ( msg ); |
---|
545 | end |
---|
546 | |
---|
547 | return |
---|
548 | |
---|
549 | |
---|
550 | |
---|
551 | |
---|
552 | function test_104 ( ncfile ) |
---|
553 | |
---|
554 | input_data = [3.14159; 2]; |
---|
555 | try |
---|
556 | nc_varput ( ncfile, 'test_1D', input_data, 0, 2, 8 ); |
---|
557 | msg = sprintf ( '%s: nc_varput succeeded when it should have failed.\n', mfilename ); |
---|
558 | error ( msg ); |
---|
559 | end |
---|
560 | |
---|
561 | |
---|
562 | return |
---|
563 | |
---|
564 | |
---|
565 | |
---|
566 | |
---|
567 | |
---|
568 | function test_105 ( ncfile ) |
---|
569 | |
---|
570 | input_data = [3.14159 2]; |
---|
571 | try |
---|
572 | nc_varput ( ncfile, 'test_singleton', input_data ); |
---|
573 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
574 | error ( msg ); |
---|
575 | end |
---|
576 | |
---|
577 | return |
---|
578 | |
---|
579 | |
---|
580 | |
---|
581 | |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | function test_107 ( ncfile ) |
---|
586 | |
---|
587 | input_data = 3.14159; |
---|
588 | try |
---|
589 | nc_varput ( ncfile, 'test_singleton', input_data, 4, 1 ); |
---|
590 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
591 | error ( msg ); |
---|
592 | end |
---|
593 | |
---|
594 | return |
---|
595 | |
---|
596 | |
---|
597 | |
---|
598 | |
---|
599 | |
---|
600 | function test_108 ( ncfile ) |
---|
601 | |
---|
602 | input_data = 3.14159; |
---|
603 | try |
---|
604 | nc_varput ( ncfile, 'test_singleton', input_data, 0, 2 ); |
---|
605 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
606 | error ( msg ); |
---|
607 | end |
---|
608 | |
---|
609 | return |
---|
610 | |
---|
611 | |
---|
612 | |
---|
613 | |
---|
614 | |
---|
615 | |
---|
616 | |
---|
617 | |
---|
618 | function test_109 ( ncfile ) |
---|
619 | |
---|
620 | input_data = 3.14159; |
---|
621 | try |
---|
622 | nc_varput ( ncfile, 'test_singleton', input_data, 0, 1, 1 ); |
---|
623 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
624 | error ( msg ); |
---|
625 | end |
---|
626 | |
---|
627 | return |
---|
628 | |
---|
629 | |
---|
630 | |
---|
631 | |
---|
632 | |
---|
633 | |
---|
634 | |
---|
635 | function test_200 ( ncfile ) |
---|
636 | |
---|
637 | input_data = [1:24]; |
---|
638 | |
---|
639 | count = nc_varsize(ncfile,'test_2D'); |
---|
640 | input_data = reshape(input_data,count); |
---|
641 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
642 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
643 | |
---|
644 | ddiff = abs(input_data - output_data); |
---|
645 | if any( find(ddiff > eps) ) |
---|
646 | msg = sprintf ( '%s: input data ~= output data \n', mfilename ); |
---|
647 | error ( msg ); |
---|
648 | end |
---|
649 | |
---|
650 | return |
---|
651 | |
---|
652 | |
---|
653 | |
---|
654 | |
---|
655 | |
---|
656 | |
---|
657 | |
---|
658 | function test_201 ( ncfile ) |
---|
659 | |
---|
660 | sz = nc_varsize(ncfile,'test_2D'); |
---|
661 | start = [0 0]; |
---|
662 | count = sz-1; |
---|
663 | |
---|
664 | input_data = [1:prod(count)]; |
---|
665 | |
---|
666 | input_data = reshape(input_data,count); |
---|
667 | nc_varput ( ncfile, 'test_2D', input_data, start, count ); |
---|
668 | output_data = nc_varget ( ncfile, 'test_2D', start, count ); |
---|
669 | |
---|
670 | ddiff = abs(input_data - output_data); |
---|
671 | if any( find(ddiff > eps) ) |
---|
672 | msg = sprintf ( '%s: input data ~= output data .\n', mfilename ); |
---|
673 | error ( msg ); |
---|
674 | end |
---|
675 | |
---|
676 | return |
---|
677 | |
---|
678 | |
---|
679 | |
---|
680 | |
---|
681 | |
---|
682 | function test_202 ( ncfile ) |
---|
683 | |
---|
684 | sz = nc_varsize(ncfile,'test_2D'); |
---|
685 | start = [1 1]; |
---|
686 | count = sz-1; |
---|
687 | |
---|
688 | input_data = [1:prod(count)] - 5; |
---|
689 | input_data = reshape(input_data,count); |
---|
690 | |
---|
691 | nc_varput ( ncfile, 'test_2D', input_data, start, count ); |
---|
692 | output_data = nc_varget ( ncfile, 'test_2D', start, count ); |
---|
693 | |
---|
694 | ddiff = abs(input_data - output_data); |
---|
695 | if any( find(ddiff > eps) ) |
---|
696 | msg = sprintf ( '%s: input data ~= output data .\n', mfilename ); |
---|
697 | error ( msg ); |
---|
698 | end |
---|
699 | |
---|
700 | |
---|
701 | return |
---|
702 | |
---|
703 | |
---|
704 | |
---|
705 | |
---|
706 | |
---|
707 | |
---|
708 | |
---|
709 | |
---|
710 | |
---|
711 | |
---|
712 | |
---|
713 | |
---|
714 | function test_203 ( ncfile ) |
---|
715 | |
---|
716 | sz = nc_varsize(ncfile,'test_2D'); |
---|
717 | start = [0 0]; |
---|
718 | count = sz/2; |
---|
719 | stride = [2 2]; |
---|
720 | |
---|
721 | input_data = [1:prod(count)]; |
---|
722 | |
---|
723 | input_data = reshape(input_data,count); |
---|
724 | nc_varput ( ncfile, 'test_2D', input_data, start, count, stride ); |
---|
725 | output_data = nc_varget ( ncfile, 'test_2D', start, count, stride ); |
---|
726 | |
---|
727 | ddiff = abs(input_data - output_data); |
---|
728 | if any( find(ddiff > eps) ) |
---|
729 | msg = sprintf ( '%s: input data ~= output data.\n', mfilename ); |
---|
730 | error ( msg ); |
---|
731 | end |
---|
732 | |
---|
733 | return |
---|
734 | |
---|
735 | |
---|
736 | |
---|
737 | |
---|
738 | |
---|
739 | |
---|
740 | |
---|
741 | |
---|
742 | function test_204 ( ncfile ) |
---|
743 | |
---|
744 | input_data = [1:49]; |
---|
745 | input_data = reshape(input_data,7,7); |
---|
746 | try |
---|
747 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
748 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
749 | error ( msg ); |
---|
750 | end |
---|
751 | |
---|
752 | |
---|
753 | return |
---|
754 | |
---|
755 | |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | |
---|
760 | function test_205 ( ncfile ) |
---|
761 | |
---|
762 | sz = nc_varsize(ncfile,'test_2D'); |
---|
763 | start = [0 0]; |
---|
764 | count = sz-1; |
---|
765 | |
---|
766 | input_data = [1:prod(count)]; |
---|
767 | input_data = reshape(input_data,count); |
---|
768 | try |
---|
769 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
770 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
771 | error ( msg ); |
---|
772 | end |
---|
773 | |
---|
774 | return |
---|
775 | |
---|
776 | |
---|
777 | |
---|
778 | |
---|
779 | |
---|
780 | |
---|
781 | function test_206 ( ncfile ) |
---|
782 | % write with a bad offset |
---|
783 | |
---|
784 | sz = nc_varsize(ncfile,'test_2D'); |
---|
785 | start = [1 1]; |
---|
786 | count = sz; |
---|
787 | |
---|
788 | input_data = [1:prod(count)]; |
---|
789 | input_data = reshape(input_data,count); |
---|
790 | try |
---|
791 | nc_varput ( ncfile, 'test_2D', input_data, start, count ); |
---|
792 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
793 | error ( msg ); |
---|
794 | end |
---|
795 | return |
---|
796 | |
---|
797 | |
---|
798 | |
---|
799 | |
---|
800 | |
---|
801 | |
---|
802 | |
---|
803 | |
---|
804 | function test_207 ( ncfile ) |
---|
805 | % write using put_vars with a bad offset |
---|
806 | |
---|
807 | sz = nc_varsize(ncfile,'test_2D'); |
---|
808 | start = [1 1]; |
---|
809 | count = sz/2; |
---|
810 | stride = [2 2]; |
---|
811 | |
---|
812 | input_data = [1:prod(count)] + 3.14159; |
---|
813 | input_data = reshape(input_data,count); |
---|
814 | |
---|
815 | try |
---|
816 | nc_varput ( ncfile, 'test_2D', input_data, start, count, stride); |
---|
817 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
818 | error ( msg ); |
---|
819 | end |
---|
820 | return |
---|
821 | |
---|
822 | |
---|
823 | |
---|
824 | |
---|
825 | |
---|
826 | |
---|
827 | function test_208 ( ncfile ) |
---|
828 | % vara with bad count |
---|
829 | sz = nc_varsize(ncfile,'test_2D'); |
---|
830 | start = [0 0]; |
---|
831 | count = sz+1; |
---|
832 | |
---|
833 | input_data = [1:prod(count)] + 3.14159; |
---|
834 | input_data = reshape(input_data,count); |
---|
835 | try |
---|
836 | nc_varput ( ncfile, 'test_2D', input_data, start, count ); |
---|
837 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
838 | error ( msg ); |
---|
839 | end |
---|
840 | return |
---|
841 | |
---|
842 | |
---|
843 | |
---|
844 | |
---|
845 | |
---|
846 | |
---|
847 | function test_209 ( ncfile ) |
---|
848 | |
---|
849 | sz = nc_varsize(ncfile,'test_2D'); |
---|
850 | start = [0 0]; |
---|
851 | count = sz/2; |
---|
852 | stride = [3 3]; |
---|
853 | |
---|
854 | input_data = [1:prod(count)] + 3.14159; |
---|
855 | input_data = reshape(input_data,count); |
---|
856 | try |
---|
857 | nc_varput ( ncfile, 'test_2D', input_data, start, count, stride); |
---|
858 | msg = sprintf ( '%s: nc_varput succeeded when it should not have.\n', mfilename ); |
---|
859 | error ( msg ); |
---|
860 | end |
---|
861 | return |
---|
862 | |
---|
863 | |
---|
864 | |
---|
865 | |
---|
866 | |
---|
867 | function test_301 ( ncfile ) |
---|
868 | |
---|
869 | % |
---|
870 | % Write some data, then put a scale factor of 2 and add offset of 1. The |
---|
871 | % data read back should be twice as large plus 1. |
---|
872 | create_test_file ( ncfile ); |
---|
873 | |
---|
874 | sz = nc_varsize(ncfile,'test_2D'); |
---|
875 | start = [0 0]; |
---|
876 | count = sz; |
---|
877 | input_data = [1:prod(count)]; |
---|
878 | input_data = reshape(input_data,count); |
---|
879 | |
---|
880 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
881 | nc_attput ( ncfile, 'test_2D', 'scale_factor', 2.0 ); |
---|
882 | nc_attput ( ncfile, 'test_2D', 'add_offset', 1.0 ); |
---|
883 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
884 | |
---|
885 | ddiff = abs(input_data - (output_data-1)/2); |
---|
886 | if any( find(ddiff > eps) ) |
---|
887 | msg = sprintf ( '%s: input data ~= output data in Test 13.\n', mfilename ); |
---|
888 | error ( msg ); |
---|
889 | end |
---|
890 | return |
---|
891 | |
---|
892 | |
---|
893 | |
---|
894 | |
---|
895 | |
---|
896 | function test_302 ( ncfile ) |
---|
897 | % |
---|
898 | % Put a scale factor of 2 and add offset of 1. |
---|
899 | % Write some data, |
---|
900 | % Put a scale factor of 4 and add offset of 2. |
---|
901 | % data read back should be twice as large |
---|
902 | create_test_file ( ncfile ); |
---|
903 | |
---|
904 | sz = nc_varsize(ncfile,'test_2D'); |
---|
905 | start = [0 0]; |
---|
906 | count = sz; |
---|
907 | input_data = [1:prod(count)]; |
---|
908 | input_data = reshape(input_data,count); |
---|
909 | |
---|
910 | |
---|
911 | nc_attput ( ncfile, 'test_2D', 'scale_factor', 2.0 ); |
---|
912 | nc_attput ( ncfile, 'test_2D', 'add_offset', 1.0 ); |
---|
913 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
914 | nc_attput ( ncfile, 'test_2D', 'scale_factor', 4.0 ); |
---|
915 | nc_attput ( ncfile, 'test_2D', 'add_offset', 2.0 ); |
---|
916 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
917 | ddiff = abs(input_data - (output_data)/2); |
---|
918 | if any( find(ddiff > eps) ) |
---|
919 | msg = sprintf ( '%s: input data ~= output data .\n', mfilename ); |
---|
920 | error ( msg ); |
---|
921 | end |
---|
922 | return |
---|
923 | |
---|
924 | |
---|
925 | |
---|
926 | |
---|
927 | |
---|
928 | |
---|
929 | |
---|
930 | |
---|
931 | |
---|
932 | function test_303 ( ncfile ) |
---|
933 | % |
---|
934 | % Put a scale factor of 2 and no add offset. |
---|
935 | % Write some data. |
---|
936 | create_test_file ( ncfile ); |
---|
937 | |
---|
938 | sz = nc_varsize(ncfile,'test_2D'); |
---|
939 | start = [0 0]; |
---|
940 | count = sz; |
---|
941 | input_data = [1:prod(count)]; |
---|
942 | input_data = reshape(input_data,count); |
---|
943 | |
---|
944 | |
---|
945 | nc_attput ( ncfile, 'test_2D', 'scale_factor', 2.0 ); |
---|
946 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
947 | |
---|
948 | % |
---|
949 | % Now change the scale_factor, doubling it. |
---|
950 | nc_attput ( ncfile, 'test_2D', 'scale_factor', 4.0 ); |
---|
951 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
952 | |
---|
953 | if output_data(1) ~= 2 |
---|
954 | msg = sprintf ( '%s: input data ~= output data .\n', mfilename ); |
---|
955 | error ( msg ); |
---|
956 | end |
---|
957 | return |
---|
958 | |
---|
959 | |
---|
960 | |
---|
961 | |
---|
962 | |
---|
963 | |
---|
964 | |
---|
965 | |
---|
966 | function test_304 ( ncfile ) |
---|
967 | |
---|
968 | create_test_file ( ncfile ); |
---|
969 | |
---|
970 | sz = nc_varsize(ncfile,'test_2D'); |
---|
971 | start = [0 0]; |
---|
972 | count = sz; |
---|
973 | input_data = [1:prod(count)]; |
---|
974 | input_data = reshape(input_data,count); |
---|
975 | |
---|
976 | |
---|
977 | input_data(1,1) = NaN; |
---|
978 | |
---|
979 | nc_attput ( ncfile, 'test_2D', '_FillValue', -1 ); |
---|
980 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
981 | |
---|
982 | % |
---|
983 | % Now change the _FillValue, to -2. |
---|
984 | nc_attput ( ncfile, 'test_2D', '_FillValue', -2 ); |
---|
985 | |
---|
986 | % |
---|
987 | % Now read the data back. Should have a -1 in position (1,1). |
---|
988 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
989 | |
---|
990 | if output_data(1) ~= -1 |
---|
991 | msg = sprintf ( '%s: input data ~= output data .\n', mfilename ); |
---|
992 | error ( msg ); |
---|
993 | end |
---|
994 | return |
---|
995 | |
---|
996 | |
---|
997 | |
---|
998 | |
---|
999 | |
---|
1000 | |
---|
1001 | |
---|
1002 | |
---|
1003 | |
---|
1004 | function test_305 ( ncfile ) |
---|
1005 | |
---|
1006 | create_test_file ( ncfile ); |
---|
1007 | |
---|
1008 | sz = nc_varsize(ncfile,'test_2D'); |
---|
1009 | start = [0 0]; |
---|
1010 | count = sz; |
---|
1011 | input_data = [1:prod(count)]; |
---|
1012 | input_data = reshape(input_data,count); |
---|
1013 | |
---|
1014 | |
---|
1015 | input_data(1,1) = NaN; |
---|
1016 | |
---|
1017 | nc_attput ( ncfile, 'test_2D', 'missing_value', -1 ); |
---|
1018 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
1019 | |
---|
1020 | % |
---|
1021 | % Now change the _FillValue, to -2. |
---|
1022 | nc_attput ( ncfile, 'test_2D', '_FillValue', -2 ); |
---|
1023 | |
---|
1024 | % |
---|
1025 | % Now read the data back. Should have a NaN in position (1,1). |
---|
1026 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
1027 | |
---|
1028 | if ~isnan(output_data(1,1)) |
---|
1029 | msg = sprintf ( '%s: output data is not correct.\n', mfilename ); |
---|
1030 | error ( msg ); |
---|
1031 | end |
---|
1032 | return |
---|
1033 | |
---|
1034 | |
---|
1035 | |
---|
1036 | |
---|
1037 | |
---|
1038 | |
---|
1039 | % Read from a single precision dataset with a single precision scale factor. |
---|
1040 | % Should still produce single precision. |
---|
1041 | function test_306 ( ncfile ) |
---|
1042 | |
---|
1043 | % |
---|
1044 | % Write some data, then put a scale factor of 2 and add offset of 1. The |
---|
1045 | % data read back should be twice as large plus 1. |
---|
1046 | create_test_file ( ncfile ); |
---|
1047 | |
---|
1048 | sz = nc_varsize(ncfile,'test_2D'); |
---|
1049 | start = [0 0]; |
---|
1050 | count = sz; |
---|
1051 | input_data = rand(1,prod(count)); |
---|
1052 | input_data = reshape(input_data,count); |
---|
1053 | |
---|
1054 | |
---|
1055 | scale_factor = single(0.5); |
---|
1056 | add_offset = single(1.0); |
---|
1057 | nc_attput ( ncfile, 'test_2D_float', 'scale_factor', scale_factor ); |
---|
1058 | nc_attput ( ncfile, 'test_2D_float', 'add_offset', add_offset ); |
---|
1059 | nc_varput ( ncfile, 'test_2D_float', input_data ); |
---|
1060 | output_data = nc_varget ( ncfile, 'test_2D_float' ); |
---|
1061 | |
---|
1062 | ddiff = abs(input_data - output_data); |
---|
1063 | if any( find(ddiff > 1e-6) ) |
---|
1064 | msg = sprintf ( 'input data ~= output data.\n' ); |
---|
1065 | error ( msg ); |
---|
1066 | end |
---|
1067 | |
---|
1068 | return |
---|
1069 | |
---|
1070 | |
---|
1071 | % |
---|
1072 | % Test a fill value / missing value conflict. The fill value should take precedence. |
---|
1073 | function test_307 ( ncfile ) |
---|
1074 | |
---|
1075 | create_test_file ( ncfile ); |
---|
1076 | |
---|
1077 | sz = nc_varsize(ncfile,'test_2D'); |
---|
1078 | start = [0 0]; |
---|
1079 | count = sz; |
---|
1080 | input_data = [1:prod(count)]; |
---|
1081 | input_data = reshape(input_data,count); |
---|
1082 | |
---|
1083 | |
---|
1084 | input_data(1,1) = NaN; |
---|
1085 | |
---|
1086 | nc_attput ( ncfile, 'test_2D', '_FillValue', -1 ); |
---|
1087 | nc_attput ( ncfile, 'test_2D', 'missing_value', -1 ); |
---|
1088 | nc_varput ( ncfile, 'test_2D', input_data ); |
---|
1089 | |
---|
1090 | |
---|
1091 | % |
---|
1092 | % Now read the data back. Should have a NaN in position (1,1). |
---|
1093 | output_data = nc_varget ( ncfile, 'test_2D' ); |
---|
1094 | |
---|
1095 | if ~isnan(output_data(1,1)) |
---|
1096 | msg = sprintf ( '%s: output data is not correct.\n', mfilename ); |
---|
1097 | error ( msg ); |
---|
1098 | end |
---|
1099 | return |
---|
1100 | |
---|
1101 | |
---|
1102 | |
---|
1103 | |
---|
1104 | |
---|
1105 | |
---|