Re: read a variable from another NCL script

From: Yi-Chih Huang <dscpln_at_nyahnyahspammersnyahnyah>
Date: Tue Dec 03 2013 - 20:11:23 MST

Hello,

    These two scripts are almost the same. The x on line 27 was used the
first time in the script. Probably I loaded another script in the
beginning so that the error "fatal:Dimension sizes of left hand side and
right hand side of assignment do not match" appeared. But, after I deleted
many variables before line 27 by "delete
([/fil,x,xs,xy,xx,tl,t,ty,la,lat/])", still "fatal:Variable (x) is
undefined", and "fatal:Undefined identifier: (ty_nmm) is undefined" showed
up. How to fix these errors and how to give local variables in a script
and not to pass these variables when it was called by other NCL script?

    Thanks much,

              Yi-Chih

######
fatal:syntax error: line 91 in file
$NCARG_ROOT/lib/ncarg/nclscripts/csm/contrib ted.ncl before or near undef
undef
----^

fatal:syntax error: line 92 in file
$NCARG_ROOT/lib/ncarg/nclscripts/csm/contrib ted.ncl before or near
size_array
function size_array
------------------^

fatal:Function identifier is defined
fatal:Variable (x) is undefined
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 94 in file
$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl

warning:Dimension (0) has not been defined

warning:Dimension (0) has not been defined
fatal:Undefined identifier: (ty_nmm) is undefined, can't continue
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 102 in
file t.ncl

On Wed, Dec 4, 2013 at 11:38 AM, Jatin Kala <jatin.kala.jk@gmail.com> wrote:

> x seems to be defined twice in your script. You do not delete it before
> defining it the second time, it seems. I would fix that first and re-try.
> Cheers,
> Jatin.
>
>
>
>
>
>
> On 04/12/2013, at 1:29 PM, Yi-Chih Huang wrote:
>
> Hello,
>
> In fact, helper_libs.ncl includes many NCL scripts. I replaced
> helper_libs.ncl with those in $NCARG_ROOT. Some errors showed up as
> follows. The command about the error on line 27 is "x =
> f->$varName(0)$" that was right when executing separately. I wonder why x
> should be defined when the script called a procedure?
>
> Thanks much,
>
> Yi-Chih
>
> ######
> ;load "$SysE/lib/ncl/helper_libs.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> ######
> yhuang@arc-env:/fs3/yhuang/scripts$ ncl t.ncl
> 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.
> fatal:syntax error: line 91 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl before or near undef
> undef
> ----^
>
> fatal:syntax error: line 92 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl before or near
> size_array
> function size_array
> ------------------^
>
> fatal:Function identifier is defined
> fatal:Variable (x) is undefined
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 94 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>
> warning:Dimension (0) has not been defined
>
> fatal:Dimension sizes of left hand side and right hand side of assignment
> do not match
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 27 in
> file t.ncl
>
>
>
> On Wed, Dec 4, 2013 at 10:54 AM, Rick Brownrigg <brownrig@ucar.edu> wrote:
>
>> Hi,
>>
>> Its hard to pinpoint the problem exactly from what you sent, but the
>> error messages seem pretty explicit. You might open in an editor your file
>> " $SysE/lib/ncl/helpers/analysis_helper.ncl" and look at the line numbers
>> mentioned in the errors to find the problems. Looks like at least two
>> variables (dirName and aString) are referenced before they are ever defined.
>>
>> Hope that helps…
>> Rick
>>
>> On Dec 3, 2013, at 6:25 PM, Yi-Chih Huang <dscpln@gmail.com> wrote:
>>
>> 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
>>
>>
>>
> _______________________________________________
> 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 20:11:37 2013

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