Hi Dave,
Thanks! This works for my do loop. I need to sum two dim array in loop. But how to average the two dimenison arry which has Fill values in the arry. My script is:
----------------
do id = 1, 30
if (id .lt. 10) then
id_str = "0" + id
else
id_str = "" + id
end if
do it = 0, 18, 6
if (it .lt. 10) then
it_str = "0" + it
else
it_str = "" + it
end if
fname = id_str + it_str
f = addfile ("/data14/cluo/WRFV3.2.1/WRFDATA/CFSR/201008/flxf01.gdas.201008"+fname+".grb2","r")
avgprecip = avgprecip + f->CPRAT_P8_L1_GGA0_avg
end do
end do
avgprecip = avgprecip/30./4.
-------------------
In above script, CPRAT_P8_L1_GGA0_avg is two dim array, which has Fill values in the array.
Thanks,
Chao
----- Original Message -----
From: "David Brown" <dbrown@ucar.edu>
To: "Chao Luo" <chao.luo@eas.gatech.edu>
Cc: ncl-talk@ucar.edu
Sent: Wednesday, November 9, 2011 4:51:34 PM
Subject: Re: do loop problem
Hi Chao,
I see a number of things wrong.
In the do loop you spelled "precip" as "prcip" on the addfile line. That means that avgprecip always gets set to the first value of precip that you initialize before the do loop.
You define id and it as integers for the do loops but then you try to make them into strings. You need separate string variables and you certainly do not want to modify the loop counter variables within the loop.
The expression "id" is not going to give you the integer value of the variable id as a string, it is going to give you the string "id"
Also if you are getting the complete variable, it is more efficient not to use '(:,:)'
You should indent properly as well
NCL does not have a single line "if" statement. Try this:
do id = 1, 30
if (id .lt. 10) then
id_str = "0" + id
else
id_str = "" + id
end if
do it = ....
etc. Hope this helps.
-dave
On Nov 9, 2011, at 4:55 PM, Chao Luo wrote:
> Hi,
>
> I want to average one parameter in CFSR files. The file name like:
> gdas.2010080100.grb2, gads.2010080106.grbs, gads.2010080112.grb, gads.2010080118.grb2
> gdas.2010080200.grb2, gads.2010080206.grbs, gads.2010080212.grb, gads.2010080218.grb2
> ...
>
> The NCL script I wrote as follows, but it dosn't work. Any help is very apprciated!
>
> Thanks much!
>
> Chao
>
> ------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
> f = addfile ("/data14/cluo/WRFV3.2.1/WRFDATA/CFSR/201008/flxf01.gdas.2010080100.grb2", "r")
> precip = f-> CPRAT_P8_L1_GGA0_avg(:,:)
> avgprecip = precip
> avgprecip(:,:) = 0.
>
> ;;;do loop for month files
>
> do id = 1, 30
> if ( id.lt.10 ) then id = 0 + "id"
> do it = 0, 18, 6
> if (it.lt.10) then it = 0 + "it"
> fname = "id" + "it"
> f = addfile ("/data14/cluo/WRFV3.2.1/WRFDATA/CFSR/201008/flxf01.gdas.201008+"fname","r")
> prcip = f->CPRAT_P8_L1_GGA0_avg(:,:) ; total precipitation
> avgprecip(:,:) = avgprecip(:,:) + precip(:,:)
> end do
> end do
> avgprecip(:,:) = avgprecip(:,:)/30./4.
> end
> ------------------------
> _______________________________________________
> 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 Wed Nov 9 21:53:58 2011
This archive was generated by hypermail 2.1.8 : Mon Nov 14 2011 - 10:41:55 MST