Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 
Previous: Compound Type CDL Example Next: Using Enums Table of contents Frames User guide
2008 Unidata NetCDF Workshop for Developers and Data Providers > User Defined Types in NetCDF-4

16.5 Using Compound Types
Compound types can store arrays of structures.

 

The following example, from libsrc4/tst_compounds.c, creates a simple compound type.

   struct s1 
   {
	 int i1;
	 int i2;
   };
   struct s1 data[DIM_LEN], data_in[DIM_LEN];

      /* Create a file with a global attribute of compound type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_compound(ncid, sizeof(struct s1), SVC_REC, &typeid)) ERR;
      if (nc_insert_compound(ncid, typeid, BATTLES_WITH_KLINGONS, 
			     HOFFSET(struct s1, i1), NC_INT)) ERR;
      if (nc_insert_compound(ncid, typeid, DATES_WITH_ALIENS, 
			     HOFFSET(struct s1, i2), NC_INT)) ERR;
      if (nc_put_att(ncid, NC_GLOBAL, SERVICE_RECORD, typeid, 3, data)) ERR;
      if (nc_close(ncid)) ERR;

 


Previous: Compound Type CDL Example Next: Using Enums Table of contents Frames User guide
2008 Unidata NetCDF Workshop for Developers and Data Providers > User Defined Types in NetCDF-4

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690