-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathtest_put.m4
1551 lines (1387 loc) · 50.3 KB
/
test_put.m4
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
dnl This is m4 source.
dnl Process using m4 to produce 'C' language file.
dnl
dnl This file is supposed to be the same as PnetCDF's test_put.m4
dnl
dnl If you see this line, you can ignore the next one.
/* Do not edit this file. It is produced from the corresponding .m4 source */
dnl
/*
* Copyright (C) 2003, Northwestern University and Argonne National Laboratory
* See COPYRIGHT notice in top-level directory.
*/
/* $Id: test_put.m4 2672 2016-12-03 19:23:53Z wkliao $ */
dnl
dnl The command-line m4 macro "PNETCDF" is to differentiate PnetCDF and netCDF
dnl in terms of function prefix names (ncmpi_ vs. nc_), integer data types
dnl (MPI_Offset vs. size_t), and function name substrings for external data
dnl types.
dnl
#include "tests.h"
ifdef(`PNETCDF',,`dnl
#ifdef USE_PNETCDF
#include <pnetcdf.h>
#ifndef PNETCDF_VERSION_MAJOR
#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h")
#endif
#ifndef PNETCDF_VERSION_MINOR
#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h")
#endif
#endif')
define(`EXPECT_ERR',`error("expecting $1 but got %s",nc_err_code_name($2));')dnl
define(`IntType', `ifdef(`PNETCDF',`MPI_Offset',`size_t')')dnl
define(`PTRDType',`ifdef(`PNETCDF',`MPI_Offset',`ptrdiff_t')')dnl
define(`TestFunc',`ifdef(`PNETCDF',`test_ncmpi_put_$1',`test_nc_put_$1')')dnl
define(`APIFunc',` ifdef(`PNETCDF',`ncmpi_$1',`nc_$1')')dnl
define(`FileOpen', `ifdef(`PNETCDF',`ncmpi_open(comm, $1, $2, info, &ncid)', `file_open($1, $2, &ncid)')')dnl
define(`FileCreate',`ifdef(`PNETCDF',`ncmpi_create(comm, $1, $2, info, &ncid)', `file_create($1, $2, &ncid)')')dnl
define(`FileDelete',`ifdef(`PNETCDF',`ncmpi_delete($1,$2)',`nc_delete($1)')')dnl
define(`VarArgs', `ifdef(`PNETCDF',`int numVars',`void')')dnl
define(`AttVarArgs',`ifdef(`PNETCDF',`int numGatts,int numVars',`void')')dnl
define(`PutVar1',`ifdef(`PNETCDF',`ncmpi_put_var1_$1_all',`nc_put_var1_$1')')dnl
define(`PutVar', `ifdef(`PNETCDF',`ncmpi_put_var_$1_all', `nc_put_var_$1')')dnl
define(`PutVara',`ifdef(`PNETCDF',`ncmpi_put_vara_$1_all',`nc_put_vara_$1')')dnl
define(`PutVars',`ifdef(`PNETCDF',`ncmpi_put_vars_$1_all',`nc_put_vars_$1')')dnl
define(`PutVarm',`ifdef(`PNETCDF',`ncmpi_put_varm_$1_all',`nc_put_varm_$1')')dnl
define(`PutAtt', `ifdef(`PNETCDF',`ncmpi_put_att_$1',`nc_put_att_$1')')dnl
define(`GetVar1',`ifdef(`PNETCDF',`ncmpi_get_var1_$1_all',`nc_get_var1_$1')')dnl
define(`DefVars',`ifdef(`PNETCDF',`def_vars($1,$2)',`def_vars($1)')')dnl
define(`PNETCDF_CHECK_ERANGE',`dnl
ifelse(`$1',`uchar',`ifdef(`PNETCDF',,`
`#'if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8)')',
`$1',`schar',`ifdef(`PNETCDF',,`
`#'if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7
else if (cdf_format < NC_FORMAT_CDF5) {
`#'else')')
else {
ifelse(`$1',`schar',`ifdef(`PNETCDF',,``#'endif')')
IF (err != NC_ERANGE)
EXPECT_ERR(NC_ERANGE, err)
ELSE_NOK
}
ifelse(`$1',`uchar',`ifdef(`PNETCDF',,``#'endif')')'
)dnl
undefine(`index')dnl
dnl dnl dnl
dnl
dnl Macros
dnl
dnl dnl dnl
dnl
dnl Upcase(str)
dnl
define(`Upcase',dnl
`dnl
translit($1, abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ)')dnl
dnl dnl dnl
dnl
dnl NCT_ITYPE(type)
dnl
define(`NCT_ITYPE', ``NCT_'Upcase($1)')dnl
define(`NC_TYPE', ``NC_'Upcase($1)')dnl
define(`X_MIN', ``X_'Upcase($1)_MIN')dnl
define(`X_MAX', ``X_'Upcase($1)_MAX')dnl
dnl
define(`CheckText', `ifelse(`$1',`text', , `== (NCT_ITYPE($1) == NCT_TEXT)')')dnl
define(`IfCheckTextChar', `ifelse(`$1',`text', `if ($2 != NC_CHAR)')')dnl
define(`CheckNumRange',
`ifelse(`$1',`text', `1',
`inRange3(cdf_format, (double)$2,$3,NCT_ITYPE($1)) && ($2 >= $1_min && $2 <= $1_max)')')dnl
define(`CheckRange',
`ifelse(`$1',`text', `0', `($2 >= $1_min && $2 <= $1_max)')')dnl
define(`CheckRange3',
`ifelse(`$1',`text', `1',
`inRange3(cdf_format, (double)$2,$3,NCT_ITYPE($1))')')dnl
dnl HASH(TYPE)
dnl
define(`HASH',dnl
`dnl
/*
* ensure hash value within range for internal TYPE
*/
$1
hash_$1(const int cdf_format,
const nc_type type,
const int rank,
const IntType *index,
const nct_itype itype)
{
double value;
value = hash4(cdf_format, type, rank, index, itype);
ifelse(`$1',`text',`return (text)value;',`
if (value > $1_max) return $1_max;
else if (value < $1_min) return $1_min;
else return ($1)value;')
}
')dnl
HASH(text)
HASH(uchar)
HASH(schar)
HASH(short)
HASH(int)
HASH(long)
HASH(float)
HASH(double)
HASH(ushort)
HASH(uint)
HASH(longlong)
HASH(ulonglong)
dnl CHECK_VARS(TYPE)
dnl
define(`CHECK_VARS',dnl
`dnl
/*
* check all vars in file which are (text/numeric) compatible with TYPE
*/
int
check_vars_$1(const char *filename, int numVars)
{
int i, d, err, ncid, cdf_format, ndims;
int canConvert; /* Both text or both numeric */
int nok = 0; /* count of valid comparisons */
int dimids[MAX_RANK];
nc_type datatype;
char name[NC_MAX_NAME];
IntType j, length, index[MAX_RANK];
double expect;
$1 value;
err = FileOpen(filename, NC_NOWRITE);
IF (err != NC_NOERR) error("open: %s", APIFunc(strerror)(err));
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR) error("inq_format: %s", APIFunc(strerror)(err));
for (i = 0; i < numVars; i++) {
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
if (!canConvert) continue;
err = APIFunc(inq_var)(ncid, i, name, &datatype, &ndims, dimids, NULL);
IF (err != NC_NOERR)
error("inq_var: %s", APIFunc(strerror)(err));
IF (strcmp(name, var_name[i]) != 0)
error("Unexpected var_name");
IF (datatype != var_type[i])
error("Unexpected type");
IF (ndims != var_rank[i])
error("Unexpected rank");
for (j = 0; j < ndims; j++) {
err = APIFunc(inq_dim)(ncid, dimids[j], 0, &length);
IF (err != NC_NOERR)
error("inq_dim: %s", APIFunc(strerror)(err));
IF (length != var_shape[i][j])
error("Unexpected shape");
}
for (j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
expect = hash4(cdf_format, var_type[i], var_rank[i], index,
NCT_ITYPE($1));
err = GetVar1($1)(ncid, i, index, &value);
if (CheckNumRange($1, expect, datatype)) {
IF (err != NC_NOERR) {
error("GetVar1($1): %s", APIFunc(strerror)(err));
} else {
ifelse(`$1', `uchar', `
/* In put_vars(), PutVara(double)() is used to write
* variables of type NC_BYTE to files. For uchar APIs,
* NC_BYTE variables are treated as unsigned for CDF-1 and 2
* formats. Thus, we skip the equal test for out-of-bound
* values below for uchar APIs.
*/
if (cdf_format < NC_FORMAT_CDF5 &&
var_type[i] == NC_BYTE && expect > schar_max)
continue;')
IF (!equal((double)value,expect,var_type[i],NCT_ITYPE($1))){
error("Var value read not that expected");
if (verbose) {
error("\n");
error("varid: %d, ", i);
error("var_name: %s, ", var_name[i]);
error("var_type: %s, ", s_nc_type(var_type[i]));
error("index:");
for (d = 0; d < var_rank[i]; d++)
error(" %d", index[d]);
error(", expect: %g, ", expect);
error("got: %g", (double) value);
}
} else {
++nok;
}
}
}
}
}
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
return nok;
}
')dnl
CHECK_VARS(text)
CHECK_VARS(uchar)
CHECK_VARS(schar)
CHECK_VARS(short)
CHECK_VARS(int)
CHECK_VARS(long)
CHECK_VARS(float)
CHECK_VARS(double)
CHECK_VARS(ushort)
CHECK_VARS(uint)
CHECK_VARS(longlong)
CHECK_VARS(ulonglong)
dnl CHECK_ATTS(TYPE)
dnl
define(`CHECK_ATTS',dnl
`dnl
/*
* for _text tests, check all attributes in file which are of text type
* Note no NC_ERANGE check for text attributes as text is not convertible to
* any other numerical data types (i.e. NC_ECHAR)
*
* for other tests, check all numerical attributes in file against values
* outside range of type $1
*/
int
check_atts_$1(int ncid, int numGatts, int numVars)
{
int i, j, cdf_format, err;
int canConvert; /* Both text or both numeric */
int nok = 0; /* count of valid comparisons */
IntType k, length, ndx[1];
nc_type datatype;
IntType nInExtRange; /* number values within external range */
IntType nInIntRange; /* number values within internal range */
double expect[MAX_NELS];
$1 value[MAX_NELS];
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR)
error("inq_format: %s", APIFunc(strerror)(err));
for (i = -1; i < numVars; i++) {
for (j = 0; j < NATTS(i); j++) {
canConvert = (ATT_TYPE(i,j) == NC_CHAR) CheckText($1);
if (!canConvert) continue;
err = APIFunc(inq_att)(ncid, i, ATT_NAME(i,j), &datatype, &length);
IF (err != NC_NOERR)
error("inq_att: %s", APIFunc(strerror)(err));
IF (datatype != ATT_TYPE(i,j))
error("inq_att: unexpected type");
IF (length != ATT_LEN(i,j))
error("inq_att: unexpected length");
assert(length <= MAX_NELS);
nInIntRange = nInExtRange = 0;
for (k = 0; k < length; k++) {
ndx[0] = k;
expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_ITYPE($1));
if (inRange3(cdf_format, expect[k], datatype, NCT_ITYPE($1))) {
++nInExtRange;
if (CheckRange($1, expect[k]))
++nInIntRange;
}
}
err = APIFunc(get_att_$1)(ncid, i, ATT_NAME(i,j), value);
if (nInExtRange == length && nInIntRange == length) {
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
} else {
IF (err != NC_NOERR && err != NC_ERANGE)
EXPECT_ERR(NC_NOERR or NC_ERANGE, err)
}
for (k = 0; k < length; k++) {
if (CheckNumRange($1, expect[k], datatype)) {
ifelse(`$1', `uchar', `
/* In put_vars(), PutVara(double)() is used to write
* variables of type NC_BYTE to files. For uchar APIs,
* NC_BYTE variables are treated as unsigned for CDF-1 and 2
* formats. Thus, we skip the equal test for out-of-bound
* values below for uchar APIs.
*/
if (cdf_format < NC_FORMAT_CDF5 &&
ATT_TYPE(i,j) == NC_BYTE && expect[k] > schar_max)
continue;')
IF (!equal((double)value[k],expect[k],datatype,NCT_ITYPE($1))) {
error("att. value read not that expected");
if (verbose) {
error("\n");
error("varid: %d, ", i);
error("att_name: %s, ", ATT_NAME(i,j));
error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j)));
error("element number: %d ", k);
error("expect: %g, ", expect[k]);
error("got: %g", (double) value[k]);
}
} else {
nok++;
}
}
}
}
}
return nok;
}
')dnl
CHECK_ATTS(text)
CHECK_ATTS(uchar)
CHECK_ATTS(schar)
CHECK_ATTS(short)
CHECK_ATTS(int)
CHECK_ATTS(long)
CHECK_ATTS(float)
CHECK_ATTS(double)
CHECK_ATTS(ushort)
CHECK_ATTS(uint)
CHECK_ATTS(longlong)
CHECK_ATTS(ulonglong)
dnl TEST_NC_PUT_VAR1(TYPE)
dnl
define(`TEST_NC_PUT_VAR1',dnl
`dnl
int
TestFunc(var1)_$1(VarArgs)
{
int i, err, ncid, cdf_format, nok=0;
int canConvert; /* Both text or both numeric */
IntType j, index[MAX_RANK];
$1 value[1];
err = FileCreate(scratch, NC_CLOBBER);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
}
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR)
error("inq_format: %s", APIFunc(strerror)(err));
def_dims(ncid);
DefVars(ncid, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
/* check if can detect a bad file ID */
err = PutVar1($1)(BAD_ID, 0, NULL, NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVar1($1)(ncid, BAD_VARID, NULL, NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
for (i = 0; i < numVars; i++) {
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
value[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVar1($1)(BAD_ID, i, NULL, value);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVar1($1)(ncid, i, NULL, value);
if (!canConvert) {
IF (err != NC_ECHAR) EXPECT_ERR(NC_ECHAR, err)
}
else if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
ELSE_NOK
')dnl
/* test NC_EINVALCOORDS */
for (j = 0; j < var_rank[i]; j++) index[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
index[j] = var_shape[i][j]; /* out of boundary check */
err = PutVar1($1)(ncid, i, index, value);
if (!canConvert) {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
index[j] = 0;
continue;
}
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
index[j] = 0;
}
for (j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
value[0] = hash_$1(cdf_format, var_type[i], var_rank[i], index,
NCT_ITYPE($1));
err = PutVar1($1)(ncid, i, index, value);
if (canConvert) {
if (CheckRange3($1, value[0], var_type[i])) {
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
ELSE_NOK
}
PNETCDF_CHECK_ERANGE($1)
} else {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
}
}
}
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
nok += check_vars_$1(scratch, numVars);
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("delete file %s failed", scratch);
return nok;
}
')dnl
TEST_NC_PUT_VAR1(text)
TEST_NC_PUT_VAR1(uchar)
TEST_NC_PUT_VAR1(schar)
TEST_NC_PUT_VAR1(short)
TEST_NC_PUT_VAR1(int)
TEST_NC_PUT_VAR1(long)
TEST_NC_PUT_VAR1(float)
TEST_NC_PUT_VAR1(double)
TEST_NC_PUT_VAR1(ushort)
TEST_NC_PUT_VAR1(uint)
TEST_NC_PUT_VAR1(longlong)
TEST_NC_PUT_VAR1(ulonglong)
dnl TEST_NC_PUT_VAR(TYPE)
dnl
define(`TEST_NC_PUT_VAR',dnl
`dnl
int
TestFunc(var)_$1(VarArgs)
{
int i, err, ncid, varid, cdf_format, nok=0;
int canConvert; /* Both text or both numeric */
int allInExtRange; /* all values within external range? */
IntType j, index[MAX_RANK];
$1 value[MAX_NELS];
err = FileCreate(scratch, NC_CLOBBER);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
}
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR)
error("inq_format: %s", APIFunc(strerror)(err));
def_dims(ncid);
DefVars(ncid, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
/* check if can detect a bad file ID */
err = PutVar($1)(BAD_ID, 0, NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVar($1)(ncid, BAD_VARID, NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
for (i = 0; i < numVars; i++) {
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */
value[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVar($1)(BAD_ID, i, value);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
value[j]= hash_$1(cdf_format,var_type[i], var_rank[i], index,
NCT_ITYPE($1));
IfCheckTextChar($1, var_type[i])
allInExtRange &= inRange3(cdf_format, (double)value[j],
var_type[i], NCT_ITYPE($1));
}
err = PutVar($1)(ncid, i, value);
if (canConvert) {
if (allInExtRange) {
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
ELSE_NOK
}
PNETCDF_CHECK_ERANGE($1)
} else { /* should flag wrong type even if nothing to write */
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
}
}
/* Preceding has written nothing for record variables, now try */
/* again with more than 0 records */
/* Write record number NRECS to force writing of preceding records */
/* Assumes variable cr is char vector with UNLIMITED dimension */
err = APIFunc(inq_varid)(ncid, "cr", &varid);
IF (err != NC_NOERR)
error("inq_varid: %s", APIFunc(strerror)(err));
index[0] = NRECS-1;
err = PutVar1(text)(ncid, varid, index, "x");
IF (err != NC_NOERR)
error("put_var1_text: %s", APIFunc(strerror)(err));
for (i = 0; i < numVars; i++) {
if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
value[j]= hash_$1(cdf_format,var_type[i], var_rank[i], index,
NCT_ITYPE($1));
IfCheckTextChar($1, var_type[i])
allInExtRange &= inRange3(cdf_format, (double)value[j],
var_type[i], NCT_ITYPE($1));
}
err = PutVar($1)(ncid, i, value);
if (canConvert) {
if (allInExtRange) {
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
ELSE_NOK
} else {
IF (err != NC_ERANGE)
EXPECT_ERR(NC_ERANGE, err)
ELSE_NOK
}
} else {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
}
}
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
nok += check_vars_$1(scratch, numVars);
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("delete file %s failed", scratch);
return nok;
}
')dnl
TEST_NC_PUT_VAR(text)
TEST_NC_PUT_VAR(uchar)
TEST_NC_PUT_VAR(schar)
TEST_NC_PUT_VAR(short)
TEST_NC_PUT_VAR(int)
TEST_NC_PUT_VAR(long)
TEST_NC_PUT_VAR(float)
TEST_NC_PUT_VAR(double)
TEST_NC_PUT_VAR(ushort)
TEST_NC_PUT_VAR(uint)
TEST_NC_PUT_VAR(longlong)
TEST_NC_PUT_VAR(ulonglong)
dnl TEST_NC_PUT_VARA(TYPE)
dnl
define(`TEST_NC_PUT_VARA',dnl
`dnl
int
TestFunc(vara)_$1(VarArgs)
{
int i, k, d, err, nslabs, ncid, cdf_format, nok=0;
int canConvert; /* Both text or both numeric */
int allInExtRange; /* all values within external range? */
IntType j, nels;
IntType start[MAX_RANK], edge[MAX_RANK];
IntType mid[MAX_RANK], index[MAX_RANK];
$1 value[MAX_NELS];
err = FileCreate(scratch, NC_CLOBBER);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
}
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR)
error("inq_format: %s", APIFunc(strerror)(err));
def_dims(ncid);
DefVars(ncid, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
/* check if can detect a bad file ID */
err = PutVara($1)(BAD_ID, 0, NULL, NULL, NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVara($1)(ncid, BAD_VARID, NULL, NULL, NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
for (i = 0; i < numVars; i++) {
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
value[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVara($1)(BAD_ID, i, NULL, NULL, value);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
for (j = 0; j < var_rank[i]; j++) {
start[j] = 0;
edge[j] = 1;
}
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVara($1)(ncid, i, NULL, NULL, value);
if (!canConvert) {
IF (err != NC_ECHAR) EXPECT_ERR(NC_ECHAR, err)
}
else if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
ELSE_NOK
/* for non-scalar variables, argument count cannot be NULL */
err = PutVara($1)(ncid, i, start, NULL, value);
if (!canConvert) {
IF (err != NC_ECHAR) EXPECT_ERR(NC_ECHAR, err)
}
else if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EEDGE) {
EXPECT_ERR(NC_EEDGE, err)
}
ELSE_NOK
')dnl
/* first test when edge[*] > 0 */
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVara($1)(ncid, i, start, edge, value);
if (!canConvert) {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
start[j] = 0;
continue;
}
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
edge[j] = var_shape[i][j] + 1;
err = PutVara($1)(ncid, i, start, edge, value);
IF (err != NC_EEDGE)
EXPECT_ERR(NC_EEDG, err)
ELSE_NOK
edge[j] = 1;
}
/* Check correct error returned when nothing to put, when edge[*]==0 */
for (j = 0; j < var_rank[i]; j++) edge[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVara($1)(ncid, i, start, edge, value);
if (!canConvert) {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
start[j] = 0;
continue;
}
#ifdef RELAX_COORD_BOUND
IF (err != NC_NOERR) /* allowed when edge[j]==0 */
EXPECT_ERR(NC_NOERR, err)
#else
IF (err != NC_EINVALCOORDS) /* not allowed even when edge[j]==0 */
EXPECT_ERR(NC_EINVALCOORDS, err)
#endif
ELSE_NOK
start[j] = var_shape[i][j]+1; /* out of boundary check */
err = PutVara($1)(ncid, i, start, edge, value);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
}
for (j = 0; j < var_rank[i]; j++) edge[j] = 1;
/* Choose a random point dividing each dim into 2 parts */
/* Put 2^rank (nslabs) slabs so defined */
nslabs = 1;
for (j = 0; j < var_rank[i]; j++) {
mid[j] = roll( var_shape[i][j] );
nslabs *= 2;
}
/* bits of k determine whether to put lower or upper part of dim */
for (k = 0; k < nslabs; k++) {
nels = 1;
for (j = 0; j < var_rank[i]; j++) {
if ((k >> j) & 1) {
start[j] = 0;
edge[j] = mid[j];
} else {
start[j] = mid[j];
edge[j] = var_shape[i][j] - mid[j];
}
nels *= edge[j];
}
for (allInExtRange = 1, j = 0; j < nels; j++) {
err = toMixedBase(j, var_rank[i], edge, index);
IF (err != 0) error("error in toMixedBase");
for (d = 0; d < var_rank[i]; d++)
index[d] += start[d];
value[j]= hash_$1(cdf_format,var_type[i], var_rank[i], index,
NCT_ITYPE($1));
IfCheckTextChar($1, var_type[i])
allInExtRange &= inRange3(cdf_format, (double)value[j],
var_type[i], NCT_ITYPE($1));
}
err = PutVara($1)(ncid, i, start, edge, value);
if (canConvert) {
if (allInExtRange) {
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
ELSE_NOK
}
PNETCDF_CHECK_ERANGE($1)
} else {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
}
}
}
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
nok += check_vars_$1(scratch, numVars);
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("delete file %s failed", scratch);
return nok;
}
')dnl
TEST_NC_PUT_VARA(text)
TEST_NC_PUT_VARA(uchar)
TEST_NC_PUT_VARA(schar)
TEST_NC_PUT_VARA(short)
TEST_NC_PUT_VARA(int)
TEST_NC_PUT_VARA(long)
TEST_NC_PUT_VARA(float)
TEST_NC_PUT_VARA(double)
TEST_NC_PUT_VARA(ushort)
TEST_NC_PUT_VARA(uint)
TEST_NC_PUT_VARA(longlong)
TEST_NC_PUT_VARA(ulonglong)
dnl TEST_NC_PUT_VARS(TYPE)
dnl
define(`TEST_NC_PUT_VARS',dnl
`dnl
int
TestFunc(vars)_$1(VarArgs)
{
int i, k, d, err, nslabs, ncid, cdf_format, nok=0;
int canConvert; /* Both text or both numeric */
int allInExtRange; /* all values within external range? */
IntType j, m, nels;
IntType start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK];
IntType index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK];
IntType sstride[MAX_RANK];
PTRDType nstarts; /* number of different starts */
PTRDType stride[MAX_RANK];
$1 value[MAX_NELS];
err = FileCreate(scratch, NC_CLOBBER);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
}
err = APIFunc(inq_format)(ncid, &cdf_format);
IF (err != NC_NOERR)
error("inq_format: %s", APIFunc(strerror)(err));
def_dims(ncid);
DefVars(ncid, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
/* check if can detect a bad file ID */
err = PutVars($1)(BAD_ID, 0, NULL, NULL, NULL, NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVars($1)(ncid, BAD_VARID, NULL, NULL, NULL, NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
for (i = 0; i < numVars; i++) {
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
value[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVars($1)(BAD_ID, i, NULL, NULL, NULL, value);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
canConvert = (var_type[i] == NC_CHAR) CheckText($1);
for (j = 0; j < var_rank[i]; j++) {
start[j] = 0;
edge[j] = 1;
stride[j] = 1;
}
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVars($1)(ncid, i, NULL, NULL, NULL, value);
if (!canConvert) {
IF (err != NC_ECHAR) EXPECT_ERR(NC_ECHAR, err)
}
else if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
ELSE_NOK
/* for non-scalar variables, argument count cannot be NULL */
err = PutVars($1)(ncid, i, start, NULL, NULL, value);
if (!canConvert) {
IF (err != NC_ECHAR) EXPECT_ERR(NC_ECHAR, err)
}
else if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EEDGE) {
EXPECT_ERR(NC_EEDGE, err)
}
ELSE_NOK
')dnl
/* first test when edge[*] > 0 */
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
start[j] = var_shape[i][j]; /* out of boundary check */
err = PutVars($1)(ncid, i, start, edge, stride, value);
if (!canConvert) {
IF (err != NC_ECHAR)
EXPECT_ERR(NC_ECHAR, err)
ELSE_NOK
start[j] = 0;
continue;
}
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
edge[j] = var_shape[i][j] + 1;
err = PutVars($1)(ncid, i, start, edge, stride, value);
IF (err != NC_EEDGE)
EXPECT_ERR(NC_EEDGE, err)
ELSE_NOK
edge[j] = 1;
stride[j] = 0;
err = PutVars($1)(ncid, i, start, edge, stride, value);
IF (err != NC_ESTRIDE)
EXPECT_ERR(NC_ESTRIDE, err)
ELSE_NOK
stride[j] = 1;
}
/* Check correct error returned even when nothing to put */
for (j = 0; j < var_rank[i]; j++) edge[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */