Beispiel #1
0
int main()
{
    int   wid, pid, rlist;
    float height, angle, dtr=0.017453292519943;
    float bkg_color[] = {1., 1., 1.};
    float x_coord, y_coord;
    char const *wks_type = "x11";
/*
 *  Initialize.
 */ 

    NhlOpen();
    rlist = NhlRLCreate(NhlSETRL);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./tx05c.ncgm");
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",NhlncgmWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 *  Create an X11 workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",
                  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,"./tx05c.ps");
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",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,"./tx05c.pdf");
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tx05c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",NhlcairoDocumentWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tx05c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetFloatArray(rlist,NhlNwkBackgroundColor,bkg_color,3);
        NhlCreate(&wid,"tx05Work",NhlcairoImageWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
/*
 *  Create a TextItem object.
 */
    NhlSetColor(wid,1, 0.0, 0.0, 1.0);
    NhlSetColor(wid,2, 0.4, 0.0, 0.4);

    NhlCreate(&pid,"TextItems",NhltextItemClass,wid,0);

/*
 *  Set text font and string.
 */

    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,NhlNtxFont ,22);
    NhlRLSetString(rlist,NhlNtxString, "NCAR");
    NhlSetValues(pid,rlist);

/*
 *  Draw string with various heights and at various angles.
 */

    angle = 0.;
    while (angle < 136.) {
      x_coord = 0.3 + 0.4*cos(dtr*angle);
      y_coord = 0.2 + 0.4*sin(dtr*angle);
      height  = 0.0005*(136.-angle);

      NhlRLClear(rlist);
      NhlRLSetFloat(rlist,NhlNtxAngleF, angle);
      NhlRLSetFloat(rlist,NhlNtxPosXF, x_coord);
      NhlRLSetFloat(rlist,NhlNtxPosYF, y_coord);
      NhlRLSetFloat(rlist,NhlNtxFontHeightF, height);
      NhlSetValues(pid,rlist);
      NhlDraw(pid);

      angle   = angle + MAX(210.*height,1.);
    }

/*
 *  Text strings at specific angles.
 */

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNtxAngleF, 180.0);
    NhlRLSetInteger(rlist,NhlNtxFont ,22);
    NhlRLSetInteger(rlist,NhlNtxFontColor ,1);
    NhlRLSetFloat(rlist,NhlNtxFontHeightF, 0.04);
    NhlRLSetFloat(rlist,NhlNtxPosXF,  0.25);
    NhlRLSetFloat(rlist,NhlNtxPosYF,  0.34);
    NhlRLSetString(rlist,NhlNtxString, "NCAR");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);

    NhlRLSetInteger(rlist,NhlNtxFontColor ,2);
    NhlRLSetFloat(rlist,NhlNtxFontHeightF, 0.03);
    NhlRLSetFloat(rlist,NhlNtxAngleF, 0.0);
    NhlRLSetFloat(rlist,NhlNtxPosYF,  0.4);
    NhlRLSetString(rlist,NhlNtxString, "180 degrees");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNtxAngleF, -45.0);
    NhlRLSetInteger(rlist,NhlNtxFont ,22);
    NhlRLSetInteger(rlist,NhlNtxFontColor ,1);
    NhlRLSetFloat(rlist,NhlNtxFontHeightF, 0.04);
    NhlRLSetFloat(rlist,NhlNtxPosXF,  0.7);
    NhlRLSetFloat(rlist,NhlNtxPosYF,  0.6);
    NhlRLSetString(rlist,NhlNtxString, "NCAR");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);

    NhlRLSetInteger(rlist,NhlNtxFontColor ,2);
    NhlRLSetFloat(rlist,NhlNtxAngleF, 0.0);
    NhlRLSetFloat(rlist,NhlNtxFontHeightF, 0.03);
    NhlRLSetFloat(rlist,NhlNtxPosXF,  0.73);
    NhlRLSetFloat(rlist,NhlNtxPosYF,  0.65);
    NhlRLSetInteger(rlist,NhlNtxJust ,NhlCENTERLEFT);
    NhlRLSetString(rlist,NhlNtxString, "-45 degrees");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);

/*
 *  Label the plot.
 */

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNtxAngleF, 0.0);
    NhlRLSetInteger(rlist,NhlNtxFont ,25);
    NhlRLSetInteger(rlist,NhlNtxJust ,NhlCENTERLEFT);
    NhlRLSetInteger(rlist,NhlNtxFontColor ,2);
    NhlRLSetFloat(rlist,NhlNtxFontHeightF, 0.05);
    NhlRLSetFloat(rlist,NhlNtxPosXF,  0.2);
    NhlRLSetFloat(rlist,NhlNtxPosYF,  0.84);
    NhlRLSetString(rlist,NhlNtxString, "Text heights &");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);

    NhlRLSetFloat(rlist,NhlNtxPosYF, 0.76);
    NhlRLSetString(rlist,NhlNtxString, "Text angles");
    NhlSetValues(pid,rlist);
    NhlDraw(pid);
    
    NhlFrame(wid);

    NhlDestroy(pid);
    NhlDestroy(wid);
    NhlClose();
    exit(0);
}
Beispiel #2
0
int main()
{
    int appid, wid, pid;
    int rlist;
    char const *wks_type = "x11";
/*
 * 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. In this example the resource file supplies the
 * plot title only.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlRLSetString(rlist,NhlNappDefaultParent,"True");
    NhlCreate(&appid,"tm02",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation object.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./tm02c.ncgm");
        NhlCreate(&wid,"tm02Work",NhlncgmWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 * Create an X11 workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlCreate(&wid,"tm02Work",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,"./tm02c.ps");
        NhlCreate(&wid,"tm02Work",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,"./tm02c.pdf");
        NhlCreate(&wid,"tm02Work",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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tm02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"tm02Work",NhlcairoDocumentWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tm02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"tm02Work",NhlcairoImageWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
/*
 * Specify the viewport extent of the object.
 */

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvpXF,.2);
    NhlRLSetFloat(rlist,NhlNvpYF,.8);
    NhlRLSetFloat(rlist,NhlNvpWidthF,.6);
    NhlRLSetFloat(rlist,NhlNvpHeightF,.6);

    NhlCreate(&pid,"TickMarks",NhltickMarkClass,wid,rlist);

    NhlDraw(pid);
    NhlFrame(wid);
    NhlDestroy(pid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #3
0
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);
}
Beispiel #4
0
int main ()
{
   char const *wks_type = "x11";
   int i=0, rlist, wks, appid, field1, field2, field3, xy1, xy2, xy3;
   int grlist, datadepid[1];
   int *dspec = datadepid;
   ng_size_t num_dspec;

/*
 *  Create variables to contain data.
 */

   FILE *x1_y3;
   float y [ncurve][npts], lon [npts], u [npts], v [npts], t [npts];
   float y1val [5] = {-90.0 , -80.0, -70.0, -60.0, -50.0};
   float y2val [6] = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0};
   float y3val [5] = {-20.0, -10.0, 0.0, 10.0, 20.0};
 
   char *y1lab [5] = {"-90.", "-80.", "-70.", "-60.", "-50."};
   char *y2lab [6] = {"10.", "20.", "30.", "40.", "50.", "60."};
   char *y3lab [5] = {"-20.", "-10.", "0.", "10.", "20."};
   char *file = "xy.asc";

/*
 *  Read ASCII file xy.asc
 */
   x1_y3 = fopen (file,"r");
/*
 *   xy.asc has 4 vars of length 129 longitudes, lon, u, v, t
 *
 *     The data is taken at 43N latitude.  Longitude is an index
 *     1-129 standing for 0 deg - 360 deg in steps of 360/128?
 *     u and v are in m/s, and t is in deg K.
 */

   while (!feof(x1_y3)) {
      fscanf (x1_y3, "%f %f %f %f", &lon[i], &u[i], &v[i], &t[i]);
      i++;
   }

   for (i=0; i < npts; i++)
   {
      lon [i] = (lon[i]- 1.0) * 360.0/128.0;
      t [i] =  (t[i] - 273.15) * 9 / 5 + 32.0 ;
      y [0][i] = u[i];
      y [1][i] = v[i];
      y [2][i] = (t[i] - 273.15) * 9.0 / 5.0 + 32.0;
   }

   NhlInitialize ();
   rlist = NhlRLCreate (NhlSETRL);

/*
 *  Create Application object.  The Application object name is used to
 *  determine the name of the resource file, which is "xy17.res" in this
 *  case. 
 */
 
   NhlRLClear (rlist);
   NhlRLSetInteger (rlist, NhlNappDefaultParent, True);
   NhlRLSetString (rlist, NhlNappUsrDir, "./");
   NhlCreate (&appid, "xy17", NhlappClass, 0, rlist);

/*
 *  If NCGM=1, then open NCGM workstation. 
 */
   if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkMetaName, "xy17c.ncgm");
      NhlCreate (&wks, "xy17Work", NhlncgmWorkstationClass, 0, rlist);
   }
   else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 *  Create an X workstation. 
 */
      NhlRLClear (rlist);
      NhlRLSetInteger (rlist, NhlNwkPause, True);
      NhlCreate (&wks, "xy17Work", NhlcairoWindowWorkstationClass, 0, rlist);
   }
   else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 *  Open PS workstation. 
 */

      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkPSFileName, "xy17c.ps");
      NhlCreate (&wks, "xy17Work", NhlpsWorkstationClass, 0, rlist);
   }
   else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 *  Open PDF workstation. 
 */
      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkPDFFileName, "xy17c.pdf");
      NhlCreate (&wks, "xy17Work", NhlpdfWorkstationClass, 0, rlist);
   }
   else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
            !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
/*
 *  Open cairo PS/PDF workstation. 
 */
      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkFileName, "xy17c");
      NhlRLSetString (rlist, NhlNwkFormat, (char*)wks_type);
      NhlCreate (&wks, "xy17Work", NhlcairoDocumentWorkstationClass, 0, rlist);
   }
   else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 *  Open cairo PNG workstation. 
 */
      NhlRLClear (rlist);
      NhlRLSetString (rlist, NhlNwkFileName, "xy17c");
      NhlRLSetString (rlist, NhlNwkFormat, (char*)wks_type);
      NhlCreate (&wks, "xy17Work", NhlcairoImageWorkstationClass, 0, rlist);
   }

/*
 *  Create a coordarrays data object and configure its extents missing
 *  values and at the same time convert it from Degrees K to Degrees F  
 */

   NhlRLClear (rlist);
   NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129);
   NhlRLSetFloatArray (rlist, NhlNcaYArray, t, 129);
   NhlCreate (&field1, "field1", NhlcoordArraysClass, appid, rlist);

/*
 *  Create a coordarrays data object and configure its extents missing
 *  values and at the same time convert it from Degrees K to Degrees F
 */

   NhlRLClear (rlist);
   NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129);
   NhlRLSetFloatArray (rlist, NhlNcaYArray, u, 129);
   NhlCreate (&field2, "field2", NhlcoordArraysClass, appid, rlist);

/*
 *  Create a coordarrays data object and configure its extents missing
 *  values and at the same time convert it from Degrees K to Degrees F
 */

   NhlRLClear (rlist);
   NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129);
   NhlRLSetFloatArray (rlist, NhlNcaYArray, v, 129);
   NhlCreate (&field3, "field3", NhlcoordArraysClass, appid, rlist);

/*
 *  Create XyPlot object for curve 1 and assign data to it
 */

   NhlRLClear (rlist);
   NhlRLSetFloat   (rlist, NhlNvpXF, 0.20);
   NhlRLSetFloat   (rlist, NhlNvpYF, 0.80);
   NhlRLSetFloat   (rlist, NhlNvpWidthF, 0.6);
   NhlRLSetFloat   (rlist, NhlNvpHeightF, 0.2);
   NhlRLSetInteger (rlist, NhlNxyCoordData, field1);
   NhlRLSetString  (rlist, NhlNtrYReverse, "False");
   NhlRLSetFloat   (rlist, NhlNtrYMaxF,  -50.0);
   NhlRLSetFloat   (rlist, NhlNtrYMinF,  -90.0);
   NhlRLSetFloat   (rlist, NhlNtrXMaxF,  360.0);
   NhlRLSetFloat   (rlist, NhlNtrXMinF,   0.0);
   NhlRLSetString  (rlist, NhlNtmYROn, "False");
   NhlRLSetString  (rlist, NhlNtmYUseLeft, "False");
   NhlRLSetString  (rlist, NhlNtmXMajorGrid, "True");
   NhlRLSetString  (rlist, NhlNtmXBLabelsOn, "False");
   NhlRLSetString  (rlist, NhlNtmYLLabelsOn, "True");
   NhlRLSetFloat   (rlist, NhlNtmYLMajorLengthF, 0.01);
   NhlRLSetFloat   (rlist, NhlNtmYLMajorOutwardLengthF, 0.0);
   NhlRLSetString  (rlist, NhlNtmYLMode, "Explicit");
   NhlRLSetFloatArray  (rlist, NhlNtmYLValues, y1val, 5);
   NhlRLSetStringArray (rlist, NhlNtmYLLabels, y1lab, 5);
   NhlRLSetString  (rlist, NhlNtmYLLabelsOn, "True");
   NhlRLSetString (rlist, NhlNtmYLLabelFontColor,"red");
   NhlRLSetString  (rlist, NhlNtiMainString, "Temperature, U, V Stacked Plots");
   NhlRLSetString  (rlist, NhlNtiYAxisString, "Temp (Deg C)");
   NhlRLSetFloat   (rlist, NhlNtiXAxisFontHeightF, 0.02);
   NhlRLSetFloat   (rlist, NhlNtiYAxisFontHeightF, 0.02);
   NhlRLSetString  (rlist, NhlNtiXAxisFont, "helvetica-bold");
   NhlRLSetString  (rlist, NhlNtiYAxisFont, "helvetica-bold");
   NhlRLSetString (rlist, NhlNtiYAxisFontColor,"red");
   NhlRLSetString  (rlist, NhlNtmYRMinorOn, "False");
   NhlRLSetString  (rlist, NhlNtmYLMinorOn, "False");
   NhlCreate(&xy1, "xy1", NhlxyPlotClass, wks, rlist);

/*
 *  Create XyPlot object for curve 2 and assign data to it
 */

   NhlRLClear (rlist);
   NhlRLSetFloat   (rlist, NhlNvpXF, 0.20);
   NhlRLSetFloat   (rlist, NhlNvpYF, 0.60);
   NhlRLSetFloat   (rlist, NhlNvpWidthF, 0.6);
   NhlRLSetFloat   (rlist, NhlNvpHeightF, 0.2);
   NhlRLSetInteger (rlist, NhlNxyCoordData, field2);
   NhlRLSetString  (rlist, NhlNtrYReverse, "False");
   NhlRLSetFloat   (rlist, NhlNtrYMaxF,   60.0);
   NhlRLSetFloat   (rlist, NhlNtrYMinF,   10.0);
   NhlRLSetFloat   (rlist, NhlNtrXMaxF,  360.0);
   NhlRLSetFloat   (rlist, NhlNtrXMinF,   0.0);
   NhlRLSetString  (rlist, NhlNtmYROn, "True");
   NhlRLSetString  (rlist, NhlNtmYLOn, "False");
   NhlRLSetString  (rlist, NhlNtmYUseLeft, "False");
   NhlRLSetString  (rlist, NhlNtmXMajorGrid, "True");
   NhlRLSetString  (rlist, NhlNtmYLLabelsOn, "False");
   NhlRLSetString  (rlist, NhlNtmYRLabelsOn, "True");
   NhlRLSetString  (rlist, NhlNtmYRMode, "Explicit");
   NhlRLSetFloatArray  (rlist, NhlNtmYRValues, y2val, 6);
   NhlRLSetStringArray (rlist, NhlNtmYRLabels, y2lab, 6);
   NhlRLSetString  (rlist, NhlNtmXBLabelsOn, "False");
   NhlRLSetString (rlist, NhlNtmYRLabelFontColor,"green");
   NhlRLSetString  (rlist, NhlNtiYAxisString, "U (m/s)");
   NhlRLSetFloat   (rlist, NhlNtiXAxisFontHeightF, 0.02);
   NhlRLSetFloat   (rlist, NhlNtiYAxisFontHeightF, 0.02);
   NhlRLSetString  (rlist, NhlNtiXAxisFont, "helvetica-bold");
   NhlRLSetString  (rlist, NhlNtiYAxisFont, "helvetica-bold");
   NhlRLSetString (rlist, NhlNtiYAxisFontColor,"green");
   NhlRLSetString  (rlist, NhlNtmYRMinorOn, "False");
   NhlRLSetString  (rlist, NhlNtmYLMinorOn, "False");
   NhlCreate(&xy2, "xy2", NhlxyPlotClass, wks, rlist);

/*
 *  Create XyPlot object for curve 3 and assign data to it
 *
 *  Increase the veiwport so the right scale will be about .15 NDC
 *  right of the other grids.  Plot only the right vertical axis.
 *  .5NDC = 360 deg lon, thus .65NDC = 360+108 deg lon.
 */

   NhlRLClear (rlist);
   NhlRLSetFloat   (rlist, NhlNvpXF, 0.20);
   NhlRLSetFloat   (rlist, NhlNvpYF, 0.40);
   NhlRLSetFloat   (rlist, NhlNvpWidthF, 0.6);
   NhlRLSetFloat   (rlist, NhlNvpHeightF, 0.2);
   NhlRLSetInteger (rlist, NhlNxyCoordData, field3);
   NhlRLSetString  (rlist, NhlNtrYReverse, "False");
   NhlRLSetFloat   (rlist, NhlNtrYMaxF,   20.0);
   NhlRLSetFloat   (rlist, NhlNtrYMinF,  -20.0);
   NhlRLSetFloat   (rlist, NhlNtrXMaxF,  360.0);
   NhlRLSetFloat   (rlist, NhlNtrXMinF,   0.0);
   NhlRLSetString  (rlist, NhlNtmYROn, "False");
   NhlRLSetString  (rlist, NhlNtmYUseLeft, "False");
   NhlRLSetString  (rlist, NhlNtmYLLabelsOn, "True");
   NhlRLSetString  (rlist, NhlNtmXBLabelsOn, "True");
   NhlRLSetString  (rlist, NhlNtmXMajorGrid, "True");
   NhlRLSetFloat   (rlist, NhlNtmYLMajorLengthF, 0.01);
   NhlRLSetFloat   (rlist, NhlNtmYLMajorOutwardLengthF, 0.0);
   NhlRLSetString  (rlist, NhlNtmYLMode, "Explicit");
   NhlRLSetString  (rlist, NhlNtmYLLabelsOn, "True");
   NhlRLSetString (rlist, NhlNtmYLLabelFontColor,"blue");
   NhlRLSetString  (rlist, NhlNtiYAxisString, "V (m/s)");
   NhlRLSetString  (rlist, NhlNtiXAxisString, "Longitude (Degs)");
   NhlRLSetFloat   (rlist, NhlNtiXAxisFontHeightF, 0.02);
   NhlRLSetFloat   (rlist, NhlNtiYAxisFontHeightF, 0.02);
   NhlRLSetString  (rlist, NhlNtiXAxisFont, "helvetica-bold");
   NhlRLSetString  (rlist, NhlNtiYAxisFont, "helvetica-bold");
   NhlRLSetString (rlist, NhlNtiYAxisFontColor,"blue");
   NhlRLSetString  (rlist, NhlNtmYRMinorOn, "False");
   NhlRLSetString  (rlist, NhlNtmYLMinorOn, "False");
   NhlRLSetFloatArray  (rlist, NhlNtmYLValues, y3val, 5);
   NhlRLSetStringArray (rlist, NhlNtmYLLabels, y3lab, 5);
   NhlCreate(&xy3, "xy3", NhlxyPlotClass, wks, rlist);

   grlist = NhlRLCreate (NhlGETRL);
   NhlRLClear (grlist);
   NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec);
   NhlGetValues(xy1, grlist);

   NhlRLClear (rlist);
   NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True);
   NhlRLSetString (rlist, NhlNxyLineColor,"red");
   NhlSetValues (dspec[0], rlist);

   NhlRLClear (grlist);
   NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec);
   NhlGetValues(xy2, grlist);

   NhlRLClear (rlist);
   NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True);
   NhlRLSetString (rlist, NhlNxyLineColor,"green");
   NhlSetValues (dspec[0], rlist);

   NhlRLClear (grlist);
   NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec);
   NhlGetValues(xy3, grlist);

   NhlRLClear (rlist);
   NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True);
   NhlRLSetString (rlist, NhlNxyLineColor,"blue");
   NhlSetValues (dspec[0], rlist);

   NhlDraw(xy1);
   NhlDraw(xy2);
   NhlDraw(xy3);
   NhlFrame(wks);

   NhlDestroy (wks);
   NhlClose();
   exit(0);
}
Beispiel #5
0
int main()
{
    int appid,wid,cnid,dataid,llid;
    int rlist, grlist;
    ng_size_t len_dims[2];
    float xvp,yvp,heightvp,widthvp;
    char const *wks_type = "x11";
    /*
     * Initialize the high level utility library
     */

    NhlInitialize();
    /*
     * Create an application context. Set the app dir to the current directory
     * so the application looks for the resource file the directory it executes
     * from.
     */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"cn03",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
        /*
         * Create a meta file workstation.
         */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./cn03c.ncgm");
        NhlCreate(&wid,"cn03Work",
                  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,"cn03Work",
                  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,"./cn03c.ps");
        NhlCreate(&wid,"cn03Work",
                  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,"./cn03c.pdf");
        NhlCreate(&wid,"cn03Work",
                  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.
         */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./cn03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"cn03Work",
                  NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
        /*
         * Create a cairo PNG workstation.
         */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./cn03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"cn03Work",
                  NhlcairoImageWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    /*
     * Create a scalar field data object with a linear X dimension representing
     * latitude and an irregular Y dimension representing geopotential height.
     * Define the start and end points of the data, based on the dataset.
     */

    NhlRLClear(rlist);
    len_dims[0] = N, len_dims[1] = M;
    NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,T,2,len_dims);
    NhlRLSetFloatArray(rlist,NhlNsfYArray,level,NhlNumber(level));
    NhlRLSetFloat(rlist,NhlNsfXCStartV,-90.0);
    NhlRLSetFloat(rlist,NhlNsfXCEndV,90.0);
    NhlRLSetFloat(rlist,NhlNsfYCStartV,1000.0);
    NhlRLSetFloat(rlist,NhlNsfYCEndV,100.0);
    NhlCreate(&dataid,"mydata",NhlscalarFieldClass,NhlDEFAULT_APP,
              rlist);
    /*
     * Create a ContourPlot object. Since ContourPlot contains a TickMark object by
     * default, the non-default TickMark resources can be set in the ContourPlot
     * object.
     */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
                   "Profile @ 105~S~o~N~W - Frame 1");
    NhlRLSetInteger(rlist,NhlNcnScalarFieldData,dataid);
    NhlRLSetFloat(rlist,NhlNvpXF,0.125);
    NhlRLSetFloat(rlist,NhlNvpYF,0.85);
    NhlRLSetFloat(rlist,NhlNvpWidthF,0.6);
    NhlRLSetFloat(rlist,NhlNvpHeightF,0.6);
    NhlRLSetFloat(rlist,NhlNcnLevelSpacingF,5.0);
    NhlRLSetInteger(rlist,NhlNtmXBMode,NhlEXPLICIT);
    NhlRLSetInteger(rlist,NhlNtmXBMinorOn,False);
    NhlRLSetFloatArray(rlist,
                       NhlNtmXBValues,labellocs,NhlNumber(labellocs));
    NhlRLSetStringArray(rlist,
                        NhlNtmXBLabels,labels,NhlNumber(labels));
    NhlCreate(&cnid,"ContourPlot1",NhlcontourPlotClass,wid,rlist);

    NhlDraw(cnid);
    NhlFrame(wid);

    /*
     * Color and add dash patterns to the lines, then display a legend
     * listing the line types. The position of the Legend is controlled by
     * resources set in the resource file. Thicken lines.
     * Note that the Legend and LabelBar are provided to the ContourPlot object
     * by its PlotManager (created by default when the ContourPlot object
     * is initialized). Therefore the resources to control them have the
     * prefix 'pm' rather than 'cn'.
     */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
                   "Profile @ 105~S~o~N~W - Frame 2");
    NhlRLSetInteger(rlist,NhlNcnMonoLineColor,False);
    NhlRLSetInteger(rlist,NhlNcnMonoLineDashPattern,False);
    NhlRLSetString(rlist,NhlNpmLegendDisplayMode,"always");
    NhlSetValues(cnid,rlist);

    NhlDraw(cnid);
    NhlFrame(wid);
    /*
     * Turn lines off, and use solid color fill instead.
     * Remove the Legend and display a LabelBar.
     * Turn off line and high/low labels.
     */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
                   "Profile @ 105~S~o~N~W - Frame 3");
    NhlRLSetString(rlist,NhlNcnLinesOn,"false");
    NhlRLSetString(rlist,NhlNcnFillOn,"true");
    NhlRLSetString(rlist,NhlNpmLegendDisplayMode,"never");
    NhlRLSetString(rlist,NhlNpmLabelBarDisplayMode,"always");
    NhlRLSetString(rlist,NhlNcnLineLabelsOn,"false");
    NhlRLSetString(rlist,NhlNcnHighLabelsOn,"false");
    NhlRLSetString(rlist,NhlNcnLowLabelsOn,"false");
    NhlSetValues(cnid,rlist);

    NhlDraw(cnid);
    NhlFrame(wid);

    /*
     * Now show the plot with the Y-Axis linearized, by overlaying the
     * plot on a LogLinPlot object. Retrieve the current view coordinates
     * of the ContourPlot object and pass them on to the LogLinPlot object.
     * Note the LogLinPlot needs to be told the data boundaries.
     */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
                   "Profile @ 105~S~o~N~W - Frame 4");
    NhlSetValues(cnid,rlist);

    grlist = NhlRLCreate(NhlGETRL);
    NhlRLClear(grlist);
    NhlRLGetFloat(grlist,NhlNvpXF,&xvp);
    NhlRLGetFloat(grlist,NhlNvpYF,&yvp);
    NhlRLGetFloat(grlist,NhlNvpWidthF,&widthvp);
    NhlRLGetFloat(grlist,NhlNvpHeightF,&heightvp);
    NhlGetValues(cnid,grlist);

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvpXF,xvp);
    NhlRLSetFloat(rlist,NhlNvpYF,yvp);
    NhlRLSetFloat(rlist,NhlNvpWidthF,widthvp);
    NhlRLSetFloat(rlist,NhlNvpHeightF,heightvp);
    NhlRLSetFloat(rlist,NhlNtrXMinF,-90.0);
    NhlRLSetFloat(rlist,NhlNtrXMaxF,90.0);
    NhlRLSetFloat(rlist,NhlNtrYMaxF,1000.0);
    NhlRLSetFloat(rlist,NhlNtrYMinF,100.0);
    NhlRLSetString(rlist,NhlNtrYReverse,"True");
    NhlCreate(&llid,"LogLin1",NhllogLinPlotClass,wid,rlist);

    /*
     * The LogLinPlot becomes the Base Plot, since it controls the coordinate
     * system that we are mapping to. Overlay the ContourPlot object on the base,
     * then plot the LogLinPlot object. Note that you cannot draw the ContourPlot
     * object directly, once it becomes an overlay Plot.
     */
    NhlAddOverlay(llid,cnid,-1);
    NhlDraw(llid);
    NhlFrame(wid);

    NhlDestroy(llid);
    NhlDestroy(dataid);
    NhlDestroy(cnid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    char const *wks_type = "x11";
    int appid,wid,vcid,vfid;
    int rlist,grlist;
    ng_size_t len_dims[3];
    float reflen, ref;
    float x[a][b][c];
    FILE * fd;
    int i,j,k;
/*
 * Generate vector data array
 */
    char  filename[256];   
    const char *dir = _NGGetNCARGEnv("data");
    sprintf( filename, "%s/asc/uvdata0.asc", dir );

    fd = fopen(filename,"r");
       
    for (k = 0; k < a; k++) {
        for (j = 0; j < b; j++) {
            for (i = 0; i < c; i++) {       
                fscanf(fd,"%f", &x[k][j][i]);
            }
        }
    }

/*
 * 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);
    grlist = NhlRLCreate(NhlGETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"vc03",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./vc03c.ncgm");
        NhlCreate(&wid,"vc03Work",
                  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,"vc03Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }

    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"vc03c.ps");
        NhlCreate(&wid,"vc03Work",NhlpsWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"vc03c.pdf");
        NhlCreate(&wid,"vc03Work",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,"vc03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"vc03Work",NhlcairoDocumentWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"vc03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"vc03Work",NhlcairoImageWorkstationClass,appid,rlist);
    }
/*
 * 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)
 */

    len_dims[0] = a;
    len_dims[1] = b;
    len_dims[2] = c;
    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNvfDataArray,&x[0][0][0],3,len_dims);
    NhlRLSetFloat(rlist,NhlNvfXCStartV, -180.0);
    NhlRLSetFloat(rlist,NhlNvfXCEndV, 0.0);
    NhlRLSetFloat(rlist,NhlNvfYCStartV, 0.0);
    NhlRLSetFloat(rlist,NhlNvfYCEndV, 90.0);
    NhlRLSetFloat(rlist,NhlNvfYCStartSubsetV, 20.0);
    NhlRLSetFloat(rlist,NhlNvfYCEndSubsetV, 80.0);
   
    NhlCreate(&vfid,"vectorfield",NhlvectorFieldClass,appid,rlist);

/*
 * Create a VectorPlot object, supplying the VectorField object as data
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString, "Filled Arrow VectorPlot");
    NhlRLSetFloat(rlist,NhlNvcRefMagnitudeF, 20.0);
    NhlRLSetString(rlist,NhlNvcFillArrowsOn, "True");
    NhlRLSetFloat(rlist,NhlNvcMinFracLengthF, 0.2);

    NhlRLSetInteger(rlist,NhlNvcVectorFieldData,vfid);

    NhlCreate(&vcid,"vectorplot",NhlvectorPlotClass,wid,rlist);


    NhlRLClear(grlist);
    NhlRLGetFloat(grlist,NhlNvcRefLengthF,&reflen);
    NhlGetValues(vcid,grlist);

    ref= 1.5 * reflen;    
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvcRefLengthF,ref);
    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
           "Variation #1:: Constant Width");
    NhlRLSetFloat(rlist,NhlNvcFillArrowWidthF, 0.15);
    NhlRLSetFloat(rlist,NhlNvcFillArrowMinFracWidthF, 1.0);
    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);


    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
           "Variation #2");
    NhlRLSetFloat(rlist,NhlNvcFillArrowMinFracWidthF,0.25);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadMinFracXF,0.0);
    NhlRLSetFloat(rlist,NhlNvcFillArrowWidthF,0.2);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadXF,0.8);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadInteriorXF,0.7);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadYF,0.2);
    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);


    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Variation #3");
    ref = 1.2 * reflen;    
    NhlRLSetFloat(rlist,NhlNvcRefLengthF,ref);
    NhlRLSetFloat(rlist,NhlNvcFillArrowWidthF,0.3);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadXF,0.4);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadInteriorXF,0.35);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadYF,0.3);

    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Variation #4");
    ref = 1.2 * reflen;    
    NhlRLSetFloat(rlist,NhlNvcRefLengthF,ref);
    NhlRLSetFloat(rlist,NhlNvcFillArrowWidthF,0.2);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadXF,1.0);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadInteriorXF,1.0);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadYF,0.2);

    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Variation #5");
    ref = 0.8 * reflen;    
    NhlRLSetFloat(rlist,NhlNvcRefLengthF,ref);
    NhlRLSetFloat(rlist,NhlNvcFillArrowWidthF,0.2);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadXF,1.5);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadInteriorXF,1.0);
    NhlRLSetFloat(rlist,NhlNvcFillArrowHeadYF,0.5);

    NhlSetValues(vcid,rlist);

    NhlDraw(vcid);
    NhlFrame(wid);
/*
 * Destroy the objects created, close the HLU library and exit.
 */
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #7
0
int main(int argc, char *argv[])

