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

23.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
2009 Unidata NetCDF Workshop for Developers and Data Providers > User Defined Types in NetCDF-4