コード例 #1
0
ファイル: fort-v2compat.c プロジェクト: akiyoshi/wrf-fire
/*
 * Open an existing netCDF file for access.
 */
static int
c_ncopn(
    const char *pathname,	/* file name for netCDF to be opened */
    int rwmode,			/* either NCWRITE or NCNOWRIT */
    int *rcode			/* returned error code */
)
{
    int ncid = -1;

#if CDF_ROUTINE_NAME
    cdf_routine_name = "NCOPN";
#endif

    if (rwmode != NC_NOWRITE && rwmode != NC_WRITE)
    {
        *rcode = NC_EINVAL;
        nc_advise("NCOPN", *rcode,
		"bad flag, did you forget to include netcdf.inc?");
    }
    else
    {
	if (pathname == NULL) {
	    *rcode = NC_EINVAL;
	}
	else
	{
	    *rcode = ((ncid = ncopen (pathname, rwmode)) == -1)
			? ncerr
			: 0;
	}

	if (*rcode != 0)
	{
	    nc_advise("NCOPN", *rcode, "");
	    *rcode = ncerr;
	}
    }

    return ncid;
}
コード例 #2
0
ファイル: nf_v2compat.c プロジェクト: BillTian/netcdf-fortran
/*
 * Open an existing netCDF file for access.
 */
extern int
c_ncopn(
    const char *pathname,	/* file name for netCDF to be opened */
    int rwmode,			/* either NCWRITE or NCNOWRIT */
    int *rcode			/* returned error code */
)
{
    int ncid = -1;

    /* Include NC_LOCK in check, in case NC_LOCK is ever implemented */
    if (rwmode < 0 ||
	rwmode > NC_WRITE + NC_SHARE + NC_CLASSIC_MODEL + NC_LOCK)
    {
        *rcode = NC_EINVAL;
        nc_advise("NCOPN", *rcode,
		"bad flag, did you forget to include netcdf.inc?");
    }
    else
    {
	if (pathname == NULL) {
	    *rcode = NC_EINVAL;
	}
	else
	{
	    *rcode = ((ncid = ncopen (pathname, rwmode)) == -1)
			? ncerr
			: 0;
	}

	if (*rcode != 0)
	{
	    nc_advise("NCOPN", *rcode, "");
	    *rcode = ncerr;
	}
    }

    return ncid;
}
コード例 #3
0
ファイル: tst_v2.c プロジェクト: ArtisticCoding/libmesh
int
main(int argc, char **argv)
{
   /*nc_set_log_level(3);*/
   printf("\n*** Testing netcdf-4 v2 API functions.\n");
   printf("*** testing simple opens and creates...");
   {
      int ncid, varid, varid_in, dimids[2];

      /* Turn off the crashing whenever there is a problem. */
      ncopts = NC_VERBOSE;

      /* Create an empty file. */
      if ((ncid = nccreate(FILE_NAME, NC_CLOBBER)) == -1) ERR;
      if (ncclose(ncid) == -1) ERR;

      /* Open the file, go into redef, and add some dims and vars. */
      if ((ncid = ncopen(FILE_NAME, NC_WRITE)) == -1) ERR;
      if (ncredef(ncid) == -1) ERR;
      if ((dimids[0] = ncdimdef(ncid, DIM1_NAME, DIM1_SIZE)) == -1) ERR;
      if ((dimids[1] = ncdimdef(ncid, DIM2_NAME, DIM2_SIZE)) == -1) ERR;
      if ((varid = ncvardef(ncid, VAR1_NAME, NC_DOUBLE, NDIMS, dimids)) == -1) ERR;
      if ((varid_in = ncvarid(ncid, VAR1_NAME)) == -1) ERR;
      if (varid_in != varid) ERR;
      if ((varid = ncvardef(ncid, VAR2_NAME, NC_INT, NDIMS, dimids)) == -1) ERR;
      if ((varid_in = ncvarid(ncid, VAR2_NAME)) == -1) ERR;
      if (varid_in != varid) ERR;
      if ((varid = ncvardef(ncid, VAR3_NAME, NC_SHORT, NDIMS, dimids)) == -1) ERR;
      if ((varid_in = ncvarid(ncid, VAR3_NAME)) == -1) ERR;
      if (varid_in != varid) ERR;
      if (ncclose(ncid) == -1) ERR;
   }

   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
コード例 #4
0
ファイル: micreateimage.c プロジェクト: BIC-MNI/emma
/* ----------------------------- MNI Header -----------------------------------
@NAME       : OpenFiles
@INPUT      : parent_file -> The name of the minc file to create the child
                             from, or NULL if there is no parent file.
              child_file  -> The name of the child file to be created.
              tm_stamp    -> A string to be prepended to the history attribute.
@OUTPUT     : parent_CDF  -> The cdfid of the opened parent file, or -1 if
                             no parent file was given.
              child_CDF   -> The cdfid of the created child file.
@RETURNS    : TRUE if all went well
              FALSE if error opening parent file (but only if one was supplied)
              FALSE if error creating child file
@DESCRIPTION: Opens the (optional) parent MINC file, and creates the (required)
              new MINC file.  Also creates the root variable (using
              micreate_std_variable) in the child file.
@METHOD     :
@GLOBALS    : none
@CALLS      : NetCDF routines
              MINC routines
@CREATED    : May 31, 1993 by MW
@MODIFIED   : Aug 11, 1993, GPW - added provisions for no parent file.
              Oct 27, 1993, GPW - moved from micreate.c to micreateimage.c;
              removed copying of attributes and history update; renamed
              from CreateChild to OpenFiles.
---------------------------------------------------------------------------- */
Boolean OpenFiles (char parent_file[], char child_file[],
                   int *parent_CDF,    int *child_CDF)
{
   struct stat statbuf;		/* used to check that created file exists */

   /*
    * If a filename for the parent MINC file was supplied, open the file;
    * else return -1 for *parent_CDF.
    */
   
   if (parent_file != NULL)
   {
      *parent_CDF = ncopen (parent_file, NC_NOWRITE);
      if (*parent_CDF == MI_ERROR)
      {
         sprintf (ErrMsg, "Error opening input file %s: %s\n", 
		  parent_file, NCErrMsg (ncerr, errno));
	 return (FALSE);
      }
   }
   else
   {
      *parent_CDF = -1;
   }

   /* 
    * Create the child file, bomb if any error.  N.B. we call nccreate() 
    * with a mode of NC_NOCLOBBER here because if we use NC_CLOBBER and 
    * the file is uncreatable (eg. permission denied), then the NetCDF
    * code incorrectly attempts to delete the file; this results in
    * errno being clobbered, so we'd print out an inaccurate error 
    * message here.
    */
   
   *child_CDF = nccreate (child_file, 
			  gClobberFlag ? NC_CLOBBER : NC_NOCLOBBER);
   if (*child_CDF == MI_ERROR) 
   {
      sprintf (ErrMsg, "Error creating file %s: %s\n",
               child_file, NCErrMsg (ncerr, errno));
      ncclose (*parent_CDF);
      return (FALSE);
   }

   /* 
    * Now just check to make sure the file exists and has non-zero size
    * (because NetCDF fails to report disk full!)
    */

   if (stat (child_file, &statbuf) != 0)
   {
      sprintf (ErrMsg, "File %s was not created: disk may be full\n",
	       child_file);
      ncclose (*parent_CDF);
      ncclose (*child_CDF);
      return (FALSE);
   }
/*
   if (statbuf.st_size == 0)
   {
      sprintf (ErrMsg, "Error creating file %s: disk may be full\n",
	       child_file);
      ncclose (*parent_CDF);
      ncclose (*child_CDF);
      return (FALSE);
   }      
*/   
#ifdef DEBUG
   printf ("OpenFiles:\n");
   printf (" Parent file %s, CDF %d\n", parent_file, *parent_CDF);
   printf (" Child file  %s, CDF %d\n\n", child_file, *child_CDF);
#endif

   /* The parent file is now open for reading, and the child file is */
   /* created and opened for definition.                             */
   
   return (TRUE);
}      /* OpenFiles () */
コード例 #5
0
ファイル: st04c.c プロジェクト: gavin971/ncl
int main(int argc, char *argv[])
{
    int i, j, d, h;
    int appid, wid, cnid, vcid, stid, txid, amid, mpid, tmid, stdmid;
    long stid_len;
    int vfield, vfield2, sfield, sfield2;
    int rlist;
    ng_size_t len_dims[2];
    long strt[1], cnt[1];
    long latlen, lonlen;
    long timelen;
    int *timestep;
    int ncid[6], uid, vid, u5id, v5id, pid, tid;
    int latid, lonid;
    float *lon, *lat;
    float *X, *Y;
    char  filename[256];
    char  *rftime;
    const char *dir = _NGGetNCARGEnv("data");
    char hour[3], day[3], mainstring[17];
    extern void get_2d_array(float *, long, long, int, int, long);
    char const *wks_type = "x11";

/*
 * Initialize the high level utility library
 */
    NhlInitialize();
/*
 * Create an application object.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlRLSetString(rlist,NhlNappDefaultParent,"True");
    NhlCreate(&appid,"st04",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./st04c.ncgm");
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",
                  NhlncgmWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 * Create an X workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }

    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"st04c.ps");
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",NhlpsWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"st04c.pdf");
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",NhlpdfWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
             !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
/*
 * Create a cairo PS/PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"st04c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",NhlcairoDocumentWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"st04c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetString(rlist,NhlNwkColorMap,"temp1");
        NhlCreate(&wid,"st04Work",NhlcairoImageWorkstationClass,appid,rlist);
    }
/*
 * Open the netCDF files.
 */
    for( i = 0; i <= 5; i++ ) {
        sprintf( filename, "%s/cdf/%s", dir, cdffiles[i] );
        ncid[i] = ncopen(filename,NC_NOWRITE);
    }
/*
 * Get the lat/lon dimensions (they happen to be the
 * same for all files in this case)
 */
    latid = ncdimid(ncid[0],"lat");
    lonid = ncdimid(ncid[0],"lon");
    ncdiminq(ncid[0],latid,(char *)0,&latlen);
    ncdiminq(ncid[0],lonid,(char *)0,&lonlen);
    len_dims[0] = latlen;
    len_dims[1] = lonlen;
/*
 * Get the variable ids
 */
    uid = ncvarid(ncid[0],"u");
    vid = ncvarid(ncid[1],"v");
    pid = ncvarid(ncid[2],"p");
    tid = ncvarid(ncid[3],"t");
    u5id = ncvarid(ncid[4],"u");
    v5id = ncvarid(ncid[5],"v");
    latid = ncvarid(ncid[0],"lat");
    lonid = ncvarid(ncid[0],"lon");
/*
 * allocate space for arrays
 */
    X = (float *)malloc(sizeof(float)*latlen*lonlen);
    Y = (float *)malloc(sizeof(float)*latlen*lonlen);
    lat = (float *)malloc(sizeof(float)*latlen);
    lon = (float *)malloc(sizeof(float)*lonlen);
/*
 * Get lat/lon values (they are the same for all files)
 */
    strt[0] = 0;
    cnt[0] = latlen;
    ncvarget(ncid[0],latid,(long const *)strt,(long const *)cnt,lat);
    cnt[0] = lonlen;
    ncvarget(ncid[0],lonid,(long const *)strt,(long const *)cnt,lon);
/*
 * Get U and V data values
 */
    get_2d_array(X,latlen,lonlen,ncid[0],uid,0);
    get_2d_array(Y,latlen,lonlen,ncid[1],vid,0);
/*
 * Create a VectorField of the surface wind data
 */
    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,X,2,len_dims);
    NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,Y,2,len_dims);
    NhlRLSetFloat(rlist,NhlNvfXCStartV,lon[0]);
    NhlRLSetFloat(rlist,NhlNvfYCStartV,lat[0]);
    NhlRLSetFloat(rlist,NhlNvfXCEndV,lon[lonlen-1]);
    NhlRLSetFloat(rlist,NhlNvfYCEndV,lat[latlen-1]);
    NhlRLSetFloat(rlist,NhlNvfMissingUValueV,-9999.0);
    NhlCreate(&vfield,"VectorField",NhlvectorFieldClass,appid,rlist);
/*
 * Create a VectorField of 500 millibar wind data
 *
 * Get U and V values
 */
    get_2d_array(X,latlen,lonlen,ncid[4],u5id,0);
    get_2d_array(Y,latlen,lonlen,ncid[5],v5id,0);

    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,X,2,len_dims);
    NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,Y,2,len_dims);
    NhlRLSetFloat(rlist,NhlNvfXCStartV,lon[0]);
    NhlRLSetFloat(rlist,NhlNvfYCStartV,lat[0]);
    NhlRLSetFloat(rlist,NhlNvfXCEndV,lon[lonlen-1]);
    NhlRLSetFloat(rlist,NhlNvfYCEndV,lat[latlen-1]);
    NhlRLSetFloat(rlist,NhlNvfMissingUValueV,-9999.0);
    NhlCreate(&vfield2,"VectorField",NhlvectorFieldClass,appid,rlist);
/*
 * Create a ScalarField of surface pressure 
 *
 * Get P data values
 */
    get_2d_array(X,latlen,lonlen,ncid[2],pid,0);

    for( i = 0; i < latlen*lonlen; i++ ) {
        if( X[i] != -9999.0 ) {
            X[i] /= 100.;
        }
    }

    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,X,2,len_dims);
    NhlRLSetFloat(rlist,NhlNsfXCStartV,lon[0]);
    NhlRLSetFloat(rlist,NhlNsfYCStartV,lat[0]);
    NhlRLSetFloat(rlist,NhlNsfXCEndV,lon[lonlen-1]);
    NhlRLSetFloat(rlist,NhlNsfYCEndV,lat[latlen-1]);
    NhlRLSetFloat(rlist,NhlNsfMissingValueV,-9999.0);
    NhlCreate(&sfield,"ScalarField",NhlscalarFieldClass,appid,rlist);
/*
 * Create a ScalarField of surface temperature 
 * (convert from Kelvin to Farenheit)
 *
 * Get T data values
 */
    get_2d_array(X,latlen,lonlen,ncid[3],tid,0);
/*
 * Convert to Fahrenheit
 */
    for( i = 0; i < latlen*lonlen; i++ ) {
        if( X[i] != -9999.0) {
            X[i] = (X[i] - 273.15) * 9.0/5.0 + 32.0;
        }
    }

    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,X,2,len_dims);
    NhlRLSetFloat(rlist,NhlNsfXCStartV,lon[0]);
    NhlRLSetFloat(rlist,NhlNsfYCStartV,lat[0]);
    NhlRLSetFloat(rlist,NhlNsfXCEndV,lon[lonlen-1]);
    NhlRLSetFloat(rlist,NhlNsfYCEndV,lat[latlen-1]);
    NhlRLSetFloat(rlist,NhlNsfMissingValueV,-9999.0);
    NhlCreate(&sfield2,"ScalarField2",NhlscalarFieldClass,appid,rlist);
/*
 * Create a ContourPlot with surface temperature data
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNcnFillOn,"true");
    NhlRLSetString(rlist,NhlNcnLinesOn,"false");
    NhlRLSetString(rlist,NhlNcnFillDrawOrder,"predraw");
    NhlRLSetInteger(rlist,NhlNcnScalarFieldData,sfield2);
    NhlCreate(&cnid,"contourplot",NhlcontourPlotClass,wid,rlist);
/*
 * Create a VectorPlot with the surface wind and pressure data
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNvcUseScalarArray,"true");
    NhlRLSetInteger(rlist,NhlNvcVectorFieldData,vfield);
    NhlRLSetInteger(rlist,NhlNvcScalarFieldData,sfield);
    NhlCreate(&vcid,"vectorplot",NhlvectorPlotClass,wid,rlist);
/*
 * Create a StreamlinePlot with 500 mb wind data
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNpmTitleDisplayMode,"always");
    NhlRLSetString(rlist,NhlNtiMainFuncCode,"~");
    NhlRLSetInteger(rlist,NhlNstVectorFieldData,vfield2);
    NhlCreate(&stid,"streamlineplot",NhlstreamlinePlotClass,wid,rlist);
/*
 * Create an annotation used to explain the streamline data
 */
    NhlCreate(&txid,"streamlineplotanno",NhltextItemClass,wid,0);
    amid = NhlAddAnnotation(stid,txid);
/*
 * Create a map object
 */
    NhlRLClear(rlist);
/*    NhlRLSetString(rlist,NhlNvpUseSegments,"true"); */
    NhlCreate(&mpid,"mapplot",NhlmapPlotClass,wid,rlist);
/*
 * Overlay everything on the MapPlot. The last object overlaid will
 * appear on top
 */
    NhlAddOverlay(mpid,cnid,-1);
    NhlAddOverlay(mpid,vcid,-1);
    NhlAddOverlay(mpid,stid,-1);
/*
 * Variables for manipulating the title string
 */
    tmid = ncdimid(ncid[1],"timestep");
    ncdiminq(ncid[1],tmid,(char *)0,&timelen);
    tmid = ncvarid(ncid[1],"timestep");
    timestep = (int *)malloc(sizeof(int)*timelen);

    strt[0] = 0;
    cnt[0] = timelen;
    ncvarget(ncid[1],tmid,(long const *)strt,(long const *)cnt,timestep);
    sprintf( hour, "00");
    sprintf( day, "05");
    
    stdmid = ncdimid(ncid[1],"timelen");
    ncdiminq(ncid[1], stdmid, (char *)0, &stid_len );
    tmid = ncvarid(ncid[1],"reftime");
    rftime = (char *)malloc((stid_len+1)*sizeof(char));

    strt[0] = 0; cnt[0] = stid_len;
    ncvarget(ncid[1],tmid,(long const *)strt,(long const *)cnt,rftime);

    for( i = 0; i <= TIMESTEPS-1; i++ ) {
        if (i != 17 && i != 36 && i != 37) {
/*
 * Figure out the hour and day from the timestep, convert to strings
 * and build the title string
 */
            d = timestep[i] / 24 + 5;
            h = timestep[i] % 24;
            if (h > 9) {
                sprintf( hour, "%d", h );
            }
            else {
                sprintf( hour, "0%d", h );
            }
            if (d > 9) {
                sprintf(day, "%d", d );
            }
            else {
                sprintf(day, "0%d", d );
            }
/*
 * Set the new title string
 */
			strcpy(mainstring, rftime);
            sprintf(&mainstring[8], "%2s %2s:00", day, hour);
            printf("%s\n",mainstring);
            NhlRLClear(rlist);
            NhlRLSetString(rlist,NhlNtiMainString,mainstring);
            NhlSetValues(stid,rlist);
/*
 * Modify the data objects with data for the current time step
 *
 * Get U and V values
 */         
            get_2d_array(X,latlen,lonlen,ncid[0],uid,i);
            get_2d_array(Y,latlen,lonlen,ncid[1],vid,i);

            NhlRLClear(rlist);
            NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,X,2,len_dims);
            NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,Y,2,len_dims);
            NhlSetValues(vfield,rlist);
/*
 * Get U and V values
 */
            get_2d_array(X,latlen,lonlen,ncid[4],u5id,i);
            get_2d_array(Y,latlen,lonlen,ncid[5],v5id,i);

            NhlRLClear(rlist);
            NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,X,2,len_dims);
            NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,Y,2,len_dims);
            NhlSetValues(vfield2,rlist);
/*
 * Get P values
 */
            get_2d_array(X,latlen,lonlen,ncid[2],pid,i);

            for( j = 0; j < latlen*lonlen; j++ ) {
                if( X[j] != -9999.0 ) {
                    X[j] /= 100.;
                }
            }
            NhlRLClear(rlist);
            NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,X,2,len_dims);
            NhlSetValues(sfield,rlist);