{
    char const *wks_type = "x11";
    int rlist,grlist;
    int appid,wid,canvas;
    int i;
    float plx[5] = { 0.1,0.9,0.5,0.1 };
    float ply[5] = { 0.1,0.1,0.9,0.1 };
    float pmx[4] = { 0.05,0.95,0.5,0.5 };
    float pmy[4] = { 0.05,0.05,1.05,0.5 };
    float pgx[4] = { 0.2,0.8,0.5,0.2 };
    float pgy[4] = { 0.25,0.25,0.85,0.25 };
    float dpgx[7] = { 5.0,110.0,110.0,0.0,110.0,5.0,5.0 };
    float dpgy[7] = { 10.,10.,20.0,20.,110.,110,10.0 };

/*
 * 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);
    grlist = NhlRLCreate(NhlGETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"pr04",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./pr04c.ncgm");
        NhlCreate(&wid,"pr04Work",
                  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,"pr04Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }

    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"pr04c.ps");
        NhlCreate(&wid,"pr04Work",NhlpsWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"pr04c.pdf");
        NhlCreate(&wid,"pr04Work",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,"pr04c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"pr04Work",NhlcairoDocumentWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"pr04c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"pr04Work",NhlcairoImageWorkstationClass,appid,rlist);
    }
/*
 * Create an IrregularPlot that covers the entire NDC space 
 * to use as a drawing canvas
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvpXF,0.1);
    NhlRLSetFloat(rlist,NhlNvpYF,0.9);
    NhlRLSetFloat(rlist,NhlNvpWidthF,0.8);
    NhlRLSetFloat(rlist,NhlNvpHeightF,0.8);
    NhlRLSetString(rlist,NhlNpmTitleDisplayMode,"always");
    NhlRLSetString(rlist,NhlNtiMainString,
		   "Irregular Plot with NDC Primitives");
    NhlCreate(&canvas,"canvas",NhlirregularPlotClass,wid,rlist);

    NhlDraw(canvas);
    NhlNDCPolyline(canvas,0,plx,ply,4);
    NhlNDCPolygon(canvas,0,pgx,pgy,4);
    NhlNDCPolymarker(canvas,0,pmx,pmy,4);
    NhlFrame(wid);

    for (i=0; i<4; i++) {
	    plx[i] = plx[i] * 100.0 + 50.;
	    ply[i] = ply[i] * 100.0 + 50.;
	    pgx[i] = pgx[i] * 100.0 + 50.;
	    pgy[i] = pgy[i] * 100.0 + 50.;
	    pmx[i] = pmx[i] * 100.0 + 50.;
	    pmy[i] = pmy[i] * 100.0 + 50.;
    }

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
		   "Clipped Data Space Primitives");
    NhlSetValues(canvas,rlist);

    NhlDraw(canvas);
    NhlDataPolyline(canvas,0,plx,ply,4);
    NhlDataPolymarker(canvas,0,pmx,pmy,4);
    NhlDataPolygon(canvas,0,pgx,pgy,4);
    NhlFrame(wid);

    for (i=0; i<4; i++) {
	    plx[i] = plx[i] - 40.;
	    ply[i] = ply[i] - 40.;
	    pgx[i] = pgx[i] - 40.;
	    pgy[i] = pgy[i] - 40.;
	    pmx[i] = pmx[i] - 40.;
	    pmy[i] = pmy[i] - 40.;
    }

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
		   "Data Space Primitives Repositioned");
    NhlSetValues(canvas,rlist);

    NhlDraw(canvas);
    NhlDataPolyline(canvas,0,plx,ply,4);
    NhlDataPolymarker(canvas,0,pmx,pmy,4);
    NhlDataPolygon(canvas,0,pgx,pgy,4);
    NhlFrame(wid);


    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
		   "A Diamond in Data Space");
    NhlSetValues(canvas,rlist);
    NhlDraw(canvas);
    plx[0] = 10.0;
    plx[1] = 50.0;
    plx[2] = 90.0;
    plx[3] = 50.0;
    plx[4] = 10.0;
    ply[0] = 50.0;
    ply[1] = 10.0;
    ply[2] = 50.0;
    ply[3] = 90.0;
    ply[4] = 50.0;
    NhlDataPolygon(canvas,0,plx,ply,4);
    plx[0] = 5.0;
    plx[2] = 95.0;
    plx[4] = 5.0;
    ply[1] = 5.0;
    ply[3] = 95.0;
    NhlDataPolyline(canvas,0,plx,ply,5);
    NhlFrame(wid);

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
		   "A Self-Intersecting Data Polygon");
    NhlSetValues(canvas,rlist);
    NhlDraw(canvas);
    NhlDataPolygon(canvas,0,dpgx,dpgy,7);
    NhlFrame(wid);

    NhlClose();
    exit(0);
}
Beispiel #8
0
int main(int argc, char *argv[])
{
    int appid,wid,mapid;
    int rlist;
    char const *wks_type = "x11";
/*
 * 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. The resource file sets most of the Contour
 * resources that remain fixed throughout the life of the Contour
 * object.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"mp01",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./mp01c.ncgm");
        NhlCreate(&wid,"mp01Work",
                  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,"mp01Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"./mp01c.ps");
        NhlCreate(&wid,"mp01Work",
                  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,"./mp01c.pdf");
        NhlCreate(&wid,"mp01Work",
                  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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./mp01c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"mp01Work",
                  NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./mp01c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"mp01Work",
                  NhlcairoImageWorkstationClass,NhlDEFAULT_APP,rlist);
    }
/*
 * Draw the default MapPlot object
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNpmTitleDisplayMode,"always");
    NhlRLSetString(rlist,NhlNtiMainString,"mp01c - Frame 1");
    NhlCreate(&mapid,"Map0",NhlmapPlotClass,wid,rlist);
    NhlDraw(mapid);
    NhlFrame(wid);

/*
 * Change some projection resources, add color fill, and
 * all the outlines (Geophysical, National, and US States).
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"mp01c - Frame 2");
    NhlRLSetString(rlist,NhlNmpFillOn,"true");
    NhlRLSetString(rlist,NhlNmpOutlineBoundarySets,"allBoundaries"); 
    NhlRLSetString(rlist,NhlNmpProjection,"orthographic");
    NhlRLSetString(rlist,NhlNmpPerimOn,"true");
    NhlRLSetFloat(rlist,NhlNvpYF,0.9);
    NhlRLSetFloat(rlist,NhlNvpHeightF,0.8);
    NhlRLSetFloat(rlist,NhlNmpCenterLatF,10.0);
    NhlRLSetFloat(rlist,NhlNmpCenterLonF,-90.0);
    NhlRLSetFloat(rlist,NhlNmpCenterRotF,45.0);
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);
/*
 * Use the national color set and limit the projection, 
 * using lat/lon boundaries.
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"mp01c - Frame 3");
    NhlRLSetString(rlist,NhlNmpFillBoundarySets,"national");
    NhlRLSetString(rlist,NhlNmpLimitMode,"latlon");
    NhlRLSetFloat(rlist,NhlNmpMinLatF,-60.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLatF,60.0);
    NhlRLSetFloat(rlist,NhlNmpMinLonF,-135.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLonF,-45.0);
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);
/*
 * Polar stereographic projection, change the grid spacing to 10 degrees
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"mp01c - Frame 4");
    NhlRLSetString(rlist,NhlNmpProjection,"stereographic");
    NhlRLSetFloat(rlist,NhlNmpGridSpacingF,10.);
    NhlRLSetFloat(rlist,NhlNmpMinLatF,20.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLatF,90.0);
    NhlRLSetFloat(rlist,NhlNmpMinLonF,0.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLonF,360.0);
    NhlRLSetFloat(rlist,NhlNmpCenterLatF,90.0);
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);

/*
 * Satellite projection using the angle limit method;
 * color US States only individually.
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"mp01c - Frame 5");
    NhlRLSetString(rlist,NhlNmpFillBoundarySets,"geophysicalAndUSStates");
    NhlRLSetString(rlist,NhlNmpProjection,"satellite");
    NhlRLSetString(rlist,NhlNmpLimitMode,"angles");
    NhlRLSetFloat(rlist,NhlNmpLeftAngleF,45.0);
    NhlRLSetFloat(rlist,NhlNmpRightAngleF,45.0);
    NhlRLSetFloat(rlist,NhlNmpBottomAngleF,45.0);
    NhlRLSetFloat(rlist,NhlNmpTopAngleF,45.0);
    NhlRLSetFloat(rlist,NhlNmpCenterLatF,20.0);
    NhlRLSetFloat(rlist,NhlNmpSatelliteDistF,1.75);
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);

/*
 * Destroy the objects created, close the HLU library and exit.
 */

    NhlDestroy(mapid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #9
0
int main(int argc, char *argv[])
{

    int appid,wid,mapid;
    int rlist;
    char const *wks_type = "x11";
/*
 * String arrays for specifying areas
 */

    NhlString fill_specs[] = { "mexico","bolivia","brazil","nicaragua",
                       "cuba","haiti","canada"};

    NhlString outline_specs[] = { "argentina","paraguay","colombia",
                      "us-colorado","us-texas",
                      "us-kentucky" };

    NhlString mask_specs[] = 
        { "us-colorado","us-texas","us-kentucky",
              "bolivia","paraguay","nicaragua","oceans" };
/*
 * 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.
 * The resource file sets most of the Contour resources that remain fixed
 * throughout the life of the Contour object.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"mp02",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation
 */
        rlist = NhlRLCreate(NhlSETRL);
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./mp02c.ncgm");
        NhlCreate(&wid,"mp02Work",
                  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,"mp02Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"./mp02c.ps");
        NhlCreate(&wid,"mp02Work",
                  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,"./mp02c.pdf");
        NhlCreate(&wid,"mp02Work",
                  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
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./mp02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"mp02Work",
                  NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./mp02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"mp02Work",
                  NhlcairoImageWorkstationClass,NhlDEFAULT_APP,rlist);
    }
/*
 * Create a plot focusing on North and South America;
 * Outlines are on by default; turn fill on.
 * By default the geophysical boundary set is used both for outline and
 * fill.
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNpmTitleDisplayMode,"Always");
    NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 1");
    NhlRLSetString(rlist,NhlNmpFillOn,"True");
    NhlRLSetString(rlist,NhlNmpProjection,"Orthographic");
    NhlRLSetString(rlist,NhlNmpPerimOn,"true");
    NhlRLSetFloat(rlist,NhlNmpCenterLatF,10.0);
    NhlRLSetFloat(rlist,NhlNmpCenterLonF,-90.0);
    NhlRLSetFloat(rlist,NhlNmpCenterRotF,45.0);
    NhlRLSetString(rlist,NhlNmpLimitMode,"LatLon");
    NhlRLSetFloat(rlist,NhlNmpMinLatF,-60.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLatF,60.0);
    NhlRLSetFloat(rlist,NhlNmpMinLonF,-135.0);
    NhlRLSetFloat(rlist,NhlNmpMaxLonF,-45.0);
    
/*
 * Highlight selected countries using their "political" color.
 */

    NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers,
                fill_specs,NhlNumber(fill_specs));

    NhlCreate(&mapid,"Map0",NhlmapPlotClass,wid,rlist);
    NhlDraw(mapid);
    NhlFrame(wid);

/*
 * Individually outline some other countries and some US states.
 */

    NhlRLClear(rlist);  
    NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 2");
    NhlRLSetStringArray(rlist,NhlNmpOutlineSpecifiers,
                outline_specs,NhlNumber(outline_specs));
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);
/*
 * Turn off the base geophysical set for outlines and fill, leaving only
 * the specified areas.
 * Also change the specification, 'canada' to 'canada*', 
 * in order to draw all areas belonging to Canada.
 * Note that another color, mpDefaultFillColor, is used for all areas
 * within the map projection that are otherwise not drawn, including the
 * oceans. If you look closely, you will see that the Canadian lakes 
 * are not drawn in the color used in the previous frame for the ocean.
 * The wild card specification, 'canada*', picks up all the lakes of
 * Canada. Lakes are drawn using mpInlandWaterFillColor, which is, by
 * default, set to the same color as mpOceanFillColor.
 */

    fill_specs[6] = "canada*";
    NhlRLClear(rlist);  
    NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 3");
    NhlRLSetString(rlist,NhlNmpFillBoundarySets,"NoBoundaries");
    NhlRLSetString(rlist,NhlNmpOutlineBoundarySets,"NoBoundaries");
    NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers,
                fill_specs,NhlNumber(fill_specs));
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);
/*
 * You can also specify area groupings using certain predefined 
 * string constants: set 'continents' on to demonstrate.
 * Masking an area is different from not explicitly drawing it. To enable
 * masking you must explicitly turn area masking and then create an area
 * mask specification list containing the name of each area to be masked.
 * There is an order of precedence for fill and masking. Explicitly 
 * named areas take precedence over area groupings, and small areas take 
 * precedence over enclosing larger areas. Otherwise masking takes 
 * precedence over filling.
 * >>> Masking or filling individual US states causes processing time and
 * >>> memory requirements to increase substantially. Hopefully the 
 * >>> performance can be improved before the release.
 */

    fill_specs[0] = "continents";
    fill_specs[1] = "us";
    NhlRLClear(rlist); 
    NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 4");
    NhlRLSetString(rlist,NhlNmpFillBoundarySets,"NoBoundaries");
    NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers,
                fill_specs,NhlNumber(fill_specs));
    NhlRLSetString(rlist,NhlNmpAreaMaskingOn,"True");
    NhlRLSetStringArray(rlist,NhlNmpMaskAreaSpecifiers,
                mask_specs,NhlNumber(mask_specs));
    NhlSetValues(mapid,rlist);

    NhlDraw(mapid);
    NhlFrame(wid);

