NhlErrorTypes tddtri_W( void ) { int *nwid, *ntri, *itwk, imtri; ng_size_t mtri, dsizes_rtri[2]; float *rtri; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,4,NULL,NULL,NULL,NULL,NULL,DONT_CARE); rtri = (float*)NclGetArgValue(1,4,NULL,dsizes_rtri,NULL,NULL,NULL,DONT_CARE); ntri = (int*)NclGetArgValue(2,4,NULL,NULL,NULL,NULL,NULL,DONT_CARE); itwk = (int*)NclGetArgValue(3,4,NULL,NULL,NULL,NULL,NULL,DONT_CARE); mtri = dsizes_rtri[0]; if(dsizes_rtri[1] != 10) { NhlPError(NhlFATAL, NhlEUNKNOWN, "tddtri: the rightmost dimension of rtri must be 10"); return(NhlFATAL); } /* * Test dimension sizes. */ if(mtri > INT_MAX) { NhlPError(NhlFATAL,NhlEUNKNOWN,"tddtri: the leftmost dimension of rtri is greater than INT_MAX"); return(NhlFATAL); } imtri = (int) mtri; /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tddtri function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tddtri(rtri, imtri, ntri, itwk); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdlbls_W( void ) { int *nwid, *ipck; float *uvwmn, *uvwmx; NrmQuark *uvwn, *uvwi; char *cuvwn0, *cuvwi0, *cuvwn1, *cuvwi1, *cuvwn2, *cuvwi2; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwmn = (float*)NclGetArgValue(1,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwmx = (float*)NclGetArgValue(2,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwn = (NrmQuark*)NclGetArgValue(3,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwi = (NrmQuark*)NclGetArgValue(4,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ipck = (int*)NclGetArgValue(5,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); cuvwn0 = NrmQuarkToString(uvwn[0]); cuvwi0 = NrmQuarkToString(uvwi[0]); cuvwn1 = NrmQuarkToString(uvwn[1]); cuvwi1 = NrmQuarkToString(uvwi[1]); cuvwn2 = NrmQuarkToString(uvwn[2]); cuvwi2 = NrmQuarkToString(uvwi[2]); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdlbls function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdlbls(uvwmn[0], uvwmn[1], uvwmn[2], uvwmx[0], uvwmx[1], uvwmx[2], cuvwn0, cuvwn1, cuvwn2, cuvwi0, cuvwi1, cuvwi2, *ipck); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdlbla_W( void ) { int *nwid, *iaxs; float *xat, *yat, *angd; NrmQuark *ilbl, *nlbl; char *cilbl, *cnlbl; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); iaxs = (int*)NclGetArgValue(1,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ilbl = (NrmQuark*)NclGetArgValue(2,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); nlbl = (NrmQuark*)NclGetArgValue(3,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); xat = (float*)NclGetArgValue(4,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); yat = (float*)NclGetArgValue(5,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); angd = (float*)NclGetArgValue(6,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); cilbl = NrmQuarkToString(*ilbl); cnlbl = NrmQuarkToString(*nlbl); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdlbla function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdlbla(*iaxs, cilbl, cnlbl, xat[0], xat[1], yat[0], yat[1], *angd); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdplch_W( void ) { int *nwid; float *xpos, *ypos, *size, *angd, *cntr; NrmQuark *chrs; char *cchrs; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); xpos = (float*)NclGetArgValue(1,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ypos = (float*)NclGetArgValue(2,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); chrs = (NrmQuark*)NclGetArgValue(3,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); size = (float*)NclGetArgValue(4,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); angd = (float*)NclGetArgValue(5,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); cntr = (float*)NclGetArgValue(6,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); cchrs = NrmQuarkToString(*chrs); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdplch function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdplch(*xpos, *ypos, cchrs, *size, *angd, *cntr); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdgrid_W( void ) { int *nwid, *noxs, *noys, *igrd; float *xbeg, *xstp, *ybeg, *ystp; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); xbeg = (float*)NclGetArgValue(1,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); xstp = (float*)NclGetArgValue(2,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); noxs = (int*)NclGetArgValue(3,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ybeg = (float*)NclGetArgValue(4,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ystp = (float*)NclGetArgValue(5,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); noys = (int*)NclGetArgValue(6,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); igrd = (int*)NclGetArgValue(7,8,NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdgrid function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdgrid(*xbeg, *xstp, *noxs, *ybeg, *ystp, *noys, *igrd); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdclrs_W( void ) { /* * Definte a variable to store the HLU object identifier. */ NclHLUObj tmp_hlu_obj; int *nwid, *ibow, *iofc, *iolc, *ilmt; float *shde, *shdr; int gkswid, grlist, nid; /* * Retrieve parameters. * * Note any of the pointer parameters can be set to NULL, which * implies you don't care about its value. In this example * the type parameter is set to NULL because the function * is later registered to only accept floating point numbers. */ nwid = (int*)NclGetArgValue(0,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ibow = (int*)NclGetArgValue(1,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); shde = (float*)NclGetArgValue(2,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); shdr = (float*)NclGetArgValue(3,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); iofc = (int*)NclGetArgValue(4,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); iolc = (int*)NclGetArgValue(5,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ilmt = (int*)NclGetArgValue(6,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist,NhlNwkGksWorkId,&gkswid); NhlGetValues(nid,grlist); gactivate_ws (gkswid); c_tdclrs(gkswid, *ibow, *shde, *shdr, *iofc, *iolc, *ilmt); gdeactivate_ws (gkswid); return(NhlNOERROR); }
NhlErrorTypes tdgrds_W( void ) { int *nwid, *igrt, *ihid; float *uvwmin, *uvwmax, *uvwstp; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwmin = (float*)NclGetArgValue(1,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwmax = (float*)NclGetArgValue(2,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); uvwstp = (float*)NclGetArgValue(3,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); igrt = (int*)NclGetArgValue(4,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ihid = (int*)NclGetArgValue(5,6,NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdgrds function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdgrds(uvwmin[0], uvwmin[1], uvwmin[2], uvwmax[0], uvwmax[1], uvwmax[2], uvwstp[0], uvwstp[1], uvwstp[2], *igrt, *ihid); gdeactivate_ws (gkswid); return(NhlNOERROR); }
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); }
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); }
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); }
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); }
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); }
NhlErrorTypes ctwrap_W( void ) { int *wks; float *lat, *lon, *data; ng_size_t nlat, nlon, nlon8, dsizes_lat[2], dsizes_lon[2], dsizes_data[2]; int inlat, inlon, idim, jdim; logical *opt; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nwks; NclHLUObj tmp_hlu_obj; /* * Work arrays. */ float *rpnt, *rwrk, *xcra, *ycra; int *iedg, *itri, *ippp, *ippe, *iwrk, *icra, *iama, *iaai, *iagi; int mpnt, medg, mtri, mnop, mnoe, mnot, lrwk, liwk, lama, ncra, ngps; int icam, ican, lopn, loen, lotn; /* * Variables for retrieving attributes from "opt". */ logical idbg = False, igrd = False, imsh = False; logical icon = True, icol = False, icap = False; NrmQuark *MapProjection, *fnam; char *cMapProjection, *cnam = NULL; int imap = 2, ilev = -1, itim = -1; NclAttList *attr_list; NclAtt attr_obj; NclStackEntry stack_entry; /* * Retrieve parameters. */ wks = (int*)NclGetArgValue(0,5, NULL, NULL,NULL,NULL,NULL,DONT_CARE); lat = (float*)NclGetArgValue(1,5, NULL, dsizes_lat, NULL,NULL,NULL,DONT_CARE); lon = (float*)NclGetArgValue(2,5, NULL, dsizes_lon, NULL,NULL,NULL,DONT_CARE); data = (float*)NclGetArgValue(3,5, NULL, dsizes_data, NULL,NULL,NULL,DONT_CARE); opt = (logical*)NclGetArgValue(4,5, NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Check input sizes. */ nlat = dsizes_lat[0]; nlon = dsizes_lat[1]; if( dsizes_lon[0] != nlat || dsizes_lon[1] != nlon || dsizes_data[0] != nlat || dsizes_data[1] != nlon ) { NhlPError(NhlFATAL,NhlEUNKNOWN,"ctwrap: the dimension sizes of the lat/lon arrays and the data must be same"); return(NhlFATAL); } /* * Hopefully the number of longitudes is divisible by 8 (the nature of the * SEAM grid), so get that number here. */ nlon8 = nlon/8; if ((nlat > INT_MAX) || (nlon > INT_MAX) || (nlon8 > INT_MAX)) { NhlPError(NhlFATAL,NhlEUNKNOWN,"ctwrap: one or more input dimension sizes is > INT_MAX"); return(NhlFATAL); } inlat = (int) nlat; inlon = (int) nlon; idim = jdim = (int) nlon8; /* * Determine the NCL identifier for the graphic object. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*wks); nwks = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist,NhlNwkGksWorkId,&gkswid); NhlGetValues(nwks,grlist); /* * Activate workstation. */ gactivate_ws (gkswid); /* * Create work arrays, lots of them. */ lopn = 5; loen = 5; lotn = 4; mnop = 7352; mnoe = 22050; mnot = 14700; lrwk = 10000; liwk = 1000; lama = 400000; ncra = lama/10; icam = 512; /* could be 1024? */ ican = 512; /* could be 1024? */ ngps = 2; mpnt = mnop*lopn; /* space for points */ medg = mnoe*loen; /* space for edges */ mtri = mnot*lotn; /* space for triangles */ rpnt = (float *)calloc(mpnt,sizeof(float)); rwrk = (float *)calloc(lrwk,sizeof(float)); xcra = (float *)calloc(ncra,sizeof(float)); ycra = (float *)calloc(ncra,sizeof(float)); iwrk = (int *)calloc(liwk,sizeof(int)); iama = (int *)calloc(lama,sizeof(int)); iaai = (int *)calloc(ngps,sizeof(int)); iagi = (int *)calloc(ngps,sizeof(int)); icra = (int *)calloc(icam*ican,sizeof(int)); iedg = (int *)calloc(medg,sizeof(int)); itri = (int *)calloc(mtri,sizeof(int)); ippp = (int *)calloc(2*mnop,sizeof(int)); ippe = (int *)calloc(2*mnoe,sizeof(int)); if(rpnt == NULL || rwrk == NULL || xcra == NULL || ycra == NULL || iwrk == NULL || iama == NULL || iaai == NULL || iagi == NULL || icra == NULL || iedg == NULL || itri == NULL || ippp == NULL || ippe == NULL) { NhlPError(NhlFATAL,NhlEUNKNOWN,"ctwrap: Unable to allocate memory for work arrays"); return(NhlFATAL); } /* * If "opt" is True, then check if any attributes have been set. */ if(*opt) { stack_entry = _NclGetArg(4, 5, DONT_CARE); switch (stack_entry.kind) { case NclStk_VAR: if (stack_entry.u.data_var->var.att_id != -1) { attr_obj = (NclAtt) _NclGetObj(stack_entry.u.data_var->var.att_id); if (attr_obj == NULL) { break; } } else { /* * att_id == -1 ==> no optional args given. */ break; } /* * Get optional arguments. */ if (attr_obj->att.n_atts <= 0) { break; } /* * Get list of attributes. */ attr_list = attr_obj->att.att_list; /* * Loop through attributes and check them. The current ones recognized are: * * "RectangularMesh" * "TriangularMesh" * "LineContours" * "FilledContours" * "CellArray" * "MapProjection" * "FieldName" * "TimeStep" * "Level" * "Debug" */ while (attr_list != NULL) { /* * Check for "RectangularGrid". */ if (!strcmp(attr_list->attname, "RectangularGrid")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'RectangularGrid' attribute must be a logical, defaulting to False."); } else { igrd = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "TriangularMesh". */ if (!strcmp(attr_list->attname, "TriangularMesh")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'TriangularMesh' attribute must be a logical, defaulting to False."); } else { imsh = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "LineContours". */ if (!strcmp(attr_list->attname, "LineContours")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'LineContours' attribute must be a logical, defaulting to True."); } else { icon = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "FilledContours". */ if (!strcmp(attr_list->attname, "FilledContours")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'FilledContours' attribute must be a logical, defaulting to False."); } else { icol = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "CellArray". */ if (!strcmp(attr_list->attname, "CellArray")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'CellArray' attribute must be a logical, defaulting to False."); } else { icap = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "FieldName". */ if (!strcmp(attr_list->attname, "FieldName")) { if(attr_list->attvalue->multidval.data_type != NCL_string) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'FieldName' attribute must be a string, ignoring..."); } else { fnam = (NrmQuark *) attr_list->attvalue->multidval.val; cnam = NrmQuarkToString(*fnam); } } /* * Check for "TimeStep". */ if (!strcmp(attr_list->attname, "TimeStep")) { if(attr_list->attvalue->multidval.data_type != NCL_int) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'TimeStep' attribute must be an integer, defaulting to -1."); } else { itim = *(int*) attr_list->attvalue->multidval.val; } } /* * Check for "Level". */ if (!strcmp(attr_list->attname, "Level")) { if(attr_list->attvalue->multidval.data_type != NCL_int) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'Level' attribute must be an integer, defaulting to -1."); } else { ilev = *(int*) attr_list->attvalue->multidval.val; } } /* * Check for "Debug". */ if (!strcmp(attr_list->attname, "Debug")) { if(attr_list->attvalue->multidval.data_type != NCL_logical) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'Debug' attribute must be a logical, defaulting to False."); } else { idbg = *(logical*) attr_list->attvalue->multidval.val; } } /* * Check for "MapProjection". */ if (!strcmp(attr_list->attname, "MapProjection")) { if(attr_list->attvalue->multidval.data_type != NCL_string) { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: The 'MapProjection' attribute must be a string, defaulting to 'CylindricalEquidistant.'"); } else { MapProjection = (NrmQuark *) attr_list->attvalue->multidval.val; cMapProjection = NrmQuarkToString(*MapProjection); if(!strcmp(cMapProjection,"Orthographic")) { imap = 1; } else if(!strcmp(cMapProjection,"CylindricalEquidistant")) { imap = 2; } else if(!strcmp(cMapProjection,"Robinson")) { imap = 3; } else if(!strcmp(cMapProjection,"LambertEqualArea")) { imap = 4; } else { NhlPError(NhlWARNING,NhlEUNKNOWN,"ctwrap: Unrecognized value for the 'MapProjection' attribute. Defaulting to 'CylindricalEquidistant'."); imap = 2; } } } attr_list = attr_list->next; } default: break; } } if(cnam == NULL) { cnam = (char*)calloc(2,sizeof(char)); strcpy(cnam,""); } NGCALLF(ctdriver,CTDRIVER)(&gkswid,lat,lon,data,&inlat,&inlon,&idim,&jdim, rpnt,&mpnt,rwrk,&lrwk,xcra,ycra,&ncra,iwrk, &liwk,iama,&lama,iaai,iagi,&ngps,icra,&icam, &ican,iedg,&medg,itri,&mtri,ippp,&mnop,ippe, &mnoe,&lopn,&loen,&lotn,&igrd,&imsh,&icon,&icol, &icap,&imap,cnam,&itim,&ilev,&idbg, strlen(cnam)); /* * Free work arrays. */ NclFree(rpnt); NclFree(rwrk); NclFree(xcra); NclFree(ycra); NclFree(iwrk); NclFree(iama); NclFree(iaai); NclFree(iagi); NclFree(icra); NclFree(iedg); NclFree(itri); NclFree(ippp); NclFree(ippe); /* * Deactivate workstation. */ gdeactivate_ws (gkswid); return(NhlNOERROR); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
int guiNhlRLCreate(NhlRLType type) { return (NhlRLCreate(type)); }
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); }
NhlErrorTypes tdez3d_W( void ) { float *x, *y, *z, *u, *value, *up; ng_size_t nx, dsizes_x[NCL_MAX_DIMENSIONS]; ng_size_t ny, dsizes_y[NCL_MAX_DIMENSIONS]; ng_size_t nz, dsizes_z[NCL_MAX_DIMENSIONS]; ng_size_t dsizes_u[NCL_MAX_DIMENSIONS]; float *rmult, *theta, *phi; int *nwid, *style; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; ng_size_t i, j, k, inx, iny, inz; /* * Retrieve parameters. * * Note any of the pointer parameters can be set to NULL, which * implies you don't care about its value. In this example * the type parameter is set to NULL because the function * is later registered to only accept floating point numbers. */ nwid = (int*)NclGetArgValue(0,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); x = (float*)NclGetArgValue(1,10, NULL, dsizes_x, NULL,NULL,NULL,DONT_CARE); y = (float*)NclGetArgValue(2,10, NULL, dsizes_y, NULL,NULL,NULL,DONT_CARE); z = (float*)NclGetArgValue(3,10, NULL, dsizes_z, NULL,NULL,NULL,DONT_CARE); u = (float*)NclGetArgValue(4,10, NULL, dsizes_u, NULL,NULL,NULL,DONT_CARE); value = (float*)NclGetArgValue(5,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); rmult = (float*)NclGetArgValue(6,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); theta = (float*)NclGetArgValue(7,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); phi = (float*)NclGetArgValue(8,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); style = (int*)NclGetArgValue(9,10,NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Test dimension sizes. */ nx = dsizes_x[0]; ny = dsizes_y[0]; nz = dsizes_z[0]; if((nx > INT_MAX) || (ny > INT_MAX) || (nz > INT_MAX)) { NhlPError(NhlFATAL,NhlEUNKNOWN,"tdez3d: the length of x, y and/or z is greater than INT_MAX"); return(NhlFATAL); } inx = (int) nx; iny = (int) ny; inz = (int) nz; /* * Check input sizes. */ if( (dsizes_u[0] == nx) && (dsizes_u[1] == ny) && (dsizes_u[2] == nz) ) { /* * Reverse the order of the dimensions. */ up = (float *) calloc(nx*ny*nz,sizeof(float)); for (i = 0; i < nx; i++) { for (j = 0; j < ny; j++) { for (k = 0; k < nz; k++) { up[nx*ny*k + j*nx + i] = u[i*nz*ny + nz*j + k]; } } } /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist,NhlNwkGksWorkId,&gkswid); NhlGetValues(nid,grlist); /* * The following section activates the workstation, calls the * c_tdez3d function, and then deactivates the workstation. */ gactivate_ws (gkswid); c_tdez3d(nx,ny,nz,x,y,z,up,*value, *rmult,*theta,*phi,*style); gdeactivate_ws (gkswid); free(up); } else { NhlPError(NhlFATAL,NhlEUNKNOWN,"tdez3d: the dimension sizes of u must be the dimension of x by the dimension of y by the dimension of z"); return(NhlFATAL); } return(NhlNOERROR); }
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); }
NhlErrorTypes tdez1d_W( void ) { int *nwid, *imrk, *style; float *x, *y, *z, *rmrk, *smrk, *rmult, *theta, *phi; ng_size_t dsizes_x[1]; ng_size_t dsizes_y[1]; ng_size_t dsizes_z[1]; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid, x0; NclHLUObj tmp_hlu_obj; /* * Retrieve parameters. * * Note any of the pointer parameters can be set to NULL, which * implies you don't care about its value. In this example * the type parameter is set to NULL because the function * is later registered to only accept floating point numbers. */ nwid = (int*)NclGetArgValue( 0,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); x = (float*)NclGetArgValue( 1,11,NULL,dsizes_x,NULL,NULL,NULL,DONT_CARE); y = (float*)NclGetArgValue( 2,11,NULL,dsizes_y,NULL,NULL,NULL,DONT_CARE); z = (float*)NclGetArgValue( 3,11,NULL,dsizes_z,NULL,NULL,NULL,DONT_CARE); imrk = (int*)NclGetArgValue( 4,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); rmrk = (float*)NclGetArgValue( 5,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); smrk = (float*)NclGetArgValue( 6,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); rmult = (float*)NclGetArgValue( 7,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); theta = (float*)NclGetArgValue( 8,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); phi = (float*)NclGetArgValue( 9,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); style = (int*)NclGetArgValue(10,11,NULL,NULL,NULL,NULL,NULL,DONT_CARE); /* * Check the input sizes. */ if( dsizes_x[0] != dsizes_y[0] || dsizes_x[0] != dsizes_z[0] ) { NhlPError(NhlFATAL,NhlEUNKNOWN,"tdez1d: the length of the x, y, and z arrays must be the same"); return(NhlFATAL); } if(dsizes_x[0] > INT_MAX) { NhlPError(NhlFATAL,NhlEUNKNOWN,"tdez1d: dsizes_x[0] = %ld is greater than INT_MAX", dsizes_x[0]); return(NhlFATAL); } x0 = (int) dsizes_x[0]; /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist,NhlNwkGksWorkId,&gkswid); NhlGetValues(nid,grlist); /* * The following section activates the workstation, calls the * tdez1d function, and then deactivates the workstation. */ gactivate_ws (gkswid); NGCALLF(tdez1d,TDEZ1D)(&x0,x,y,z,imrk,rmrk,smrk,rmult,theta,phi,style); gdeactivate_ws (gkswid); return(NhlNOERROR); }
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); }
NhlErrorTypes tdcurv_W( void ) { int *nwid, *iarh; float *ucrv, *vcrv, *wcrv, *arhl, *arhw; /* * Variables for retrieving workstation information. */ int grlist, gkswid, nid; NclHLUObj tmp_hlu_obj; ng_size_t ncrv; int incrv; ng_size_t dsizes_ucrv[1]; ng_size_t dsizes_vcrv[1]; ng_size_t dsizes_wcrv[1]; /* * Retrieve parameters. */ nwid = (int*)NclGetArgValue(0,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); ucrv = (float*)NclGetArgValue(1,7,NULL,dsizes_ucrv,NULL,NULL,NULL,DONT_CARE); vcrv = (float*)NclGetArgValue(2,7,NULL,dsizes_vcrv,NULL,NULL,NULL,DONT_CARE); wcrv = (float*)NclGetArgValue(3,7,NULL,dsizes_wcrv,NULL,NULL,NULL,DONT_CARE); iarh = (int*)NclGetArgValue(4,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); arhl = (float*)NclGetArgValue(5,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); arhw = (float*)NclGetArgValue(6,7,NULL,NULL,NULL,NULL,NULL,DONT_CARE); if(dsizes_ucrv[0] != dsizes_vcrv[0] || dsizes_ucrv[0] != dsizes_wcrv[0]) { NhlPError(NhlFATAL, NhlEUNKNOWN, "tdcurv: ucurv, vcurv, and wcurv must be the same length"); return(NhlFATAL); } ncrv = dsizes_ucrv[0]; /* * Test dimension sizes. */ if(ncrv > INT_MAX) { NhlPError(NhlFATAL,NhlEUNKNOWN,"tdcurv: the length of the input arrays are > INT_MAX"); return(NhlFATAL); } incrv = (int) ncrv; /* * Determine the NCL identifier for the graphic object in nid. */ tmp_hlu_obj = (NclHLUObj) _NclGetObj(*nwid); nid = tmp_hlu_obj->hlu.hlu_id; /* * Retrieve the GKS workstation id from the workstation object. */ grlist = NhlRLCreate(NhlGETRL); NhlRLClear(grlist); NhlRLGetInteger(grlist, NhlNwkGksWorkId, &gkswid); NhlGetValues(nid, grlist); /* * The following section activates the workstation, calls the * c_tdcurv function, and then deactivates the workstation. */ gactivate_ws (gkswid); NGCALLF(tdcurv,TDCURV)(ucrv, vcrv, wcrv, &incrv, iarh, arhl, arhw); gdeactivate_ws (gkswid); return(NhlNOERROR); }
/* * 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); }
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); }