/*
 * Get T values
 */
            get_2d_array(X,latlen,lonlen,ncid[3],tid,i);
/*
 * Convert to Fahrenheit
 */
            for( j = 0; j < latlen*lonlen; j++ ) {
                if( X[j] != -9999.0) {
                    X[j] = (X[j] - 273.15) * 9.0/5.0 + 32.0;
                }
            }

            NhlRLClear(rlist);
            NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,X,2,len_dims);
            NhlSetValues(sfield2,rlist);
/* 
 * Draw the plot
 */
            NhlDraw(mpid);
            NhlFrame(wid);
        }
    }
/* 
 *  Destroy the workstation object and exit.
 */
    NhlDestroy(wid);
    NhlClose();
    exit(0);
}
コード例 #6
0
ファイル: tst_vars2.c プロジェクト: mmase/wgrib2
int
main(int argc, char **argv)
{
   int ncid, dimids[NUM_DIMS];
   int varid;
   int nvars_in, varids_in[NUM_DIMS];
   signed char fill_value = 42, fill_value_in;
   nc_type xtype_in;
   size_t len_in;
   char name_in[NC_MAX_NAME + 1];
   int attnum_in;
   int cnum;

#ifdef USE_PARALLEL
   MPI_Init(&argc, &argv);
#endif

   printf("\n*** Testing netcdf-4 variable functions, even more.\n");
   for (cnum = 0; cnum < MAX_CNUM; cnum++)
   {
      int cmode;
      
      switch(cnum)
      {
         case 0:
            printf("*** Testing with classic format:\n");
            cmode = 0;
            break;
         case 1:
            printf("*** Testing with 64-bit offset format:\n");
            cmode = NC_64BIT_OFFSET;
            break;
         case 2:
            printf("*** Testing with HDF5:\n");
            cmode = NC_NETCDF4|NC_CLOBBER;
            break;
         case 3:
            printf("*** Testing with HDF5, netCDF Classic Model:\n");
            cmode = NC_CLASSIC_MODEL | NC_NETCDF4;
      }

      printf("**** testing simple fill value attribute creation...");
      {
         /* Create a netcdf-4 file with one scalar var. Add fill
          * value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, 0, NULL, &varid)) ERR;
         if (nc_enddef(ncid)) ERR;
         if (nc_redef(ncid)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;              
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
         if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
         if (nvars_in != 1 || varids_in[0] != 0) ERR;
         if (nc_inq_varname(ncid, 0, name_in)) ERR;
         if (strcmp(name_in, VAR_NAME)) ERR;
         if (nc_inq_att(ncid, varid, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, varid, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing simple fill value with data read...");
      {
         size_t start[NUM_DIMS], count[NUM_DIMS];
         signed char data = 99, data_in;

         /* Create a netcdf-4 file with one unlimited dim and one
          * var. Add fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         if (nc_enddef(ncid)) ERR;
         if (nc_redef(ncid)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_enddef(ncid)) ERR;

         /* Write the second record. */
         start[0] = 1;
         count[0] = 1;
         if (nc_put_vara_schar(ncid, varid, start, count, &data)) ERR;

         /* Read the first record, it should be the fill value. */
         start[0] = 0;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != fill_value) ERR;

         /* Read the second record, it should be the value we just wrote
          * there. */
         start[0] = 1;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != data) ERR;
      
         /* Close up. */
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

         /* Check metadata. */
         if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
         if (nvars_in != 1 || varids_in[0] != 0) ERR;
         if (nc_inq_varname(ncid, 0, name_in)) ERR;
         if (strcmp(name_in, VAR_NAME)) ERR;

         /* Check fill value att. */
         if (nc_inq_att(ncid, varid, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, varid, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;

         /* Read the first record, it should be the fill value. */
         start[0] = 0;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != fill_value) ERR;

         /* Read the second record, it should be the value we just wrote
          * there. */
         start[0] = 1;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != data) ERR;
      
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with one other attribute...");

      {
         int losses_value = 192, losses_value_in;

         /* Create a netcdf-4 file with one dim and one var. Add another
          * attribute, then fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         if (nc_put_att_int(ncid, varid, LOSSES_NAME, NC_INT, 1, &losses_value)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
         if (nc_inq_att(ncid, 0, LOSSES_NAME, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_INT || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, LOSSES_NAME, &losses_value_in)) ERR;
         if (losses_value_in != losses_value) ERR;
         if (nc_inq_att(ncid, 0, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;
         if (nc_inq_attid(ncid, 0, LOSSES_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with three other attributes...");
      {
#define NUM_LEADERS 3
         char leader[NUM_LEADERS][NC_MAX_NAME + 1] = {"hair_length_of_strategoi", 
                                                      "hair_length_of_Miltiades", 
                                                      "hair_length_of_Darius_I"};
         short hair_length[NUM_LEADERS] = {3, 11, 4};
         short short_in;
         int a;

         /* Create a netcdf file with one dim and one var. Add 3
          * attributes, then fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         for (a = 0; a < NUM_LEADERS; a++)
            if (nc_put_att_short(ncid, varid, leader[a], NC_SHORT, 1, &hair_length[a])) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_close(ncid)) ERR;

         /* Open the file. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

         /* Check our three hair-related attributes. */
         for (a = 0; a < NUM_LEADERS; a++)
         {
            if (nc_inq_att(ncid, 0, leader[a], &xtype_in, &len_in)) ERR;
            if (xtype_in != NC_SHORT || len_in != 1) ERR;
            if (nc_get_att(ncid, 0, leader[a], &short_in)) ERR;
            if (short_in != hair_length[a]) ERR;
            if (nc_inq_attid(ncid, 0, leader[a], &attnum_in)) ERR;
            if (attnum_in != a) ERR;
         }

         /* Check our fill value attribute. */
         if (nc_inq_att(ncid, 0, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;

         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with simple example...");
      {
/* Dims stuff. */
#define NDIMS 3
#define VAR_DIMS 3
#define DIM_A "dim1"
#define DIM_A_LEN 4
#define DIM_B "dim2"
#define DIM_B_LEN 3
#define DIM_C "dim3"
#define DIM_C_LEN NC_UNLIMITED

/* Var stuff. */
#define CXX_VAR_NAME "P"

/* Att stuff. */
#define NUM_ATTS 4
#define LONG_NAME "long_name"
#define PRES_MAX_WIND "pressure at maximum wind"
#define UNITS "units"
#define HECTOPASCALS "hectopascals"

         int dimid[NDIMS], var_dimids[VAR_DIMS] = {2, 1, 0};
         float fill_value = -9999.0f;
         char long_name[] = PRES_MAX_WIND;

         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;

         /* Create dims. */
         if (nc_def_dim(ncid, DIM_A, DIM_A_LEN, &dimid[0])) ERR;
         if (nc_def_dim (ncid, DIM_B, DIM_B_LEN, &dimid[1])) ERR;
         if (nc_def_dim(ncid, DIM_C, DIM_C_LEN, &dimid[2])) ERR;

         /* Create var. */
         if (nc_def_var(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, 
                        var_dimids, &varid)) ERR;
         if (varid) ERR;

         if (nc_put_att(ncid, varid, LONG_NAME, NC_CHAR, strlen(long_name) + 1, 
                        long_name)) ERR;
         if (nc_put_att(ncid, varid, UNITS, NC_CHAR, strlen(UNITS) + 1, 
                        UNITS)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         /* Now add a fill value. This will acutually cause HDF5 to
          * destroy the dataset and recreate it, recreating also the
          * three attributes that are attached to it. */
         if (nc_put_att(ncid, varid, _FillValue, NC_FLOAT, 
                        1, &fill_value)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, 0, &ncid)) ERR;
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 2) ERR;

         if (nc_close(ncid)) ERR;
      }
      SUMMARIZE_ERR;

#ifndef NO_NETCDF_2
      /* The following test is an attempt to recreate a problem occuring
         in the cxx tests. The file is created in c++ in nctsts.cpp. */
      printf("**** testing fill value with example from cxx tests in v2 api...");
      {
/* Dims stuff. */
#define NDIMS_1 4
#define VAR_DIMS 3
#define LAT "lat"
#define LAT_LEN 4
#define LON "lon"
#define LON_LEN 3
#define FRTIMED "frtimed"
#define FRTIMED_LEN NC_UNLIMITED
#define TIMELEN "timelen"
#define TIMELEN_LEN 20

/* Var stuff. */
#define CXX_VAR_NAME "P"

/* Att stuff. */
#define NUM_ATTS 4
#define LONG_NAME "long_name"
#define UNITS "units"

         int dimid[NDIMS_1], var_dimids[VAR_DIMS] = {2, 0, 1};
         float fill_value = -9999.0f;
         char long_name[] = PRES_MAX_WIND;
         int i, attid[NUM_ATTS];

         ncid = nccreate(FILE_NAME, NC_NETCDF4);

         /* Create dims. */
         dimid[0] = ncdimdef(ncid, LAT, LAT_LEN);
         dimid[1] = ncdimdef(ncid, LON, LON_LEN);
         dimid[2] = ncdimdef(ncid, FRTIMED, FRTIMED_LEN);
         dimid[3] = ncdimdef(ncid, TIMELEN, TIMELEN_LEN);

         /* Just check our dimids to see that they are correct. */
         for (i = 0; i < NDIMS_1; i++)
            if (dimid[i] != i) ERR;

         /* Create var. */
         varid = ncvardef(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, var_dimids);
         if (varid) ERR;

         /* Add three atts to the var, long_name, units, and
          * valid_range. */
         if (nc_put_att(ncid, varid, LONG_NAME, NC_CHAR, strlen(long_name) + 1,
                        long_name)) ERR;
         if (nc_put_att(ncid, varid, UNITS, NC_CHAR, strlen(UNITS) + 1,
                        UNITS)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         /* Now add a fill value. This will acutually cause HDF5 to
          * destroy the dataset and recreate it, recreating also the
          * three attributes that are attached to it. */
         attid[3] = ncattput(ncid, varid, _FillValue, NC_FLOAT,
                             1, &fill_value);

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         ncclose(ncid);

         /* Open the file and check. */
         ncid = ncopen(FILE_NAME, 0);
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 2) ERR;
         ncclose(ncid);
      }
      SUMMARIZE_ERR;
#endif /* NO_NETCDF_2 */
   }

   printf("**** testing create order varids...");

#define UNITS "units"
#define DIMNAME "x"
#define VARNAME "data"
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int ncid, dimid, varid, xvarid;
      char units[] = "zlotys";

      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
      if (nc_def_dim(ncid, DIMNAME, 1, &dimid)) ERR;
      if (nc_enddef(ncid)) ERR;
      if (nc_redef(ncid)) ERR;
      if (nc_def_var(ncid, DIMNAME, NC_INT, 1, &dimid, &xvarid)) ERR;
      if (nc_put_att_text(ncid, xvarid, UNITS, strlen(units), units)) ERR;
      if (nc_def_var(ncid, VARNAME, NC_INT, 1, &dimid, &varid)) ERR;
      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
#define RANK_wind 1
   printf("**** testing simple variable renaming...");
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int  ncid, lat_dim, time_dim, lon_dim, wind_id;
      size_t lat_len = 73, time_len = 10, lon_len = 145;
      int cdf_goober[1];

/*      if (nc_set_default_format(NC_FORMAT_NETCDF4, NULL)) ERR;*/
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* define dimensions */
      if (nc_def_dim(ncid, "a", lon_len, &lon_dim)) ERR;
      if (nc_def_dim(ncid, "b", lat_len, &lat_dim)) ERR;
      if (nc_def_dim(ncid, "c", time_len, &time_dim)) ERR;

      if (nc_put_att_text(ncid, NC_GLOBAL, "a", 3, "bar")) ERR;
      cdf_goober[0] = 2;
      if (nc_put_att_int(ncid, NC_GLOBAL, "b", NC_INT, 1, cdf_goober)) ERR;

      /* define variables */
      if (nc_def_var(ncid, "aa", NC_FLOAT, RANK_wind, &lon_dim, &wind_id)) ERR;
      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_rename_var(ncid, 0, "az")) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR; 
   printf("**** testing dimension and variable renaming...");
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int  ncid, lat_dim, time_dim, lon_dim, wind_id;
      size_t lat_len = 73, time_len = 10, lon_len = 145;
      int wind_dims[RANK_wind], wind_slobber[1], cdf_goober[1];

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* define dimensions */
      if (nc_def_dim(ncid, "lon", lon_len, &lon_dim)) ERR;
      if (nc_def_dim(ncid, "lat", lat_len, &lat_dim)) ERR;
      if (nc_def_dim(ncid, "time", time_len, &time_dim)) ERR;

      if (nc_put_att_text(ncid, NC_GLOBAL, "foo", 3, "bar")) ERR;
      cdf_goober[0] = 2;
      if (nc_put_att_int(ncid, NC_GLOBAL, "goober", NC_INT, 1, cdf_goober)) ERR;

      /* define variables */
      wind_dims[0] = lon_dim;
      if (nc_def_var(ncid, "temp", NC_FLOAT, RANK_wind, wind_dims, &wind_id)) ERR;

      if (nc_put_att_text(ncid, wind_id, "bar", 3, "foo")) ERR;
      wind_slobber[0] = 3;
      if (nc_put_att_int(ncid, wind_id, "slobber", NC_INT, 1, wind_slobber)) ERR;
      if (nc_close(ncid)) ERR;

      /* re-open dataset*/
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_dimid(ncid, "lon", &lon_dim)) ERR;

      /* rename dimension */
      if (nc_rename_dim(ncid, lon_dim, "longitude")) ERR;
      if (nc_inq_varid(ncid, "temp", &wind_id)) ERR;

      /* rename variable */
      if (nc_rename_var(ncid, wind_id, "wind")) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR; 


/*    printf("*** testing 2D array of NC_CHAR..."); */
/*    { */
/*       int dimid[NDIMS_1], var_dimids[VAR_DIMS] = {2, 0, 1}; */
/*       float fill_value = -9999.0f; */
/*       char long_name[] = PRES_MAX_WIND; */
/*       int i, attid[NUM_ATTS]; */

/*       ncid = nccreate(FILE_NAME, NC_NETCDF4); */

/*       /\* Create dims. *\/ */
/*       dimid[0] = ncdimdef(ncid, LAT, LAT_LEN); */
/*       dimid[1] = ncdimdef(ncid, LON, LON_LEN); */

/*       /\* Create var. *\/ */
/*       varid = ncvardef(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, var_dimids); */
/*       if (varid) ERR; */

/*       ncclose(ncid); */

/*       /\* Open the file and check. *\/ */
/*       ncid = ncopen(FILE_NAME, 0); */
/*       ncclose(ncid); */
/*    } */

/*    SUMMARIZE_ERR; */

#define NDIMS 3
#define NNAMES 4
#define NLINES 13
/*    printf("**** testing funny names for netCDF-4..."); */
/*    { */
/*       int  ncid, wind_id; */
/*       size_t len[NDIMS] = {7, 3, 1}; */
/*       int dimids[NDIMS], dimids_in[NDIMS], ndims_in; */
/*       char funny_name[NNAMES][NC_MAX_NAME] = {"\a\t", "\f\n", "\r\v", "\b"}; */
/*       char name_in[NC_MAX_NAME + 1]; */
/*       char *speech[NLINES] = {"who would fardels bear, ", */
/* 			      "To grunt and sweat under a weary life, ", */
/* 			      "But that the dread of something after death, ", */
/* 			      "The undiscover'd country from whose bourn ", */
/* 			      "No traveller returns, puzzles the will ", */
/* 			      "And makes us rather bear those ills we have ", */
/* 			      "Than fly to others that we know not of? ", */
/* 			      "Thus conscience does make cowards of us all; ", */
/* 			      "And thus the native hue of resolution ", */
/* 			      "Is sicklied o'er with the pale cast of thought, ", */
/* 			      "And enterprises of great pith and moment ", */
/* 			      "With this regard their currents turn awry, ", */
/* 			      "And lose the name of action."}; */
/*       char *speech_in[NLINES]; */
/*       int i; */
/*       unsigned short nlines = NLINES; */
/*       unsigned int nlines_in; */

/*       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */

/*       /\* Define dimensions. *\/ */
/*       for (i = 0; i < NDIMS; i++) */
/* 	 if (nc_def_dim(ncid, funny_name[i], len[i], &dimids[i])) ERR; */

/*       /\* Write some global atts. *\/ */
/*       if (nc_put_att_string(ncid, NC_GLOBAL, funny_name[0], NLINES,  */
/* 			    (const char **)speech)) ERR; */
/*       if (nc_put_att_ushort(ncid, NC_GLOBAL, funny_name[1], NC_UINT, 1, &nlines)) ERR; */

/*       /\* Define variables. *\/ */
/*       if (nc_def_var(ncid, funny_name[3], NC_INT64, NDIMS, dimids, &wind_id)) ERR; */

/*       if (nc_close(ncid)) ERR; */

/*       /\* Open the file and check. *\/ */
/*       if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */
/*       if (nc_inq_dimids(ncid, &ndims_in, dimids_in, 0)) ERR; */
/*       if (ndims_in != NDIMS) ERR; */
/*       for (i = 0; i < NDIMS; i++) */
/*       { */
/* 	 if (dimids_in[i] != i) ERR; */
/* 	 if (nc_inq_dimname(ncid, i, name_in)) ERR; */
/* 	 if (strcmp(name_in, funny_name[i])) ERR; */
/*       } */

/*       if (nc_get_att_string(ncid, NC_GLOBAL, funny_name[0], (char **)speech_in)) ERR; */
/*       for (i = 0; i < NLINES; i++) */
/* 	 if (strcmp(speech_in[i], speech[i])) ERR; */
/*       if (nc_get_att_uint(ncid, NC_GLOBAL, funny_name[1], &nlines_in)) ERR; */
/*       if (nlines_in != NLINES) ERR; */
/*       if (nc_free_string(NLINES, (char **)speech_in)) ERR; */
/*       if (nc_inq_varname(ncid, 0, name_in)) ERR; */
/*       if (strcmp(name_in, funny_name[3])) ERR; */
/*       if (nc_close(ncid)) ERR; */
/*    } */
/*    SUMMARIZE_ERR; */
   printf("**** testing endianness...");