/*
 * Destroy the objects created, close the HLU library and exit.
 */

    NhlDestroy(mapid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
void QNCLContourLine::plot(QGRIB2Message *grb2Msg, QString outputPath, QString outputFileName)
{
    /*float xbvalues1[7] = {0.,60.,120.,180.,240.,300.,360.};
    char *xblabels1[7] = {"0","60E","120E","180","120W","60W","0"};
    float xbvalues2[11] = {0.,3.,6.,9.,12.,15.,18.,21.,24.,27.,30.};
    float ylvalues[7] = {-90., -60.,-30.,0.,30.,60.,90.};
    char *xblabels2[11] = {"0","3","6","9","12","15","18","21","24","27","30"};
    char *yllabels[7] = {"90S","60S","30S","EQ","30N","60N","90N"};*/
    /*rules setting*/
    float       xbValues[7] = {0};
    char        *xbLabels[7];
    float       ybValues[7] = {0};
    char        *ybLabels[7];
    int         xLabelCount = 0, yLabelCount = 0;
    double *    dData;
    float  *    fData;
    //float       cmap[255][3] = {0};
    int         ni, nj;
    int         mi, mj;
    int         xStart, xEnd;
    int         yStart, yEnd;
    int         appid, jan, cn, mp, tx, srlist;
    ng_size_t   length[2];
    float       cmap[256][3];
    //float  *    cmap;
    size_t      nSize;
    ng_size_t   icount[2];
    int         k = 0;
    int         ps2;//1, ps2, png1;
    char        setting[256]= {0};

    /*x label setting*/
    memset(xbLabels, 0, sizeof(xbLabels));
    memset(ybLabels, 0, sizeof(ybLabels));
    xLabelCount = width/100 + 1;
    xLabelCount = (xLabelCount < 2)?2:((xLabelCount>7)?7:xLabelCount);
    for (int i = 0; i < xLabelCount; i ++) {
        xbValues[i] = leftLongitude + (rightLongitude - leftLongitude) * i / (xLabelCount - 1);
        xbLabels[i] = (char *)calloc(10, 1);
        if ((xbValues[i] == 0) || (xbValues[i] == 180) || (xbValues[i]) == 360)
            sprintf(xbLabels[i], "%d", ((int)xbValues[i])%360);
        else if ((xbValues[i] > 0) && (xbValues[i] < 180)) {
            if ((xbValues[i]-(int)xbValues[i]) == 0)
                sprintf(xbLabels[i], "%dE", ((int)xbValues[i])%360);
            else
                sprintf(xbLabels[i], "%3.4fE", xbValues[i]);
        }
        else if ((xbValues[i] > 180) && (xbValues[i] < 360)) {
            if ((xbValues[i]-(int)xbValues[i]) == 0)
                sprintf(xbLabels[i], "%dW", (360 - (int)xbValues[i]));
            else
                sprintf(xbLabels[i], "%3.4fW", 360. - xbValues[i]);
        }
    }
    yLabelCount = height/100+1;
    yLabelCount = (yLabelCount < 2)?2:((yLabelCount>7)?7:yLabelCount);
    for (int i = 0; i < yLabelCount; i++) {
        ybValues[i] = topLatitude - (topLatitude - bottomLatitude) * i / (yLabelCount - 1);
        ybLabels[i] = (char *)calloc(10, 1);
        if (ybValues[i] == 0)
            sprintf(ybLabels[i], "%d", ((int)ybValues[i])%360);
        else if ((ybValues[i] > 0) && (ybValues[i] <= 90)) {
            if ((ybValues[i]-(int)ybValues[i]) == 0)
                sprintf(ybLabels[i], "%dN", ((int)ybValues[i])%360);
            else
                sprintf(ybLabels[i], "%3.4fN", ybValues[i]);
        }
        else if ((ybValues[i] < 0) && (ybValues[i] >= -90)) {
            if ((ybValues[i]-(int)ybValues[i]) == 0)
                sprintf(ybLabels[i], "%dW", ((int)ybValues[i])%360);
            else
                sprintf(ybLabels[i], "%3.4fW", ybValues[i]);
        }
    }

    /*get data from grib2 message between in the contour setting*/
    grib_handle * hgrib = grb2Msg->getGRIBHandle();
    QString     workName;
    workName = outputFileName;
    workName = workName.left(workName.indexOf('.'));
    ni = grb2Msg->getGrid()->xp();
    nj = grb2Msg->getGrid()->yp();
    nSize = ni * nj;
    dData = (double *)calloc(ni*nj, sizeof(double));



    grib_get_double_array(hgrib, "values", dData, &nSize);
    mi = ((rightLongitude - leftLongitude) * 1000000 / grb2Msg->getGrid()->dx()) + 1;
    mj = ((topLatitude - bottomLatitude) * 1000000 / grb2Msg->getGrid()->dy()) + 1;
    if (mi > ni)
        mi = ni;
    if (mj > nj)
        mj = nj;
    fData = (float *)calloc(mi * mj, sizeof(float));
    xStart = (int)((leftLongitude * 1000000 - grb2Msg->getGrid()->lon1())/grb2Msg->getGrid()->dx());
    if ((xStart * grb2Msg->getGrid()->dx()) > (leftLongitude * 1000000))
        xStart --;
    if (xStart < 0)
        xStart = 0;
    xEnd = (int)((rightLongitude * 1000000 - grb2Msg->getGrid()->lon1())/grb2Msg->getGrid()->dx()) + 1;
    if ((xEnd * grb2Msg->getGrid()->dx()) < (rightLongitude * 1000000))
        xEnd++;
    if (xEnd > ni)
        xEnd = ni;
    yStart = (int)((grb2Msg->getGrid()->lat1() - topLatitude * 1000000)/grb2Msg->getGrid()->dy());
    if ((grb2Msg->getGrid()->lat1() - yStart * grb2Msg->getGrid()->dy()) < (topLatitude * 1000000))
        yStart--;
    if (yStart < 0)
        yStart = 0;
    yEnd = (int)((grb2Msg->getGrid()->lat1() - bottomLatitude * 1000000)/grb2Msg->getGrid()->dy()) + 1;
    if ((grb2Msg->getGrid()->lat1() - yEnd * grb2Msg->getGrid()->dy()) > (bottomLatitude * 1000000))
        yEnd++;
    if (yEnd > nj)
        yEnd = nj;
    for (int jj = yStart; jj < yEnd; jj++) {
        for (int ii = xStart; ii < xEnd; ii ++) {
            fData[k++] = dData[jj * ni + ii];
        }
    }

    NhlInitialize();
    srlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(srlist);
    NhlRLSetString(srlist, "appDefaultParent", "True");
    memset(setting, 0, sizeof(setting));
    strncpy(setting, outputPath.toStdString().c_str(), sizeof(setting)-1);
    NhlRLSetString(srlist, "appUsrDir", setting);
    NhlCreate(&appid, grb2Msg->getName().toStdString().c_str(), NhlappClass, 0, srlist);

    NhlRLClear(srlist);
    QString outputpsFileName = outputPath + "/" + outputFileName;
    memset(setting, 0, sizeof(setting));
    strncpy(setting, outputpsFileName.toStdString().c_str(), sizeof(setting)-1);
    NhlRLSetString(srlist, NhlNwkFileName, setting);
    /*NhlRLSetString(srlist, NhlNwkFormat, "ps");*/
    NhlRLSetString(srlist, NhlNwkFormat, "png");

    /*NhlRLSetString(srlist, NhlNwkOrientation, "landscape");
    NhlRLSetString(srlist, NhlNwkOrientation, "portrait");
    NhlRLSetInteger(srlist, NhlNwkDeviceLowerX, 0);
    NhlRLSetInteger(srlist, NhlNwkDeviceLowerY, 60);
    NhlRLSetInteger(srlist, NhlNwkDeviceUpperX, width);
    NhlRLSetInteger(srlist, NhlNwkDeviceUpperY, height); */
    float   fcolor[3] = {0};
    float   bcolor[3] = {0};
    int r, g, b;
    foregroundColor.getRgb(&r, &g, &b);
    fcolor[0] = ((float)r)/255.;
    fcolor[1] = ((float)g)/255.;
    fcolor[2] = ((float)b)/255.;
    length[0] = 3;
    NhlRLSetFloatArray(srlist, NhlNwkForegroundColor, fcolor, length[0]);
    backgroundColor.getRgb(&r, &g, &b);
    bcolor[0] = ((float)r)/255.;
    bcolor[1] = ((float)g)/255.;
    bcolor[2] = ((float)b)/255.;
    length[0] = 3;
    NhlRLSetFloatArray(srlist, NhlNwkBackgroundColor, bcolor, length[0]);
    length[0] = loadColormap(colormap, &cmap[0][0], 256);
    length[1] = 3;
    if (length[0] > 0) {
        NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0], 2, length);
    } else {
        memset(setting, 0, sizeof(setting));
        strncpy(setting, colormap.toStdString().c_str(), sizeof(setting)-1);
        NhlRLSetString(srlist, NhlNwkColorMap, setting);
    }
    /*NhlCreate(&ps2, workName.toStdString().c_str(), NhlpsWorkstationClass, 0, srlist);*/
    NhlCreate(&ps2, workName.toStdString().c_str(), NhlcairoImageWorkstationClass, 0, srlist);


    icount[1] = xEnd - xStart;
    icount[0] = yEnd - yStart; /**/
    NhlRLClear(srlist);
    NhlRLSetMDFloatArray(srlist, NhlNsfDataArray, fData, 2, icount);
    NhlRLSetFloat(srlist, NhlNsfXCStartV, leftLongitude);
    NhlRLSetFloat(srlist, NhlNsfXCEndV, rightLongitude);
    NhlRLSetFloat(srlist, NhlNsfYCStartV, topLatitude);
    NhlRLSetFloat(srlist, NhlNsfYCEndV, bottomLatitude);
    NhlCreate(&jan, "sf", NhlscalarFieldClass, appid, srlist);
    //NhlRLSetString(srlist, NhlNwkOrientation, "landscape");
    /*NhlRLSetString(srlist, NhlNwkOrientation, "portrait");*/
    NhlRLSetString(srlist, NhlNcnLineDrawOrder, "predraw");

    /** Create a ContourPlot object.*/
    NhlRLClear(srlist);
    NhlRLSetInteger(srlist, NhlNcnScalarFieldData, jan);
    NhlRLSetFloat(srlist, NhlNvpXF, .1);
    NhlRLSetFloat(srlist, NhlNvpYF, .75);
    NhlRLSetFloat(srlist, NhlNvpWidthF, 0.8);
    NhlRLSetFloat(srlist, NhlNvpHeightF, 0.4);
    NhlRLSetString(srlist, NhlNcnInfoLabelOn, "False");
    NhlRLSetString(srlist, NhlNcnHighLabelsOn, "False");
    NhlRLSetString(srlist, NhlNcnLowLabelsOn, "False");
    //NhlRLSetIntegerArray(srlist, NhlNcnLineColors, linecolors, 15);

    NhlRLSetString(srlist, NhlNcnLineDrawOrder, "predraw");
    NhlRLSetString(srlist, NhlNcnFillDrawOrder, "predraw");
    NhlRLSetString(srlist, NhlNcnLabelDrawOrder, "predraw");
    memset(setting, 0, sizeof(setting));
    strncpy(setting, levelSelectionMode.toStdString().c_str(), sizeof(setting)-1);
    NhlRLSetString(srlist, NhlNcnLevelSelectionMode, setting);
    NhlRLSetInteger(srlist, NhlNcnMaxLevelCount, maxLevelCount);
    if (levelSelectionMode == "ManualLevels") {
        NhlRLSetFloat(srlist, NhlNcnMinLevelValF, minLevel);
        NhlRLSetFloat(srlist, NhlNcnMaxLevelValF, maxLevel);
        NhlRLSetFloat(srlist, NhlNcnLevelSpacingF, levelSpacing);
    } else if (levelSelectionMode == "ExplicitLevels") {
        length[0] = maxLevelCount;
        NhlRLSetFloatArray(srlist, NhlNcnLevelSpacingF, lineLevels, length[0]);
    } else if (levelSelectionMode == "EqualSpacedLevels") {
        NhlRLSetFloat(srlist, NhlNcnLevelSpacingF, levelSpacing);
    }

    if (plotMode == 0) {
        NhlRLSetString(srlist, NhlNcnFillOn, "False");
        NhlRLSetString(srlist, NhlNcnLinesOn, "True");
        NhlRLSetString(srlist, NhlNcnLineLabelsOn, "True");
        NhlRLSetInteger(srlist, NhlNcnLineLabelInterval, 2);
        NhlRLSetString(srlist, NhlNcnLineLabelPlacementMode, "computed");
        if (monoColor == false) {
            NhlRLSetString(srlist, NhlNcnMonoLineColor, "False");
            NhlRLSetIntegerArray(srlist, NhlNcnLineColors, lineColors, maxLevelCount);
        } else {
            NhlRLSetString(srlist, NhlNcnMonoLineColor, "True");
            /*NhlRLSetString(srlist, NhlNcnLineColor, "Black");*/
            NhlRLSetInteger(srlist, NhlNcnLineColor, lineColor);
        }
    } else {
        NhlRLSetString(srlist, NhlNcnFillOn, "True");
        NhlRLSetString(srlist, NhlNcnLinesOn, "False");
        NhlRLSetString(srlist, NhlNcnFillMode, "AreaFill");
        NhlRLSetString(srlist, NhlNcnLineLabelsOn, "False");
        length[0] = maxLevelCount;
        NhlRLSetIntegerArray(srlist, NhlNcnFillColors, lineColors, length[0]);
    }
    NhlRLSetString(srlist, NhlNtmXBMode, "EXPLICIT");
    NhlRLSetFloatArray(srlist, NhlNtmXBValues, xbValues, xLabelCount);
    NhlRLSetStringArray(srlist, NhlNtmXBLabels, &xbLabels[0], xLabelCount);
    NhlRLSetString(srlist, NhlNtmYLMode, "EXPLICIT");
    NhlRLSetFloatArray(srlist, NhlNtmYLValues, ybValues, yLabelCount);
    NhlRLSetStringArray(srlist, NhlNtmYLLabels, &ybLabels[0], yLabelCount);
    NhlRLSetString(srlist, NhlNtmXTLabelsOn, "False");
    NhlRLSetString(srlist, NhlNtmYRLabelsOn, "False");
    NhlRLSetFloat(srlist, NhlNtmXBLabelFontHeightF, .010);
    NhlRLSetFloat(srlist, NhlNtmYLLabelFontHeightF, .010);
    NhlRLSetFloat(srlist, NhlNtmXBMajorOutwardLengthF, .006);
    NhlRLSetFloat(srlist, NhlNtmXBMajorLengthF, .006);
    NhlRLSetFloat(srlist, NhlNtmXTMajorLengthF, 0.);
    NhlRLSetFloat(srlist, NhlNtmXTMajorOutwardLengthF, 0.);
    NhlRLSetFloat(srlist, NhlNtmYLMajorOutwardLengthF, .006);
    NhlRLSetFloat(srlist, NhlNtmYLMajorLengthF, .006);
    NhlRLSetString(srlist, NhlNtmXBMinorOn, "False");
    NhlRLSetString(srlist, NhlNtmXTMinorOn, "False");
    NhlRLSetString(srlist, NhlNtmYLMinorOn, "False");
    NhlRLSetString(srlist, NhlNtmYRMinorOn, "False");
    if (monoThickness == true) {
        NhlRLSetString(srlist, NhlNcnMonoLineThickness, "True");
        NhlRLSetFloat(srlist, NhlNcnLineThicknessF, thickness);
    } else {
        NhlRLSetString(srlist, NhlNcnMonoLineThickness, "False");
        NhlRLSetFloatArray(srlist, NhlNcnLineThicknesses, lineThicknesses, maxLevelCount);
    }
    NhlCreate(&cn, "cn", NhlcontourPlotClass, ps2, srlist);

    /* Create a MapPlot object. */
    NhlRLClear(srlist);
    NhlRLSetFloat(srlist, NhlNvpXF, .1);
    NhlRLSetFloat(srlist, NhlNvpYF, .75);
    NhlRLSetFloat(srlist, NhlNvpWidthF, 0.8);
    NhlRLSetFloat(srlist, NhlNvpHeightF, 0.4);
    /*NhlRLSetString(srlist, NhlNmpFillOn, "True");*/
    NhlRLSetString(srlist, NhlNmpFillOn, "False");
    NhlRLSetString(srlist, NhlNmpLabelsOn, "False");
    /*NhlRLSetString(srlist, NhlNmpGeophysicalLineColor, "Black");
    NhlRLSetString(srlist, NhlNmpDefaultFillColor, "DarkSalmon");
    NhlRLSetString(srlist, NhlNmpLandFillColor, "DarkSalmon");
    NhlRLSetString(srlist, NhlNmpOceanFillColor, "Blue");
    NhlRLSetString(srlist, NhlNmpInlandWaterFillColor, "Blue");*/
    NhlRLSetString(srlist, NhlNmpOutlineOn, "True");
    NhlRLSetString(srlist, NhlNgsLineColor, "Black");
    /*NhlRLSetString(srlist, NhlNmpOutlineOn, "True");
    NhlRLSetString(srlist, NhlNmpOutlineBoundarySets, "Geophysical");*/
    /*NhlRLSetString(srlist, NhlNmpOutlineDrawOrder, "predraw");*/
    NhlRLSetString(srlist, NhlNmpOutlineBoundarySets, "Geophysical");
    NhlRLSetFloat(srlist, NhlNmpGeophysicalLineThicknessF, 1);
    NhlRLSetString(srlist, NhlNmpGeophysicalLineColor, "Black");
    /*NhlRLSetString(srlist, NhlNmpPerimDrawOrder, "predraw");*/
    memset(setting, 0, sizeof(setting));
    strncpy(setting, mapProject.toStdString().c_str(), sizeof(setting)-1);
    if (mapProject == "Polar Stereographic") {
        NhlRLSetString(srlist, NhlNmpProjection, "Stereographic");
        if (polarPosition == "NH") {
            NhlRLSetFloat(srlist, NhlNmpMinLatF, 0);
            NhlRLSetFloat(srlist, NhlNmpMaxLatF, 90);
            NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude);
            NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude);
            NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2);
            NhlRLSetFloat(srlist, NhlNmpCenterLatF, 90);
        } else {
            NhlRLSetFloat(srlist, NhlNmpMinLatF, -90);
            NhlRLSetFloat(srlist, NhlNmpMaxLatF, 0);
            NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude);
            NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude);
            NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2);
            NhlRLSetFloat(srlist, NhlNmpCenterLatF, -90);
        }
    } else {
        NhlRLSetString(srlist, NhlNmpProjection, setting);
        NhlRLSetFloat(srlist, NhlNmpMinLatF, bottomLatitude);
        NhlRLSetFloat(srlist, NhlNmpMaxLatF, topLatitude);
        NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude);
        NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude);
        NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2);
        NhlRLSetFloat(srlist, NhlNmpCenterLatF, (topLatitude + bottomLatitude)/2);
    }

    NhlRLSetString(srlist, NhlNmpGridAndLimbOn, "False");
    NhlRLSetString(srlist, NhlNmpLimitMode, "latlon");
    NhlCreate(&mp, "mp", NhlmapPlotClass, ps2, srlist);

    /* Create a TextItem object. */
    QString title = grb2Msg->getParameter()->nclName();
    QString level;
    level.setNum(grb2Msg->getLevel()->firstLevel());
    switch (grb2Msg->getLevel()->firstLevelType()) {
    case 100:
    case 101:
        level += "Pa";
        break;
    case 0:
    case 106:
        level += "m";
        break;
    }
    title += " " + level + " " + grb2Msg->getTimeLevel()->getName() ;

    NhlRLClear(srlist);
    NhlRLSetFloat(srlist, NhlNtxPosXF, 0.5);
    NhlRLSetFloat(srlist, NhlNtxPosYF, 0.8);
    NhlRLSetString(srlist, NhlNtxJust, "CENTERCENTER");
    memset(setting, 0, sizeof(setting));
    strncpy(setting, title.toStdString().c_str(), sizeof(setting)-1);
    NhlRLSetString(srlist, NhlNtxString, setting);
    NhlRLSetFloat(srlist, NhlNtxFontHeightF, .030);
    NhlRLSetInteger(srlist, NhlNtxFont, 25);
    NhlCreate(&tx, "tx", NhltextItemClass, ps2, srlist);

    NhlDraw(mp);
    NhlDraw(cn);
    NhlDraw(tx);
    NhlFrame(ps2);

    NhlDestroy(ps2);
    NhlDestroy(appid);
    for (int idx = 0; idx < xLabelCount; idx ++) {
        free(xbLabels[idx]);
    }
    for (int idx = 0; idx < yLabelCount; idx ++) {
        free(ybLabels[idx]);
    }
    free(dData);
    free(fData);
}
Beispiel #11
0
int main(int argc, char *argv[])
{
    char const *wks_type = "x11";
    int appid,wid,stid,vfid;
    int rlist,grlist;
    ng_size_t len_dims[2];
    float stepsize,arrowlength,spacing;
    float U[N][M],V[N][M];

/*
 * Generate vector data arrays
 */
    {
	    float igrid, jgrid;
	    int i,j;
	    igrid = 2.0 * PI / (float) M;
	    jgrid = 2.0 * PI / (float) N;
	    for (j = 0; j < N; j++) {
		    for (i = 0; i < M; i++) {
			    U[j][i] = 10.0 * cos(jgrid * (float) j);
			    V[j][i] = 10.0 * cos(igrid * (float) i);
		    }
	    }
    }

/*
 * 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);
    grlist = NhlRLCreate(NhlGETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"st02",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./st02c.ncgm");
        NhlCreate(&wid,"st02Work",
                  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,"st02Work",NhlcairoWindowWorkstationClass,appid,rlist);
    }

    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
/*
 * Create an older-style PostScript workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"st02c.ps");
        NhlCreate(&wid,"st02Work",NhlpsWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
/*
 * Create an older-style PDF workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"st02c.pdf");
        NhlCreate(&wid,"st02Work",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,"st02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"st02Work",NhlcairoDocumentWorkstationClass,appid,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"st02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"st02Work",NhlcairoImageWorkstationClass,appid,rlist);
    }
/*
 * 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)
 */

    len_dims[0] = N;
    len_dims[1] = M;
    NhlRLClear(rlist);
    NhlRLSetMDFloatArray(rlist,NhlNvfUDataArray,&U[0][0],2,len_dims);
    NhlRLSetMDFloatArray(rlist,NhlNvfVDataArray,&V[0][0],2,len_dims);
    NhlCreate(&vfid,"vectorfield",NhlvectorFieldClass,appid,rlist);


/*
 * Create a StreamlinePlot object, supplying the VectorField object as data
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,
		   "Modifying StreamlinePlot resources");
    NhlRLSetInteger(rlist,NhlNstVectorFieldData,vfid);
    NhlCreate(&stid,"streamlineplot",NhlstreamlinePlotClass,wid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);

/* 
 * Get the values of several resources that are set dynamically based
 * on the assumed NDC size of a grid cell. Each of this will be separately
 * modified in the course of this example to illustrate their effect.
 */
      
    NhlRLClear(grlist);
    NhlRLGetFloat(grlist,NhlNstStepSizeF,&stepsize);
    NhlRLGetFloat(grlist,NhlNstArrowLengthF,&arrowlength);
    NhlRLGetFloat(grlist,NhlNstMinLineSpacingF,&spacing);
    NhlGetValues(stid,grlist);

/* 
 * Increase the step size 
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Larger Step Size");
    NhlRLSetFloat(rlist,NhlNstStepSizeF,stepsize * 4.0);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);
/* 
 * Decrease the step size 
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Smaller Step Size");
    NhlRLSetFloat(rlist,NhlNstStepSizeF,stepsize * 0.25);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);

/* 
 * Increase the minimum line spacing 
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Larger Minimum Line Spacing");
    NhlRLSetFloat(rlist,NhlNstStepSizeF,stepsize);
    NhlRLSetFloat(rlist,NhlNstMinLineSpacingF, spacing * 4.0);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);
/* 
 * Decrease the minimum line spacing
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Smaller Minimum Line Spacing");
    NhlRLSetFloat(rlist,NhlNstMinLineSpacingF,spacing * 0.25);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);

/* 
 * Increase the line starting grid stride 
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Larger Line Starting Grid Stride");
    NhlRLSetFloat(rlist,NhlNstMinLineSpacingF,spacing);
    NhlRLSetInteger(rlist,NhlNstLineStartStride,3);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);
/* 
 * Decrease the line starting grid stride
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Smaller Line Starting Grid Stride");
    NhlRLSetInteger(rlist,NhlNstLineStartStride,1);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);

/*
 * Increase the arrow size
 */

    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtiMainString,"Larger Arrows");
    NhlRLSetInteger(rlist,NhlNstLineStartStride,2);
    NhlRLSetFloat(rlist,NhlNstArrowLengthF, arrowlength * 2.0);
    NhlSetValues(stid,rlist);

    NhlDraw(stid);
    NhlFrame(wid);

