ncl 例子.docx
- 文档编号:9097248
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:64
- 大小:61.41KB
ncl 例子.docx
《ncl 例子.docx》由会员分享,可在线阅读,更多相关《ncl 例子.docx(64页珍藏版)》请在冰豆网上搜索。
ncl例子
如何设置你的NCL环境
您可以使用NCL之前,必须做四件事:
1.设置NCARG_ROOT环境变量。
2.添加$NCARG_ROOT/bin您的UNIX搜索路径。
3.确保你的显示正确地设置环境变量。
4.放一个.hluresfile文件在您的主目录。
1.设置NCARG_ROOT环境变量。
NCARG_ROOT环境变量设置为根目录的NCL软件安装。
例如,如果安装了NCL/usr/local/bin/usr/local/lib,那么NCARG_ROOT应该设置为/usr/local.
设置这个环境变量,你必须知道你什么样的UNIXshell环境运行。
通常,输入:
echo$SHELL
在UNIX命令行会告诉你这个信息。
如果它说类似“/bin/tcsh”或“/bin/csh”,那么你可以设置环境变量如下(使用“/usr/local”为例):
setenvNCARG_ROOT/usr/local
如果它说“/bin/bash”或“/bin/ksh”,然后使用:
exportNCARG_ROOT=/usr/local
如果它说“/bin/sh”,然后使用这两行:
NCARG_ROOT=/usr/local
exportNCARG_ROOT
有类型这些命令在每次登录时,最好将这些线(或线)添加到适当的”。
在您的主目录*”文件。
(~/。
cshrc或~/。
bashrc是两个例子,(一定要使用一个适合您正在运行shell环境。
)
NCARG_ROOT美元/bin添加到你的搜索路径。
这是必要的,当您运行NCL系统知道在哪里可以找到“NCL”可执行。
首先,你需要找出当前UNIX路径设置。
这通常发生在一个的”。
在您的主目录*”文件。
你可以搜索通过输入路径设置:
grep-ipath~/.*
如果你看到类似这些线之一:
setpath=(~/bin/usr/bin/bin/etc/usr/X11R6/bin/usr/local/bin)
或
exportPATH=~/bin:
/usr/bin:
/bin/etc:
/usr/X11R6/bin:
/usr/local/bin
然后你可以编辑这个文件,并添加“NCARG_ROOT美元/bin”路径的列表:
setpath=(~/bin/usr/bin/bin/etc/usr/X11R6/bin/usr/local/bin$NCARG_ROOT/bin)
或
exportPATH=~/bin:
/usr/bin:
/bin/etc:
/usr/X11R6/bin:
/usr/local/bin:
$NCARG_ROOT/bin
设置显示环境变量。
为了运行NCL脚本显示他们的直接输出一个X11窗口,你需要显示环境变量设置正确。
通常你可以测试这个马上通过调用一个X应用程序是否正确。
一个好的测试X应用程序“xeyes”:
xeyes
如果一双眼睛在屏幕上弹出,然后你的显示环境变量已经被正确设置。
如果不是,你得到一个错误消息:
Error:
Can'topendisplay
然后你需要设置显示环境变量。
显示环境变量需要设置为机器的IP地址,你是显示X11窗口,而不是机器的IP地址,您正在运行NCL。
所以,例如,如果你是登录到一台机器叫做“buffy.ucar.edu”(IP地址111.12.14.16)和运行NCL从那里,但显示图形的机器称为“xander.ucar.edu”(IP地址111.12.15.17),然后在窗口中登录到“巴菲”,类型:
setenvDISPLAY111.12.15.17:
0
(见以上说明设置环境变量对不同类型的壳。
你可能,此外,从一个窗口,你登录“xander”需要类型:
xhost111.12.14.16
这告诉xander的机器,可以让程序由“巴菲”被显示在监视器。
再一次,与上面的NCARG_ROOT环境变量中,您可能想要将这些行添加到适当的”。
在您的主目录*”文件。
如果上面的不工作,那么请检查与您的系统管理员。
”。
在您的主目录hluresfile”文件。
为了更好地定制NCL图形环境,我们强烈建议你复制一个.hluresfile到您的主目录。
您可以定制这个文件对你的喜欢,但至少,你想改变默认的字体,默认颜色表,函数代码的文本。
如何运行NCL
一旦你的NCL环境已经正确设置,您已经准备好运行NCL。
如果你已经有一个NCL脚本,说“欧米茄。
ncl”,您可以运行它通过键入:
nclomega.ncl
如果你没有一个NCL脚本运行,和你想要运行一个示例,然后输入:
ng4exgsun01n
这应该复制一个NCL脚本称为“gsun01n。
ncl”您的当前工作目录并运行
1.load"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl";LoadtheNCLfilethatcontainsthegsn_*
2.;functionsusedbelow.
3.begin
4.x=new(9,float);Definetwo1Darraysof9elementseach.
5.y=new(9,float)
6.
7.x=(/10.,20.,30.,40.,50.,60.,70.,80.,90./)
8.y=(/0.,0.71,1.,0.7,0.002,-0.71,-1.,-0.71,-0.003/)
9.
10.wks=gsn_open_wks("x11","gsun01n");OpenanX11workstation.
11.
12.plot=gsn_xy(wks,x,y,False);DrawanXYplotwith1curve.
13.
14.;-----------Beginsecondplot-----------------------------------------
15.
16.y2=(/(/0.,0.7,1.,0.7,0.,-0.7,-1.,-0.7,0./),\
17.(/2.,2.7,3.,2.7,2.,1.3,1.,1.3,2./),\
18.(/4.,4.7,5.,4.7,4.,3.3,3.,3.3,4./)/)
19.
20.x@long_name="X";Defineattributesofx
21.y2@long_name="Y";andy2.
22.
23.plot=gsn_xy(wks,x,y2,False);DrawanXYplotwith3curves.
24.
25.;-----------Beginthirdplot-----------------------------------------
26.
27.resources=True;Indicateyouwantto
28.;setsomeresources.
29.
30.resources@xyLineColors=(/2,3,4/);Definelinecolors.
31.resources@xyLineThicknesses=(/1.,2.,5./);Definelinethicknesses
32.;(1.0isthedefault).
33.
34.plot=gsn_xy(wks,x,y2,resources);DrawanXYplot.
35.
36.;----------Beginfourthplot------------------------------------------
37.
38.resources@tiMainString="X-Yplot";TitlefortheXYplot
39.resources@tiXAxisString="XAxis";LabelfortheXaxis
40.resources@tiYAxisString="YAxis";LabelfortheYaxis
41.resources@tiMainFont="Helvetica";Fontfortitle
42.resources@tiXAxisFont="Helvetica";FontforXaxislabel
43.resources@tiYAxisFont="Helvetica";FontforYaxislabel
44.
45.resources@xyMarkLineModes=(/"Lines","Markers","MarkLines"/)
46.resources@xyMarkers=(/0,1,3/);(none,dot,asterisk)
47.resources@xyMarkerColor=3;Markercolor
48.resources@xyMarkerSizeF=0.03;Markersize(default
49.;is0.01)
50.
51.plot=gsn_xy(wks,x,y2,resources);DrawanXYplot.
52.
53.;----------Beginfifthplot------------------------------------------
54.
55.filename="$NCARG_ROOT/lib/ncarg/data/asc/xy.asc"
56.
57.data=asciiread(filename,(/129,4/),"float")
58.
59.uv=new((/2,129/),float)
60.uv(0,:
)=data(:
1)
61.uv(1,:
)=data(:
2)
62.
63.lon=data(:
0)
64.lon=(lon-1)*360./128.
65.
66.delete(resources);Startwithnewlistofresources.
67.
68.resources=True
69.
70.resources@tiMainString="U/Vcomponentsofwind"
71.resources@tiXAxisString="longitude"
72.resources@tiYAxisString="m/s"
73.resources@tiXAxisFontHeightF=0.02;Changethefontsize.
74.resources@tiYAxisFontHeightF=0.02
75.
76.resources@xyLineColors=(/3,4/);Setthelinecolors.
77.resources@xyLineThicknessF=2.0;Doublethewidth.
78.
79.resources@xyLabelMode="Custom";LabelXYcurves.
80.resources@xyExplicitLabels=(/"U","V"/);Labelsforcurves
81.resources@xyLineLabelFontHeightF=0.02;Fontsizeandcolor
82.resources@xyLineLabelFontColor=2;forlinelabels
83.
84.plot=gsn_xy(wks,lon,uv,resources);DrawanXYplotwith2curves.
85.
86.delete(plot);Cleanup.
87.delete(resources)
88.end
Explanationofexample1
Line1:
load"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
LoadtheNCLscriptthatcontainsthefunctionsandprocedures(theonesthatstartwith"gsn_")thatareusedinthisexample.The load statementinNCLworksmuchlike include worksinCandFortran90programs.
Line3:
begin
StarteveryNCLscriptwiththe begin statementandenditwiththe end statement.
Lines4-5:
x=new(9,float)
y=new(9,float)
Declaretwo1-dimensionalfloatarraysof9elementseachwiththe new statement.Thefirstargumentof newindicatesthedimensionalityofthevariable,andthesecondargumentitstype.Inthiscase,thetwo newstatementsareredundant,becauseinNCLyoucandeclarevariablesbyinitializingthem(asyoudointhenexttwolines).
ForanoverviewofNCL'svariabletypes,seethe"NCLdatatypesoverview"sectionofthe NCLReferenceManual.
Lines7-8:
x=(/10.,20.,30.,40.,50.,60.,70.,80.,90./)
y=(/0.,0.71,1.,0.7,0.002,-0.71,-1.,-0.71,-0.003/)
Assignvaluestothe1-dimensionalarraysyoujustdeclared.Inanassignmentstatement,acomma-separatedlistofarrayvaluesisprecededby"(/"andterminatedby"/)".ArraysinNCLaremodeledafterarraysintheCprogramminglanguage;thatis,theyarerow-majorandbeginatindex0(insteadofcolumn-majorandindex1asinFortran).
Line10:
wks=gsn_open_wks("x11","gsun01n")
ToproducegraphicswithNCL,youneedtotellitwheretodrawthegraphics.Thechoices,whicharealsoknownas workstations,areanX11window,anNCARGraphicsmetafile(NCGM),oraPostScriptfile(regular,encapsulated,orencapsulatedinterchange).
Thefunction gsn_open_wks opensoneofthesetypesofworkstationssoyoucandrawgraphicstoit.Thefirstargument(a string)indicateswhereyouwantthegraphicaloutputdrawn("x11"foranX11window,"ncgm"foranNCGM,and"ps","eps",or"epsi"foraPostScriptfile).Thesecondargument(alsoa string)determinesthenameofthefileifyoudrawthegraphicaloutputtoanNCGMoraPostScriptfile(name.ncgm foranNCGMfile,and name.{ps,eps,epsi} foraPostScriptfile,where name isthesecondstringyoupassin).Thesecondargumentalsocomesintoplaywhen resourcefiles arediscussedin example8 and 9.
Thevaluereturnedfrom gsn_open_wks isaspecialvariableoftype graphic,whichisanNCLvariabletypetodefinegraphical objects.
Line12:
plot=gsn_xy(wks,x,y,False)
Thefunction gsn_xy createsanddrawsanXYplotandreturnstheXYplotasavariableoftype graphic (inmostcases,youprobablywon'tneedtodoanythingwiththisreturnvalue).ThefirstargumentistheworkstationyouwanttodrawtheXYplotto(thevariablereturnedfromthepreviouscallto gsn_open_wks).ThenexttwoargumentsarethevariablescontainingtheXandYarraysthatyouwanttoplot.Thesetwoargumentscanbeoftype float, double,or integer andcanbe1-dimensionalormulti-dimensional(explainedbelow).Thelastargumentisa logical valueindicatingwhetheryouhavesetany"resources"forchangingthelookofaplot.TogetthedefaultXYplotthatNCLprovides,passthevalue False forthelastargument(inNCL,logical valuesaresetwiththespecialkeywords True or False,whichbothmustbecapitalized).
The gsn_xy functiondrawstheXYplotwith tickmarks selectedat"nice"values.NotitleorX/Yaxislabelsareprovidedinthedefaultplot,butthesecanbeeasilyaddedasshowninthenextfewplots.Youcanalsochangethestyleofthetickmarksasshownin example7.
Bydefault,whenaplotisdrawntoanX11windoworanNCGMfile,ithasablackbackgroundandawhiteforeground.IfaplotisdrawntoaPostScriptfile,ithasawhitebackgroundandablackforeground.Inlaterexamples,youwilllearnhowtospecifythebackgroundandforegroundcolors,andwhenyoudothis,theplothasthesamecolors,nomatterwhichworkstationyoudrawitto.
Sinceyouopenedaworkstationtypeof"x11",the gsn_xy functionproducesanX11windowonwhichyouneedtoclickwiththeleftmousebuttontoadvancetothenextframe.
Line14:
;-----------Beginsecondplot-----------------------------------------
Dividerinthecodetoindicatethestartofthecodeforthesecondplot.
DrawanXYplotwiththreecurves,eachcurvehavingninepoints.
Lines16-18:
y2=(/(/0.,0.7,1.,0.7,0.,-0.7,-1.,-0.7,0./),\
(/2.,2.7,3.,2.7,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ncl 例子