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 nameif(iscoord(dimnames(0)) coord0 = temperature&$temperature!0$end if
下面的指令碼會輸出以下圖形:
; =================================================;; 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: tType: floatTotal Size: 48 bytes 12 valuesNumber of Dimensions: 2Dimensions 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)latVariable: lon (coordinate)Type: integerTotal Size: 12 bytes 3 valuesNumber of Dimensions: 1Dimensions and sizes:[lon | 3]Coordinates: (0)-180(1)0(2)180Variable: lat (coordinate)Type: integerTotal Size: 16 bytes 4 valuesNumber of Dimensions: 1Dimensions and sizes:[lat | 4]Coordinates: (0)-90(1)-45(2)45(3)90(0)temperature(0)K