关键词不能为空

当前您在: 主页 > 英语 >

NCL常见错误解决方案

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-09 09:37
tags:

-

2021年2月9日发(作者:transitional)



NCL Frequently Asked Questions (FAQ)



Basics


?|?


NCL core language


?|?


File input/output


?|?


Data handling


?|?


Data


a nalysis


?|?


Visualization

< p>
?|?


Array


functions


?|


Output


formats


?|?


Error


messages


?|?


Memory


issues


?|?


Document ation


?|?


Miscellaneous


?|



Basics



1.



Where can I download NCL



2.



I'm having problems downloading NCL from the ESG website.



3.



How do I set up my environment to run NCL



4.



How do I run NCL



5.



How do I determine the version of NCL



6.



Are there any email lists I can join



7.



Where can I see some examples of how to use NCL



8.



Are there any NCL command line options I can use



9.



Are there any editor enhancements for editing NCL scripts



10.



I


f I'm running NCL interactively, are there any command-line shortcuts I can


use



11.



I


f I'm running interactively, how can I load some existing NCL code



12.



I


s there anyway I can turn off the preceding


of values



13.



M


y NCL script is quitting suddenly, and I'm not sure where and/or why.



14.



H


ow do I tell if I have an OPeNDAP-enabled NCL



NCL core language



1.



How do I comment a line in NCL Is there a way to have a block of comments



2.



Is there a continuation character in NCL



3.



How do I easily convert a number to a string



4.



How do I create a new variable that doesn't contain a _FillValue attribute



5.



How do I create a double, long, short, or byte variable without using


one of the conversion routines, like


integertobyte




6.



