[gradsusr] help in monthly average precipitation script for aphrodite data

Waheed waheed.met at gmail.com
Fri Mar 11 12:24:08 EST 2011


Dear Muhammad Rahiz
*
*
*Thanx alot! this has solved my problem. one more thing I have data of
such annual files for 57 years. this script gives me the output*
*for every month. now i want to combine these all 57 files , i know conv can
do this but this gives a file with sum of 57 years if i want to write the
file by dividing the variable var by 57 how can i do it*
*
*
*best regards*
*
*
On Thu, Mar 10, 2011 at 4:05 PM, Muhammad Rahiz <
muhammad.rahiz at ouce.ox.ac.uk> wrote:

> Dear Waheed,
>
> A quick query and a suggestion which follows. If you're trying to get the
> monthly average for May (t=121,t=151) for each year which you've done by
> 'p53=ave(precip,t=121,t=151)', why do you need to issue 'sum7=sum6+p58'
> which suggests a cumulative total?
>
> You could condense the script by creating a loop (not tested);
>
> *** Start of script ***
> m = 1
> while(m <= 10)          # 10 = 1951-1960
>  ifile = 'files.txt'    # files.txt contains a list of your netcdf files
>  rec = read(ifile)
>
>  IO = sublin(rec,1)
>  if(IO = 1)
>   say ifile' > File open error'
>  endif
>  if (IO = 0)
>   a = subwrd(rec,2)
>  endif
>
> 'sdfopen 'a''
> say ''
> say ' Filename: 'a''
> say ' File no: 'm''
>
>
> 'set lat 23.025 37.475'
> 'set lon <60.025%2079.975>60.025 79.975'
> 'define var=ave(precip,t=121,t=151)' # change values if leap year
>
> 'set sdfwrite yr.'m'.nc
> 'sdfwrite 'var'
>
> 'close 1'
> m = m + 1
> endwhile
> 'quit'
> *** End of script ***
>
> What this does is to produce the May average for each year and write the
> output to a separate file for each year. The sdfwrite command does not allow
> to write >1 variable to a file. But this can be overcome by concantenating
> the files using other utilities like NetCDF operators, CDO.
>
> Since you're dealing with leap years, you could specify the files
> containing leap years in files.txt and change the 't' values and repeat the
> step for non-leap years.
>
>
> --
> Muhammad Rahiz
> Researcher & DPhil Candidate (Climate Systems & Policy)
> School of Geography & the Environment
> University of Oxford
>
>
> On Thu, 10 Mar 2011, Waheed wrote:
>
>  Dear all
>>
>> Grads version: 2.0.a8
>> OS : RHL 5 (32bit).
>>
>> i am trying to find the monthly average precipitation from yearly nc files
>>  of daily data.
>> i want to get ouput in nc format but monthly average for each month.
>> dkiktev had sent me a script and i made modifications in it. now i m
>> running it for 10
>> years from 1951-1960 for the month of May . But i am having trouble with
>> it.
>>
>> the script is as follows :
>> * monthly average for the month on May from 1951-1960
>>
>> 'sdfopen 1951.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p51=ave(precip,t=121,t=151)'
>> 'close 1'
>> 'sdfopen 1952.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p52=ave(precip,t=122,t=152)'
>> 'define sum1=p51+p52'
>> 'close 1'
>> 'undefine p51'
>> 'undefine p52'
>> 'sdfopen 1953.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p53=ave(precip,t=121,t=151)'
>> 'define sum2=sum1+p53'
>> 'undefine sum1'
>> 'undefine p53'
>> 'close 1'
>> 'sdfopen 1954.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p54=ave(precip,t=121,t=151)'
>> 'define sum3=sum2+p54'
>> 'undefine sum2'
>> 'undefine p54'
>> 'close 1'
>> 'sdfopen 1955.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p55=ave(precip,t=121,t=151)'
>> 'define sum4=sum3+p55'
>> 'undefine sum3'
>> 'undefine p55'
>> 'close 1'
>> 'sdfopen 1956.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p56=ave(precip,t=122,t=152)'
>> 'define sum5=sum4+p56'
>> 'undefine sum4'
>> 'undefine p56'
>> 'close 1'
>> 'sdfopen 1957.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p57=ave(precip,t=121,t=151)'
>> 'define sum6=sum5+p57'
>> 'undefine sum5'
>> 'undefine p57'
>> 'close 1'
>> 'sdfopen 1958.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p58=ave(precip,t=121,t=151)'
>> 'define sum7=sum6+p58'
>> 'undefine sum6'
>> 'undefine p58'
>> 'close 1'
>> 'sdfopen 1959.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p59=ave(precip,t=121,t=151)'
>> 'define sum8=sum7+p59'
>> 'undefine sum7'
>> 'undefine p59'
>> 'close 1'
>> 'sdfopen 1960.nc'
>> 'set lat 23.025 37.475'
>> 'set lon <60.025%2079.975>60.025 79.975'
>> 'define p60=ave(precip,t=122,t=152)'
>> 'define sum9=sum8+p60'
>> 'undefine sum8'
>> 'undefine p60'
>> 'close 1'
>> 'define pave=sum9/10'
>> 'set sdfwrite waheed.nc'
>> 'sdfwrite pave'
>> 'quit'
>>
>> It gives an error " define error : no files open yet"
>>
>> any suggestions for this script or if there is something better please
>> tell .
>>
>> Thanx in advance
>>
>>
>> Best regards
>> --
>> Waheed Iqbal
>>  (Meteorologist)
>> Pakistan Meteorological Department
>> R & D Islamabad,Pakistan
>> +923334547814
>>
>>
>>
>>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Waheed Iqbal
Meteorologist
Pakistan Meteorological Department
R & D Division, Islamabad,Pakistan.
+923334547814
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20110311/919e9c16/attachment-0003.html 


More information about the gradsusr mailing list