/*
 * Destroy the objects created, close the HLU library and exit.
 */
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #12
0
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);
}
Beispiel #13
0
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);
}
Beispiel #14
0
int main()
{
    int appid, wid, pid;
    int rlist;
    char const *wks_type = "x11";
/*
 * 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. In this example the resource file supplies the
 * plot title only.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlRLSetString(rlist,NhlNappDefaultParent,"True");
    NhlCreate(&appid,"tm03",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation object.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./tm03c.ncgm");
        NhlCreate(&wid,"tm03Work",NhlncgmWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
/*
 * Create an X11 workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlCreate(&wid,"tm03Work",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,"./tm03c.ps");
        NhlCreate(&wid,"tm03Work",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,"./tm03c.pdf");
        NhlCreate(&wid,"tm03Work",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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tm03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"tm03Work",NhlcairoDocumentWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./tm03c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"tm03Work",NhlcairoImageWorkstationClass,
                  NhlDEFAULT_APP,rlist);
    }

    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvpXF,.2);
    NhlRLSetFloat(rlist,NhlNvpYF,.8);
    NhlRLSetFloat(rlist,NhlNvpWidthF,.6);
    NhlRLSetFloat(rlist,NhlNvpHeightF,.6);
    NhlRLSetFloat(rlist,NhlNtmYLDataTopF,100.0);
    NhlRLSetFloat(rlist,NhlNtmYLDataBottomF,1000.0);
    NhlRLSetFloat(rlist,NhlNtmXBDataRightF,90.0);
    NhlRLSetFloat(rlist,NhlNtmXBDataLeftF,-90.0);
    NhlRLSetInteger(rlist,NhlNtmYLStyle,NhlIRREGULAR);
    NhlRLSetInteger(rlist,NhlNtmXBMode,NhlEXPLICIT);
    NhlRLSetInteger(rlist,NhlNtmXBMinorOn,False);
    NhlRLSetFloatArray(rlist,
               NhlNtmXBValues,labellocs,NhlNumber(labellocs));

/*
 * Array 'level' contains original grid point data locations in Y
 * direction. Providing the grid points to the TickMark object as the
 * control points for the IRREGULAR style transformation, means that
 * these points will be evenly spaced along the Y axis. Since this is
 * how CONPACK thinks the points are spaced, the tick marks will
 * correctly correspond with the  data coordinates. See the HLU User's
 * Guide for a complete discussion of IRREGULAR style transformations.
*/
    NhlRLSetStringArray(rlist,
                NhlNtmXBLabels,labels,NhlNumber(labels));
    NhlRLSetFloatArray(rlist,
               NhlNtmYLIrregularPoints,level,NhlNumber(level));

    NhlCreate(&pid,"TickMarks",NhltickMarkClass,wid,rlist);

    NhlDraw(pid);
    NhlFrame(wid);
    NhlDestroy(pid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #15
0
int main()
{
    int appid, wid, pid;
    int rlist;
    char *labels[5];
    NhlColorIndex colors[5];
    NhlMarkerIndex item_ind[5];
    float mkthik[5];
    char const *wks_type = "x11";

/*
 * Initialize data values
 */
    labels[0] = "Marker_0";
    labels[1] = "Marker_1";
    labels[2] = "Marker_2";
    labels[3] = "Marker_3";
    labels[4] = "Marker_4";
    colors[0] = 3;
    colors[1] = 5;
    colors[2] = 7;
    colors[3] = 9;
    colors[4] = 11;
    mkthik[0] = 2.;
    mkthik[1] = 3.;
    mkthik[2] = 4.;
    mkthik[3] = 5.;
    mkthik[4] = 6.;
    item_ind[0] =  2;
    item_ind[1] =  3;
    item_ind[2] =  4;
    item_ind[3] =  5;
    item_ind[4] =  6;

/*
 * 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.
 * In this example the resource file supplies the plot title only.
 */
    rlist = NhlRLCreate(NhlSETRL);
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNappDefaultParent,"True");
    NhlRLSetString(rlist,NhlNappUsrDir,"./");
    NhlCreate(&appid,"lg02",NhlappClass,NhlDEFAULT_APP,rlist);

    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./lg02c.ncgm");
        NhlCreate(&wid,"lg02Work",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,"lg02Work",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,"./lg02c.ps");
        NhlCreate(&wid,"lg02Work",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,"./lg02c.pdf");
        NhlCreate(&wid,"lg02Work",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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./lg02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"lg02Work",NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,
                  rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./lg02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wid,"lg02Work",NhlcairoImageWorkstationClass,NhlDEFAULT_APP,
                  rlist);
    }
/*
 * Specify the viewport extent of the object.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNvpXF,0.);
    NhlRLSetFloat(rlist,NhlNvpYF,1.);
    NhlRLSetFloat(rlist,NhlNvpWidthF,1.);
    NhlRLSetFloat(rlist,NhlNvpHeightF,1.);

/*
 * Specify the type of markers for the legend.
 */
    NhlRLSetInteger(rlist,NhlNlgItemCount,5);
    NhlRLSetInteger(rlist,NhlNlgMonoItemType,True);
    NhlRLSetInteger(rlist,NhlNlgItemType,NhlMARKERS);
    NhlRLSetStringArray(rlist,NhlNlgLabelStrings,labels,5);
    NhlRLSetIntegerArray(rlist,NhlNlgMarkerColors,colors,5);
    NhlRLSetIntegerArray(rlist,NhlNlgMarkerIndexes,item_ind,5);
    NhlRLSetString(rlist,NhlNlgMonoMarkerThickness,"False");
    NhlRLSetFloatArray(rlist,NhlNlgMarkerThicknesses,mkthik,5);
    NhlRLSetFloat(rlist,NhlNlgMarkerSizeF,.05);
    NhlCreate(&pid,"Legend",NhllegendClass,wid,rlist);

    NhlDraw(pid);
    NhlFrame(wid);
    NhlDestroy(pid);
    NhlDestroy(wid);
    NhlDestroy(appid);
    NhlClose();
    exit(0);
}
Beispiel #16
0
void guiNhlRLSetInteger(int id, char *resname, int value)
{
    NhlRLSetInteger(id, (NhlString)resname, value);
}
Beispiel #17
0
int main()
{
      int appid, widx,widn,widp,widpdf, pidx,pidn,pidp,pidpdf;
      int srlist;
      int i;
/*
 * 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. In this example the resource file supplies the
 * plot title only.
 */
      srlist = NhlRLCreate(NhlSETRL);
      NhlRLClear(srlist);
      NhlRLSetString(srlist,NhlNappUsrDir,"./");
      NhlRLSetString(srlist,NhlNappDefaultParent,"True");
      NhlCreate(&appid,"basic07",NhlappClass,NhlDEFAULT_APP,srlist);

/*
 * Create an NCGM workstation.
 */
      NhlRLClear(srlist);
      NhlRLSetString(srlist,NhlNwkMetaName,"basic07c.ncgm");
      NhlCreate(&widn,"basic07ncgm",NhlncgmWorkstationClass,NhlDEFAULT_APP,
                srlist);
/*
 * Create an older-style PostScript workstation.
 */
      NhlRLClear(srlist);
      NhlRLSetString(srlist,NhlNwkPSFileName,"basic07c.ps");
      NhlRLSetString(srlist,NhlNwkOrientation,"portrait");
      NhlRLSetString(srlist,NhlNwkPSFormat,"ps");
      NhlCreate(&widp,"basic07ps",NhlpsWorkstationClass,NhlDEFAULT_APP,
                srlist);
/*
 * Create an older-style PDF workstation.
 */
      NhlRLClear(srlist);
      NhlRLSetString(srlist,NhlNwkPDFFileName,"basic07c.pdf");
      NhlRLSetString(srlist,NhlNwkOrientation,"portrait");
      NhlRLSetString(srlist,NhlNwkPDFFormat,"pdf");
      NhlCreate(&widpdf,"basic07pdf",NhlpdfWorkstationClass,NhlDEFAULT_APP,
                srlist);
/*
 * Create an X Workstation.
 */
      NhlRLClear(srlist);
      NhlRLSetString(srlist,NhlNwkPause,"True");
      NhlCreate(&widx,"basic07x11",NhlcairoWindowWorkstationClass,NhlDEFAULT_APP,
                srlist);
/*
 * Create four plots, one for each workstation type.
 *
 *  Use color index 2
 */
      i = 2;
      NhlRLClear(srlist);
      NhlRLSetInteger(srlist,NhlNtxBackgroundFillColor,i);
      NhlCreate(&pidx,"TextItems",NhltextItemClass,widx,srlist);

      NhlCreate(&pidn,"TextItems",NhltextItemClass,widn,srlist);

      NhlCreate(&pidp,"TextItems",NhltextItemClass,widp,srlist);

      NhlCreate(&pidpdf,"TextItems",NhltextItemClass,widpdf,srlist);

      NhlDraw(pidx);
      NhlDraw(pidn);
      NhlDraw(pidp);
      NhlDraw(pidpdf);
      NhlFrame(widx);
      NhlFrame(widp);
      NhlFrame(widpdf);
      NhlFrame(widn);
 
      NhlDestroy(pidx);
      NhlDestroy(pidn);
      NhlDestroy(pidp);
      NhlDestroy(pidpdf);
      NhlDestroy(widx);
      NhlDestroy(widp);
      NhlDestroy(widpdf);
      NhlDestroy(widn);
      NhlDestroy(appid);

      NhlClose();
      exit (0);
}
Beispiel #18
0
int main()
{
    int appid1,appid2,wks,wks2,con1,con2,con3,field1,rlist;

    int data1[5][5] = { {3,4,4,5,5}, 
                        {2,3,5,5,4},
                        {2,4,5,4,4},
                        {3,4,4,4,3},
                        {3,3,3,3,3} };

    ng_size_t  dims[2] = { 5, 5 };

/*
 * Initialize the graphics libraries and create a resource list that
 * is normally used to assign name/value pairs within objects.  Then
 * clear (empty) this list, and create an application object.  This
 * object manages multiple resource databases used by separate objects.
 */
    NhlInitialize();
    rlist = NhlRLCreate(NhlSETRL);

    NhlRLClear(rlist);
    NhlCreate(&appid1,"appid1",NhlappClass,NhlDEFAULT_APP,rlist);
/*
 * ###########
 * # FRAME 1 #
 * ###########
 * This frame demonstrates how to create and assign data to a contour plot.
 *
 * Create an X workstation.
 */
    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,NhlNwkPause,True);
    NhlCreate(&wks,"wks",NhlcairoWindowWorkstationClass,NhlDEFAULT_APP,rlist);
