[gradsusr] Pass Data via the 'Return' Expression
Brian Doty
doty at cola.iges.org
Thu Apr 22 22:23:01 EDT 2010
Here's a function I use to format the grads date and time for various
plot annotation (titles, etc):
* Function to reformat the GrADS date/time into something
* more readable
function mydate
'query time'
sres = subwrd(result,3)
wd = subwrd(result,6)
i = 1
while (substr(sres,i,1)!='Z')
i = i + 1
endwhile
hour = substr(sres,1,i)
isav = i
i = i + 1
while (substr(sres,i,1)>='0' & substr(sres,i,1)<='9')
i = i + 1
endwhile
day = substr(sres,isav+1,i-isav-1)
month = substr(sres,i,3)
year = substr(sres,i+3,4)
return (hour' 'wd', 'month' 'day', 'year)
As you can see, it returns some stuff there at the end.
When you invoke this function from elsewhere, there are a couple of
ways to use the returned string. One way is to assign it to a variable:
dtlabel = mydate()
Another way is to just use it inline, for example:
'draw string 0.1 0.2 12Hr Forecast Valid 'mydate()
There is also a way to share variables between script functions by
using a "global" variable, which is any variable name that starts with
an underscore. Those variables are shared by all the functions in the
script file. I tend to avoid using them (because it can be hard later
to figure out where they are getting set vs where they are getting
used) -- but they do come in handy at times... Brian
On Apr 20, 2010, at 5:21 PM, Charles Seman wrote:
> Mark,
>
> Don't know if you have resolved this yet, but Bob Hart's "plotskew.gs"
> script has examples of what it appears that you want to do:
> http://www.iges.org/grads/gadoc/library
> ftp://grads.iges.org/grads/scripts/plotskew.gs
>
> Hope this helps,
> Chuck
>
> Mark Sponsler wrote:
>>
>> I have a script that calls a second script (and passes some arguments
>> to it). That works fine. I'm trying to get the second script to
>> return
>> some data back to the first script, but am having difficulty. I use
>> the 'return' command to have the second script return control back
>> the
>> first script, but cannot seem to get any variable data to pass with
>> it. It seems this is possible per the Grads documentation:
>>
>>
>>
>>
>>
>> To return from a function, use the |return| command:
>>
>> |return /expression/|
>>
>> The |/expression/| is optional; if not provided, a NULL string
>> will be returned. (A null string is: '') The result of the
>> function is the result of the expression specified on the return
>> command.
>>
>>
>>
>> In the second script, the last line is:
>>
>>
>>
>> return val1
>>
>>
>>
>> Where val1 is a variable string
>>
>>
>>
>> Just can't seem to get the first script to read the contents of
>> val1. Could always write the data to a file, but am looking for
>> something a little more elegant.
>>
>>
>>
>>
>> Any help would be appreciated,
>> Mark
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>
> --
>
> Please note that Charles.Seman at noaa.gov should be considered my NOAA
> email address, not cjs at gfdl.noaa.gov.
>
> ********************************************************************
> Charles Seman Charles.Seman at noaa.gov
> U.S. Department of Commerce / NOAA / OAR
> Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547
> 201 Forrestal Road fax: (609) 987-5063
> Princeton, NJ 08540-6649 http://www.gfdl.noaa.gov/~cjs/
> ********************************************************************
>
> "The contents of this message are mine personally and do not reflect
> any
> official or unofficial position of the United States Federal
> Government,
> the United States Department of Commerce, or NOAA."
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20100422/01048bfd/attachment-0003.html
More information about the gradsusr
mailing list