Previous: Geographic Subsetting in LibCF Next: The LibCF Website Table of contents Frames 2010 Unidata NetCDF Workshop > libcf: A New Library for CF Conventions Support

24.9 LibCF Example
This example illustrates the use of libcf.

 

      /* CReate a file and use nccd_def_file to annotate it. */
      if (nc_create(FILE_NAME_SIMPLE_SIGMA, 0, &ncid)) ERR;
      if (nccf_def_file(ncid, TITLE, HISTORY)) ERR;
      if (nccf_def_latitude(ncid, NLATS, NC_INT, &lat_did, 
			    &lat_vid)) ERR;
      if (nccf_def_longitude(ncid, NLONS, NC_INT, &lon_did, 
			     &lon_vid)) ERR;

      /* Now define sigma level coordinage var and dim. */
      if (nccf_def_lvl_sigma(ncid, "sigma", NC_FLOAT, NLVLS, 
			     &lvl_did, &lvl_vid)) ERR;

      /* Now define the time coordinate. */
      if (nccf_def_time(ncid, "time", NC_UNLIMITED, NC_FLOAT, TIME_UNITS, 
			"time", &time_did, &time_vid)) ERR;

      /* Before we can set the sigma level formula terms, we
       * need to define two variables, the surface pressure and PTOP
       * (a scalar).*/
      dimids[0] = lat_did;
      dimids[1] = lon_did;
      if (nc_def_var(ncid, "ps", NC_FLOAT, 2, dimids, &ps_vid)) ERR;
      if (nc_def_var(ncid, "PTOP", NC_FLOAT, 0, NULL, &ptop_vid)) ERR;

      /* Save the ps and ptop info in the formula terms attribute. */
      if (nccf_def_ft_sigma(ncid, lvl_vid, ps_vid, ptop_vid)) ERR;

      /* Now create a data variable. */
      dimids[0] = time_did;
      dimids[1] = lvl_did;
      dimids[2] = lat_did;
      dimids[3] = lon_did;
      if (nc_def_var(ncid, "data", NC_FLOAT, NDIMS, dimids, &data_vid)) ERR;

      /* End define mode. */
      if (nc_enddef(ncid)) ERR;

      /* Write lats and lons. */
      if (nc_put_var_int(ncid, lat_vid, lat)) ERR;      
      if (nc_put_var_int(ncid, lon_vid, lon)) ERR;      

 


Previous: Geographic Subsetting in LibCF Next: The LibCF Website Table of contents Frames 2010 Unidata NetCDF Workshop > libcf: A New Library for CF Conventions Support