<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="GENERATOR" content="MSHTML 8.00.7600.16700">
<style id="owaTempEditStyle"></style><style title="owaParaStyle"><!--P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
--></style>
</head>
<body ocsi="x">
<div style="FONT-FAMILY: Tahoma; DIRECTION: ltr; COLOR: #000000; FONT-SIZE: 13px">
<div>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">Dear Jeff and other Grads users,</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">First of all, really appreciate your help and time.</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">In order to make my question more clearly and simple, I have reduced the data size and simplified the code. I attach the .dat file, .ctl file and .gs file, as well as fprintf.gs
file. There is no problem running the attached try_loop_p2.gs. The output SW1.txt is 359.505, which should be a string, not a value. My problem is how to transfer SW1 to a number.</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">Still in try_loop_p2.gs, if remove the first * marks in lines 9 and 12 (or lines 10 and 13), error occurs. The error information is “Syntax Error” or “Non-numeric args to numeric
operation ”.</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">My problem is how to make SW2=SW1+1/ or SW3=SWDOWN+1 work.</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">Thank you very much!</font></p>
<p style="MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3"><font face="Calibri">Qinglan Li
<span style="mso-spacerun: yes"> </span></font></font></p>
</div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma"></font> </div>
<div style="DIRECTION: ltr" id="divRpF668394">
<hr tabindex="-1">
<font color="#000000" size="2" face="Tahoma"><b>From:</b> gradsusr-bounces@gradsusr.org [gradsusr-bounces@gradsusr.org] On Behalf Of Jeffrey Duda [jdduda@iastate.edu]<br>
<b>Sent:</b> Wednesday, January 05, 2011 1:46 PM<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>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" target="_blank">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" target="_blank">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 style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<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 size="3" face="Calibri">Dear all,</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri"></font> </p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">Thank you very much!</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">Qinglan Li</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri"></font> </p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri"></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 size="3" face="Calibri">'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 size="3" face="Calibri">'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 size="3" face="Calibri">tim=25</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">while(tim<=25)</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">SWDOWN_rr1=0</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">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 size="3" face="Calibri">nrr=0</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">SWDOWN_nrr1=0</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">SWDOWN_nrr2=0</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">m=1</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">while(m<=1)</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">n=1</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">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 size="3" face="Calibri">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 size="3" face="Calibri">endwhile</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">SWDOWN_rr1=SWDOWN_nrr1/nrr</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">SWDOWN_rr2=SWDOWN_nrr2/nrr</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">*'d SWDOWN_rr1'</font></p>
<p style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class="MsoNormal"><font size="3" face="Calibri">*'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 size="3" face="Calibri">endwhile</font></p>
</div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma"></font> </div>
<div style="DIRECTION: ltr">
<hr>
<font color="#000000" size="2" face="Tahoma"><b>From:</b> <a href="mailto:gradsusr-bounces@gradsusr.org">
gradsusr-bounces@gradsusr.org</a> [<a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a>] On Behalf Of Jeffrey Duda [<a href="mailto:jdduda@iastate.edu">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">dwmurphy@nps.edu</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; 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 align="center" size="3" width="95%">
</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">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" target="_blank">www.meteor.iastate.edu/~jdduda</a><br>
</div>
</div>
</body>
</html>