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
|
/* This is part of the netCDF package. Copyright 2005-2007 University
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file
for conditions of use.
Test attributes.
$Id: tst_atts3.c 2796 2014-10-28 03:40:29Z wkliao $
*/
#include "config.h"
#include <nc_tests.h>
#include "err_macros.h"
#include <signal.h>
#include "netcdf.h"
#ifdef USE_PARALLEL
#include "netcdf_par.h"
#endif
#define FILE_NAME "tst_atts_3.nc"
#define FILE_NAME2 "tst_atts_2.nc"
#define VAR1_NAME "Horace_Rumpole"
#define VAR2_NAME "Claude_Erskine-Brown"
#define VAR3_NAME "Phillida_Erskine-Brown_Q.C."
#define DIM1_NAME "Old_Bailey_case_number"
#define DIM1_LEN 10
#define DIM2_NAME "occupancy_in_chambers"
#define DIM2_LEN 15
#define ATT_INT_NAME "Old_Bailey_Room_Numbers"
#define ATT_DOUBLE_NAME "Equity_Court_Canteen_Charges"
#define ATT_SHORT_NAME "Ecclesiastical_Court_Appearences"
#define ATT_TEXT_NAME "Speech_to_Jury"
#define ATT_TEXT_NAME2 "Speech_to_She_Who_Must_be_Obeyed"
#define ATT_UCHAR_NAME "Number_of_current_briefs"
#define ATT_SCHAR_NAME "Slate_totals_at_Pomeroys_Wine_Bar"
#define ATT_USHORT_NAME "brief_no"
#define ATT_UINT_NAME "Orders_from_SWMBO"
#define ATT_INT64_NAME "judges_golf_score"
#define ATT_UINT64_NAME "Number_of_drinks_in_career_to_date"
/*
#define ATT_USHORT_NAME "Chamber_Gas_Electric_and_Telephone_Bill_Share"
*/
#define ATT_FLOAT_NAME "Average_Nanoseconds_for_Lose_Win_or_Appeal"
#define ATT_LEN 3
char speech[] = "Once more unto the breach, dear friends, once more;\n\
Or close the wall up with our English dead.\n\
In peace there's nothing so becomes a man\n\
As modest stillness and humility:\n\
But when the blast of war blows in our ears,\n\
Then imitate the action of the tiger;\n\
Stiffen the sinews, summon up the blood,\n\
Disguise fair nature with hard-favour'd rage;\n\
Then lend the eye a terrible aspect;\n\
Let pry through the portage of the head\n\
Like the brass cannon; let the brow o'erwhelm it\n\
As fearfully as doth a galled rock\n\
O'erhang and jutty his confounded base,\n\
Swill'd with the wild and wasteful ocean.\n\
Now set the teeth and stretch the nostril wide,\n\
Hold hard the breath and bend up every spirit\n\
To his full height. On, on, you noblest English.\n\
Whose blood is fet from fathers of war-proof!\n\
Fathers that, like so many Alexanders,\n\
Have in these parts from morn till even fought\n\
And sheathed their swords for lack of argument:\n\
Dishonour not your mothers; now attest\n\
That those whom you call'd fathers did beget you.\n\
Be copy now to men of grosser blood,\n\
And teach them how to war. And you, good yeoman,\n\
Whose limbs were made in England, show us here\n\
The mettle of your pasture; let us swear\n\
That you are worth your breeding; which I doubt not;\n\
For there is none of you so mean and base,\n\
That hath not noble lustre in your eyes.\n\
I see you stand like greyhounds in the slips,\n\
Straining upon the start. The game's afoot:\n\
Follow your spirit, and upon this charge\n\
Cry 'God for Harry, England, and Saint George!'";
/* Test the ordering of atts for a cmode. */
#define NUM_ATTS 8
#define ATT_MAX_NAME 25
int
tst_att_ordering(int cmode)
{
int ncid;
char name[NUM_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
"Gd", "Gatt-name-dashes", "Gatt.name.dots"};
int len[NUM_ATTS] = {0, 2, 3, 3, 3, 3, 1, 1};
signed char b[2] = {-128, 127};
short s[3] = {-32768, 0, 32767};
int i[3] = {42, 0, -42};
float f[3] = {42.0, -42.0, 42.0};
double d[3] = {420.0, -420.0, 420.0};
int att_name_dashes = -1, att_name_dots = -2;
char name_in[NC_MAX_NAME];
int j;
/* Create a file with some global atts. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, cmode, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, name[0], len[0], NULL)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, name[1], NC_BYTE, len[1], b)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, name[2], NC_SHORT, len[2], s)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[3], NC_INT, len[3], i)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, name[4], NC_FLOAT, len[4], f)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, name[5], NC_DOUBLE, len[5], d)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[6], NC_INT, len[6], &att_name_dashes)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[7], NC_INT, len[7], &att_name_dots)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check the order. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
for (j = 0; j < NUM_ATTS; j++)
{
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
if (strcmp(name_in, name[j])) ERR;
}
/* Close up shop. */
if (nc_close(ncid)) ERR;
return err;
}
int
main(int argc, char **argv)
{
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
unsigned char uchar_in[ATT_LEN];
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 127, 100000};
float float_in[ATT_LEN], float_out[ATT_LEN] = {-0.5, 0.25, 0.125};
double double_in[ATT_LEN], double_out[ATT_LEN] = {-0.25, .5, 0.125};
long long longlong_in[ATT_LEN] = {-1LL, -1LL, -1LL};
#ifdef TEST_PNETCDF
MPI_Init(&argc, &argv);
#endif
(void) signal(SIGFPE, SIG_IGN);
printf("\n*** Testing netcdf-3 attribute functions.\n");
printf("*** testing really simple global atts...");
#define NUM_SIMPLE_ATTS 9
{
int ncid;
char name[NUM_SIMPLE_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
"Gd", "G7", "G8", "G9"};
char name_in[NC_MAX_NAME];
int j;
/* Create a file with some global atts. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
if (nc_put_att_int(ncid, NC_GLOBAL, name[j], NC_INT, 0, NULL)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check the order. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
for (j = 0; j < NUM_SIMPLE_ATTS; j++)
{
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
if (strcmp(name_in, name[j])) ERR;
}
/* Close up shop. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing simple global atts...");
{
int ncid;
nc_type att_type;
size_t att_len;
int i;
char *speech_in;
/* This won't work, because classic files can't create these types. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN,
int_out)) ERR;
/* It is also OK to read classic types converted into
* supported C types. though the conversion may encounter
* out-of-range values */
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_INT_NAME, uchar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0 || i == 2) continue;
if (uchar_in[i] != (unsigned char) int_out[i]) ERR;
}
/* This was bug NCF-171: on 32-bit platforms, bad values returned */
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != (long long) int_out[i]) ERR;
if (nc_close(ncid)) ERR;
/* Create a file with a global attribute of each type. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
if (nc_close(ncid)) ERR;
/* Open the file and check attributes. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
/* Check text. */
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len))
ERR;
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
if (!(speech_in = malloc(att_len + 1))) ERR;
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
if (strcmp(speech, speech_in)) ERR;
free(speech_in);
/* Check numeric values. */
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (schar_in[i] != schar_out[i]) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != short_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != int_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != float_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != double_out[i]) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing attribute data type conversions...");
{
int ncid;
int i;
/* Reopen the file and try different type conversions. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
/* No text conversions are allowed, and people who try them should
* be locked up, away from decent folk! */
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_TEXT_NAME, short_in) != NC_ECHAR) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_TEXT_NAME, int_in) != NC_ECHAR) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_TEXT_NAME, float_in) != NC_ECHAR) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_TEXT_NAME, double_in) != NC_ECHAR) ERR;
/* Read all atts (except text) as double. */
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SCHAR_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != schar_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SHORT_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != short_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_INT_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != int_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_FLOAT_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != float_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != double_out[i]) ERR;
/* Read all atts (except text) as float. */
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SCHAR_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != schar_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SHORT_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != short_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_INT_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != int_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != float_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != (float) double_out[i]) ERR;
/* Read all atts (except text) as int. */
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SCHAR_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != schar_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SHORT_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != short_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != int_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_FLOAT_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != (int) float_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != (int) double_out[i]) ERR;
/* Read all atts (except text) as short. */
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SCHAR_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != schar_out[i]) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != short_out[i]) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_INT_NAME, short_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0 || i == 2) continue;
if (short_in[i] != (short) int_out[i]) ERR;
}
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_FLOAT_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != (short) float_out[i]) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != (short) double_out[i]) ERR;
/* Read all atts (except text) as schar. */
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (schar_in[i] != schar_out[i]) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0 || i == 2) continue;
if (schar_in[i] != (signed char) short_out[i]) ERR;
}
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0 || i == 2) continue;
if (schar_in[i] != (signed char) int_out[i]) ERR;
}
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (schar_in[i] != (signed char) float_out[i]) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (schar_in[i] != (signed char) double_out[i]) ERR;
/* Read all atts (except text) as uchar. */
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, uchar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (uchar_in[i] != (unsigned char) schar_out[i]) ERR;
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_SHORT_NAME, uchar_in) != NC_ERANGE) ERR;
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_INT_NAME, uchar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0 || i == 2) continue;
if (uchar_in[i] != (unsigned char) int_out[i]) ERR;
}
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, uchar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0) continue;
if (uchar_in[i] != (unsigned char) float_out[i]) ERR;
}
if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, uchar_in) != NC_ERANGE) ERR;
for (i = 0; i < ATT_LEN; i++) {
if (i == 0) continue;
if (uchar_in[i] != (unsigned char) double_out[i]) ERR;
}
/* Read all atts (except text) into long long variable. */
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_SCHAR_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != schar_out[i]) ERR;
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_SHORT_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != short_out[i]) ERR;
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT_NAME, longlong_in)) ERR;
/* This was bug NCF-171: on 32-bit platforms, bad values returned */
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != (long long) int_out[i]) ERR;
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_FLOAT_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != (long long)float_out[i]) ERR;
if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != (long long)double_out[i]) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing zero-length attributes...");
{
int ncid;
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
/* Create a file with a global attribute of each type of zero length. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
if (nc_close(ncid)) ERR;
}
/* Make sure we can read all these zero-length atts. */
{
int ncid;
signed char schar_in[ATT_LEN];
short short_in[ATT_LEN];
/*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
int int_in[ATT_LEN];
float float_in[ATT_LEN];
double double_in[ATT_LEN];
size_t len;
nc_type xtype;
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_CHAR) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_BYTE) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_SHORT) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_INT_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_INT) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_FLOAT) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
if (nc_inq_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, &xtype, &len)) ERR;
if (len || xtype != NC_DOUBLE) ERR;
/* Conversions no longer result in range errors, since there's no data. */
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing zero-length attributes and redef...(this test skipped for HDF5-1.8.0 beta1");
{
int ncid;
signed char schar_in[ATT_LEN];
short short_in[ATT_LEN];
int int_in[ATT_LEN];
float float_in[ATT_LEN];
double double_in[ATT_LEN];
/* Create a file with a global attribute of each type of zero length. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
if (nc_close(ncid)) ERR;
/* Make sure we can read all these zero-length atts added during a
* redef. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
/* Conversions no longer result in range errors, since there's no data. */
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing attribute deletes and renames...");
{
int ncid, varid, dimids[2];
nc_type att_type;
size_t att_len;
char *speech_in;
char name_in[NC_MAX_NAME + 1];
int attid_in, natts_in;
int int_out[ATT_LEN] = {-100000, 128, 100000};
/* Create a file with a global attribute. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1,
speech)) ERR;
if (nc_close(ncid)) ERR;
/* Rename it. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_inq_attid(ncid, NC_GLOBAL, ATT_TEXT_NAME, &attid_in)) ERR;
if (attid_in != 0) ERR;
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
if (strcmp(name_in, ATT_TEXT_NAME)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ATT_TEXT_NAME2)) ERR;
if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
if (strcmp(name_in, ATT_TEXT_NAME2)) ERR;
if (nc_close(ncid)) ERR;
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2, &att_type, &att_len)) ERR;
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
if (!(speech_in = malloc(att_len + 1))) ERR;
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME2, speech_in)) ERR;
if (strcmp(speech, speech_in)) ERR;
free(speech_in);
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in) != NC_ENOTATT) ERR;
if (nc_close(ncid)) ERR;
/* Now delete the att. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_redef(ncid)) ERR;
if (nc_del_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2)) ERR;
if (nc_close(ncid)) ERR;
/* Now create a file with a variable, which has an att. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and delete it. Make sure it's gone. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_redef(ncid)) ERR;
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and readd the attribute. Enddef and redef,
* and delete it, then check to make sure it's gone. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_redef(ncid)) ERR;
if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
if (nc_inq_varnatts(ncid, 0, &natts_in)) ERR;
if (natts_in != 0) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing attribute create order...");
#define ATT0 "Maturin"
#define ATT1 "Aubery"
{
int ncid, varid, dimids[2];
int attid_in;
const int number = 42;
/* Create a file with several global attributes. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_int(ncid, NC_GLOBAL, ATT0, NC_INT, 1, &number)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, ATT1, NC_INT, 1, &number)) ERR;
if (nc_close(ncid)) ERR;
/* Open it and check the order. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_inq_attid(ncid, NC_GLOBAL, ATT0, &attid_in)) ERR;
if (attid_in != 0) ERR;
if (nc_inq_attid(ncid, NC_GLOBAL, ATT1, &attid_in)) ERR;
if (attid_in != 1) ERR;
if (nc_close(ncid)) ERR;
/* Now create a file with a variable, which has two atts. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
if (nc_put_att_int(ncid, varid, ATT0, NC_INT, 1, &number)) ERR;
if (nc_put_att_int(ncid, varid, ATT1, NC_INT, 1, &number)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check the order of the attributes on the var. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, NC_WRITE, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
#endif
if (nc_inq_attid(ncid, 0, ATT0, &attid_in)) ERR;
if (attid_in != 0) ERR;
if (nc_inq_attid(ncid, 0, ATT1, &attid_in)) ERR;
if (attid_in != 1) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing attribute ordering some more...");
#define VAR_NAME "i"
#define A1_NAME "i"
#define A2_NAME "f"
#define A3_NAME "d"
#define A1_LEN 3
#define A2_LEN 4
#define A3_LEN 5
{
int ncid;
int varid, natts, nvars;
double dvalue[] = {999.99, 999.99, 999.99, 999.99, 999.99};
char name_in[NC_MAX_NAME + 1];
/* Create a file with one var, and attach three atts to it. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_def_var(ncid, VAR_NAME, NC_INT, 0, NULL, &varid)) ERR;
if (nc_put_att_double(ncid, varid, A1_NAME, NC_INT, A1_LEN, dvalue)) ERR;
if (nc_put_att_double(ncid, varid, A2_NAME, NC_INT, A2_LEN, dvalue)) ERR;
if (nc_put_att_double(ncid, varid, A3_NAME, NC_INT, A3_LEN, dvalue)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
if (nc_inq_nvars(ncid, &nvars)) ERR;
if (nvars != 1) ERR;
if (nc_inq_varnatts(ncid, 0, &natts)) ERR;
if (natts != 3) ERR;
if (nc_inq_attname(ncid, 0, 0, name_in)) ERR;
if (strcmp(name_in, A1_NAME)) ERR;
if (nc_inq_attname(ncid, 0, 1, name_in)) ERR;
if (strcmp(name_in, A2_NAME)) ERR;
if (nc_inq_attname(ncid, 0, 2, name_in)) ERR;
if (strcmp(name_in, A3_NAME)) ERR;
/* Close up shop. */
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing attribute ordering even more...");
/* Test the ordering of atts for each cmode. */
if (tst_att_ordering(NC_CLOBBER)) ERR;
if (tst_att_ordering(NC_CLOBBER|NC_64BIT_OFFSET)) ERR;
SUMMARIZE_ERR;
printf("*** testing attributes and enddef/redef...");
#define ATT_1 "a"
#define ATT_2 "b"
#define ATT_3 "c"
{
int ncid, att = 1;
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_put_att(ncid, NC_GLOBAL, ATT_1, NC_INT, 1, &att)) ERR;
if (nc_put_att(ncid, NC_GLOBAL, ATT_2, NC_INT, 1, &att)) ERR;
if (nc_put_att(ncid, NC_GLOBAL, ATT_3, NC_INT, 1, &att)) ERR;
if (nc_close(ncid)) ERR;
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
#endif
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** testing copy of simple global atts...");
{
int ncid, ncid2;
nc_type att_type;
size_t att_len;
int i;
char *speech_in;
signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
/* Create a file with a global attribute of each type. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid)) ERR;
#else
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
#endif
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;
/* Create another file and copy all the attributes. */
#ifdef TEST_PNETCDF
if (nc_create_par(FILE_NAME2, NC_CLOBBER, MPI_COMM_WORLD, MPI_INFO_NULL,&ncid2)) ERR;
#else
if (nc_create(FILE_NAME2, NC_CLOBBER, &ncid2)) ERR;
#endif
if (nc_copy_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ncid2, NC_GLOBAL)) ERR;
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
if (nc_copy_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, ncid2, NC_GLOBAL)) ERR;
if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT_NAME, ncid2, NC_GLOBAL)) ERR;
if (nc_copy_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, ncid2, NC_GLOBAL)) ERR;
if (nc_copy_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, ncid2, NC_GLOBAL)) ERR;
/* Close both files. */
if (nc_close(ncid)) ERR;
if (nc_close(ncid2)) ERR;
/* Open the file and check attributes. */
#ifdef TEST_PNETCDF
if (nc_open_par(FILE_NAME2, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)) ERR;
#else
if (nc_open(FILE_NAME2, 0, &ncid)) ERR;
#endif
/* Check text. */
if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
if (!(speech_in = malloc(att_len + 1))) ERR;
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;
if (strcmp(speech, speech_in)) ERR;
free(speech_in);
/* Check numeric values. */
if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (schar_in[i] != schar_out[i]) ERR;
if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (short_in[i] != short_out[i]) ERR;
if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (int_in[i] != int_out[i]) ERR;
if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (float_in[i] != float_out[i]) ERR;
if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (double_in[i] != double_out[i]) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
#ifdef TEST_PNETCDF
MPI_Finalize();
#endif
FINAL_RESULTS;
}
|