NCL的示例1:常见符号的用法

NCL的示例1这个例子中演示了三个符号的使用:

!设置(维数)坐标名称

@设置资源属性

&:设置(维数)坐标值

在字符串引用中,还会遇到美元$符号:

dimnames = (/"frtime","lat","lon"/)
attnames = (/"_FillValue", "long_name"/)
att0 = temperature@$attnames(0)$     ; access to attribute
; Example of referencing a coordinate variable 
; without knowing the dimension name
if(iscoord(dimnames(0)) 
	coord0 = temperature&$temperature!0$
end if
下面的脚本会输出以下图形:

NCL的示例1:常见符号的用法_第1张图片

; =================================================;
; LearnNCL1.ncl
; =================================================;
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
; =================================================;
begin
;创建一个 3X4 的数组t,3行2列. 下面的\表示换行
t=(/\
	(/1.,2.,3.,4./),\
	(/5.,6.,7.,8./),\
	(/9.,10.,11.,12./)\
	/)
;打印信息
print(t)

;设置维数坐标名称使用 ! 符号
t!0="lon"
t!1="lat"
;打印信息
print(t!0)
print(t!1)

;设置维数坐标值使用 & 符号
t&lon=(/-180,0,180/)
t&lat=(/-90,-45,45,90/)
;打印信息
print(t&lon)
print(t&lat)

;设置属性使用 @ 符号
t@long_name="temperature"
t@units="K"
;打印维数坐标值
print(t@long_name)
print(t@units)

  xwks   = gsn_open_wks( "x11","ncltest") ; Open an X11 workstation.
;------------------------------------------------------------------
  resources                 = True      ; set some resources.
  resources@cnFillOn          = True    ; Turn on contour line fill.
  
  resources@tiMainString    = t@long_name
  resources@tiXAxisString    = t!0
  resources@tiYAxisString    = t!1
  resources@sfXArray         = t&lon   ;用这个做横坐标刻度值
  resources@sfYArray         = t&lat   ;用这个做纵坐标刻度值
  
  contourmap = gsn_contour_map(xwks,t(lat|:,lon|:),resources)
;------------------------------------------------------------------
  delete(resources)
  resources                 = True      ; set some resources.
  resources@cnFillOn          = True    ; Turn on contour line fill.
  
  resources@tiMainString    = t@long_name
  resources@tiXAxisString    = t!0
  resources@tiYAxisString    = t!1
  resources@sfXArray         = t&lon   ;用这个做横坐标刻度值
  resources@sfYArray         = t&lat   ;用这个做纵坐标刻度值

  contour = gsn_contour(xwks,t(lat|:,lon|:),resources) 

;------------------------------------------------------------------
end

打印输出的信息如下:

 Copyright (C) 1995-2013 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.1.2
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.


Variable: t
Type: float
Total Size: 48 bytes
            12 values
Number of Dimensions: 2
Dimensions and sizes:	[3] x [4]
Coordinates: 
(0,0)	 1
(0,1)	 2
(0,2)	 3
(0,3)	 4
(1,0)	 5
(1,1)	 6
(1,2)	 7
(1,3)	 8
(2,0)	 9
(2,1)	10
(2,2)	11
(2,3)	12
(0)	lon
(0)	lat


Variable: lon (coordinate)
Type: integer
Total Size: 12 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:	[lon | 3]
Coordinates: 
(0)	-180
(1)	0
(2)	180


Variable: lat (coordinate)
Type: integer
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes:	[lat | 4]
Coordinates: 
(0)	-90
(1)	-45
(2)	45
(3)	90
(0)	temperature
(0)	K


你可能感兴趣的:(NCL的示例1:常见符号的用法)