Re: do loop problem

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 09 2011 - 17:51:34 MST

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 17:51:40 2011

This archive was generated by hypermail 2.1.8 : Mon Nov 14 2011 - 10:41:55 MST