How do I include the double quote (



7.



Can NCL prompt for user input



8.



Is it possible to have global variables in NCL



9.



How can I delete multiple NCL variables with one statement



10.



H


ow do I delete a named dimension



11.



I


s there a way to see the loaded variables and their dimensions in NCL similar


to



12.



I


'm getting an unexpected value when I use the power ('^') operator combined


with a negative value.



13.



H


ow


do


I


create


a


list


of


string


integers


with


leading


zeros


(




etc)



14.



H


ow do I get the current date into NCL as a string





15.



H


ow do I get a list of files into an array of strings in NCL



16.



H


ow can I recursively get a list of files in a directory tree into NCL



17.



H


ow do I concatenate strings and values in NCL



18.



H


ow do I retrieve an environment variable in NCL



19.



H


ow do I print nicely formatted, multiple columns of data in NCL



20.



C


an multiple variables be returned from a user created function



File input/output



1.



What's the easiest way to convert a GRIB1, GRIB2, HDF 4, or HDF-EOS 2 file to


a NetCDF file



2.



How do I dump the contents of a GRIB, HDF, or HDF-EOS file (or variable on the


file) to the screen



3.



How do I convert a large file to a NetCDF file



4.



How do I write a large (> 2 GB) variable to a netCDF file



5.



How do I get the latest tables for reading GRIB files



6.



Why have some of my GRIB2 variable names changed since I updated to NCL?How do


I write a scalar to a NetCDF file



7.



How


do


I


retain


metadata


for


a


variable


that


was


read


off


a


series


of


files


using




8.



How do I access an NCL file variable, attributes, or coordinate arrays if they


have hyphens/dashes ('-') in the name



9.



How do I read/write NetCDF, HDF4, HDF- EOS2, GRIB1, GRIB2, or CCM History Tape


files



10.



H


ow do I read/write ASCII files



11.



H


ow do I read CSV files



12.



H


ow do I write a formatted ASCII file



13.



H


ow do I read an ASCII file if I don't know how many lines it contains



14.



H


ow do I read an ASCII file that contains delimiters



15.



H


ow do I read/write binary files



16.



O


nce I've opened a file with


attributes it contains



17.



I


s there a way to control whether my binary file is read or written as little


endian or big endian



18.



I


'm having trouble reading a Fortran binary file with records.



19.



I


'm


trying


to


convert


a


file


to


a


NetCDF


file


using



but


getting


an error message about violating format constraints.



20.



W


hy


do


I


get


different


results


when


reading


my


HDF- EOS2


file,


depending


on


whether


I use the



21.



C


an I read shapefiles using NCL



22.



H


ow can I get at vgroup data on my HDF4 file



23.



W


hen I run my script, I'm getting an error message


Not a valid ID



24.



W


hen I try to access the Climate Diagnostics Center [CDC] OPeNDAP server via


NCL, I get





25.



I


'm running into a problem when opening lots of files with addfile or addfiles


(



Data handling



1.



How do I set a missing value for my data



2.



How do I determine if my data contains any missing values, or count how many


missing values it has



3.



How do I change the missing value to another value



4.



How do I deal with NaN (not-a-number) values in my data



5.



How do I deal with



Data analysis



1.



How do I average values in a multi- dimensioned array



2.



How


can


I


do


an


element-wise


minimum/maximum


between


two


arrays


of


the


same


size



3.



How do I interpolate my 2-dimensional random data to a 2-dimensional gridded


array



4.



How do I interpolate my 3-dimensional random data to a 3-dimensional gridded


array



5.



How


can


I


figure


out


if


a


particular


latitude/longitude


point


is


within


a


specific


area, like Europe



Visualization



1.



How can I create an



2.



How can I maximize the size of a plot in the frame



3.



How do I get multiple plots on a page



4.



What's a good way to generate a color map (table)



5.



My map projection doesn't look right.



6.



How do I change all of my fonts to be the same in my visualization



7.



How can I change the text function code to something other than a colon



8.



How can I get a degree symbol in a text string



9.



How can I get things like accents or umlauts over my text



10.



H


ow


can


I


get


special


characters,


like


Greek


symbols,


in


my


graphical


text


strings



11.



C


an I use real PostScript fonts in my PostScript file



12.



I


'm having trouble importing a PS file into an application like Adobe


Illustrator.



13.



H


ow can I get the length of my axes to be the same ratio as the range of my axes



14.



H


ow do I change the aspect ratio or size of my map or plot



15.



C


an I set color resources by color name rather than color index values



16.



H


ow can I speed up the drawing of filled contours in NCL



17.



C


an I change color index values or color maps in mid-frame



18.



H


ow do I get my PostScript/PDF output to cover most of an 8-1/2



19.



H


ow can I control the size and location of the X11 window that NCL brings up



20.



H


ow do I tell NCL to ignore missing values in my plot





21.



H


ow can I get more labels on my contour lines



22.



M


y X or Y axis values are not linear. How can I change this



23.



H


ow do I get log scaling on either of my plot axes



24.



H


ow


do


I


fill


my


contour


levels


with


various


shading


patterns


and/or


solid


colors



25.



H


ow do I overlay a contour plot (or a vector/streamline plot) on a map



26.



H


ow do I force the tickmarks to point inward



27.



I


'm trying to control the tickmarks on the top or right axis, and nothing is


happening.



28.



H


ow can I improve the resolution of my map outlines



29.



W


hen I draw a map using the high-resolution map database, I seem to randomly


get different resolutions.



30.



H


ow can I get more geographical outlines in my map, like the provinces of China



31.



I


f 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



32.



H


ow do I generate a wire- frame surface or isosurface plot in NCL



33.



H


ow 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



34.



H


ow can I have a new line as part of a graphical text string in NCL



35.



H


ow


come


I


get


different


line


thicknesses


on


different


output


devices


using


the


same thickness value



36.



H


ow can I put a timestamp on my plot



37.



W


hy am I not getting the color I expect when I reference a named color



38.



W


hy is my land not being filled in the color I expect



39.



H


ow do I set up my NCL script so that it uses a resource file



40.



H


ow can I move and resize my labelbar and/or legend



41.



H


ow can I set the precision of the label bar labels



42.



H


ow can I generate some



Array functions



1.



How do I get the dimensions of an array



2.



How do I create unique random subscripts



3.



How do I eliminate missing values from a one-dimensional array



4.



How


do


I


generate


a


one- dimensional


array


of


equally-spaced


integers


or


floating


point numbers



5.



How do I find or print the minimum/maximum values of my data array



Output formats



1.



How do I change the default NCGM/PostScript/PDF file name to something else



2.



How do I convert my NCL graphics file to another format, like PNG, to put on


the web or in a presentation



3.



How do I remove all the white space from an image



4.



Is there a way to make the PostScript files generated by NCL smaller





5.



Can I produce a PNG image directly from NCL



6.



Is there a way to remove the



7.



How can I tilt an NCL graphic



8.



How can I convert a series of PS or EPS files to an animation



9.



How can I produce Google Earth kmz files



10.



H


ow do I convert my multi- frame NCL graphics file to an MPEG movie file



11.



H


ow do I include an encapsulated PostScript file from NCL in a LaTex document



Error messages



1.



When I run my script, I'm getting a



2.



When I run NCL, I get an error message about being unable to load the


Resource File



3.



When I run NCL, I get an error message about the X driver, like


display



4.



What's the deal with the error message



5.



How can I turn off NCL warning messages



6.



I'm trying to list some files, and getting an error



7.



When I try to run ncl, I get an error about



8.



I'm trying to compile my NCAR Graphics program using the Intel or gfortran


compiler, but getting some undefined references.



9.



When I run ncl version I get an error


specification string.



10.



W


hen I run ncl, I get an error about libpng not being current.



11.



I


'm getting an error from WRAPIT about being unable to find



12.



I


'm getting a strange



13.



I



am


trying


to


create


a


contour


plot


and


getting


an


error


about


the


scalar


field


being constant.



14.



I


am trying to create a contour plot and getting errors about sfXArray and


sfYArray having an incorrect dimension size.



15.



I


'm getting an



16.



I


'm getting the error message


FUNCTION CODE



17.



I


'm getting the error



18.



I


'm


getting


an


error


from


the



script


about



being


an


undefined


procedure.



19.



W


hen running a script with overlaid plots, I'm getting an error


Plot Member



20.



W


hen


I


use


NCL's


systemfunc


on


a


X/Cygwin


system,


I


get


the


error



create


child process



21.



W


hen I compile an NCAR Graphics program, I get errors about undefined symbols


like



22.



W


hen I use



23.



I


'm trying to assign a value to an NCL variable, but getting a


can't be coerced to type of left hand side





24.



I


'm calling NCL from a shell script and getting a fatal error on line -1.



25.



I


'm getting an


message.



26.



I


'm


trying


to


draw


primitives


(markers,


lines,


polygons)


on


my


plot,


and


getting


an error essage



27.



W


hen


I


call


one


of


the


gsn_csm_xxxx_map


plotting


scripts,


I


get


an


error


message


about a units attribute not being correct.



28.



I


'm trying to create a contour, vector, or contour plot, and getting a weird


error about spline approximation.



29.



W


hen


I


print


something


in


NCL,


I


get


an


error


about


my


PAGER


environment


variable.



Memory issues



1.



What's the biggest array that NCL can allocate



2.



I'm running into a memory issue when I create lots of strings.



Documentation



1.



Is there a way I can download the NCL website documentation so I can access it


locally on my machine



2.



Where can I see a list of all the NCL resources



3.



Where can I see a list of all the NCL functions and procedures



4.



Where can I see a list of links to dash patterns, marker styles, color tables,


etc



Miscellaneous



1.



How should I cite NCL



2.



How can I add a logo to an NCL plot



3.



How do I call a C or Fortran function or procedure from NCL



4.



How


do


I


make


sure


that


a


C/Fortran


routine


I


want


to


wrap


doesn't


conflict


with


a routine that might already be part of NCL



5.



How do I fix buffering issues with NCL



6.



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



1.



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.



2.



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.



3.



How do I set up my environment to run NCL





o



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


your home directory to see what kind of files you have that start with


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



From sh:



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??(you need to subscribe first).



o



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



.


If


you


are


not


running


on


a


remote


machine,


then


you


can


try


setting


it


to



Please


contact


your


system


administrator


if


you


are


not sure what to set it to.



For example, from C-shell (csh):



setenv DISPLAY :



setenv DISPLAY :0



Set the DISPLAY environment variable to indicate where to display




setenv DISPLAY localhost:



From bash:



export DISPLAY=:



export DISPLAY=:0



export DISPLAY=localhost:



o



Put a



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.



o



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:



1.



2.



Secure Sockets Layer


?(SSL) library



OPeNDAP


?libraries



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.



4.



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 The use of this software is governed by a License


Agreement.



See for more details.



ncl 0>



To quit out of interactive mode, type



To run NCL on an existing NCL script called



ncl



5.



How do I determine the version of NCL



The version number is echoed whenever you run NCL. You can also type


the UNIX command line to get the version number.





6.



Are there any email lists I can join



Yes. For basic questions about installing NCL and setting up your environment to


use it:



all other questions on NCL:



questions relating specifically to NCAR Graphics:



7.



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.



8.



Are there any NCL command line options I can use



Yes, see the


NCL command line options



NCL Reference Manual


.



9.



Are there any editor enhancements for editing NCL scripts



Yes, see the?


support page


?for a list.



10.



I


f 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


Reference Manual


.



11.



I


f 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.



12.



I


s there anyway I can turn off the preceding


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)



(2)



(3)



(4)



(5)



. . .



then you can get rid of the



option


?when you invoke





Variable: x



Type: float



Total Size: 80 bytes



20 values



Number of Dimensions: 1



Dimensions and sizes: [20]



Coordinates:



0








. . .



13.



M


y NCL script is quitting suddenly, and I'm not sure where and/or why.



If you are running an NCL script and getting a


(which


technically


shouldn't


happen,


but


does


on


occasion),


then


try


commenting


out


your




command line option


:



ncl -x



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.



14.



H


ow do I tell if I have an OPeNDAP-enabled NCL



A quick way is to do an


references libraries like


with?


OPeNDAP


?capabilities enabled:



ldd `which ncl`



You should see output like:



=> /usr/local/lib/ (0x0000002a)



=> /usr/local/lib/ (0x0000002a956ee000)



=> /usr/local/lib/ (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 =



filename =



exists =


isfilepresent


(url+filename)



if(. then



print(



print(


servers, or NCL does not have OPeNDAP capabilities on this system



status_exit(1)



else




print


(





f =


addfile


(url + filename,



vars =


getfilevarnames


(f)



vars_out = (/





sqsort


(vars)




sqsort


(vars_out)





print


(vars) These two lists should




print


(vars_out) be the same.



end if



NCL core language



1.



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



;



2.



Is there a continuation character in NCL



Yes, you can use the '' character:



x = (/








; 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))



3.



How do I easily convert a number to a string



Use the '+' string concatenator:





x =



str =



Use?


sprinti

< p>
?or?


sprintf


?for formatted strings.



4.



How do I create a new variable that doesn't contain a _FillValue attribute



5.



x =


new


(5, float,



6.



How do I create a double, long, short, or byte variable without using


one of the conversion routines, like


integertobyte




7.



8.



9.



x = double, x = 1d (also acceptable)



l = 1l long



s = 5h short



10.



b = 1b ; byte



11.



T


he long, short, and byte literals were added in?


do I include the double quote


(



Since NCL uses double quotes to denote strings, you have to add an extra step to


get them into a string. As of we have a new function?


str_get_dq


?for retrieving the


double quote character:



quote =


str_get_dq


()



print(



print(



If you have an older version, you can do it this way:



quote =


inttochar


(34)



print(



print(



12.



Can NCL prompt for user input



No, not directly, but you can use NCL's?


systemfunc


?function or its?


command line


option


?capability to do this.






print


(



ans =


toint


(


systemfunc


(




print


(



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



1.



2.



3.



4.



5.



6.



7.




Create a shell script called



#!/bin/sh




echo -n



read x



echo -n



read title




8.



9.



10.




eval ncl x=$$x 'title=



Create an NCL script called



11.



;---You can provide a default value for



12.



if(.(



13.



print(



14.



exit



15.



end if



16.




17.



print(



18.



print(



19.




20.



y = x * 100.



21.



print(



22.



24.



./



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



25.



27.




28.



echo -n



29.



set fname = $$<



30.




31.



echo -n



32.



set level = $$<



33.




34.



eval ncl level=$$level 'fname=



35.



Create an NCL script called



Create a c-shell script called



26.



#!/bin/csh -f



Make sure



23.



chmod 775



36.



if(.not.


isvar


(



37.



fname =



38.



end if



39.




40.



if(.not.


isvar


(



41.



level = 850. Set a default



42.



end if



43.




44.




print


(



45.




print


(



46.






47.



;---Do some more stuff in your NCL script...



48.



a =


addfile


(fname,



49.



T = a->T({level},:,:) Read a 3D variable at a particular level.



50.



52.



./



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.



13.



I


s it possible to have global variables in NCL



NCL does not have an explicit way of defining


scoping


rules,


which


are


similar


to


Pascal's,


can


be


used


to


simulate



variables


For more information, see the?


NCL reference manual


, specifically, the


NC L?


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 = Use some naming convention for



; global variables [here, all caps]




function area_circ(r:numeric)



begin



return(PI*(r^2))



end




; Main code



begin



print(



radius =




area = area_circ(radius)



print(



end




14.



H


ow can I delete multiple NCL variables with one statement



In version and later, you can delete multiple variables of mixed types and sizes


by


using the?


delete


procedure and


the special syntax


the variables


you want to delete:



lat =


fspan


(-90,90,64)



lon =


fspan


(-1 80,180,128)



data =


random_uniform


(-10,10,(/10,20,30/))



varnames = (/




Make sure



51.



chmod 775




. . .




delete


([/data,varnames,lat,lon/])





print


(lon(0)) This will produce an error that



This is currently in alpha-test mode.



15.



H


ow 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 =



print(x)



x!0 =



print(x)



16.



I


s there a way to see the loaded variables and their dimensions in NCL similar


to



See t he?


list_vars


?procedure.

< p>


17.



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^2



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



whereas:



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)



18.



H


ow


do


I


create


a


list


of


string


integers


with


leading


zeros


(




etc)



Use the?


sprinti


?function with


a format


like


strings with leading zeros where possible). For example:



ii =


ispan


(0,100,1)



iis =


sprinti


(





19.



H


ow 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(



20.



H


ow do I get a list of files into an array of strings in NCL



Use the?


systemfunc


?function with the UNIX



filenames = systemfunc(



21.



H


ow can I recursively get a list of files in a directory tree into NCL



Use the?


systemfunc


?function with the UNIX



filenames =


systemfunc


(



If you are looking for a specific set of files, like ones that end in


the



filenames =


systemfunc


(



22.



H


ow do I concatenate strings and values in NCL



You can use the


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 =



will produce the string



You can use the functions?


sp rinti


?and?


sprintf


?to generate formatted strings. For


example, if you want to construct filenames on the fly with names like


your code would look something like this:



do i=1,10



filename =


sprinti


(



...do something with


filename


...



end do



23.



H


ow do I retrieve an environment variable in NCL



Use the function?


getenv


:



env_str =


getenv


(



24.



H


ow 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?


write_matrix


.


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


?


p rint_table


?and?


write_table


.


These


can


handle


variables


of


mixed


type.


Please


see the documentation and examples for these procedures.



Here's an example on how to use?


write_matrix


:





N = 5



M = 7



ave =



std =



x =


random_normal


(ave, std, (/N,M/))





write_matrix


(x,



This example will produce the following output:

















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



NCL Reference Manual


. There's an example on?


2-dimensional array


printing


?in the?


WRAPIT


?guide.



The functions?


sprinti


?and?


sprintf


?can also be used to generate formatted output.



25.



C


an 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(



function foo(...)



begin



:



:



x = .. type float (:,:)



y = .. type double (:,:,:,:)



z = .. type string (1) a scalar



i = .. type integer (:)




return(


[/


x, y, z, i


]


) return as variable of type


list



end




ans = foo(...)




printVarSummary(ans) variable of type list






x = ans


[0]


explicitly extract each return variable



y = ans


[1]


; [..] syntax is for variable of type list



z = ans


[2]



i = ans


[3]



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 and



Click




input/output



1.



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




where?


xxx


?is


the


file


suffix,


like




or



(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



NCL Reference Manual


.



2.



How do I dump the contents of a GRIB, HDF, or HDF-EOS file (or variable on the


file) to the screen



Use?


ncl_fi ledump


?on the UNIX command line. Some examples:



ncl_filedump ncl_filedump -v


PRES_6_SFC


-ftime


-h


for


a


usage


message.



3.



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?



?option:



ncl_convert2nc -L



4.



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



option


to



or


to



This


requires


calling?


setfileoption


?and


setting the






setfileoption


(




or





setfileoption


(




or





setfileoption


(



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.



NOTE:



For any of the above three options to function properly,


called prior to


addfile


(



5.



How do I get the latest tables for reading GRIB files



GRIB1



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


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?


NCL_GRIB_ PTABLE_PATH


?appropriately. Also read the next section entitled



User-defined GRIB1 parameter tables




GRIB2



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_GRI B2_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?


.*.*.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)



Example:



0:0:Temperature:K:TMP





Why


have


some


of


my


GRIB2


variable


names


changed


since


I


updated


to


NCL?



necessary,


you can change them back the way they were by setting the environment


variable


NIO_GRIB 2_CODETABLES


?to the path: $$NCARG_ROOT/lib/ncarg/. See the release


notes for?


GRIB Updates


?for an explanation of why they have changed.



6.



How do I write a scalar to a NetCDF file



The first way is to use



spherical = new(1,



spherical!0 =



spherical =


tochar


(1)



ncid->spherical = spherical



The second way is to use?


filevardef


:



filevardef(ncid,



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


dimension will not appear, so the variable?


is


?a true NetCDF scalar.



7.



How


do


I


retain


metadata


for


a


variable


that


was


read


off


a series


of


files


using




Use a special function from??called?


addfiles_GetVar


. For example:



load




fils =


systemfunc


(




f =


addfiles


(fils,



T =


addfiles_GetVar


(f,fils,




printVarSummary


(T)



8.



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



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->$$



or





var_string =



print(in->$$var_string$$)



You can also use $$$$ for attribute names:



lname = data@$$



For


more


information


on


using


'$$'


to


reference


file


variables,


see


the


section



File


variable string references



NCL Reference Manual


.



9.



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(



ncfile_out = addfile(




; 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



end



For 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



NCL Reference Manual


.



10.



H


ow do I read/write ASCII files



Use the?


asciiread


?function to read an ASCII file and


the?


a sciiwrite


?or?


write_matrix


?procedures to write an ASCII file.



Here's an example:



;



; Assume the



; 16471 of them.



; the data, and in this case we are passing dimensions (/91,181/), so



;



; be verified by printing the dimsizes of





;



ocean1 = asciiread(



print(dimsizes(ocean1))




;



; Write out part of



; 15 integers, since (7:3:2,0:4) is a 3 x 5 array.



;



asciiwrite(



For more complex examples, see the ASCII read/write examples in the list of?


file


I/O application examples


.



11.



H


ow do I read CSV files



See the


Reading CSV files application




12.



H


ow 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



N = 5



M = 7



ave =



std =



x =


random_normal


(ave, std, (/N,M/))




res = True



res@fout =




write_matrix


(x,



This example will produce the following output in

















13.



H


ow do I read an ASCII file if I don't know how many lines it contains



There are two ways you can do this:



1.



2.



Use


asciiread


:



z =


asciiread


(





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


(




ncol = 4 ; number of columns



nrow =


dimsizes


(z)/ncol ; get number of points



znew =


onedtond


(z,(/nrow,ncol/)) ; znew will be nrow x ncol



3.



4.



5.



6.



7.



Use?


systemfunc


?to count the number of lines in the file before you read


ncol = 4



nrow =


toint


(


systemfunc


(



; of lines in a file



z =


asciiread


(



it. Assuming again that you have a data file with 4 columns of data:



14.



H


ow 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.



15.



H


ow do I read/write binary files



Use the


app ropriate?


cbinread


,?

cbinwrite


,?


craybinrecread< /p>


,?


fbindirread


,?


fbindirwrite


,?


fbinre


ad


,


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?< /p>


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).



16.



O


nce I've opened a file with


attributes it contains



Use the functions?


getfilevar atts


,?


getfilevardims

< br>, 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.



17.



I


s there a way to control whether my binary file is read or written as little


endian or big endian



Use the?


setfileoption


?procedure:




setfileoption


(



v =


cbinread


(





setfileoption


(




cbinwrite


(





18.



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 bytes.



This happens if the Fortran program that created the binary file was compiled with


a


version


of



that


sets


the


marker


size


to


whatever



is


on


that


system.



As a work-around, you can recompile the code that created the binary file with the


option



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?


setfileoption


?that will allow you to


specify the record marker size that the file was written with.



19.



I


'm


trying


to


convert


a


file


to


a


NetCDF


file


using



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



file


You


need


to


use


the?



?option


with ncl_convert2nc.



20.



W


hy


do


I


get


different


results


when


reading


my


HDF- EOS2


file,


depending


on


whether


I use the



If


you


use


the



extension,


then


NCL


uses


the


underlying


HDF4


interface


to


read


your data, whereas if you use the


the HDF-EOS2 library interface.



Using the


since the HDF-EOS2 software provides software to calculate additional lat/lon


information.



Side tip: if your HDF-EOS2 file has an


read this file as an HDF-EOS2 file simply by appending an


file


name


in


the?


addfile


?call


(you


don't


need


to


rename


the


file).


For


example,


if


your


file is called



a =


addfile


(



21.



C


an 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:





GDAL


?- 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):? particular,


you


can


rasterize


vector


data


(like


shapefiles)


with


the


command



There's an example in this post on how to use these tools:? can also extract the


polygon


from


the


vector


file


into


an


ascii


file:?


FWTools


?packag e


-


an


open


source


GIS binary kit for Windows and Linux



You


can


use


this


package


to


convert


shapefiles


to


text.


The



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?


asciiread

< br>?function.



22.



H


ow 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


then


you


can


use


the


HDF


dumper


program,



hdp



to


get


at


the


vgroup


data


you need. You first


need


to use


on the file to


find out what


your data is in:



hdp dumpvd



This will produce output like this:



Vdata: 0



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 = metadata; class = metadata;



number of attributes = 0



- field index 0: [Product_ID], type=4, order=80



number of attributes = 0



. . .



You


can


see


that


the



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



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 =




; specify desiredvariable



vari =




; output text file name and the directory where it is to be placed



dirh =



filh =




; use NCL's


system


procedure and pipe output to file




system


(




; read the file created by the


hdp



hgt =


asciiread


(dirh+filh, -1,



hgt!0 =



hjt@long_name =



hgt@units =




hgt = 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




23.



W


hen I run my script, I'm getting an error message


Not a valid ID



You


should


only


see


this


error


if


you


are


using


version 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?


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(



...write stuff to file pointed to by 'f'.




delete


(f)



end





24.



W


hen I try to access the Climate Diagnostics Center [CDC] OPeNDAP server via


NCL, I get



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??with:



o



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.



o



o



The name of your institution.



A one-line blurb about your intended use of the data.



See the??URL for the complete story.



After registration with CDC, an NCL script might look like:



CDC_URL =



CDC_FILP =




filp = CDC_URL + CDC_FILP



if (


isfilepresent


(filp)) then



fp =


addfile


(filp,



else



print(



print(



print(



print(



print(



exit



end if




x = fp->FOO



25.



I


'm running into a problem when opening lots of files with addfile or addfiles


(



If


you


need


to


open


lots


of


files


with?


addfiles


,


then


call?


setfile option


?as


follows,


before you call?


addfiles


:



setfileoption(



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



1.



How do I set a missing value for my data



For the variable that contains your data, set the attribute


_FillValue



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


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.



2.



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(



else



print(



end if



To count the number of missing values, use the?


num


?function:



num_msg =


num


(< /p>


ismissing


(data)))



print(



3.



How do I change the missing value to another value



If


your


data


contains


a



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


as


an


official


missing


value.


You


want


to


set


the



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.



4.



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 values.



To


do


this,


use


the?


replace_ieeenan


?function


to


convert


the


NaNs


to


missing


values.


You can optionally use


isnan_ieee


?to first determine if any of your values are equal


to NaN:





If



if (any(isnan_ieee(x))) then



replace_ieeenan (x, x@_FillValue, 0)



end if



If



if (any(isnan_ieee(x))) then



x@_FillValue = or whatever value you want to use



replace_ieeenan (x, x@_FillValue, 0)



end if



5.



How do I deal with



As with NaN values, the computational and plotting functions in NCL cannot handle




To do this, use the?


where


?funct ion:



If



x = where(abs(x)., x@_FillValue, x)



Here's some more generic code to first check if x has a _FillValue attribute:



if(.(x,



x@_FillValue = default_fillvalue(typeof(x))



end if



x = where(abs(x)., x@_FillValue, x)



Data analysis



1.



How do I average values in a multi-dimensioned array



Use the?


avg


,?


dim_avg_n


?or?


dim_avg


?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 :



x = (/(/(/2,3/), (/4,5/), (/1,2/)/), (/(/3,8/), (/1,4/), (/0,2/)/)/)



y =


avg


(x)



If you have a multi-dimensional array, say?


T(ntim,klev,nlat,mlon)


?a nd you wish to


obtain the temporal mean at each level, latitude and longitude then:




T_time_mean =


dim_avg_n


(temp, 0) (klev,nlat,mlon)




or, to retain meta data:






T_time_mean =


dim_avg_n_Wrap


(temp, 0) requires




If


you


have


a


multi-dimensional


array,


say?


prc(ntim,nlat,mlon)

< br>?containing


3-hourly


precipitation rates (eg, mm/hour) and it is desired to calculate the average


precipitation rate for an each day then:




dimprc =


dimsizes


(prc)



ntim = dimprc(0) total number of time steps



ntJump = 8 ; eight samples per day (=24/3)




prcDay = prc(::ntJump,:,:) create array with meta data




ntStrt = 0



ntLast = ntJump-1



do nt=0,ntim-1,ntJump



prcDay(nt/8,:,:) =


dim_avg_n


(prc(ntStrt:ntLast,:,:), 0)



ntStrt = ntStrt + ntJump



ntLast = ntLast + ntJump



end do





printVarSummary


(prcDay)




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?


dim_s um_n


?would be used:




prcDay(nt/8,:,:) =

< p>
dim_sum_n


(prc(ntStrt:ntLast,:,:), 0)




2.



How


can


I


do


an


element- wise


minimum/maximum


between


two


arrays


of


the


same


size



Use the vers atile?


where


?function:



xmin =


where




xmax =


where




3.



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.



The?


Random Data to Grid


?example URL has several examples. As a specific example,


two interpolation functions are?


natgrid


?or?


dsgrid2


. Here's an example:



NX = 21



NY = 21




; Define the input data arrays.





x = (/, , , , ,



y = (/, , , , ,



z = (/, , , , ,




; 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.



; dimensioned 21 x 21.



natout =


natgrid


(x, y, z, xo, yo)




print


(natout)




; Do the gridding using dsgrid2.



; dimensioned 21 x 21.



dsout =


dsgrid2


(x, y, z, xo, yo)




print


(dsout)



4.



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?

< br>triple2grid


?and?


dsgrid3


.



Here's an example of using?


dsgrid3


:



NX = 21



NY = 21



NZ = 21



x = (/, , , , ,



y = (/, , , , ,



z = (/, , , , ,



u = x*x + y*y + z*z




xo =


new


((/NX/),float)



yo =


new


((/NY/),float)



zo =


new


((/NZ/),float)




;



; Create the output grid.



;



xmin =



ymin =





zmin =



xmax =



ymax =



zmax =




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 =


dsgrid3


(x, y, z, u, xo, yo, zo)




print


(output)



5.



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



the lat/lon coordinates that define


the particular area


that you're interested in, then you can use the


gc_inout


?func tion.



Otherwise, assume you have a?


crude


?regional approximation that indicates the area


you're interested in, say:



latS = 36



latN = 70



lonW = -10



lonE = 60



Further assume you have a data array



eMask


):



work = x(0,:,:)



LAT = conform( work, work&lat, 0)



LON = conform( work, work&lon, 1)



eMask = new ( (/nlat,mlon/),



eMask = where .and. .and.



.and. 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 the?


mask


?applications page.





Visualization



1.



How can I create an



Use



as


an


output


format,


when


you


open


a


workstation


for


sending


the


graphics


to.



For example, if you're using the?


gsn_open_wks


?function:



wks =


gsn_open_wks


(



2.



How can I maximize the size of a plot in the frame



If you are using one of the?


gsn_


xxx


?pl otting scripts, then set the special


re source?


gsnMaximize


?to True.



Run the following simple script and compare the two frames:



load




data =


generate_2d_array


(10, 10, , , 0, (/129,129/))




wks =


gsn_open_wks


(




plot =


gsn_con tour


(wks,data,False)




res = True



res@


gsnMaximize


= True



plot =


gsn _contour


(wks,data,res)



3.



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).



4.



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 valuesHSV


?color wheel and how it helps you create a color map.



For an example, try modifying the HSV values in the file


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




wks =


gsn_open_wks


(




gsn_draw_colormap


(wks) Draw the default colormap







gs n_define_colormap


(wks,




gsn_draw_colormap


(wks) ; draw it.



5.



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?


mpMaxL onF


:



res@mpCenterLonF = (res@mpMinLonF + res@mpMaxLonF)/2.



6.



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, .




If


you


always


want


to


use


this


font


in


all


of


your


NCL


scripts,


then


put


the


following


line in a file called


.hluresfile




*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


running any NCL scripts.



If


you want this font to apply only to a particular NCL


script, first


create a file


called?,


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



load




wks =


gsn_open_wks


(




y = (/1,3,-1,-2,0,2,3/)



x =


ispan


(0,


dimsizes


(y)-1,1)




res = True



res@


tiMainString


=



res@


tiXAxisString


=



res@


tiYAxisString


=




xy =


gsn_xy


(wks,x,y,res) Create and draw an XY plot.



The



! Change all fonts to times-bold





*Font : times- bold



Try


changing



in


the



file


to


other


fonts


to


see


the


results.


Use


either


a font name or a font index as listed in the?


font tables


.



7.



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


=



then


you


change


the


function


code


associated


with


this


resource


to


another


character


(say '~') with the


txFuncCode


?resource:



res@


txFuncCode


=



res@


txString


=



If you are setting the X axis label with?


tiXAxisString


, then the corresponding


function code resource would be


tiXAxisFuncCode


, and so on.



8.



How can I get a degree symbol in a text string



You can use?


font table 34


?with the character



load




begin



wks =


gsn_open_wks


(




res = True ; plot mods desired




res@


tiMainString


=




res@


tmXBMode


=



res@


tmXBValues


= (/ , , ,



res@


tmXBLabels


=


(/



res@


tmXBLabelFontColor


=




plot =


gsn_blank_plot


(wks,res)



end



9.



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






begin




wks =


gsn_open_wks


(




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



; :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 =




;



; 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 =





gsn_text_ndc


(wks,str1,,,res) ; Draw the text string




gsn_text_ndc


(wks,str2,,,res)





frame


(wks)



end



10.



H


ow


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


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



any text string resource to indicate you want a bell symbol. The


to the original font.



For example, to use it in a title:



res@


tiMainString


=



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.



11.



C


an 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



then


you


will


get


NCL?


font


21


?which


is


a


Helvetica


font


that


is


drawn


using


filled areas, . 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


resou rce?


txFontQuality


?to



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



begin



wks =


gsn_open_wks


(




txres = True



txres@


txFontQuality


=



txres@


txFontHeightF


=



txres@


txFuncCode


=




gsn_text_ndc


(wks,




frame


(wks)






txres@


txDirection


=




gsn_text_ndc


(wks,




frame


(wks)




txres@


txDirection


=




gsn_text_ndc


(wks,





.5,.5,txres)




frame


(wks)



end



12.



I


'm having trouble importing a PS file into an application like Adobe


Illustrator.



You can try


PostScript using an


application like



or



fro m?


ImageMagick


:



convert



13.



H


ow can I get the length of my axes to be the same ratio as the range of my axes



You can use the?


vpWidthF


?and?


vpHeightF


?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


gsnShape


?to True:



load



load




begin



ny = 100



mx = 50




; Generate some dummy data.



z =


gener ate_2d_array


(20,20,-136.,450.,0,(/ny,mx /))




; Open an X11 window.



wks =


gsn_open_wks


(




; Generate contour plot with default axes.



res = True



res@


gsnMaximize


= True




plot =


gsn_csm_contour


(wks, z ,res)




; Set resource to reshape axes.



res@


gsnShape


= True



plot =


gsn_csm_contour


(wks, z ,res)






end



14.



H


ow 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


?a nd?


vpHeightF


. The viewport coordinates are


normalized; that is, they take values from to (inclusive).



For example, if you want your plot to be wider than it is high, then you might


set?


vpWidthF


?to and


vpHeightF


?= :



load



load




wks =


gsn_open_wks


(




y = (/1,3,-1,-2,0,2,3/)



x =


ispan


(0,


dimsizes


(y)-1,1)




res = True



res@


vpWidthF


=



res@


vpHeightF


=




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


as above, but you must also set the resource?


mpShapeMode


?to



load




wks =


gsn_open_wks


(




mpres = True



mpres@


mpShapeMode


=



mpres@


gsnMaximize


= True



mpres@


vpWidthF


=



mpres@


vpHeightF


=




map =


gsn_map


(wks,



In


the


above


script,


to


maximize


the


plot


in


the


frame


but


retain


the


aspect


ratio,


the special resource


gsnMaximize


?is set to True.



15.



C


an 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/



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


=




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:



(/(/,,,(/,,,(/,,,(/,,,



(/,,,(/,,,(/,,,(/,,,



(/,,,(/,,,(/,,,(/,,,



(/,,,(/,,,(/,,,(/,,,



(/,,/)



and


you


also


want


to


include


the


named


colors






and



...



cmap = (/
















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


.



16.



H


ow can I speed up the drawing of filled contours in NCL



You can try setting the?


cnFillMode


?resource to



and


further

< p>
set


cnRasterSmoothingOn


?to


True


if


you


want


smoother


contours.



17.



C


an 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.



-


-


-


-


-


-


-


-



本文更新与2021-02-09 09:37,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/620368.html

NCL常见错误解决方案的相关文章