[gradsusr] How to convert a string to a real number?

Jeffrey Duda jdduda at iastate.edu
Tue Jan 4 14:34:05 EST 2011


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:

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.

Rv = 461.5
Rd = 287.05
Cp = 1005
lv = 2.5e6

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.

  'tempK = tc + 273'
  'es = 6.11*exp((2.5e6/461.5)*((1/273) - (1/tempK)))'
  'e = qvapor*((p+pb)/100) / (qvapor + 0.622)'
  'equivt = tempK + 'Lv'*qvapor/'Cp'
  'thetae = equivt*pow(1000/slp,'Rd'/'Cp')'


I hope this helps, but ask more questions if it doesn't.

Jeff Duda

On Tue, Jan 4, 2011 at 1:24 PM, Murphy, Darren W <dwmurphy at nps.edu> wrote:

>  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.
>
> Thanks,
> Darren
>
>
> On 1/4/11 6:45 AM, "qinglan" <qinglan at hku.hk> wrote:
>
> Dear All,
>
> 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?
>
> Really appreciate your help!
> Best regards,
> Qinglan Li
>
>
> ------------------------------
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Jeff Duda
Iowa State University
Meteorology Graduate Student
3134 Agronomy Hall
www.meteor.iastate.edu/~jdduda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20110104/1eda9a4e/attachment-0003.html 


More information about the gradsusr mailing list