#define NDIMS4 1
#define DIM4_NAME "Joe"
#define VAR_NAME4 "Ed"
#define DIM4_LEN 10
   {
      int dimids[NDIMS4], dimids_in[NDIMS4];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM4_LEN], data_in[DIM4_LEN];
      int endian_in;
      int i;

      for (i = 0; i < DIM4_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM4_NAME, DIM4_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME4, NC_INT, NDIMS4, dimids, &varid)) ERR;
      if (nc_def_var_endian(ncid, varid, NC_ENDIAN_BIG)) ERR;
      if (varid != 0) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS4 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims,
                     dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT ||
          ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR;
      if (nc_inq_var_endian(ncid, 0, &endian_in)) ERR;
      if (endian_in != NC_ENDIAN_BIG) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS4 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims,
                     dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT ||
          ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR;
      if (nc_inq_var_endian(ncid, 0, &endian_in)) ERR;
      if (endian_in != NC_ENDIAN_BIG) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM4_LEN; i++)
	 if (data[i] != data_in[i]) ERR;

      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing chunking...");
   {
#define NDIMS5 1
#define DIM5_NAME "D5"
#define VAR_NAME5 "V5"
#define DIM5_LEN 1000

      int dimids[NDIMS5], dimids_in[NDIMS5];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM5_LEN], data_in[DIM5_LEN];
      int chunksize[NDIMS5] = {5};
      int chunksize_in[NDIMS5];
      int contiguous_in;
      int i, d;

      for (i = 0; i < DIM5_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM5_NAME, DIM5_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME5, NC_INT, NDIMS5, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, chunksize)) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS5 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME5) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS5; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM5_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS5 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME5) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS5; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM5_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing contiguous storage...");
   {
#define NDIMS6 1
#define DIM6_NAME "D5"
#define VAR_NAME6 "V5"
#define DIM6_LEN 100

      int dimids[NDIMS6], dimids_in[NDIMS6];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM6_LEN], data_in[DIM6_LEN];
      int chunksize_in[NDIMS6];
      int contiguous_in;
      int i, d;

      for (i = 0; i < DIM6_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS6, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 1, NULL)) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS6; d++)
	 if (chunksize_in[d] != 0) ERR;
      if (!contiguous_in) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM6_LEN; i++)
         if (data_in[i] != data[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS6; d++)
	 if (chunksize_in[d] != 0) ERR;
      if (!contiguous_in) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM6_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing extreme numbers dude...");
   {
#define VAR_NAME7 "V5"
#define DIM6_LEN 100

      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
/*      unsigned long long data = 9223372036854775807ull, data_in;*/
      unsigned long long data = 9223372036854775817ull, data_in;

      /* Create a netcdf-4 file with scalar var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_var(ncid, VAR_NAME7, NC_UINT64, 0, NULL, &varid)) ERR;
      if (nc_put_var_ulonglong(ncid, varid, &data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, NULL, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME7) || xtype_in != NC_UINT64 || ndims != 0 || natts != 0) ERR;
      if (nc_get_var_ulonglong(ncid, varid, &data_in)) ERR;
      if (data_in != data) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, NULL, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME7) || xtype_in != NC_UINT64 || ndims != 0 || natts != 0) ERR;
      if (nc_get_var_ulonglong(ncid, varid, &data_in)) ERR;
      if (data_in != data) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes...");
   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_grp(ncid, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_varname(ncid, 0, name_in)) ERR;
      if (strcmp(name_in, GENERIC_NAME)) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes some more...");

   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_grp(ncid, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes != 1) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes even more...");

   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one group. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_grp(ncid, GENERIC_NAME, NULL)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps != 1) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("**** testing error code for too-large chunks...");
   {
#define NDIMS17 2
#define DIM17_NAME "personality"
#define DIM17_NAME_2 "good_looks"
#define VAR_NAME17 "ed"
#define DIM17_LEN 2147483644 /* max dimension size - 2GB - 4. */
#define DIM17_2_LEN 1000

      int dimids[NDIMS17], dimids_in[NDIMS17];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int chunksize[NDIMS17] = {5, 5};
      int bad_chunksize[NDIMS17] = {5, DIM17_LEN};
      int chunksize_in[NDIMS17];
      int contiguous_in;
      int d;

      /* Create a netcdf-4 file with two dims and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM17_NAME, DIM17_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM17_NAME_2, DIM17_2_LEN, &dimids[1])) ERR;
      if (dimids[0] != 0 || dimids[1] != 1) ERR;
      if (nc_def_var(ncid, VAR_NAME17, NC_UINT64, NDIMS17, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, bad_chunksize) != NC_EBADCHUNK) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, chunksize)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS17 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME17) || xtype_in != NC_UINT64 || ndims != 2 || natts != 0 || 
	  dimids_in[0] != 0 || dimids_in[1] != 1) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS17; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS17 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME17) || xtype_in != NC_UINT64 || ndims != 2 || natts != 0 || 
	  dimids_in[0] != 0 || dimids_in[1] != 1) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS17; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   FINAL_RESULTS;

#ifdef USE_PARALLEL
   MPI_Finalize();
#endif   
}
コード例 #7
0
ファイル: wr_dpi.c プロジェクト: goma/brkfix
int
wr_dpi(Dpi *d,
       char *filename,
       int verbosity)
{
  int err = 0;
  int status = 0;
  int u = 0;			/* short hand for unit... */

  struct Shadow_Identifiers si;

  memset(&si, 0, sizeof(struct Shadow_Identifiers));

  /*
   * From the C interface guide the basic calling sequence is given
   * for the case of adding new dimensions, variables and attributes to
   * an existing netCDF dataset.
   *
   *  nc_open();
   *  nc_redef();
   *    nc_def_dim();
   *    nc_def_var();
   *    nc_put_att();
   *  nc_enddef();
   *  nc_put_var();
   *  nc_close();
   *
   */

  /*
   * Open the file.
   */

#ifdef NETCDF_3
  err = nc_open(filename, NC_WRITE, &u);
  if ( err != NC_NOERR )
    {
      EH(-1, "nc_open() problem.");
    }
#endif
#ifdef NETCDF_2
  err = ncopen(filename, NC_WRITE);
  EH(err, "ncopen() problem.");
  u   = err;
#endif

  /*
   * Go into define mode.
   */

#ifdef NETCDF_3
  err = nc_redef(u);
  if ( err != NC_NOERR )
    {
      EH(-1, "nc_redef() problem.");
    }
#endif
#ifdef NETCDF_2
  err = ncredef(u);
  EH(err, "ncredef() problem.");
#endif

  /*
   * Define each of the netCDF dimensions that will be needed to describe
   * the extent of netCDF variables that are arrays.
   */
 
  define_dimension(u, DIM_LEN_EB_NUM_PRIVATE_ELEMS, 
		   d->len_eb_num_private_elems,
		   &si.len_eb_num_private_elems);

  define_dimension(u, DIM_LEN_ELEM_VAR_TAB_GLOBAL,
		   d->len_elem_var_tab_global,
		   &si.len_elem_var_tab_global);

  define_dimension(u, DIM_LEN_ELEM_ELEM_LIST, /* new e-e */
		   d->len_elem_elem_list,
		   &si.len_elem_elem_list);

  define_dimension(u, DIM_LEN_NODE_DESCRIPTION,
		   d->len_node_description,
		   &si.len_node_description);

  define_dimension(u, DIM_LEN_NS_NODE_LIST,
		   d->len_ns_node_list,
		   &si.len_ns_node_list);

  define_dimension(u, DIM_LEN_NS_DISTFACT_LIST,
		   d->len_ns_distfact_list,
		   &si.len_ns_distfact_list);

  define_dimension(u, DIM_LEN_SS_ELEM_LIST,
		   d->len_ss_elem_list,
		   &si.len_ss_elem_list);

  define_dimension(u, DIM_LEN_SS_DISTFACT_LIST,
		   d->len_ss_distfact_list,
		   &si.len_ss_distfact_list);

  define_dimension(u, DIM_LEN_STRING,
		   d->len_string,
		   &si.len_string);

  define_dimension(u, DIM_LEN_PTR_SET_MEMBERSHIP,
		   d->len_ptr_set_membership,
		   &si.len_ptr_set_membership);

  define_dimension(u, DIM_LEN_SET_MEMBERSHIP,
		   d->len_set_membership,
		   &si.len_set_membership);

  define_dimension(u, DIM_NUM_ELEM_BLOCKS,
		   d->num_elem_blocks,
		   &si.num_elem_blocks);

  define_dimension(u, DIM_NUM_ELEM_BLOCKS_GLOBAL,
		   d->num_elem_blocks_global,
		   &si.num_elem_blocks_global);

  define_dimension(u, DIM_NUM_ELEMS,
		   d->num_elems,
		   &si.num_elems);

  define_dimension(u, DIM_NUM_GLOBAL_NODE_DESCRIPTIONS,
		   d->num_global_node_descriptions,
		   &si.num_global_node_descriptions);

  define_dimension(u, DIM_NUM_NEIGHBORS,
		   d->num_neighbors,
		   &si.num_neighbors);

  define_dimension(u, DIM_NUM_NODE_SETS,
		   d->num_node_sets,
		   &si.num_node_sets);

  define_dimension(u, DIM_NUM_NODE_SETS_GLOBAL,
		   d->num_node_sets_global,
		   &si.num_node_sets_global);

  define_dimension(u, DIM_NUM_NODES,
		   d->num_nodes,
		   &si.num_nodes);

  define_dimension(u, DIM_NUM_PROPS_EB, d->num_props_eb,
		   &si.num_props_eb);

      define_dimension(u, DIM_NUM_PROPS_NS,
		       d->num_props_ns,
		       &si.num_props_ns);

      define_dimension(u, DIM_NUM_PROPS_SS,
		       d->num_props_ss,
		       &si.num_props_ss);

  define_dimension(u, DIM_NUM_SIDE_SETS,
		   d->num_side_sets,
		   &si.num_side_sets);

  define_dimension(u, DIM_NUM_SIDE_SETS_GLOBAL,
		   d->num_side_sets_global,
		   &si.num_side_sets_global);

  define_dimension(u, DIM_NUM_UNIVERSE_NODES,
		   d->num_universe_nodes,
		   &si.num_universe_nodes);

  if (d->num_side_sets_global > 0) {
    define_dimension(u, DIM_LEN_SS_BLOCK_INDEX_GLOBAL,
                     d->num_side_sets_global + 1,
                     &si.len_ss_block_index_global);
    
    define_dimension(u, DIM_LEN_SS_BLOCK_LIST_GLOBAL,
                     d->ss_block_index_global[d->num_side_sets_global],
                     &si.len_ss_block_list_global);
  } else {
      define_dimension(u, DIM_LEN_SS_BLOCK_INDEX_GLOBAL,
                       0,
                       &si.len_ss_block_index_global);
      define_dimension(u, DIM_LEN_SS_BLOCK_LIST_GLOBAL,
                       0,
                       &si.len_ss_block_list_global);
  }
  
  /*
   * Define variables. Arrays only get defined if their respective dimensions
   * are greater than zero.
   *
   * Also, this handy routine uses two arguments for the possibility of
   * up to 2D arrays. Dummy arguments of "-1" are inserted for 1D arrays 
   * or for scalar variables ( zero dimensional arrays).
   */
  
  define_variable(u, VAR_DPI_VERSION_STRING, NC_CHAR, 1,
		  si.len_string, -1,
		  d->len_string, -1,
		  &si.dpi_version_string);

  define_variable(u, VAR_EB_ELEM_TYPE_GLOBAL, NC_CHAR, 2, 
		  si.num_elem_blocks_global, si.len_string,
		  d->num_elem_blocks_global, d->len_string,
		  &si.eb_elem_type_global);

  define_variable(u, VAR_EB_ID_GLOBAL, NC_INT, 1, 
		  si.num_elem_blocks_global, -1,
		  d->num_elem_blocks_global, -1,
		  &si.eb_id_global);

  define_variable(u, VAR_EB_INDEX_GLOBAL, NC_INT, 1, 
		  si.num_elem_blocks, -1,
		  d->num_elem_blocks, -1,
		  &si.eb_index_global);

  define_variable(u, VAR_EB_NUM_ATTR_GLOBAL, NC_INT, 1, 
		  si.num_elem_blocks_global, -1,
		  d->num_elem_blocks_global, -1,
		  &si.eb_num_attr_global);

  define_variable(u, VAR_EB_NUM_ELEMS_GLOBAL, NC_INT, 1, 
		  si.num_elem_blocks_global, -1,
		  d->num_elem_blocks_global, -1,
		  &si.eb_num_elems_global);

  define_variable(u, VAR_EB_NUM_NODES_PER_ELEM_GLOBAL, NC_INT, 1, 
		  si.num_elem_blocks_global, -1,
		  d->num_elem_blocks_global, -1,
		  &si.eb_num_nodes_per_elem_global);

  define_variable(u, VAR_EB_NUM_PRIVATE_ELEMS, NC_INT, 1, 
		  si.num_elem_blocks, -1,
		  d->num_elem_blocks, -1,
		  &si.eb_num_private_elems);

  if ( d->num_props_eb > 1 )	/* Properties are weird, recall. */
    {
      define_variable(u, VAR_EB_PROP_GLOBAL, NC_INT, 2,
		      si.num_props_eb, si.num_elem_blocks_global,
		      d->num_props_eb, d->num_elem_blocks_global,
		      &si.eb_prop_global);
    }

  if ( d->num_elems > 0 )
    {
      define_variable(u, VAR_ELEM_INDEX_GLOBAL, NC_INT, 1,
		      si.num_elems, -1,
		      d->num_elems, -1,
		      &si.elem_index_global);
    }

  if ( d->len_elem_var_tab_global > 0 )
    {
      define_variable(u, VAR_ELEM_VAR_TAB_GLOBAL, NC_INT, 1,
		      si.len_elem_var_tab_global, -1,
		      d->len_elem_var_tab_global, -1,
		      &si.elem_var_tab_global);
    }

  if ( d->len_elem_elem_list > 0 )
    {
      define_variable(u, VAR_ELEM_OWNER, NC_INT, 1,
		      si.num_elems, -1,
		      d->num_elems, -1,
		      &si.elem_owner);

      define_variable(u, VAR_ELEM_ELEM_LIST_GLOBAL, NC_INT, 1,
		      si.len_elem_elem_list, -1,
		      d->len_elem_elem_list, -1,
		      &si.elem_elem_list_global);

      define_variable(u, VAR_ELEM_ELEM_TWST_GLOBAL, NC_INT, 1,
		      si.len_elem_elem_list, -1,
		      d->len_elem_elem_list, -1,
		      &si.elem_elem_twst_global);

      define_variable(u, VAR_ELEM_ELEM_FACE_GLOBAL, NC_INT, 1,
		      si.len_elem_elem_list, -1,
		      d->len_elem_elem_list, -1,
		      &si.elem_elem_face_global);

      define_variable(u, VAR_ELEM_ELEM_PROC_GLOBAL, NC_INT, 1,
		      si.len_elem_elem_list, -1,
		      d->len_elem_elem_list, -1,
		      &si.elem_elem_proc_global);
    }

  define_variable(u, VAR_GLOBAL_NODE_DESCRIPTION, NC_INT, 2, 
		  si.num_global_node_descriptions, si.len_node_description,
		  d->num_global_node_descriptions, d->len_node_description,
		  &si.global_node_description);

  define_variable(u, VAR_MY_NAME, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.my_name);

  define_variable(u, VAR_NEIGHBOR, NC_INT, 1, 
		  si.num_neighbors, -1,
		  d->num_neighbors, -1,
		  &si.neighbor);

  if ( d->num_nodes > 0 )
    {
      define_variable(u, VAR_NODE_INDEX_GLOBAL, NC_INT, 1,
		      si.num_nodes, -1,
		      d->num_nodes, -1,
		      &si.node_index_global);
    }

  define_variable(u, VAR_NS_DISTFACT_INDEX_GLOBAL, NC_INT, 1,
		  si.num_node_sets_global, -1,
		  d->num_node_sets_global, -1,
		  &si.ns_distfact_index_global);

  define_variable(u, VAR_NS_DISTFACT_LEN_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.ns_distfact_len_global);

  define_variable(u, VAR_NS_DISTFACT_LIST_INDEX_GLOBAL, NC_INT, 1,
		  si.len_ns_distfact_list, -1,
		  d->len_ns_distfact_list, -1,
		  &si.ns_distfact_list_index_global);

  define_variable(u, VAR_NS_ID_GLOBAL, NC_INT, 1, 
		  si.num_node_sets_global, -1,
		  d->num_node_sets_global, -1,
		  &si.ns_id_global);

  define_variable(u, VAR_NS_INDEX_GLOBAL, NC_INT, 1, 
		  si.num_node_sets, -1,
		  d->num_node_sets, -1,
		  &si.ns_index_global);

  define_variable(u, VAR_NS_NODE_INDEX_GLOBAL, NC_INT, 1,
		  si.num_node_sets_global, -1,
		  d->num_node_sets_global, -1,
		  &si.ns_node_index_global);


  define_variable(u, VAR_NS_NODE_LEN_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.ns_node_len_global);

  define_variable(u, VAR_NS_NODE_LIST_INDEX_GLOBAL, NC_INT, 1,
		  si.len_ns_node_list, -1,
		  d->len_ns_node_list, -1,
		  &si.ns_node_list_index_global);

  define_variable(u, VAR_NS_NUM_DISTFACTS_GLOBAL, NC_INT, 1, 
		  si.num_node_sets_global, -1,
		  d->num_node_sets_global, -1,
		  &si.ns_num_distfacts_global);

  define_variable(u, VAR_NS_NUM_NODES_GLOBAL, NC_INT, 1, 
		  si.num_node_sets_global, -1,
		  d->num_node_sets_global, -1,
		  &si.ns_num_nodes_global);

  if ( d->num_props_ns > 1 )
    {
      define_variable(u, VAR_NS_PROP_GLOBAL, NC_INT, 2, 
		      si.num_props_ns, si.num_node_sets_global,
		      d->num_props_ns, d->num_node_sets_global,
		      &si.ns_prop_global);
    }

  define_variable(u, VAR_NUM_BOUNDARY_NODES, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_boundary_nodes);

  define_variable(u, VAR_NUM_DOFS_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_dofs_global);

  define_variable(u, VAR_NUM_ELEMS_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_elems_global);

  define_variable(u, VAR_NUM_EXTERNAL_NODES, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_external_nodes);

  define_variable(u, VAR_NUM_INTERNAL_NODES, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_internal_nodes);

  define_variable(u, VAR_NUM_NODES_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.num_nodes_global);

  define_variable(u, VAR_PTR_SET_MEMBERSHIP, NC_INT, 1, 
		  si.len_ptr_set_membership, -1,
		  d->len_ptr_set_membership, -1,
		  &si.ptr_set_membership);

  define_variable(u, VAR_SET_MEMBERSHIP, NC_INT, 1, 
		  si.len_set_membership, -1,
		  d->len_set_membership, -1,
		  &si.set_membership);

  define_variable(u, VAR_SS_DISTFACT_INDEX_GLOBAL, NC_INT, 1, 
		  si.num_side_sets_global, -1,
		  d->num_side_sets_global, -1,
		  &si.ss_distfact_index_global);

  define_variable(u, VAR_SS_DISTFACT_LIST_INDEX_GLOBAL, NC_INT, 1, 
		  si.len_ss_distfact_list, -1,
		  d->len_ss_distfact_list, -1,
		  &si.ss_distfact_list_index_global);

  define_variable(u, VAR_SS_DISTFACT_LEN_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.ss_distfact_len_global);

  define_variable(u, VAR_SS_ELEM_INDEX_GLOBAL, NC_INT, 1, 
		  si.num_side_sets_global, -1,
		  d->num_side_sets_global, -1,
		  &si.ss_elem_index_global);

  define_variable(u, VAR_SS_ELEM_LEN_GLOBAL, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.ss_elem_len_global);

  define_variable(u, VAR_SS_ELEM_LIST_INDEX_GLOBAL, NC_INT, 1, 
		  si.len_ss_elem_list, -1,
		  d->len_ss_elem_list, -1,
		  &si.ss_elem_list_index_global);

  define_variable(u, VAR_SS_ID_GLOBAL, NC_INT, 1, 
		  si.num_side_sets_global, -1,
		  d->num_side_sets_global, -1,
		  &si.ss_id_global);

  define_variable(u, VAR_SS_INDEX_GLOBAL, NC_INT, 1, 
		  si.num_side_sets, -1,
		  d->num_side_sets, -1,
		  &si.ss_index_global);

  define_variable(u, VAR_SS_NUM_DISTFACTS_GLOBAL, NC_INT, 1, 
		  si.num_side_sets_global, -1,
		  d->num_side_sets_global, -1,
		  &si.ss_num_distfacts_global);

  define_variable(u, VAR_SS_NUM_SIDES_GLOBAL, NC_INT, 1, 
		  si.num_side_sets_global, -1,
		  d->num_side_sets_global, -1,
		  &si.ss_num_sides_global);

  if ( d->num_props_ss > 1 )
    {
      define_variable(u, VAR_SS_PROP_GLOBAL, NC_INT, 2, 
		      si.num_props_ss, si.num_side_sets_global,
		      d->num_props_ss, d->num_side_sets_global,
		      &si.ss_prop_global);
    }
    
  if ( d->num_side_sets_global > 0 )
    {
      define_variable(u, VAR_SS_INTERNAL_GLOBAL, NC_INT, 1,
                      si.num_side_sets_global, -1,
                      d->num_side_sets_global, -1,
                      &si.ss_internal_global);

      define_variable(u, VAR_SS_BLOCK_INDEX_GLOBAL, NC_INT, 1,
                      si.len_ss_block_index_global, -1,
                      d->num_side_sets_global + 1, -1,
                      &si.ss_block_index_global);

      define_variable(u, VAR_SS_BLOCK_LIST_GLOBAL, NC_INT, 1,
                      si.len_ss_block_list_global, -1,
                      d->ss_block_index_global[d->num_side_sets_global], -1,
                      &si.ss_block_list_global);
    }

  define_variable(u, VAR_UNDEFINED_BASIC_EQNVAR_ID, NC_INT, 0, 
		  -1, -1,
		  -1, -1,
		  &si.undefined_basic_eqnvar_id);


  /*
   * Leave define mode.
   */

#ifdef NETCDF_3
  err = nc_enddef(u);
  if ( err != NC_NOERR )
    {
      EH(-1, "nc_enddef() problem.");
    }
#endif
#ifdef NETCDF_2
  err = ncendef(u);
  EH(err, "ncendef() problem.");
#endif

  /*
   * Put variable values.
   *
   * This form is good for scalars, 1d arrays and 2d arrays. Any more and
   * you'll need to add another argument to the list for the backward
   * compatible to netCDF implementation to work properly. We'll assume
   * that start[] arrays that ncvarput() uses will be full of zeroes.
   * If not, then you'll need to do that case by hand.
   */

  put_variable(u, NC_CHAR, 1, 
	       d->len_string,			-1, 
	       si.dpi_version_string,		d->dpi_version_string);

  put_variable(u, NC_CHAR, 2, 
	       d->num_elem_blocks_global,	d->len_string,
	       si.eb_elem_type_global, &(d->eb_elem_type_global[0][0]));

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks_global,	-1, 
	       si.eb_id_global,			d->eb_id_global);

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks,		-1, 
	       si.eb_index_global,		d->eb_index_global);

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks_global,	-1, 
	       si.eb_num_attr_global,		d->eb_num_attr_global);

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks_global,	-1, 
	       si.eb_num_elems_global,		d->eb_num_elems_global);

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks_global,	-1, 
	       si.eb_num_nodes_per_elem_global,	
	       d->eb_num_nodes_per_elem_global);

  put_variable(u, NC_INT, 1, 
	       d->num_elem_blocks,		-1, 
	       si.eb_num_private_elems,		d->eb_num_private_elems);

  if ( d->num_props_eb > 1 )
    {
      put_variable(u, NC_INT, 2,
		   d->num_props_eb, d->num_elem_blocks_global,
		   si.eb_prop_global, &(d->eb_prop_global[0][0]));
    }

  if ( d->num_elems > 0 )
    {
      put_variable(u, NC_INT, 1, 
		   d->num_elems, -1, 
		   si.elem_index_global,	d->elem_index_global);

      put_variable(u, NC_INT, 1, d->num_elems,	-1, si.elem_owner,
		   d->elem_owner);

    }

  if ( d->len_elem_var_tab_global > 0 )
    {
      put_variable(u, NC_INT, 1, 
		   d->len_elem_var_tab_global,	-1, 
		   si.elem_var_tab_global,	d->elem_var_tab_global);
    }

  if ( d->len_elem_elem_list > 0 )
    {
      put_variable(u, NC_INT, 1, d->len_elem_elem_list,	-1, 
		   si.elem_elem_list_global, d->elem_elem_list_global);
      put_variable(u, NC_INT, 1, d->len_elem_elem_list,	-1, 
		   si.elem_elem_face_global, d->elem_elem_face_global);
      put_variable(u, NC_INT, 1, d->len_elem_elem_list,	-1, 
		   si.elem_elem_twst_global, d->elem_elem_twst_global);
      put_variable(u, NC_INT, 1, d->len_elem_elem_list,	-1, 
		   si.elem_elem_proc_global, d->elem_elem_proc_global);
    }

  put_variable(u, NC_INT, 2, 
	       d->num_global_node_descriptions,	d->len_node_description, 
	       si.global_node_description,&(d->global_node_description[0][0]));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.my_name,		&(d->my_name));

  put_variable(u, NC_INT, 1, 
	       d->num_neighbors,	-1, 
	       si.neighbor,		d->neighbor);

  if ( d->num_nodes > 0 )
    {
      put_variable(u, NC_INT, 1, 
		   d->num_nodes,	-1, 
		   si.node_index_global,	d->node_index_global);
    }

  put_variable(u, NC_INT, 0, 
	       -1, 	-1, 
	       si.ns_distfact_len_global, &(d->ns_distfact_len_global));

  put_variable(u, NC_INT, 0, 
	       -1, 	-1, 
	       si.ns_node_len_global, &(d->ns_node_len_global));

  put_variable(u, NC_INT, 1, 
	       d->num_node_sets_global,	-1, 
	       si.ns_id_global,		d->ns_id_global);

  put_variable(u, NC_INT, 1, 
	       d->num_node_sets,	-1, 
	       si.ns_index_global,	d->ns_index_global);

  put_variable(u, NC_INT, 1, 
	       d->len_ns_distfact_list,	-1, 
	       si.ns_distfact_list_index_global, 
	       d->ns_distfact_list_index_global);

  put_variable(u, NC_INT, 1, 
	       d->num_node_sets_global,		-1, 
	       si.ns_distfact_index_global,	d->ns_distfact_index_global);

  put_variable(u, NC_INT, 1, 
	       d->num_node_sets_global,		-1, 
	       si.ns_node_index_global,	d->ns_node_index_global);

  put_variable(u, NC_INT, 1, 
	       d->len_ns_node_list,	-1, 
	       si.ns_node_list_index_global, 
	       d->ns_node_list_index_global);



  put_variable(u, NC_INT, 1, 
	       d->num_node_sets_global,		-1, 
	       si.ns_num_distfacts_global,	d->ns_num_distfacts_global);

  put_variable(u, NC_INT, 1, 
	       d->num_node_sets_global,	-1, 
	       si.ns_num_nodes_global,	d->ns_num_nodes_global);

  if ( d->num_props_ns > 1 )
    {
      put_variable(u, NC_INT, 2,
		   d->num_props_ns,		d->num_node_sets_global,
		   si.ns_prop_global,	&(d->ns_prop_global[0][0]));
    }

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_boundary_nodes,	&(d->num_boundary_nodes));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_dofs_global,	&(d->num_dofs_global));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_elems_global,	&(d->num_elems_global));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_external_nodes,	&(d->num_external_nodes));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_internal_nodes,	&(d->num_internal_nodes));

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.num_nodes_global,	&(d->num_nodes_global));

  put_variable(u, NC_INT, 1, 
	       d->len_ptr_set_membership,	-1, 
	       si.ptr_set_membership,	d->ptr_set_membership);

  put_variable(u, NC_INT, 1, 
	       d->len_set_membership,	-1, 
	       si.set_membership,	d->set_membership);

  put_variable(u, NC_INT, 1, d->num_side_sets_global, -1, 
	       si.ss_distfact_index_global, d->ss_distfact_index_global);

  put_variable(u, NC_INT, 0, -1, -1, 
	       si.ss_distfact_len_global, &(d->ss_distfact_len_global));

  if ( d->len_ss_distfact_list > 0 )
    {
      put_variable(u, NC_INT, 1, d->len_ss_distfact_list, -1, 
		   si.ss_distfact_list_index_global, 
		   d->ss_distfact_list_index_global);
    }

  put_variable(u, NC_INT, 1, d->num_side_sets_global, -1, 
	       si.ss_elem_index_global, d->ss_elem_index_global);

  put_variable(u, NC_INT, 0, -1, -1, 
	       si.ss_elem_len_global, &(d->ss_elem_len_global));

  if ( d->len_ss_elem_list > 0 )
    {
      put_variable(u, NC_INT, 1, d->len_ss_elem_list, -1, 
		   si.ss_elem_list_index_global, d->ss_elem_list_index_global);
    }

  put_variable(u, NC_INT, 1, 
	       d->num_side_sets_global,	-1, 
	       si.ss_id_global,		d->ss_id_global);

  if ( d->num_side_sets > 0 )
    {
      put_variable(u, NC_INT, 1, 
		   d->num_side_sets,	-1, 
		   si.ss_index_global,	d->ss_index_global);
    }

  put_variable(u, NC_INT, 1, 
	       d->num_side_sets_global,		-1, 
	       si.ss_num_distfacts_global,	d->ss_num_distfacts_global);

  put_variable(u, NC_INT, 1, 
	       d->num_side_sets_global,		-1, 
	       si.ss_num_sides_global,		d->ss_num_sides_global);

  if ( d->num_props_ss > 1 )
    {
      put_variable(u, NC_INT, 2,
		   d->num_props_ss,		d->num_side_sets_global,
		   si.ss_prop_global,		&(d->ss_prop_global[0][0]));
    }

  put_variable(u, NC_INT, 0, 
	       -1,	-1, 
	       si.undefined_basic_eqnvar_id, &(d->undefined_basic_eqnvar_id));
  
  if (d->num_side_sets_global > 0) {
      put_variable(u, NC_INT, 1,
                   d->num_side_sets_global, -1,
                   si.ss_internal_global, d->ss_internal_global);

      put_variable(u, NC_INT, 1,
                   d->num_side_sets_global+1, -1,
                   si.ss_block_index_global, d->ss_block_index_global);

      put_variable(u, NC_INT, 1,
                   d->ss_block_index_global[d->num_side_sets_global], -1,
                   si.ss_block_list_global, d->ss_block_list_global);
  }  
  /*
   * Close the file (flush buffers).
   */

