This module describes a basic structure for an NCL script used to create and display graphics. Complicated tasks may require a more elaborate structure. After experience with using NCL, you may find a structure that is more suitable to your needs and preferences, but the following will get you started. A very simple example is provided below. For more sophisticated examples, consult the Quick Start Guide.
After your datasets have been created or imported, you may want to manipulate the data. For example, you may want to convert temperatures from Fahrenheit to Celsius. Or you may want to compute quantities based on the imported data, thereby creating new data fields. NCL has a wide selection of internal functions and procedures to help you with data manipulation. See the module on Data manipulation for details.
; ; Simple NCL script just to illustrate the NCL plot generation structure ; discussed in this module. ; ; ; Draw an X-Y plot with internally-generated data. ; ; ; Step 1 - create linear arrays containing the data to be plotted. ; This data could have been read in using one of the read ; functions, or by doing an addfile on a file in a supported ; data format. ; x_data = (/ -2., -1., 0., 1., 2., 3. /) y_data = (/ 2., 1., 0., 1., 2., 3. /) ; ; Step 2 - create an X11 window to use as an output device for displaying ; the plot. Set the pause option so that a call to "frame" will ; pause waiting for a mouse click or keyboard entry. ; xworkid = create "simple" xWorkstationClass defaultapp "wkPause" : "True" end create ; ; Step 3 - create an XyPlot object using the data in x_data and y_data. ; ; ; First create the data object. ; dataid = create "xyData" coordArraysClass defaultapp "caXArray": x_data "caYArray": y_data end create ; ; Next, create the XyPlot object which is a child of the ; XWorkstation object. Set the appropriate resource ; to force recomputation of plot limits when the data ; is changed. ; plotid = create "xyPlot" xyPlotClass xworkid "xyCoordData": dataid "xyComputeYMax": "True" end create ; ; Step 4 - Draw the plot. ; draw(plotid) frame(xworkid) ; ; Step 5 - Modify the data and redraw. ; y_data = y_data^2 ; ; Modify the data object. ; setvalues dataid "caYArray": y_data end setvalues ; ; Inform the plot object of the data change. ; setvalues plotid "xyCoordData": dataid end setvalues ; ; Redraw ; draw(plotid) frame(xworkid)
NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?