[gradsusr] Fw: problem with an extract script
Muhammad Rahiz
muhammad.rahiz at ouce.ox.ac.uk
Wed Jan 5 14:23:53 EST 2011
Hi Ismaila,
The attached script may help you achieve what you want but you need to
modify it to adapt to your requirements. What you should do
is to first create a *.txt file (see sample timesteps.txt) with two
columns. The first column is the timestep for first day of June. The second is the timestep
for the last day of Sep. Add 365 to both columns to get the timesteps for the second year and so on.
The example given is for a 365day calendar and daily data. Adjust
accordingly to suit your data. The contents of the *.txt file would resemble something like the following
152 273
517 638
In the *.gs script, change "ttot" (where ttot=no. of loops which is
determined by the number of lines in the txt file). Subsequently, the *.gs
script would do the average of JJAS and write the output of each year to a file.
I'm not able to view the output as in you original script, you wanted it to be written to *.dat file which requires
a corresponding *.ctl file to open (which unfortunately I do not have the
liberty to create). Anyway, the loop works because I've tested it by writing to *png
files. Comment/delete the following lines;
draw title ...
printim ...
And uncomment the commented lines in the mid-section of the script.
Your original script contains lots of errors due to syntax. And you could
optimize it further by. Refer to the script and see where you can
improve...
HTH
--
Muhammad Rahiz
Researcher & DPhil Candidate (Climate Systems & Policy)
School of Geography & the Environment
University of Oxford
On Wed, 5 Jan 2011, Ismaila Diallo wrote:
> Hi,
> muhamed,you are right for your suggestion (how must i do the loop in this
> script)???????So the data time is more than 10 years and i need only a period of
> 10 years it's why i set the tmax at 3920. 1) in each year i need only the june
> july august september data (JJAS).2) the data covert a big domain and i need
> data for a region (in the big domain).3) with this average i must get one value
> for each year (this value must be the
>
>
> average of JJAS for the year).
>
> Until now i try to change this script but something is wrong again.
>
>
> the script is:
>
> 'reinit'
> 'sdfopen /home/lpaosf/RT.1996-2007_DAY.AVG.NC'
> t=518
> tmax=3926
> 'set fwrite test.dat'
> 'set gxout fwrite'
> while (t<=3926)
> 'set t 't
> 'define jun=ave(rt,t=t+0,t='t+30')'
> 'set t 't+30
> 'define jul=ave(rt,t=t+0,t='t+31')'
> 'set t 't+61
> 'define aug=ave(rt,t=t+0,t='t+31')'
> 'set t 't+92
> 'define sep=ave(rt,t=t+0,t='t=t+30')'
> 'define jjas=(jun+jul+aug+sep)/4'
> 'define aa=ave(jjas,lon='-8.5',lon='8.5')'
> 'define bb=ave(aa,lat='10',lat='16')'
> 'd bb'
> t=t+365
> endwhile
> 'disable fwrite'
>
> so again i think in your great help to resolve this problem.
>
> Sincerely
> ismaila
>
>
>
>
-------------- next part --------------
'reinit'
'sdfopen xx.obs.aNcep.tas.day.nc'
'q file'
vx = sublin(result,7)
vr = subwrd(vx,1)
* Reads time steps *
* Remarks: ttot = number of loops (determined by the number of lines in *.txt)
ttot = 3
tx = 1
while(tx<=ttot)
fname ='timesteps.txt'
rec = read(fname)
IO = sublin(rec,1)
if(IO = 1)
say fname' > File open error'
'quit'
endif
if(IO = 0)
t1 = subwrd(rec,2)
t2 = subwrd(rec,3)
endif
*'set gxout fwrite'
*out=''t1'-'t2'.dat'
*'set fwrite 'out''
say ' Timestep: t='t1' to t='t2''
new='ave('vr',t='t1',t='t2')'
'd 'new''
*'disable fwrite'
'draw title 't1'-'t2''
'printim 't1'.'t2'.png white'
tx=tx+1
'clear'
endwhile
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: timesteps.txt
Url: http://gradsusr.org/pipermail/gradsusr/attachments/20110105/d0cd9dd1/attachment-0003.txt
More information about the gradsusr
mailing list