#ifdef NETCDF_3
  err = nc_close(u);
  if ( err != NC_NOERR )
    {
      EH(-1, "nc_close() problem.");
    }
#endif
#ifdef NETCDF_2
  err = ncclose(u);
  EH(err, "ncclose()");
#endif

  return(status);
}
コード例 #8
0
ファイル: mppnccombine.c プロジェクト: rwills/fms-idealized
/* Open an input netCDF file and get some information about it */
int process_ncinfile(char *ncname, unsigned char appendnc, int outncfid,
                     char *outncname, int *nfiles, unsigned char verbose)
{
    struct fileinfo ncinfile;  /* Information about an input netCDF file */
    int nfiles2;  /* Number of files in the decomposed domain */
    int d, v, n;  /* Loop variables */
    int dimid;  /* ID of a dimension */
    int decomp[4];  /* "domain_decomposition" information */
    char attname[MAX_NC_NAME];  /* Name of a global or variable attribute */
    unsigned char ncinfileerror=0;  /* Were there any file errors? */

    /* Open an input netCDF file; return if not openable - possibly IEEE */
    if ((ncinfile.ncfid=ncopen(ncname,NC_NOWRITE))==(-1)) return(2);

    /* Determine the number of files in the decomposed domain */
    if (ncattget(ncinfile.ncfid,NC_GLOBAL,"NumFilesInSet",
                 (void *)&nfiles2)==(-1))
    {
        if (*nfiles==1)
        {
            fprintf(stderr,"Error: missing the \"NumFilesInSet\" global attribute!\n");
            return(1);
        }
        else if (*nfiles==(-1))
        {
            fprintf(stderr,"Warning: missing the \"NumFilesInSet\" global attribute.\n");
        }
    }
    *nfiles=nfiles2;

    /* Get some general information about the input netCDF file */
    if (ncinquire(ncinfile.ncfid,&(ncinfile.ndims),&(ncinfile.nvars),
                  &(ncinfile.ngatts),&(ncinfile.recdim))==(-1))
    {
        fprintf(stderr,"Error: cannot read the file's metadata!\n");
        ncclose(ncinfile.ncfid);
        return(1);
    }

    /* Get some information about the dimensions */
    for (d=0; d < ncinfile.ndims; d++)
    {
        if ((ncdiminq(ncinfile.ncfid,d,ncinfile.dimname[d],
                      &(ncinfile.dimsize[d])))==(-1))
        {
            fprintf(stderr,"Error: cannot read dimension #%d's metadata!\n",d);
            ncclose(ncinfile.ncfid);
            return(1);
        }
        ncinfile.dimfullsize[d]=ncinfile.dimsize[d];
        ncinfile.dimstart[d]=1;
        ncinfile.dimend[d]=(-1);
    }

    /* Get some information about the variables */
    for (v=0; v < ncinfile.nvars; v++)
    {
        if ((ncvarinq(ncinfile.ncfid,v,ncinfile.varname[v],
                      &(ncinfile.datatype[v]),&(ncinfile.varndims[v]),
                      ncinfile.vardim[v],&(ncinfile.natts[v])))==(-1))
        {
            fprintf(stderr,"Error: cannot read variable #%d's metadata!\n",v);
            ncclose(ncinfile.ncfid);
            return(1);
        }

        /* If the variable is also a dimension then get decomposition info */
        if ((dimid=ncdimid(ncinfile.ncfid,ncinfile.varname[v]))!=(-1))
        {
            if (ncattget(ncinfile.ncfid,v,"domain_decomposition",
                         (void *)decomp)!=(-1))
            {
                ncinfile.dimfullsize[dimid]=decomp[1]-decomp[0]+1;
                ncinfile.dimstart[dimid]=decomp[2]-(decomp[0]-1);
                ncinfile.dimend[dimid]=decomp[3]-(decomp[0]-1);
            }
            else
            {
                ncinfile.dimfullsize[dimid]=ncinfile.dimsize[dimid];
                ncinfile.dimstart[dimid]=1;
                ncinfile.dimend[dimid]=(-1);
            }
        }
    }

#if DEBUG==1
    print_debug(&ncinfile,verbose);
#endif

    /* If the output netCDF file was just created then define its structure */
    if (!appendnc)
    {
#if DEBUG==1
        printf("Creating output netCDF file... \"%s\"\n",outncname);
#endif
        /* Define the dimensions */
        for (d=0; d < ncinfile.ndims; d++)
        {
            if (d==ncinfile.recdim)
                ncdimdef(outncfid,ncinfile.dimname[d],NC_UNLIMITED);
            else ncdimdef(outncfid,ncinfile.dimname[d],ncinfile.dimfullsize[d]);
        }

        /* Define the variables and copy their attributes */
        for (v=0; v < ncinfile.nvars; v++)
        {
            ncvardef(outncfid,ncinfile.varname[v],ncinfile.datatype[v],
                     ncinfile.varndims[v],ncinfile.vardim[v]);
            for (n=0; n < ncinfile.natts[v]; n++)
            {
                ncattname(ncinfile.ncfid,v,n,attname);
                if (!strcmp(attname,"domain_decomposition")) continue;
                else
                {
                    if (ncattcopy(ncinfile.ncfid,v,attname,outncfid,v)==(-1))
                    {
                        fprintf(stderr,"Error: cannot copy variable \"%s\"'s attributes!\n",
                                ncinfile.varname[v]);
                        return(1);
                    }
                }
            }
        }

        /* Copy the global attributes */
        for (n=0; n < ncinfile.ngatts; n++)
        {
            ncattname(ncinfile.ncfid,NC_GLOBAL,n,attname);
            if (!strcmp(attname,"NumFilesInSet")) continue;
            else if (!strcmp(attname,"filename"))
                ncattput(outncfid,NC_GLOBAL,attname,NC_CHAR,strlen(outncname),
                         (void *)outncname);
            else
            {
                if (ncattcopy(ncinfile.ncfid,NC_GLOBAL,attname,outncfid,
                              NC_GLOBAL)==(-1))
                {
                    fprintf(stderr,"Error: cannot copy the file's global attributes!\n");
                    return(1);
                }
            }
        }

        /* Definitions done */
        ncendef(outncfid);
    }

    /* Copy all the data values of the dimensions and variables */
    ncinfileerror=copy_nc_data(&ncinfile,outncfid,appendnc,verbose);

    /* Done */
    ncclose(ncinfile.ncfid);
    return(ncinfileerror);
}
コード例 #9
0
ファイル: mppnccombine.c プロジェクト: rwills/fms-idealized
int main(int argc, char *argv[])
{
    unsigned char verbose=0;  /* Print some progress information? */
    unsigned char appendnc=0;  /* Append to an existing netCDF file? */
    unsigned char removein=0;  /* Remove the ".####" decomposed input files? */
    int nstart=0;  /* PE number of the first input netCDF file */
    int nend;  /* PE number of the last input netCDF file */
    int outputarg=(-1);  /* Argument # of the output netCDF file */
    int inputarg=(-1);  /* Argument # of first input netCDF file */
    struct stat statbuf;  /* Dummy structure for file-testing "stat" call */
    int outncfid;  /* ID of the output netCDF file */
    char outfilename[2048], *strptr;  /* Name of the output netCDF file */
    int outlen;  /* Length of the output filename */
    char infilename[2048];  /* Name of an input file */
    unsigned char infileerror=0;  /* Were there any file errors? */
    int nfiles=(-1);  /* Number of files in the decomposed domain */
    int a;  /* Loop variable */

    /* Check the command-line arguments */
    if (argc < 2)
    {
        usage();
        return(1);
    }
    for (a=1; a < argc; a++)
    {
        if (!strcmp(argv[a],"-v")) verbose=1;
        else if (!strcmp(argv[a],"-a")) appendnc=1;
        else if (!strcmp(argv[a],"-r")) removein=1;
        else if (!strcmp(argv[a],"-n"))
        {
            a++;
            if (a < argc) nstart=atoi(argv[a]);
            else
            {
                usage();
                return(1);
            }
        }
        else
        {
            outputarg=a;
            break;
        }
    }
    if (outputarg==(-1))
    {
        usage();
        return(1);
    }
    if (argc-1 > outputarg) inputarg=outputarg+1;
    sprintf(outfilename,argv[outputarg]);
    outlen=strlen(outfilename);
    if (outlen > 4)
    {
        strptr=outfilename+outlen-5;
        if (!strcmp(strptr,".0000")) outfilename[outlen-5]='\0';
    }

    /* Disable fatal returns from netCDF library functions */
    ncopts=0;

    /* Create a new netCDF output file */
    if (!appendnc)
    {
        if (stat(outfilename,&statbuf)==0)
        {
            fprintf(stderr,"Error: output file seems to exist already!\n");
            return(1);
        }
        if ((outncfid=nccreate(outfilename,NC_NOCLOBBER))==(-1))
        {
            fprintf(stderr,"Error: cannot create the output netCDF file!\n");
            return(1);
        }
        ncsetfill(outncfid,NC_NOFILL);
    }
    /* Open an existing netCDF file for appending */
    else
    {
        if ((outncfid=ncopen(outfilename,NC_WRITE))==(-1))
        {
            fprintf(stderr,"Error: cannot open the output netCDF file for appending!\n");
            return(1);
        }
    }

    /* No input files are specified on the command-line */
    if (inputarg==(-1))
    {
        nend=nstart+1;
        for (a=nstart; a < nend; a++)
        {
            sprintf(infilename,"%s.%04d",outfilename,a);
            if (verbose) printf("Processing... \"%s\"",infilename);
#if DEBUG==1
            else if (!verbose) printf("\nfile=%s\n",infilename);
#endif
            if (stat(infilename,&statbuf)!=0)
            {
                if (verbose) printf("\n");
                fprintf(stderr,"Error: cannot read the input file \"%s\"!\n",
                        infilename);
                if (a==0) infileerror=3;
                else infileerror=1;
                break;
            }
            infileerror=process_ncinfile(infilename,appendnc,outncfid,
                                         outfilename,&nfiles,verbose);
            if (infileerror==2)
            {
                printf("IEEE input files are not currently supported!\n");
                infileerror=3;
                break;
            }
            else if (infileerror==1) break;
            if (a==nstart && nfiles > 0) nend=nstart+nfiles;
            appendnc=1;
            if (verbose)
            {
                if ((nend-a-1)==1) printf("\n(1 file to go)\n");
                else printf("\n(%d files to go)\n",nend-a-1);
            }
        }
    }
    /* Loop over all the specified input files */
    else
        for (a=inputarg; a < argc; a++)
        {
            if (verbose) printf("Processing... \"%s\"",argv[a]);
#if DEBUG==1
            else if (!verbose) printf("\nfile=%s\n",argv[a]);
#endif
            if (stat(argv[a],&statbuf)!=0)
            {
                if (verbose) printf("\n");
                fprintf(stderr,"Error: cannot read the input file \"%s\"!\n",
                        argv[a]);
                if (a==inputarg) infileerror=3;
                else infileerror=1;
                break;
            }
            infileerror=process_ncinfile(argv[a],appendnc,outncfid,outfilename,
                                         &nfiles,verbose);
            if (infileerror==2)
            {
                printf("IEEE input files are not currently supported!\n");
                infileerror=3;
                break;
            }
            else if (infileerror==1) return(1);
            appendnc=1;
            if (verbose)
            {
                if ((argc-a-1)==1) printf("\n(1 file to go)\n");
                else printf("\n(%d files to go)\n",argc-a-1);
            }
        }

    /* Clean up... return 1 on error, otherwise 0 */
    ncclose(outncfid);
    if (!infileerror)
    {
        if (removein)
        {
            /* No input files are specified on the command-line */
            if (inputarg==(-1))
            {
                for (a=nstart; a < nend; a++)
                {
                    sprintf(infilename,"%s.%04d",outfilename,a);
                    if (verbose)
                    {
                        if ((nend-a-1)==1)
                            printf("Removing... \"%s\" (1 file to go)\n",infilename);
                        else
                            printf("Removing... \"%s\" (%d files to go)\n",infilename,
                                   nend-a-1);
                    }
                    unlink(infilename);
                }
            }
            /* Loop over all the specified input files */
            else
                for (a=inputarg; a < argc; a++)
                {
                    printf("Removing... \"%s\" (%d files to go)\n",argv[a],
                           argc-a-1);
                    unlink(argv[a]);
                }
        }
    }
    else if (infileerror==3)
    {
        unlink(outfilename);
        infileerror=1;
    }
    return(infileerror);
}
コード例 #10
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
/*
 * TODO, lots of declared, but unused variables here
 */
