Re: read a variable from another NCL script

From: Yi-Chih Huang <dscpln_at_nyahnyahspammersnyahnyah>
Date: Tue Dec 03 2013 - 18:25:24 MST

Hello,

     I used t_nmm(ty_nmm), procedure and load to read the variable because
another NCL script is in a different directory as follows. These two
scripts are almost the same. I am trying to draw two lines on the same
plot to see the detail. Originally these two scripts separately worked
just fine without any error message. But after I changed one script to
procedure, there were numerous error message showing up that never happened
before. What do you think the problem is in the scripts?

    Thanks much,

          Yi-Chih

.....
fatal:error in statement
fatal:Variable (dirName) is undefined
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 99 in file
$SysE/lib/ncl/helpers/analysis_helper.ncl

fatal:syntax error: line 101 in file
$SysE/lib/ncl/helpers/analysis_helper.ncl before or near pp
procedure pp
-----------^

fatal:error in statement
fatal:Variable (aString) is undefined
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 103 in
file $SysE/lib/ncl/helpers/analysis_helper.ncl

fatal:syntax error: line 105 in file
$SysE/lib/ncl/helpers/analysis_helper.ncl before or near TerminateProgram
procedure TerminateProgram
-------------------------^

fatal:error in statement
(0) Program Terminated

#####
load "$SysE/lib/ncl/helper_libs.ncl"
load "/fs3/yhuang/nmm/t.ncl"

begin
  latS = -30.0
  latN = 30.0
  lonE = 30.0
  lonW = 160.0

  dir1 = "/fs3/SysE_DB/nmm/CFSR/Monthly/Mean/"
  yrStrt = 1981
  yrLast = 2006
  year = ispan(yrStrt, yrLast,1) ; integer
  yrDir = year + "/" ; string
  nyr = dimsizes(year)

  lvl = (/"200","500"/)
  nlvl = dimsizes(lvl)
  varName= (/"t","lat"/)

  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls t_200.nc")
  f = addfile (dir+fil(0), "r")
  x = f->$varName(0)$
  dims = getfilevardims(f,varName(0))
  xs = x(5:8,{latS:latN},{lonE:lonW}) ; Indian Ocean
  xy = dim_avg_n_Wrap( xs, 0 )
  ds = dimsizes(xy)
  xx = new((/nyr,nlvl,ds(0),ds(1)/),float,"No_FillValue")

  delete (fil)
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls t_200.nc t_500.nc")
    nlvl= dimsizes(fil)

    do nl= 0,nlvl-1
      f = addfile (dir+fil(nl), "r")

      x = f->$varName(0)$
      dims = getfilevardims(f,varName(0))
      xs = x(5:8,{latS:latN},{lonE:lonW}) ; Indian Ocean
      xy = dim_avg_n_Wrap( xs, 0 )
      xx(ny,nl,:,:)= xy
    end do
  end do

  tl= dim_avg_n_Wrap( xx, 0 )
  tl!0 = "level"
  t= dim_avg_n_Wrap( tl, 0 )

  ty = dim_avg_n_Wrap( t, 1 )
  f = addfile (dir+fil(0), "r")
  la = f->$varName(1)$
  dims = getfilevardims(f,varName(1))
  lat = la({$dims(1)$|30:-30})

  t_nmm(ty_nmm)

  wks= gsn_open_wks("pdf","t_CFSR")
  gsn_define_colormap(wks,"BlueRed") ; use the BlueRed colormap
(instead of default colormap)

  res = True
  res@gsnAddCyclic = False
  res@mpMinLatF = -30
  res@mpMaxLatF = 30
  res@mpMinLonF = 30
  res@mpMaxLonF = 160
  res@cnFillOn = True
  res@gsnSpreadColors = True ; use full colormap
  res@gsnSpreadColorStart = 10 ; for BlueRed
  res@gsnSpreadColorEnd = 250 ; for BlueRed
  res@cnSpanFillPalette = True
  res@cnLinesOn = False ; turn off the contour
lines
  res@cnLevelSelectionMode= "ManualLevels"
  res@cnMinLevelValF = 238
  res@cnMaxLevelValF = 249
  res@cnLevelSpacingF = 0.5

  res@lbLabelBarOn = True
  res@pmLabelBarWidthF= 0.8
  res@lbLabelStride = 4
  res@mpFillOn = False
  res@mpOutlineBoundarySets = "National" ; turns on country
boundaries.
  res@gsnLeftString = "CFSR: Average Monthly Temperature between 200-500
hPa during JJAS"
  res@cnFillDrawOrder = "Predraw"

  plot = gsn_csm_contour_map(wks,t,res)

  wks = gsn_open_wks ("pdf","tXY_CFSR")
  resL = True
  resL@tiMainString = "CFSR: Average Monthly Temperature during JJAS"
  resL@xyLineColor = "Brown"
  resR@xyLineColor = "NavyBlue"
  plot =
