How to debug the error "fatal:syntax error: line 68 in file stdgsnClr.ncl before or near )"

From: Yi-Chih Huang <dscpln_at_nyahnyahspammersnyahnyah>
Date: Wed Dec 11 2013 - 02:23:48 MST

Hello,

    I am trying to use ESMF regrid functions to obtain the fields in a
lower resolution in a function, and then transport the variables to the
main script. I can show the 3x1 plots in the function and output "1" at
the end of the function as below. However, those three fields cannot be
transported back to the main script. The error message "fatal:syntax
error: line 68 in file stdgsnClr.ncl before or near ) " is so brief that I
cannot figure out what was wrong in the script especially I didn't have any
probem when using area_hi2lores_Wrap to get a lower resolution in a
function. Under such a condition, what can I do to debug the script?

    Thanks much,

            Yi-Chih

######
Variable: uStd_regrid_2x3
Type: float
Total Size: 126324 bytes
            31581 values
Number of Dimensions: 2
Dimensions and sizes: [lat | 121] x [lon | 261]
Coordinates:
            lat: [-89.25619506835938..89.25619506835938]
            lon: [0.6896551847457886..359.3103637695312]
Number Of Attributes: 16
  missing_value : 1e+20
  remap : remapped via ESMF_regrid_with_weights: Bilinear remapping
  stddev_op_ncl : dim_stddev_n over dimension(s): time
  _FillValue : 1e+20
  DataFreq : Monthly
  average_op_ncl : dim_avg_n over dimension(s): year
  lv_ISBL1 : 850
  center : US National Weather Service - NCEP (WMC)
  long_name : u-component of wind
  units : m/s
  level_indicator : 100
  gds_grid_type : 0
  parameter_table_version : 2
  parameter_number : 33
  model : Climate Data Assimilation System (CDAS)
  initial_time : 02/05/2006 (00:00)
(0) 1
fatal:syntax error: line 68 in file stdgsnClr.ncl before or near )
  out = stdgsnClr_nmm ()
-----------------------^

fatal:Syntax Error in block, block not executed
fatal:error at line 124 in file stdgsnClr.ncl

yhuang@arc-env:/fs3/yhuang/scripts$

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

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

  in= addfile("/fs3/yhuang/precip.mon.mean.nc","r") ; 197901-201306
  precip= in->precip

  prect= precip(24:335,{latS:latN},{lonE:lonW}) ; 198101-200612 Indian Ocean
  precy= clmMonTLL( prect )
  pcpStdTime = dim_stddev_n_Wrap( precy, 0 )
printVarSummary(pcpStdTime)

  yrStrt = 1979;1981
  yrLast = 2009;2006
  year = ispan(yrStrt, yrLast,1) ; integer
  yrDir = year + "/" ; string
  varName= (/"precip"/)
  nyr = dimsizes(year)

  dir1= "/fs3/SysE_DB/nmm/CFSR/Monthly/Mean/"
  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)
  f = addfile (dir+fil(0), "r")

  delete ([/fil,varName/])
  varName= (/"uwnd","vwnd"/)
  x := f->$varName(0)$
  dims = getfilevardims(f,varName(0))
  xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
  xu = dim_avg_n_Wrap( xs,0)
  ds = dimsizes(xs)
  xx := new((/nyr,12,ds(1),ds(2)/),float,"No_FillValue")

  do nf= 0,1 ; nf ahead of ny to read u,v seperately
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)

    f = addfile (dir+fil(nf), "r")
    x = f->$varName(nf)$
    dims = getfilevardims(f,varName(nf))
    xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
    xx(ny,:,:,:)= (/xs/)
    xx!0 = "year"

    if ( ny .eq. nyr-1 ) then
      uv = dim_avg_n_Wrap( xx, 0 )

      if ( nf .eq. 0 ) then
        uStdTime = dim_stddev_n_Wrap( uv, 0 )
      else if ( nf .eq. 1 ) then
        vStdTime = dim_stddev_n_Wrap( uv, 0 )
      end if
      end if
    end if
  end do
  end do
  copy_VarMeta(xu,uStdTime)
  copy_VarMeta(xu,vStdTime)
printVarSummary(uStdTime)

  out = stdgsnClr_nmm ()
printVarSummary(out)
  pcpStd_regrid_2x3= out[0]
  uStd_regrid_2x3 = out[1]
  vStd_regrid_2x3 = out[2]

  wks= gsn_open_wks("X11","stdgsnClr_both")
  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 = 25 ; for BlWhRe
