Re: Loop over Variables

From: IMRAN NADEEM <qphoton_at_nyahnyahspammersnyahnyah>
Date: Thu, 20 Nov 2008 17:46:48 +0100

Hi Alvaro,

      Thanks for your reply. Your are right, I want to have this from
escorc(reord1,reorder_obs) instead of escorc("reord1",reorder_obs).
But when I reference variable by putting it within dollar signs '$', I get
error. I tried your script and got the same error:

*************************************************
fatal:syntax error: line 66 in file new_cor.ncl before or near $
 corr=escorc($
-------------^
fatal:Syntax Error in block, block not executed
********************************

Regards
Nadeem

On Thu, Nov 20, 2008 at 5:21 PM, "Álvaro M. Valdebenito B." <
alvaro.valdebenito_at_met.no> wrote:

> Dear Nadeem,
> it seems to me that you are mixing up the variables
> with the names that you used on your old code.
>
> For instance, in the following line
> corr_nam(i)=escorc(reord_nam(i),reorder_obs)
> you want something like
> corr1=escorc(reord1,reorder_obs)
> but what you wrote is equivalent to
> corr_nam(i)=escorc("reord1",reorder_obs)
>
> You need to change such lines into something like:
> corr=escorc($reord_nam(i)$,reorder_obs)
>
> I reorganised a bit your script, but I'm not sure that this
> changes will speed up thing for you. I hope it helps.
>
> Álvaro.
>
> IMRAN NADEEM wrote:
>
>> Dear Users,
>>
>> I am facing problem using do loop over variables in the input file.
>> The attached script is an attempt to reduce the original script. In original
>> script,
>> I handled each variable individually (without using do loops) and it
>> worked fine but it got too lengthy.
>>
>> Any help/suggestion is welcomed
>> Regards
>> Nadeem
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> --
> Álvaro M. Valdebenito B. alvaro.valdebenito_at_met.no
> Air Pollution Section/Research Department Tel. +47-2296 3397
> Norwegian Meteorological Institute http:\\www.met.no
> P.O. Box 43 Blindern, 0313 Oslo, NORWAY http:\\www.emep.int/CWF
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> infile="Precip_all7_rgrid.nc" ; input file
> nc_file= addfile(infile,"r")
>
> rt1= nc_file->rt_old (lat|:,lon|:,time|:)
> rt2= nc_file->rt_as (lat|:,lon|:,time|:)
> rt3= nc_file->rt_em (lat|:,lon|:,time|:)
> rt4= nc_file->rt_25km (lat|:,lon|:,time|:)
> rt5= nc_file->rt_mm5 (lat|:,lon|:,time|:)
> rt6= nc_file->rt_czech(lat|:,lon|:,time|:)
> obs= nc_file->rt_obs (lat|:,lon|:,time|:) ;observations
> lon= nc_file->lon
> lat= nc_file->lat
>
> var_nam =(/"rt1","rt2","rt3","rt4","rt5","rt6","obs"/)
> ;
> reord_nam=(/"reord1","reord2","reord3","rord4","reord5","reord6","reord_obs"/)
> ; corr_nam=(/"corr1","corr2","corr3","corr4","corr5","corr6"/)
> ; avg_nam=(/"avg1","avg2","avg3","avg4","avg5","avg5"/)
> titl_nam=(/"Reg-Def" ,"Reg-AS" ,"Reg-EM","Reg-25km", "MM5","Reg_Czech"/)
> nvar=dimsizes(var_nam)
>
> plots = new(nvar-1,graphic) ;6 plots
> wks = gsn_open_wks("eps","Correlation")
> gsn_define_colormap(wks,"BrownBlue12")
>
> res = True
> res_at_gsnMaximize = True
> res_at_gsnDraw = False ; don't draw
> res_at_gsnFrame = False ; don't advance frame
> res_at_gsnAddCyclic = False ; regional data
>
> ; Setting contour resources
> res_at_cnLevelSelectionMode = "ExplicitLevels" ; Define own levels.
> res_at_cnLevels = (/-0.4,-0.2,-0.1,0.1,0.2,0.4,0.6,0.8,0.9,1.0/)
> res_at_cnFillOn = True
> res_at_cnLinesOn = False
> res_at_cnLineLabelsOn = False
> res_at_cnRasterModeOn = True
> res_at_lbLabelBarOn = False
>
> ; Setting map resources
> res_at_mpOutlineBoundarySets ="National"
> res_at_mpMinLatF = 43. ; range to zoom in on
> res_at_mpMaxLatF = 49.3
> res_at_mpMinLonF = 4.
> res_at_mpMaxLonF = 17.
>
> res_at_gsnCenterString = " "
> res_at_tiMainString = " "
> res_at_tmYROn = False ; Turn off right and top tick marks
> res_at_tmXTOn = False ; Turn off right and top tick marks
>
>
> corr=new((/dimsizes(lat),dimsizes(lon)/)float)
> ; Assign dimension names and coordinate variables.
> corr!0 = "lat"
> corr!1 = "lon"
> corr&lon=lon
> corr&lat=lon
>
> do i = 0, nvar-2
> ; calculate cross correlations with observed data
> corr=escorc($var_nam(i)$,obs)
>
> ;Calculate domain average of correlation
> avgn=avg(corr)
>
> res_at_gsnRightString = "Avg="+avgn
> res_at_gsnLeftString = titl_nam(i)
> plots(i) = gsn_csm_contour_map(wks,corr,res)
> end do
>
> pnlres = True
> pnlres_at_txString = "Temporal Correlation 1981-1990"
> pnlres_at_gsnPanelLabelBar = True
> pnlres_at_gsnPanelDebug=True
> pnlres_at_gsnPanelXF = (/-1,.53,-1,.53,-1,.53/) ; Adjust rightmost plots
> pnlres_at_gsnPanelYF = (/-1,-1,.62,.62,.35,.35/) ; Adjust bottommost
> plots.
>
> gsn_panel(wks,plots,(/3,2/),pnlres)
>
> end
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Nov 20 2008 - 09:46:48 MST

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 11:38:52 MST