Qinglan,<br>Are you sure you're using the subwrd function correctly? I don't think you are. If you want to get the value of SWDOWN.1 and SWDOWN.2, do something like<br><br>(set environment commands)<br>'d SWDOWN.1'<br>
SW1 = subwrd(result,1) !make sure this is the correct one...depending on how your control file is setup, you might get "Notice: interpolation will be made", then the value, in which case you'll need to do a sublin command first, then the subwrd command<br>
<br>I'm pretty sure that's the source of your error. Here's an example from another script I use (<a href="http://vgeo.gs">vgeo.gs</a>):<br><br>'q dims'<br>xline=sublin(result,2)<br>xdim1=subwrd(xline,11)<br>
xdim2=subwrd(xline,13)<br>yline=sublin(result,3)<br>ydim1=subwrd(yline,11)<br>ydim2=subwrd(yline,13)<br>...<br>...<br>...<br>x3 = xdim1 + xdim2<br>say xdim1 "+" xdim2 "=" x3<br>...<br>...<br><br><b>The output is:</b><br>
ga-> run <a href="http://vgeo.gs">vgeo.gs</a> <br>1+301=302<br><br>Try making those changes and see if it works then.<br><br>Jeff<br><br>P.S. Alternately, you can try using the maskout function to define a new variable for SWDOWN which is undefined where your LU_index variable is 1. Such a command could be like:<br>
'define SWDOWNmask = maskout(SWDOWN.1,LU_index - 1.5)'<br>This would make sure not to mask out SWDOWN.1 when LU_index was 2 or greater (I'm assuming the values of LU_index are positive integers only).<br><br><br>
<div class="gmail_quote">On Tue, Jan 4, 2011 at 9:19 PM, qinglan <span dir="ltr"><<a href="mailto:qinglan@hku.hk">qinglan@hku.hk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<div style="font-family: Tahoma; direction: ltr; color: rgb(0, 0, 0); font-size: 13px;">
<div>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Dear all,</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Thanks for the response, but the reply has not solved my problem. Let me make my question more specific. I would like to calculate the average of the SWDOWN
(short wave radiation) over certain land type, here referring to rural land type (LU_index =not 1).</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">The following is my original code.<span>
</span>First of all, I want summate all the values of SWDOWN for all the grids with LU_index!=1 and LU_index!=1, then divided by the total number of nrr.<span>
</span>tim, m and n might be larger, here for simplifying purpose, setting them for only one loop each.</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">The problem is the outputs of SWDOWN.1 or SWDOWN.2 are not a single value, the program treat SWDOWN.1 as a vector, even the t, x, y (tim, m, n) are fixed to
one value. </font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri">Firstly, there is an error for this sentence<span>
</span></font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SWDOWN_nrr1=SWDOWN_nrr1+SWDOWN.1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Or I try to output SWDOWN.1 to a single value
</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW1=subwrd(SWDOWN.1,1)</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>the program treats SW1 as a string, not a value, so<span>
</span></font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SW5=SW1+SW2<span>
</span>makes mistakes, as well as<span> </span>SWDOWN_nrr1=SWDOWN_nrr1+'SW1'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Possible solutions for my problems are:<span>
</span>convert the output of SWDOWN.1 to a single value, which I can use for summation.<span>
</span>SWDOWN_nrr1=SWDOWN_nrr1+SWDOWN.1; </font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">or convert a string to a value, which I can also use it for summation.<span>
</span>SWDOWN_nrr1=SWDOWN_nrr1+'SW1'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal">
<font face="Calibri" size="3"> </font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Thank you very much!</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">Qinglan Li</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3"> </font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3"> </font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'reinit'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">'open Small_Nest3_Moisture_2000July23-27_00_UTC_2000_land_AH100.ctl'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">'open Small_Nest3_Moisture_2000July23-27_00_UTC_1980_land_AH100_changed_0.7profile.ctl'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">tim=25</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">while(tim<=25)</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_rr1=0</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_rr2=0</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>'set t 'tim''</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">nrr=0</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_nrr1=0</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_nrr2=0</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">m=1</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">while(m<=1)</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">n=1</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">while(n<=1)</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>'set x 'm''</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>'set y 'n''</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>LU1=LU_index.1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>LU2=LU_index.2</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW1=subwrd(SWDOWN.1,1)</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW2=subwrd(SWDOWN.2,1)</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW5=SW1+SW2<span>
</span>********error</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW3=1.1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SW4=2.2 </font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>if (LU1!=1 & LU2!=1)</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>nrr=nrr+1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SWDOWN_nrr1=SWDOWN_nrr1+'SW1'<span> </span>
******error</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>SWDOWN_nrr2=SWDOWN_nrr2+'SW2'<span> </span>
******error</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>endif</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>n=n+1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">endwhile</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>m=m+1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">endwhile</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_rr1=SWDOWN_nrr1/nrr</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">SWDOWN_rr2=SWDOWN_nrr2/nrr</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">*'d SWDOWN_rr1'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">*'d SWDOWN_rr2'</font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'d 'SWDOWN_nrr1''</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'d 'SWDOWN_nrr2''
</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'fprintf 'LU1' LU1.txt'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'d 'LU2''</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'fprintf 'SW1' SW1.txt'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'fprintf 'SW5' SW5.txt'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'fprintf 'nrr' nrr.txt'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span> </span>'fprintf 'SWDOWN_nrr2' SWDOWN_nrr2.txt'</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font size="3"><font face="Calibri"><span>
</span>tim=tim+1</font></font></p>
<p style="line-height: normal; margin: 0in 0in 10pt;" class="MsoNormal"><font face="Calibri" size="3">endwhile</font></p>
</div>
<div dir="ltr"><font color="#000000" face="Tahoma" size="2"></font> </div>
<div style="direction: ltr;">
<hr>
<font color="#000000" face="Tahoma" size="2"><b>From:</b> <a href="mailto:gradsusr-bounces@gradsusr.org" target="_blank">gradsusr-bounces@gradsusr.org</a> [<a href="mailto:gradsusr-bounces@gradsusr.org" target="_blank">gradsusr-bounces@gradsusr.org</a>] On Behalf Of Jeffrey Duda [<a href="mailto:jdduda@iastate.edu" target="_blank">jdduda@iastate.edu</a>]<br>
<b>Sent:</b> Wednesday, January 05, 2011 3:34 AM<br>
<b>To:</b> GrADS Users Forum<br>
<b>Subject:</b> Re: [gradsusr] How to convert a string to a real number?<br>
</font><br>
</div><div><div></div><div class="h5">
<div></div>
<div>As far as I'm aware, you shouldn't have to explicitly convert in grads scripting. Just use your quotes correctly. Here's an example from a script I wrote to compute theta-e:<br>
<br>
These constants are set as variables within the grads script only (i.e., they don't exist in the command window...I can't display Rv or Rd etc.). Thus they're regarded as constants or strings.<br>
<br>
Rv = 461.5<br>
Rd = 287.05<br>
Cp = 1005<br>
lv = 2.5e6<br>
<br>
In the actual theta-e computation below, notice how the variables are used between single quotes so as not to be a part of a command that would otherwise be issued in the command window. This is all you should have to do to use a string as a number or vice
versa.<br>
<br>
'tempK = tc + 273'<br>
'es = 6.11*exp((2.5e6/461.5)*((1/273) - (1/tempK)))'<br>
'e = qvapor*((p+pb)/100) / (qvapor + 0.622)'<br>
'equivt = tempK + 'Lv'*qvapor/'Cp'<br>
'thetae = equivt*pow(1000/slp,'Rd'/'Cp')'<br>
<br>
<br>
I hope this helps, but ask more questions if it doesn't.<br>
<br>
Jeff Duda<br>
<br>
<div class="gmail_quote">On Tue, Jan 4, 2011 at 1:24 PM, Murphy, Darren W <span dir="ltr">
<<a href="mailto:dwmurphy@nps.edu" target="_blank">dwmurphy@nps.edu</a>></span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<div><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;">I’d like to second this question. I am having the same issue. I think the Grads literature says that some commands can use a number as a string for calculations. However,
when I try and use my number “string” in a max or min Grads function, it throws an error.<br>
<br>
Thanks,<br>
Darren<br>
<br>
<br>
On 1/4/11 6:45 AM, "qinglan" <<a href="http://qinglan@hku.hk" target="_blank">qinglan@hku.hk</a>> wrote:<br>
<br>
</span></font>
<blockquote><font size="2"><font face="Tahoma, Verdana, Helvetica, Arial"><span style="font-size: 10pt;">Dear All,<br>
<br>
</span></font></font><font size="4"><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 14pt;">Is there anybody know how to convert a string to a real number in Grads? For example, if my string is ‘300.5’, I want to get the value of 300.5,
which is a real number, how to do that?<br>
<br>
Really appreciate your help!<br>
Best regards,<br>
Qinglan Li<br>
</span></font></font><font size="2"><font face="Tahoma, Verdana, Helvetica, Arial"><span style="font-size: 10pt;"><br>
</span></font></font><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"><br>
<hr width="95%" align="center" size="3">
</span></font><font size="2"><font face="Consolas, Courier New, Courier"><span style="font-size: 10pt;">_______________________________________________<br>
gradsusr mailing list<br>
<a href="http://gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
</span></font></font></blockquote>
</div>
<br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org" target="_blank">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>
Jeff Duda<br>
Iowa State University<br>
Meteorology Graduate Student<br>
3134 Agronomy Hall<br>
<a href="http://www.meteor.iastate.edu/%7Ejdduda" target="_blank">www.meteor.iastate.edu/~jdduda</a><br>
</div>
</div></div></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>Jeff Duda<br>Iowa State University<br>Meteorology Graduate Student<br>3134 Agronomy Hall<br><a href="http://www.meteor.iastate.edu/~jdduda">www.meteor.iastate.edu/~jdduda</a><br>