static void do_netcdfquery_proc(Widget, XtPointer, XtPointer)
{
    int setno, src;
    char xvar[256], yvar[256];
    char buf[256], fname[512];
    XmString xms;
    XmString *s, cs;
    int *pos_list;
    int i, j, pos_cnt, cnt;
    char *cstr;

    int cdfid; /* netCDF id */
    int ndims, nvars, ngatts, recdim;
    int var_id;
    long start[2];
    long count[2];
    char varname[256];
    nc_type datatype = 0;
    int dim[100], natts;
    long dimlen[100];
    long len;

    int x_id, y_id;
    nc_type xdatatype = 0;
    nc_type ydatatype = 0;
    int xndims, xdim[10], xnatts;
    int yndims, ydim[10], ynatts;
    long nx, ny;

    int atlen;
    char attname[256];
    char atcharval[256];

    extern int ncopts;

    ncopts = 0; /* no crash on error */

    set_wait_cursor();

    strcpy(fname, xv_getstr(netcdf_file_item));

    if ((cdfid = ncopen(fname, NC_NOWRITE)) == -1)
    {
        errwin("Can't open file.");
        goto out2;
    }
    if (XmListGetSelectedPos(netcdf_listx_item, &pos_list, &pos_cnt))
    {
        XtVaGetValues(netcdf_listx_item,
                      XmNselectedItemCount, &cnt,
                      XmNselectedItems, &s,
                      NULL);
        cs = XmStringCopy(*s);
        if (XmStringGetLtoR(cs, charset, &cstr))
        {
            strcpy(xvar, cstr);
            XtFree(cstr);
        }
        XmStringFree(cs);
    }
    else
    {
        errwin("Need to select X, either variable name or INDEX");
        goto out1;
    }
    if (XmListGetSelectedPos(netcdf_listy_item, &pos_list, &pos_cnt))
    {
        XtVaGetValues(netcdf_listy_item,
                      XmNselectedItemCount, &cnt,
                      XmNselectedItems, &s,
                      NULL);
        cs = XmStringCopy(*s);
        if (XmStringGetLtoR(cs, charset, &cstr))
        {
            strcpy(yvar, cstr);
            XtFree(cstr);
        }
        XmStringFree(cs);
    }
    else
    {
        errwin("Need to select Y");
        goto out1;
    }
    if (strcmp(xvar, "INDEX") == 0)
    {
        stufftext("X is the index of the Y variable\n", STUFF_START);
    }
    else
    {
        if ((x_id = ncvarid(cdfid, xvar)) == -1)
        {
            char ebuf[256];
            sprintf(ebuf, "do_query(): No such variable %s for X", xvar);
            errwin(ebuf);
            goto out1;
        }
        ncvarinq(cdfid, x_id, NULL, &xdatatype, &xndims, xdim, &xnatts);
        ncdiminq(cdfid, xdim[0], NULL, &nx);
        sprintf(buf, "X is %s, data type %s \t length [%d]\n", xvar, getcdf_type(xdatatype), nx);
        stufftext(buf, STUFF_TEXT);
        sprintf(buf, "\t%d Attributes:\n", xnatts);
        stufftext(buf, STUFF_TEXT);
        for (i = 0; i < xnatts; i++)
        {
            atcharval[0] = 0;
            ncattname(cdfid, x_id, i, attname);
            ncattinq(cdfid, x_id, attname, &datatype, &atlen);
            switch (datatype)
            {
            case NC_CHAR:
                ncattget(cdfid, x_id, attname, (void *)atcharval);
                break;
            }
            sprintf(buf, "\t\t%s: %s\n", attname, atcharval);
            stufftext(buf, STUFF_TEXT);
        }
    }
    if ((y_id = ncvarid(cdfid, yvar)) == -1)
    {
        char ebuf[256];
        sprintf(ebuf, "do_query(): No such variable %s for Y", yvar);
        errwin(ebuf);
        goto out1;
    }
    ncvarinq(cdfid, y_id, NULL, &ydatatype, &yndims, ydim, &ynatts);
    ncdiminq(cdfid, ydim[0], NULL, &ny);
    sprintf(buf, "Y is %s, data type %s \t length [%d]\n", yvar, getcdf_type(ydatatype), ny);
    stufftext(buf, STUFF_TEXT);
    sprintf(buf, "\t%d Attributes:\n", ynatts);
    stufftext(buf, STUFF_TEXT);
    for (i = 0; i < ynatts; i++)
    {
        atcharval[0] = 0;
        ncattname(cdfid, y_id, i, attname);
        ncattinq(cdfid, y_id, attname, &datatype, &atlen);
        switch (datatype)
        {
        case NC_CHAR:
            ncattget(cdfid, y_id, attname, (void *)atcharval);
            break;
        }
        sprintf(buf, "\t\t%s: %s\n", attname, atcharval);
        stufftext(buf, STUFF_TEXT);
    }

out1:
    ;
    ncclose(cdfid);

out2:
    ;
    stufftext("\n", STUFF_STOP);
    unset_wait_cursor();
}
コード例 #11
0
ファイル: exopen.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_open (const char  *path,
             int    mode,
             int   *comp_ws,
             int   *io_ws,
             float *version)
{
   int exoid;
   nclong file_wordsize;
   char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */
 
/* set error handling mode to no messages, non-fatal errors */
  ex_opts(exoptval);    /* call required to set ncopts first time through */


  if (mode == EX_READ)  /* READ ONLY */
  {
#if defined(__LIBCATAMOUNT__)
    if ((exoid = ncopen (path, NC_NOWRITE)) < 0)
#else
    if ((exoid = ncopen (path, NC_NOWRITE|NC_SHARE)) < 0)
#endif
    {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      if (ncerr == 0)
        exerrval = EX_FATAL;
      else
        exerrval = ncerr;
      sprintf(errmsg,"Error: failed to open %s read only",path);
      ex_err("ex_open",errmsg,exerrval); 
      return(EX_FATAL);
    } 
  }

  else if (mode == EX_WRITE) /* READ/WRITE */
  {
#if defined(__LIBCATAMOUNT__)
    if ((exoid = ncopen (path, NC_WRITE)) < 0)
#else
    if ((exoid = ncopen (path, NC_WRITE|NC_SHARE)) < 0)
#endif
    {
      /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
      if (ncerr == 0)
        exerrval = EX_FATAL;
      else
        exerrval = ncerr;
      sprintf(errmsg,"Error: failed to open %s write only",path);
      ex_err("ex_open",errmsg,exerrval); 
      return(EX_FATAL);
    } 

    /* turn off automatic filling of netCDF variables */

    if (ncsetfill (exoid, NC_NOFILL) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
             "Error: failed to set nofill mode in file id %d",
              exoid);
      ex_err("ex_open", errmsg, exerrval);
      return (EX_FATAL);
    }
  }
  else 
  {
    exerrval = EX_BADFILEMODE;
    sprintf(errmsg,"Error: invalid file open mode: %d",mode);
    ex_err("ex_open",errmsg,exerrval); 
    return (EX_FATAL);
  }

/* determine version of EXODUS II file, and the word size of
 * floating point values stored in the file
 */

   if (ncattget (exoid, NC_GLOBAL, ATT_VERSION, version) == -1)
   {
     exerrval  = ncerr;
     sprintf(errmsg,"Error: failed to get database version for file id: %d",
             exoid);
     ex_err("ex_open",errmsg,exerrval);
     return(EX_FATAL);
   }
   
/* check ExodusII file version - old version 1.x files are not supported */
   if (*version < 2.0)
   {
     exerrval  = EX_FATAL;
     sprintf(errmsg,"Error: Unsupported file version %.2f in file id: %d",
             *version, exoid);
     ex_err("ex_open",errmsg,exerrval);
     return(EX_FATAL);
   }
   
   if (ncattget (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, &file_wordsize) == -1)
   {  /* try old (prior to db version 2.02) attribute name */
     if (ncattget (exoid,NC_GLOBAL,ATT_FLT_WORDSIZE_BLANK,&file_wordsize) == -1)
     {
       exerrval  = EX_FATAL;
       sprintf(errmsg,"Error: failed to get file wordsize from file id: %d",
             exoid);
       ex_err("ex_open",errmsg,exerrval);
       return(exerrval);
     }
   }

/* initialize floating point size conversion.
 */

   if (ex_conv_ini( exoid, comp_ws, io_ws, file_wordsize ) != EX_NOERR ) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
           "Error: failed to init conversion routines in file id %d",
            exoid);
     ex_err("ex_open", errmsg, exerrval);
     return (EX_FATAL);
   }

   return (exoid);
}
コード例 #12
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
void update_netcdfs(void)
{
    int i, j;
    char buf[256], fname[512];
    XmString xms;
    int cdfid; /* netCDF id */
    int ndims, nvars, ngatts, recdim;
    int var_id;
    long start[2];
    long count[2];
    char varname[256];
    nc_type datatype = 0;
    int dim[100], natts;
    long dimlen[100];
    long len;
    extern int ncopts;

    ncopts = 0; /* no crash on error */

    if (netcdf_frame != NULL)
    {
        strcpy(fname, xv_getstr(netcdf_file_item));
        set_wait_cursor();
        XmListDeleteAllItems(netcdf_listx_item);
        XmListDeleteAllItems(netcdf_listy_item);
        xms = XmStringCreateLtoR("INDEX", charset);
        XmListAddItemUnselected(netcdf_listx_item, xms, 0);
        XmStringFree(xms);

        if (strlen(fname) < 2)
        {
            unset_wait_cursor();
            return;
        }
        if ((cdfid = ncopen(fname, NC_NOWRITE)) == -1)
        {
            errwin("Can't open file.");
            unset_wait_cursor();
            return;
        }
        ncinquire(cdfid, &ndims, &nvars, &ngatts, &recdim);
        /*
          printf("%d %d %d %d\n", ndims, nvars, ngatts, recdim);
      */
        for (i = 0; i < ndims; i++)
        {
            ncdiminq(cdfid, i, NULL, &dimlen[i]);
        }
        for (i = 0; i < nvars; i++)
        {
            ncvarinq(cdfid, i, varname, &datatype, &ndims, dim, &natts);
            if ((var_id = ncvarid(cdfid, varname)) == -1)
            {
                char ebuf[256];
                sprintf(ebuf, "update_netcdfs(): No such variable %s", varname);
                errwin(ebuf);
                continue;
            }
            if (ndims != 1)
            {
                continue;
            }
            ncdiminq(cdfid, dim[0], (char *)NULL, &len);
            sprintf(buf, "%s", varname);
            xms = XmStringCreateLtoR(buf, charset);
            XmListAddItemUnselected(netcdf_listx_item, xms, 0);
            XmListAddItemUnselected(netcdf_listy_item, xms, 0);
            XmStringFree(xms);
        }
        ncclose(cdfid);
        unset_wait_cursor();
    }
}
コード例 #13
0
ファイル: vc06c.c プロジェクト: gavin971/ncl
int main(int argc, char *argv[])
{
    char const *wks_type = "x11";
    int appid,wid,vcid,vfid, sfid, mpid;
    int rlist;
    float U[73][73],V[73][73], PSL[73][73];
    char  smindist0[6] ;
    char  smindist1[5] ;
    char  smindist2[4] ;
    char  title[35];
    char  smindist[7] ;
    char slongitude[100] ;
/*
 * Declare variables for getting information from netCDF file.
 */
    int   uv, p, u_id, v_id, p_id, lon_id, lat_id, FRAME_COUNT;
    int  i, mindistval, longitudeval;
    ng_size_t icount[3];
    float val;
    long  start[2], count[2], lonlen, latlen; 
    float CenLonF;
    char  filenameUV[256];
    char  filenamePsl[256];
    const char *dirUV = _NGGetNCARGEnv("data");
    const char *dirPsl = _NGGetNCARGEnv("data");
/*
 * Generate vector data array
 */
    FRAME_COUNT=13;
/*
 * Open the netCDF file.
 */
    sprintf( filenameUV, "%s/cdf/941110_UV.cdf", dirUV );
    uv = ncopen(filenameUV,NC_NOWRITE);
/*
 * Open the netCDF file.
 */
    sprintf( filenamePsl, "%s/cdf/941110_P.cdf", dirPsl );
    p = ncopen(filenamePsl,NC_NOWRITE);
/*
 * Initialize the high level utility library
 */
    NhlInitialize();
/*
 * Create an application context. Set the app dir to the current
 * directory so the application looks for a resource file in the working
 * directory. 
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"vc06",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./vc06c.ncgm");
        NhlCreate(&wid,"vc06Work",
                  NhlncgmWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 * Create an X workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlCreate(&wid,"vc06Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }

    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"vc06c.ps");
        NhlCreate(&wid,"vc06Work",NhlpsWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"vc06c.pdf");
        NhlCreate(&wid,"vc06Work",NhlpdfWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
             !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
/*
 * Create a cairo PS/PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"vc06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"vc06Work",NhlcairoDocumentWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"vc06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"vc06Work",NhlcairoImageWorkstationClass,appid,rlist);
    }
/*
 * Get the U and V and lat/lon dimensions.
 */
    lat_id = ncdimid(uv,"lat");
    lon_id = ncdimid(uv,"lon");
    u_id = ncvarid(uv,"u");
    v_id = ncvarid(uv,"v");
    ncdiminq(uv,lat_id,(char *)0,&latlen);
    ncdiminq(uv,lon_id,(char *)0,&lonlen);

    start[0] = start[1] = 0;
    count[0] = latlen; count[1] = lonlen;
    ncvarget(uv,u_id,(long const *)start,(long const *)count,U);
    ncvarget(uv,v_id,(long const *)start,(long const *)count,V);
/*
 * Create a VectorField data object using the data set defined above.
 * By default the array bounds will define the data boundaries (zero-based,
 * as in C language conventions)
 */
    icount[0] = latlen; icount[1] = lonlen;

    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,&U[0][0],2,icount);
    NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,&V[0][0],2,icount);
    NhlRLSetFloat(rlist,NhlNvfXCStartV, -180.0);
    NhlRLSetFloat(rlist,NhlNvfXCEndV, 180.0);
    NhlRLSetFloat(rlist,NhlNvfYCStartV,-90.0);
    NhlRLSetFloat(rlist,NhlNvfYCEndV, 90.0);
    NhlCreate(&vfid,"vectorfield",NhlvectorFieldClass,appid,rlist);
/*
 * Get the PSL and lat/lon dimensions.
 */
    lat_id = ncdimid(p,"lat");
    lon_id = ncdimid(p,"lon");
    p_id = ncvarid(p,"Psl");
    ncdiminq(p,lat_id,(char *)0,&latlen);
    ncdiminq(p,lon_id,(char *)0,&lonlen);

    start[0] = start[1] = 0;
    count[0] = latlen; count[1] = lonlen;
    ncvarget(p,p_id,(long const *)start,(long const *)count,PSL);
    icount[0] = latlen; icount[1] = lonlen;

    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,&PSL[0][0],2,icount);
    NhlRLSetFloat(rlist,NhlNsfXCStartV, -180.0);
    NhlRLSetFloat(rlist,NhlNsfXCEndV, 180.0);
    NhlRLSetFloat(rlist,NhlNsfYCStartV, -90.0);
    NhlRLSetFloat(rlist,NhlNsfYCEndV, 90.0);
    NhlCreate(&sfid,"scalarfield",NhlscalarFieldClass,appid,rlist);
/*
 * Create a VectorPlot object, supplying the VectorField object as data
 * Setting vcMonoFillArrowFillColor False causes VectorPlot to color the
 * vector arrows individually based, by default, on the vector magnitude.
 * Also supply the ScalarField object that will be used to determine the
 * color of each individual vector arrow.
 * Setting vcMonoVectorLineColor False causes VectorPlot to color the
 * vector arrows individually and setting vcUseScalarArray True results
 * in VectorPlot applying the colors based on the contents of the scalarfield.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvcRefMagnitudeF, 20.0);
    NhlRLSetString(rlist,NhlNvcUseScalarArray, "True");
    NhlRLSetString(rlist,NhlNvcFillArrowsOn, "True");
    NhlRLSetString(rlist,NhlNvcMonoFillArrowFillColor, "False");
    NhlRLSetFloat(rlist,NhlNvcMinFracLengthF, 0.25);
    NhlRLSetInteger(rlist,NhlNvcVectorFieldData,vfid);
    NhlRLSetInteger(rlist,NhlNvcScalarFieldData,sfid);
    NhlCreate(&vcid,"vectorplot",NhlvectorPlotClass,wid,rlist);

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNmpProjection, "ORTHOGRAPHIC");
    NhlRLSetFloat(rlist,NhlNmpCenterLatF, 50);
    NhlCreate(&mpid,"mapplot",NhlmapPlotClass,wid,rlist);

    NhlAddOverlay(mpid,vcid, -1);
/*
 * Strings used to create fixed length numbers
 */
    strcpy(smindist0 ,"0.000");
    strcpy(smindist1 ,"0.00");
    strcpy( smindist2 ,"0.0");