; res@gsnSpreadColorEnd = 85 ; for BlWhRe
  res@gsnSpreadColorStart = 10 ; for BlueRed
  res@gsnSpreadColorEnd = 250 ; for BlueRed
  res@cnSpanFillPalette = True
  res@cnLinesOn = False ; turn off the contour
lines

  res@lbLabelBarOn = True
  res@pmLabelBarWidthF= 0.8
  res@lbLabelStride = 4
  res@mpFillOn = False
  res@mpOutlineBoundarySets = "National" ; turns on country
boundaries.
  res@cnFillDrawOrder = "Predraw"

  res@gsnDraw = False
load "$SysE/lib/ncl/helper_libs.ncl"
load "./season_from_month.ncl"
load "/fs3/yhuang/nmm/stdgsnClr.ncl"

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

  in= addfile("/fs3/yhuang/precip.mon.mean.nc","r") ; 197901-201306
  precip= in->precip

  prect= precip(24:335,{latS:latN},{lonE:lonW}) ; 198101-200612 Indian Ocean
  precy= clmMonTLL( prect )
  pcpStdTime = dim_stddev_n_Wrap( precy, 0 )
printVarSummary(pcpStdTime)

  yrStrt = 1979;1981
  yrLast = 2009;2006
  year = ispan(yrStrt, yrLast,1) ; integer
  yrDir = year + "/" ; string
  varName= (/"precip"/)
  nyr = dimsizes(year)

  dir1= "/fs3/SysE_DB/nmm/CFSR/Monthly/Mean/"
  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)
  f = addfile (dir+fil(0), "r")

  delete ([/fil,varName/])
  varName= (/"uwnd","vwnd"/)
  x := f->$varName(0)$
  dims = getfilevardims(f,varName(0))
  xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
  xu = dim_avg_n_Wrap( xs,0)
  ds = dimsizes(xs)
  xx := new((/nyr,12,ds(1),ds(2)/),float,"No_FillValue")

  do nf= 0,1 ; nf ahead of ny to read u,v seperately
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)

    f = addfile (dir+fil(nf), "r")
    x = f->$varName(nf)$
    dims = getfilevardims(f,varName(nf))
    xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
    xx(ny,:,:,:)= (/xs/)
    xx!0 = "year"

    if ( ny .eq. nyr-1 ) then
      uv = dim_avg_n_Wrap( xx, 0 )

      if ( nf .eq. 0 ) then
        uStdTime = dim_stddev_n_Wrap( uv, 0 )
      else if ( nf .eq. 1 ) then
        vStdTime = dim_stddev_n_Wrap( uv, 0 )
      end if
      end if
    end if
  end do
  end do
  copy_VarMeta(xu,uStdTime)
  copy_VarMeta(xu,vStdTime)
printVarSummary(uStdTime)

  out = stdgsnClr_nmm ()
printVarSummary(out)
  pcpStd_regrid_2x3= out[0]
  uStd_regrid_2x3 = out[1]
  vStd_regrid_2x3 = out[2]

  wks= gsn_open_wks("X11","stdgsnClr_both")
  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 = 25 ; for BlWhRe
; res@gsnSpreadColorEnd = 85 ; for BlWhRe
  res@gsnSpreadColorStart = 10 ; for BlueRed
  res@gsnSpreadColorEnd = 250 ; for BlueRed
  res@cnSpanFillPalette = True
  res@cnLinesOn = False ; turn off the contour
lines

  res@lbLabelBarOn = True
  res@pmLabelBarWidthF= 0.8
  res@lbLabelStride = 4
  res@mpFillOn = False
  res@mpOutlineBoundarySets = "National" ; turns on country
boundaries.
  res@cnFillDrawOrder = "Predraw"

  res@gsnDraw = False
  res@gsnFrame = False
  plot = new(6,graphic) ; create plot array
  res@cnLevelSelectionMode= "ManualLevels"
  res@cnMinLevelValF = 0.
  res@cnMaxLevelValF = 10.
  res@cnLevelSpacingF = 0.2
  res@gsnLeftString = "CFSR: Standard Deviation of Average Monthly Rain
Rate during JJAS"
  plot(0)= gsn_csm_contour_map(wks,pcpStdTime,res)
  res@gsnLeftString = "NMM: Standard Deviation of Average Monthly Rain
Rate during JJAS"
  plot(1)= gsn_csm_contour_map(wks,pcpStd_regrid_2x3,res)
  res@cnLevelSpacingF = 0.2
  res@gsnLeftString = "CFSR: Standard Deviation of Average Monthly Zonal
Wind during JJAS"
  plot(2)= gsn_csm_contour_map(wks,uStdTime,res)
  res@gsnLeftString = "NMM: Standard Deviation of Average Monthly Zonal
