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 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 argc, char *argv[]) { int appid,wid,mapid; int rlist; char const *wks_type = "x11"; /* * String arrays for specifying areas */ NhlString fill_specs[] = { "mexico","bolivia","brazil","nicaragua", "cuba","haiti","canada"}; NhlString outline_specs[] = { "argentina","paraguay","colombia", "us-colorado","us-texas", "us-kentucky" }; NhlString mask_specs[] = { "us-colorado","us-texas","us-kentucky", "bolivia","paraguay","nicaragua","oceans" }; /* * Initialize the high level utility library */ NhlInitialize(); /* * Create an application context. Set the app dir to the current directory * so the application looks for a resource file in the working directory. * The resource file sets most of the Contour resources that remain fixed * throughout the life of the Contour object. */ rlist = NhlRLCreate(NhlSETRL); NhlRLClear(rlist); NhlRLSetString(rlist,NhlNappUsrDir,"./"); NhlCreate(&appid,"mp02",NhlappClass,NhlDEFAULT_APP,rlist); if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) { /* * Create a meta file workstation */ rlist = NhlRLCreate(NhlSETRL); NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkMetaName,"./mp02c.ncgm"); NhlCreate(&wid,"mp02Work", NhlncgmWorkstationClass,NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) { /* * Create an X workstation */ NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNwkPause,True); NhlCreate(&wid,"mp02Work",NhlcairoWindowWorkstationClass,appid,rlist); } else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) { /* * Create an older-style PostScript workstation */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkPSFileName,"./mp02c.ps"); NhlCreate(&wid,"mp02Work", NhlpsWorkstationClass,NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) { /* * Create an older-style PDF workstation */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkPDFFileName,"./mp02c.pdf"); NhlCreate(&wid,"mp02Work", NhlpdfWorkstationClass,NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") || !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) { /* * Create a cairo PS/PDF workstation */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkFileName,"./mp02c"); NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type); NhlCreate(&wid,"mp02Work", NhlcairoDocumentWorkstationClass,NhlDEFAULT_APP,rlist); } else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) { /* * Create a cairo PNG workstation */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNwkFileName,"./mp02c"); NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type); NhlCreate(&wid,"mp02Work", NhlcairoImageWorkstationClass,NhlDEFAULT_APP,rlist); } /* * Create a plot focusing on North and South America; * Outlines are on by default; turn fill on. * By default the geophysical boundary set is used both for outline and * fill. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNpmTitleDisplayMode,"Always"); NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 1"); NhlRLSetString(rlist,NhlNmpFillOn,"True"); NhlRLSetString(rlist,NhlNmpProjection,"Orthographic"); NhlRLSetString(rlist,NhlNmpPerimOn,"true"); NhlRLSetFloat(rlist,NhlNmpCenterLatF,10.0); NhlRLSetFloat(rlist,NhlNmpCenterLonF,-90.0); NhlRLSetFloat(rlist,NhlNmpCenterRotF,45.0); NhlRLSetString(rlist,NhlNmpLimitMode,"LatLon"); NhlRLSetFloat(rlist,NhlNmpMinLatF,-60.0); NhlRLSetFloat(rlist,NhlNmpMaxLatF,60.0); NhlRLSetFloat(rlist,NhlNmpMinLonF,-135.0); NhlRLSetFloat(rlist,NhlNmpMaxLonF,-45.0); /* * Highlight selected countries using their "political" color. */ NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers, fill_specs,NhlNumber(fill_specs)); NhlCreate(&mapid,"Map0",NhlmapPlotClass,wid,rlist); NhlDraw(mapid); NhlFrame(wid); /* * Individually outline some other countries and some US states. */ NhlRLClear(rlist); NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 2"); NhlRLSetStringArray(rlist,NhlNmpOutlineSpecifiers, outline_specs,NhlNumber(outline_specs)); NhlSetValues(mapid,rlist); NhlDraw(mapid); NhlFrame(wid); /* * Turn off the base geophysical set for outlines and fill, leaving only * the specified areas. * Also change the specification, 'canada' to 'canada*', * in order to draw all areas belonging to Canada. * Note that another color, mpDefaultFillColor, is used for all areas * within the map projection that are otherwise not drawn, including the * oceans. If you look closely, you will see that the Canadian lakes * are not drawn in the color used in the previous frame for the ocean. * The wild card specification, 'canada*', picks up all the lakes of * Canada. Lakes are drawn using mpInlandWaterFillColor, which is, by * default, set to the same color as mpOceanFillColor. */ fill_specs[6] = "canada*"; NhlRLClear(rlist); NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 3"); NhlRLSetString(rlist,NhlNmpFillBoundarySets,"NoBoundaries"); NhlRLSetString(rlist,NhlNmpOutlineBoundarySets,"NoBoundaries"); NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers, fill_specs,NhlNumber(fill_specs)); NhlSetValues(mapid,rlist); NhlDraw(mapid); NhlFrame(wid); /* * You can also specify area groupings using certain predefined * string constants: set 'continents' on to demonstrate. * Masking an area is different from not explicitly drawing it. To enable * masking you must explicitly turn area masking and then create an area * mask specification list containing the name of each area to be masked. * There is an order of precedence for fill and masking. Explicitly * named areas take precedence over area groupings, and small areas take * precedence over enclosing larger areas. Otherwise masking takes * precedence over filling. * >>> Masking or filling individual US states causes processing time and * >>> memory requirements to increase substantially. Hopefully the * >>> performance can be improved before the release. */ fill_specs[0] = "continents"; fill_specs[1] = "us"; NhlRLClear(rlist); NhlRLSetString(rlist,NhlNtiMainString,"mp02c - Frame 4"); NhlRLSetString(rlist,NhlNmpFillBoundarySets,"NoBoundaries"); NhlRLSetStringArray(rlist,NhlNmpFillAreaSpecifiers, fill_specs,NhlNumber(fill_specs)); NhlRLSetString(rlist,NhlNmpAreaMaskingOn,"True"); NhlRLSetStringArray(rlist,NhlNmpMaskAreaSpecifiers, mask_specs,NhlNumber(mask_specs)); NhlSetValues(mapid,rlist); NhlDraw(mapid); NhlFrame(wid); /* * Destroy the objects created, close the HLU library and exit. */ NhlDestroy(mapid); NhlDestroy(wid); NhlDestroy(appid); NhlClose(); exit(0); }
void QNCLContourLine::plot(QGRIB2Message *grb2Msg, QString outputPath, QString outputFileName) { /*float xbvalues1[7] = {0.,60.,120.,180.,240.,300.,360.}; char *xblabels1[7] = {"0","60E","120E","180","120W","60W","0"}; float xbvalues2[11] = {0.,3.,6.,9.,12.,15.,18.,21.,24.,27.,30.}; float ylvalues[7] = {-90., -60.,-30.,0.,30.,60.,90.}; char *xblabels2[11] = {"0","3","6","9","12","15","18","21","24","27","30"}; char *yllabels[7] = {"90S","60S","30S","EQ","30N","60N","90N"};*/ /*rules setting*/ float xbValues[7] = {0}; char *xbLabels[7]; float ybValues[7] = {0}; char *ybLabels[7]; int xLabelCount = 0, yLabelCount = 0; double * dData; float * fData; //float cmap[255][3] = {0}; int ni, nj; int mi, mj; int xStart, xEnd; int yStart, yEnd; int appid, jan, cn, mp, tx, srlist; ng_size_t length[2]; float cmap[256][3]; //float * cmap; size_t nSize; ng_size_t icount[2]; int k = 0; int ps2;//1, ps2, png1; char setting[256]= {0}; /*x label setting*/ memset(xbLabels, 0, sizeof(xbLabels)); memset(ybLabels, 0, sizeof(ybLabels)); xLabelCount = width/100 + 1; xLabelCount = (xLabelCount < 2)?2:((xLabelCount>7)?7:xLabelCount); for (int i = 0; i < xLabelCount; i ++) { xbValues[i] = leftLongitude + (rightLongitude - leftLongitude) * i / (xLabelCount - 1); xbLabels[i] = (char *)calloc(10, 1); if ((xbValues[i] == 0) || (xbValues[i] == 180) || (xbValues[i]) == 360) sprintf(xbLabels[i], "%d", ((int)xbValues[i])%360); else if ((xbValues[i] > 0) && (xbValues[i] < 180)) { if ((xbValues[i]-(int)xbValues[i]) == 0) sprintf(xbLabels[i], "%dE", ((int)xbValues[i])%360); else sprintf(xbLabels[i], "%3.4fE", xbValues[i]); } else if ((xbValues[i] > 180) && (xbValues[i] < 360)) { if ((xbValues[i]-(int)xbValues[i]) == 0) sprintf(xbLabels[i], "%dW", (360 - (int)xbValues[i])); else sprintf(xbLabels[i], "%3.4fW", 360. - xbValues[i]); } } yLabelCount = height/100+1; yLabelCount = (yLabelCount < 2)?2:((yLabelCount>7)?7:yLabelCount); for (int i = 0; i < yLabelCount; i++) { ybValues[i] = topLatitude - (topLatitude - bottomLatitude) * i / (yLabelCount - 1); ybLabels[i] = (char *)calloc(10, 1); if (ybValues[i] == 0) sprintf(ybLabels[i], "%d", ((int)ybValues[i])%360); else if ((ybValues[i] > 0) && (ybValues[i] <= 90)) { if ((ybValues[i]-(int)ybValues[i]) == 0) sprintf(ybLabels[i], "%dN", ((int)ybValues[i])%360); else sprintf(ybLabels[i], "%3.4fN", ybValues[i]); } else if ((ybValues[i] < 0) && (ybValues[i] >= -90)) { if ((ybValues[i]-(int)ybValues[i]) == 0) sprintf(ybLabels[i], "%dW", ((int)ybValues[i])%360); else sprintf(ybLabels[i], "%3.4fW", ybValues[i]); } } /*get data from grib2 message between in the contour setting*/ grib_handle * hgrib = grb2Msg->getGRIBHandle(); QString workName; workName = outputFileName; workName = workName.left(workName.indexOf('.')); ni = grb2Msg->getGrid()->xp(); nj = grb2Msg->getGrid()->yp(); nSize = ni * nj; dData = (double *)calloc(ni*nj, sizeof(double)); grib_get_double_array(hgrib, "values", dData, &nSize); mi = ((rightLongitude - leftLongitude) * 1000000 / grb2Msg->getGrid()->dx()) + 1; mj = ((topLatitude - bottomLatitude) * 1000000 / grb2Msg->getGrid()->dy()) + 1; if (mi > ni) mi = ni; if (mj > nj) mj = nj; fData = (float *)calloc(mi * mj, sizeof(float)); xStart = (int)((leftLongitude * 1000000 - grb2Msg->getGrid()->lon1())/grb2Msg->getGrid()->dx()); if ((xStart * grb2Msg->getGrid()->dx()) > (leftLongitude * 1000000)) xStart --; if (xStart < 0) xStart = 0; xEnd = (int)((rightLongitude * 1000000 - grb2Msg->getGrid()->lon1())/grb2Msg->getGrid()->dx()) + 1; if ((xEnd * grb2Msg->getGrid()->dx()) < (rightLongitude * 1000000)) xEnd++; if (xEnd > ni) xEnd = ni; yStart = (int)((grb2Msg->getGrid()->lat1() - topLatitude * 1000000)/grb2Msg->getGrid()->dy()); if ((grb2Msg->getGrid()->lat1() - yStart * grb2Msg->getGrid()->dy()) < (topLatitude * 1000000)) yStart--; if (yStart < 0) yStart = 0; yEnd = (int)((grb2Msg->getGrid()->lat1() - bottomLatitude * 1000000)/grb2Msg->getGrid()->dy()) + 1; if ((grb2Msg->getGrid()->lat1() - yEnd * grb2Msg->getGrid()->dy()) > (bottomLatitude * 1000000)) yEnd++; if (yEnd > nj) yEnd = nj; for (int jj = yStart; jj < yEnd; jj++) { for (int ii = xStart; ii < xEnd; ii ++) { fData[k++] = dData[jj * ni + ii]; } } NhlInitialize(); srlist = NhlRLCreate(NhlSETRL); NhlRLClear(srlist); NhlRLSetString(srlist, "appDefaultParent", "True"); memset(setting, 0, sizeof(setting)); strncpy(setting, outputPath.toStdString().c_str(), sizeof(setting)-1); NhlRLSetString(srlist, "appUsrDir", setting); NhlCreate(&appid, grb2Msg->getName().toStdString().c_str(), NhlappClass, 0, srlist); NhlRLClear(srlist); QString outputpsFileName = outputPath + "/" + outputFileName; memset(setting, 0, sizeof(setting)); strncpy(setting, outputpsFileName.toStdString().c_str(), sizeof(setting)-1); NhlRLSetString(srlist, NhlNwkFileName, setting); /*NhlRLSetString(srlist, NhlNwkFormat, "ps");*/ NhlRLSetString(srlist, NhlNwkFormat, "png"); /*NhlRLSetString(srlist, NhlNwkOrientation, "landscape"); NhlRLSetString(srlist, NhlNwkOrientation, "portrait"); NhlRLSetInteger(srlist, NhlNwkDeviceLowerX, 0); NhlRLSetInteger(srlist, NhlNwkDeviceLowerY, 60); NhlRLSetInteger(srlist, NhlNwkDeviceUpperX, width); NhlRLSetInteger(srlist, NhlNwkDeviceUpperY, height); */ float fcolor[3] = {0}; float bcolor[3] = {0}; int r, g, b; foregroundColor.getRgb(&r, &g, &b); fcolor[0] = ((float)r)/255.; fcolor[1] = ((float)g)/255.; fcolor[2] = ((float)b)/255.; length[0] = 3; NhlRLSetFloatArray(srlist, NhlNwkForegroundColor, fcolor, length[0]); backgroundColor.getRgb(&r, &g, &b); bcolor[0] = ((float)r)/255.; bcolor[1] = ((float)g)/255.; bcolor[2] = ((float)b)/255.; length[0] = 3; NhlRLSetFloatArray(srlist, NhlNwkBackgroundColor, bcolor, length[0]); length[0] = loadColormap(colormap, &cmap[0][0], 256); length[1] = 3; if (length[0] > 0) { NhlRLSetMDFloatArray(srlist,NhlNwkColorMap,&cmap[0][0], 2, length); } else { memset(setting, 0, sizeof(setting)); strncpy(setting, colormap.toStdString().c_str(), sizeof(setting)-1); NhlRLSetString(srlist, NhlNwkColorMap, setting); } /*NhlCreate(&ps2, workName.toStdString().c_str(), NhlpsWorkstationClass, 0, srlist);*/ NhlCreate(&ps2, workName.toStdString().c_str(), NhlcairoImageWorkstationClass, 0, srlist); icount[1] = xEnd - xStart; icount[0] = yEnd - yStart; /**/ NhlRLClear(srlist); NhlRLSetMDFloatArray(srlist, NhlNsfDataArray, fData, 2, icount); NhlRLSetFloat(srlist, NhlNsfXCStartV, leftLongitude); NhlRLSetFloat(srlist, NhlNsfXCEndV, rightLongitude); NhlRLSetFloat(srlist, NhlNsfYCStartV, topLatitude); NhlRLSetFloat(srlist, NhlNsfYCEndV, bottomLatitude); NhlCreate(&jan, "sf", NhlscalarFieldClass, appid, srlist); //NhlRLSetString(srlist, NhlNwkOrientation, "landscape"); /*NhlRLSetString(srlist, NhlNwkOrientation, "portrait");*/ NhlRLSetString(srlist, NhlNcnLineDrawOrder, "predraw"); /** Create a ContourPlot object.*/ NhlRLClear(srlist); NhlRLSetInteger(srlist, NhlNcnScalarFieldData, jan); NhlRLSetFloat(srlist, NhlNvpXF, .1); NhlRLSetFloat(srlist, NhlNvpYF, .75); NhlRLSetFloat(srlist, NhlNvpWidthF, 0.8); NhlRLSetFloat(srlist, NhlNvpHeightF, 0.4); NhlRLSetString(srlist, NhlNcnInfoLabelOn, "False"); NhlRLSetString(srlist, NhlNcnHighLabelsOn, "False"); NhlRLSetString(srlist, NhlNcnLowLabelsOn, "False"); //NhlRLSetIntegerArray(srlist, NhlNcnLineColors, linecolors, 15); NhlRLSetString(srlist, NhlNcnLineDrawOrder, "predraw"); NhlRLSetString(srlist, NhlNcnFillDrawOrder, "predraw"); NhlRLSetString(srlist, NhlNcnLabelDrawOrder, "predraw"); memset(setting, 0, sizeof(setting)); strncpy(setting, levelSelectionMode.toStdString().c_str(), sizeof(setting)-1); NhlRLSetString(srlist, NhlNcnLevelSelectionMode, setting); NhlRLSetInteger(srlist, NhlNcnMaxLevelCount, maxLevelCount); if (levelSelectionMode == "ManualLevels") { NhlRLSetFloat(srlist, NhlNcnMinLevelValF, minLevel); NhlRLSetFloat(srlist, NhlNcnMaxLevelValF, maxLevel); NhlRLSetFloat(srlist, NhlNcnLevelSpacingF, levelSpacing); } else if (levelSelectionMode == "ExplicitLevels") { length[0] = maxLevelCount; NhlRLSetFloatArray(srlist, NhlNcnLevelSpacingF, lineLevels, length[0]); } else if (levelSelectionMode == "EqualSpacedLevels") { NhlRLSetFloat(srlist, NhlNcnLevelSpacingF, levelSpacing); } if (plotMode == 0) { NhlRLSetString(srlist, NhlNcnFillOn, "False"); NhlRLSetString(srlist, NhlNcnLinesOn, "True"); NhlRLSetString(srlist, NhlNcnLineLabelsOn, "True"); NhlRLSetInteger(srlist, NhlNcnLineLabelInterval, 2); NhlRLSetString(srlist, NhlNcnLineLabelPlacementMode, "computed"); if (monoColor == false) { NhlRLSetString(srlist, NhlNcnMonoLineColor, "False"); NhlRLSetIntegerArray(srlist, NhlNcnLineColors, lineColors, maxLevelCount); } else { NhlRLSetString(srlist, NhlNcnMonoLineColor, "True"); /*NhlRLSetString(srlist, NhlNcnLineColor, "Black");*/ NhlRLSetInteger(srlist, NhlNcnLineColor, lineColor); } } else { NhlRLSetString(srlist, NhlNcnFillOn, "True"); NhlRLSetString(srlist, NhlNcnLinesOn, "False"); NhlRLSetString(srlist, NhlNcnFillMode, "AreaFill"); NhlRLSetString(srlist, NhlNcnLineLabelsOn, "False"); length[0] = maxLevelCount; NhlRLSetIntegerArray(srlist, NhlNcnFillColors, lineColors, length[0]); } NhlRLSetString(srlist, NhlNtmXBMode, "EXPLICIT"); NhlRLSetFloatArray(srlist, NhlNtmXBValues, xbValues, xLabelCount); NhlRLSetStringArray(srlist, NhlNtmXBLabels, &xbLabels[0], xLabelCount); NhlRLSetString(srlist, NhlNtmYLMode, "EXPLICIT"); NhlRLSetFloatArray(srlist, NhlNtmYLValues, ybValues, yLabelCount); NhlRLSetStringArray(srlist, NhlNtmYLLabels, &ybLabels[0], yLabelCount); NhlRLSetString(srlist, NhlNtmXTLabelsOn, "False"); NhlRLSetString(srlist, NhlNtmYRLabelsOn, "False"); NhlRLSetFloat(srlist, NhlNtmXBLabelFontHeightF, .010); NhlRLSetFloat(srlist, NhlNtmYLLabelFontHeightF, .010); NhlRLSetFloat(srlist, NhlNtmXBMajorOutwardLengthF, .006); NhlRLSetFloat(srlist, NhlNtmXBMajorLengthF, .006); NhlRLSetFloat(srlist, NhlNtmXTMajorLengthF, 0.); NhlRLSetFloat(srlist, NhlNtmXTMajorOutwardLengthF, 0.); NhlRLSetFloat(srlist, NhlNtmYLMajorOutwardLengthF, .006); NhlRLSetFloat(srlist, NhlNtmYLMajorLengthF, .006); NhlRLSetString(srlist, NhlNtmXBMinorOn, "False"); NhlRLSetString(srlist, NhlNtmXTMinorOn, "False"); NhlRLSetString(srlist, NhlNtmYLMinorOn, "False"); NhlRLSetString(srlist, NhlNtmYRMinorOn, "False"); if (monoThickness == true) { NhlRLSetString(srlist, NhlNcnMonoLineThickness, "True"); NhlRLSetFloat(srlist, NhlNcnLineThicknessF, thickness); } else { NhlRLSetString(srlist, NhlNcnMonoLineThickness, "False"); NhlRLSetFloatArray(srlist, NhlNcnLineThicknesses, lineThicknesses, maxLevelCount); } NhlCreate(&cn, "cn", NhlcontourPlotClass, ps2, srlist); /* Create a MapPlot object. */ NhlRLClear(srlist); NhlRLSetFloat(srlist, NhlNvpXF, .1); NhlRLSetFloat(srlist, NhlNvpYF, .75); NhlRLSetFloat(srlist, NhlNvpWidthF, 0.8); NhlRLSetFloat(srlist, NhlNvpHeightF, 0.4); /*NhlRLSetString(srlist, NhlNmpFillOn, "True");*/ NhlRLSetString(srlist, NhlNmpFillOn, "False"); NhlRLSetString(srlist, NhlNmpLabelsOn, "False"); /*NhlRLSetString(srlist, NhlNmpGeophysicalLineColor, "Black"); NhlRLSetString(srlist, NhlNmpDefaultFillColor, "DarkSalmon"); NhlRLSetString(srlist, NhlNmpLandFillColor, "DarkSalmon"); NhlRLSetString(srlist, NhlNmpOceanFillColor, "Blue"); NhlRLSetString(srlist, NhlNmpInlandWaterFillColor, "Blue");*/ NhlRLSetString(srlist, NhlNmpOutlineOn, "True"); NhlRLSetString(srlist, NhlNgsLineColor, "Black"); /*NhlRLSetString(srlist, NhlNmpOutlineOn, "True"); NhlRLSetString(srlist, NhlNmpOutlineBoundarySets, "Geophysical");*/ /*NhlRLSetString(srlist, NhlNmpOutlineDrawOrder, "predraw");*/ NhlRLSetString(srlist, NhlNmpOutlineBoundarySets, "Geophysical"); NhlRLSetFloat(srlist, NhlNmpGeophysicalLineThicknessF, 1); NhlRLSetString(srlist, NhlNmpGeophysicalLineColor, "Black"); /*NhlRLSetString(srlist, NhlNmpPerimDrawOrder, "predraw");*/ memset(setting, 0, sizeof(setting)); strncpy(setting, mapProject.toStdString().c_str(), sizeof(setting)-1); if (mapProject == "Polar Stereographic") { NhlRLSetString(srlist, NhlNmpProjection, "Stereographic"); if (polarPosition == "NH") { NhlRLSetFloat(srlist, NhlNmpMinLatF, 0); NhlRLSetFloat(srlist, NhlNmpMaxLatF, 90); NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude); NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude); NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2); NhlRLSetFloat(srlist, NhlNmpCenterLatF, 90); } else { NhlRLSetFloat(srlist, NhlNmpMinLatF, -90); NhlRLSetFloat(srlist, NhlNmpMaxLatF, 0); NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude); NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude); NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2); NhlRLSetFloat(srlist, NhlNmpCenterLatF, -90); } } else { NhlRLSetString(srlist, NhlNmpProjection, setting); NhlRLSetFloat(srlist, NhlNmpMinLatF, bottomLatitude); NhlRLSetFloat(srlist, NhlNmpMaxLatF, topLatitude); NhlRLSetFloat(srlist, NhlNmpMinLonF, leftLongitude); NhlRLSetFloat(srlist, NhlNmpMaxLonF, rightLongitude); NhlRLSetFloat(srlist, NhlNmpCenterLonF, (leftLongitude+rightLongitude)/2); NhlRLSetFloat(srlist, NhlNmpCenterLatF, (topLatitude + bottomLatitude)/2); } NhlRLSetString(srlist, NhlNmpGridAndLimbOn, "False"); NhlRLSetString(srlist, NhlNmpLimitMode, "latlon"); NhlCreate(&mp, "mp", NhlmapPlotClass, ps2, srlist); /* Create a TextItem object. */ QString title = grb2Msg->getParameter()->nclName(); QString level; level.setNum(grb2Msg->getLevel()->firstLevel()); switch (grb2Msg->getLevel()->firstLevelType()) { case 100: case 101: level += "Pa"; break; case 0: case 106: level += "m"; break; } title += " " + level + " " + grb2Msg->getTimeLevel()->getName() ; NhlRLClear(srlist); NhlRLSetFloat(srlist, NhlNtxPosXF, 0.5); NhlRLSetFloat(srlist, NhlNtxPosYF, 0.8); NhlRLSetString(srlist, NhlNtxJust, "CENTERCENTER"); memset(setting, 0, sizeof(setting)); strncpy(setting, title.toStdString().c_str(), sizeof(setting)-1); NhlRLSetString(srlist, NhlNtxString, setting); NhlRLSetFloat(srlist, NhlNtxFontHeightF, .030); NhlRLSetInteger(srlist, NhlNtxFont, 25); NhlCreate(&tx, "tx", NhltextItemClass, ps2, srlist); NhlDraw(mp); NhlDraw(cn); NhlDraw(tx); NhlFrame(ps2); NhlDestroy(ps2); NhlDestroy(appid); for (int idx = 0; idx < xLabelCount; idx ++) { free(xbLabels[idx]); } for (int idx = 0; idx < yLabelCount; idx ++) { free(ybLabels[idx]); } free(dData); free(fData); }
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); }