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
|
/* This is part of the netCDF package.
Copyright 2005 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
Test HDF5 file code. These are not intended to be exhaustive tests,
but they use HDF5 the same way that netCDF-4 does, so if these
tests don't work, than netCDF-4 won't work either.
This file deals with HDF5 attributes.
$Id: tst_h_atts.c,v 1.20 2010/06/01 15:34:51 ed Exp $
*/
#include "h5_err_macros.h"
#include <nc_tests.h>
#include <hdf5.h>
#include <H5DSpublic.h>
#define FILE_NAME "tst_h_atts.h5"
#define GRP_NAME "Hamlet"
#define ATT1_NAME "Hamlets_Self_Evaluation"
#define ATT2_NAME "Commentary"
#define MAX_LEN 50
#define NUM_EMPS 6
#define EMP_GRP "Emperors"
#define NC3_STRICT_ATT_NAME "_nc3_strict"
char txt[] = "O, what a rogue and peasant slave am I!\n"
"Is it not monstrous that this player here,\n"
"But in a fiction, in a dream of passion,\n"
"Could force his soul so to his own conceit\n"
"That from her working all his visage wann'd,\n"
"Tears in his eyes, distraction in's aspect,\n"
"A broken voice, and his whole function suiting\n"
"With forms to his conceit? and all for nothing!\n"
"For Hecuba!\n"
"What's Hecuba to him, or he to Hecuba,\n"
"That he should weep for her?";
int
main()
{
hid_t fileid, grpid, spaceid, typeid, attid;
char *txt_in;
size_t txt_size;
hssize_t size;
size_t type_size;
int ndims;
hsize_t num_obj;
printf("\n*** Checking HDF5 attribute functions.\n");
printf("*** Checking HDF5 attribute ordering...");
{
float val = 99;
char emp[NUM_EMPS][MAX_LEN + 1] = {"Augustus", "Tiberius",
"Caligula", "Claudius",
"Ne_r_o", "V.esp.asi.an"};
char obj_name[MAX_LEN + 1];
int e, i;
/* Open file and create group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gcreate(fileid, EMP_GRP, 0)) < 0) ERR;
/* Create space fo zero-length attributes. */
if ((spaceid = H5Screate(H5S_NULL)) < 0) ERR;
/* Attach some zero-length float attributes! */
for (e = 0; e < NUM_EMPS; e++)
{
if ((attid = H5Acreate(grpid, emp[e], H5T_NATIVE_FLOAT, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_FLOAT, &val) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
}
/* Close everything. */
if (H5Sclose(spaceid) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(fileid) < 0) ERR;
/* Now open the file again and read in the attributes. */
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, EMP_GRP)) < 0) ERR;
/* How many attributes are there? */
if ((num_obj = H5Aget_num_attrs(grpid)) != NUM_EMPS) ERR;
/* Make sure the names are in the correct order. */
for (i = 0; i < num_obj; i++)
{
if ((attid = H5Aopen_idx(grpid, (unsigned int)i)) < 0) ERR;
if (H5Aget_name(attid, MAX_LEN + 1, obj_name) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (strcmp(obj_name, emp[i])) ERR;
}
if (H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 attribute deletes...");
{
/* Create a file and open the root group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* Attach a text attribute with some of Hamlet's lines. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
if (H5Tset_size(typeid, strlen(txt) + 1) < 0) ERR;
if ((attid = H5Acreate(grpid, ATT1_NAME, typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, txt) < 0) ERR;
/* Delete the attribute. */
if (H5Aclose(attid) < 0) ERR;
if (H5Adelete(grpid, ATT1_NAME) < 0) ERR;
/* Create and write it again. */
if ((attid = H5Acreate(grpid, ATT1_NAME, typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, txt) < 0) ERR;
/* Close everything. */
if (H5Aclose(attid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 attributes attached to the fileid...");
{
/* See if we can write an attribute to the root group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* Attach a text attribute with some of Hamlet's lines. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
if (H5Tset_size(typeid, strlen(txt) + 1) < 0) ERR;
if ((attid = H5Acreate(grpid, ATT1_NAME, typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, txt) < 0) ERR;
if (H5Aclose(attid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 attributes in a group...");
{
/* Open file and create group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;
/* Attach a text attribute with some of Hamlet's lines. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
if (H5Tset_size(typeid, strlen(txt) + 1) < 0) ERR;
if ((attid = H5Acreate(grpid, ATT1_NAME, typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, txt) < 0) ERR;
if (H5Aclose(attid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
/* Now open the file again and read in the attribute. */
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
if ((attid = H5Aopen_name(grpid, ATT1_NAME)) < 0) ERR;
if ((typeid = H5Aget_type(attid)) < 0) ERR;
/* Check the size of the string in the attribute. */
if (H5Tget_class(typeid) != H5T_STRING) ERR;
if (!(txt_size = H5Tget_size(typeid))) ERR;
if (txt_size != strlen(txt) + 1) ERR;
/* Now read the attribute. But if I don't malloc the memory first,
* I get zapped with a seg-fault. Aren't strings supposed to be
* different? */
if (!(txt_in = malloc(txt_size+1))) ERR;
if (H5Aread(attid, typeid, txt_in) < 0) ERR;
if (strcmp(txt_in, txt)) ERR;
if (strlen(txt_in) != strlen(txt)) ERR;
/* For a scalar, ndims is 0 but simple_extent_npoints is 1. For a
* NULL dataspace (see below), they are both 0. */
if ((spaceid = H5Aget_space(attid)) < 0) ERR;
if ((size = H5Sget_simple_extent_npoints(spaceid)) < 0) ERR;
if (size != 1) ERR;
if ((ndims = H5Sget_simple_extent_ndims(spaceid)) < 0) ERR;
if (ndims != 0) ERR;
if (!(type_size = H5Tget_size(typeid))) ERR;
if (type_size != strlen(txt) + 1) ERR;
free(txt_in);
if (H5Aclose(attid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 zero length attributes...");
{
hid_t attid1;
float val = 99;
/* Open file and create group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0)
ERR;
if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0)
ERR;
/* Attach a float attribute with no data. The
* hell with Hamlet anyway! */
if ((spaceid = H5Screate(H5S_NULL)) < 0)
ERR;
if ((typeid = H5Tcopy(H5T_NATIVE_FLOAT)) < 0)
ERR;
if ((attid = H5Acreate(grpid, ATT1_NAME,
typeid, spaceid, H5P_DEFAULT)) < 0)
ERR;
if (H5Awrite(attid, H5T_NATIVE_FLOAT, &val) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (H5Tclose(typeid) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(fileid) < 0) ERR;
/* Now open the file again and read in the attribute. */
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
if ((attid = H5Aopen_name(grpid, ATT1_NAME)) < 0) ERR;
if ((spaceid = H5Aget_space(attid)) < 0) ERR;
if ((size = H5Sget_simple_extent_npoints(spaceid)) < 0) ERR;
if (size != 0) ERR;
if ((ndims = H5Sget_simple_extent_ndims(spaceid)) < 0) ERR;
if (ndims != 0) ERR;
/* Attach a text attribute with no data. */
if ((spaceid = H5Screate(H5S_NULL)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
if (H5Tset_size(typeid, 1) < 0) ERR;
if ((attid1 = H5Acreate(grpid, ATT2_NAME, typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_FLOAT, &val) < 0) ERR;
if (H5Sclose(spaceid) < 0 ||
H5Aclose(attid) < 0 ||
H5Aclose(attid1) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
/* Now open the file again and read in the attribute. */
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, GRP_NAME)) < 0) ERR;
if ((attid = H5Aopen_name(grpid, ATT2_NAME)) < 0) ERR;
if ((spaceid = H5Aget_space(attid)) < 0) ERR;
if ((size = H5Sget_simple_extent_npoints(spaceid)) < 0) ERR;
if (size != 0) ERR;
if ((ndims = H5Sget_simple_extent_ndims(spaceid)) < 0) ERR;
if (ndims != 0) ERR;
if (H5Sclose(spaceid) < 0 ||
H5Aclose(attid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking how HDF5 handles a delete and recreation of dataset with atts...");
#define DIM1_LEN 3
#define VAR_NAME "Hamlet"
#define NUM_SPEECHES 3
#define MAX_SPEECH_LEN 4095
{
/* Why test this out? Because this happens when the netcdf-4 user
* assigns a fill value attribute to a var. Since HDF5 demands that
* the fill value be supplied on var creation, I have to delete the
* dataset and recreate it, readding the attributes that existed
* when I delete it. */
hid_t var_spaceid = 0, datasetid = 0;
hsize_t dims[1];
char speech[NUM_SPEECHES][MAX_SPEECH_LEN + 1] = {
"A little more than kin, and less than kind!",
"Speak the speech, I pray you, as I pronounc'd it to you, trippingly on\n"
"the tongue. But if you mouth it, as many of our players do, I had as\n"
"live the town crier spoke my lines. Nor do not saw the air too much\n"
"with your hand, thus, but use all gently; for in the very torrent,\n"
"tempest, and (as I may say) whirlwind of your passion, you must\n"
"acquire and beget a temperance that may give it smoothness. O, it\n"
"offends me to the soul to hear a robustious periwig-pated fellow tear\n"
"a passion to tatters, to very rags, to split the cars of the\n"
"groundlings, who (for the most part) are capable of nothing but\n"
"inexplicable dumb shows and noise. I would have such a fellow whipp'd\n"
"for o'erdoing Termagant. It out-herods Herod. Pray you avoid it.",
"O, I die, Horatio!\n"
"The potent poison quite o'ercrows my spirit.\n"
"I cannot live to hear the news from England,\n"
"But I do prophesy th' election lights\n"
"On Fortinbras. He has my dying voice.\n"
"So tell him, with th' occurrents, more and less,\n"
"Which have solicited- the rest is silence."};
char speech_name[NUM_SPEECHES][MAX_LEN + 1] = {"Act_1_Scene_2",
"Act_3_Scene_2",
"Act_5_Scene_2"};
char obj_name[MAX_LEN + 1];
int i;
/* Create a file and get its root group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* Create a dataset. */
dims[0] = DIM1_LEN;
if ((var_spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
if ((datasetid = H5Dcreate(grpid, VAR_NAME, H5T_NATIVE_HBOOL,
var_spaceid, H5P_DEFAULT)) < 0) ERR;
/* Attach three text attributes with some of Hamlet's lines to
* the dataset. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
for (i = 0; i < NUM_SPEECHES; i++)
{
if (H5Tset_size(typeid, strlen(speech[i]) + 1) < 0) ERR;
if ((attid = H5Acreate(datasetid, speech_name[i], typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, speech[i]) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
}
if (H5Dclose(datasetid) < 0 ||
H5Sclose(var_spaceid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Tclose(typeid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
/* Now open the file and delete the dataset (and all its
* attributes). */
/* Open file, group, and dataset. */
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
if ((datasetid = H5Dopen1(grpid, VAR_NAME)) < 0) ERR;
/* How many attributes are there? */
if ((num_obj = H5Aget_num_attrs(datasetid)) != NUM_SPEECHES) ERR;
/* Make sure the names are in the correct order. */
for (i = 0; i < num_obj; i++)
{
if ((attid = H5Aopen_idx(datasetid, (unsigned int)i)) < 0) ERR;
if (H5Aget_name(attid, MAX_LEN + 1, obj_name) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (strcmp(obj_name, speech_name[i])) ERR;
}
/* Delete the HDF5 dataset. */
if (H5Dclose(datasetid) < 0) ERR;
if (H5Gunlink(grpid, VAR_NAME) < 0) ERR;
/* Recreate it and add the attributes again. */
if ((var_spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
if ((datasetid = H5Dcreate(grpid, VAR_NAME, H5T_NATIVE_HBOOL,
var_spaceid, H5P_DEFAULT)) < 0) ERR;
/* Attach three text attributes with some of Hamlet's lines to
* the dataset. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((typeid = H5Tcopy(H5T_C_S1)) < 0) ERR;
for (i = 0; i < NUM_SPEECHES; i++)
{
if (H5Tset_size(typeid, strlen(speech[i]) + 1) < 0) ERR;
if ((attid = H5Acreate(datasetid, speech_name[i], typeid, spaceid,
H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, typeid, speech[i]) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
}
/* How many attributes are there? */
if ((num_obj = H5Aget_num_attrs(datasetid)) != NUM_SPEECHES) ERR;
/* Make sure the names are in the correct order. */
for (i = 0; i < num_obj; i++)
{
if ((attid = H5Aopen_idx(datasetid, (unsigned int)i)) < 0) ERR;
if (H5Aget_name(attid, MAX_LEN + 1, obj_name) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (strcmp(obj_name, speech_name[i])) ERR;
}
if (H5Dclose(datasetid) < 0 ||
H5Sclose(var_spaceid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking some more simple atts...");
{
hid_t fcpl_id, fapl_id, hdfid, grpid;
hid_t spaceid, attid, attid1;
int one = 1;
hsize_t dims[1];
/* Create a HDF5 file. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
/* if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;*/
if ((hdfid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
if (H5Pclose(fcpl_id) < 0) ERR;
/* Open the root group. */
if ((grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0) ERR;
/* Write an attribute. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((attid = H5Acreate2(grpid, NC3_STRICT_ATT_NAME, H5T_NATIVE_INT,
spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
H5Fflush(hdfid, H5F_SCOPE_GLOBAL);
dims[0] = 1;
if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "l", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "y", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "c", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(hdfid) < 0) ERR;
if ((hdfid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, fapl_id)) < 0) ERR;
if ((grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0)
if (H5Pclose(fapl_id) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(hdfid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking some more simple atts even more...");
{
hid_t fcpl_id, fapl_id, hdfid, grpid;
hid_t spaceid, attid, attid1;
int one = 1;
hsize_t dims[1];
/* Create a HDF5 file. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
/* if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;*/
if ((hdfid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
if (H5Pclose(fcpl_id) < 0) ERR;
/* Open the root group. */
if ((grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0) ERR;
/* Write an attribute. */
if ((spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
if ((attid = H5Acreate(grpid, NC3_STRICT_ATT_NAME, H5T_NATIVE_INT,
spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
H5Fflush(hdfid, H5F_SCOPE_GLOBAL);
dims[0] = 1;
if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "z", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "y", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if ((attid1 = H5Acreate2(grpid, "c", H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
if (H5Aclose(attid1) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(hdfid) < 0) ERR;
if ((hdfid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, fapl_id)) < 0) ERR;
if ((grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0)
if (H5Pclose(fapl_id) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(hdfid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 attribute ordering some more...");
{
#define DIM2_LEN 2
hid_t fileid, grpid, attid, spaceid, dimscaleid, att_spaceid;
hid_t fcpl_id, fapl_id;
hsize_t num_obj, dims[1];
char obj_name[MAX_LEN + 1];
char att_name[3][20] = {"first", "second", "third"};
signed char b[DIM2_LEN] = {-127, 126};
int i;
/* Create a file and get its root group. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* Write two group-level attributes containing byte attays of
* length 2, call them "first" and "second". */
dims[0] = DIM2_LEN;
if ((att_spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
if ((attid = H5Acreate(grpid, att_name[0], H5T_NATIVE_UCHAR,
att_spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_UCHAR, b) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if ((attid = H5Acreate(grpid , att_name[1], H5T_NATIVE_UCHAR,
att_spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_UCHAR, b) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
/* Create a dataset which will be a HDF5 dimension scale. */
dims[0] = 1;
if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
if ((dimscaleid = H5Dcreate(grpid, "D1", H5T_IEEE_F32BE,
spaceid, H5P_DEFAULT)) < 0)
ERR;
/* Indicate that this is a scale. */
if (H5DSset_scale(dimscaleid, NULL) < 0) ERR;
/* Add another attribute to the group. Call it "third". */
if ((attid = H5Acreate(grpid , att_name[2], H5T_NATIVE_UCHAR,
att_spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid, H5T_NATIVE_UCHAR, b) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (H5Dclose(dimscaleid) < 0 ||
H5Sclose(spaceid) < 0 ||
H5Sclose(att_spaceid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
/* Now open the file and check. Magically, the attributes "second"
* and "first" will be out of order. This can be checked with
* h5dump, or with the following code, which will fail if it does
* not find three attributes, in order "first", "second", and
* "third". */
/* Open file, group. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
fapl_id)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* How many attributes are there? */
if ((num_obj = H5Aget_num_attrs(grpid)) != 3) ERR;
/* Make sure the names are in the correct order. */
for (i = 0; i < num_obj; i++)
{
if ((attid = H5Aopen_idx(grpid, (unsigned int)i)) < 0) ERR;
if (H5Aget_name(attid, MAX_LEN + 1, obj_name) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (strcmp(obj_name, att_name[i])) ERR;
}
if (H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
printf("*** Checking HDF5 attribute ordering with 9 attributes...(skipping for HDF5 1.8.0 beta1)");
#define NUM_SIMPLE_ATTS 9
#define ATT_MAX_NAME 2
{
hid_t fileid, grpid, attid, att_spaceid;
hsize_t num_obj;
char obj_name[MAX_LEN + 1];
char name[NUM_SIMPLE_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
"Gd", "G7", "G8", "G9"};
hid_t fcpl_id, fapl_id;
int i;
/* Set up property lists to turn on creation ordering. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
/* Create a file and get its root group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* These will all be zero-length atts. */
if ((att_spaceid = H5Screate(H5S_NULL)) < 0) ERR;
for (i = 0; i < NUM_SIMPLE_ATTS; i++)
{
if ((attid = H5Acreate(grpid, name[i], H5T_NATIVE_INT,
att_spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
}
if (H5Sclose(att_spaceid) < 0 ||
H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
/* Now open the file and check. */
/* Open file, group. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) ERR;
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR,
fapl_id)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* How many attributes are there? */
if ((num_obj = H5Aget_num_attrs(grpid)) != NUM_SIMPLE_ATTS) ERR;
/* Make sure the names are in the correct order. */
for (i = 0; i < num_obj; i++)
{
if ((attid = H5Aopen_idx(grpid, (unsigned int)i)) < 0) ERR;
if (H5Aget_name(attid, MAX_LEN + 1, obj_name) < 0) ERR;
if (H5Aclose(attid) < 0) ERR;
if (strcmp(obj_name, name[i])) ERR;
}
if (H5Gclose(grpid) < 0 ||
H5Fclose(fileid) < 0) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}
|