gsn_csm_xy2(wks,ty&lat,ty({lat|-30:30}),ty_nmm({lat|-30:30}),resL,resR)
end

#####
procedure t_nmm (ty)

load "$SysE/lib/ncl/helper_libs.ncl"

begin
  latS = -30.0
  latN = 30.0
  lonE = 30.0
  lonW = 160.0

  dir1 = "/fs3/SysE_DB/nmm/NMM/Monthly/Mean/"
  yrStrt = 1981
  yrLast = 2006
  year = ispan(yrStrt, yrLast,1) ; integer
  yrDir = year + "/" ; string
  nyr = dimsizes(year)

  lvl = (/"200","500"/)
  nlvl= dimsizes(lvl)
  varName= (/"temp","lat"/)

  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls temp_200.nc")
  f = addfile (dir+fil(0), "r")
  x = f->$varName(0)$
  dims = getfilevardims(f,varName(0))
  xs = x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
  xy = dim_avg_n_Wrap( xs, 0 )
  ds = dimsizes(xy)
  xx = new((/nyr,nlvl,ds(0),ds(1)/),float,"No_FillValue")

  delete (fil)
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls temp_2??.nc temp_5??.nc")
    nlvl = dimsizes(fil)

    do nl= 0,nlvl-1
      f = addfile (dir+fil(nl), "r")

      x = f->$varName(0)$
      dims = getfilevardims(f,varName(0))
      xs = x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
      xy = dim_avg_n_Wrap( xs, 0 )
      xx(ny,nl,:,:)= xy
    end do
  end do

  tl= dim_avg_n_Wrap( xx, 0 )
  tl!0 = "level"
  t = dim_avg_n_Wrap( tl, 0 )

  ty = dim_avg_n_Wrap( t, 1 )
  f = addfile (dir+fil(0), "r")
  la = f->$varName(1)$
  dims = getfilevardims(f,varName(1))
  lat = la({$dims(1)$|30:-30}) ; get latitudes in the domain
printVarSummary(t)
printVarSummary(ty)
printVarSummary(lat)

  wks= gsn_open_wks("pdf","t_nmm")
  gsn_define_colormap(wks,"BlueRed")

  res = True
  res@gsnAddCyclic = False
  res@mpMinLatF = -30
  res@mpMaxLatF = 30
  res@mpMinLonF = 30
  res@mpMaxLonF = 160
  res@cnFillOn = True
  res@gsnSpreadColors = True ; use full colormap
  res@gsnSpreadColorStart = 10 ; for BlueRed
  res@gsnSpreadColorEnd = 250 ; for BlueRed
  res@cnSpanFillPalette = True
  res@cnLinesOn = False ; turn off the contour
lines
  res@cnLevelSelectionMode= "ManualLevels"
  res@cnMinLevelValF = 238
  res@cnMaxLevelValF = 249
  res@cnLevelSpacingF = 0.5

  res@lbLabelBarOn = True
  res@pmLabelBarWidthF= 0.8
  res@lbLabelStride = 4
  res@mpFillOn = False
  res@mpOutlineBoundarySets = "National" ; turns on country
boundaries.
  res@gsnLeftString = "NMM: Average Monthly Temperature between 200-500
hPa during JJAS"
  res@cnFillDrawOrder = "Predraw"

  plot = gsn_csm_contour_map(wks,t,res)

  wks = gsn_open_wks ("pdf","tXY_nmm")
  xyres = True
  xyres@tiMainString = "CFSR: Average Monthly Temperature during JJAS"
  plot = gsn_csm_xy (wks,ty&lat,ty({lat|-30:30}),xyres)
end

On Wed, Dec 4, 2013 at 1:48 AM, Dennis Shea <shea@ucar.edu> wrote:

>
> A counterparts to a fortran subroutine and function
> are an NCL procedure and function. These are both
> discussed in the Mini-Language Manual and the NCL
> Reference Manual.
>
> Many functions and procedures are in
>
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl
> $NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl
> $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>
> %> less $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>
> ===
> WRAPIT is for interlanguage communication:
> NCL which is written in C and Fortran
>
>
>
> On 12/3/13 12:24 AM, Yi-Chih Huang wrote:
>
>> Hello,
>>
>> I am trying to read a variable from another NCL script. WRAPIT does
>> not seem to support this function from the Mini-Language Manual. What is
>> a
>> simple way to read variable from another NCL script? Is there a
>> counterpart of Fortran subroutine on NCL?
>>
>> Thanks much,
>>
>> Yi-Chih
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Dec 3 18:25:42 2013

This archive was generated by hypermail 2.1.8 : Wed Dec 04 2013 - 20:42:38 MST