/*
 * Create FRAME_COUNT frames, increasing the value of vcMinDistanceF
 * and decreasing the value of mpCenterLonF at each successive frame.
 *
 * Note that the first frame and the last frame are equivalent in
 * longitude.
 */
    for(i = (FRAME_COUNT-1);i > -1; i--){
        NhlRLClear(rlist);       
        CenLonF =  i * 360./(FRAME_COUNT-1);
        NhlRLSetFloat(rlist,NhlNmpCenterLonF,CenLonF);
        NhlSetValues(mpid,rlist);
/*
 * create fixed length strings representing the current longitude
 * and the value of vcMinDistanceF
 */
        longitudeval = (int)(i * 360./(FRAME_COUNT-1) + 0.5);

        sprintf(slongitude,"%d:S:o:N:",longitudeval);

        val = ((FRAME_COUNT-1) - i) * 0.0175/(FRAME_COUNT-1);
        mindistval = (int)(10000*val + 0.5);

        if (mindistval < 10){
            sprintf(smindist,"%s%d",smindist0,mindistval);
        }
        else {
            if (mindistval < 100){
                sprintf(smindist,"%s%d",smindist1,mindistval);
            }
            else {
                sprintf(smindist,"%s%d",smindist2,mindistval);
            }
        }

        NhlRLClear(rlist);
        
        strcpy(title,"Varying vcMinDistanceF :: ");
        strcat(title,smindist);
        
        NhlRLSetString(rlist,NhlNtiMainString,title);
        NhlRLSetString(rlist,NhlNtiXAxisString,slongitude);
        NhlRLSetFloat(rlist,NhlNvcMinDistanceF,val);
        NhlSetValues(vcid,rlist);

        NhlDraw(mpid);
        NhlFrame(wid);

    }/*end for*/
/*
 * Destroy the objects created, close the HLU library and exit.
 */
    NhlDestroy(mpid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
コード例 #14
0
ファイル: cn08c.c プロジェクト: gavin971/ncl
int main()
{
/*
 * Declare variables for the HLU routine calls.
 */
    int     appid, workid, field1, con1;
    int     srlist, i, j, k;
    ng_size_t   icount[2];
    float cmap[NCOLORS][3];
/*
 * Declare variables for getting information from netCDF file.
 */
    int   ncid, lon_id, lat_id, level_id, temp_id;
    float temp[10][33], special_value;
    float lon[36], lat[33], level[10];
    float min_lat, min_level, max_lat, max_level;
    long  start[4], count[4], lonlen, latlen, levellen;
    char  filename[256], string[50];
    const char *dir = _NGGetNCARGEnv("data");
/*
 * Default is to create an NCGM file.
 */
    char const *wks_type = "ncgm";

/*
 * Initialize the HLU library and set up resource template.
 */
    NhlInitialize();
    srlist = NhlRLCreate(NhlSETRL);
/*
 * Create Application object.
 */
    NhlRLClear(srlist);

    NhlRLSetString(srlist,NhlNappDefaultParent,"True");
    NhlRLSetString(srlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"cn08",NhlappClass,NhlDEFAULT_APP,srlist);

	cmap[0][0] = 0.0; cmap[0][1] = 0.0; cmap[0][2] = 0.0;
	cmap[1][0] = 1.0; cmap[1][1] = 1.0; cmap[1][2] = 1.0;
	cmap[2][0] = 1.0; cmap[2][1] = 1.0; cmap[2][2] = 1.0;
	cmap[3][0] = 1.0; cmap[3][1] = 0.0; cmap[3][2] = 0.0;
	cmap[4][0] = 0.0; cmap[4][1] = 1.0; cmap[4][2] = 0.0;
	cmap[5][0] = 0.0; cmap[5][1] = 0.0; cmap[5][2] = 1.0;
	cmap[6][0] = 1.0; cmap[6][1] = 1.0; cmap[6][2] = 0.0;
	cmap[7][0] = 0.0; cmap[7][1] = 1.0; cmap[7][2] = 1.0;
	cmap[8][0] = 1.0; cmap[8][1] = 0.0; cmap[8][2] = 1.0;
	cmap[9][0] = 0.5; cmap[9][1] = 0.0; cmap[9][2] = 0.0;
	cmap[10][0] = 0.5; cmap[10][1] = 1.0; cmap[10][2] = 1.0;
	cmap[11][0] = 0.0; cmap[11][1] = 0.0; cmap[11][2] = 0.5;
	cmap[12][0] = 1.0; cmap[12][1] = 1.0; cmap[12][2] = 0.5;
	cmap[13][0] = 0.5; cmap[13][1] = 0.0; cmap[13][2] = 1.0;
	cmap[14][0] = 1.0; cmap[14][1] = 0.5; cmap[14][2] = 0.0;
	cmap[15][0] = 0.0; cmap[15][1] = 0.5; cmap[15][2] = 1.0;
	cmap[16][0] = 0.5; cmap[16][1] = 1.0; cmap[16][2] = 0.0;
	cmap[17][0] = 0.5; cmap[17][1] = 0.0; cmap[17][2] = 0.5;
	cmap[18][0] = 0.5; cmap[18][1] = 1.0; cmap[18][2] = 0.5;
	cmap[19][0] = 1.0; cmap[19][1] = 0.5; cmap[19][2] = 1.0;
	cmap[20][0] = 0.0; cmap[20][1] = 0.5; cmap[20][2] = 0.0;
	cmap[21][0] = 0.5; cmap[21][1] = 0.5; cmap[21][2] = 1.0;
	cmap[22][0] = 1.0; cmap[22][1] = 0.0; cmap[22][2] = 0.5;

    icount[0] = NCOLORS;
    icount[1] = 3;

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file object.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkMetaName,"./cn08c.ncgm");
        NhlCreate(&workid,"cn08Work",NhlncgmWorkstationClass,
                  NhlDEFAULT_APP,srlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 * Create an X11 workstation.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkPause,"True");
        NhlCreate(&workid,"cn08Work",NhlcairoWindowWorkstationClass,
              NhlDEFAULT_APP,srlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkPSFileName,"./cn08c.ps");
        NhlCreate(&workid,"cn08Work",NhlpsWorkstationClass,
                  NhlDEFAULT_APP,srlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkPDFFileName,"./cn08c.pdf");
        NhlCreate(&workid,"cn08Work",NhlpdfWorkstationClass,
                  NhlDEFAULT_APP,srlist);
    }
    else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
             !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
/*
 * Create a cairo PS/PDF workstation.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkFileName,"./cn08c");
        NhlRLSetString(srlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&workid,"cn08Work",NhlcairoDocumentWorkstationClass,
                  NhlDEFAULT_APP,srlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(srlist);
		NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0],2,icount);
        NhlRLSetString(srlist,NhlNwkFileName,"./cn08c");
        NhlRLSetString(srlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&workid,"cn08Work",NhlcairoImageWorkstationClass,
                  NhlDEFAULT_APP,srlist);
    }
/*
 * Open data file containing grid of global temperatures.
 */
    sprintf( filename, "%s/cdf/contour.cdf", dir );
    ncid = ncopen(filename,NC_NOWRITE);
/*
 * Get the lat/lon/level dimensions.
 */
    lat_id = ncdimid(ncid,"lat");
    lon_id = ncdimid(ncid,"lon");
    level_id  = ncdimid(ncid,"level");
    ncdiminq(ncid,lat_id,(char *)0,&latlen);
    ncdiminq(ncid,lon_id,(char *)0,&lonlen);
    ncdiminq(ncid,level_id,(char *)0,&levellen);
/*
 * Read in temperature values and convert from degrees F to degrees K.
 */
    temp_id = ncvarid(ncid,"T");
    start[0] = start[1] = start[2] = start[3] = 0;
    count[0] = 1; count[1] = levellen; count[2] = latlen; count[3] = 1;
    ncvarget(ncid,temp_id,(long const *)start,(long const *)count,temp);
    ncattget(ncid,temp_id,"_FillValue",&special_value);
    for( j = 0; j < levellen; j++ ) {
        for( k = 0; k < latlen; k++ ) {
            temp[j][k] = (temp[j][k] - 273.15) * 9./5. + 32.;
        }
    }
/*
 * Read in lat/lon/level values.
 */
    lat_id = ncvarid(ncid,"lat");
    count[0] = latlen;
    ncvarget(ncid,lat_id,(long const *)start,(long const *)count,lat);

    lon_id = ncvarid(ncid,"lon");
    count[0] = lonlen;
    ncvarget(ncid,lon_id,(long const *)start,(long const *)count,lon);

    level_id = ncvarid(ncid,"level");
    count[0] = levellen;
    ncvarget(ncid,level_id,(long const *)start,(long const *)count,level);
/*
 * Set up initial scalar field with longitude of temperature data.
 */
    icount[0] = levellen; icount[1] = latlen;
    NhlRLClear(srlist);
    NhlRLSetMDFloatArray(srlist,NhlNsfDataArray,&temp[0][0],2,icount);
    NhlRLSetFloat(srlist,NhlNsfMissingValueV,special_value);
    NhlRLSetFloat(srlist,NhlNsfXCStartV,lat[0]);
    NhlRLSetFloat(srlist,NhlNsfXCEndV,lat[latlen-1]);
    NhlRLSetFloatArray(srlist,NhlNsfXArray,lat,latlen);
    NhlRLSetFloatArray(srlist,NhlNsfYArray,level,levellen);
    NhlCreate(&field1,"field1",NhlscalarFieldClass,appid,srlist);
/*
 * Determine extents of grid
 */
    if(lat[0] < lat[latlen-1]) {
        min_lat = lat[0];
        max_lat = lat[latlen-1];
    }
    else {
        max_lat = lat[0];
        min_lat = lat[latlen-1];
    }
    if(level[0] < level[levellen-1]) {
        min_level = level[0];
        max_level = level[levellen-1];
    }
    else {
        max_level = level[0];
        min_level = level[levellen-1];
    }
/*
 * Create contour using manual spacing.
 */
    NhlRLClear(srlist);
    NhlRLSetFloat(srlist,NhlNvpXF,.2);
    NhlRLSetFloat(srlist,NhlNvpYF,.8);
    NhlRLSetFloat(srlist,NhlNvpWidthF, .6);
    NhlRLSetFloat(srlist,NhlNvpHeightF, .6);
    NhlRLSetString(srlist,NhlNcnFillOn, "True");
    NhlRLSetInteger(srlist,NhlNcnScalarFieldData, field1);
    NhlRLSetString(srlist,NhlNcnLevelSelectionMode, "ManualLevels");
    NhlRLSetInteger(srlist,NhlNcnMaxLevelCount, 25);
    NhlRLSetFloat(srlist,NhlNcnMinLevelValF, -80.0);
    NhlRLSetFloat(srlist,NhlNcnMaxLevelValF, 110.0);
    NhlRLSetFloat(srlist,NhlNcnLevelSpacingF, 10.0);
    NhlRLSetFloat(srlist,NhlNtrXMinF, min_lat);
    NhlRLSetFloat(srlist,NhlNtrXMaxF, max_lat);
    NhlRLSetFloat(srlist,NhlNtrYMinF, min_level);
    NhlRLSetFloat(srlist,NhlNtrYMaxF, max_level);
    NhlRLSetString(srlist,NhlNtrYReverse, "True");
    sprintf(string,"Longitude %g Degrees", lon[0] );
    NhlRLSetString(srlist,NhlNtiMainString,string);
    NhlCreate(&con1,"con1",NhlcontourPlotClass,workid,srlist);
/* 
 * Draw first step
 */
    NhlDraw(con1);
    NhlFrame(workid);
/*
 * Loop on remaining longitude values and reset the title every
 * iteration.
 */
    for( i = 1; i <= lonlen-1; i++ ) {
/*
 * Read in temperature values and convert from degrees F to degrees K.
 */
        start[0] = start[1] = start[2] = 0;
        start[3] = i;
        count[0] = 1; count[1] = levellen;
        count[2] = latlen; count[3] = 1;
        ncvarget(ncid,temp_id,(long const *)start,(long const *)count,
                 temp);
        for( j = 0; j < levellen; j++ ) {
            for( k = 0; k < latlen; k++ ) {
                temp[j][k] = (temp[j][k] - 273.15) * 9./5. + 32.;
            }
        }
        NhlRLClear(srlist);
        icount[0] = levellen; icount[1] = latlen;
        NhlRLSetMDFloatArray(srlist,NhlNsfDataArray,&temp[0][0],2,icount);
/*
 * Create new scalar field.
 */
        NhlSetValues(field1,srlist);
        NhlRLClear(srlist);
        sprintf(string,"Longitude %g Degrees", lon[i] );
        NhlRLSetString(srlist,NhlNtiMainString,string);
        NhlSetValues(con1,srlist);
        NhlDraw(con1);
        NhlFrame(workid);
    }
/*
 * Close the netCDF file.
 */
    ncclose(ncid);
/*
 * NhlDestroy destroys the given id and all of its children.
 */
    NhlRLDestroy(srlist);
    NhlDestroy(appid);
/*
 * Restores state.
 */
    NhlClose();
    exit(0);
}
コード例 #15
0
ファイル: mexcdf53.c プロジェクト: linhvannguyen/PhDworks
void
mexFunction	(
	INT			nlhs,
	Matrix	*	plhs[],
	INT			nrhs,
	const Matrix	*	prhs[]
	)