/*
 * Create a scalar field object that will be used as a data set for a 
 * contour object.  The sfDataArray resource is used to assign a data
 * array to a scalar field data object.
 */
    NhlRLClear(rlist);
    NhlRLSetMDIntegerArray(rlist,"sfDataArray",&data1[0][0],2,dims);
    NhlCreate(&field1,"field1",NhlscalarFieldClass,
              NhlDEFAULT_APP,rlist);
/*
 * Create a contour plot object and assign the data using the
 * cnScalarFieldData resource.
 */
    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,"cnScalarFieldData",field1);
    NhlCreate(&con1,"con1",NhlcontourPlotClass,wks,rlist);
/*
 * Draw the plot. 
 */
    NhlDraw(con1);
/*
 * Update and clear the workstation.
 */
    NhlFrame(wks);
/*
 * ###########
 * # FRAME 2 #
 * ###########
 * This frame demonstrates how to set resources using a resource file.
 *
 * Resources are read from a resource file called basic03.res because
 * the first argument in the create call is "basic03". This resource file
 * is only read at the time an application object is created.
 * The resource file contains resource assignments that control the
 * characteristics of a plot.
 */
    NhlRLClear(rlist);
    NhlCreate(&appid2,"basic03",NhlappClass,NhlDEFAULT_APP,rlist);
/*
 * Create another workstation window and make it a child of the
 * new application object by using the appid2 variable as the argument
 * for the parent id.  By making this a child of the application
 * object, the resources that are set in the basic03.res resource
 * file will apply to this object and its children.
 */
    NhlRLClear(rlist);
    NhlCreate(&wks2,"wks2",NhlcairoWindowWorkstationClass,appid2,rlist);
/*
 * Create another contour plot object and assign the data.
 * Notice that the parent id is wks2, making the contour object
 * a child of the new workstation.
 */
    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,"cnScalarFieldData",field1);
    NhlCreate(&con2,"con2",NhlcontourPlotClass,wks2,rlist);
/*
 * The contour object is drawn with filled contours because there is
 * a resource in basic03.res that specifies that contour fill is on.
 */
    NhlDraw(con2);
/*
 * Updates and clear the workstation.
 */
    NhlFrame(wks2);
/*
 * ###########
 * # FRAME 3 #
 * ###########
 * This frame demonstrates how resources can be set when an object is
 * created.  
 *
 * A variable length list of resource name/value pairs specifies
 * a resource and its value.  In this example contour line labels are turned
 * off by setting the "cnLineLabelsOn" resource to "False".
 */
    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,"cnScalarFieldData",field1);
    NhlRLSetString(rlist,"cnLineLabelsOn","False");
    NhlCreate(&con3,"con3",NhlcontourPlotClass,wks2,rlist);
/*
 * Draw the contour object.
 */
    NhlDraw (con3);
/*
 * Update and clear the workstation.
 */
    NhlFrame(wks2);
/*
 * ###########
 * # FRAME 4 #
 * ###########
 * This frame demonstrates how to use the setvalues expression to set 
 * resources for an object that has already been created.
 *
 * The setvalues expression is used to assign values to the resources
 * of a object whose id is given as the first argument in the expression.
 * In this example, that argument is "con3."
 *
 * Any resource that is valid for the con3 object can be set in the following
 * expression.  In this example, setting "cnFillOn" to "False" turns 
 * contour fill off.  By default, cnFillOn is "False", but since it
 * is set to "True" in the resource file, we can override that value by
 * using the setvalues expression.  
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,"cnFillOn","False");
    NhlSetValues(con3,rlist);
/*
 * Draw the contour object.
 */
    NhlDraw (con3);
