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); }
/* * 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() { 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 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); }
void guiNhlRLSetFloatArray(int id, char *resname, float *data, int num_elements) { ng_size_t ndims = (ng_size_t) num_elements; NhlRLSetFloatArray(id, (NhlString) resname, data, ndims); }
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() { /* * 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); }
int main() { int appid, wid, pid; int rlist; char const *wks_type = "x11"; /* * Initialize the high level utility library */ NhlInitialize(); /* * Create an application context. Set the app dir to the current * directory so the application looks for a resource file in the * working directory. In this example the resource file supplies the * plot title only. */ rlist = NhlRLCreate(NhlSETRL); NhlRLClear(rlist); NhlRLSetString(rlist,NhlNappUsrDir,"./"); NhlRLSetString(rlist,NhlNappDefaultParent,"True"); NhlCreate(&appid,"tm03",NhlappClass,NhlDEFAULT_APP,rlist); if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) { /* * Create a meta file workstation object. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkMetaName,"./tm03c.ncgm"); NhlCreate(&wid,"tm03Work",NhlncgmWorkstationClass, NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) { /* * Create an X11 workstation. */ NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNwkPause,True); NhlCreate(&wid,"tm03Work",NhlcairoWindowWorkstationClass, NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) { /* * Create an older-style PostScript workstation. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkPSFileName,"./tm03c.ps"); NhlCreate(&wid,"tm03Work",NhlpsWorkstationClass, NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) { /* * Create an older-style PDF workstation. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkPDFFileName,"./tm03c.pdf"); NhlCreate(&wid,"tm03Work",NhlpdfWorkstationClass, NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") || !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) { /* * Create a cairo PS/PDF workstation. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkFileName,"./tm03c"); NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type); NhlCreate(&wid,"tm03Work",NhlcairoDocumentWorkstationClass, NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) { /* * Create a cairo PNG workstation. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkFileName,"./tm03c"); NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type); NhlCreate(&wid,"tm03Work",NhlcairoImageWorkstationClass, NhlDEFAULT_APP,rlist); } NhlRLClear(rlist); NhlRLSetFloat(rlist,NhlNvpXF,.2); NhlRLSetFloat(rlist,NhlNvpYF,.8); NhlRLSetFloat(rlist,NhlNvpWidthF,.6); NhlRLSetFloat(rlist,NhlNvpHeightF,.6); NhlRLSetFloat(rlist,NhlNtmYLDataTopF,100.0); NhlRLSetFloat(rlist,NhlNtmYLDataBottomF,1000.0); NhlRLSetFloat(rlist,NhlNtmXBDataRightF,90.0); NhlRLSetFloat(rlist,NhlNtmXBDataLeftF,-90.0); NhlRLSetInteger(rlist,NhlNtmYLStyle,NhlIRREGULAR); NhlRLSetInteger(rlist,NhlNtmXBMode,NhlEXPLICIT); NhlRLSetInteger(rlist,NhlNtmXBMinorOn,False); NhlRLSetFloatArray(rlist, NhlNtmXBValues,labellocs,NhlNumber(labellocs)); /* * Array 'level' contains original grid point data locations in Y * direction. Providing the grid points to the TickMark object as the * control points for the IRREGULAR style transformation, means that * these points will be evenly spaced along the Y axis. Since this is * how CONPACK thinks the points are spaced, the tick marks will * correctly correspond with the data coordinates. See the HLU User's * Guide for a complete discussion of IRREGULAR style transformations. */ NhlRLSetStringArray(rlist, NhlNtmXBLabels,labels,NhlNumber(labels)); NhlRLSetFloatArray(rlist, NhlNtmYLIrregularPoints,level,NhlNumber(level)); NhlCreate(&pid,"TickMarks",NhltickMarkClass,wid,rlist); NhlDraw(pid); NhlFrame(wid); NhlDestroy(pid); NhlDestroy(wid); NhlDestroy(appid); NhlClose(); exit(0); }
int main () { char const *wks_type = "x11"; int i=0, rlist, wks, appid, field1, field2, field3, xy1, xy2, xy3; int grlist, datadepid[1]; int *dspec = datadepid; ng_size_t num_dspec; /* * Create variables to contain data. */ FILE *x1_y3; float y [ncurve][npts], lon [npts], u [npts], v [npts], t [npts]; float y1val [5] = {-90.0 , -80.0, -70.0, -60.0, -50.0}; float y2val [6] = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0}; float y3val [5] = {-20.0, -10.0, 0.0, 10.0, 20.0}; char *y1lab [5] = {"-90.", "-80.", "-70.", "-60.", "-50."}; char *y2lab [6] = {"10.", "20.", "30.", "40.", "50.", "60."}; char *y3lab [5] = {"-20.", "-10.", "0.", "10.", "20."}; char *file = "xy.asc"; /* * Read ASCII file xy.asc */ x1_y3 = fopen (file,"r"); /* * xy.asc has 4 vars of length 129 longitudes, lon, u, v, t * * The data is taken at 43N latitude. Longitude is an index * 1-129 standing for 0 deg - 360 deg in steps of 360/128? * u and v are in m/s, and t is in deg K. */ while (!feof(x1_y3)) { fscanf (x1_y3, "%f %f %f %f", &lon[i], &u[i], &v[i], &t[i]); i++; } for (i=0; i < npts; i++) { lon [i] = (lon[i]- 1.0) * 360.0/128.0; t [i] = (t[i] - 273.15) * 9 / 5 + 32.0 ; y [0][i] = u[i]; y [1][i] = v[i]; y [2][i] = (t[i] - 273.15) * 9.0 / 5.0 + 32.0; } NhlInitialize (); rlist = NhlRLCreate (NhlSETRL); /* * Create Application object. The Application object name is used to * determine the name of the resource file, which is "xy17.res" in this * case. */ NhlRLClear (rlist); NhlRLSetInteger (rlist, NhlNappDefaultParent, True); NhlRLSetString (rlist, NhlNappUsrDir, "./"); NhlCreate (&appid, "xy17", NhlappClass, 0, rlist); /* * If NCGM=1, then open NCGM workstation. */ if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) { NhlRLClear (rlist); NhlRLSetString (rlist, NhlNwkMetaName, "xy17c.ncgm"); NhlCreate (&wks, "xy17Work", NhlncgmWorkstationClass, 0, rlist); } else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) { /* * Create an X workstation. */ NhlRLClear (rlist); NhlRLSetInteger (rlist, NhlNwkPause, True); NhlCreate (&wks, "xy17Work", NhlcairoWindowWorkstationClass, 0, rlist); } else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) { /* * Open PS workstation. */ NhlRLClear (rlist); NhlRLSetString (rlist, NhlNwkPSFileName, "xy17c.ps"); NhlCreate (&wks, "xy17Work", NhlpsWorkstationClass, 0, rlist); } else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) { /* * Open PDF workstation. */ NhlRLClear (rlist); NhlRLSetString (rlist, NhlNwkPDFFileName, "xy17c.pdf"); NhlCreate (&wks, "xy17Work", NhlpdfWorkstationClass, 0, rlist); } else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") || !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) { /* * Open cairo PS/PDF workstation. */ NhlRLClear (rlist); NhlRLSetString (rlist, NhlNwkFileName, "xy17c"); NhlRLSetString (rlist, NhlNwkFormat, (char*)wks_type); NhlCreate (&wks, "xy17Work", NhlcairoDocumentWorkstationClass, 0, rlist); } else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) { /* * Open cairo PNG workstation. */ NhlRLClear (rlist); NhlRLSetString (rlist, NhlNwkFileName, "xy17c"); NhlRLSetString (rlist, NhlNwkFormat, (char*)wks_type); NhlCreate (&wks, "xy17Work", NhlcairoImageWorkstationClass, 0, rlist); } /* * Create a coordarrays data object and configure its extents missing * values and at the same time convert it from Degrees K to Degrees F */ NhlRLClear (rlist); NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129); NhlRLSetFloatArray (rlist, NhlNcaYArray, t, 129); NhlCreate (&field1, "field1", NhlcoordArraysClass, appid, rlist); /* * Create a coordarrays data object and configure its extents missing * values and at the same time convert it from Degrees K to Degrees F */ NhlRLClear (rlist); NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129); NhlRLSetFloatArray (rlist, NhlNcaYArray, u, 129); NhlCreate (&field2, "field2", NhlcoordArraysClass, appid, rlist); /* * Create a coordarrays data object and configure its extents missing * values and at the same time convert it from Degrees K to Degrees F */ NhlRLClear (rlist); NhlRLSetFloatArray (rlist, NhlNcaXArray, lon, 129); NhlRLSetFloatArray (rlist, NhlNcaYArray, v, 129); NhlCreate (&field3, "field3", NhlcoordArraysClass, appid, rlist); /* * Create XyPlot object for curve 1 and assign data to it */ NhlRLClear (rlist); NhlRLSetFloat (rlist, NhlNvpXF, 0.20); NhlRLSetFloat (rlist, NhlNvpYF, 0.80); NhlRLSetFloat (rlist, NhlNvpWidthF, 0.6); NhlRLSetFloat (rlist, NhlNvpHeightF, 0.2); NhlRLSetInteger (rlist, NhlNxyCoordData, field1); NhlRLSetString (rlist, NhlNtrYReverse, "False"); NhlRLSetFloat (rlist, NhlNtrYMaxF, -50.0); NhlRLSetFloat (rlist, NhlNtrYMinF, -90.0); NhlRLSetFloat (rlist, NhlNtrXMaxF, 360.0); NhlRLSetFloat (rlist, NhlNtrXMinF, 0.0); NhlRLSetString (rlist, NhlNtmYROn, "False"); NhlRLSetString (rlist, NhlNtmYUseLeft, "False"); NhlRLSetString (rlist, NhlNtmXMajorGrid, "True"); NhlRLSetString (rlist, NhlNtmXBLabelsOn, "False"); NhlRLSetString (rlist, NhlNtmYLLabelsOn, "True"); NhlRLSetFloat (rlist, NhlNtmYLMajorLengthF, 0.01); NhlRLSetFloat (rlist, NhlNtmYLMajorOutwardLengthF, 0.0); NhlRLSetString (rlist, NhlNtmYLMode, "Explicit"); NhlRLSetFloatArray (rlist, NhlNtmYLValues, y1val, 5); NhlRLSetStringArray (rlist, NhlNtmYLLabels, y1lab, 5); NhlRLSetString (rlist, NhlNtmYLLabelsOn, "True"); NhlRLSetString (rlist, NhlNtmYLLabelFontColor,"red"); NhlRLSetString (rlist, NhlNtiMainString, "Temperature, U, V Stacked Plots"); NhlRLSetString (rlist, NhlNtiYAxisString, "Temp (Deg C)"); NhlRLSetFloat (rlist, NhlNtiXAxisFontHeightF, 0.02); NhlRLSetFloat (rlist, NhlNtiYAxisFontHeightF, 0.02); NhlRLSetString (rlist, NhlNtiXAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFontColor,"red"); NhlRLSetString (rlist, NhlNtmYRMinorOn, "False"); NhlRLSetString (rlist, NhlNtmYLMinorOn, "False"); NhlCreate(&xy1, "xy1", NhlxyPlotClass, wks, rlist); /* * Create XyPlot object for curve 2 and assign data to it */ NhlRLClear (rlist); NhlRLSetFloat (rlist, NhlNvpXF, 0.20); NhlRLSetFloat (rlist, NhlNvpYF, 0.60); NhlRLSetFloat (rlist, NhlNvpWidthF, 0.6); NhlRLSetFloat (rlist, NhlNvpHeightF, 0.2); NhlRLSetInteger (rlist, NhlNxyCoordData, field2); NhlRLSetString (rlist, NhlNtrYReverse, "False"); NhlRLSetFloat (rlist, NhlNtrYMaxF, 60.0); NhlRLSetFloat (rlist, NhlNtrYMinF, 10.0); NhlRLSetFloat (rlist, NhlNtrXMaxF, 360.0); NhlRLSetFloat (rlist, NhlNtrXMinF, 0.0); NhlRLSetString (rlist, NhlNtmYROn, "True"); NhlRLSetString (rlist, NhlNtmYLOn, "False"); NhlRLSetString (rlist, NhlNtmYUseLeft, "False"); NhlRLSetString (rlist, NhlNtmXMajorGrid, "True"); NhlRLSetString (rlist, NhlNtmYLLabelsOn, "False"); NhlRLSetString (rlist, NhlNtmYRLabelsOn, "True"); NhlRLSetString (rlist, NhlNtmYRMode, "Explicit"); NhlRLSetFloatArray (rlist, NhlNtmYRValues, y2val, 6); NhlRLSetStringArray (rlist, NhlNtmYRLabels, y2lab, 6); NhlRLSetString (rlist, NhlNtmXBLabelsOn, "False"); NhlRLSetString (rlist, NhlNtmYRLabelFontColor,"green"); NhlRLSetString (rlist, NhlNtiYAxisString, "U (m/s)"); NhlRLSetFloat (rlist, NhlNtiXAxisFontHeightF, 0.02); NhlRLSetFloat (rlist, NhlNtiYAxisFontHeightF, 0.02); NhlRLSetString (rlist, NhlNtiXAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFontColor,"green"); NhlRLSetString (rlist, NhlNtmYRMinorOn, "False"); NhlRLSetString (rlist, NhlNtmYLMinorOn, "False"); NhlCreate(&xy2, "xy2", NhlxyPlotClass, wks, rlist); /* * Create XyPlot object for curve 3 and assign data to it * * Increase the veiwport so the right scale will be about .15 NDC * right of the other grids. Plot only the right vertical axis. * .5NDC = 360 deg lon, thus .65NDC = 360+108 deg lon. */ NhlRLClear (rlist); NhlRLSetFloat (rlist, NhlNvpXF, 0.20); NhlRLSetFloat (rlist, NhlNvpYF, 0.40); NhlRLSetFloat (rlist, NhlNvpWidthF, 0.6); NhlRLSetFloat (rlist, NhlNvpHeightF, 0.2); NhlRLSetInteger (rlist, NhlNxyCoordData, field3); NhlRLSetString (rlist, NhlNtrYReverse, "False"); NhlRLSetFloat (rlist, NhlNtrYMaxF, 20.0); NhlRLSetFloat (rlist, NhlNtrYMinF, -20.0); NhlRLSetFloat (rlist, NhlNtrXMaxF, 360.0); NhlRLSetFloat (rlist, NhlNtrXMinF, 0.0); NhlRLSetString (rlist, NhlNtmYROn, "False"); NhlRLSetString (rlist, NhlNtmYUseLeft, "False"); NhlRLSetString (rlist, NhlNtmYLLabelsOn, "True"); NhlRLSetString (rlist, NhlNtmXBLabelsOn, "True"); NhlRLSetString (rlist, NhlNtmXMajorGrid, "True"); NhlRLSetFloat (rlist, NhlNtmYLMajorLengthF, 0.01); NhlRLSetFloat (rlist, NhlNtmYLMajorOutwardLengthF, 0.0); NhlRLSetString (rlist, NhlNtmYLMode, "Explicit"); NhlRLSetString (rlist, NhlNtmYLLabelsOn, "True"); NhlRLSetString (rlist, NhlNtmYLLabelFontColor,"blue"); NhlRLSetString (rlist, NhlNtiYAxisString, "V (m/s)"); NhlRLSetString (rlist, NhlNtiXAxisString, "Longitude (Degs)"); NhlRLSetFloat (rlist, NhlNtiXAxisFontHeightF, 0.02); NhlRLSetFloat (rlist, NhlNtiYAxisFontHeightF, 0.02); NhlRLSetString (rlist, NhlNtiXAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFont, "helvetica-bold"); NhlRLSetString (rlist, NhlNtiYAxisFontColor,"blue"); NhlRLSetString (rlist, NhlNtmYRMinorOn, "False"); NhlRLSetString (rlist, NhlNtmYLMinorOn, "False"); NhlRLSetFloatArray (rlist, NhlNtmYLValues, y3val, 5); NhlRLSetStringArray (rlist, NhlNtmYLLabels, y3lab, 5); NhlCreate(&xy3, "xy3", NhlxyPlotClass, wks, rlist); grlist = NhlRLCreate (NhlGETRL); NhlRLClear (grlist); NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec); NhlGetValues(xy1, grlist); NhlRLClear (rlist); NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True); NhlRLSetString (rlist, NhlNxyLineColor,"red"); NhlSetValues (dspec[0], rlist); NhlRLClear (grlist); NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec); NhlGetValues(xy2, grlist); NhlRLClear (rlist); NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True); NhlRLSetString (rlist, NhlNxyLineColor,"green"); NhlSetValues (dspec[0], rlist); NhlRLClear (grlist); NhlRLGetIntegerArray(grlist,NhlNxyCoordDataSpec,&dspec,&num_dspec); NhlGetValues(xy3, grlist); NhlRLClear (rlist); NhlRLSetInteger (rlist, NhlNxyMonoLineColor, True); NhlRLSetString (rlist, NhlNxyLineColor,"blue"); NhlSetValues (dspec[0], rlist); NhlDraw(xy1); NhlDraw(xy2); NhlDraw(xy3); NhlFrame(wks); NhlDestroy (wks); NhlClose(); exit(0); }