File: tst_h_refs.c

package info (click to toggle)
netcdf-parallel 1%3A4.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,668 kB
  • sloc: ansic: 200,241; sh: 10,807; yacc: 2,522; makefile: 1,306; lex: 1,153; xml: 173; awk: 2
file content (115 lines) | stat: -rw-r--r-- 4,313 bytes parent folder | download | duplicates (2)
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
/* This is part of the netCDF package.  Copyright 2005 University
   Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
   conditions of use.

   This program tests fixes for reading netCDF-4 files that contain
   datasets with reference datatypes.  The netCDF-4 library should ignore
   the datasets & attributes that have reference datatypes and allow the 
   rest of the file to be accessed.
*/

#include <config.h>
#include <nc_tests.h>
#include <err_macros.h>
#include <hdf5.h>

#define FILE_NAME "tst_h_refs.h5"
#define REF_ATT_NAME "refatt"
#define REF_VAR_NAME "refvar"
#define INT_ATT_NAME "intatt"
#define INT_VAR_NAME "intvar"

int
main()
{
    printf("\n*** Creating file with datasets & attributes that have reference datatypes.\n");
    {
	hid_t fileid, scalar_spaceid;
	hid_t attid, dsetid;

	if ((scalar_spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
	
	/* Create new file, using default properties. */
	if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
	
        /* Create dataset with reference datatype */
        if ((dsetid = H5Dcreate2(fileid, REF_VAR_NAME, H5T_STD_REF_OBJ, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;

        /* Create attribute with reference datatype on reference dataset */
        if ((attid = H5Acreate2(dsetid, REF_ATT_NAME, H5T_STD_REF_OBJ, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;

        /* Create attribute with native int datatype on reference dataset */
        if ((attid = H5Acreate2(dsetid, INT_ATT_NAME, H5T_NATIVE_INT, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;

        /* Close reference dataset */
        if (H5Dclose(dsetid) < 0) ERR;


        /* Create dataset with native int datatype */
        if ((dsetid = H5Dcreate2(fileid, INT_VAR_NAME, H5T_NATIVE_INT, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;

        /* Create attribute with reference datatype on integer dataset */
        if ((attid = H5Acreate2(dsetid, REF_ATT_NAME, H5T_STD_REF_OBJ, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;

        /* Create attribute with native int datatype on integer dataset */
        if ((attid = H5Acreate2(dsetid, INT_ATT_NAME, H5T_NATIVE_INT, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;

        /* Close integer dataset */
        if (H5Dclose(dsetid) < 0) ERR;


        /* Create attribute on root group with reference datatype */
        if ((attid = H5Acreate2(fileid, REF_ATT_NAME, H5T_STD_REF_OBJ, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;

        /* Create attribute on root group with native int datatype */
        if ((attid = H5Acreate2(fileid, INT_ATT_NAME, H5T_NATIVE_INT, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
        if (H5Aclose(attid) < 0) ERR;


        /* Close rest */
	if (H5Sclose(scalar_spaceid) < 0) ERR;
	if (H5Fclose(fileid) < 0) ERR;
    }

    printf("*** Checking accessing file through netCDF-4 API...");
    {
	int ncid, varid, attid;
        int natts = 0;
	nc_type type;

	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

        /* Check the root group's attributes are OK */
	if (nc_inq_varnatts(ncid, NC_GLOBAL, &natts )) ERR;
	if (natts != 1) ERR;    /* Reference attribute should not be present */
	if (nc_inq_attid(ncid, NC_GLOBAL, INT_ATT_NAME, &attid)) ERR;
	if (nc_inq_atttype(ncid, NC_GLOBAL, INT_ATT_NAME, &type)) ERR;
	if (type != NC_INT) ERR;

        /* Verify that the reference dataset is not present */
	if (!nc_inq_varid(ncid, REF_VAR_NAME, &varid)) ERR;

        /* Verify that the integer dataset is present and OK */
	if (nc_inq_varid(ncid, INT_VAR_NAME, &varid)) ERR;
	if (nc_inq_vartype(ncid, varid, &type)) ERR;
	if (type != NC_INT) ERR;

        /* Check the integer dataset's attributes are OK */
	if (nc_inq_varnatts(ncid, varid, &natts )) ERR;
	if (natts != 1) ERR;    /* Reference attribute should not be present */
	if (nc_inq_attid(ncid, varid, INT_ATT_NAME, &attid)) ERR;
	if (nc_inq_atttype(ncid, varid, INT_ATT_NAME, &type)) ERR;
	if (type != NC_INT) ERR;

	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;

    FINAL_RESULTS;
}