/*
 * Update and clear the workstation
 */
    NhlFrame(wks2);
/*
 * Clean up (deleting the parent object recursively deletes all of its 
 * children).
 */
    NhlDestroy(wks);
    NhlDestroy(appid1);
    NhlDestroy(appid2);

    NhlClose();
    exit (0);
}
Beispiel #19
0
int main()
{
    int appid,wks,con1,rlist;

    char const *wks_type = "x11";

/*
 * Initialize the graphics libraries and create a resource list that
 * is normally used to assign name/value pairs within objects.  Then
 * clear (empty) this list, and create an application object.  This
 * object manages multiple resource databases used by separate objects.
 */
    NhlInitialize();
    rlist = NhlRLCreate(NhlSETRL);

    NhlRLClear(rlist);
    NhlCreate(&appid,"basic02",NhlappClass,NhlDEFAULT_APP,rlist);
/*
 * ###########
 * # FRAME 1 #
 * ###########
 * Choose the type of output you want to create.  You may write your
 * output to an NCGM file, X workstation window, or a PostScript file. 
 */
    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
/*
 * Create a meta file workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./basic02c.ncgm");
        NhlCreate(&wks,"wks",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(&wks,"wks",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,"./basic02c.ps");
        NhlCreate(&wks,"wks",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,"./basic02c.pdf");
        NhlCreate(&wks,"wks",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.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wks,"wks",NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,
                  rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
/*
 * Create a cairo PNG workstation.
 */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic02c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlCreate(&wks,"wks",NhlcairoImageWorkstationClass,NhlDEFAULT_APP,
                  rlist);
    }

/*
 * Create a plot object.  In this example, we will create a contour plot.
 *
 * Four view class resources, vpXF, vpYF, vpWidthF, and vpHeightF, are
 * assigned values in the following create call.  The combination of
 * these four resources determines where the plot will display in the
 * output window.  The values of these resources are specified in 
 * Normalized Device Coordinates (NDCs).  In this two-dimensional coordinate 
 * system (0,0) specifies the lower-left corner and (1,1) specifies the 
 * upper-right corner of a plot.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,"vpXF",0.05); 
    NhlRLSetFloat(rlist,"vpYF",0.95); 
    NhlRLSetFloat(rlist,"vpWidthF",0.4); 
    NhlRLSetFloat(rlist,"vpHeightF",0.4); 
    NhlCreate(&con1,"con1",NhlcontourPlotClass,wks,rlist);
/*
 * Draw the plot. 
 */
    NhlDraw(con1);
/*
 * The frame call updates and then clears the workstation.
 * Anything written to the workstation after a frame call is made will be
 * drawn in a subsequent frame. 
 */
    NhlFrame(wks);
/*
 * ###########
 * # FRAME 2 #
 * ###########
 *
 * This example demonstrates drawing multiple plots in a single frame.
 *
 * Calling draw again will produce the identical plot that was drawn in the
 * first frame.
 */
    NhlDraw(con1);
/*
 * To add another plot to the same frame, we first need to reset the 
 * viewport resources so that the next plot does not overwrite the first
 * one.  The setvalues expression is used to set resources after an object
 * has already been created.  The first argument, "con1", in the setvalues
 * expression specifies an object id of a plot that was generated earlier
 * with the create call.  This is then followed by a list of resource value
 * pairs that apply to the object.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,"vpXF",0.55); 
    NhlRLSetFloat(rlist,"vpYF",0.45); 
    NhlRLSetFloat(rlist,"vpWidthF",0.2); 
    NhlRLSetFloat(rlist,"vpHeightF",0.2); 
        NhlSetValues(con1,rlist);
/*
 * Because of the new viewport resource settings, calling draw produces 
 * a plot in the lower-right quadrant of the frame.
 */
    NhlDraw(con1);
/*
 * Updates and clear the workstation.
 */
    NhlFrame(wks);
/*
 * Clean up (destroying the parent object recursively destroys all of its 
 * children).
 */
    NhlDestroy(con1);
    NhlClose();
    exit (0);
}
Beispiel #20
0
int main ()
{
    int appid,nwks,xwks,xcon,field1,rlist;

    int data1[5][5] = { {3,4,4,5,5},
                        {2,3,5,5,4},
                        {2,4,5,4,4},
                        {3,4,4,4,3},
                        {3,3,3,3,3} };
    ng_size_t dims[2] = { 5, 5 };
/*
 * ##########
 * # STEP 1 #
 * ##########
 * Initialize the graphics libraries and create a resource list that
 * is normally used to assign name/value pairs within objects.  Then
 * clear (empty) this list, and create an application object.  This
 * object manages multiple resource databases used by separate objects.
 */
    NhlInitialize();
    rlist = NhlRLCreate(NhlSETRL);
    
    NhlRLClear(rlist);
    NhlCreate(&appid,"appid",NhlappClass,NhlDEFAULT_APP,rlist);
/*
 * ##########
 * # STEP 2 #
 * ##########
 * For each type of output you must create a workstation object using create.
 *
 * The first argument, "&xwks", is a variable that identifies the object.
 * The second argument, '"xwks"', to the create call sets the name of the 
 * object being created. The third argument, "NhlcairoWindowWorkstationClass", or 
 * "NhlncgmWorkstationClass" identifies the type or class of the object 
 * to create. In this case an X workstation or an NCGM workstation.
 * The fourth argument, "NhlDEFAULT_APP", specifies the id of the object's 
 * parent.  In this case, the object has no parent, so the constant 
 * "NhlDEFAULT_APP" is used.  The fifth argument, "rlist", is the resource 
 * list modifiers to be used when creating the object.
 */
    NhlRLClear(rlist);
    NhlCreate(&xwks,"xwks",NhlcairoWindowWorkstationClass,NhlDEFAULT_APP,rlist);
/*
 * The resource, wkMetaName, lets you specify the name of the output NCGM
 * file.  In this example, it is called basic04c.ncgm.  If omitted, the 
 * default name, gmeta,  will be used.
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,"wkMetaName","basic04c.ncgm");
    NhlCreate(&nwks,"nwks",NhlncgmWorkstationClass,NhlDEFAULT_APP,
              rlist);
/*
 * Create a scalar field object that will be used as a data set for a
 * contour object.  The sfDataArray resource is used to assign a data
 * array to a scalar field data object.
 */
    NhlRLClear(rlist);
    NhlRLSetMDIntegerArray(rlist,"sfDataArray",&data1[0][0],2,dims);
    NhlCreate(&field1,"field1",NhlscalarFieldClass,
              NhlDEFAULT_APP,rlist);
/*
 * ##########
 * # STEP 3 #
 * ##########
 * Create the object you want to draw.
 *
 * Create a contour object and
 * assign data using the cnScalarFieldData resource.
 */
    NhlRLClear(rlist);
    NhlRLSetInteger(rlist,"cnScalarFieldData",field1);
    NhlCreate(&xcon,"xcon",NhlcontourPlotClass,xwks,rlist);
/*
 * ##########
 * # STEP 4 #
 * ##########
 * Draw the object
 */
    NhlDraw(xwks);
/*
 * ##########
 * # STEP 5 #
 * ##########
 * Call frame to update and clear the workstations
 */
    NhlFrame(xwks);
/*
 * ##########
 * # STEP 6 #
 * ##########
 * Change workstations
 */
    NhlChangeWorkstation(xcon,nwks);
/*
 * ##########
 * # STEP 7 #
 * ##########
 * Draw the object
 */
    NhlDraw(nwks);
/*
 * ##########
 * # STEP 8 #
 * ##########
 * Call frame to update and clear the workstations
 */
    NhlFrame(nwks);
/*
 * ##########
 * # STEP 6 #
 * ##########
 * Clean up memory.
 */
    NhlDestroy(xwks);
    NhlDestroy(nwks);

    NhlClose();
    exit (0);
}
Beispiel #21
0
/*
 * Main program.
 */
int main()
{

    int appid,rlist;
    int xwork_id,text_id,box_id,data_id;
    int dataspec;
    int i;

    char text[6];

    float xdra[] = {0.0, 0.1, 0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0};
    float ydra[] = {0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0, 0.1, 0.5};
    float xpos,ypos;

/*
 * Define a simple color map (index 0 defines the background color).
 */
    float cmap[4][3] = { { 1.0, 1.0, 1.0 },
                 { 0.0, 0.0, 1.0 },
                 { 0.0, 1.0, 0.0 },
                 { 1.0, 0.0, 0.0 } };
    ng_size_t dims[] = {4,3};
/*
 * Set the display. Default is to display output to an X workstation.
 */
    char const *wks_type = "x11";

/*
 * Initialize the high level utility library and create application.
 */
    NhlInitialize();

        rlist = NhlRLCreate(NhlSETRL);
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNappUsrDir,"./");
        NhlCreate(&appid,"basic06",NhlappClass,NhlDEFAULT_APP,rlist);


    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
    /*
     * Create a meta file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./basic06c.ncgm");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlncgmWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
    /*
     * Create an X workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoWindowWorkstationClass,
                          NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
    /*
     * Create a PS file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"./basic06c.ps");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlpsWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
    /*
     * Create a PS file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"./basic06c.pdf");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",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.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoDocumentWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
    /*
     * Create a cairo PNG workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoImageWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }

/*
 * Create data object for an XyPlot
 */
    NhlRLClear(rlist);
    NhlRLSetFloatArray(rlist,NhlNcaXArray,xdra,NhlNumber(xdra));
    NhlRLSetFloatArray(rlist,NhlNcaYArray,ydra,NhlNumber(ydra));
    NhlCreate(&data_id,"xyData",NhlcoordArraysClass,NhlDEFAULT_APP,rlist);

/*
 * Create a simple XyPlot object with no labels or borders.  The
 * parent for this object is xwork_id, hence it will be sent to
 * the workstation identified by xwork_id when the draw procedure
 * is invoked on it.
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtmXBBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmXTBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmYLBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmYRBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmXBOn,"False");
    NhlRLSetString(rlist,NhlNtmXTOn,"False");
    NhlRLSetString(rlist,NhlNtmYLOn,"False");
    NhlRLSetString(rlist,NhlNtmYROn,"False");
    NhlRLSetFloat(rlist,NhlNvpXF,0.0);
    NhlRLSetFloat(rlist,NhlNvpYF,1.0);
    NhlRLSetFloat(rlist,NhlNvpWidthF,1.0);
    NhlRLSetFloat(rlist,NhlNvpHeightF,1.0);
    NhlCreate(&box_id,"Box",NhlxyPlotClass,xwork_id,rlist);

/*
 * Create a TextItem object.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNtxPosXF,0.5);
    NhlRLSetFloat(rlist,NhlNtxPosYF,0.5);
    NhlRLSetInteger(rlist,NhlNtxFont,26);
        NhlCreate(&text_id,"Text",NhltextItemClass,xwork_id,rlist);

/*
 * Add the data identified by data_id to the XyPlot.
 */
    dataspec = NhlAddData(box_id,"xyCoordData",data_id);

/*
 * Draw three labeled boxes at different sizes and in different positions
 * and with different colors.
 */
    for(i=1;i<=3;++i)
    {
        xpos = -0.05*i*i + 0.5*i - 0.20;
        ypos = 1.0-xpos;
        sprintf(text,"%s %d","Box",i);  

    /*
     * Specify a text string and its color.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNtxString,text);
        NhlRLSetInteger(rlist,NhlNtxFontColor,4-i);
        NhlSetValues(text_id,rlist);

    /*
     * Set the XyPlot curve color.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNxyMonoLineColor,"True");
        NhlRLSetInteger(rlist,NhlNxyLineColor,i);
        NhlSetValues(dataspec,rlist);

    /*
     * Draw box and text.
     */
        draw_plot(box_id, xpos, ypos, 0.36-0.09*(i-1));
        draw_text(text_id, xpos, ypos, 0.08-0.02*(i-1));
    }

    NhlFrame(xwork_id);

    NhlDestroy(xwork_id);
        NhlClose();
    exit (0);
}
Beispiel #22
0
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);
}