Thanks Eric. It worked out perfectly. One remaining problem is : I don't want to write rain.2 in the file that I am creating. Because of 'd 24*rain.2' it is also written in the output file. Is there any way to suppress rain.2, and write only the intended variable (iwc)?<br>
thanks again. <br><br><div class="gmail_quote">On Thu, Mar 12, 2009 at 3:48 PM, Eric Altshuler <span dir="ltr"><<a href="mailto:ela@cola.iges.org">ela@cola.iges.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
John,<br>
<br>
One problem I immediately see is that in your if statement:<br>
<div class="im"><br>
'define aa=rain.2*24'<br>
if (rainlow <= aa & aa < rainhigh)<br>
<br>
</div>you are trying to compare the script variables rainlow and rainhigh with 'aa', which is a GrADS defined data variable, not a script variable. This will not work. You need to assign a particular single value to the script variable aa. An example might be the following, with the dimension environment set to all dimensions fixed:<br>
<br>
...<br>
...<br>
'set t 't1<br>
...<br>
'set z 'z1<br>
...<br>
'set x 'x1<br>
'set y 'y1<br>
'd 24*rain.2'<br>
aa=subwrd(result,4)<br>
<div class="im">if (rainlow <= aa & aa < rainhigh)<br>
</div>...<br>
...<br>
<br>
where x1, y1, z1 and t1 are the values (assigned to these script variables) you want for the fixed dimensions. You already have a looping structure set up for Z, and I assume you also have one for T, but you will also need to loop over the values of X and Y so that the script variable aa is assigned a single value in each iteration of the loop.<br>
<br>
Best regards,<br>
<br>
Eric L. Altshuler<br>
Assistant Research Scientist<br>
Center for Ocean-Land-Atmosphere Studies<br>
<div class="im">4041 Powder Mill Road, Suite 302<br>
</div>Calverton, MD 20705-3106<br>
USA<br>
<br>
E-mail: <a href="mailto:ela@cola.iges.org">ela@cola.iges.org</a><br>
Phone: (301) 902-1257<br>
Fax: (301) 595-9793<br>
<div class="im"><br>
----- Original Message -----<br>
From: "John Guhin" <<a href="mailto:johnguhin@GMAIL.COM">johnguhin@GMAIL.COM</a>><br>
To: <a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a><br>
</div><div><div></div><div class="h5">Sent: Thursday, March 12, 2009 12:31:00 PM GMT -05:00 US/Canada Eastern<br>
Subject: Re: if statement in grads<br>
<br>
Thanks Stephen. You are correct for more than one time step. But can we read<br>
a 2D variable at all inside the if statement? Consider the following:<br>
<br>
'open /raid/pray/processed_data/IWC/iwc.ctl'<br>
'open /raid/pray/processed_data/AMSRE/rain-amsre_15jun06-31aug08.ctl'<br>
rainlow=0 ; rainhigh=5;<br>
lon1=0 ; lon2=360<br>
lat1=-30 ; lat2=30<br>
undef=-1e+34<br>
z1=1<br>
while(z1<19)<br>
'set z 'z1<br>
'define aa=rain.2*24'<br>
if (rainlow <= aa & aa < rainhigh)<br>
'd aave(iwc,lon='lon1',lon='lon2',lat='lat1',lat='lat2')'<br>
else<br>
'd aave(iwc*0+'undef',lon='lon1',lon='lon2',lat='lat1',lat='lat2')'<br>
endif<br>
z1=z1+1<br>
endwhile<br>
<br>
iwc is 3D. rain.2 is actually a 2D variable, so aa is also 2D. I think<br>
thats where the problem is. Anybody has faced similar problem?<br>
thanks.<br>
<br>
<br>
<br>
On Thu, Mar 12, 2009 at 11:39 AM, Stephen R McMillan <<br>
<a href="mailto:smcmillan@planalytics.com">smcmillan@planalytics.com</a>> wrote:<br>
<br>
><br>
> John,<br>
> The if statement you quoted--the one that Jennifer suggested--is valid, as<br>
> is the nested method that Pablo suggested. However, your unexpected results<br>
> appear to indicate the "if..else" conditions (in particular are not changing<br>
> during the second time loop iteration. Since your variable 'aa' would be<br>
> the same at each timestep, then I suppose 'iwc' may be the culprit. Have you<br>
> tried echo-displaying the conditional results at each timestep to confirm<br>
> their values?<br>
> Stephen Mc<br>
><br>
><br>
> *John Guhin <<a href="mailto:johnguhin@GMAIL.COM">johnguhin@GMAIL.COM</a>>*<br>
> Sent by: <a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a><br>
><br>
> 03/11/2009 08:03 PM<br>
> Please respond to<br>
> <a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a><br>
><br>
> To<br>
> GRADSUSR@LIST.CINECA.ITcc<br>
> Subject<br>
> Re: if statement in grads<br>
><br>
><br>
><br>
><br>
> Thanks Stephen.<br>
> I simplified the script by considering only one time (t). The problem is<br>
> indeed if statement.<br>
> It seems if statement like this if (rainlow <=aa & aa<rainhigh)<br>
> does not work in grads. Is it true? or there is another way to solve my<br>
> problem?<br>
><br>
> thanks in advance.<br>
><br>
><br>
> On Wed, Mar 11, 2009 at 5:07 PM, Stephen R McMillan <*<br>
</div></div>> <a href="mailto:smcmillan@planalytics.com">smcmillan@planalytics.com</a>* <<a href="mailto:smcmillan@planalytics.com">smcmillan@planalytics.com</a>>>wrote:<br>
<div class="im">> John,<br>
> Check the position of your "t1=1" line. As it is, it would appear to<br>
> repeat the 20 days once. Did you intend to put "t1=1" before the outermost<br>
> while loop?<br>
> Stephen Mc<br>
><br>
><br>
</div>> *John Guhin <**<a href="mailto:johnguhin@GMAIL.COM">johnguhin@GMAIL.COM</a>* <<a href="mailto:johnguhin@GMAIL.COM">johnguhin@GMAIL.COM</a>>*>*<br>
> Sent by: *<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>* <<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>><br>
<div class="im">><br>
> 03/11/2009 03:48 PM<br>
> Please respond to<br>
</div>> *<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>* <<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>><br>
><br>
><br>
> To<br>
> *<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>* <<a href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a>>cc<br>
<div class="im">> Subject<br>
> Re: if statement in grads<br>
><br>
><br>
><br>
><br>
><br>
><br>
> Hi,<br>
> I tried with<br>
> if (rainlow <=aa & aa<rainhigh)<br>
><br>
> but didn't work. Am I mising something?<br>
><br>
> thanks in advance.<br>
><br>
><br>
</div>> On Wed, Mar 11, 2009 at 1:28 PM, Jennifer Adams <*<a href="mailto:jma@cola.iges.org">jma@cola.iges.org</a>*<<a href="mailto:jma@cola.iges.org">jma@cola.iges.org</a>><br>
<div><div></div><div class="h5">> >wrote:<br>
> Try changing your if statement to:<br>
> if (rainlow <=aa & aa<rainhigh)<br>
> --Jennifer<br>
><br>
> On Mar 11, 2009, at 1:19 PM, John Guhin wrote:<br>
><br>
><br>
> Hi,<br>
> I am trying to use if statement in a grads script... which doesn't seem<br>
> to work. I am<br>
> attaching the gs file. iwc is a 3D variable, and rain is 2D variable<br>
> exactly in the same grids. I am trying to extract iwc when rain is within<br>
> certain range. The script executes without any error, but the output repeats<br>
> itself every 20 days. This means that the " if" statement is not working!!<br>
> Any help would be appreciated.<br>
><br>
> 'reinit'<br>
> 'c'<br>
> 'open iwc.ctl'<br>
> 'open /rain.ctl'<br>
> 'set gxout fwrite'<br>
> 'set fwrite iwc_ppt_binned.dat'<br>
><br>
> lon1=40 ; lon2=180<br>
> lat1=-20 ; lat2=20<br>
> undef=-1e+34<br>
> rainlow=0 ; rainhigh=5;<br>
><br>
> while(rainhigh<11)<br>
> t1=1<br>
> while(t1<21)<br>
> 'set t 't1<br>
> z1=1<br>
> while(z1<19)<br>
> 'set z 'z1<br>
> 'define aa=24*rain.2(z=1)'<br>
> if (rainlow <= aa < rainhigh)<br>
> 'd aave(iwc,lon='lon1',lon='lon2',lat='lat1',lat='lat2')'<br>
> else<br>
> 'd aave(iwc*0+'undef',lon='lon1',lon='lon2',lat='lat1',lat='lat2')'<br>
> endif<br>
> z1=z1+1<br>
> endwhile<br>
> t1=t1+1<br>
> endwhile<br>
> rainlow=rainlow+5<br>
> rainhigh=rainhigh+5<br>
> endwhile<br>
><br>
> 'close 2'<br>
> 'close 1'<br>
> 'disable fwrite'<br>
><br>
> --<br>
> John Guhin<br>
> --<br>
> Jennifer M. Adams<br>
> IGES/COLA<br>
> 4041 Powder Mill Road, Suite 302<br>
> Calverton, MD 20705<br>
</div></div>> *<a href="mailto:jma@cola.iges.org">jma@cola.iges.org</a>* <<a href="mailto:jma@cola.iges.org">jma@cola.iges.org</a>><br>
<div><div></div><div class="h5">><br>
><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> John Guhin<br>
><br>
><br>
><br>
> ***************************************************<br>
> The information contained in this e-mail message is intended only for the<br>
> use of the recipient(s) named above and may contain information that is<br>
> privileged, confidential, and/or proprietary. If you are not the intended<br>
> recipient, you may not review, copy or distribute this message. If you have<br>
> received this communication in error, please notify the sender immediately<br>
> by e-mail, and delete the original message.<br>
> ***************************************************<br>
><br>
><br>
><br>
> --<br>
> John Guhin<br>
><br>
><br>
><br>
> ***************************************************<br>
> The information contained in this e-mail message is intended only for the<br>
> use of the recipient(s) named above and may contain information that is<br>
> privileged, confidential, and/or proprietary. If you are not the intended<br>
> recipient, you may not review, copy or distribute this message. If you have<br>
> received this communication in error, please notify the sender immediately<br>
> by e-mail, and delete the original message.<br>
> ***************************************************<br>
><br>
<br>
<br>
<br>
--<br>
John Guhin<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>John Guhin<br>