Wind during JJAS"
  plot(3)= gsn_csm_contour_map(wks,uStd_regrid_2x3,res)
  res@cnMinLevelValF = 0.
  res@cnMaxLevelValF = 7.
  res@cnLevelSpacingF = 0.1
  res@gsnLeftString = "CFSR: Standard Deviation of Average Monthly
Meridional Wind during JJAS"
  plot(4)= gsn_csm_contour_map(wks,vStdTime,res)
  res@gsnLeftString = "NMM: Standard Deviation of Average Monthly
Meridional Wind during JJAS"
  plot(5)= gsn_csm_contour_map(wks,vStd_regrid_2x3,res)

  gsn_panel(wks,plot,(/3,2/),False)
end

######
function stdgsnClr_nmm ()
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
local dir1, dir, fil, f, x, xs, xu, xx, dims, ds, pcp, pcpStdTime_nmm,
uStdTime_nmm, vStdTime_nmm
;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
  varName= (/"precip"/)
  nyr = dimsizes(year)

  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls precip.nc") ;;;;;;;; read
precipitation
  f = addfile (dir+fil, "r")
  x = f->$varName(0)$
  dims= getfilevardims(f,varName(0))
  xs = x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean, nmm data are only JJAS
  xu = dim_avg_n_Wrap( xs,0)
  ds = dimsizes(xs)
  nnm = ds(0)
  xx = new((/nyr,ds(0),ds(1),ds(2)/),float)
YYYYMM= new ( (/nyr,ds(0)/), double)

  delete (fil)
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls precip.nc")
    f = addfile (dir+fil, "r")

    x := f->$varName(0)$
    dims= getfilevardims(f,varName(0))
    xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
    xx(ny,:,:,:)= xs
    YYYYMM(ny,:) = cd_calendar(xs&$xs!0$, 1)
  end do
printMinMax(xx,True)
print(YYYYMM(0:2,0:3))

  pcp = dim_avg_n_Wrap( xx, 0 ) *86400 ; kg/m^2/s -> mm/day
  pcpStdTime_nmm = dim_stddev_n_Wrap( pcp, 0 )
  copy_VarMeta(xu,pcpStdTime_nmm)
printVarSummary(pcpStdTime_nmm)

;---Input file containing source grid
    srcFileName = "pregpcp.test.daily.nc"

;---Filenames for source, destination, and weight files
    srcGridName = "src_SCRIP.nc"
    dstGridName_2x3 = "dst_SCRIP_2x3.nc"
    wgtFile_2x3_pfx = "Fixed_2_2x3"
    outFile_2x3_pfx = "pregpcp_regrid_2x3"

;---Interpolation methods to use
    methods = (/"bilinear","patch","conserve"/)
    nmethods = dimsizes(methods)

;---Read variable to regrid
    dimx = dimsizes( pcpStdTime_nmm )
    nlat = dimx(0)
    mlon = dimx(1)

;---Create destination lat/lon arrays
    NLAT2x3 = 72
    MLON2x3 = 144
    LAT2x3 = latGlobeFo(NLAT2x3, "LAT2x3", "latitude" , "degrees_north")
    LON2x3 = lonGlobeFo(MLON2x3, "LON2x3", "longitude", "degrees_east" )

;---Common resources
    Opt = True

    Opt@SrcFileName = srcGridName ; name of output source file
    Opt@ForceOverwrite = True

    Opt@SrcInputFileName = srcFileName ; optional, but good idea
    Opt@SrcTitle = "GPCP Grid"

    ;;Opt@PrintTimings = True
    ;;Opt@Debug = True

;---Create separate options for each destination grid
    Optp2x3 = Opt
    Optp2x3@DstTitle = "2x3"
    Optp2x3@DstGridLon = LON2x3
    Optp2x3@DstGridLat = LAT2x3
    Optp2x3@DstFileName = dstGridName_2x3

    Optp2x3@InterpMethod = methods(0) ; performance 0,1 >> 2
    pcpStd_regrid_2x3 = ESMF_regrid(pcpStdTime_nmm,Optp2x3)
    printVarSummary(pcpStd_regrid_2x3)

  delete ([/fil,varName/])
  dir1= "/fs3/SysE_DB/nmm/NMM/Monthly/Mean/"
  dir = str_concat(dir1+yrDir(0))
  fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)
  f = addfile (dir+fil(0), "r")

  varName= (/"uwnd","vwnd"/)
  x := f->$varName(0)$
  dims = getfilevardims(f,varName(0))
  xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean, nmm data are only
