屏号为nc490due是什么屏

扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
下载作业帮安装包
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
初中英语短文翻译DUE to a medical error, 44-year-old Safiya became blind. She now feels helpless. And all she had to depend on was her husband Meraj.
Meraj loved Safiya with all his heart. He wanted to help his wife gain her confidence (信心) again.
Finally, Safiya felt ready to return to her job, but how would she get there? She used to take the bus, but was now too frightened to get around the city by herself. Meraj promised (承诺) that he would ride the bus with her.
For two weeks, each morning they made the journey together and Meraj would take a cab back to his office. Finally, Safiya decided to try the trip herself. Monday, Tuesday, Wednesday, Thursday... Each day she went on her own. It went perfectly.
On Friday morning, Safiya took the bus to work as usual. As she was paying for her fare (票价) to get off the bus, the driver said: “Lady, I sure envy (羡慕) you.”
“Why do you say that?” she asked the driver.
The driver answered: “You know, every morning for the past week, a gentleman stood across the corner watching you. He makes sure you cross the street safely and he watches you until you enter your office building. Then he blows you a kiss and walks away.”
Tears of happiness poured down Safiya’s cheeks (脸颊). Her husband had given her a gift more powerful than sight (视力) – the gift of love that can bring light. 谢谢
作业帮用户
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
由于医疗事故,44岁的索菲亚成了盲人。现在她感到无助,她只能依靠她的丈夫默拉克。默拉克全心全意地爱着索菲亚。他想帮助他的妻子重获信心。最后,索菲亚觉得准备好回去工作了,但是她怎么去呢?她以前做公交车,但是现在凭她自己在城里穿行太危险。默拉克答应与她一起坐公交车。这两周,每天早晨他们都一起上路,然后默拉克坐出租车回到他的办公室。最后,索菲亚决定自己走。周一,周二,周三,周四....每天她都自己走,而且很顺利。到了周五早晨,索菲亚像往常一样坐公交车去上班。当她付完车票钱下车后,司机说,“女士,我很羡慕你”,“你为什么这样说?”,她问司机。司机说“你知道,在上周的每天早晨,有一位男士都在路口看着你。他确认你安全过马路,并看着你进入你的办公楼。然后给你一个飞吻才走”。索菲亚的脸上瞬间留下了热泪。相对于失去视力,她丈夫给力她一份更为沉重的礼物,这份爱的礼物给她带来了光明。
为您推荐:
扫描下载二维码NCL Frequently Asked Questions (FAQ)
NCL core language
File input/output
Data handling
Data analysis
Visualization
Array functions
Graphical output
Error messages and other issues
Memory issues
Documentation
Miscellaneous
Where can I download NCL?
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
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
setenv PATH=/usr/local/bin:$PATH
From bash or ksh:
export NCARG_ROOT=/usr/local
export PATH=/usr/local/bin:$PATH
NCARG_ROOT=/usr/local
PATH=/usr/local/bin:$PATH
export NCARG_ROOT
export 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
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
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.0
From 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
-enabled version of NCL
[You don't need to worry about these instructions if you are not
using OPenDAP.]
-enabled binaries
require some libraries to be installed on your host computer:
(SSL) library
Once you have these libraries, you may be required to set the
environment variable LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Macs) to
contain the directory where they are located on your host system in
order for OPeNDAP-enabled versions of NCL to work properly.
How do I run NCL?
Once you have NCL installed, you can run it interactively by
typing on the UNIX command line:
This will echo some information to the screen, and give you a prompt:
Copyright (C)
- All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 5.1.0
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
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:
For all other questions on NCL:
For questions relating specifically to NCAR Graphics:
Where can I see some examples of how to use NCL?
To see hundreds of NCL application examples, see the .
These examples are full NCL scripts that you can download. Some of the
are provided
as a separate link.
If you are a complete beginner to NCL, then there's a
described line-by-line.
Are there any NCL command line options I can use?
Yes, see the "" section in the NCL Reference Manual.
Are there any editor enhancements for editing NCL scripts?
Yes, see the
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
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
to print some values, and
you see output like this:
Variable: x
Type: float
Total Size: 80 bytes
Number of Dimensions: 1
Dimensions and sizes:
Coordinates:
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
Number of Dimensions: 1
Dimensions and sizes:
Coordinates:
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
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
capabilities enabled:
ldd `which ncl`
You should see output like:
libnc-dap.so.3 => /usr/local/lib/libnc-dap.so.3 (0x57000)
libdap.so.6 => /usr/local/lib/libdap.so.6 (0xee000)
libdapclient.so.1 => /usr/local/lib/libdapclient.so.1 (0xb9000)
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 = (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)
("OPeNDAP isfilepresent test successful.")
f = (url + filename,"r")
vars = (f)
vars_out = (/"l","j","i","cross","aloan","shot","order","bears"/)
(vars_out)
(vars) These two lists should
(vars_out) be the same.
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. This comment can be at the end of a line
Block comments are a new feature in NCL 6.4.0. Surround the lines to be commented out
and ;/ characters, as in:
All this text is
now part of a
multi-line comment.
Prior to NCL version 6.4.0, there
unfortunately was 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,
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:
str = "" + x
formatted strings.
How do I create a new variable that doesn't contain a _FillValue attribute?
x = (5, float, "No_FillValue")
How do I create a double, long, short, or byte variable without using "new" or one of the conversion routines, like ""?
x = 1. double, x = 1d
(also acceptable)
l = 1 long
s = 5 short
b = 1 byte
The long, short, and byte literals were added in .
How do I include the double quote (") character in an NCL string?
Since NCL uses double quotes to denote strings, you have to add an
extra step to get them into a string. As of V5.1.1, we have a new
for retrieving the double
quote character:
quote = ()
print("The word " + quote + "string" + quote + " has double quotes around it.")
print("'Single' quotes are no big deal.")
If you have an older version, you can do it this way:
quote = (34)
print("The word " + quote + "string" + quote + " has double quotes around it.")
print("'Single' quotes are no big deal.")
Can NCL prompt for user input?
No, not directly, but you can use NCL's
function or its command line
option capability to do this.
"systemfunc" example
("Enter a Number")
ans = (("read ANS; echo $ANS"))
("Number * 10 = "+(ans*10))
Command line argument examples
A more involved way is to write a shell script that queries for input
values. You can then use the NCL command line
argument capability to pass these values as arguments on the NCL
command line.
Shell script example to prompt for a float and a string
Create a shell script called "input.sh":
echo -n "Enter a floating point value: "
echo -n "Enter a title (no quotes): "
read title
eval ncl x=$x \'title=\"$title\"\' your_script.ncl
Create an NCL script called "your_script.ncl" that references "x"
and "title":
;---You can provide a default value for "x" and "title" instead of exiting.
if(.not.isvar("x").or..not.isvar("title")) then
print("No value provided for 'x' and or 'title'. Exiting")
print("x = " + x)
print("title = '" + title + "'")
y = x * 100.
print("y = x*100 = " + y)
Make sure "input.sh" is executable, and run it:
chmod 775 input.sh
./input.sh
This should prompt you for a value and a title and then print some information.
C-Shell script example to prompt for a filename and a level value
Create a c-shell script called "input.csh":
#!/bin/csh -f
echo -n "Input filename: "
set fname = $<
echo -n "Input level value: "
set level = $<
eval ncl level=$level 'fname=\""$fname"\"' your_script.ncl
Create an NCL script called "your_script.ncl" that references
"fname" and "level":
if(.not.("fname")) then
fname = "myfile.nc" Set a default
if(.not.("level")) then
level = 850. Set a default
("filename = '" + fname + "'")
("level = " + level)
;---Do some more stuff in your NCL script...
a = (fname,"r")
T = a->T({level},:,:) Read a 3D variable at a particular level.
Make sure "input.csh" is executable, and run it:
chmod 775 input.csh
./input.csh
This will prompt you for a filename and level value, and pass this
information to the NCL script.
This particular NCL script
will assign these values to normal NCL variables, and then
use them in the script as usual.
You can do this kind of thing with any scripting language you want,
like tcsh, bash, or even Python.
Is it possible to have global variables in NCL?
NCL does not have an explicit way of defining "global
variables". However, NCL's scoping rules, which are similar to
Pascal's, can be used to simulate "global variables" For more
information, see the NCL
reference manual, specifically, the NCL statement documentation.
In a nutshell, if you define a variable above a function,
procedure, or the main code, you can reference it in that
function, procedure, or main code:
PI = 3.14157 Use some naming convention for
global variables [here, all caps]
function area_circ(r:numeric)
return(PI*(r^2))
; Main code
print("PI = " + PI)
radius = 1.5
area = area_circ(radius)
print("area of a circle with radius " + radius + " = " + area)
How can I delete multiple NCL variables with one statement?
In version 6.0.0 and later, you can delete multiple variables of mixed
types and sizes by using the
procedure and
the special syntax "[/" and "/]" around the variables you want to
= (-90,90,64)
= (-180,180,128)
data = (-10,10,(/10,20,30/))
varnames = (/"T","P","U","V"/) 1D string array
([/data,varnames,lat,lon/])
(lon(0)) This will produce an error that "lon" is undefined
This is currently in alpha-test mode.
How do I delete a named dimension?
Unfortunately, this is not possible. If we get a lot of requests for
this capability, then we'll consider adding this functionality.
You can set a named dimension to
"", but this is not quite
the same thing:
x = (/1,2,3/)
x!0 = "this"
Is there a way to see the loaded variables and their dimensions in NCL similar to "whos" in matlab?
procedure.
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:
yields a value of 9 because it behaves as:
x = (-3)^2
Note how the use of parentheses can change the results:
print(- (3+2)^2)
----> yields 25
print(- ((3+2)^2))
yields -25
Finally, 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)?
function with a format like "%0.i"
(the "%0" indicates to fill in the strings with leading zeros where
possible).
For example:
= (0,100,1)
iis = ("%0.3i",ii) "000", "001", ... "100"
How do I get the current date into NCL as a string?
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?
function with the UNIX "ls"
filenames = systemfunc("ls *.txt")
How can I recursively get a list of files in a directory tree into NCL?
function with the UNIX "find"
filenames = ("find /home/haley/data -type f -print")
If you are looking for a specific set of files, like ones that end in
".nc", use the "-name" option:
filenames = ("find /home/haley/data -name '*.nc' -type f -print")
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:
date_str = "The date is " + month + "/" + day + "/" + year
will produce the string "The date is 1/21/2002".
You can use the functions
to generate formatted strings.
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:
filename = "sw" + ("%0.3i",i) + ".out"
...do something with filename...
How do I retrieve an environment variable in NCL?
Use the function :
env_str = ("PATH")
How do I print nicely formatted, multiple columns of data in NCL?
There are several functions that will nicely
format 2D arrays using a user-specified format string. The original
procedure was . This can write to
either a text file or to standard out. It is limited to
one variable of the same type. It use fortran style format syntax.
Two new procedures were introduced in NCL version 6.1.0:
These can handle variables of mixed type. Please see the documentation
and examples for these procedures.
Here's an example on how to use :
= (ave, std, (/N,M/))
(x, "5f7.2", False)
This example will produce the following output:
-0.63 -14.12
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 "" in the
NCL Reference Manual. There's an example on
in the WRAPIT guide.
The functions
can also be used to generate formatted
Can multiple variables be returned from a user created function?
Yes. However, it not as direct as (say) Matlab. In NCL, the return
argument must be of type list. This can contain variables of different
types and sizes.
A schematic example:
undef("foo")
function foo(...)
x = .. type float
y = .. type double
z = .. type string
i = .. type integer
return( [/ x, y, z, i ] ) return as variable of type list
ans = foo(...)
printVarSummary(ans) variable of type list
= ans[0] explicitly extract each return variable
= ans[1] [..] syntax is for variable of type list
delete(ans)
Note: There is no need to explicitly extract the list variables.
They could be accessed as components of 'ans'
Please see the Mini-Language Manual:
Sections 2.18 and 5.7
Click "Support" at top of NCL home page ... Manuals
http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf
Also: http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml
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:
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
For more information on supported file formats in NCL, see the
"" section in the .
How do I dump the contents of a GRIB, HDF, or HDF-EOS file (or variable on the file) to the screen?
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
constraints
then try the
ncl_convert2nc U12345.grb -L
How do I write a large (> 2 GB) variable to a netCDF file?
In order to write large variables to a NetCDF file, you have to set the
NetCDF "Format" option to "LargeFile" or to "NetCDF4Classic".
requires calling
and setting the "Format" using one of these three calls:
("nc","Format","LargeFile")
("nc","Format","NetCDF4Classic")
("nc","Format","NetCDF4")
The reason you have to set this option is that the NetCDF library
requires that this decision be made when the file is first created,
before there is any knowledge of the size of variables that will be
written. We may eventually make this this default, but the current
recommendation from Unidata is to maintain backwards compatibility
where possible for apps that can only deal with the original small
file format of NetCDF.
This will make NCL create a NetCDF4 file, which has no limitation on variable size.
For any of the above three options to function properly,
"setfileoption" must be called prior to ("filename.nc", "c").
How do I get the latest tables for reading GRIB files?
You can use your own text-based tables that you can update
yourself. Start with text-based tables that are downloadable
from our website at .
Click on any of the built-in tables and you will find a link to a
downloadable text-based version that you can use if you set
appropriately. Also read the next section entitled "".
Except for parameters in files created for the TIGGE project, GRIB2
parameters are all defined in text files contained in the
grib2_codetables directory tree. By default this directory is found at
$NCARG_ROOT/lib/ncarg/grib2_codetables. If you want to add parameters
or modify the name, description, or units of any number of parameters, copy the complete directory
tree to your own location, and then set the environment variable NIO_GRIB2_CODETABLES
to the path of this location. The files that relate specifically to
parameter tables can be found in the parallel subdirectories ecmwf/4/ and
ncep/4. They have names of the form 4.2.*.*.table.
Just be sure to maintain the format of these files when modifying or adding
to them. Basically each line contains 5 fields separated by
colons. The parameter number is repeated:
param number:param number:description (long_name attribute):units:short name (must not contain spaces or non-alphanumeric characters)
0:0:Temperature:K:TMP
Why have some of my GRIB2 variable names changed since I updated to NCL ?
If necessary, you can change them back the way they were by setting the environment variable NIO_GRIB2_CODETABLES to the path:
$NCARG_ROOT/lib/ncarg/grib2_codetables.previous. See the release notes for
for an explanation of why they have changed.
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 = (1)
ncid->spherical = spherical
The second way is to use :
filevardef(ncid, "spherical","character","ncl_scalar")
ncld->spherical = tochar(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 . For
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
fils = ("ls /model/annual*nc")
= (fils, "r")
= (f,fils,"T")
How do I access an NCL file variable, attributes, or coordinate arrays if they have hyphens/dashes ('-') 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> (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 ('$'):
(in->$"Data-Set-14"$)
var_string = "Data-Set-14"
print(in->$var_string$)
You can also use $$ for attribute names:
lname = data@$"long-name"$
For more information on using '$' to reference file variables, see the
section "" in
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
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
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:
= 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
For some more complex examples, see the .
For detailed information on the file formats that NCL supports, see
the "" section in the .
How do I read/write ASCII files?
function to read an ASCII file
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 .
How do I read CSV files?
See the "" applications page.
How do I write a formatted ASCII file?
Use a function called
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":
(ave, std, (/N,M/))
res = True
res@fout = "file.txt"
(x, "5f7.2", res)
This example will produce the following output in "file.txt":
-0.63 -14.12
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 :
z = ("file.dat",-1,float)
If you have multiple columns of data, and you know how many columns
there are, then you can use
to restructure
the one-dimensional array returned from
. In the example below, assume there are 4
columns of data:
z = ("file.dat",-1,"float")
number of columns
nrow = (z)/ get number of points
znew = (z,(/nrow,ncol/)) znew will be nrow x ncol
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:
nrow = (("wc -l wgt")) "wc -l" returns the #
of lines in a file
z = ("file.dat",(/nrow,ncol/),"float")
How do I read an ASCII file that contains delimiters?
There's an
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 ,
function, depending on what type of binary file you have.
addition, you may also want to use the functions
getting the number of unformatted Fortran records in a file.
For some complex examples, see the binary read/write examples in
the list of .
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 ,
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?
procedure:
("bin","ReadByteOrder","LittleEndian")
v = ("data.littleEndian.bin",-1,"float")
("bin","WriteByteOrder","BigEndian")
("data.bigEndian.bin",v)
I'm having trouble reading a Fortran binary file with records.
It's possible you are running into a problem where the record marker
was written with 8 bytes, and NCL is expecting the marker to be 4
This happens if the Fortran program that created the binary file was
compiled with a version of "gfortran" that sets the marker
size to whatever "off_t" is on that system.
As a work-around, you can recompile the code that created the binary
file with the option "-frecord-marker=4" to force a 4-byte record, and
run the code again to regenerate the file.
It is on our list to create a new option in
that will allow you to specify the
record marker size that the file was written with.
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
constraints
then you may have what qualifies as a "large file". You need to use
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
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 = ("swath.hdf.hdfeos","r")
Can I read shapefiles using NCL?
NCL currently does not have the ability to read shapefiles.
The NCL development team is looking into this format to determine
the best way these files might be supported.
Meanwhile, some users have emailed us with suggestions which we'll
include here:
- Geospatial Data
Abstraction Library
This package includes a set of command lines tools that are very
handy to work with georeferenced data format (including GeoTiff, HDF
and NetCDF): http://www.gdal.org/gdal_utilities.html.
In particular, you can rasterize vector data (like shapefiles) with
the command "gdal_rasterize".
There's an example in this post on how
to use these tools: http://lists.osgeo.org/pipermail/gdal-dev/2006-June/009369.html
You can also extract the polygon from the vector file into an ascii
file: http://www.gdal.org/ogrinfo.html
package - an
open source GIS binary kit for Windows and Linux
You can use this package to convert shapefiles to text.
The "ogr2ogr" command line utility allows for
type conversion between a variety of GIS related formats (it
hasn't been verified whether NetCDF or HDF is one such format).
A user reported that he converted a shapefile to a Mapinfo file (MIF
format) which is a text format file of lon/lat pairs for each defined
region. You could then read in this text file using NCL's
How can I get at vgroup data on my HDF4 file?
NCL cannot (yet) read vgroup data on an HDF file.
If you install HDF4
on your system (available from http://www.hdfgroup.org/release4/obtain.html),
then you can use the HDF dumper program, "hdp" to get at the vgroup
data you need. You first need to use "hdp dumpvd" on the file to find
out what "Vdata" index your data is in:
hdp dumpvd calipso.hdf
This will produce output like this:
tag = 1962; reference = 34;
number of records = 1; interlace = FULL_INTERLACE (0);
fields = [Product_ID, Date_Time_at_Granule_Start,
Date_Time_at_Granule_End,
Initial_Subsatellite_Latitude,
Initial_Subsatellite_Longitude,
Final_Subsatellite_Latitude,
Final_Subsatellite_Longitude, Lidar_Data_Altitudes];
record size (in bytes) = 1746;
name = class =
number of attributes = 0
- field index 0: [Product_ID], type=4, order=80
number of attributes = 0
You can see that the "Lidar_Data_Altitudes" variable is in vdata 0, so
use this with the hdp command to get the data only:
hdp dumpvd -i 0 -d -f Lidar_Data_Altitudes
calipso.hdf
An alternative approach to extracting the Lidar_Data_Altitudes
is to invoke the hdp command line operator from with an NCL
script. For example:
; input hdf4 file name and the directory where it resides
diri = "./"
fili = "CAL_LID_L1-ValStage1-V3-01.T05-00-22ZN.hdf"
; specify desiredvariable
vari = "Lidar_Data_Altitudes"
; output text file name and the directory where it is to be placed
dirh = "./"
filh = "CAL_LID_L1-ValStage1.height.txt"
; use NCL's system procedure and pipe output to file
system("hdp dumpvd -i 0 -d -f "+vari+" "+diri+fili+" >! "+dirh+filh)
; read the file created by the hdp
= asciiread(dirh+filh, -1, "float")
hjt@long_name = "HEIGHT"
= hgt(::-1) if height need to be reordered
If you are not sure where hdp resides,
from your home directory, try:
find . -name hdp -print
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.1.0.
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
procedure:
f = addfile("newfile.nc","w")
...write stuff to file pointed to by 'f'.
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:
= "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 ((filp)) then
fp = (filp,"r")
print("============================================")
print("CDC_URL : "+CDC_URL)
print("CDC_FILP: "+CDC_FILP)
print("does not exist: message from NCL script")
print("============================================")
x = fp->FOO
I'm running into a problem when opening lots of files with addfile or addfiles ("Too many files open").
If you need to open lots of files with ,
as follows, before you call
setfileoption("nc", "SuppressClose", 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
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 , 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?
function combined with the
function to return a single True or False
indicating whether your data contains missing values:
is_msg = ((data)))
if(is_msg) then
print("'data' contains missing values.")
print("'data' doesn't contain any missing values.")
To count the number of missing values, use the
num_msg = ((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
(data@missing_value) not necessary, just cleaning up
There are other ways to assign a _FillValue attribute. See the
How do I deal with NaN (not-a-number) values in my data?
The computational and plotting functions in NCL cannot handle NaN
values directly. You must first convert the NaN values to missing
To do this, use the
function to
convert the NaNs to missing values. You can optionally use
to first determine if any of your values
are equal to NaN:
If "x" already has a _FillValue attribute:
if (any(isnan_ieee(x))) then
replace_ieeenan (x, x@_FillValue, 0)
If "x" doesn't have a _FillValue attribute:
if (any(isnan_ieee(x))) then
x@_FillValue = 1.e20 or whatever value you want to use
replace_ieeenan (x, x@_FillValue, 0)
How do I deal with "Inf" (infinity) values in my data?
As with NaN values, the computational and plotting functions in NCL
cannot handle "Inf" values directly. You must first convert the "Inf"
values to missing values.
To do this, use the
If "x" already has a _FillValue attribute:
x = where(abs(x).gt.1e20, x@_FillValue, x)
Here's some more generic code to first check if x has a _FillValue
attribute:
if(.not.isatt(x,"_FillValue")) then
x@_FillValue = default_fillvalue(typeof(x))
x = where(abs(x).gt.1e20, x@_FillValue, x)
Data analysis
How do I average values in a multi-dimensioned array?
functions.
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/)/)/)
If you have a multi-dimensional array, say T(ntim,klev,nlat,mlon)
and you wish to obtain the temporal mean at each level, latitude and longitude
T_time_mean
= (temp, 0) (klev,nlat,mlon)
or, to retain meta data:
T_time_mean
= (temp, 0) requires contributed.ncl
If you have a multi-dimensional array, say prc(ntim,nlat,mlon)
containing 3-hourly precipitation rates (eg, mm/hour) and it is desired
to calculate the average precipitation rate for an each day then:
dimprc = (prc)
= dimprc(0) total number of time steps
ntJump = 8 eight samples per day
prcDay = prc(::ntJump,:,:) create array with meta data
ntStrt = 0
ntLast = ntJump-1
do nt=0,ntim-1,ntJump
prcDay(nt/8,:,:) = (prc(ntStrt:ntLast,:,:), 0)
ntStrt = ntStrt + ntJump
ntLast = ntLast + ntJump
If the original data had been total precipitation over a 3-hour span and the
daily total (sum) precipitation had been desired, the approach would be exactly the
same except that
would be used:
prcDay(nt/8,:,:) = (prc(ntStrt:ntLast,:,:), 0)
How can I do an element-wise minimum/maximum between two arrays of the same size?
Use the versatile
xmin = (x1.lt.x2,x1,x2)
xmax = (x1.gt.x2,x1,x2)
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
and look in the interpolation or regridding sections.
example URL has several examples.
As a specific example,
two interpolation functions are
. Here's an example:
; 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 = (0,NX-1,1) * xc
yc = 1./(NY-1.)
yo = (0,NY-1,1) * yc
; Do the gridding using natgrid. "natout" will be a 2-dimensional array
; dimensioned 21 x 21.
natout = (x, y, z, xo, yo)
; Do the gridding using dsgrid2. "dsout" will be a 2-dimensional array
; dimensioned 21 x 21.
dsout = (x, y, z, xo, yo)
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
Here's an example of using :
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 = ((/NX/),float)
yo = ((/NY/),float)
zo = ((/NZ/),float)
; Create the output grid.
xmin = -2.0
ymin = -2.0
zmin = -2.0
ii = (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 = (x, y, z, u, xo, yo, zo)
How can I figure out if a particular latitude/longitude point is within a specific area, like Europe?
There's no ready-made function that will do this based on just the
area name, like "Europe".
However, if you have the lat/lon
coordinates that define the particular area that you're interested in,
then you can use the
Otherwise, assume you have a crude regional approximation that
indicates the area you're interested in, say:
lonW = -10
Further assume you have a data array "x" with coordinate arrays "time" x
"lat" x "lon".
You can then set up a "Europe" mask (eMask):
= conform( work, work&lat, 0)
= conform( work, work&lon, 1)
eMask = new ( (/nlat,mlon/), "logical", "No_FillValue")
eMask = where(LAT.ge.latS .and. LAT.le.latN .and. \
LON.ge.lonE .and. LON.le.lonW,
True, False)
copy_VarCoords(work, eMask) Copy coordinate arrays
; Clean up
delete(work)
delete(LAT)
delete(LON)
To plot an area using your new mask variable to exclude the areas
you're not interested in, see example 5 on
applications page.
Visualization
How can I create an "editable" graphics file required for journal publication?
Use "eps" as an output format, when you open a workstation for sending
the graphics to.
For example, if you're using the
wks = ("eps","myplot")
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
Run the following simple script and compare the two frames:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
data = (10, 10, -19.69, 15.82, 0, (/129,129/))
wks = ("x11","max")
plot = (wks,data,False)
res@ = True
plot = (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
. If your plots are not the
same size, then you can use the
resources , , ,
For some panel examples, see the panel applications page.
page also shows you tricks on paneling plots that are not the same
size ( 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 " 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
to draw the current color
map associated with the workstation:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
wks = ("ncgm","gsn_draw_colormap")
(wks) Draw the default colormap
(wks,"hotres") Change color map and
(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 . 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
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 "" 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 . 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 = ("x11","font") Open an X11 workstation.
y = (/1,3,-1,-2,0,2,3/)
x = (0,(y)-1,1)
res = True
= "This is an XY plot"
res@ = "X values"
res@ = "Y values"
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
How can I change the text function code to something other than a colon?
If you want your
permanently changed (to, say, a '~') for every time
you run NCL, then in the ~./ 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
res@ = "Time : 0600 hours"
then you change the function code associated with this resource to
another character (say '~') with the
res@ = "~"
= "Time : 0600 hours"
If you are setting the X axis label with , then the corresponding function
code resource would be ,
and so on.
How can I get a degree symbol in a text string?
You can use
with the character "0" to get a degree symbol:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
wks = ("x11","degree")
plot mods desired
res@ = "Example degree (~S~o~N~) symbol"
= "Explicit" explicit labels
= (/"20~F34~0~F~","40~F34~0~F~","60~F34~0~F~","80~F34~0~F~"/)
res@ = "Red"
plot = (wks,res)
How can I get things like accents or umlauts over my text?
It's not trivial, but it is doable, using . Here's an example:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
wks = ("x11","text")
; 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"
(wks,str1,0.5,0.7,res) Draw the text string
(wks,str2,0.5,0.3,res)
How can I get special characters, like Greek symbols, in my graphical text strings?
First browse the
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
index 18, for example), and the corresponding character, then you
can use the
'F' to change the font.
For example, to get a bell symbol, you would see that character 'n' in
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@ = "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.
you use NCL , 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
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
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":
wks = ("ps","font_test")
txres = True
txres@ = "low"
txres@ = 0.04
(wks,"Test PS fonts",.5,.5,txres)
txres@ = "down"
(wks,"Vertical",.5,.5,txres)
txres@ = "across"
"degree sign:: :F34:0:FC:superscript:: 1.3:F0L1:4:F:10:S:300",
.5,.5,txres)
I'm having trouble importing a PS file into an application like Adobe Illustrator.
You can try "fixing" the PostScript using an application like "ps2ps" or
"convert" from :
convert test.ps test2.ps
How can I get the length of my axes to be the same ratio as the range of my axes?
You can use the
resources to control the width and
height. You will need to calculate the range of each of your axes, and
then figure out the normalized values (from 0 to 1) to use.
Or, if you are using any of the non-map gsn_xxxx plotting
functions, then you can set the special resource
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
; Generate some dummy data.
z = (20,20,-136.,450.,0,(/ny,mx/))
; Open an X11 window.
wks = ("x11","axes_ratio")
; Generate contour plot with default axes.
res = True
res@ = True
plot = (wks, z ,res)
; Set resource to reshape axes.
res@ = True
plot = (wks, z ,res)
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
The viewport coordinates are
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
to 0.4 and
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
wks = ("x11","viewport") Open an X11 workstation.
y = (/1,3,-1,-2,0,2,3/)
x = (0,(y)-1,1)
res = True
res@ = 0.4
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
to "FreeAspect":
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
wks = ("x11","viewport") Open an X11 workstation.
= "FreeAspect" Allow the aspect ratio to be changed.
map = (wks,"CylindricalEquidistant",mpres)
In the above script, to maximize the plot in the frame but retain the
aspect ratio, the special resource
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
enclosed in double quotes. An ASCII list of the valid color names is
in the file "$NCARG_ROOT/lib/ncarg/database/rgb.txt",
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@ = 2 index value
res@ = "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 = (...)
(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 .
How can I speed up the drawing of filled contours in NCL?
You can try setting the
resource to "RasterFill" (the
default is "AreaFill"), and further set
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
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 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.
should work in all cases in going to NCGM and translating with ctrans.
Producing X11 output works unless you specifically reset the background
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
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"
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)
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@ = i+j*nx
(wks,x,y,res)
Original color map is "black", "red", "green", "blue".
cmap = (/ (/0.,0.,0./), (/1.,0.,0./), (/0.,1.,0./), (/0.,0.,1./) /)
rlist = True
rlist@ = cmap
wks_type = "x11"
wks = (wks_type,"cell")
(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.
(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)
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
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
data = (10, 10, -19.69, 15.82, 0, (/129,129/))
wks = ("pdf,"pdfmax")
res@ = True
plot = (wks,data,res)
Another (but harder) way is when you create your PostScript/PDF
workstation, use the resources , , , and
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 = (type,"psmax")
blank = (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)
to your "~/" 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
attribute of
your data is set to the missing value.
Otherwise:
for contour data - use the
for vector/streamline data, use the
for XY data, use the resources
For a contour example with missing values:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
; Create some dummy data for the contour plot.
7, 7, 7 /),\
5, 5, 7 /),\
5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\
3, 999, 5, 7 /),\
3, 999, 5, 7 /),\
3, 999, 5, 7 /),\
3, 999, 5, 7 /),\
3, 999, 5, 7 /),\
5, 999, 999, 999, 999, 999, 999, 999, 5, 7 /),\
5, 5, 7 /),\
7, 7, 7 /)/)
T@_FillValue = 999 Set _FillValue.
wks = ("x11","contour")
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 = ("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 = (wks,y,False) Create and draw an XY plot.
Note the gaps in the XY curve due to missing values.
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
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
allows you to increase the density of the contour labels, if
set to "Computed" or "Randomized".
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
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"
; Generate some dummy data.
level = (/, 700, 500, 400, 300, 250, 200, 150, 100/)
= (-90,90,20)
= (10, 12, -20., 17., 0, (/ nlev,nlat/))
= "lev" Name the dimensions and
= "lat" attach coordinate arrays
data&lev = This coordinate array is irregulary spaced
data&lat = lat
wks = ("x11","linear")
(wks,"rainbow")
; Set up resources.
= T Maximize plot in frame
= T Span full color map
= T Turn on contour fill
= F Turn off contour lines
= T Control labelbar spacing
= "Irregularly-spaced values"
plot = (wks,data,res) Create filled contours
= "Y axis linearized"
res@ = True
plot = (wks,data,res) Create filled contours
How do I get log scaling on either of my plot axes?
For an XY plot, set the transformation resources
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.
(/10, 100, 00, 70, 300, 1/)
wks = ("x11","logxy") Open an X11 workstation.
xyres = True
xyres@ = "linear"
xyres@ = "linear"
xyplot = (wks,y,xyres) Create and draw the XY plot.
; Change the Y axis scale to be log and redraw the plot.
xyres@ = "log"
xyres@ = T To keep from getting some warning msgs.
xyplot = (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
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.
T = new((/N,N/),float)
jspn = (-N/2,N/2,1)^2
ispn = (-N/2,N/2,1)^2
do i = 0, (ispn)-1
T(i,:) = ispn(i) + jspn
T = 100.0 - (8^2 * T)
wks = ("x11","logcon") Open an X11 workstation.
cnres = True
cnres@ = "linear" Label for X axis.
cnres@ = "log" Label for Y axis.
= T Log scaling for Y axis
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
resources), then you can set the
appropriate
resource to True:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
; Create some dummy data for the contour plot.
T = ((/N,N/),float)
jspn = (-N/2,N/2,1)^2
ispn = (-N/2,N/2,1)^2
do i = 0, (ispn)-1
T(i,:) = ispn(i) + jspn
T = 100.0 - (8^2 * T)
wks = ("x11","logcon")
; Create some dummy data for the Y axis that is not regularly spaced.
750, , , \
, , , , , 5500, \
= Irregular Y axis
cnres@ = T Force Y axis to be log.
= "log" Label for Y axis.
= "linear" Label for X axis.
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
True. If you are using gsn_xxx interfaces,
then you can additionally set
to make sure your full color map
is spanned. To change the default colors used for the contour levels,
to an array of
desired color indexes.
If you want to fill the contour levels with different shading
patterns, you must set
to False, and then set
to an array of
desired fill pattern indexes.
There are : pattern 0 is solid fill, patterns
1-16 are various fill patterns, and pattern 17 is a special
fill pattern.
If you use "-1" for a fill pattern, this means to leave it transparent
(no fill).
There's a function called
that allows you to specify
contour levels where you want specific shading or colors.
Here's an example showing how to create a contou

我要回帖

更多关于 工号牌定制ncyitong 的文章

 

随机推荐