/* This is part of the netCDF package. Copyright 2005 University Corporation for Atmospheric Research/Unidata See COPYRIGHT file for conditions of use. Test netcdf-4 group code. $Id: tst_grps.c,v 1.37 2010/04/07 15:21:28 ed Exp $ */ #include #include "netcdf.h" #define FILE_NAME "tst_grps.nc" #define DIM1_NAME "kingdom" #define DIM1_LEN 3 #define DIM2_NAME "year" #define DIM2_LEN 5 #define VAR1_NAME "Number_of_Beheadings_in_Family" #define DYNASTY "Tudor" #define HENRY_VII "Henry_VII" #define MARGARET "Margaret" #define JAMES_V_OF_SCOTLAND "James_V_of_Scotland" #define MARY_I_OF_SCOTLAND "Mary_I_of_Scotland" #define JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND "James_VI_of_Scotland_and_I_of_England" #define MAX_SIBLING_GROUPS 10 #define NUM_CASTLES_NAME "Number_of_Castles" int main(int argc, char **argv) { printf("\n*** Testing netcdf-4 group functions.\n"); printf("*** testing simple group create..."); { int ncid; char name_in[NC_MAX_NAME + 1]; int henry_vii_id; int grpid_in[MAX_SIBLING_GROUPS], varids_in[MAX_SIBLING_GROUPS]; int dimids_in[MAX_SIBLING_GROUPS], nvars_in, ndims_in, ncid_in; int parent_ncid; char name_out[NC_MAX_NAME + 1]; int num_grps; /* Create a file with one group, a group to contain data about * Henry VII. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_inq_grp_parent(ncid, &parent_ncid) != NC_ENOGRP) ERR; /* This should also work as simple "is this the root group" test */ if (nc_inq_grp_parent(ncid, NULL) != NC_ENOGRP) ERR; strcpy(name_out, HENRY_VII); if (nc_def_grp(ncid, name_out, &henry_vii_id)) ERR; if (nc_inq_grp_parent(henry_vii_id, &parent_ncid)) ERR; if (parent_ncid != ncid) ERR; if (nc_inq_ncid(ncid, HENRY_VII, &ncid_in)) ERR; if (ncid_in != henry_vii_id) ERR; if (nc_inq_ncid(ncid, MARGARET, &ncid_in) != NC_ENOGRP) ERR; if (nc_close(ncid)) ERR; /* Check it out. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grp_parent(ncid, &parent_ncid) != NC_ENOGRP) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; if (num_grps != 1) ERR; if (nc_inq_grps(ncid, NULL, grpid_in)) ERR; if (nc_inq_grpname(ncid, name_in)) ERR; if (strcmp(name_in, "/")) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (nc_inq_grp_parent(grpid_in[0], &parent_ncid)) ERR; if (parent_ncid != ncid) ERR; if (strcmp(name_in, HENRY_VII)) ERR; if (nc_inq_varids(grpid_in[0], &nvars_in, varids_in)) ERR; if (nvars_in != 0) ERR; if (nc_inq_varids(grpid_in[0], &ndims_in, dimids_in)) ERR; if (ndims_in != 0) ERR; if (nc_inq_ncid(ncid, HENRY_VII, &ncid_in)) ERR; if (ncid_in != grpid_in[0]) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing netcdf-3 and group functions..."); { int ncid; char name_in[NC_MAX_NAME + 1]; size_t len_in; /* Create a classic file. */ if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; if (nc_inq_grpname(ncid, name_in)) ERR; if (strcmp(name_in, "/")) ERR; if (nc_inq_grpname_full(ncid, &len_in, name_in)) ERR; if (strcmp(name_in, "/") || len_in != 1) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; /* printf("*** testing use of unlimited dim in parent group..."); */ /* { */ /* #define NDIMS_IN_VAR 1 */ /* #define NDIMS_IN_FILE 2 */ /* #define BABE_LIMIT 3 */ /* #define DIM_NAME1 "Influence" */ /* #define DIM_NAME2 "Babe_Factor" */ /* #define VAR_NAME1 "Court_of_Star_Chamber" */ /* #define VAR_NAME2 "Justice_of_the_Peace" */ /* #define VAR_NAME3 "Bosworth_Field" */ /* int ncid, dimid1, dimid2, varid1, varid2, varid3, henry_vii_id; */ /* int grpid_in, varid_in1, varid_in2, varid_in3; */ /* nc_type xtype_in; */ /* int ndims_in, dimids_in[NDIMS_IN_FILE], dimid1_in, natts; */ /* char name_in[NC_MAX_NAME + 1]; */ /* size_t len_in, index[NDIMS_IN_VAR] = {0}; */ /* long long value = NC_FILL_INT64 + 1, value_in; */ /* /\* Create a file with an unlimited dim and a limited, used by */ /* * variables in child groups. *\/ */ /* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */ /* if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimid1)) ERR; */ /* if (nc_def_dim(ncid, DIM_NAME2, BABE_LIMIT, &dimid2)) ERR; */ /* if (nc_def_grp(ncid, HENRY_VII, &henry_vii_id)) ERR; */ /* if (nc_def_var(henry_vii_id, VAR_NAME1, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid1)) ERR; */ /* if (nc_def_var(henry_vii_id, VAR_NAME2, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid2)) ERR; */ /* if (nc_def_var(henry_vii_id, VAR_NAME3, NC_INT64, NDIMS_IN_VAR, &dimid2, &varid3)) ERR; */ /* /\* Check it out. Find the group by name. *\/ */ /* if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR; */ /* /\* Ensure that dimensions in parent are visible and correct. *\/ */ /* if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR; */ /* if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR; */ /* if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR; */ /* if (strcmp(name_in, DIM_NAME1) || len_in != 0) ERR; */ /* if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR; */ /* if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR; */ /* /\* Check the vars in the group. *\/ */ /* if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR; */ /* if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR; */ /* if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR; */ /* if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR; */ /* if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid1 || natts != 0) ERR; */ /* if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid1 || natts != 0) ERR; */ /* if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid2 || natts != 0) ERR; */ /* /\* Write one value to one variable. *\/ */ /* if (nc_put_var1_longlong(grpid_in, varid_in1, index, &value)) ERR; */ /* /\* Read one value from the second unlim dim variable. It should */ /* * be the fill value. *\/ */ /* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR; */ /* if (value_in != NC_FILL_INT64) ERR; */ /* /\* Read one value from the variable with limited dim. It should */ /* * be the fill value. *\/ */ /* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR; */ /* if (value_in != NC_FILL_INT64) ERR; */ /* /\* Attempt to read beyond end of dimensions to generate error. *\/ */ /* index[0] = BABE_LIMIT; */ /* if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_close(ncid)) ERR; */ /* /\* Check it out again. *\/ */ /* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */ /* /\* Find the group by name. *\/ */ /* if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR; */ /* /\* Ensure that dimensions in parent are visible and correct. *\/ */ /* if (nc_inq_dimids(grpid_in, &ndims_in, dimids_in, 1)) ERR; */ /* if (ndims_in != NDIMS_IN_FILE || dimids_in[0] != dimid1 || dimids_in[1] != dimid2) ERR; */ /* if (nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)) ERR; */ /* if (strcmp(name_in, DIM_NAME1) || len_in != 1) ERR; */ /* if (nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)) ERR; */ /* if (strcmp(name_in, DIM_NAME2) || len_in != BABE_LIMIT) ERR; */ /* /\* Check the vars in the group. *\/ */ /* if (nc_inq_varid(grpid_in, VAR_NAME1, &varid_in1)) ERR; */ /* if (nc_inq_varid(grpid_in, VAR_NAME2, &varid_in2)) ERR; */ /* if (nc_inq_varid(grpid_in, VAR_NAME3, &varid_in3)) ERR; */ /* if (varid_in1 != varid1 || varid_in2 != varid2 || varid_in3 != varid3) ERR; */ /* if (nc_inq_var(grpid_in, varid1, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME1) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid1 || natts != 0) ERR; */ /* if (nc_inq_var(grpid_in, varid2, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME2) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid1 || natts != 0) ERR; */ /* if (nc_inq_var(grpid_in, varid3, name_in, &xtype_in, &ndims_in, &dimid1_in, &natts)) ERR; */ /* if (strcmp(name_in, VAR_NAME3) || xtype_in != NC_INT64 || ndims_in != NDIMS_IN_VAR || */ /* dimid1_in != dimid2 || natts != 0) ERR; */ /* /\* Read one value from the second unlim dim variable. It should */ /* * be the fill value. *\/ */ /* index[0] = 0; */ /* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in)) ERR; */ /* if (value_in != NC_FILL_INT64) ERR; */ /* /\* Read one value from the variable with limited dim. It should */ /* * be the fill value. *\/ */ /* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in)) ERR; */ /* if (value_in != NC_FILL_INT64) ERR; */ /* /\* Attempt to read beyond end of dimensions to generate error. *\/ */ /* index[0] = BABE_LIMIT; */ /* if (nc_get_var1_longlong(grpid_in, varid_in1, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_get_var1_longlong(grpid_in, varid_in2, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_get_var1_longlong(grpid_in, varid_in3, index, &value_in) != NC_EINVALCOORDS) ERR; */ /* if (nc_close(ncid)) ERR; */ /* } */ /* SUMMARIZE_ERR; */ printf("*** testing simple nested group creates..."); { int ncid, grp_ncid; int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id; int james_i_of_england_id; char name_in[NC_MAX_NAME + 1]; char full_name[NC_MAX_NAME * 10], full_name_in[NC_MAX_NAME * 10]; int grpid_in[MAX_SIBLING_GROUPS]; int grp_in; int num_grps; size_t len; /* Create a file with some nested groups in it, suitable * to storing information about the Tudor dynasty of England. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, HENRY_VII, &henry_vii_id)) ERR; if (nc_def_grp(henry_vii_id, MARGARET, &margaret_id)) ERR; if (nc_def_grp(margaret_id, JAMES_V_OF_SCOTLAND, &james_v_of_scotland_id)) ERR; if (nc_def_grp(james_v_of_scotland_id, MARY_I_OF_SCOTLAND, &mary_i_of_scotland_id)) ERR; if (nc_def_grp(mary_i_of_scotland_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &james_i_of_england_id)) ERR; strcpy(full_name, "/"); if (nc_inq_grpname_full(ncid, &len, full_name_in)) ERR; if (len != 1 || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grpname_len(ncid, &len)) ERR; if (len != 1) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != ncid) ERR; if (nc_inq_grp_ncid(ncid, HENRY_VII, NULL)) ERR; if (nc_inq_grp_ncid(ncid, HENRY_VII, &grp_ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; if (num_grps != 1) ERR; if (nc_inq_grps(ncid, NULL, grpid_in)) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, HENRY_VII)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, HENRY_VII); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; if (len != strlen(HENRY_VII) + 1 || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; if (nc_inq_grp_ncid(grpid_in[0], MARGARET, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, MARGARET)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, "/"); strcat(full_name, MARGARET); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; if (len != strlen(full_name) || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; if (nc_inq_grp_ncid(grpid_in[0], JAMES_V_OF_SCOTLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, JAMES_V_OF_SCOTLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, "/"); strcat(full_name, JAMES_V_OF_SCOTLAND); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; if (len != strlen(full_name) || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; if (nc_inq_grp_ncid(grpid_in[0], MARY_I_OF_SCOTLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, MARY_I_OF_SCOTLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, "/"); strcat(full_name, MARY_I_OF_SCOTLAND); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; if (len != strlen(full_name) || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; if (nc_inq_grp_ncid(grpid_in[0], JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, "/"); strcat(full_name, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; if (len != strlen(full_name) || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; if (nc_close(ncid)) ERR; /* Check it out. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grp_ncid(ncid, HENRY_VII, &grp_ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; if (num_grps != 1) ERR; if (nc_inq_grps(ncid, NULL, grpid_in)) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, HENRY_VII)) ERR; if (grpid_in[0] != grp_ncid) ERR; if (nc_inq_grp_ncid(grpid_in[0], MARGARET, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, MARGARET)) ERR; if (grpid_in[0] != grp_ncid) ERR; if (nc_inq_grp_ncid(grpid_in[0], JAMES_V_OF_SCOTLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, JAMES_V_OF_SCOTLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; if (nc_inq_grp_ncid(grpid_in[0], MARY_I_OF_SCOTLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, MARY_I_OF_SCOTLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; if (nc_inq_grp_ncid(grpid_in[0], JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR; if (grpid_in[0] != grp_ncid) ERR; /* Close up shop. */ if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing simple sibling group creates..."); { int ncid; int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id; int james_i_of_england_id, tudor_id; char name_in[NC_MAX_NAME + 1]; int grpid_in[MAX_SIBLING_GROUPS]; int ncid_in; int num_grps; int dynasty; /* Create a file with one group, and beneath it a group for each Tudor. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; if (nc_def_grp(tudor_id, HENRY_VII, &henry_vii_id)) ERR; if (nc_def_grp(tudor_id, MARGARET, &margaret_id)) ERR; if (nc_def_grp(tudor_id, JAMES_V_OF_SCOTLAND, &james_v_of_scotland_id)) ERR; if (nc_def_grp(tudor_id, MARY_I_OF_SCOTLAND, &mary_i_of_scotland_id)) ERR; if (nc_def_grp(tudor_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &james_i_of_england_id)) ERR; if (nc_close(ncid)) ERR; /* Make sure we've got all the tudors where we want them. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(dynasty, name_in)) ERR; if (strcmp(name_in, DYNASTY)) ERR; if (nc_inq_grps(dynasty, &num_grps, grpid_in)) ERR; if (num_grps != 5) ERR; if (nc_inq_ncid(dynasty, HENRY_VII, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, HENRY_VII)) ERR; if (nc_inq_ncid(dynasty, MARGARET, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, MARGARET)) ERR; if (nc_inq_ncid(dynasty, JAMES_V_OF_SCOTLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, JAMES_V_OF_SCOTLAND)) ERR; if (nc_inq_ncid(dynasty, MARY_I_OF_SCOTLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, MARY_I_OF_SCOTLAND)) ERR; if (nc_inq_ncid(dynasty, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing more group attributes..."); { int ncid, num_grps, dynasty, ncid_in; int grpid_in[MAX_SIBLING_GROUPS]; int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id; int james_i_of_england_id, tudor_id; int num_castles_henry_vii = 1, num_castles_margaret = 0, num_castles_james_v = 2; int num_castles_mary_i = 3, num_castles_james_vi = 4; char name_in[NC_MAX_NAME + 1]; /* Create a file with one group, and beneath it a group for each * Tudor. We will have some attributes in the groups.*/ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; if (nc_def_grp(tudor_id, HENRY_VII, &henry_vii_id)) ERR; if (nc_put_att_int(henry_vii_id, NC_GLOBAL, NUM_CASTLES_NAME, NC_INT, 1, &num_castles_henry_vii)) ERR; if (nc_def_grp(tudor_id, MARGARET, &margaret_id)) ERR; if (nc_put_att_int(margaret_id, NC_GLOBAL, NUM_CASTLES_NAME, NC_INT, 1, &num_castles_margaret)) ERR; if (nc_def_grp(tudor_id, JAMES_V_OF_SCOTLAND, &james_v_of_scotland_id)) ERR; if (nc_put_att_int(james_v_of_scotland_id, NC_GLOBAL, NUM_CASTLES_NAME, NC_INT, 1, &num_castles_james_v)) ERR; if (nc_def_grp(tudor_id, MARY_I_OF_SCOTLAND, &mary_i_of_scotland_id)) ERR; if (nc_put_att_int(mary_i_of_scotland_id, NC_GLOBAL, NUM_CASTLES_NAME, NC_INT, 1, &num_castles_mary_i)) ERR; if (nc_def_grp(tudor_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &james_i_of_england_id)) ERR; if (nc_put_att_int(james_i_of_england_id, NC_GLOBAL, NUM_CASTLES_NAME, NC_INT, 1, &num_castles_james_vi)) ERR; if (nc_close(ncid)) ERR; /* Make sure we've got all the tudors where we want them. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(dynasty, name_in)) ERR; if (strcmp(name_in, DYNASTY)) ERR; if (nc_inq_grps(dynasty, &num_grps, grpid_in)) ERR; if (num_grps != 5) ERR; if (nc_inq_ncid(dynasty, HENRY_VII, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, HENRY_VII)) ERR; if (nc_inq_ncid(dynasty, MARGARET, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, MARGARET)) ERR; if (nc_inq_ncid(dynasty, JAMES_V_OF_SCOTLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, JAMES_V_OF_SCOTLAND)) ERR; if (nc_inq_ncid(dynasty, MARY_I_OF_SCOTLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, MARY_I_OF_SCOTLAND)) ERR; if (nc_inq_ncid(dynasty, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &ncid_in)) ERR; if (nc_inq_grpname(ncid_in, name_in)) ERR; if (strcmp(name_in, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND)) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing groups and dimensions..."); { int ncid; int tudor_id; int num_grps; int dimid, dimid_in, dynasty; size_t len_in; char name_in[NC_MAX_NAME + 1]; /* Create a file with one group, and within that group, a dimension.*/ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; if (nc_def_dim(tudor_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_close(ncid)) ERR; /* Now check the file to see if the dimension is there. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; if (num_grps != 1) ERR; if (nc_inq_grpname(dynasty, name_in)) ERR; if (strcmp(name_in, DYNASTY)) ERR; if (nc_inq_dimid(dynasty, DIM1_NAME, &dimid_in)) ERR; if (dimid_in != 0) ERR; if (nc_inq_dimname(dynasty, 0, name_in)) ERR; if (strcmp(name_in, DIM1_NAME)) ERR; if (nc_inq_dim(dynasty, 0, name_in, &len_in)) ERR; if (strcmp(name_in, DIM1_NAME)) ERR; if (len_in != DIM1_LEN) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing groups and vars..."); { int ncid, ndims_in; int tudor_id; int num_grps; int dimid, dynasty, varid; size_t len_in; int natts_in; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; int dimids_in[MAX_SIBLING_GROUPS]; /* Create a file with one group, and within that group, a * dimension, and a variable.*/ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; if (nc_def_dim(tudor_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(tudor_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_close(ncid)) ERR; /* Now check the file to see if the dimension and variable are * there. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; if (num_grps != 1) ERR; if (nc_inq_dim(dynasty, 0, name_in, &len_in)) ERR; if (strcmp(name_in, DIM1_NAME) || len_in != DIM1_LEN) ERR; if (nc_inq_var(dynasty, 0, name_in, &xtype_in, &ndims_in, dimids_in, &natts_in)) ERR; if (strcmp(name_in, VAR1_NAME) || xtype_in != NC_INT || ndims_in != 1 || dimids_in[0] != 0 || natts_in != 0) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing group functions in netCDF classic file..."); { int ncid; int num_grps; /* Create a classic file.*/ if (nc_create(FILE_NAME, 0, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; if (num_grps) ERR; if (nc_close(ncid)) ERR; /* Now check the file to see if the dimension and variable are * there. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; if (num_grps) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing groups and vars..."); { int ncid, ndims_in; int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id; int james_i_of_england_id, tudor_id; int dimids_in[MAX_SIBLING_GROUPS]; int num_grps; int dimid, dynasty, varid; size_t len_in; int natts_in; int grpids_in[10]; nc_type xtype_in; char name_in[NC_MAX_NAME + 1]; int data_out[DIM1_LEN] = {-99, 0, 99}, data_in[DIM1_LEN]; int i, j; /* Create a file with a group, DYNASTY, containing 5 groups, * each with a dimension and one int variable. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_grp(ncid, DYNASTY, &tudor_id)) ERR; /* Henry VII. */ if (nc_def_grp(tudor_id, HENRY_VII, &henry_vii_id)) ERR; if (nc_def_dim(henry_vii_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(henry_vii_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_put_var_int(henry_vii_id, varid, data_out)) ERR; /* Margaret. */ if (nc_def_grp(tudor_id, MARGARET, &margaret_id)) ERR; if (nc_def_dim(margaret_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(margaret_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_put_var_int(margaret_id, varid, data_out)) ERR; /* James V of Scotland. */ if (nc_def_grp(tudor_id, JAMES_V_OF_SCOTLAND, &james_v_of_scotland_id)) ERR; if (nc_def_dim(james_v_of_scotland_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(james_v_of_scotland_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_put_var_int(james_v_of_scotland_id, varid, data_out)) ERR; /* Mary I of Scotland. */ if (nc_def_grp(tudor_id, MARY_I_OF_SCOTLAND, &mary_i_of_scotland_id)) ERR; if (nc_def_dim(mary_i_of_scotland_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(mary_i_of_scotland_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_put_var_int(mary_i_of_scotland_id, varid, data_out)) ERR; /* James VI of Scotland and I of England. */ if (nc_def_grp(tudor_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &james_i_of_england_id)) ERR; if (nc_def_dim(james_i_of_england_id, DIM1_NAME, DIM1_LEN, &dimid)) ERR; if (nc_def_var(james_i_of_england_id, VAR1_NAME, NC_INT, 1, &dimid, &varid)) ERR; if (nc_put_var_int(james_i_of_england_id, varid, data_out)) ERR; /*nc_show_metadata(ncid);*/ /* Check it out. */ if (nc_inq_grps(ncid, &num_grps, &dynasty)) ERR; if (num_grps != 1) ERR; if (nc_inq_grps(dynasty, &num_grps, grpids_in)) ERR; if (num_grps != 5) ERR; for (i = 0; i < 5; i++) { if (nc_inq_dim(grpids_in[i], i, name_in, &len_in)) ERR; if (strcmp(name_in, DIM1_NAME) || len_in != DIM1_LEN) ERR; if (nc_inq_var(grpids_in[i], 0, name_in, &xtype_in, &ndims_in, dimids_in, &natts_in)) ERR; if (strcmp(name_in, VAR1_NAME) || xtype_in != NC_INT || ndims_in != 1 || dimids_in[0] != i || natts_in != 0) ERR; if (nc_get_var_int(grpids_in[i], 0, data_in)) ERR; for (j=0; j