NCL Frequently Asked Questions (FAQ)
Basics | NCL core language | File input/output | Data handling | Data analysis | Visualization | Array functions | Output formats | Error messages | Memory issues | Documentation | Miscellaneous |Basics
- Where can I download NCL?
- I'm having problems downloading NCL from the ESG website.
- How do I set up my environment to run NCL?
- How do I run NCL?
- How do I determine the version of NCL?
- Are there any email lists I can join?
- Where can I see some examples of how to use NCL?
- Are there any NCL command line options I can use?
- Are there any editor enhancements for editing NCL scripts?
- If I'm running NCL interactively, are there any command-line shortcuts I can use?
- If I'm running interactively, how can I load some existing NCL code?
- Is there anyway I can turn off the preceding "(n)" output when I print a bunch of values?
- My NCL script is quitting suddenly, and I'm not sure where and/or why.
- How do I tell if I have an OPeNDAP-enabled NCL?
NCL core language
- How do I comment a line in NCL? Is there a way to have a block of comments?
- Is there a continuation character in NCL?
- How do I easily convert a number to a string?
- How do I create a new variable that doesn't contain a _FillValue attribute?
- How do I create a double, long, or short variable without using "new"?
- How do I include the double quote (") character in an NCL string?
- I'm getting an unexpected value when I use the power ('^') operator combined with a negative value.
- How do I create a list of string integers with leading zeros ("008", "009", "010", etc)?
- How do I get the current date into NCL as a string?
- How do I get a list of files into an array of strings in NCL?
- How do I concatenate strings and values in NCL?
- How do I retrieve an environment variable in NCL?
- How do I print nicely formatted, multiple columns of data in NCL?
File input/output
- What's the easiest way to convert a GRIB1, GRIB2, HDF 4, or HDF-EOS 2 file to a NetCDF file?
- How do I dump the contents of a GRIB, HDF, or HDF-EOS file (or variable on the file) to the screen?
- How do I convert a large file to a NetCDF file?
- How do I write a scalar to a NetCDF file?
- How do I retain metadata for a variable that was read off a series of files using "addfiles"?
- How do I access an NCL file variable if it has hyphens ('-') in the name?
- How do I read/write NetCDF, HDF4, HDF-EOS2, GRIB1, GRIB2, or CCM History Tape files?
- How do I read/write ASCII files?
- How do I write a formatted ASCII file?
- How do I read an ASCII file if I don't know how many lines it contains?
- How do I read an ASCII file that contains delimiters?
- How do I read/write binary files?
- Once I've opened a file with "addfile", how do I find out what variables and attributes it contains?
- Is there a way to control whether my binary file is read or written as little endian or big endian?
- I'm trying to convert a file to a NetCDF file using "ncl_convert2nc", but getting an error message about violating format constraints.
- Why do I get different results when reading my HDF-EOS2 file, depending on whether I use the ".hdf" or ".hdfeos" extension?
- When I run my script, I'm getting an error message "ncclose: ncid 0: NetCDF: Not a valid ID".
- When I try to access the Climate Diagnostics Center [CDC] OPeNDAP server via NCL, I get "Permission denied".
- I'm running into a problem when opening lots of files with addfile or addfiles.
Data handling
- How do I set a missing value for my data?
- How do I determine if my data contains any missing values, or count how many missing values it has?
- How do I change the missing value to another value?
Data analysis
- How do I average values in a multi-dimensioned array?
- How do I interpolate my 2-dimensional random data to a 2-dimensional gridded array?
- How do I interpolate my 3-dimensional random data to a 3-dimensional gridded array?
Visualization
- How can I maximize the size of a plot in the frame?
- How do I get multiple plots on a page?
- What's a good way to generate a color map (table)?
- My map projection doesn't look right.
- How do I change all of my fonts to be the same in my visualization?
- How can I change the text function code to something other than a colon?
- How can I get a degree symbol in a text string?
- How can I get things like accents or umlauts over my text?
- How can I get special characters, like Greek symbols, in my graphical text strings?
- Can I use real PostScript fonts in my PostScript file?
- How do I change the aspect ratio or size of my map or plot?
- Can I set color resources by color name rather than color index values?
- How can I speed up the drawing of filled contours in NCL?
- Can I change color index values or color maps in mid-frame?
- How do I get my PostScript/PDF output to cover most of an 8-1/2" x 11" page?
- How can I control the size and location of the X11 window that NCL brings up?
- How do I tell NCL to ignore missing values in my plot?
- How can I get more labels on my contour lines?
- My X or Y axis values are not linear. How can I change this?
- How do I get log scaling on either of my plot axes?
- How do I fill my contour levels with various shading patterns and/or solid colors?
- How do I overlay a contour plot (or a vector/streamline plot) on a map?
- How can I improve the resolution of my map outlines?
- How can I get more geographical outlines in my map, like the provinces of China?
- If I am creating a color contour or vector plot, how do I select my colors such that they are spread across my whole color map?
- How do I generate a wire-frame surface or isosurface plot in NCL?
- How do I draw weather symbols (wind barbs, weather front lines, high and low pressure indicators, arrows, dots, weather icons, cloud symbols, lightning bolts, etc.) on a map?
- How can I have a new line as part of a graphical text string in NCL?
- How come I get different line thicknesses on different output devices using the same thickness value?
- How can I put a timestamp on my plot?
- Why am I not getting the color I expect when I reference a named color?
- How do I set up my NCL script so that it uses a resource file?
- How can I move and resize my labelbar and/or legend?
- How can I generate some "nice" 2D random data for a contour and/or vector plot?
Array functions
- How do I get the dimensions of an array?
- How do I create unique random subscripts?
- How do I eliminate missing values from a one-dimensional array?
- How do I generate a one-dimensional array of equally-spaced integers or floating point numbers?
- How do I find or print the minimum/maximum values of my data array?
Output formats
- How do I change the default NCGM/PostScript/PDF file name to something else?
- How do I convert my NCL graphics file to another format, like PNG, to put on the web or in a presentation?
- Can I produce a PNG image directly from NCL?
- How do I convert my multi-frame NCL graphics file to an MPEG movie file?
- How do I include an encapsulated PostScript file from NCL in a LaTex document?
Error messages
- When I run NCL, I get an error message about being unable to load the "System Resource File".
- When I run NCL, I get an error message about the X driver.
- What's the deal with the error message "error: line -1 before or near..."?
- I'm getting a strange "workspace reallocation" error message.
- I'm getting an "ARSCAM/ARPRAM ALGORITHM FAILURE" error message.
- I'm getting the error message "PLCHHQ - CHARACTER NUMBER 10 (w) IS NOT A LEGAL FUNCTION CODE".
- I'm trying to assign a value to an NCL variable, but getting a "right hand side can't be coerced to type of left hand side" error message.
- I'm getting an "MDRGSF/MDRGOF - ERROR OPENING RANGS/GSHHS CAT FILE" error message.
- I'm trying to draw primitives (markers, lines, polygons) on my plot, and getting an error essage "tfPolyDrawList element 0 is invalid".
- When I call one of the gsn_csm_xxxx_map plotting scripts, I get an error message about a units attribute not being correct.
- I'm trying to create a contour, vector, or contour plot, and getting a weird error about spline approximation.
Memory issues
Documentation
- Where can I see a list of all the NCL resources?
- Where can I see a list of all the NCL functions and procedures?
- Where can I see a list of links to dash patterns, marker styles, color tables, etc?
Miscellaneous
- Is there a way for NCL to query the user for input?
- How do I call a C or Fortran function or procedure from NCL?
- I'm trying to compile my NCAR Graphics program using the Intel compilers, but getting some undefined references.
- If I obscure an NCL X11 window with another application, the X11 window doesn't refresh when I bring it back to the foreground.
Basics
- Where can I download NCL?
See the NCL download page for full instructions. You can download precompiled binaries for a specific UNIX system, or source code.
- I'm having problems downloading NCL from the ESG website.
Please see our ESG troubleshooting guide for help. If this doesn't help, then send email to the ncl-install email list.
- How do I set up my environment to run NCL?
- Set the NCARG_ROOT environment variable and your search path to
where NCL/NCARG resides
In order to use the software, you must set your NCARG_ROOT environment variable to the parent directory where the NCL executables and accompanying files were installed. You also need to make sure that the directory where the NCL/NCARG executables reside are on your search path. It is best to do this from one of your .* files in your home directory. If you are not sure which shell you are running, you can do an "ls -a" in your home directory to see what kind of files you have that start with ".", and then look in these files to see how environment variables are set.
In the example above, we would set these with the following:
From C-shell (csh):
setenv NCARG_ROOT /usr/local set path=(/usr/local/bin $path)From bash:export NCARG_ROOT=/usr/local export PATH=(/usr/local/bin $PATH)You should now be set for using NCL and/or NCAR Graphics. If you have any problems, or questions about installing NCL from source code or binaries, please send email to ncl-install@ucar.edu (you need to subscribe first). - Set the DISPLAY environment variable to indicate where to display
graphics
This is not an NCL specific environment variable, but rather one that is used by any X11 Windows application that you run. For NCL or NCAR Graphics, it is needed when you display your graphics to an X11 window, or if you use ictrans, ctrans, or idt to view your NCGM files.
This variable must be set to the IP address or name of the machine you want to display your graphics on, for example "localhost:13.0" . If you are not running on a remote machine, then you can try setting it to ":0.0". Please contact your system administrator if you are not sure what to set it to.
For example, from C-shell (csh):
setenv DISPLAY :0.0 setenv DISPLAY 128.117.14.12:0 setenv DISPLAY localhost:13.0From bash:export DISPLAY=:0.0 export DISPLAY=128.117.14.12:0 export DISPLAY=localhost:13.0 - Put a ".hluresfile" file in your home directory
In order to better customize the NCL graphical environment, we highly recommend that you copy a .hluresfile to your home directory. You can customize this file to your liking, but at a minimum, you want to change the default font, the default color table, and the text function code.
- Special instructions if you have an OPeNDAP-enabled version of NCL
[You don't need to worry about these instructions if you are not using OPenDAP.]
OPeNDAP-enabled binaries require some libraries to be installed on your host computer:
- Secure Sockets Layer (SSL) library
- OPeNDAP libraries
Once you have these libraries, you may be required to set the environment variable LD_LIBRARY_PATH to contain the directory where they are located on your host system in order for OPeNDAP-enabled versions of NCL to work properly.
- Set the NCARG_ROOT environment variable and your search path to
where NCL/NCARG resides
- How do I run NCL?
Once you have NCL installed, you can run it interactively by typing on the UNIX command line:
ncl
This will echo some information to the screen, and give you a prompt:Copyright (C) 1995-2008 - All Rights Reserved University Corporation for Atmospheric Research NCAR Command Language Version 5.0.1 The use of this software is governed by a License Agreement. See http://www.ncl.ucar.edu/ for more details. ncl 0>
To quit out of interactive mode, type "quit" (without the double quotes).To run NCL on an existing NCL script called "myscript.ncl", type on the UNIX command line:
ncl myscript.ncl
- How do I determine the version of NCL?
The version number is echoed whenever you run NCL. You can also type "ncl -V" on the UNIX command line to get the version number.
- Are there any email lists I can join?
Yes. For basic questions about installing NCL and setting up your environment to use it:
http://mailman.ucar.edu/mailman/listinfo/ncl-install
For all other questions on NCL:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
For questions relating specifically to NCAR Graphics:http://mailman.ucar.edu/mailman/listinfo/ncarg-talk
- Where can I see some examples of how to use NCL?
To see hundreds of NCL application examples, see the category list of application pages. These examples are full NCL scripts that you can download. Some of the datasets are provided as a separate link.
If you are a complete beginner to NCL, then there's a tutorial with examples that are described line-by-line.
- Are there any NCL command line options I can use?
Yes, see the "NCL command line options" section in the NCL Reference Manual.
- Are there any editor enhancements for editing NCL scripts?
Yes, see the support page for a list.
- If I'm running NCL interactively, are there any command-line shortcuts I can use?
There are shortcuts that allow you to navigate through previous commands and edit them. For more information, go to the "
NCL Command Line Shortcuts" section in the NCL Reference Manual. - If I'm running interactively, how can I load some existing NCL code?
You can use the loadscript procedure, where you give it the name of the file that contains NCL commands.
- Is there anyway I can turn off the preceding "(n)" output when I print a bunch of values?
If you are using print to print some values, and you see output like this:
Variable: x Type: float Total Size: 80 bytes 20 values Number of Dimensions: 1 Dimensions and sizes: [20] Coordinates: (0) 0 (1) 0.5263158 (2) 1.052632 (3) 1.578947 (4) 2.105263 (5) 2.631579 . . .then you can get rid of the "(0)", "(1)", etc, by using the "-n" command line option when you invoke "ncl". Your output will then look like:Variable: x Type: float Total Size: 80 bytes 20 values Number of Dimensions: 1 Dimensions and sizes: [20] Coordinates: 0 0.5263158 1.052632 1.578947 2.105263 2.631579 . . .- My NCL script is quitting suddenly, and I'm not sure where and/or why.
If you are running an NCL script and getting a "bus error" or "segmentation fault" (which technically shouldn't happen, but does on occasion), then try commenting out your "begin" and "end" statement for the main code, and running your script with the "-x" command line option:
ncl -x your_script.ncl
This will cause every line of your script to be echoed to the screen, and you will be able to see where it is quitting suddenly.- How do I tell if I have an OPeNDAP-enabled NCL?
A quick way is to do an "ldd" or "otool -L" on the "ncl" executable to see if it references libraries like "libnc-dap.so" and "libdapclient.so". This will indicate your version of NCL was built with OPeNDAP capabilities enabled:
ldd `which ncl`
You should see output like:libnc-dap.so.3 => /usr/local/lib/libnc-dap.so.3 (0x0000002a95557000) libdap.so.6 => /usr/local/lib/libdap.so.6 (0x0000002a956ee000) libdapclient.so.1 => /usr/local/lib/libdapclient.so.1 (0x0000002a958b9000)
Here's short test to see if your OPeNDAP-enabled NCL is working. Note that you must be on a system that allows OPeNDAP access:url = "http://test.opendap.org/opendap/data/nc/" filename = "123.nc" exists = isfilepresent(url+filename) if(.not.exists) then print("OPeNDAP isfilepresent test unsuccessful.") print("Either you don't have the appropriate permissions to access OPeNDAP servers, or NCL does not have OPeNDAP capabilities on this system") status_exit(1) else print("OPeNDAP isfilepresent test successful.") f = addfile(url + filename,"r") vars = getfilevarnames(f) vars_out = (/"l","j","i","cross","aloan","shot","order","bears"/) sqsort(vars) sqsort(vars_out) print(vars) ; These two lists should print(vars_out) ; be the same. end if
- If I'm running interactively, how can I load some existing NCL code?
NCL core language
- How do I comment a line in NCL? Is there a way to have a block of comments?
The comment character in NCL is a semicolon (';'). You can use it on a line by itself or after an NCL command:
; Here is a comment before a command that assigns a variable. x = 5. x = 5. ; This comment can be at the end of a line
Unfortunately, there is no way to designate a block of comments, other than putting semicolons in front of all the lines:; ; This is a block of comments, ; each of which must be ; preceded by its own semicolon ;
- Is there a continuation character in NCL?
Yes, you can use the '\' character:
x = (/"This", "is", "a", "long", "array", "of", "strings", "that", \ "we", "can", "continue", "on", "a", "new", "line", "with", "a", \ "\", "character."/) ; Can use \ for arithmetic expressions output(i,1:n-2) = (p4)*(var( i-1, 1 : n-2 ) + var( i, 2 : n-1) + \ var( i+1, 1 : n-2 ) + var( i, 0 : n-3)) + \ (q4)*(var( i-1, 0 : n-3 ) + var( i-1, 2 : n-1) + \ var( i+1, 2 : n-1 ) + var( i+1, 0 : n-3)) - How do I easily convert a number to a string?
Use the '+' string concatenator:
x = 3.14 str = "" + x
- How do I create a new variable that doesn't contain a _FillValue attribute?
x = new(5, float, "No_FillValue")
- How do I create a double, long, or short variable without using "new"?
x = 1.d ; double, x = 1d (also acceptable) l = 1l ; long s = 1s ; short
The long and short literals were added in V5.0.1. - How do I include the double quote (") character in an NCL string?
Since NCL uses double quotes to denote strings, you have to do an extra step to get them into a string:
quote = inttochar(34) print("The word " + quote + "string" + quote + " has double quotes around it.") print("'Single' quotes are no big deal.")
- I'm getting an unexpected value when I use the power ('^') operator combined with a negative value.
The negation operator ('-') has the highest precedence in an NCL expression, potentially producing unexpected results. For example, the following expression:
x = - 3^2yields a value of 9 because it behaves as:x = (-3)^2Note how the use of parentheses can change the results:print(- (3+2)^2) ----> yields 25whereas:print(- ((3+2)^2)) ----> yields -25Finally, if the '-' symbol appears between two expressions or numbers, then it is treated as a minus rather than negation. Hence, the following yields a value of 9:
x = 0 - 3^2 ; equivalent to x = (0) - (3^2) - How do I create a list of string integers with leading zeros ("008", "009", "010", etc)?
Use the sprinti function with a format like "%0.i" (the "%0" indicates to fill in the strings with leading zeros where possible). For example:
ii = ispan(0,100,1) iis = sprinti("%0.3i",ii) ; "000", "001", ... "100"
- How do I get the current date into NCL as a string?
Use the systemfunc function, which executes a UNIX system call and returns the output as a string:
datestr = systemfunc("date") - How do I get a list of files into an array of strings in NCL?
Use the systemfunc function, with the UNIX "ls" command:
filenames = systemfunc("ls *.txt") - How do I concatenate strings and values in NCL?
You can use the "+" operator, which will automatically recognize when you are operating on strings. You can also concatenate strings with other NCL variable types, like float and integers. For example, the following NCL code snippet:
month = 1 day = 21 year = 2002 date_str = "The date is " + month + "/" + day + "/" + year
will produce the string "The date is 1/21/2002".You can use the functions sprinti and sprintf to generate formatted strings. For example, if you want to construct filenames on the fly with names like "sw001.out", "sw002.out",..., "sw010.out", your code would look something like this:
do i=1,10 filename = "sw" + sprinti("%0.3i",i) + ".out" ...do something with filename... end do - How do I retrieve an environment variable in NCL?
Use the function getenv:
env_str = getenv("PATH") - How do I print nicely formatted, multiple columns of data in NCL?
There's a function write_matrix that will nicely format 2D arrays using a user-specified format string.
Here's an example on how to use it:
N = 5 M = 7 ave = 0.0 std = 5.0 x = random_normal(ave, std, (/N,M/)) write_matrix(x, "5f7.2", False)
This example will produce the following output:4.35 4.39 0.27 -3.35 -6.90 4.36 4.66 3.77 -1.66 4.06 9.73 -5.84 0.89 8.46 10.39 4.91 4.59 -3.09 7.55 4.56 1.77 3.68 5.08 0.14 -5.63 -0.63 -14.12 -2.51 1.76 -1.43 -4.29 0.07 5.85 0.87 8.65
A more complicated method is to write a C or Fortran subroutine to print the data as you want it, and then use wrapit77 as described in the section "using the wrapit77 application" in the NCL Reference Manual. There's an example on 2-dimensional array printing in the Getting Started Using NCL manual.The functions sprinti and sprintf can also be used to generate formatted output.
File input/output
- What's the easiest way to convert a GRIB1, GRIB2, HDF 4, or HDF-EOS 2 file to a NetCDF file?
On the UNIX command line:
ncl_convert2nc your_file.xxx
where xxx is the file suffix, like "grb", "hdf", or "hdfeos" (other file extensions are recognized).If you need to write an NCL script to do the conversion, see the output netcdf applications page.
For more information on supported file formats in NCL, see the "Information on supported data formats" section in the NCL Reference Manual.
- How do I dump the contents of a GRIB, HDF, or HDF-EOS file (or variable on the file) to the screen?
Use ncl_filedump on the UNIX command line. Some examples:
ncl_filedump ced1.lf00.t00z.ega.grb ncl_filedump -v PRES_6_SFC -ftime ced1.lf00.t00z.ega.grb
Type "ncl_filedump -h" for a usage message. - How do I convert a large file to a NetCDF file?
If you are using ncl_convert2nc to convert a supported file (like GRIB) to a NetCDF file, and getting the error message:
ncendef: ncid 0: NetCDF: One or more variable sizes violate format constraintsthen try the "-L" option:
ncl_convert2nc U12345.grb -L - How do I write a scalar to a NetCDF file?
The first way is to use "ncl_scalar" as a dimension name:
spherical = new(1,"character") spherical!0 = "ncl_scalar" spherical = integertocharacter(1) ncid->spherical = spherical
The second way is to use filevardef:filevardef(ncid, "spherical","character","ncl_scalar") ncld->spherical = integertocharacter(1)
Note that for either of these methods, if you look at this file in NCL it will appear as if there is a dimension named "ncl_scalar". In an ncdump of the file, however, the dimension will not appear, so the variable is a true NetCDF scalar. - How do I retain metadata for a variable that was read off a series of files using "addfiles"?
Use a special function from contributed.ncl called addfiles_GetVar. For example:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" fils = systemfunc("ls /model/annual*nc") f = addfiles(fils, "r") T = addfiles_GetVar(f,fils,"T") printVarSummary(T) - How do I access an NCL file variable if it has hyphens ('-') in the name?
If you have an NCL file variable with hyphens in the name (for example, "in->Data-Set-14"), then you will get an error message if you try to access this variable directly. This is because NCL treats the hyphens as minus symbols:
ncl> print(in->Data-Set-14) fatal:Either file (in) isn't defined or variable (Data) is not a variable in the file fatal:Execute: Error occurred at or near line 24
To get around this problem, turn the name of the variable into a string, and enclose the string in dollar signs ('$'):print(in->$"Data-Set-14"$)
orvar_string = "Data-Set-14" print(in->$var_string$)
For more information on using '$' to reference file variables, see the section "File variable string references" in the NCL Reference Manual. - How do I read/write NetCDF, HDF4, HDF-EOS2, GRIB1, GRIB2, or CCM History Tape files?
To open any one of these types of files, use the addfile function, which opens a data file and returns a pointer to the file. Once you have a pointer to the file, you have access to all of its global and variable attributes and coordinate arrays. You can also use addfile to open a NetCDF or HDF file for writing (not GRIB1, GRIB2, HDF-EOS2, or CCM files, since you can't write these files in NCL).
For example, to open a GRIB file and write some of its variables to a NetCDF file:
begin grib_file = addfile("ced1.lf00.t00z.eta.grb","r") ; Open GRIB file to read ncfile_out = addfile("data.nc","c") ; Open NetCDF file to write ; Write some data to NetCDF file. ncfile_out->PRES = grib_file->PRES_6_SFC ncfile_out->HGT = grib_file->HGT_6_SFC ncfile_out->A_PCP = grib_file->A_PCP_6_SFC_acc ncfile_out->NCPCP = grib_file->NCPCP_6_SFC_acc ncfile_out->ACPCP = grib_file->ACPCP_6_SFC_acc ncfile_out->CAPE = grib_file->CAPE_6_SFC endFor some more complex examples, see the file I/O application examples.
For detailed information on the file formats that NCL supports, see the "Information on supported data formats" section in the NCL Reference Manual.
- How do I read/write ASCII files?
Use the asciiread function to read an ASCII file and the asciiwrite or write_matrix procedures to write an ASCII file.
Here's an example:
; ; Assume the "oceanland30e.asc" file contains a single column of integers, ; 16471 of them. "asciiread" allows you to specify the dimensionality of ; the data, and in this case we are passing dimensions (/91,181/), so ; "ocean1" will be a 2-dimensional array dimensioned 91 x 181, which can ; be verified by printing the dimsizes of "ocean1." ; ocean1 = asciiread("oceanland30e.asc",(/91,181/),"integer") print(dimsizes(ocean1)) ; ; Write out part of "ocean1" to a new ASCII file. "data.asc" will contain ; 15 integers, since (7:3:2,0:4) is a 3 x 5 array. ; asciiwrite("data.asc",ocean1(7:3:2,0:4))For more complex examples, see the ASCII read/write examples in the list of file I/O application examples.
- How do I write a formatted ASCII file?
Use a function called write_matrix that will nicely format 2D arrays using a user-specified format string.
Here's an example that writes a 2D array to a file called "file.txt":
N = 5 M = 7 ave = 0.0 std = 5.0 x = random_normal (ave, std, (/N,M/)) res = True res@fout = "file.txt" write_matrix (x, "5f7.2", res)
This example will produce the following output in "file.txt":4.35 4.39 0.27 -3.35 -6.90 4.36 4.66 3.77 -1.66 4.06 9.73 -5.84 0.89 8.46 10.39 4.91 4.59 -3.09 7.55 4.56 1.77 3.68 5.08 0.14 -5.63 -0.63 -14.12 -2.51 1.76 -1.43 -4.29 0.07 5.85 0.87 8.65
- How do I read an ASCII file if I don't know how many lines it contains?
There are two ways you can do this:
- Use "-1" in the second argument to asciiread:
z = asciiread("file.dat",-1,float)
If you have multiple columns of data, and you know how many columns there are, then you can use onedtond to restructure the one-dimensional array returned from asciiread. In the example below, assume there are 4 columns of data:z = asciiread("file.dat",-1,"float") ncol = 4 ; number of columns nrow = dimsizes(z)/ncol ; get number of points znew = onedtond(z,(/nrow,ncol/)) ; znew will be nrow x ncol
- Use systemfunc to count the number of lines in
the file before you read it. Assuming again that you have a data
file with 4 columns of data:
ncol = 4 nrow = stringtointeger(systemfunc("wc -l wgt")) ; "wc -l" returns the # ; of lines in a file z = asciiread("file.dat",(/nrow,ncol/),"float")
- Use "-1" in the second argument to asciiread:
- How do I read an ASCII file that contains delimiters?
There's an applications page that describes a script that reads an ASCII file with delimiters, and creates a netCDF file that contains all the data. This script assumes that the first line of your ASCII file contains the names of the fields, and uses these names as variable names on the netCDF file.
- How do I read/write binary files?
Use the appropriate cbinread, cbinwrite, craybinrecread, fbindirread, fbindirwrite, fbinread, fbinrecread, fbinrecwrite, or fbinwrite function, depending on what type of binary file you have. In addition, you may also want to use the functions craybinnumrec or fbinnumrec for getting the number of unformatted Fortran records in a file.
For some complex examples, see the binary read/write examples in the list of file I/O application examples.
See the setfileoption procedure for ways to change how your binary file is read/written (big endian versus little endian, for example).
- Once I've opened a file with "addfile", how do I find out what variables and attributes it contains?
Use the functions getfilevaratts, getfilevardims, and getfilevarnames to retrieve the list of attribute names for a file variable, the list of dimension names for a file variable, or the list of variable names for a file, respectively.
- Is there a way to control whether my binary file is read or written as little endian or big endian?
Use the setfileoption procedure:
setfileoption("bin","ReadByteOrder","LittleEndian") v = cbinread("data.littleEndian.bin",-1,"float") setfileoption("bin","WriteByteOrder","BigEndian") cbinwrite("data.bigEndian.bin",v)
- I'm trying to convert a file to a NetCDF file using "ncl_convert2nc", but getting an error message about violating format constraints.
If you are trying to convert a file to NetCDF using ncl_convert2nc, and getting the following error message:
ncendef: ncid 0: NetCDF: One or more variable sizes violate format constraintsthen you may have what qualifies as a "large file". You need to use the "-L" option with ncl_convert2nc. - Why do I get different results when reading my HDF-EOS2 file, depending on whether I use the ".hdf" or ".hdfeos" extension?
If you use the ".hdf" extension, then NCL uses the underlying HDF4 interface to read your data, whereas if you use the "hdfeos or "he2" extension, NCL reads the file using the HDF-EOS2 library interface.
Using the ".hdfeos" extension software will give you slightly more information, since the HDF-EOS2 software provides software to calculate additional lat/lon information.
Side tip: if your HDF-EOS2 file has an ".hdf" extension, then you can force NCL to read this file as an HDF-EOS2 file simply by appending an ".he2" or ".hdfeos" to the file name in the addfile call (you don't need to rename the file). For example, if your file is called "swath.hdf" and you want to read it as a HDF-EOS2, use the following:
a = addfile("swath.hdf.hdfeos","r")
- When I run my script, I'm getting an error message "ncclose: ncid 0: NetCDF: Not a valid ID".
You should only see this error if you are using version 5.0.0 of an OPeNDAP-enabled NCL. It usually occurs when you exit the NCL script.
We verified this is a bug created by recent changes to NCL's handling of its internal cleanup and exit procedures. This bug has been fixed and will be available in V5.0.1.
Note that this does not cause a problem in reading NetCDF files. When you write a file, however, you may have to delete the file handler variable before you exit the script, by using the delete procedure:
begin ... f = addfile("newfile.nc","w") ...write stuff to file pointed to by 'f'. delete(f) end - When I try to access the Climate Diagnostics Center [CDC] OPeNDAP server via NCL, I get "Permission denied".
It is likely that the CDC OPeNDAP server does not recognize the IP address of the machine being used. The CDC server was shut down due to security concerns. They have opened the OPeNDAP server on a host by host basis. If you wish to access the CDC OPeNDAP server, please e-mail esrl.psd.data@noaa.gov with:
- The IP address of the machine from which you wish access. This should be a static IP address (not generated via DHCP). It would better if this address could successfully undergo reverse DNS lookup to produce a fully qualified hostname.
- The name of your institution.
- A one-line blurb about your intended use of the data.
See the http://www.cdc.noaa.gov/opendap.html URL for the complete story.
After registration with CDC, an NCL script might look like:
CDC_URL = "http://www.cdc.noaa.gov/cgi-bin/opendap/nph-nc/Datasets/" ; generic CDC CDC_FILP = "ncep.reanalysis.dailyavgs/pressure/air.2005.nc" ; data path filp = CDC_URL + CDC_FILP if (isfilepresent(filp)) then fp = addfile(filp,"r") else print("============================================") print("CDC_URL : "+CDC_URL) print("CDC_FILP: "+CDC_FILP) print("does not exist: message from NCL script") print("============================================") exit end if x = fp->FOO
- I'm running into a problem when opening lots of files with addfile or addfiles.
If you need to open lots of files with either addfile or addfiles, then you should probably consider calling setfileoption and setting "SuppressClose" to False.
The number of files you can have open at any time is dependent on your system. A general limit seems to be around 1024.
Data handling
- How do I set a missing value for my data?
For the variable that contains your data, set the attribute "_FillValue" to the missing value. For example, the following NCL code:
x = (/1,2,3,-999,5,6,7,-999,-999,10/) x@_FillValue = -999
sets the missing value of x to -999.The "_FillValue" attribute is recognized by many NCL functions and procedures and thus the computations will behave differently when they encounter missing values (like ignore them or return with an error message). For example, if you pass the above x array to the NCL function sum, you will get a return value of 34.
- How do I determine if my data contains any missing values, or count how many missing values it has?
Use the ismissing function combined with the any function to return a single True or False indicating whether your data contains missing values:
is_msg = any(ismissing(data))) if(is_msg) then print("'data' contains missing values.") else print("'data' doesn't contain any missing values.") end if
To count the number of missing values, use the num function:num_msg = num(ismissing(data))) print("data contains " + num_msg + " missing values.")
- How do I change the missing value to another value?
If your data contains a "_FillValue" attribute, simply set it to the value you want, but be sure to use the same type (float, double, etc).
For example, to change your data's missing values from 0 to -999, use:
data@_FillValue = -999
If your data contains a "missing_value" attribute, this won't be recognized by NCL as an official missing value. You want to set the "_FillValue" attribute to this value:data@_FillValue = data@missing_value delete(data@missing_value) ; not necessary, just cleaning up
There are other ways to assign a _FillValue attribute. See the assignFillValue function.
Data analysis
- How do I average values in a multi-dimensioned array?
Use the avg or dimavg function.
For example, in the following NCL code snippet where x is a 2 x 3 x 2 array, y will be a scalar value equal to 2.916667:
x = (/(/(/2,3/), (/4,5/), (/1,2/)/), (/(/3,8/), (/1,4/), (/0,2/)/)/) y = avg(x)
If you want to average all the values in a multi-dimensioned array for a particular dimension, then use the dim_avg function. For example, if you have a 3-dimensional array called temp that contains temperature values on a latitude/longitude grid for each hour of the day, and you want to compute the average temperature at each hour, then your code would look something like this:temp!0 = "time" temp!1 = "lat" temp!2 = "lon" hourly_avg_temp = dim_avg(temp(lat|:,lon|:,time|:))
The above example also shows how to reorder your dimensions in case the dimension that you want to average across is not the last dimension of your array. hourly_avg_temp will be a one-dimensional array with the same number of elements as the first dimension of temp. - How do I interpolate my 2-dimensional random data to a 2-dimensional gridded array?
There are lots of functions available for doing different kinds of interpolations and regridding. For a list, go to the NCL functions and procedures page and look in the interpolation or regridding sections.
Two such functions are natgrid or dsgrid2. Here's an example:
NX = 21 NY = 21 ; Define the input data arrays. x = (/0.00, 1.00, 0.00, 1.00, 0.40, 0.75/) y = (/0.00, 0.00, 1.00, 1.00, 0.20, 0.65/) z = (/0.00, 0.00, 0.00, 0.00, 1.25, 0.80/) ; Define the output grid. xc = 1./(NX-1.) xo = ispan(0,NX-1,1) * xc yc = 1./(NY-1.) yo = ispan(0,NY-1,1) * yc ; Do the gridding using natgrid. "natout" will be a 2-dimensional array ; dimensioned 21 x 21. natout = natgrid(x, y, z, xo, yo) print(natout) ; Do the gridding using dsgrid2. "dsout" will be a 2-dimensional array ; dimensioned 21 x 21. dsout = dsgrid2(x, y, z, xo, yo) print(dsout)
- How do I interpolate my 3-dimensional random data to a 3-dimensional gridded array?
First, see the question above on 2-dimensional grids.
Two functions for handling 3D random data are triple2grid and dsgrid3.
Here's an example of using dsgrid3:
NX = 21 NY = 21 NZ = 21 x = (/0.00, 1.00, 0.00, 1.00, 0.40, 0.75/) y = (/0.00, 0.00, 1.00, 1.00, 0.20, 0.65/) z = (/0.00, 0.00, 0.00, 0.00, 1.25, 0.80/) u = x*x + y*y + z*z xo = new((/NX/),float) yo = new((/NY/),float) zo = new((/NZ/),float) ; ; Create the output grid. ; xmin = -2.0 ymin = -2.0 zmin = -2.0 xmax = 2.0 ymax = 2.0 zmax = 2.0 ii = fspan(0,20.,21) xo = xmin + (ii/(NX-1)) * (xmax-xmin) yo = ymin + (ii/(NY-1)) * (ymax-ymin) zo = zmin + (ii/(NZ-1)) * (zmax-zmin) ; ; Interpolate. "output" will be a 3-dimensional grid dimensioned 21x21x21. ; output = dsgrid3(x, y, z, u, xo, yo, zo) print(output)
Visualization
- How can I maximize the size of a plot in the frame?
If you are using one of the gsn_xxx plotting scripts, then set the special resource gsnMaximize to True.
Run the following simple script and compare the two frames:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" data = generate_2d_array(10, 10, -19.69, 15.82, 0, (/129,129/)) wks = gsn_open_wks("x11","max") plot = gsn_contour(wks,data,False) res = True res@gsnMaximize = True plot = gsn_contour(wks,data,res)
- How do I get multiple plots on a page?
If your plots are all the same size, then you can use the procedure gsn_panel. If your plots are not the same size, then you can use the viewport resources vpXF, vpYF, vpWidthF, and vpHeightF.
For some panel examples, see the panel applications page. This page also shows you tricks on paneling plots that are not the same size (#9 and #14 are two such examples).
- What's a good way to generate a color map (table)?
See the page on creating your own color map, or the section "Creating your own color map using HSV values" for an introduction to the HSV color wheel and how it helps you create a color map.
For an example, try modifying the HSV values in the file "gsn_color.ncl" and running it through NCL to see the different results you get.
You can use the function gsn_draw_colormap to draw the current color map associated with the workstation:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" wks = gsn_open_wks("ncgm","gsn_draw_colormap") gsn_draw_colormap(wks) ; Draw the default colormap gsn_define_colormap(wks,"hotres") ; Change color map and gsn_draw_colormap(wks) ; draw it.
- My map projection doesn't look right.
If you're plotting a subset of longitudes and getting a strange looking map, then you may need to set the resource mpCenterLonF. This will tell NCL where you want the center longitude of the plot to be. Usually, this should be set to the halfway point between mpMinLonF and mpMaxLonF:
res@mpCenterLonF = (res@mpMinLonF + res@mpMaxLonF)/2.
- How do I change all of my fonts to be the same in my visualization?
First select a font from the NCL font tables and remember the name, i.e. "helvetica".
If you always want to use this font in all of your NCL scripts, then put the following line in a file called ".hluresfile" in your home directory:
*Font : helvetica(We highly recommend using the helvetica font for all NCL scripts, because the default font doesn't look good when you print it.)If NCL sees a ".hluresfile" in your home directory, it will always load it before running any NCL scripts.
If you want this font to apply only to a particular NCL script, first create a file called xxx.res, where xxx is the second argument to gsn_open_wks. Then, include the above line in that file.
Any fonts that you are explicitly setting in your NCL script will override resources set in ~/.hluresfile or the NCL script-specific resource file.
Here's an example (with the "font.res" below):
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" wks = gsn_open_wks("x11","font") ; Open an X11 workstation. y = (/1,3,-1,-2,0,2,3/) x = ispan(0,dimsizes(y)-1,1) res = True res@tiMainString = "This is an XY plot" res@tiXAxisString = "X values" res@tiYAxisString = "Y values" xy = gsn_xy(wks,x,y,res) ; Create and draw an XY plot.
The "font.res" file:! Change all fonts to times-bold *Font : times-bold
Try changing "times-bold" in the "font.res" file to other fonts to see the results. Use either a font name or a font index as listed in the font tables. - How can I change the text function code to something other than a colon?
If you want your text function code permanently changed (to, say, a '~') for every time you run NCL, then in the ~./.hluresfile put the following line:
*TextFuncCode : ~TextFuncCode can be set to whatever character you want (the default is a colon, ':'). This special resource can only be set in a resource file and not in an NCL script.To change the text function code to another character inside of an NCL script, use any one of the *FuncCode resources that corresponds with the resource you are using to set the text string.
For example, if you are setting the txString resource:
res@txString = "Time : 0600 hours"then you change the function code associated with this resource to another character (say '~') with the txFuncCode resource:res@txFuncCode = "~" res@txString = "Time : 0600 hours"If you are setting the X axis label with tiXAxisString, then the corresponding function code resource would be tiXAxisFuncCode, and so on. - How can I get a degree symbol in a text string?
You can use font table 34 with the character "0" to get a degree symbol:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" begin wks = gsn_open_wks("x11","degree") res = True ; plot mods desired res@tiMainString = "Example degree (~S~o~N~) symbol" res@tmXBMode = "Explicit" ; explicit labels res@tmXBValues = (/ 0.2, 0.4, 0.6, 0.8/) res@tmXBLabels = (/"20~F34~0~F~","40~F34~0~F~","60~F34~0~F~","80~F34~0~F~"/) res@tmXBLabelFontColor = "Red" plot = gsn_blank_plot(wks,res) end
- How can I get things like accents or umlauts over my text?
It's not trivial, but it is doable, using text function codes. Here's an example:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" begin wks = gsn_open_wks("x11","text") res = True res@txJust = 4 res@txFont = 25 res@txFontHeightF = .1 ; ; Explanation of the text string function codes: ; ; :F22: - Select font 22 (Helvetica bold) ; :H-15F35: - Move 15 digitized font units left and select font 35. ; The character "H" in font 35 is an umlaut. ; :H4F22: - Move 4 digitized font units right and select font 22. ; :H-14F35: - Move 14 digitized font units left and select font 35. ; :H3F22: - Move 3 digitized font units right and select font 22. ; str1 = ":F22:u:H-15F35:H:H4F22:berho:H-14F35:H:H3F22:hen" ; ; Explanation of the text string function codes: ; ; :F22: - Select font 22. ; :H-16V6F35: - Move 16 digitized units left, 6 digitized units ; up, and select font 35. ; :V-6H5F22: - Move 6 digitized units down and select font 22. ; :H-13F35: - Move 13 digitized units left and select font 35. ; :F22H2: - Select font 22 and move 2 digitized units right. ; str2 = ":F22:U:H-16V6F35:H:V-6H5F22:bersta:H-13F35:H:F22H2:nder" gsn_text_ndc(wks,str1,0.5,0.7,res) ; Draw the text string gsn_text_ndc(wks,str2,0.5,0.3,res) frame(wks) end
- How can I get special characters, like Greek symbols, in my graphical text strings?
First browse the font tables to find the one that contains the character(s) you want. Clicking on any one of the font names, like "math_symbols", will show you all the characters for that particular font.
Once you find the character you desire, note the font table index ("math_symbols" is index 18, for example), and the corresponding character, then you can use the text function code 'F' to change the font.
For example, to get a bell symbol, you would see that character 'n' in the "symbol_set1" table (index 19) is a bell. You can then use the string "~F19~n~F~" in any text string resource to indicate you want a bell symbol. The "~F~" means go back to the original font.
For example, to use it in a title:
res@tiMainString = "Bell (~F19~n~F~)"
Note that we're assuming the default function code (a colon, ':'), has been changed to a tilde, '~'. See the question above on changing function codes. - Can I use real PostScript fonts in my PostScript file?
Essentially no, except in one situation that is discussed below. When you use NCL font number 4, you will get the stroked simplex_roman font, no matter what kind of workstation you are going to, even a PostScript workstation. If you change "4" to "Helvetica," then you will get NCL font 21 which is a Helvetica font that is drawn using filled areas, i.e. filled areas will be put into the output PostScript and not code to use the built-in PostScript Helvetica font.
However, there is one circumstance which will allow you to use a PostScript font directly and not have filled areas inserted into the output PostScript. This can be accomplished by setting the resource txFontQuality to "low." There are some significant downsides to this. First, no matter what font you select in NCL, the font used in the output PostScript will be Helvetica. If you select a character, such as a degree symbol, that is not in the Helvetica font, it will not be drawn correctly. Secondly, all text strings will be monospaced. Thirdly, when plotting to workstations other than PostScript or PDF, you will get a very low-level stick font.
The primary upside to this is a reduction in the size of the output PostScript file. Another advantage is that you will be using a built-in PostScript font that will be produced with high fidelity, even at very small sizes.
Here is an example of using font quality "low":
begin wks = gsn_open_wks("ps","font_test") txres = True txres@txFontQuality = "low" txres@txFontHeightF = 0.04 txres@txFuncCode = ":" gsn_text_ndc(wks,"Test PS fonts",.5,.5,txres) frame(wks) txres@txDirection = "down" gsn_text_ndc(wks,"Vertical",.5,.5,txres) frame(wks) txres@txDirection = "across" gsn_text_ndc(wks, \ "degree sign:: :F34:0:FC:superscript:: 1.3:F0L1:4:F:10:S:300", \ .5,.5,txres) frame(wks) end
- How do I change the aspect ratio or size of my map or plot?
For a plot that doesn't contain a map, you can use the viewport resources vpWidthF and vpHeightF. The viewport coordinates are normalized; that is, they take values from 0.0 to 1.0 (inclusive).
For example, if you want your plot to be wider than it is high, then you might set vpWidthF to 0.4 and vpHeightF = 0.75:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" wks = gsn_open_wks("x11","viewport") ; Open an X11 workstation. y = (/1,3,-1,-2,0,2,3/) x = ispan(0,dimsizes(y)-1,1) res = True res@vpWidthF = 0.75 res@vpHeightF = 0.4 xy = gsn_csm_xy(wks,x,y,res) ; Create and draw an XY plot.
In order to change the aspect ratio of a map, you can still use the "vp" resources as above, but you must also set the resource mpShapeMode to "FreeAspect":load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" wks = gsn_open_wks("x11","viewport") ; Open an X11 workstation. mpres = True mpres@mpShapeMode = "FreeAspect" ; Allow the aspect ratio to be changed. mpres@gsnMaximize = True mpres@vpWidthF = 0.8 mpres@vpHeightF = 0.8 map = gsn_map(wks,"CylindricalEquidistant",mpres)
In the above script, to maximize the plot in the frame but retain the aspect ratio, the special resource gsnMaximize is set to True. - Can I set color resources by color name rather than color index values?
Yes, as long as the color you want to reference exists in your current color map. Any place that you would normally use a color index value, you can use a color name enclosed in double quotes. An ASCII list of the valid color names is in the file "$NCARG_ROOT/lib/ncarg/database/rgb.txt", and a graphical representation is also available".
For example, if color index 2 is red in your color map, and you want to set the main title font color to red, then you can do it one of two ways from an NCL script:
res@tiMainFontColor = 2 ; index value res@tiMainFontColor = "red" ; color name
Whenever a named color is used, the current color map is searched for the color that is the closest match to that color. This means that if you access a color that doesn't have a close match in your color map, you may not get the color you are expecting. To get around this problem, make sure the color map you use contains all the named colors you want by adding them explicitly to your color map.For example, if you want your general color map to have the following RGB values:
(/(/0.0,0.0,0.0/),(/1.0,1.0,1.0/),(/1.0,0.0,0.0/),(/0.0,1.0,0.0/), (/0.0,0.0,1.0/),(/1.0,1.0,0.0/),(/0.0,1.0,1.0/),(/1.0,0.0,1.0/), (/0.5,0.0,0.0/),(/0.5,1.0,1.0/),(/0.0,0.0,0.5/),(/1.0,1.0,0.5/), (/0.5,0.0,1.0/),(/1.0,0.5,0.0/),(/0.0,0.5,1.0/),(/0.5,1.0,0.0/), (/0.5,0.0,0.5/)/)
and you also want to include the named colors "Olive", "Plum", "Gold", "MediumBlue", and "LightSlateGray", then set the new color map as follows:... cmap = (/"(/0.0,0.0,0.0/)","(/1.0,1.0,1.0/)","(/1.0,0.0,0.0/)",\ "(/0.0,1.0,0.0/)","(/0.0,0.0,1.0/)","(/1.0,1.0,0.0/)",\ "(/0.0,1.0,1.0/)","(/1.0,0.0,1.0/)","(/0.5,0.0,0.0/)",\ "(/0.5,1.0,1.0/)","(/0.0,0.0,0.5/)","(/1.0,1.0,0.5/)",\ "(/0.5,0.0,1.0/)","(/1.0,0.5,0.0/)","(/0.0,0.5,1.0/)",\ "(/0.5,1.0,0.0/)","(/0.5,0.0,0.5/)",\ "Olive","Plum","Gold","MediumBlue","LightSlateGray"/) wks = gsn_open_wks(...) gsn_define_colormap(wks,cmap) ...Note: in order to mix RGB values with color names, you must enclose each entry in double quotes. More information about named colors is available in the color fill applications page. - How can I speed up the drawing of filled contours in NCL?
You can try setting the cnFillMode resource to "RasterFill" (the default is "AreaFill"), and further set cnRasterSmoothingOn to True if you want smoother contours.
- Can I change color index values or color maps in mid-frame?
The main consideration in doing this is changing the background color. If the background color is changed in mid-picture (color index 0), then in most cases at the time you change the background color your entire frame will be overwritten with that color. As long as you do not change the background color in mid-picture, your results should be as desired. See the simple example below.
Trying to swap in an entire new color map is problematic, again primarily due to considerations with resetting the background color. If you are producing PS or PDF output and if your background color is the default, then things should work. Things should work in all cases in going to NCGM and translating with ctrans. Producing X11 output works unless you specifically reset the background color.
But, to be on the safe side, what will work in all cases is starting off with any color map and then redefining any color indices except the background. For example, if you have a color table with 256 defined colors and want to replace that in mid-picture with a different color table, use the function NhlSetColor to redefine all color index values except for index 0. The logic in the following example illustrates this:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" begin res = True ; ; draw_cells draws cells fitting them into a box with lower left ; corner (xll,yll) and upper right corner (xur,yur) with nx cells ; in x and ny cells in y. For each call each cell is colored ; using increasing indices in cmap, starting with index 0. ; procedure draw_cells(wks:graphic, xll:float, yll:float, xur:float, \ yur:float, nx:integer, ny:integer, \ cmap[*][3]:numeric) begin xinc = (xur-xll)/nx yinc = (yur-yll)/ny do j=0,ny-1 plly = yll + j*yinc pury = plly + yinc do i=0,nx-1 pllx = xll + i*xinc purx = pllx + xinc x = (/pllx,purx,purx,pllx,pllx/) y = (/plly,plly,pury,pury,plly/) res@gsFillColor = i+j*nx gsn_polygon_ndc(wks,x,y,res) end do end do end ; ; Original color map is "black", "red", "green", "blue". ; cmap = (/ (/0.,0.,0./), (/1.,0.,0./), (/0.,1.,0./), (/0.,0.,1./) /) rlist = True rlist@wkColorMap = cmap wks_type = "x11" wks = gsn_open_wks(wks_type,"cell") gsn_define_colormap(wks,cmap) ; ; Draw color boxes using the original color map. ; draw_cells(wks, 0., 0., 1.0, 0.5, 2, 2, cmap) ; ; Redefine indices 1-3. ; NhlSetColor(wks, 1, 0., 1., 1.) ; cyan NhlSetColor(wks, 2, 1., 0., 1.) ; magenta NhlSetColor(wks, 3, 1., 1., 0.) ; yellow ; ; Draw color boxes using the redefined color map. ; draw_cells(wks, 0., 0.5, 1.0, 1.0, 2, 2, cmap) frame(wks) end - How do I get my PostScript/PDF output to cover most of an 8-1/2" x 11" page?
You can do this one of two ways. If you are using one of the gsn_xxx plotting scripts, then the easy way is to set the special resource gsnMaximize to True:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" data = generate_2d_array(10, 10, -19.69, 15.82, 0, (/129,129/)) wks = gsn_open_wks("pdf,"pdfmax") res = True res@gsnMaximize = True plot = gsn_contour(wks,data,res)
Another (but harder) way is when you create your PostScript/PDF workstation, use the resources wkDeviceLowerX, wkDeviceLowerY, wkDeviceUpperX, and wkDeviceUpperY to position the output anywhere on the page.load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" type = "ps" type@wkDeviceLowerX = -75 ; These coordinates can be negative. type@wkDeviceLowerY = -50 type@wkDeviceUpperX = 750 type@wkDeviceUpperY = 950 wks = gsn_open_wks(type,"psmax") res = True blank = gsn_blank_plot(wks,res)
Note that it is possible to have negative values for these resources, and to use them to change the aspect ratio of the plot. - How can I control the size and location of the X11 window that NCL brings up?
Add the lines:
! Make default X11 window larger (adjust as necessary) *wkWidth : 800 *wkHeight : 800
to your "~/.hluresfile" file. - How do I tell NCL to ignore missing values in my plot?
If you are using gsn_xxx routines to generate your graphics, then all you need to do is make sure that the _FillValue attribute of your data is set to the missing value.
Otherwise:
- for contour data - use the ScalarField
resource sfMissingValueV
- for vector/streamline data, use the VectorField
vfMissingUValueV and/or
vfMissingVValueV resources
- for XY data, use the resources caXMissingV and/or caYMissingV
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create some dummy data for the contour plot. T = (/ (/ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 /),\ (/ 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7 /),\ (/ 7, 5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\ (/ 7, 5, 999, 3, 3, 3, 3, 3, 999, 5, 7 /),\ (/ 7, 5, 999, 3, 2, 2, 2, 3, 999, 5, 7 /),\ (/ 7, 5, 999, 3, 2, 1, 2, 3, 999, 5, 7 /),\ (/ 7, 5, 999, 3, 2, 2, 2, 3, 999, 5, 7 /),\ (/ 7, 5, 999, 3, 3, 3, 3, 3, 999, 5, 7 /),\ (/ 7, 5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\ (/ 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7 /),\ (/ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 /)/) T@_FillValue = 999 ; Set _FillValue. wks = gsn_open_wks("x11","contour") contour = gsn_contour(wks,T,False) ; Draw a contour plot.Note the hole in the middle of the contour plot due to the presence of missing values.For an XY plot example with missing values:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" wks = gsn_open_wks("x11","xy") y = (/1,3,-1,-2,0,2,3,0,5,-2,1,0,0,8,10,5,-3/) y@_FillValue = 0 ; Set the missing value. xy = gsn_y(wks,y,False) ; Create and draw an XY plot.
Note the gaps in the XY curve due to missing values. - for contour data - use the ScalarField
resource sfMissingValueV
- How can I get more labels on my contour lines?
NCL uses a complex algorithm to determine where to put contour line labels, and sometimes this generates unexpected results, like not getting enough contour labels.
You can set the cnLinelabelPlacementMode to different values to try to control the way the contour lines are labeled. The default is "Randomized", and you can try the values "Constant" or "Computed".
The resource cnLineLabelDensityF allows you to increase the density of the contour labels, if cnLinelabelPlacementMode is set to "Computed" or "Randomized".
See the contour labels applications page for some examples.
- My X or Y axis values are not linear. How can I change this?
You can set the special gsn resources gsnXAxisIrregular2Linear and/or gsnYAxisIrregular2Linear to True.
For an example, run the following code:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin ; ; Generate some dummy data. ; level = (/1000, 850, 700, 500, 400, 300, 250, 200, 150, 100/) lat = fspan(-90,90,20) nlat = dimsizes(lat) nlev = dimsizes(level) data = generate_2d_array(10, 12, -20., 17., 0, (/ nlev,nlat/)) data!0 = "lev" ; Name the dimensions and data!1 = "lat" ; attach coordinate arrays data&lev = level ; This coordinate array is irregulary spaced data&lat = lat wks = gsn_open_wks("x11","linear") gsn_define_colormap(wks,"rainbow") ; Set up resources. res = True res@gsnMaximize = True ; Maximize plot in frame res@gsnSpreadColors = True ; Span full color map res@cnFillOn = True ; Turn on contour fill res@cnLinesOn = False ; Turn off contour lines res@lbLabelAutoStride = True ; Control labelbar spacing res@tiYAxisString = "Irregularly-spaced values" plot = gsn_csm_contour(wks,data,res) ; Create filled contours res@tiYAxisString = "Y axis linearized" res@gsnYAxisIrregular2Linear = True plot = gsn_csm_contour(wks,data,res) ; Create filled contours end
- How do I get log scaling on either of my plot axes?
For an XY plot, set the transformation resources trXLog and/or trYLog to True, depending on which axes you want to be in log scaling.
Here's an example with default linear axes, and then with the Y axis "logged":
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create dummy data for XY plot. y = (/10, 100, 5000, 10, 9000, 70, 300, 10000, 600/) wks = gsn_open_wks("x11","logxy") ; Open an X11 workstation. xyres = True xyres@tiXAxisString = "linear" xyres@tiYAxisString = "linear" xyplot = gsn_y(wks,y,xyres) ; Create and draw the XY plot. ; Change the Y axis scale to be log and redraw the plot. xyres@trYLog = True xyres@tiYAxisString = "log" xyres@xyComputeYMin = True ; To keep from getting some warning msgs. xyplot = gsn_y(wks,y,xyres) ; Create and draw the XY plot.
For a contour plot, the method for changing to log scaling depends on whether the coordinates for the axis you want to log are regularly or irregularly spaced. If they are regularly spaced, then use trXLog or trYLog just like it was done for the XY plot above:load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create some dummy data for the contour plot. N=25 T = new((/N,N/),float) jspn = ispan(-N/2,N/2,1)^2 ispn = ispan(-N/2,N/2,1)^2 do i = 0, dimsizes(ispn)-1 T(i,:) = ispn(i) + jspn end do T = 100.0 - sqrt(8^2 * T) wks = gsn_open_wks("x11","logcon") ; Open an X11 workstation. cnres = True cnres@sfYCStartV = 10 cnres@sfYCEndV = 1000 cnres@tiXAxisString = "linear" ; Label for X axis. cnres@tiYAxisString = "log" ; Label for Y axis. cnres@trYLog = True ; Log scaling for Y axis contour = gsn_contour(wks,T,cnres) ; Create and draw contour plot.
If you are using one of the gsn_xxx plotting functions, and if the coordinates for the axis you want to log are irregularly spaced (as they are if your data contains coordinate arrays or you set one of either the sfXArray or sfYArray resources), then you can set the appropriate gsnXAxisIrregular2Log or gsnYAxisIrregular2Log resource to True:load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create some dummy data for the contour plot. N = 25 T = new((/N,N/),float) jspn = ispan(-N/2,N/2,1)^2 ispn = ispan(-N/2,N/2,1)^2 do i = 0, dimsizes(ispn)-1 T(i,:) = ispn(i) + jspn end do T = 100.0 - sqrt(8^2 * T) wks = gsn_open_wks("x11","logcon") ; Create some dummy data for the Y axis that is not regularly spaced. y = (/ 10, 50, 100, 150, 250, 500, 750, 1000, 1100, 1300, 1500, \ 1750, 2000, 2200, 2400, 2600, 3000, 4000, 4500, 5000, 5100, 5500, \ 7000, 9000,10000/) cnres = True cnres@sfYArray = y ; Irregular Y axis cnres@gsnYAxisIrregular2Log = True ; Force Y axis to be log. cnres@tiYAxisString = "log" ; Label for Y axis. cnres@tiXAxisString = "linear" ; Label for X axis. contour = gsn_contour(wks,T,cnres) ; Create and draw contour plot.
For some more complex examples, see examples 4-6 on the zonal applications page for an example of these and similar resources. - How do I fill my contour levels with various shading patterns and/or solid colors?
If you just want to fill your contour levels with various solid colors, set cnFillOn to True. If you are using gsn_xxx interfaces, then you can additionally set gsnSpreadColors to make sure your full color map is spanned. To change the default colors used for the contour levels, set cnFillColors to an array of desired color indexes.
If you want to fill the contour levels with different shading patterns, you must set cnMonoFillPattern to False, and then set cnFillPatterns to an array of desired fill pattern indexes.
There are 18 different fill patterns: pattern 0 is solid fill, patterns 1-16 are various fill patterns, and pattern 17 is a special stipple fill pattern. If you use "-1" for a fill pattern, this means to leave it transparent (no fill).
There's a function called gsn_contour_shade that allows you to specify contour levels where you want specific shading or colors.
Here's an example showing how to create a contour plot using different fill patterns and colors:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ; Create some data for the contour plot. data = generate_2d_array(10, 10, -19.69, 15.82, 0, (/129,129/)) wks = gsn_open_wks("x11","fillcon") cnres = True cnres@cnFillOn = True ; Turn on contour level fill. cnres@cnMonoFillPattern = False ; Indicate you want multiple fill patterns. ; ; Set cnFillPatterns and cnFillColors to various indexes representing ; fill patterns and colors. A fill pattern index of "0" is solid fill. ; If you don't want any fill for a particular contour level, set it ; to "-1," which means "transparent." ; cnres@cnFillPatterns = (/0, 2, 3, 0, 6, 8,10,-1, 9, 0,11,12,17,16/) cnres@cnFillColors = (/6,10,14, 8, 4, 2, 9, 1,12, 3,20,13, 5, 7/) contour = gsn_csm_contour(wks,data,cnres)
For examples of gsn_contour_shade, see example 13 on the contour effects applications page. - How do I overlay a contour plot (or a vector/streamline plot) on a map?
The easiest way to do this is use one of the overlay functions found in the list of gsn_xxx interfaces (like gsn_csm_contour_map, gsn_csm_vector_scalar_map, etc).
If your data doesn't contain any coordinate arrays and it hasn't already been transformed into some map projection, then you need to set the resources sfXArray and sfYArray (vfXArray and vfYArray for vector/streamline plots) to arrays that define the values for the axes. For overlaying on a map, these values would be longitude and latitude respectively.
Here's a simple contour example:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create some dummy data for the contour/map plot. data = generate_2d_array(10, 10, -19.69, 15.82, 0, (/64,128/)) wks = gsn_open_wks("x11","fillcon") res = True res@sfXArray = fspan(-180,180,128) res@sfYArray = fspan( -90, 90, 64) plot = gsn_contour_map(wks,data,res)
If the plot has already been transformed to map coordinates, then you can set the tfDoNDCOverlay resource to True, indicating to NCL that no map transformation is to take place. In order for this to work, however, your map projection must be set up to exactly match the area your data represents. Sometimes this information is available, say, on the same file that the data came from.Here's a simple (and rather crude) vector example using a cylindrical equidistant map:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create some dummy data for the contour/map plot. udata = generate_2d_array(10, 10, -19, 15, 0, (/32,64/)) vdata = generate_2d_array(10, 10, -21, 17, 0, (/32,64/)) wks = gsn_open_wks("x11","fillcon") res = True res@tfDoNDCOverlay = True plot = gsn_vector_map(wks,udata,vdata,res)
Of course, these types of plots are usually more complex than the above, because if you don't know the map projection, it can be difficult setting up the map limits correctly. For some more complex examples, see the native grid application page. - How can I improve the resolution of my map outlines?
Use the mpDataBaseVersion resource. The default is "LowRes". If you change this to "MediumRes" or "HighRes", you will improve the resolution of your map outlines.
Note: the "HighRes" resource shows coastal outlines only, and you should not use this resolution for global maps (it's slow, and you may see some strange artifacts). The high-resolution database does not come with NCL; instructions for downloading and installing this database can be found on the high-resolution coastlines description page.
For an example comparing the three levels of resolutions:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" wks = gsn_open_wks("x11","mapres") res = True res@gsnMaximize = True ; Maximize plot in frame res@mpMinLonF = -15. ; Area to zoom in on. res@mpMaxLonF = 15 res@mpMinLatF = 40. res@mpMaxLatF = 70. ; Default "LowRes" database. map = gsn_csm_map(wks,res) ; "MediumRes" database. res@mpDataBaseVersion = "MediumRes" map = gsn_csm_map(wks,res) ; "HighRes" database. res@mpDataBaseVersion = "HighRes" map = gsn_csm_map(wks,res)
- How can I get more geographical outlines in my map, like the provinces of China?
We have been adding more outlines (like China provinces) to our map databases, but they won't be available in NCL right away.
Meanwhile, if you already have latitude/longitude locations for the desired outlines, then you can draw them yourself. There are some examples where extra map outlines for India and Brazil were added by hand.
Go to:
http://www.ncl.ucar.edu/Applications/polyg.shtml
and see examples 9 and 11. - If I am creating a color contour or vector plot, how do I select my colors such that they are spread across my whole color map?
If you are using one of the gsn_xxx interfaces, then, you can set the special resource gsnSpreadColors to True. Otherwise, you can set the cnFillColors or vcLevelColors to arrays of color indices or names.
Run the following script and compare the color fills in the two frames:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" cdf_file = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf","r") Z = cdf_file->Z(0,0,:,:) ; geopotential height wks = gsn_open_wks("x11","spread_colors") ; Open an X11 workstation. gsn_define_colormap(wks,"temp1") ; Use a rainbow color map that ; has 63 colors and goes from ; gray to blue to red. res = True res@cnFillOn = True ; Turn on contour fill. res@lbLabelAutoStride = True ; Control labelbar label spacing. plot = gsn_csm_contour(wks,Z,res) ; Draw a filled contour plot. ; are mostly blue. res@gsnSpreadColors = True ; Choose colors across whole color map. plot = gsn_csm_contour(wks,Z,res) ; Note that the contour colors now ; span from gray to blue to red.
If you want to only use a subset of the color map, then you can also set gsnSpreadColorStart and gsnSpreadColorEnd resources:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" cdf_file = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf","r") Z = cdf_file->Z(0,0,:,:) ; geopotential height wks = gsn_open_wks("x11","spread_colors") gsn_define_colormap(wks,"tbr_240-300") res = True res@gsnMaximize = True res@cnFillOn = True ; Turn on contour fill res@gsnSpreadColors = True ; Spread the colors res@gsnSpreadColorStart = 23 ; Start at 24th color res@gsnSpreadColorEnd = 187 ; There are 201 colors res@lbLabelAutoStride = True ; Control labelbar labels plot = gsn_csm_contour(wks,Z,res)
- How do I generate a wire-frame surface or isosurface plot in NCL?
There are a basic set of 3D plotting routines, based on a library interface called Tdpack.
For wire-frame plots, you can use tdez2d, and for isosurfaces you can use tdez3d. For some examples of these and other Tdpack routines, see the Tdpack applications page.
- How do I draw weather symbols (wind barbs, weather front lines, high and low pressure indicators, arrows, dots, weather icons, cloud symbols, lightning bolts, etc.) on a map?
Use the procedures wmbarb, wmdrft, and/or wmlabs in combination with one of the gsn_*map* functions.
Here's an example of drawing a weather front and a couple of "High" symbols on a satellite view map projection:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Create a color map and an X11 workstation. cmap = (/ (/ 1., 1., 1. /), \ ; 0 - White background. (/ 0., 0., 0. /), \ ; 1 - Black foreground. (/ 1., 0., 0. /), \ ; 2 - Red. (/ 0., 0., 1. /), \ ; 3 - Blue. (/ 0., 1., 1. /), \ ; 4 - Cyan. (/ 1., 0., 1. /)/) ; 5 - Magenta. wks = gsn_open_wks("x11","wmlabs") gsn_define_colormap(wks,cmap) ; Create a satellite view projection. mpres = True mpres@gsnFrame = False ; Don't advance the frame. mpres@gsnMaximize = True ; Maximize plot on page. mpres@mpOutlineBoundarySets = "National" mpres@mpGridLineColor = 0 mpres@mpCenterLatF = 40. mpres@mpCenterLonF = -105. map = gsn_map(wks,"Satellite",mpres) ; Draw a stationary front. wmsetp("ezf",1) ; Tell wmap we are using an existing map projection. wmsetp("lin",1.0) ; Line width of front curve. wmsetp("fro","stationary"); Specify stationary front. wmsetp("cfc",3) ; Use blue for the triangles. wmsetp("wfc",2) ; Use red for the bumps. wmsetp("swi",0.04) ; Increase the size of the bumps and triangles. xlat = (/ 20., 30., 35., 40., 45. , 50./) ; Latitudes. xlon = (/-195., -125., -115., -105., -95., -85./) ; Longitudes. wmdrft(wks, xlat, xlon) ; Draw front. ; Draw a couple of High symbols. wmsetp("hib",4) ; Cyan for background. wmsetp("his",1) ; Black for shadow. wmsetp("hic",5) ; Magenta for bounding circle. wmsetp("sht",0.02) ; Increase size. xl = (/ 50., 50./) ; Latitudes. yl = (/-105.,-145./) ; Longitudes. wmlabs(wks, xl, yl, "HI") ; Draw symbols. frame(wks) - How can I have a new line as part of a graphical text string in NCL?
Use the text function code that represents a carriage return ('C'):
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" begin wks = gsn_open_wks("x11","test") ; Assumes '~' is the function code, and not the default ':' title = "This is a title~C~with a carriage return" txres = True txres@txFontHeightF = 0.03 gsn_text_ndc(wks,title,0.5,0.5,txres) end - How come I get different line thicknesses on different output devices using the same thickness value?
Line thicknesses displayed on different output devices (X11, PostScript, PDF, etc.) can be significantly different for the same line thickness value. This is due to several factors.
Every device has a default, or nominal, line thickness (also sometimes call line width). This nominal line width is the width of a line drawn with the default thickness value of 1.0. In general this nominal line width is different for different devices. What a given device considers its default line width can vary from barely visible to fat. For example, the nominal line width for PostScript output may look thinner than a line drawn with the same width specification on an X11 window. Also, the results for X11 output can vary depending on the resolution of the output device.
The linewidth scale factor is applied to the nominal line width on a given device. However, it will not necessarily produce lines that are exactly that factor bigger than the default width. In fact the scale factor may have no effect, or unexpected effects. In general the scale factor is applied to the default line width of the device and maps onto the nearest available hardware line width that a device supports. For printed PostScript output the results you get will probably be as accurate as you will want, but for X11 output, or PostScript displayed on a computer monitor, you will get varying results.
Different devices also interpret fractional, or zero, line widths differently. For example, PostScript and PDF will always produce a line, no matter how small the line width value is - a zero linewidth value will produce a line one pixel wide. However, for X11 output any line width value less than 0.5 will usually map to a zero-width line, that being the closest available hardware line width. In contrast to PS or PDF, a zero-width line in X11 output is not drawn.
If you are trying to "zero" out a line, the recommendation is to do it some other way than setting the line thickness to 0. For example, you can draw it in the background color. This way you will get the same results for X11 and PostScript.
The bottom line is that you should not be surprised by what you get when it comes to line widths - it definitely depends on the output device.
The following script can be run to get an idea what various lines drawn with different thickness specifications will look like on different devices.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" begin wktype = "ps" wks = gsn_open_wks (wktype, "thickness") cmap = (/"White","Black"/) gsn_define_colormap(wks,cmap) ; ; Main title. ; txres = True txres@txFontHeightF = 0.04 txres@txFont = 22 gsn_text_ndc(wks,"Line thicknesses",0.5,0.95,txres) txres@txFontHeightF = 0.025 gsn_text_ndc(wks, \ "(results will vary depending on the output device)",0.5,0.88,txres) ; ; Specify the sample line thicknesses. ; thicknesses = (/8.00, 4.00, 2.00, 1.00, 0.75, 0.50, 0.25, 0.00/) ; ; Draw and label lines with the sample thicknesses. ; pres = True ytop = 0.78 txres@txFontHeightF = 0.02 txres@txJust = "CenterLeft" do i = 0,dimsizes(thicknesses)-1 pres@gsLineThicknessF = thicknesses(i) yh = ytop - 0.1*i gsn_text_ndc(wks,"Thickness = " + thicknesses(i),0.05,yh+0.025,txres) gsn_polyline_ndc(wks,(/0.05,0.95/),(/yh,yh/),pres) end do frame (wks) end
- How can I put a timestamp on my plot?
Use the infoTimeStamp procedure:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" data = generate_2d_array(10, 10, -19.69, 15.82, 0, (/129,129/)) wks = gsn_open_wks("x11","max") plot = gsn_contour(wks,data,False) res = True res@gsnFrame = False plot = gsn_csm_contour(wks,data,res) infoTimeStamp(wks,0.02,"") frame(wks)
- Why am I not getting the color I expect when I reference a named color?
Each named color has a specific RGB value