/* 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 compound type feature. $Id: tst_compounds.c,v 1.33 2008/04/23 17:01:35 ed Exp $ */ #include #include #include "netcdf.h" #include #define FILE_NAME "tst_compounds.nc" #define SVC_REC "Service_Record" #define BATTLES_WITH_KLINGONS "Number_of_Battles_with_Klingons" #define DATES_WITH_ALIENS "Dates_with_Alien_Hotties" #define STARDATE "Stardate" #define DIM_LEN 3 #define SERVICE_RECORD "Kirk_Service_Record" int main(int argc, char **argv) { #ifdef USE_PARALLEL MPI_Init(&argc, &argv); #endif printf("\n*** Testing netcdf-4 user defined type functions.\n"); printf("*** testing REALLY simple compound variable create..."); { int ncid, typeid, varid; int ndims, nvars, natts, unlimdimid; nc_type xtype; size_t size_in, nfields_in; char name_in[NC_MAX_NAME + 1]; /* Create a file with a compound type. Write a little data. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_compound(ncid, sizeof(int), SVC_REC, &typeid)) ERR; if (nc_insert_compound(ncid, typeid, BATTLES_WITH_KLINGONS, 0, NC_INT)) ERR; if (nc_def_var(ncid, SERVICE_RECORD, typeid, 0, NULL, &varid)) ERR; if (nc_close(ncid)) ERR; /* Open the file and take a peek. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 0 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_vartype(ncid, 0, &xtype)) ERR; if (nc_inq_compound(ncid, xtype, name_in, &size_in, &nfields_in)) ERR; if (strcmp(name_in, SVC_REC) || size_in != sizeof(int) || nfields_in != 1) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing simple compound variable create..."); { int ncid, typeid, varid; size_t nfields; int dimid; int ndims, nvars, natts, unlimdimid; char name[NC_MAX_NAME + 1]; size_t size; nc_type xtype, field_xtype; int dimids[] = {0}, fieldid; int field_ndims, field_sizes[NC_MAX_DIMS]; size_t offset; int i; struct s1 { int i1; int i2; }; struct s1 data[DIM_LEN], data_in[DIM_LEN]; /* Create some phony data. */ for (i=0; i