<div dir="ltr"><br><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(121, 6, 25); font-family: arial, sans-serif; font-size: 13px; font-weight: bold; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Dear Muhammad Rahiz</span><div>
<font class="Apple-style-span" color="#790619" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><b><br>
</b></span></font></div><div><font class="Apple-style-span" color="#790619" face="arial, sans-serif"><b>Thanx alot<span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">! this has solved my problem. one more thing I have data of such annual files for 57 years. this script gives me the output</span></b></font></div>
<div><font class="Apple-style-span" color="#790619" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><b>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</b></span></font></div>
<div><font class="Apple-style-span" color="#790619" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><b><br>
</b></span></font></div><div><font class="Apple-style-span" color="#790619" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><b>best regards</b></span></font></div>
<div><font class="Apple-style-span" color="#790619" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><b><br>
</b></span></font><div class="gmail_quote">On Thu, Mar 10, 2011 at 4:05 PM, Muhammad Rahiz <span dir="ltr"><<a href="mailto:muhammad.rahiz@ouce.ox.ac.uk">muhammad.rahiz@ouce.ox.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Dear Waheed,<br>
<br>
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?<br>
<br>
You could condense the script by creating a loop (not tested);<br>
<br>
*** Start of script ***<br>
m = 1<br>
while(m <= 10) # 10 = 1951-1960<br>
ifile = 'files.txt' # files.txt contains a list of your netcdf files<br>
rec = read(ifile)<br>
<br>
IO = sublin(rec,1)<br>
if(IO = 1)<br>
say ifile' > File open error'<br>
endif<br>
if (IO = 0)<br>
a = subwrd(rec,2)<br>
endif<br>
<br>
'sdfopen 'a''<br>
say ''<br>
say ' Filename: 'a''<br>
say ' File no: 'm''<div class="im"><br>
<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br></div>
'define var=ave(precip,t=121,t=151)' # change values if leap year<br>
<br>
'set sdfwrite yr.'m'.nc<br>
'sdfwrite 'var'<br>
<br>
'close 1'<br>
m = m + 1<br>
endwhile<br>
'quit'<br>
*** End of script ***<br>
<br>
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.<br>
<br>
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.<br><font color="#888888">
<br>
<br>
-- <br>
Muhammad Rahiz<br>
Researcher & DPhil Candidate (Climate Systems & Policy)<br>
School of Geography & the Environment<br>
University of Oxford</font><div><div></div><div class="h5"><br>
<br>
On Thu, 10 Mar 2011, Waheed wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all<br>
<br>
Grads version: 2.0.a8<br>
OS : RHL 5 (32bit).<br>
<br>
i am trying to find the monthly average precipitation from yearly nc files of daily data.<br>
i want to get ouput in nc format but monthly average for each month.<br>
dkiktev had sent me a script and i made modifications in it. now i m running it for 10<br>
years from 1951-1960 for the month of May . But i am having trouble with it.<br>
<br>
the script is as follows :<br>
* monthly average for the month on May from 1951-1960<br>
<br>
'sdfopen <a href="http://1951.nc" target="_blank">1951.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p51=ave(precip,t=121,t=151)'<br>
'close 1'<br>
'sdfopen <a href="http://1952.nc" target="_blank">1952.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p52=ave(precip,t=122,t=152)'<br>
'define sum1=p51+p52'<br>
'close 1'<br>
'undefine p51'<br>
'undefine p52'<br>
'sdfopen <a href="http://1953.nc" target="_blank">1953.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p53=ave(precip,t=121,t=151)'<br>
'define sum2=sum1+p53'<br>
'undefine sum1'<br>
'undefine p53'<br>
'close 1'<br>
'sdfopen <a href="http://1954.nc" target="_blank">1954.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p54=ave(precip,t=121,t=151)'<br>
'define sum3=sum2+p54'<br>
'undefine sum2'<br>
'undefine p54'<br>
'close 1'<br>
'sdfopen <a href="http://1955.nc" target="_blank">1955.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p55=ave(precip,t=121,t=151)'<br>
'define sum4=sum3+p55'<br>
'undefine sum3'<br>
'undefine p55'<br>
'close 1'<br>
'sdfopen <a href="http://1956.nc" target="_blank">1956.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p56=ave(precip,t=122,t=152)'<br>
'define sum5=sum4+p56'<br>
'undefine sum4'<br>
'undefine p56'<br>
'close 1'<br>
'sdfopen <a href="http://1957.nc" target="_blank">1957.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p57=ave(precip,t=121,t=151)'<br>
'define sum6=sum5+p57'<br>
'undefine sum5'<br>
'undefine p57'<br>
'close 1'<br>
'sdfopen <a href="http://1958.nc" target="_blank">1958.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p58=ave(precip,t=121,t=151)'<br>
'define sum7=sum6+p58'<br>
'undefine sum6'<br>
'undefine p58'<br>
'close 1'<br>
'sdfopen <a href="http://1959.nc" target="_blank">1959.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p59=ave(precip,t=121,t=151)'<br>
'define sum8=sum7+p59'<br>
'undefine sum7'<br>
'undefine p59'<br>
'close 1'<br>
'sdfopen <a href="http://1960.nc" target="_blank">1960.nc</a>'<br>
'set lat 23.025 37.475'<br>
'set lon <a href="tel:60.025%2079.975" target="_blank"></a><a href="tel:60.025%2079.975" target="_blank">60.025 79.975</a>'<br>
'define p60=ave(precip,t=122,t=152)'<br>
'define sum9=sum8+p60'<br>
'undefine sum8'<br>
'undefine p60'<br>
'close 1'<br>
'define pave=sum9/10'<br>
'set sdfwrite <a href="http://waheed.nc" target="_blank">waheed.nc</a>'<br>
'sdfwrite pave'<br>
'quit'<br>
<br>
It gives an error " define error : no files open yet"<br>
<br>
any suggestions for this script or if there is something better please tell .<br>
<br>
Thanx in advance<br>
<br>
<br>
Best regards<br>
--<br>
Waheed Iqbal<br>
(Meteorologist)<br>
Pakistan Meteorological Department<br>
R & D Islamabad,Pakistan<br>
+923334547814<br>
<br>
<br>
<br>
</blockquote>
</div></div><br>_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div>Waheed Iqbal</div><div>Meteorologist</div><div>Pakistan Meteorological Department</div><div>R & D Division, Islamabad,Pakistan.</div><div>+923334547814</div>
<div> </div><div> </div><br>
</div></div>