{
	char		*	opname;
	OPCODE			opcode;
	
	Matrix		*	mat;
	
	int				status;
	char		*	path;
	int				cmode;
	int				mode;
	int				cdfid;
	int				ndims;
	int				nvars;
	int				natts;
	int				recdim;
	char		*	name;
	long			length;
	int				dimid;
	nc_type			datatype;
	int			*	dim;
	int				varid;
	long		*	coords;
	VOIDP			value;
	long		*	start;
	long		*	count;
	int			*	intcount;
	long		*	stride;
	long		*	imap;
	long			recnum;
	int				nrecvars;
	int			*	recvarids;
	long		*	recsizes;
	VOIDPP			datap;		/*	pointers for record access.	*/
	int				len;
	int				incdf;
	int				invar;
	int				outcdf;
	int				outvar;
	int				attnum;
	char		*	attname;
	char		*	newname;
	int				fillmode;
	
	int				i;
	int				m;
	int				n;
	char		*	p;
	char			buffer[MAX_BUFFER];
	
	DOUBLE		*	pr;
	DOUBLE			addoffset;
	DOUBLE			scalefactor;
	int				autoscale;		/*	do auto-scaling if this flag is non-zero.	*/
	
	/*	Disable the NC_FATAL option from ncopts.	*/
	
	if (ncopts & NC_FATAL)	{
		ncopts -= NC_FATAL;
	}
	
	/*	Display usage if less than one input argument.	*/
	
	if (nrhs < 1)	{
	
		Usage();
		
		return;
	}
	
	/*	Convert the operation name to its opcode.	*/
	
	opname = Mat2Str(prhs[0]);
	for (i = 0; i < strlen(opname); i++)	{
		opname[i] = (char) tolower((int) opname[i]);
	}
	p = opname;
	if (strncmp(p, "nc", 2) == 0)	{	/*	Trim away "nc".	*/
		p += 2;
	}
	
	i = 0;
	opcode = NONE;
	while (ops[i].opcode != NONE)	{
		if (!strcmp(p, ops[i].opname))	{
			opcode = ops[i].opcode;
			if (ops[i].nrhs > nrhs)	{
				mexPrintf("MEXCDF: opname = %s\n", opname);
				mexErrMsgTxt("MEXCDF: Too few input arguments.\n");
			}
			else if (0 && ops[i].nlhs > nlhs)	{	/*	Disabled.	*/
				mexPrintf("MEXCDF: opname = %s\n", opname);
				mexErrMsgTxt("MEXCDF: Too few output arguments.\n");
			}
			break;
		}
		else	{
			i++;
		}
	}
	
	if (opcode == NONE)	{
		mexPrintf("MEXCDF: opname = %s\n", opname);
		mexErrMsgTxt("MEXCDF: No such operation.\n");
	}
	
	Free((VOIDPP) & opname);
	
	/*	Extract the cdfid by number.	*/
	
	switch (opcode)	{
	
	case USAGE:
	case CREATE:
	case OPEN:
	case TYPELEN:
	case SETOPTS:
	case ERR:
	case PARAMETER:
	
		break;
	
	default:

		cdfid = Scalar2Int(prhs[1]);
	
		break;
	}
	
	/*	Extract the dimid by number or name.	*/
	
	switch (opcode)	{

	case DIMINQ:
	case DIMRENAME:
	
		if (mxIsNumeric(prhs[2]))	{
			dimid = Scalar2Int(prhs[2]);
		}
		else	{
			name = Mat2Str(prhs[2]);
			dimid = ncdimid(cdfid, name);
			Free((VOIDPP) & name);
		}
		break;
	
	default:
	
		break;
	}
	
	/*	Extract the varid by number or name.	*/
	
	switch (opcode)	{

	case VARINQ:
	case VARPUT1:
	case VARGET1:
	case VARPUT:
	case VARGET:
	case VARPUTG:
	case VARGETG:
	case VARRENAME:
	case VARCOPY:
	case ATTPUT:
	case ATTINQ:
	case ATTGET:
	case ATTCOPY:
	case ATTNAME:
	case ATTRENAME:
	case ATTDEL:
	
		if (mxIsNumeric(prhs[2]))	{
			varid = Scalar2Int(prhs[2]);
		}
		else	{
			name = Mat2Str(prhs[2]);
			varid = ncvarid(cdfid, name);
			Free((VOIDPP) & name);
			if (varid == -1)	{
				varid = Parameter(prhs[2]);
			}
		}
		break;
	
	default:
	
		break;
	}
	
	/*	Extract the attname by name or number.	*/
	
	switch (opcode)	{
	
	case ATTPUT:
	case ATTINQ:
	case ATTGET:
	case ATTCOPY:
	case ATTRENAME:
	case ATTDEL:
	
		if (mxIsNumeric(prhs[3]))	{
			attnum = Scalar2Int(prhs[3]);
			attname = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
			status = ncattname(cdfid, varid, attnum, attname);
		}
		else	{
			attname = Mat2Str(prhs[3]);
		}
		break;
	
	default:
	
		break;
	}
	
	/*	Extract the "add_offset" and "scale_factor" attributes.	*/
	
	switch (opcode)	{
	
	case VARPUT1:
	case VARGET1:
	case VARPUT:
	case VARGET:
	case VARPUTG:
	case VARGETG:

		addoffset = Add_Offset(cdfid, varid);
		scalefactor = Scale_Factor(cdfid, varid);
		if (scalefactor == 0.0)	{
			scalefactor = 1.0;
		}
		
		break;
	
	default:
	
		break;
	}
	
	/*	Perform the NetCDF operation.	*/
	
	switch (opcode)	{
		
	case USAGE:
	
		Usage();
		
		break;
	
	case CREATE:
		
		path = Mat2Str(prhs[1]);
		
		if (nrhs > 2)	{
			cmode = Parameter(prhs[2]);
		}
		else	{
			cmode = NC_NOCLOBBER;	/*	Default.	*/
		}
		
		cdfid = nccreate(path, cmode);
		
		plhs[0] = Int2Scalar(cdfid);
		plhs[1] = Int2Scalar((cdfid >= 0) ? 0 : -1);
		
		Free((VOIDPP) & path);
		
		break;
		
	case OPEN:
		
		path = Mat2Str(prhs[1]);
		
		if (nrhs > 2)	{
			mode = Parameter(prhs[2]);
		}
		else	{
			mode = NC_NOWRITE;	/*	Default.	*/
		}
		
		cdfid = ncopen(path, mode);
		
		plhs[0] = Int2Scalar(cdfid);
		plhs[1] = Int2Scalar((cdfid >= 0) ? 0 : -1);
		
		Free((VOIDPP) & path);
		
		break;
		
	case REDEF:
		
		status = ncredef(cdfid);
		
		plhs[0] = Int2Scalar(status);
		
		break;
		
	case ENDEF:
		
		status = ncendef(cdfid);
		
		plhs[0] = Int2Scalar(status);
		
		break;
		
	case CLOSE:
		
		status = ncclose(cdfid);
		
		plhs[0] = Int2Scalar(status);
		
		break;
		
	case INQUIRE:
	
		status = ncinquire(cdfid, & ndims, & nvars, & natts, & recdim);
		
		if (nlhs > 1)	{
			plhs[0] = Int2Scalar(ndims);
			plhs[1] = Int2Scalar(nvars);
			plhs[2] = Int2Scalar(natts);
			plhs[3] = Int2Scalar(recdim);
			plhs[4] = Int2Scalar(status);
		}
		else	{	/*	Default to 1 x 5 row vector.	*/
			plhs[0] = mxCreateFull(1, 5, REAL);
			pr = mxGetPr(plhs[0]);
			if (status == 0)	{
				pr[0] = (DOUBLE) ndims;
				pr[1] = (DOUBLE) nvars;
				pr[2] = (DOUBLE) natts;
				pr[3] = (DOUBLE) recdim;
			}
			pr[4] = (DOUBLE) status;
		}
		
		break;
		
	case SYNC:
	
		status = ncsync(cdfid);
		
		plhs[0] = Int2Scalar(status);
		
		break;
		
	case ABORT:
	
		status = ncabort(cdfid);
		
		plhs[0] = Int2Scalar(status);
		
		break;
		
	case DIMDEF:
	
		name = Mat2Str(prhs[2]);
		length = Parameter(prhs[3]);
		
		dimid = ncdimdef(cdfid, name, length);
		
		plhs[0] = Int2Scalar(dimid);
		plhs[1] = Int2Scalar((dimid >= 0) ? 0 : dimid);
		
		Free((VOIDPP) & name);
		
		break;
		
	case DIMID:
	
		name = Mat2Str(prhs[2]);
		
		dimid = ncdimid(cdfid, name);
		
		plhs[0] = Int2Scalar(dimid);
		plhs[1] = Int2Scalar((dimid >= 0) ? 0 : dimid);
		
		Free((VOIDPP) & name);
		
		break;
		
	case DIMINQ:
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		
		status = ncdiminq(cdfid, dimid, name, & length);
		
		plhs[0] = Str2Mat(name);
		plhs[1] = Long2Scalar(length);
		plhs[2] = Int2Scalar(status);
		
		Free((VOIDPP) & name);
		
		break;
		
	case DIMRENAME:
		
		name = Mat2Str(prhs[3]);
		
		status = ncdimrename(cdfid, dimid, name);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & name);
		
		break;
		
	case VARDEF:
	
		name = Mat2Str(prhs[2]);
		datatype = (nc_type) Parameter(prhs[3]);
		ndims = Scalar2Int(prhs[4]);
		if (ndims == -1)	{
			ndims = Count(prhs[5]);
		}
		dim = Mat2Int(prhs[5]);
		
		varid = ncvardef(cdfid, name, datatype, ndims, dim);
		
		Free((VOIDPP) & name);
		
		plhs[0] = Int2Scalar(varid);
		plhs[1] = Int2Scalar((varid >= 0) ? 0 : varid);
		
		break;
		
	case VARID:
	
		name = Mat2Str(prhs[2]);
		
		varid = ncvarid(cdfid, name);
		
		Free((VOIDPP) & name);
		
		plhs[0] = Int2Scalar(varid);
		plhs[1] = Int2Scalar((varid >= 0) ? 0 : varid);
		
		break;
		
	case VARINQ:
	
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		plhs[0] = Str2Mat(name);
		plhs[1] = Int2Scalar(datatype);
		plhs[2] = Int2Scalar(ndims);
		plhs[3] = Int2Mat(dim, 1, ndims);
		plhs[4] = Int2Scalar(natts);
		plhs[5] = Int2Scalar(status);
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		break;
		
	case VARPUT1:
		
		coords = Mat2Long(prhs[3]);
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		if (datatype == NC_CHAR)	{
			mat = SetNum(prhs[4]);
		}
		else	{
			mat = prhs[4];
		}
		if (mat == NULL)	{
			mat = prhs[4];
		}
		
		pr = mxGetPr(mat);
		
		autoscale = (nrhs > 5 && Scalar2Int(prhs[5]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		status = Convert(opcode, datatype, 1, buffer, scalefactor, addoffset, pr);
		status = ncvarput1(cdfid, varid, coords, buffer);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & coords);
		
		break;
		
	case VARGET1:
		
		coords = Mat2Long(prhs[3]);
		
		autoscale = (nrhs > 4 && Scalar2Int(prhs[4]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		mat = Int2Scalar(0);
		
		pr = mxGetPr(mat);
		
		status = ncvarget1(cdfid, varid, coords, buffer);
		status = Convert(opcode, datatype, 1, buffer, scalefactor, addoffset, pr);
		
		if (datatype == NC_CHAR)	{
			plhs[0] = SetStr(mat);
		}
		else	{
			plhs[0] = mat;
		}
		if (plhs[0] == NULL)	{
/*			prhs[0] = mat;		*/
			plhs[0] = mat;		/*	ZYDECO 24Jan2000	*/
		}
		
		plhs[1] = Int2Scalar(status);
		
		Free((VOIDPP) & coords);
		
		break;
		
	case VARPUT:
		
		start = Mat2Long(prhs[3]);
		count = Mat2Long(prhs[4]);
		
		autoscale = (nrhs > 6 && Scalar2Int(prhs[6]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		if (datatype == NC_CHAR)	{
			mat = SetNum(prhs[5]);
		}
		else	{
			mat = prhs[5];
		}
		if (mat == NULL)	{
			mat = prhs[5];
		}
		
		pr = mxGetPr(mat);
		
		for (i = 0; i < ndims; i++)	{
			if (count[i] == -1)	{
				status = ncdiminq(cdfid, dim[i], name, & count[i]);
				count[i] -= start[i];
			}
		}
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		len = 0;
		if (ndims > 0)	{
			len = 1;
			for (i = 0; i < ndims; i++)	{
				len *= count[i];
			}
		}
		
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr);
		status = ncvarput(cdfid, varid, start, count, value);
		Free((VOIDPP) & value);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & start);
		Free((VOIDPP) & count);
		
		break;
		
	case VARGET:
		
		start = Mat2Long(prhs[3]);
		count = Mat2Long(prhs[4]);
        intcount = Mat2Int(prhs[4]);
		
		autoscale = (nrhs > 5 && Scalar2Int(prhs[5]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		for (i = 0; i < ndims; i++)	{
			if (count[i] == -1)	{
				status = ncdiminq(cdfid, dim[i], name, & count[i]);
				count[i] -= start[i];
			}
		}
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		m = 0;
		n = 0;
		if (ndims > 0)	{
			m = count[0];
			n = count[0];
			for (i = 1; i < ndims; i++)	{
				n *= count[i];
				if (count[i] > 1)	{
					m = count[i];
				}
			}
			n /= m;
		}
		len = m * n;
		if (ndims < 2)	{
			m = 1;
			n = len;
		}
		
		for (i = 0; i < ndims; i++)	{
			intcount[i] = count[ndims-i-1];   /*	Reverse order.	*/
		}
		
		if (MEXCDF_4 || ndims < 2)	{
			mat = mxCreateFull(m, n, mxREAL);	/*	mxCreateDoubleMatrix	*/
		}
# if MEXCDF_5
		else	{
			mat = mxCreateNumericArray(ndims, intcount, mxDOUBLE_CLASS, mxREAL);
		}
# endif
		
		pr = mxGetPr(mat);
		
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = ncvarget(cdfid, varid, start, count, value);
		status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr);
		Free((VOIDPP) & value);
		
		if (datatype == NC_CHAR)	{
			plhs[0] = SetStr(mat);
		}
		else	{
			plhs[0] = mat;
		}
		if (plhs[0] == NULL)	{
			plhs[0] = mat;
		}
		
		plhs[1] = Int2Scalar(status);
		
		Free((VOIDPP) & intcount);
		Free((VOIDPP) & count);
		Free((VOIDPP) & start);
		
		break;
		
	case VARPUTG:
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		if (nrhs > 7)	{
			if (datatype == NC_CHAR)	{
				mat = SetStr(prhs[7]);
			}
			else	{
				mat = prhs[7];
			}
			if (mat == NULL)	{
				mat = prhs[7];
			}
		}
		else	{
			if (datatype == NC_CHAR)	{
				mat = SetStr(prhs[6]);
			}
			else	{
				mat = prhs[6];
			}
			if (mat == NULL)	{
				mat = prhs[6];
			}
		}
		pr = mxGetPr(mat);
		
		start = Mat2Long(prhs[3]);
		count = Mat2Long(prhs[4]);
		stride = Mat2Long(prhs[5]);
		imap = NULL;
		
		for (i = 0; i < ndims; i++)	{
			if (count[i] == -1)	{
				status = ncdiminq(cdfid, dim[i], name, & count[i]);
				count[i] -= start[i];
			}
		}
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		len = 0;
		if (ndims > 0)	{
			len = 1;
			for (i = 0; i < ndims; i++)	{
				len *= count[i];
			}
		}
		
		autoscale = (nrhs > 8 && Scalar2Int(prhs[8]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr);
		status = ncvarputg(cdfid, varid, start, count, stride, imap, value);
		Free((VOIDPP) & value);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & stride);
		Free((VOIDPP) & count);
		Free((VOIDPP) & start);
		
		break;
		
	case VARGETG:
		
		start = Mat2Long(prhs[3]);
		count = Mat2Long(prhs[4]);
        intcount = Mat2Int(prhs[4]);
		stride = Mat2Long(prhs[5]);
		imap = NULL;
		
		autoscale = (nrhs > 7 && Scalar2Int(prhs[7]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int));
		
		status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts);
		
		datatype = RepairBadDataType(datatype);
		
		for (i = 0; i < ndims; i++)	{
			if (count[i] == -1)	{
				status = ncdiminq(cdfid, dim[i], name, & count[i]);
				count[i] -= start[i];
			}
		}
		
		Free((VOIDPP) & name);
		Free((VOIDPP) & dim);
		
		m = 0;
		n = 0;
		if (ndims > 0)	{
			m = count[0];
			n = count[0];
			for (i = 1; i < ndims; i++)	{
				n *= count[i];
				if (count[i] > 1)	{
					m = count[i];
				}
			}
			n /= m;
		}
		len = m * n;
		if (ndims < 2)	{
			m = 1;
			n = len;
		}
		
		for (i = 0; i < ndims; i++)	{
			intcount[i] = count[ndims-i-1];   /*	Reverse order.	*/
		}
		
		if (MEXCDF_4 || ndims < 2)	{
			mat = mxCreateFull(m, n, mxREAL);	/*	mxCreateDoubleMatrix	*/
		}
# if MEXCDF_5
		else	{
			mat = mxCreateNumericArray(ndims, intcount, mxDOUBLE_CLASS, mxREAL);
		}
# endif
		
		pr = mxGetPr(mat);
		
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = ncvargetg(cdfid, varid, start, count, stride, imap, value);
		status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr);
		Free((VOIDPP) & value);
		
		if (datatype == NC_CHAR)	{
			plhs[0] = SetStr(mat);
		}
		else	{
			plhs[0] = mat;
		}
		if (plhs[0] == NULL)	{
/*			prhs[0] = mat;		*/
			plhs[0] = mat;		/*	ZYDECO 24Jan2000	*/
		}
		
		plhs[1] = Int2Scalar(status);
		
		Free((VOIDPP) & stride);
		Free((VOIDPP) & intcount);
		Free((VOIDPP) & count);
		Free((VOIDPP) & start);
		
		break;

	case VARRENAME:
		
		name = Mat2Str(prhs[3]);
		
		status = ncvarrename(cdfid, varid, name);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & name);
		
		break;
		
	case VARCOPY:
	
		incdf = cdfid;
		
		invar = varid;
		
		outcdf = Scalar2Int(prhs[3]);
	
		outvar = -1;
/*		outvar = ncvarcopy(incdf, invar, outcdf);	*/
		
		plhs[0] = Int2Scalar(outvar);
		plhs[1] = Int2Scalar((outvar >= 0) ? 0 : outvar);
		
		break;
		
	case ATTPUT:
		
		datatype = (nc_type) Parameter(prhs[4]);
		
		datatype = RepairBadDataType(datatype);
		
		if (datatype == NC_CHAR)	{
			mat = SetNum(prhs[6]);
		}
		else	{
			mat = prhs[6];
		}
		if (mat == NULL)	{
			mat = prhs[6];
		}
		
		len = Scalar2Int(prhs[5]);
		if (len == -1)	{
			len = Count(mat);
		}
		
		pr = mxGetPr(mat);
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = Convert(opcode, datatype, len, value, (DOUBLE) 1.0, (DOUBLE) 0.0, pr);
		
		status = ncattput(cdfid, varid, attname, datatype, len, value);
		
		if (value != NULL)	{
			Free((VOIDPP) & value);
		}
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case ATTINQ:
		
		status = ncattinq(cdfid, varid, attname, & datatype, & len);
		
		datatype = RepairBadDataType(datatype);
		
		plhs[0] = Int2Scalar((int) datatype);
		plhs[1] = Int2Scalar(len);
		plhs[2] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case ATTGET:
		
		status = ncattinq(cdfid, varid, attname, & datatype, & len);
		
		datatype = RepairBadDataType(datatype);
		
		value = (VOIDP) mxCalloc(len, nctypelen(datatype));
		status = ncattget(cdfid, varid, attname, value);
		
		mat = mxCreateDoubleMatrix(1, len, mxREAL);
		
		pr = mxGetPr(mat);
		
		status = Convert(opcode, datatype, len, value, (DOUBLE) 1.0, (DOUBLE) 0.0, pr);
		
		if (value != NULL)	{
			Free((VOIDPP) & value);
		}
		
		if (datatype == NC_CHAR)	{
			plhs[0] = SetStr(mat);
		}
		else	{
			plhs[0] = mat;
		}
		if (plhs[0] == NULL)	{
/*			prhs[4] = mat;		*/
			plhs[0] = mat;		/*	ZYDECO 24Jan2000	*/
		}
		
		plhs[1] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case ATTCOPY:
	
		incdf = cdfid;
		
		invar = varid;
		
		outcdf = Scalar2Int(prhs[4]);
	
		if (mxIsNumeric(prhs[5]))	{
			outvar = Scalar2Int(prhs[2]);
		}
		else	{
			name = Mat2Str(prhs[5]);
			outvar = ncvarid(cdfid, name);
			Free((VOIDPP) & name);
		}
	
		status = ncattcopy(incdf, invar, attname, outcdf, outvar);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case ATTNAME:
		
		attnum = Scalar2Int(prhs[3]);
		attname = (char *) mxCalloc(MAX_NC_NAME, sizeof(char));
		
		status = ncattname(cdfid, varid, attnum, attname);
		
		plhs[0] = Str2Mat(attname);
		plhs[1] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case ATTRENAME:
	
		newname = Mat2Str(prhs[4]);
		
		status = ncattrename(cdfid, varid, attname, newname);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		Free((VOIDPP) & newname);
		
		break;
		
	case ATTDEL:
		
		status = ncattdel(cdfid, varid, attname);
		
		plhs[0] = Int2Scalar(status);
		
		Free((VOIDPP) & attname);
		
		break;
		
	case RECPUT:
		
		recnum = Scalar2Long(prhs[2]);
		pr = mxGetPr(prhs[3]);
		
		autoscale = (nrhs > 4 && Scalar2Int(prhs[4]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int));
		recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long));
		datap = (VOIDPP) mxCalloc(MAX_VAR_DIMS, sizeof(VOIDP));
		
		status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes);
		
		if (status == -1)	{
			plhs[0] = Int2Scalar(status);
			break;
		}
		
		length = 0;
		n = 0;
		for (i = 0; i < nrecvars; i++)	{
			ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL);
		
			datatype = RepairBadDataType(datatype);
			
			length += recsizes[i];
			n += (recsizes[i] / nctypelen(datatype));
		}
		
		if (Count(prhs[3]) < n)	{
			status = -1;
			plhs[0] = Int2Scalar(status);
			break;
		}
		
		if ((value = (VOIDP) mxCalloc((int) length, sizeof(char))) == NULL)	{
			status = -1;
			plhs[0] = Int2Scalar(status);
			break;
		}
		
		length = 0;
		p = value;
		for (i = 0; i < nrecvars; i++)	{
			datap[i] = p;
			p += recsizes[i];
		}
		
		p = (char *) value;
		pr = mxGetPr(prhs[3]);
		
		for (i = 0; i < nrecvars; i++)	{
			ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL);
		
			datatype = RepairBadDataType(datatype);
		
			length = recsizes[i] / nctypelen(datatype);
			if (autoscale)	{
				addoffset = Add_Offset(cdfid, recvarids[i]);
				scalefactor = Scale_Factor(cdfid, recvarids[i]);
				if (scalefactor == 0.0)	{
					scalefactor = 1.0;
				}
			}
			Convert(opcode, datatype, length, (VOIDP) p,  scalefactor, addoffset, pr);
			pr += length;
			p += recsizes[i];
		}
		
		status = ncrecput(cdfid, recnum, datap);
		
		plhs[0] = Int2Scalar(status);
		
		Free ((VOIDPP) & value);
		Free ((VOIDPP) & datap);
		Free ((VOIDPP) & recsizes);
		Free ((VOIDPP) & recvarids);
		
		break;
		
	case RECGET:
		
		recnum = Scalar2Long(prhs[2]);
		
		autoscale = (nrhs > 3 && Scalar2Int(prhs[3]) != 0);
		
		if (!autoscale)	{
			scalefactor = 1.0;
			addoffset = 0.0;
		}
		
		recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int));
		recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long));
		datap = (VOIDPP) mxCalloc(MAX_VAR_DIMS, sizeof(VOIDP));
		
		status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes);
		
		if (status == -1)	{
			Free ((VOIDPP) & recsizes);
			Free ((VOIDPP) & recvarids);
			plhs[1] = Int2Scalar(status);
			break;
		}
		
		if (nrecvars == 0)	{
			Free ((VOIDPP) & recsizes);
			Free ((VOIDPP) & recvarids);
			plhs[0] = mxCreateFull(0, 0, REAL);
			break;
		}
		
		length = 0;
		n = 0;
		for (i = 0; i < nrecvars; i++)	{
			ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL);
		
			datatype = RepairBadDataType(datatype);
			
			length += recsizes[i];
			n += (recsizes[i] / nctypelen(datatype));
		}
		
		if ((value = (VOIDP) mxCalloc((int) length, sizeof(char))) == NULL)	{
			status = -1;
			plhs[1] = Int2Scalar(status);
			break;
		}
		
		if (value == NULL)	{
			status = -1;
			plhs[1] = Int2Scalar(status);
			break;
		}
		
		length = 0;
		p = value;
		for (i = 0; i < nrecvars; i++)	{
			datap[i] = p;
			p += recsizes[i];
		}
		
		if ((status = ncrecget(cdfid, recnum, datap)) == -1)	{
			plhs[1] = Int2Scalar(status);
			break;
		}
		
		m = 1;
		
		plhs[0] = mxCreateFull(m, n, REAL);
		
		if (plhs[0] == NULL)	{
			status = -1;
			plhs[1] = Int2Scalar(status);
			break;
		}
		
		pr = mxGetPr(plhs[0]);
		p = (char *) value;
		
		for (i = 0; i < nrecvars; i++)	{
			status = ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL);
		
			datatype = RepairBadDataType(datatype);
			
			if (status == -1)	{
				plhs[1] = Int2Scalar(status);
				break;
			}
			length = recsizes[i] / nctypelen(datatype);
			if (autoscale)	{
				addoffset = Add_Offset(cdfid, recvarids[i]);
				scalefactor = Scale_Factor(cdfid, recvarids[i]);
				if (scalefactor == 0.0)	{
					scalefactor = 1.0;
				}
			}
			Convert(opcode, datatype, length, (VOIDP) p,  scalefactor, addoffset, pr);
			pr += length;
			p += recsizes[i];
		}
		
		plhs[1] = Int2Scalar(status);
		
		Free ((VOIDPP) & value);
		Free ((VOIDPP) & datap);
		Free ((VOIDPP) & recsizes);
		Free ((VOIDPP) & recvarids);
		
		break;

	case RECINQ:
		
		recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int));
		recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long));
		
		status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes);
		
		if (status != -1)	{
			for (i = 0; i < nrecvars; i++)	{
				ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL);
		
				datatype = RepairBadDataType(datatype);
			
				recsizes[i] /= nctypelen(datatype);
			}
			m = 1;
			n = nrecvars;
			plhs[0] = Int2Mat(recvarids, m, n);
			plhs[1] = Long2Mat(recsizes, m, n);
		}
		
		plhs[2] = Int2Scalar(status);
		
		Free ((VOIDPP) & recsizes);
		Free ((VOIDPP) & recvarids);
		
		break;
		
	case TYPELEN:
	
		datatype = (nc_type) Parameter(prhs[1]);
		
		len = nctypelen(datatype);
		
		plhs[0] = Int2Scalar(len);
		plhs[1] = Int2Scalar((len >= 0) ? 0 : 1);
		
		break;
		
	case SETFILL:
	
		fillmode = Scalar2Int(prhs[1]);
		
		status = ncsetfill(cdfid, fillmode);
		
		plhs[0] = Int2Scalar(status);
		plhs[1] = Int2Scalar(0);
		
		break;

	case SETOPTS:
		
		plhs[0] = Int2Scalar(ncopts);
		plhs[1] = Int2Scalar(0);
		ncopts = Scalar2Int(prhs[1]);
		
		break;
		
	case ERR:
	
		plhs[0] = Int2Scalar(ncerr);
		ncerr = 0;
		plhs[1] = Int2Scalar(0);
		
		break;
		
	case PARAMETER:
	
		if (nrhs > 1)	{
			plhs[0] = Int2Scalar(Parameter(prhs[1]));
			plhs[1] = Int2Scalar(0);
		}
		else	{
			i = 0;
			while (strcmp(parms[i].name, "NONE") != 0)	{
				mexPrintf("%12d %s\n", parms[i].code, parms[i].name);
				i++;
			}
			plhs[0] = Int2Scalar(0);
			plhs[1] = Int2Scalar(-1);
		}
		
		break;
		
	default:
	
		break;
	}
	
	return;
}
コード例 #16
0
ファイル: vc09c.c プロジェクト: gavin971/ncl
int main ()
{

/*
 *  If zoom = 0 then this script will animate the entire United States.
 *  If zoom = 1 then this script will animate just the Great Lakes region
 *  of the United States.
 *
 */

    int ZOOM=0;

    int i, j, k, u_id, v_id, p_id, t_id, *time, *timestep;
    int rlist, uf, vf, pf, tf, tim_id, lat_id, lon_id, tit_id;
    int appid, wid, vfield, sfield, sfield2, mapid, vcid, cnid;
    int title_id1, title_id2, txid1;
    long timlen, latlen, lonlen, titlen;
    long start [3] = {0,0,0}, count [3]={0,0,0};
    float MinLat, MaxLat, MinLon, MaxLon;
    float *U, *V, *P, *T, *lat, *lon;
    ng_size_t len_dims[2];
    char Uname [256], Vname [256], Pname [256], Tname [256];
    char *reftime;
    char title [256];
    const char *dir = _NGGetNCARGEnv ("data");
    extern void get_2d_array(float *, long, long, int, int, long);
    const char *wks_type = "ncgm";

/*
 *  Create an application object.  It will look for a resource file
 *  named vc09.res
 */

    NhlInitialize();
    rlist= NhlRLCreate (NhlSETRL);
  
    NhlRLClear (rlist);
    NhlRLSetString (rlist,NhlNappUsrDir,"./");
    NhlRLSetString (rlist,NhlNappDefaultParent,"True");
    NhlCreate (&appid, "vc09", NhlappClass, NhlDEFAULT_APP, rlist);

/*
 *  Create an ncgmWorkstation object.
 */

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
       NhlRLClear (rlist);
       NhlRLSetString (rlist, NhlNwkMetaName, "./vc09c.ncgm");
       NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
       NhlCreate (&wid, "vc09Work", NhlncgmWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 *  Create an X11 workstation.
 */
      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkPause, "True");
      NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
      NhlCreate (&wid, "vc09Work", NhlcairoWindowWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {

/*
 *  Create an older-style PostScript workstation.
 */
       NhlRLClear (rlist);
       NhlRLSetString (rlist, NhlNwkPSFileName, "vc09c.ps");
	   NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
       NhlCreate (&wid, "vc09Work", NhlpsWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 *  Create an older-style PDF workstation.
 */
       NhlRLClear (rlist);
       NhlRLSetString (rlist, NhlNwkPDFFileName, "vc09c.pdf");
	   NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
       NhlCreate (&wid, "vc09Work", NhlpdfWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }
    else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
             !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
/*
 *  Create a cairo PS/PDF Workstation object.
 */
       NhlRLClear (rlist);
       NhlRLSetString (rlist, NhlNwkFileName, "vc09c");
       NhlRLSetString (rlist, NhlNwkFormat,(char*)wks_type);
	   NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
       NhlCreate (&wid, "vc09Work", NhlcairoDocumentWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 *  Create a cairo PNG Workstation object.
 */
       NhlRLClear (rlist);
       NhlRLSetString (rlist, NhlNwkFileName, "vc09c");
       NhlRLSetString (rlist, NhlNwkFormat,(char*)wks_type);
	   NhlRLSetString (rlist, NhlNwkColorMap, "temp1");
       NhlCreate (&wid, "vc09Work", NhlcairoImageWorkstationClass,
                   NhlDEFAULT_APP, rlist);
    }

/*
 *  Open the netcdf files.
 */

    sprintf (Uname, "%s/cdf/Ustorm.cdf",dir);
    sprintf (Vname, "%s/cdf/Vstorm.cdf",dir);
    sprintf (Pname, "%s/cdf/Pstorm.cdf",dir);
    sprintf (Tname, "%s/cdf/Tstorm.cdf",dir);

    uf = ncopen (Uname, NC_NOWRITE);
    vf = ncopen (Vname, NC_NOWRITE);
    pf = ncopen (Pname, NC_NOWRITE);
    tf = ncopen (Tname, NC_NOWRITE);

    lat_id = ncdimid (uf,"lat");
    lon_id = ncdimid (uf,"lon");
    tim_id = ncdimid (vf,"timestep");
    tit_id = ncdimid (vf,"timelen");

    ncdiminq (uf,lat_id,(char *)0,&latlen);
    ncdiminq (uf,lon_id,(char *)0,&lonlen);
    ncdiminq (vf,tim_id,(char *)0,&timlen);
    ncdiminq (vf,tit_id,(char *)0,&titlen);

    len_dims [0] = latlen;
    len_dims [1] = lonlen;

    U = (float *)malloc(sizeof(float)*latlen*lonlen);
    V = (float *)malloc(sizeof(float)*latlen*lonlen);
    P = (float *)malloc(sizeof(float)*latlen*lonlen);
    T = (float *)malloc(sizeof(float)*latlen*lonlen);
    lat = (float *)malloc(sizeof(float)*latlen);
    lon = (float *)malloc(sizeof(float)*lonlen);

    u_id = ncvarid (uf,"u");
    v_id = ncvarid (vf,"v");
    p_id = ncvarid (pf,"p");
    t_id = ncvarid (tf,"t");
    lat_id = ncvarid (uf,"lat");
    lon_id = ncvarid (uf,"lon");
    tim_id = ncvarid (vf,"timestep");
    tit_id = ncvarid (vf,"reftime");

    start[2] = start[1] = start[0] =0;
    count[0] = latlen;
    count [1] = count [2] = 0;
    ncvarget(uf,lat_id,(long const *)start,(long const *)count,lat);
    count[0] = lonlen;
    ncvarget(uf, lon_id, (long const *)start, (long const *)count, lon);

    count [0] = timlen;
    timestep = (int *) malloc (sizeof (int) * timlen);
    ncvarget (vf, tim_id, (long const *)start, (long const *)count, timestep);

    count [0] = titlen;
    reftime = (char *) malloc (sizeof (char) * (titlen+1));
    ncvarget (vf, tit_id, (long const *)start, (long const *)count, reftime);

/*
 * Get U and V data values
 */
    get_2d_array (U, latlen, lonlen, uf, u_id, 0);
    get_2d_array (V, latlen, lonlen, vf, v_id, 0);

    get_2d_array (P, latlen, lonlen, pf, p_id, 0);
    get_2d_array (T, latlen, lonlen, tf, t_id, 0);

    for (i=0; i < latlen*lonlen; i++) {
        if (P[i] != -9999.0 ) P [i] /= 100.0;
        if (T[i] != -9999.0 ) T [i] = (T[i] - 273.15) * 9.0 / 5.0 + 32.0;
    }

    NhlRLClear (rlist);
    NhlRLSetMDFloatArray (rlist, NhlNvfUDataArray, U, 2, len_dims);
    NhlRLSetMDFloatArray (rlist, NhlNvfVDataArray, V, 2, len_dims);
    NhlRLSetFloat   (rlist, NhlNvfXCStartV, lon [0] );
    NhlRLSetFloat   (rlist, NhlNvfYCStartV, lat [0] );
    NhlRLSetFloat   (rlist, NhlNvfXCEndV, lon [lonlen-1]);
    NhlRLSetFloat   (rlist, NhlNvfYCEndV, lat [latlen-1]);
    NhlRLSetInteger (rlist, NhlNvfXCStride, 2);
    NhlRLSetInteger (rlist, NhlNvfYCStride, 2);
    NhlRLSetFloat   (rlist, NhlNvfMissingUValueV, -9999.0);
    NhlCreate (&vfield, "VectorField", NhlvectorFieldClass, appid, rlist);

    NhlRLClear (rlist);
    NhlRLSetMDFloatArray (rlist, NhlNsfDataArray, P, 2, len_dims);
    NhlRLSetFloat   (rlist, NhlNsfXCStartV, lon [0] );
    NhlRLSetFloat   (rlist, NhlNsfYCStartV, lat [0] );
    NhlRLSetFloat   (rlist, NhlNsfXCEndV, lon [lonlen - 1]);
    NhlRLSetFloat   (rlist, NhlNsfYCEndV, lat [latlen - 1]);
    NhlRLSetInteger (rlist, NhlNsfXCStride, 2);
    NhlRLSetInteger (rlist, NhlNsfYCStride, 2);
    NhlRLSetFloat   (rlist, NhlNsfMissingValueV, -9999.0);
    NhlCreate (&sfield, "ScalarField", NhlscalarFieldClass, appid, rlist);

    NhlRLClear (rlist);
    NhlRLSetMDFloatArray (rlist, NhlNsfDataArray, T, 2, len_dims);
    NhlRLSetFloat   (rlist, NhlNsfXCStartV, lon [0]);
    NhlRLSetFloat   (rlist, NhlNsfYCStartV, lat [0]);
    NhlRLSetFloat   (rlist, NhlNsfXCEndV, lon [lonlen - 1]);
    NhlRLSetFloat   (rlist, NhlNsfYCEndV, lat [latlen - 1]);
    NhlRLSetInteger (rlist, NhlNsfXCStride, 2);
    NhlRLSetInteger (rlist, NhlNsfYCStride, 2);
    NhlRLSetFloat   (rlist, NhlNsfMissingValueV, -9999.0);
    NhlCreate (&sfield2, "ScalarField2", NhlscalarFieldClass, appid, rlist);

/*
 * To zoom in on a certain area of the first plot adjust the following
 * four numbers.
 *
 * The following four numbers will cause the plots to display the
 * entire United States.
 */

    if (ZOOM == 0) {
       MinLat = 18.0;
       MaxLat = 65.0;
       MinLon = -128.0;
       MaxLon = -58.0;
    }
    else

/*
 * The Following four numbers will zoom in on the great lakes region of 
 * the United States.
 */

    if (ZOOM == 1) {
       MinLat = 40.0;
       MaxLat = 60.0;
       MinLon = -100.0;
       MaxLon = -58.0;
    }

/*
 *  Create a map object
 */

    NhlRLClear (rlist);
    NhlRLSetFloat  (rlist, NhlNvpXF, 0.03);
    NhlRLSetFloat  (rlist, NhlNvpYF, 0.85);
    NhlRLSetFloat  (rlist, NhlNvpWidthF, 0.8);
    NhlRLSetFloat  (rlist, NhlNvpHeightF, 0.8);
    NhlRLSetString (rlist, NhlNvpUseSegments, "true");
    NhlRLSetFloat  (rlist, NhlNmpMinLatF, MinLat);
    NhlRLSetFloat  (rlist, NhlNmpMaxLatF, MaxLat);
    NhlRLSetFloat  (rlist, NhlNmpMinLonF, MinLon);
    NhlRLSetFloat  (rlist, NhlNmpMaxLonF, MaxLon);
    NhlRLSetFloat  (rlist, NhlNmpCenterLonF, -100.0);
    NhlRLSetFloat  (rlist, NhlNmpCenterLatF, 40.0);
    NhlRLSetString (rlist, NhlNmpGridAndLimbDrawOrder, "predraw");
    NhlCreate (&mapid, "map", NhlmapPlotClass, wid, rlist);

    NhlRLClear (rlist);
    NhlRLSetString  (rlist, NhlNcnFillOn, "True");
    NhlRLSetString  (rlist, NhlNcnLinesOn, "False");
    NhlRLSetString  (rlist, NhlNcnFillDrawOrder, "predraw");
    NhlRLSetInteger (rlist, NhlNcnScalarFieldData, sfield);
    NhlRLSetString  (rlist, NhlNpmLabelBarDisplayMode, "always");
    NhlRLSetFloat   (rlist, NhlNpmLabelBarHeightF, 0.075);
    NhlRLSetFloat   (rlist, NhlNpmLabelBarWidthF, 0.6);
    NhlRLSetString  (rlist, NhlNlbOrientation, "horizontal");
    NhlRLSetString  (rlist, NhlNlbPerimOn, "False");
    NhlRLSetString  (rlist, NhlNpmLabelBarSide, "top");
    NhlCreate (&cnid,"contourplot", NhlcontourPlotClass, wid, rlist);

/*
 *  Create a VectorPlot object using the above data field.
 */

    NhlRLClear(rlist);
    NhlRLSetString  (rlist, NhlNvcUseScalarArray, "true");
    NhlRLSetInteger (rlist, NhlNvcVectorFieldData, vfield);
    NhlRLSetInteger (rlist, NhlNvcScalarFieldData, sfield2);
    NhlRLSetFloat   (rlist, NhlNvcMinFracLengthF, 0.33);
    NhlRLSetString  (rlist, NhlNvcMonoLineArrowColor, "false");
    NhlRLSetString  (rlist, NhlNvcVectorDrawOrder, "predraw");
    NhlRLSetString  (rlist, NhlNpmLabelBarDisplayMode, "always");
    NhlRLSetFloat   (rlist, NhlNpmLabelBarWidthF, 0.1);
    NhlRLSetString  (rlist, NhlNlbPerimOn, "False");
    NhlCreate (&vcid, "vectorplot", NhlvectorPlotClass, wid, rlist);

    sprintf (title, "%s + %d", reftime, timestep [0]);

    NhlRLClear (rlist);
    NhlRLSetFloat  (rlist, NhlNvpXF, 0.03);
    NhlRLSetFloat  (rlist, NhlNvpYF, 0.85);
    NhlRLSetFloat  (rlist, NhlNvpWidthF, 0.8);
    NhlRLSetFloat  (rlist, NhlNvpHeightF, 0.8);
    NhlRLSetString (rlist, NhlNtiMainFuncCode, "~");
    NhlRLSetInteger(rlist, NhlNtiMainFont, 25);
    NhlRLSetString (rlist, NhlNtiMainString, title);
    NhlCreate (&title_id1, "Titles", NhltitleClass, wid, rlist);

    NhlRLClear (rlist);
    NhlRLSetFloat  (rlist, NhlNvpXF, 0.03);
    NhlRLSetFloat  (rlist, NhlNvpYF, 0.9);
    NhlRLSetFloat  (rlist, NhlNvpWidthF, 0.8);
    NhlRLSetFloat  (rlist, NhlNvpHeightF, 0.8);
    NhlRLSetString (rlist, NhlNtiMainString, "January 1996 Snow Storm");
    NhlRLSetInteger (rlist, NhlNtiMainFont, 25 );
    NhlCreate (&title_id2, "Titles", NhltitleClass, wid, rlist);

    NhlRLClear (rlist);
    NhlRLSetFloat  (rlist, NhlNtxPosXF, 0.25);
    NhlRLSetFloat  (rlist, NhlNtxPosYF, 0.08);
    NhlRLSetFloat (rlist, NhlNtxFontHeightF, 0.015 );
    NhlRLSetString (rlist, NhlNtxString, "Contours represent pressure field.:C:Vectors represent wind direction:C:colored by temperature." );
    NhlCreate (&txid1, "text", NhltextItemClass, wid, rlist);

    NhlAddOverlay(mapid,cnid,-1);
    NhlAddOverlay(mapid,vcid,-1);

    time = (int *) malloc (sizeof (int) * timlen);
    for (i = 0; i < timlen; i++) time [i] = timestep [i];

    j= 2*(timlen - 1)/3;

    for (i = j; i < timlen; i++)
    {
      if ((time[i] != 102) && (time[i] != 222) && (time[i] != 216)) { 

        get_2d_array (U, latlen, lonlen, uf, u_id, i);
        get_2d_array (V, latlen, lonlen, vf, v_id, i);

        get_2d_array (P, latlen, lonlen, pf, p_id, i);
        get_2d_array (T, latlen, lonlen, tf, t_id, i);

        NhlRLClear (rlist);
        NhlRLSetMDFloatArray (rlist, NhlNvfUDataArray, U, 2, len_dims);
        NhlRLSetMDFloatArray (rlist, NhlNvfVDataArray, V, 2, len_dims);
        NhlSetValues (vfield,rlist);

        for (k=0; k < latlen*lonlen; k++) {
           if (P[k] != -9999.0 ) P [k] /= 100.0;
           if (T[k] != -9999.0 ) T [k] = (T[k] - 273.15) * 9.0 / 5.0 + 32.0;
        }

        NhlRLClear (rlist);
        NhlRLSetMDFloatArray (rlist, NhlNsfDataArray, P, 2, len_dims);
        NhlSetValues (sfield, rlist);

        NhlRLClear (rlist);
        NhlRLSetMDFloatArray (rlist, NhlNsfDataArray, T, 2, len_dims);
        NhlSetValues (sfield2,rlist);

        sprintf (title, "%s + %d", reftime, timestep [i]);

        NhlRLClear (rlist);
        NhlRLSetString (rlist,  NhlNtiMainString, title);
        NhlSetValues (title_id1, rlist);

        NhlDraw (mapid);
        NhlDraw (title_id1);
        NhlDraw (title_id2);
		NhlDraw (txid1);
        NhlFrame (wid);
      }  
    }

/*
 *  Close the Netcdf files.
 */

    ncclose (uf);
    ncclose (vf);
    ncclose (pf);
    ncclose (tf);

/*
 *  Destroy the workstation object and exit.
 */

    NhlDestroy (wid);
    NhlClose ();
    exit(0);
}