JJAS
  ds = dimsizes(xs)
  xx := new((/nyr, 5,ds(1),ds(2)/),float,"No_FillValue")

  delete (fil)
  do nf= 0,1
  do ny= 0,nyr-1
    dir = str_concat(dir1+yrDir(ny))
    fil = systemfunc("cd "+dir+" ; ls *wnd_850.nc") ; input file name(s)

    f = addfile (dir+fil(nf), "r")
    x = f->$varName(nf)$
    dims = getfilevardims(f,varName(nf))
    xs := x(:,{latS:latN},{lonE:lonW}) ; Indian Ocean
    xx(ny,0:3,:,:)= xs ; 0:3 & 0 in 4 to estimate std dev of annual cycle
    xx!0 = "year"

    if ( ny .eq. nyr-1 ) then
      uv = dim_avg_n_Wrap( xx, 0 )

      if ( nf .eq. 0 ) then
        uStdTime_nmm = dim_stddev_n_Wrap( uv, 0 )
      else if ( nf .eq. 1 ) then
        vStdTime_nmm = dim_stddev_n_Wrap( uv, 0 )
      end if
      end if
    end if
  end do
  end do
printVarSummary(uStdTime_nmm)

;---Read variable to regrid
    dimx = dimsizes( uStdTime_nmm )
    nlat = dimx(0)
    mlon = dimx(1)

;---Create destination lat/lon arrays
    NLAT2x3:= 121
    MLON2x3:= 261
    LAT2x3 := latGlobeFo(NLAT2x3, "LAT2x3", "latitude" , "degrees_north")
    LON2x3 := lonGlobeFo(MLON2x3, "LON2x3", "longitude", "degrees_east" )

;---Create separate options for each destination grid
    Optw2x3 = Opt
    Optw2x3@DstTitle = "2x3"
    Optw2x3@DstGridLon = LON2x3
    Optw2x3@DstGridLat = LAT2x3
    Optw2x3@DstFileName = dstGridName_2x3

    Optw2x3@InterpMethod = methods(0) ; performance 0,1 >> 2
    uStd_regrid_2x3 = ESMF_regrid(uStdTime_nmm,Optw2x3)
    vStd_regrid_2x3 = ESMF_regrid(vStdTime_nmm,Optw2x3)
 printVarSummary(uStd_regrid_2x3)

  wks= gsn_open_wks("X11","stdgsnClr_nmm")
  gsn_define_colormap(wks,"BlueRed")
  plot = new(3,graphic) ; create plot array

  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 = 25 ; for BlWhRe
; res@gsnSpreadColorEnd = 85 ; for BlWhRe
  res@gsnSpreadColorStart = 10 ; for BlueRed
  res@gsnSpreadColorEnd = 250 ; for BlueRed
  res@cnSpanFillPalette = True
  res@cnLinesOn = False ; turn off the contour
lines

  res@lbLabelBarOn = True
  res@pmLabelBarWidthF= 0.8
  res@lbLabelStride = 4
  res@mpFillOn = False
  res@mpOutlineBoundarySets = "National" ; turns on country
boundaries.
  res@cnFillDrawOrder = "Predraw"

  res@gsnDraw = False
  res@gsnFrame = False
  res@cnLevelSelectionMode= "ManualLevels"
  res@cnMinLevelValF = 0.
  res@cnMaxLevelValF = 10.
  res@cnLevelSpacingF = 0.2
  res@gsnLeftString = "NMM: Average Monthly Rrecipitation Rate during
JJAS"
  plot(0)= gsn_csm_contour_map(wks,pcpStd_regrid_2x3,res)
  res@cnLevelSpacingF = 0.2
  res@gsnLeftString = "NMM: Average U Component of Wind during JJAS"
  plot(1)= gsn_csm_contour_map(wks,uStd_regrid_2x3,res)
  res@cnMinLevelValF = 0.
  res@cnMaxLevelValF = 7.
  res@cnLevelSpacingF = 0.1
  res@gsnLeftString = "NMM: Average U Component of Wind during JJAS"
  plot(2)= gsn_csm_contour_map(wks,vStd_regrid_2x3,res)

  gsn_panel(wks,plot,(/3,1/),False)
print("1")

; return ([/pcpStd_regrid_2x3,uStdTimeLo,vStdTimeLo/])
  return ([/pcpStd_regrid_2x3,uStd_regrid_2x3,vStd_regrid_2x3/])
end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Dec 11 02:24:02 2013

This archive was generated by hypermail 2.1.8 : Fri Dec 13 2013 - 11:39:30 MST