NCL Examples
NCL基本使用及实例演示
![NCL基本使用及实例演示](https://img.taocdn.com/s3/m/51c82cd5b14e852458fb571e.png)
10年9月9日星期四
NCL基本语言特性
文档:/Document/ 类似Fortran、C,不过是脚本 主要步骤:
• • • •
载入脚本 读入数据 处理数据 图形显示
执行脚本:
> ncl <脚本名称>.ncl <参数>=<值> ... 注意:如果传入字符串,则\”<值>\”
2
10年9月9日星期四
• NCL的网站 • NCL的下载及安装 • NCL的基本语言特性 • NCL的实例
3
10年9月9日星期四
4
10年9月9日星期四
5
10年9月9日星期四
6
10年9月9日星期四
7
10年9月9日星期四
8
10年9月9日星期四
9
10年9月9日星期四
contributed.ncl - 一些用户贡献的脚本
clmDayTLL(函数) /Document/Functions/Contributed/index.shtml 16
10年9月9日星期四
NCL基本语言特性
一、读入数据
自描述数据格式:NetCDF、HDF 、GRIB f = addfile(“<目录>/<文件名>.<扩展名>”, “<文件模式>”)
11
10年9月9日星期四
NCL的安装
下载需要在ESG网站上注册用户,根据需要下载相应的压缩包 NCL无须编译,直接解压缩即可
安装:(对于Windows,需要安装Cygwin/X,比较繁琐,但也是可以安装)
> tar xzf ncl_ncarg-5.2.1.<...>.tar.gz -C <存放目录> > cd ~; vi .bashrc export NCARG_ROOT=<存放目录> export PATH=$PATH:$NCARG_ROOT/bin 可能遇到无法找到库的问题,应根据实际情况安装相应库
ncl 计算趋势系数
![ncl 计算趋势系数](https://img.taocdn.com/s3/m/c9a8c77582c4bb4cf7ec4afe04a1b0717fd5b31d.png)
ncl 计算趋势系数
; 读取NetCDF文件 f = addfile("datafile.nc", "r")
; 读取时间序列数据 data = f->data
; 计算趋势系数 trend = linregres(data, (/0, n-1/))
ncl 计算趋势系数
; 打印趋势系数 print("趋势系数: ", trend(0))
; 关闭文件 f->close() ``` 在上述代码中,首先导入了NCL的相关库,然后使用`addfile`函数打开NetCDF文件并读 取时间序列数据。接下来,使用`linregres`函数计算趋势系数,其中`data`为输入的时间序列 数据,`(/0, n-1/)`表示计算整个时间范围的趋势系数。最后,使用`print`函数打印计算得到 的趋势系数。
ncl 计算趋势系数
NCL(NetCDF Command Language)是一种用于处理和分析NetCDF数据的编程语言 。在NCL中,可以使用内置的函数和工具来计算趋势系数。以下是一个示例代码,用于计算 一维时间序列数据的趋势系数:
```ncl ; 假设有一个名为"data"的一维时间序列变量 ; 其维度为time,长度为n ; 可以使用linregres函数计算趋势系数
ncl 计趋势系数
请注意,上述代码仅适用于一维时间序列数据。如果数据具有多个维度,需要根据实际情 况进行相应的调整。此外,NCL还提供了其他用于计算趋势系数的函数和方法,可以根据具 体需求选择合适的方法进行计算。
ncl排序函数
![ncl排序函数](https://img.taocdn.com/s3/m/cd59155a6fdb6f1aff00bed5b9f3f90f76c64de2.png)
ncl排序函数NCL排序函数是一种强大的工具,可以帮助我们对数据进行排序和整理。
在这篇文章中,我将详细介绍NCL排序函数的使用方法,以及它对我们日常工作的帮助。
让我们来了解一下什么是NCL排序函数。
NCL是一种编程语言,它专门用于气象数据分析和可视化。
排序函数是NCL中的一个重要功能,它可以按照规定的顺序对数据进行排序,以便我们能够更好地理解和分析数据。
在使用NCL排序函数之前,我们需要确保数据已经准备好并导入到NCL环境中。
一旦我们完成了这些准备工作,就可以使用NCL排序函数来对数据进行排序了。
NCL排序函数提供了多种排序算法,包括冒泡排序、插入排序和快速排序等。
这些算法各有特点,可以根据数据的特点和需求选择合适的算法。
在使用NCL排序函数时,我们需要指定排序的字段和排序的顺序。
例如,我们可以按照某个字段的升序或降序对数据进行排序。
这样可以使数据更加有序,并更方便我们进行进一步的分析和处理。
除了排序功能,NCL排序函数还可以进行多字段排序和条件排序。
多字段排序可以根据多个字段的值进行排序,以便更好地理解数据之间的关系。
条件排序则可以根据指定的条件对数据进行筛选和排序,以便更好地满足我们的需求。
总的来说,NCL排序函数是一个非常实用的工具,它可以帮助我们对数据进行排序和整理,提高数据的可读性和可分析性。
无论是在科研、气象预报还是其他领域,都可以使用NCL排序函数来处理数据,从而更好地理解和利用数据。
希望通过本文的介绍,您对NCL排序函数有了更深入的了解,并能够熟练地使用它来处理数据。
相信在以后的工作中,NCL排序函数会成为您的得力助手,为您的工作带来更多的便利和效率。
NCL常见错误解决方案
![NCL常见错误解决方案](https://img.taocdn.com/s3/m/6fd1a50db6360b4c2e3f5727a5e9856a56122667.png)
NCL常见错误解决⽅案analysis | Visualization | Array functions | | Error messages | Memory issues | Documentation | Miscellaneous | BasicsNCL core languageFile input/outputData handlingData analysisVisualizationArray functionsOutput formatsError messagesMemory issuesDocumentationMiscellaneousBasics1.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 residesIn 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):o Set the DISPLAY environment variable to indicate where to display graphicsThis is not an NCL specific environment variable, but rather one that is used by any X11 Windows application that you run. For NCL or NCAR Graphics, it is needed when you display your graphics to an X11 window, or if you use ictrans, ctrans, or idt to view your NCGM files.This variable must be set to the IP address or name of the machine you want to display your graphics on, for example "localhost:13.0" . If you are not running on a remote machine, then you can try setting it to ":0.0". Please contact your system administrator if you are not sure what to set it to.For example, from C-shell (csh):ncl myscript.ncl5.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.6.Are there any email lists I can join?Yes. For basic questions about installing NCL and setting up your environment to use it:/doc/f51caa1180eb6294dd886cd4.html /mailman/listinfo/ncl-installFor all other questions on NCL:/doc/f51caa1180eb6294dd886cd4.html /mailman/listinfo/ncl-talkFor questions relating specifically to NCAR Graphics:/doc/f51caa1180eb6294dd886cd4.html /mailman/listinfo/ncarg-talk7.Where can I see some examples of how to use NCL?To see hundreds of NCL application examples, see the category list of application pages. These examples are full NCL scripts that you can download. Some ofthe 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" section in the NCL Reference Manual. 9.Are there any editor enhancements for editing NCL scripts?Yes, see the support page for a list.10.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.11.If I'm running interactively, how can I load some existing NCL code?NCL core language1.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: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:File input/output1.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使用介绍
![ncl使用介绍](https://img.taocdn.com/s3/m/1d7b85eeaeaad1f346933fac.png)
fbindirread, fbinread asciiread
For text
–
Algebraic Operations
Array based algebra Standard operators: -, ^, *, /, %, + Unique operators: %, #, <, > Logical operators: .eq., .ne., .le., .gt., .ge., .lt., .and., .xor., .or., .not. Dimensionality of operands must either match or be scalar Missing values are filtered out by identifying missing value with _FillValue attribute
Many useful functions and procedures Code integration tool (ability to import FORTRAN)
Why use NCL?
Capable data processing environment with many useful functions Strong and easy to use file I/O capability Useful for the development and integration of FORTRAN processing routines Robust publication quality 2D graphics w/ detailed maps Mature product Free!
Data Types
四级英语必备模板
![四级英语必备模板](https://img.taocdn.com/s3/m/ce524e8c8e9951e79a89271e.png)
话题作文:这个模板的中文大意是:在某种场合,发生某种现象,并提供一些相关数据,然后列出这种现象的三个原因,并将三个原因总结为一个最主要原因,最后提出避免这种现象的两个办法。
总的来说,利用这个模板写英语作文,是相当容易的,您只要将适当的内容,填写到对应的方括号中,一篇通顺的英语作文即可完成。
下面就是这个模板。
N0wadays,there are m0re and m0re [某种现象] In [某种场合]。
It Is estImated that [相关数据]。
Why have there been s0 many [某种现象]? Maybe the reas0ns can be lIsted as f0ll0ws。
The fIrst 0ne Is [原因一]。
BesIdes, [原因二]。
The thIrd 0ne Is [原因三]. T0 sum up,the maIn cause 0f [某种现象]Is due t0 [最主要原因]。
It Is hIgh tIme that s0methIng were d0ne up0n It. F0r 0ne thIng,[解决办法一]。
0n the 0ther hand, [解决办法二]. All these measures wIll certaInly reduce the number 0f [某种现象].模块(一)N0wadays ,there are m0re and m0re XX In s0me bIg cItIes 。
It Is estImated that ( 用具体数据说明XX现象). Why have there been s0 many XX ?Maybe the reas0ns can be lIsted as f0ll0ws。
The fIrst 0ne Is that ( 原因一)。
BesIdes,( 原因二)。
The thIrd reas0n Is (原因三)。
NCL画图个例讲解
![NCL画图个例讲解](https://img.taocdn.com/s3/m/58229216227916888586d70e.png)
Example 1——XY plots这个例子介绍了NCL的基础知识,例如如何开始和结束NCL脚本,如何创建和初始化变量,如何创建和绘制XY坐标图,以及如何设置resources来改变XY坐标图的外观。
此外还介绍了NCL变量包含元数据的概念,以及展示了如何从ASCII文件读取数据。
这个例子创建了5个XY坐标图。
前四个图使用了NCL脚本生成的数据,第五个图读取了ASCII文件的数据。
第一个图有一个曲线,其他图右多条曲线。
每个图相对前一个图来讲都有一些改动的地方,例如添加标题、线标签,改变线条颜色和粗细,添加标记。
在以后的例子中将有更加复杂的XY坐标图。
请注意,“line”和“curve”在这个示例中互换使用,用来表示XY坐标图的曲线。
分号“;”在NCL脚本中表示允许注释。
所有的注释都必须以分号开头,任何在分号之后和下一个换行符前的东西都将忽略。
注释可以在一行中单独出现,也可以出现在NCL命令之后。
但是在同一行注释不能出现在命令之前,因为注释符之后所有的东西都被忽略。
运行这个示例,必须下载以下文件:gsun01n.ncl,然后键入:ncl gsun01n.ncl 示例1代码及解释1. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Load the NCL file that contains the gsn_*载入本示例使用的包含函数和程序(以gsn开头的)的NCL脚本。
NCL中的load语句的作用和C和Fortran90程序中include作用一样。
2.; functions used below.3. begin每个NCL脚本都以begin声明开始,以end声明结束。
4. x = new(9,float) ; Define two 1D arrays of 9 elements each.5. y = new(9,float)用new语句来声明2个各有9个元素的1维浮点数组。
ncl绘图
![ncl绘图](https://img.taocdn.com/s3/m/7a49ffafb0717fd5360cdcc3.png)
• Primitives
− markers, polylines, polygons, text
• 特殊的绘图
− bar charts, skew-T, wind roses, taylor diagrams
Introduction to NCL Graphics
NCL 可绘制的图形类型 • XY
Introduction to NCL Graphics
目标
• 主要面向初学者. . .但对于中高级学者会有一些 tips • 掌握NCL绘图相关基本概念和方法 • 列出绘图中常用的一些语句和方法 • 绘制达到发表要求的图形
Introduction to NCL Graphics
NCL Graphics topics
• PyNGL/PyNIO Python modules
Introduction to NCL Graphics
NCL 可绘制的图形类型
超过40个绘图模板 • XY • Contour • Vector • Streamline • Overlays
− Contours 叠加在maps, vectors 叠加在contours, 等等.
• Debugging tips
• Creating images for Web and/or presentations
• PyNGL/PyNIO Python modules
• Contour
• Vector
• Streamline
• Overlays • Primitives • Specialized plots
Introduction to NCL Graphics
Scatter and line plot Based on a visualization of Joel Norris (Scripps) using dummy data
ncl官网使用指南
![ncl官网使用指南](https://img.taocdn.com/s3/m/bb8b0215c281e53a5802ffe6.png)
NCL Website Tour /
Frequently Asked Questions (FAQ)
Support->FAQ
• A good learning tool • Some basic questions:“How do I run NCL?” to more complex: “How do I overlay contours on a map?” • Lots of sample code snippets provided • Categorized, but questions may not be in category you’re expecting. For example, “error messages” versus “visualization” • Feel free to contribute suggestions!
/Support/email_lists.shtml
NCL Website Tour /
Workshop stuff
Support->Workshops->Useful Links
• • • • PowerPoint slides Example scripts used in graphics lecture Step-by-step graphical exercises Sample data files
NCL Website Tour /
Color tables
NCL-Popular Links->Color Tables • How to change/create your own color table • Using named colors • Images of available color tables
ncl代码
![ncl代码](https://img.taocdn.com/s3/m/6e1638d9910ef12d2af9e7b9.png)
Variable: f_preType: floatTotal Size: 2058825600 bytes514706400 valuesNumber of Dimensions: 3Dimensions and sizes: [time | 7943] x [lat | 180] x [lon | 360]Coordinates:time: [9770..17712]lat: [90..-89]lon: [ 0..359]Number Of Attributes: 7long_name : NOAA Climate Data Record (CDR) of Daily GPCP Satellite-Gauge Combined Precipitationstandard_name : lwe_precipitation_rateunits : mm/daycoordinates : time latitude longitudevalid_range : ( 0, 100 )missing_value : -9999_FillValue : -9999Variable: f_timeType: floatTotal Size: 31772 bytes7943 valuesNumber of Dimensions: 1Dimensions and sizes: [ncl_join | 7943]Coordinates:Number Of Attributes: 5long_name : timestandard_name : timeunits : days since 1970-01-01 00:00:00 0:00calendar : Gregorianaxis : TVariable: fType: filefilename: gpcp_daily_cdr_v13rA1_y1996_m10_d01path: /mnt/f/paper/data/data/daily/gpcp_daily_cdr_v13rA1_y1996_m10_d01.nc Number of Attributes:45Conventions : CF-1.6, ACDD 1.3title : Global Precipitation Climatatology Project (GPCP) Climate Data Record (CDR), Daily V1.3source : /data1/GPCP_CDR/GPCP_Output/1DD//bin/199610/stfsg3.19961001.s references : Huffman et al. 1997, /10.1175/1520-0477(1997)078<0005:TGPCPG>2.0.CO;2; Adler et al. 2003, /10.1175/1525-7541(2003)004<1147:TVGPCP>2.0.CO;2; Huffman et al. 2009, /10.1029/2009GL040000; Adler et al. 2017, Global Precipitation Climatology Project (GPCP) Daily Analysis: Climate Algorithm Theoretical Basis Document (C-ATBD)history : 1) 2017-09-09T16:50:25Z, Dr. Jian-Jian Wang, U of Maryland, Created beta (B1) fileMetadata_Conventions : CF-1.6, Unidata Dataset Discovery v1.0, NOAA CDR v1.0, GDS v2.0standard_name_vocabulary : CF Standard Name Table (v41, 22 February 2017)id : 199610/gpcp_daily_cdr_v13rA1_y1996_m10_d01.ncnaming_authority : gov.noaa.ncdcdate_created : 2017-09-09T16:50:25Zlicense : No constraints on data access or use.summary : Global Precipitation Climatology Project (GPCP) Daily Version 1.3 gridded, merged satellite/gauge precipitation Climate data Record (CDR) from 1996 to present.keywords : EARTH SCIENCE > ATMOSPHERE > PRECIPITATION > PRECIPITATION AMOUNTkeywords_vocabulary : NASA Global Change Master Directory (GCMD) Earth Science Keywords, Version 7.0cdm_data_type : Gridproject : GPCP > Global Precipitation Climatology Projectprocessing_level : NASA Level 3creator_name : Dr. Jian-Jian Wangcreator_email : jjwang@institution : ACADEMIC > UMD/ESSIC > Earth System Science Interdisciplinary Center, University of Marylandpublisher_name : NOAA National Centers for Environmental Information (NCEI)publisher_email : jjwang@publisher_url : https://geospatial_lat_min : -89.5geospatial_lat_max : 89.5geospatial_lat_units : degrees_northgeospatial_lat_resolution : 1 degreegeospatial_lon_min : .5geospatial_lon_max : 359.5geospatial_lon_units : degrees_eastgeospatial_lon_resolution : 1 degreetime_coverage_start : 1996-10-01T00:00:00Ztime_coverage_end : 1996-10-01T23:59:59Ztime_coverage_duration : P1Dcontributor_name : Robert Adler, Jian-Jian Wangcontributor_role : principalInvestigator, processor and custodianacknowledgment : This project was supported in part by a grant from the NOAA Climate Data Record (CDR) Program for satellites.cdr_program : NOAA Climate Data Record Program for satellites, FY 2011.cdr_variable : precipitationmetadata_link : gov.noaa.ncdc:XXXXXproduct_version : v13rA1platform : , GOES (Geostationary Operational Environmental Satellite), GMS (Japan Geostationary Meteorological Satellite), METEOSAT, TIROS > Television Infrared Observation Satellite, DMSP (Defense Meteorological Satellite Program)sensor : , Imager, Imager, Imager, TOVS > TIROS Operational Vertical Sounder, SSMI > Special Sensor Microwave/Imagerspatial_resolution : 1 degreecomment : Processing computer: dimensions:nlat = 180nlon = 360time = 1nv = 2variables:Variable: latitudeType: floatTotal Size: 180 values720 bytesNumber of Dimensions: 1Dimensions and sizes: [ 180 <nlat> ]Coordinates:Number of Attributes: 7long_name : Latitudestandard_name : latitudeunits : degrees_northvalid_range : ( -90, 90 )missing_value : -9999bounds : lat_bounds_FillValue : -9999Variable: longitudeType: floatTotal Size: 360 values1440 bytesNumber of Dimensions: 1Dimensions and sizes: [ 360 <nlon> ]Coordinates:Number of Attributes: 7long_name : Longitudestandard_name : longitudeunits : degrees_eastvalid_range : ( 0, 360 )missing_value : -9999bounds : lon_bounds_FillValue : -9999Variable: timeType: floatTotal Size: 1 values4 bytesNumber of Dimensions: 1Dimensions and sizes: [ 1 <time> ]Coordinates:time: [9770..9770]Number of Attributes: 5long_name : timestandard_name : timeunits : days since 1970-01-01 00:00:00 0:00calendar : Gregorianaxis : TVariable: lat_boundsType: floatTotal Size: 360 values1440 bytesNumber of Dimensions: 2Dimensions and sizes: [ 180 <nlat> x 2 <nv> ]Coordinates:Number of Attributes: 2units : degrees_northcomment : latitude values at the north and south bounds of each pixel.Variable: lon_boundsType: floatTotal Size: 720 values2880 bytesNumber of Dimensions: 2Dimensions and sizes: [ 360 <nlon> x 2 <nv> ]Coordinates:Number of Attributes: 2units : degrees_eastcomment : longitude values at the west and east bounds of each pixel.Variable: time_boundsType: floatTotal Size: 2 values8 bytesNumber of Dimensions: 2Dimensions and sizes: [ 2 <nv> x 1 <time> ]Coordinates:time: [9770..9770]Number of Attributes: 2units : days since 1970-01-01 00:00:00 0:00comment : time bounds for each time value Variable: precipType: floatTotal Size: 64800 values259200 bytesNumber of Dimensions: 2Dimensions and sizes: [ 180 <nlat> x 360 <nlon> ]Coordinates:Number of Attributes: 7long_name : NOAA Climate Data Record (CDR) of Daily GPCP Satellite-Gauge Combined Precipitationstandard_name : lwe_precipitation_rateunits : mm/daycoordinates : time latitude longitudevalid_range : ( 0, 100 )missing_value : -9999_FillValue : -9999Variable: fType: filefilename: daily_prepath: /mnt/f/paper/data/data/daily_pre.ncfile global attributes:dimensions:time = 7943 // unlimitedlat = 180lon = 360variables:float pre ( time, lat, lon )long_name : NOAA Climate Data Record (CDR) of Daily GPCP Satellite-Gauge Combined Precipitationstandard_name : lwe_precipitation_rateunits : mm/daycoordinates : time latitude longitudevalid_range : ( 0, 100 )missing_value : -9999_FillValue : -9999float time ( time )axis : Tcalendar : Gregorianunits : days since 1970-01-01 00:00:00 0:00standard_name : timelong_name : timefloat lat ( lat )bounds : lat_boundsmissing_value : -9999valid_range : ( -90, 90 )units : degrees_northstandard_name : latitudelong_name : Latitude_FillValue : -9999float lon ( lon )bounds : lon_boundsmissing_value : -9999valid_range : ( 0, 360 )units : degrees_eaststandard_name : longitudelong_name : Longitude_FillValue : -9999Variable: rcType: floatTotal Size: 259200 bytes64800 valuesNumber of Dimensions: 2Dimensions and sizes: [lat | 180] x [lon | 360] Coordinates:lat: [90..-89]lon: [ 0..359]Number Of Attributes: 7tval : 2.925953rstd : 0.3068212nptxy : 20xave : 2007.5yave : 18.4yintercept : -1783.822_FillValue : 9.96921e+36Variable: paType: floatTotal Size: 259200 bytes64800 valuesNumber of Dimensions: 2Dimensions and sizes: [lat | 180] x [lon | 360] Coordinates:lat: [90..-89]lon: [ 0..359]Variable: num_exType: floatTotal Size: 5184000 bytes1296000 valuesNumber of Dimensions: 3Dimensions and sizes: [time | 20] x [lat | 180] x [lon | 360] Coordinates:time: [1998..2017]lat: [90..-89]lon: [ 0..359]。
NCL入门
![NCL入门](https://img.taocdn.com/s3/m/81ed947ca45177232f60a2d9.png)
蔡宏珂
2016年6月10日
提纲
• • • • • 概述 语法基础 文件读写 函数过程 图形绘制
NCL简介
• 专为(大气)科学 • 数据分析和可视化 • 程序设计语言
NCL优势和缺点
• 足够便捷
– 较低的学习成本 – 简练的文件和图形接口 – 良好的文档和示例
netCDF-3、netCDF-4 classic、netCDF-4、 HDF4、二进制、ASCII文本 HDF-EOS2、HDF-EOS5、GRIB1、GRIB2、OGR
– 给维度定位 T&Lat=(/-90,-80,-70,…,80,90/) – 以一个一维数组A作为另一个数组B(通常是多维 数组)其中一个维度的坐标/索引 – A数组也可有其自身的属性
• 命名维度和维度坐标的区别
– 命名维度是名字,字符串,不依赖于坐标维度 – 维度坐标是数据,数值,定义和引用均依赖于命 名维度
文件读写
• • • • 文件格式简介 二进制文件 ASCII文本文件 netCDF/HDF自描述文件
文件格式简介
• 二进制文件
– .dat、 .bin
• ASCII文本文件
– .txt、 .csv;
• NetCDF(r、w、c)
– .nc、.cdf、.netcdf
• GRIB1和GRIB2(r)
– .gr、.gr1、.grb、.grib、.grb1、.grib1、.gr2、grb2、.grib2
• HDF(r、w、c),只支持Scientific Data Set
– .hdf、.hd
• HDFEOS(r)
– .hdfeos、he2、he4
• Shapefile(r)
NCL常见错误解决方案
![NCL常见错误解决方案](https://img.taocdn.com/s3/m/a7247245964bcf84b9d57bc2.png)
BasicsNCL core languageFile input/outputData handlingData analysisVisualizationArray functionsOutput formatsError messagesMemory issuesDocumentationMiscellaneousBasics1.Where can I download NCLSee 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 NCLo Set the NCARG_ROOT environment variable and your search path to where NCL/NCARG residesIn 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):NCL core language1.How do I comment a line in NCL Is there a way to have a block of commentsThe comment character in NCL is a semicolon (';'). You can use it on a line by itself or after an NCL command: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:input/output1.What's the easiest way to convert a GRIB1, GRIB2, HDF 4, or HDF-EOS 2 file toa NetCDF fileOn the UNIX command line: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 environmentvariable NIO_GRIB2_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 fileThe first way is to use "ncl_scalar" as a dimension name:orYou can also use $$ for attribute names: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 "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?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 "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 formatconstraintsthen you may have what qualifies as a "large file". You need to use the?"-L"?option with ncl_convert2nc.20.W hy do I get different results when reading my HDF-EOS2 file, depending on whetherI use the ".hdf" or ".hdfeos" extensionIf you use the ".hdf" extension, then NCL uses the underlying HDF4 interface to read your data, whereas if you use the "hdfeos or "he2" extension, NCL reads the file using the HDF-EOS2 library interface.Using the ".hdfeos" extension software will give you slightly more information, since the HDF-EOS2 software provides software to calculate additional lat/lon information.Side tip: if your HDF-EOS2 file has an ".hdf" extension, then you can force NCL to read this file as an HDF-EOS2 file simply by appending an ".he2" or ".hdfeos" to the file name in the?addfile?call (you don't need to rename the file). For example, if your file is called "" and you want to read it as a HDF-EOS2, use the following:a = addfile("","r")21.C an I read shapefiles using NCLNCL 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 LibraryThis 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 "gdal_rasterize".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?package - an open source GIS binary kit for Windows and LinuxYou 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?asciiread?function.22.H ow can I get at vgroup data on my HDF4 fileNCL 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 "hdp dumpvd" on the file to find out what "Vdata" index your data is in:hdp dumpvdThis will produce output like this: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:24.W hen 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??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 The name of your institution.o 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: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 handling1.How do I set a missing value for my dataFor the variable that contains your data, set the attribute "_FillValue" to the missing value. For example, the following NCL code:If "x" already has a _FillValue attribute:If "x" doesn't have a _FillValue attribute:Here's some more generic code to first check if x has a _FillValue attribute:Data analysisVisualizationOnce you find the character you desire, note the font table index ("math_symbols" is index 18, for example), and the corresponding character, then you can use the?text function code?'F' to change the font.For example, to get a bell symbol, you would see that character 'n' in the "symbol_set1" table (index 19) is a bell. You can then use the string "~F19~n~F~" in any text string resource to indicate you want a bell symbol. The "~F~" means go back to the original font.For example, to use it in a title:res@tiMainString = "Bell (~F19~n~F~)"Note that we're assuming the default function code (a colon, ':'), has been changed to a tilde, '~'. See the question above on changing function codes.11.C an I use real PostScript fonts in my PostScript fileEssentially no, except in one situation that is discussed below. When you use NCL?font number 4, you will get the stroked simplex_roman font, no matter what kind of workstation you are going to, even a PostScript workstation. If you change "4" to "Helvetica," then you will get NCL?font 21?which is a Helvetica font that is drawn using filled areas, . filled areas will be put into the output PostScript and not code to use the built-in PostScript Helvetica font.However, there is one circumstance which will allow you to use a PostScript font directly and not have filled areas inserted into the output PostScript. This can be accomplished by setting the resource?txFontQuality?to "low." There are some significant downsides to this. First, no matter what font you select in NCL, the font used in the output PostScript will be Helvetica. If you select a character, such as a degree symbol, that is not in the Helvetica font, it will not be drawn correctly. Secondly, all text strings will be monospaced. Thirdly, when plotting to workstations other than PostScript or PDF, you will get a very low-level stick font.The primary upside to this is a reduction in the size of the output PostScript file. Another advantage is that you will be using a built-in PostScript font that will be produced with high fidelity, even at very small sizes.Here is an example of using font quality "low":plot = gsn_contour_map(wks,data,res)If the plot has already been transformed to map coordinates, then you can set the?tfDoNDCOverlay?resource to True, indicating to NCL that no map transformation is to take place. In order for this to work, however, your map projection?must be set up to exactly match the area your data represents. Sometimes this information is available, say, on the same file that the data came from.Here's a simple (and rather crude) vector example using a cylindrical equidistant map:Use the?mpDataBaseVersion?resource. The default is "LowRes". If you change this to "MediumRes" or "HighRes", you will improve the resolution of your map outlines.Note: the "HighRes" resource shows coastal outlines only, and you should not use this resolution for global maps (it's slow, and you may see some strange artifacts). The high-resolution database does not come with NCL; instructions for downloading and installing this database can be found on the?high-resolution coastlines description page.For an example comparing the three levels of resolutions:。
使用NCL处理WRF Output
![使用NCL处理WRF Output](https://img.taocdn.com/s3/m/b5a87635580216fc700afd3c.png)
云水混合比: 比湿: 气体状体方程:
湿空气密度:
云水密度:
USTC ACE Lab
Fig 1.
2004-08-26-00-00-00
2010年西太平洋1接近地面和6km附近,与傅
老师绘制的CWC吻合较好。 两次台风的CWC均出现“双峰”特点,说明台风的CWC有一定的规律。
H=(“PH”+”PHB”)/9.81
H=fi->height
;通过位势计算
网格层 (N+1层)
; indirect variables , can’t read
wrf_user_getvar
Extracts data from ARW WRF model output, and does basic diagnostics calculations.
使用NCL处理WRF Output
SA11007005 李文卓
USTC ACE Lab
USTC ACE Lab
Some indirect meteorological variables
WRF model outputs the state variables defined in the Registry file, and these state variables are used in the model's prognostic equations.
USTC ACE Lab
便捷处理方法
NCL 的 wrf_user_getvar ()函数可以将WRF Output 直接插值到高度层或气 压层,实现垂直坐标转换,便于NCL继续处理。
Example:
USTC ACE Lab
NCL中文学习手册
![NCL中文学习手册](https://img.taocdn.com/s3/m/8a98a23787c24028915fc32e.png)
致谢
衷心感谢上海海洋大学海洋科学学院胡松老师的悉心指导;感谢南京信息工程大学大气科学学院海洋科学 系程军老师领我入门;感谢刘畅同学耐心细致的修订工作。
本人在学习 NCL 过程中,对手册进行了翻译,仅供方便学习查找使用。由于本人水平有限,本手册还存在 许多不足,对一些专业名词略有模糊,望大家指正,可发邮件至: l_n.2006@
第四章 输出 ............................................................................................................................................................. 15 4.1 printVarSummary ........................................................................................................................................ 16 4.2 print ............................................................................................................................................................. 16 4.3 sprintf, sprinti .............................................................................................................................................. 17 4.4 write_matrix ..........................................................................................................................................日 于上海海洋大学
NCL_Bruyere教程
![NCL_Bruyere教程](https://img.taocdn.com/s3/m/1b59513287c24028915fc3e0.png)
Horizontal, cross-section, skewT, meteogram, panel /Download Fill out short registration form (there is a short waiting period) Read and agree to OSI-based license Get version 5.1.1 or later (current v6.0.0) setenv NCARG_ROOT /usr/local/ncl
26 29 30 32 35 36 (.) (t) (o) (.) (b) (y) IS IS IS IS IS IS NOT NOT NOT NOT NOT NOT A A A A A A LEGAL LEGAL LEGAL LEGAL LEGAL LEGAL FUNCTION FUNCTION FUNCTION FUNCTION FUNCTION FUNCTION CODE CODE CODE CODE CODE CODE
14
Generate Plots
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl" begin a = addfile("./geo_em.d01.nc","r") wks = gsn_open_wks("pdf","plt_ter5") res = True res@MainTitle = "GEOGRID FIELDS” pltres = True mpres = True ter = wrf_user_getvar(a,"HGT_M",0) res@cnFillOn = True res@ContourParameters = (/0.,1000.,50./) contour = wrf_contour(a,wks,ter,res) plot = wrf_map_overlays(a,wks,(/contour/),\ pltres,mpres) end
ncl polymarker类型
![ncl polymarker类型](https://img.taocdn.com/s3/m/c709c63c30b765ce0508763231126edb6f1a760c.png)
NCL Polymarker类型1. 简介NCL(NCAR Command Language)是一种用于科学数据分析和可视化的编程语言,是NCAR(National Center for Atmospheric Research)开发的一种专业工具。
在NCL中,Polymarker是绘图函数的一种类型,用于创建多个不同样式的点标记。
2. Polymarker类型的属性Polymarker类型具有以下属性:- 符号样式:可以选择不同样式的点标记,包括圆圈、方块、星形等。
- 大小:可以设置点标记的大小。
- 颜色:可以设置点标记的颜色。
3. Polymarker类型的用法示例以下是使用NCL Polymarker类型的简单示例:```nclbeginwks = gsn_open_wks("x11","plot")x = (/1, 2, 3, 4, 5/)y = (/5, 4, 3, 2, 1/)res = TrueresgsMarkerIndex = 16 ; 设置标记类型为圆圈resgsMarkerSizeF = 0.03 ; 设置标记大小resgsMarkerColor = "blue" ; 设置标记颜色plot = gsn_point(wks, x, y, res)end```4. Polymarker类型的应用Polymarker类型广泛应用于科学数据可视化领域,特别适用于散点图和地图中的点标记。
通过设置不同的符号样式、大小和颜色,可以使数据图表更加清晰易读。
5. 总结NCL Polymarker类型是NCL中用于绘制多个不同样式的点标记的一种类型,具有灵活的属性设置和广泛的应用领域。
通过合理地运用Polymarker类型,可以有效地展示科学数据,提高数据可视化的质量和效果。
对于NCL(NCAR Command Language)的Polymarker 类型而言,它是科学数据可视化中不可或缺的一部分。
使用NCL处理WRF Output
![使用NCL处理WRF Output](https://img.taocdn.com/s3/m/b5a87635580216fc700afd3c.png)
云水混合比: 比湿: 气体状体方程:
湿空气密度:
云水密度:
USTC ACE Lab来自Fig 1.2004-08-26-00-00-00
2010年西太平洋12号台风FANAPI
Fig 1.云水廓线(CWC)出现“双峰”,峰值在接近地面和6km附近,与傅
老师绘制的CWC吻合较好。 两次台风的CWC均出现“双峰”特点,说明台风的CWC有一定的规律。
5. total tempurature in K
φ=“PH” + “PHB” H=(“PH” + “PHB” ) / 9.81 θ =“T” + 300
P=( “P” + “PB” ) * 0.01
USTC ACE Lab
NCL 处理WRF Output 与 .nc 的相同点
fi = addfile("../DATA/wrfout_d04_2004-08-26_00_00_00.nc","r")
USTC ACE Lab
Some indirect meteorological variables
WRF model outputs the state variables defined in the Registry file, and these state variables are used in the model's prognostic equations.
Some of these variables are perturbation fields. Therefore some definition for
reconstructing meteorological variables is necessary. 1. total geopotential 2. total geopotential height in m 3. total potential temperature in K 4. total pressure in mb
第二章-NCL变量及基本语法
![第二章-NCL变量及基本语法](https://img.taocdn.com/s3/m/692d617f01f69e314332943c.png)
详细查看netCDF变量 (NCL)
ncl <return> ncl 0 > f = addfile (“UV300.nc”, “r”) ncl 1 > u = f->U ncl 2 > printVarSummary (u)
; 交互模式
; 打开文档 (nc, grb, hdf, hdfeos) ; 提取 STRUCTURE ; 查看变量
创建数组 (/…/) – a_integer – a_float – a_double – a_string – a_logical – a_2darray
= (/1, 2, 3/) ; ispan(1,3,1) = (/2.0, 5 , 8.0/) ; fspan(2,8,3) = (/12 , 2d0 , 3.2 /) ; (/12,2 ,3.2 /)*1d0 = (/"abcd", "e", "Hello, World”/) = (/True, False, True/) = (/ (/1,2,3/), (/4,5,6/), (/7,8,9/) /)
DIMENSION SIZES & NAMES dimensions: lat = 64 lon = 128 time = 12
time=UNLIMITED (比如12个月)
文件属性 全域属性: title = “Temp: 1999” source = “NCAR” Conventions = ”CF-1.0”
x
name: type: shape: size: values:
x float [real] 2-dimensions 6 (rows) x 5 (columns) x(2,3) = 8.46 [row major, 0-based indexing]
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Example 1 - XY plotsThis example creates five XY plots. The first four plots use data generated within the NCL script, and the fifth plot uses data read from an ASCII file.The first plot has one curve, and the rest of the plots have multiple curves. Each plot has some aspect changed from the previous plot, like titles and line labels added, line colors and thicknesses changed, and markers added. More complex XY plots are shown in later examples. Please note that the words "line" and "curve" are used interchangeably in this example to refer to curves in an XY plot.The semicolon ";" character allows comments in an NCL script. Comments must begin with a semicolon, and anything after the semicolon and before the next newline character is ignored by NCL. Comments may appear alone on a line or after an NCL command. Comments cannot appear on the same line before a command because everything after the comment character is ignored.To run this example, you must download the following file:gsun01n.ncland then type:ncl gsun01n.nclOutput from example 1Frame 1 Frame 2 Frame 3 Frame 4 Frame 5(Click on any frame to see it enlarged.)NCL code for example 11. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; Load the NCL file that contains the gsn_*2. ; functions used below.3. begin4. x = new(9,float) ; Define two 1D arrays of 9 elements each.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") ; Open an X11 workstation.11.12. plot = gsn_xy(wks,x,y,False) ; Draw an XY plot with 1 curve.13.14. ;----------- Begin second plot -----------------------------------------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" ; Define attributes of x21. y2@long_name = "Y" ; and y2.22.23. plot = gsn_xy(wks,x,y2,False) ; Draw an XY plot with 3 curves.24.25. ;----------- Begin third plot -----------------------------------------26.27. resources = True ; Indicate you want to28. ; set some resources.29.30. resources@xyLineColors = (/2,3,4/) ; Define line colors.31. resources@xyLineThicknesses = (/1.,2.,5./) ; Define line thicknesses32. ; (1.0 is the default).33.34. plot = gsn_xy(wks,x,y2,resources) ; Draw an XY plot.35.36. ;---------- Begin fourth plot ------------------------------------------37.38. resources@tiMainString = "X-Y plot" ; Title for the XY plot39. resources@tiXAxisString = "X Axis" ; Label for the X axis40. resources@tiYAxisString = "Y Axis" ; Label for the Y axis41. resources@tiMainFont = "Helvetica" ; Font for title42. resources@tiXAxisFont = "Helvetica" ; Font for X axis label43. resources@tiYAxisFont = "Helvetica" ; Font for Y axis label44.45. resources@xyMarkLineModes = (/"Lines","Markers","MarkLines"/)46. resources@xyMarkers = (/0,1,3/) ; (none, dot, asterisk)47. resources@xyMarkerColor = 3 ; Marker color48. resources@xyMarkerSizeF = 0.03 ; Marker size (default49. ; is 0.01)50.51. plot = gsn_xy(wks,x,y2,resources) ; Draw an XY plot.52.53. ;---------- Begin fifth plot ------------------------------------------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) ; Start with new list of resources.67.68. resources = True69.70. resources@tiMainString = "U/V components of wind"71. resources@tiXAxisString = "longitude"72. resources@tiYAxisString = "m/s"73. resources@tiXAxisFontHeightF = 0.02 ; Change the font size.74. resources@tiYAxisFontHeightF = 0.0275.76. resources@xyLineColors = (/3,4/) ; Set the line colors.77. resources@xyLineThicknessF = 2.0 ; Double the width.78.79. resources@xyLabelMode = "Custom" ; Label XY curves.80. resources@xyExplicitLabels = (/"U","V"/) ; Labels for curves81. resources@xyLineLabelFontHeightF = 0.02 ; Font size and color82. resources@xyLineLabelFontColor = 2 ; for line labels83.84. plot = gsn_xy(wks,lon,uv,resources) ; Draw an XY plot with 2 curves.85.86. delete(plot) ; Clean up.87. delete(resources)88. endExplanation of example 1Line 1:load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"Load the NCL script that contains the functions and procedures (the ones that start with "gsn_") that are used in this example.The load statement in NCL works much like include works in C and Fortran 90 programs.Line 3:beginStart every NCL script with the begin statement and end it with the end statement.Lines 4-5:x = new(9,float)y = new(9,float)Declare two 1-dimensional float arrays of 9 elements each with the new statement. The first argument of new indicates the dimensionality of the variable, and the second argument its type. In this case, the two new statements are redundant, because in NCL you can declare variables by initializing them (as you do in the next two lines).For an overview of NCL's variable types, see the "NCL data types overview" section of the NCL Reference Manual.Lines 7-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/)Assign values to the 1-dimensional arrays you just declared. In an assignment statement, a comma-separated list of array values is preceded by "(/" and terminated by "/)". Arrays in NCL are modeled after arrays in the C programming language; that is, they are row-major and begin at index 0 (instead of column-major and index 1 as in Fortran).Line 10:wks = gsn_open_wks("x11","gsun01n")To produce graphics with NCL, you need to tell it where to draw the graphics. The choices, which are also known as workstations, are an X11 window, an NCAR Graphics metafile (NCGM), or a PostScript file (regular, encapsulated, or encapsulated interchange).The function gsn_open_wks opens one of these types of workstations so you can draw graphics to it. The first argument(a string) indicates where you want the graphical output drawn ("x11" for an X11 window, "ncgm" for an NCGM, and "ps", "eps", or "epsi" for a PostScript file). The second argument (also a string) determines the name of the file if you draw the graphical output to an NCGM or a PostScript file (name.ncgm for an NCGM file, and name.{ps,eps,epsi} for a PostScript file, where name is the second string you pass in). The second argument also comes into play when resource files are discussed in example 8 and 9.The value returned from gsn_open_wks is a special variable of type graphic, which is an NCL variable type to define graphical objects. Line 12:plot = gsn_xy(wks,x,y,False)The function gsn_xy creates and draws an XY plot and returns the XY plot as a variable of type graphic (in most cases, you probably won't need to do anything with this return value). The first argument is the workstation you want to draw the XY plot to (the variable returned from the previous call to gsn_open_wks). The next two arguments are the variables containing the X and Y arrays that you want to plot. These two arguments can be of type float, double, or integer and can be 1-dimensional or multi-dimensional (explained below). The last argument is a logical value indicating whether you have set any "resources" for changing the look of a plot. To get the default XY plot that NCL provides, pass the value False for the last argument (in NCL,logical values are set with the special keywords True or False, which both must be capitalized).The gsn_xy function draws the XY plot with tick marks selected at "nice" values. No title or X/Y axis labels are provided in the default plot, but these can be easily added as shown in the next few plots. You can also change the style of the tick marks as shown in example 7.By default, when a plot is drawn to an X11 window or an NCGM file, it has a black background and a white foreground. If a plot is drawn to a PostScript file, it has a white background and a black foreground. In later examples, you will learn how to specify the background and foreground colors, and when you do this, the plot has the same colors, no matter which workstation you draw it to.Since you opened a workstation type of "x11", the gsn_xy function produces an X11 window on which you need to click with the left mouse button to advance to the next frame.Line 14:;----------- Begin second plot -----------------------------------------Divider in the code to indicate the start of the code for the second plot.Draw an XY plot with three curves, each curve having nine points.Lines 16-18:y2 = (/(/0., 0.7, 1., 0.7, 0., -0.7, -1., -0.7, 0./),\(/2., 2.7, 3., 2.7, 2., 1.3, 1., 1.3, 2./),\(/4., 4.7, 5., 4.7, 4., 3.3, 3., 3.3, 4./)/)Define a 3 x 9 array (the first dimension represents the number of curves, and the second dimension represents the number of points). Note that this time you are not using new to declare the array, because in NCL you can create variables by assigning values to them. NCL is able to determine the dimensionality and type of a variable by the way it is initialized.For example, to create a 2 x 3 x 4 integer array called i with each value set to 0, use the following NCL statement:i = (/ (/ (/0,0,0,0/), (/0,0,0,0/), (/0,0,0,0/) /),\(/ (/0,0,0,0/), (/0,0,0,0/), (/0,0,0,0/) /) /)The above could have also been accomplished with the following two lines:i = new((/2,3,4/),integer)i = 0The "\" character is used in NCL as a line continuation character.Lines 20-21:x@long_name = "X"y2@long_name = "Y"NCL variables are more general than variables used in traditional programming languages such as C and Fortran. As usual, they contain values, but they may also contain ancillary information about the variable. This additional information is often called "metadata." Metadata is divided into three categories: attributes, named dimensions, and coordinate variables.Variables can have an unlimited number of attributes assigned to them, and each attribute is assigned to a variable using the "@" symbol. In lines 20-21, you are creating an attribute called "long_name" for both the x and y2 variables. For more information on variable properties in NCL, see the "Variables" section in the "Basics."By default, if an attribute called "long_name" is set for either the X or Y data arrays, (as is commonly done in netCDF files),then gsn_xy uses this attribute to label the X and/or Y axis in the XY plot (unless you have overridden this by setting resources as shown below).Line 23:plot = gsn_xy(wks,x,y2,False)Draw a new XY plot, using the same X array from the first plot and the new y2 array you just defined. Since x is only a 1-dimensional array, NCL pairs the values in the x array with the values in each of the three curves in the y2 array. If a 3 x 9 X array had been declared in addition to the 3 x 9 Y array, then each value in the Y array would have been paired with the corresponding value in the X array.Note that if more than one curve is drawn in an XY plot, then gsn_xy draws each curve with a unique dash pattern. There are 16 different dash patterns available; see the list of "dash patterns" in the graphics documentation.Note the new X and Y axis labels that result from the attribute "long_name" being set for each axis.Line 25:;----------- Begin third plot -----------------------------------------Draw the same three curves, using different colors and line thicknesses for each one.Line 27:resources = TrueThis line introduces the concept of using "resources" to change the look of a plot. In NCL, there are hundreds of resources you can set for changing line colors and thicknesses, adding titles, changing fonts, creating label bars and legends, changing map projections, modifying the size of a plot, masking out certain areas, etc. There are also resources for changing the data of a plot, like setting minimum and maximum values, selecting strides or subsets of data, and setting missing values.Most resources have default values that are either hard-coded or set dynamically by NCL when you run the NCL script. For example, the line thickness for a curve is hard-coded to a value of 1.0, but the minimum and maximum values of a curve are set dynamically according to the actual minimum and maximum data values used in the XY plot. You only need to set a resource if you want to change its default value.Resources are grouped by the type of graphical object or data they describe, and these groupings are discussed here and in other examples. To set resources for use by the gsn_* suite of functions, first define a variable of type logical and set its value to True, then specify the resources as attributes of this logical variable. As stated above, a variable can have an unlimited number of attributes. This variable that you create should then get passed to the appropriate gsn_* plotting routine for the resources to take effect.Important note: This method for setting resources is specific to the gsn_* suite of functions and procedures. Setting resources using straight NCL code is quite different, and is covered in the "Going beyond the basics" section of this document.Line 30:resources@xyLineColors = (/2,3,4/)Set the resource xyLineColors to define a different line color for each line. The default is 1 which is the foreground color ("white" in this case). The colors specified here are represented by integer index values, where each index maps to a color in a predefined color table (also called a "color map"). Since a color table has not been defined in this example, a default color table with 32 indices is provided by NCL (later examples will show how to create your own color map). To see the default color table, go to the "Color tables" section of the NCAR Graphics Reference Manual. In the default color table, the integer values 2, 3, and 4 represent the colors "red", "green", and "blue" respectively. Color resources can also be set using named colors, so the xyLineColors resource could have been set with the following code:resources@xyLineColors = (/"red","green","blue"/)Named colors are covered in more detail in examples 4 and 7.If you had wanted the same line color for each curve, but wanted it something other than "1", then you could have used the singular resource, xyLineColor.XY plot resources belong to the "XyPlot" group and start with the letters "xy". Each XyPlot resource is documented with its type and its default value in the XyPlot resource descriptions.Line 31:resources@xyLineThicknesses = (/1.,2.,5./)Using the xyLineThicknesses resource, define a different line thickness for each curve. The default thickness is 1.0, so a value of 2.0 doubles the line thickness and a value of 5.0 increases the line thickness by a factor of 5, and so on. Again, you could have used the singular resource xyLineThicknessF to set all the curves to the same thickness.Line 34:plot = gsn_xy(wks,x,y2,resources)Draw the plot, this time passing the list of resources that you just created. Each curve is a different color and has a different line thickness. Line 36:;---------- Begin fourth plot ------------------------------------------Create the same plot as before, only add a title at the top, change the X and Y axis labels, change the font of the title and labels, and use markers and/or lines to draw each curve.Since you are creating the same plot as before, you want to keep the same resources that you set for the previous XY plot. You can just add more attributes to the resources variable to customize the plot some more.If you had wanted to go back to all the default resources before creating the next XY plot, you could have either used a new variable name for the resources, or deleted the current list of resources with the delete(resources) command and started over with a new list. Lines 38-40:resources@tiMainString = "X-Y plot"resources@tiXAxisString = "X Axis"resources@tiYAxisString = "Y Axis"Set some resources for adding a title to the top of the plot and for changing the labels of the X and Y axes.Title resources belong to the "Title" group and start with "ti.Lines 41-43:resources@tiMainFont = "Helvetica"resources@tiXAxisFont = "Helvetica"resources@tiYAxisFont = "Helvetica"Set some resources for changing the font of the titles you just defined above. Fonts can be set by using a string that describes the font, or by using an index into a font table. A table of all the available fonts along with their names and index values appears in the "Font table" section of the NCAR Graphics Reference Manual.Note that predefined strings, like those listed in the font table, are case-insensitive, and that you could have specified the font with "helvetica" or "HELVETICA" or any another combination of uppercase and lowercase characters.Lines 45-46:resources@xyMarkLineModes = (/"Lines","Markers","MarkLines"/)resources@xyMarkers = (/0,1,3/)Use the xyMarkLineModes resource to add markers to the curves (since the default is to draw all curves without markers). There are three types of lines that can be drawn: regular lines ("Lines"), markers only ("Markers"), and lines with markers ("MarkLines"). In this plot, you are using this resource to invoke all three kinds of lines. The xyMarkers resource defines the type of markers you want to use. There are seventeen marker styles to choose from.Lines 47-48:resources@xyMarkerColor = 3resources@xyMarkerSizeF = 0.03By using the "singular" resources xyMarkerColor and xyMarkerSizeF instead of the "plural" resources xyMarkerColors and xyMarkerSizes, youget the same marker color and size for all the lines that have markers. The default marker size is 0.01, so a value of 0.03 triples the markersize.Line 51:plot = gsn_xy(wks,x,y2,resources)Draw the plot with the new resources you set.Line 53:;---------- Begin fifth plot ------------------------------------------Read in some data from an ASCII file, set several resources for titles, line colors, and labeling lines, and then create an XY plot with twocurves.Lines 55-57:filename = "$NCARG_ROOT/lib/ncarg/data/asc/xy.asc"data = asciiread(filename,(/129,4/),"float")Read in an ASCII file using the NCL function asciiread. NCARG_ROOT is an environment variable (that must be set to run these NCL scripts)and you can use environment variables in NCL in a file path name by prefixing a "$" to the name.The first argument of asciiread is the file name, the second argument (a 1-dimensional integer array) is the dimensionality of the data you are reading in, and the third argument (a string) is the type of the data. In this case, the ASCII data file has 4 columns of data with 129 rows each, so a dimensionality of (/129,4/) is used to read in the data.Lines 59-61:uv = new((/2,129/),float)uv(0,:) = data(:,1)uv(1,:) = data(:,2)Create a 2-dimensional float array dimensioned 2 x 129 and assign some values of data to it. The notation "(:,1)" indicates the second setof 129 values from data (remember, arrays in NCL start at index 0, not index 1). If you had wanted to select elements 50 to 100 of the firstset of 129 values, you would have used the notation "(49:99,0)".Lines 63-64:lon = data(:,0)lon = (lon-1) * 360./128.Assign data's first set of 129 values to the variable lon. Since the values stored in the lon variable range from 1.0 to 129.0, and are actuallysupposed to represent longitude values from 0.0 to 360.0 in steps of 360/128, you need to convert each value by subtracting 1 andmultiplying it by 360/128. In NCL, you can do scalar arithmetic on a whole array using the same notation as if it were a scalar value. You canalso multiply, divide, add, and subtract arrays in one step as long as they are the appropriate size for doing such array computations.Lines 63-64 could also have been combined into one line:lon = (data(:,0)-1) * 360./128.Lines 66-68:delete(resources)resources = TrueAssuming you don't want to use any of the resources that had been set for the earlier plots, you can start with a new template of resourcesusing the delete command. If you plan to set some new resources, the variable resources must be again set to True, since delete removes allinformation relating to it. You could have also just used a new variable name.Lines 70-74:resources@tiMainString = "U/V components of wind"resources@tiXAxisString = "longitude"resources@tiYAxisString = "m/s"resources@tiXAxisFontHeightF = 0.02resources@tiYAxisFontHeightF = 0.02Set some resources for putting a title on the plot, labeling the X and Y axes, and changing the font size of the X/Y axis labels.Lines 76-82:resources@xyLineColors = (/3,4/)resources@xyLineThicknessF = 2.0resources@xyLabelMode = "Custom"resources@xyExplicitLabels = (/"U","V"/)resources@xyLineLabelFontHeightF = 0.02resources@xyLineLabelFontColor = 2Set some resources for defining line colors and thicknesses and for creating line labels. You set xyLabelMode to "Custom" to indicate that you want to customize how to label the XY plot curves (there are no labels by default). You can indicate what labels you want withthe xyExplicitLabels resource. The xyLineLabel* resources used here change the font size and color of the line labels.Line 84:plot = gsn_xy(wks,lon,uv,resources)Draw an XY plot, using the new list of resources you just set.Lines 86-87:delete(plot)delete(resources)Use the delete command to remove some of the variables created in this NCL script. This is not really necessary in this case, since you are at the end of the NCL script, but it's a good idea to get in the habit of cleaning up variables that you no longer need.Line 88:endEnd every NCL script with end.Example 2 - contour plotsThis example reads a netCDF file and creates five contour plots using three different datasets, and it sets resources to get different types of contour plots. This example also writes some of the netCDF data to an ASCII file.To find out more about netCDF, see /packages/netcdf/To run this example, you must download the following file:gsun02n.ncland then type:ncl gsun02n.nclOutput from example 2Frame 1 Frame 2 Frame 3 Frame 4 Frame 5(Click on any frame to see it enlarged.)NCL code for example 21. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"2.3. begin4.5. cdf_file = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/contour.cdf","r")6.7. temp = cdf_file->T(0,0,:,:) ; temperature8. Z = cdf_file->Z(0,0,:,:) ; geopotential height9. pres = cdf_file->Psl(0,:,:) ; pressure at mean sea level10. lat = cdf_file->lat ; latitude11. lon = cdf_file->lon ; longitude12.13. temp = temp - 273.15 ; Convert Kelvin -> Celsius14. pres = pres * 0.01 ; Convert Pa -> mb15. temp@units = "(C)" ; Change units to reflect16. pres@units = "(mb)" ; conversion done.17.18. xwks = gsn_open_wks("x11","gsun02n") ; Open an X11 workstation.19.20. plot = gsn_contour(xwks,temp,False) ; Draw a contour plot.21.22. ;----------- Begin second plot -----------------------------------------23.24. resources = True ; Indicate you want to set some25. ; resources.26.27. resources@cnMonoLineColor = False ; Turn off the drawing of28. ; contours lines in one color.29.30. resources@tiMainString = "Temperature (C)" ; Create a title.31.32. plot = gsn_contour(xwks,temp,resources) ; Draw a contour plot.33.34. ;----------- Begin third plot -----------------------------------------35.36. resources@cnFillOn = True ; Turn on contour line fill.37. resources@cnMonoFillPattern = False ; Turn off using a single fill38. ; pattern.39. resources@cnMonoFillColor = True40. resources@cnMonoLineColor = True41.42. resources@tiXAxisString = lon@long_name43. resources@tiYAxisString = lat@long_name44. resources@sfXArray = lon45. resources@sfYArray = lat46.47. plot = gsn_contour(xwks,temp,resources) ; Draw a contour plot.48.49. ;---------- Begin fourth plot ------------------------------------------50.51. resources@cnMonoFillPattern = True ; Turn solid fill back on.52. resources@cnMonoFillColor = False ; Use multiple colors.53. resources@cnLineLabelsOn = False ; Turn off line labels.54. resources@cnInfoLabelOn = False ; Turn off informational55. ; label.56. resources@cnLinesOn = False ; Turn off contour lines.57.58. resources@pmLabelBarDisplayMode = "Always" ; Turn on label bar.59. resources@lbPerimOn = False ; Turn off perimeter on60. ; label bar.61.62. resources@tiMainString = Z@long_name63. resources@tiMainFont = 2664. resources@tiXAxisFont = 2665. resources@tiYAxisFont = 2666.67. plot = gsn_contour(xwks,Z,resources) ; Draw a contour plot.68.69. ;---------- Begin fifth plot ------------------------------------------70.71. cmap = (/(/0.,0.,0./),(/1.,1.,1./),(/.1,.1,.1/),(/.15,.15,.15/),\72. (/.2,.2,.2/),(/.25,.25,.25/),(/.3,.3,.3/),(/.35,.35,.35/),\73. (/.4,.4,.4/),(/.45,.45,.45/),(/.5,.5,.5/),(/.55,.55,.55/),\74. (/.6,.6,.6/),(/.65,.65,.65/),(/.7,.7,.7/),(/.75,.75,.75/),\75. (/.8,.8,.8/),(/.85,.85,.85/)/)76.77. gsn_define_colormap(xwks,cmap) ; Define a new color map.78.79. resources@tiMainString = pres@long_name80.81. plot = gsn_contour(xwks,pres,resources) ; Draw a contour plot.82.83. print(temp(2:5,7:9)) ; Print subset of "temp" variable.84.85. print(temp!0) ; Print the dimension names for the86. print(temp!1) ; first two dimensions of T.87. print(temp@long_name) ; Print "long_name" and "units"88. print(temp@units) ; attributes of "T".89. print(temp&lat) ; Print coordinate variables "lat"90. print(temp&lon) ; and "lon".91.92. ascii_file = "data.asc" ; Create name of ASCII file.93. system("/bin/rm -f " + ascii_file) ; Remove ASCII file.94. asciiwrite(ascii_file,temp(7:3:2,0:4)) ; Write part of temp to ASCII95. ; file.96. delete(plot) ; Clean up.97. delete(temp)98. delete(resources)99. end。