1 /* This is part of the netCDF package.
2    Copyright 2005 University Corporation for Atmospheric Research/Unidata
3    See COPYRIGHT file for conditions of use.
4 
5    Use HDF5 to read c0.nc, a file created by ncdump. This check was
6    added to detect a problem in the early HDF5 1.8.0 releases. This
7    program is called from the test script tst_netcdf4.sh, which uses
8    ncgen to create the test file c0_tst_netcdf4.nc, which this program
9    reads with HDF5.
10 
11    Ed Hartnett
12 */
13 #include <nc_tests.h>
14 #include "err_macros.h"
15 #include <hdf5.h>
16 
17 #define FILE_NAME "tst_netcdf4_c0.nc"
18 #define MAX_NAME 1024
19 
20 int
main()21 main()
22 {
23    printf("\n*** Checking HDF5 file c0.nc.\n");
24    printf("*** Checking HDF5 objcts...");
25    {
26       hid_t fileid, grpid;
27       hsize_t num_obj, i;
28       char obj_name[MAX_NAME];
29 
30       if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
31       if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
32 
33       /* Find the variables. Read their metadata and attributes. */
34       if (H5Gget_num_objs(grpid, &num_obj) < 0) ERR;
35       for (i=0; i<num_obj; i++)
36       {
37 	 /* Get the class (i.e. group, dataset, etc.), and the name of
38 	  * the object. */
39 	 if (H5Gget_objtype_by_idx(grpid, i) < 0) ERR;
40 	 if (H5Gget_objname_by_idx(grpid, i, obj_name, MAX_NAME) < 0) ERR;
41       }
42 
43       if (H5Gclose(grpid) < 0 ||
44 	  H5Fclose(fileid) < 0) ERR;
45    }
46    SUMMARIZE_ERR;
47    FINAL_RESULTS;
48 }
49