Passing arguments to Grads script
Ben-Jei Tsuang
btsuang at YAHOO.COM
Tue Feb 1 01:09:16 EST 2005
Dear Dan:
If you have more than one arguments, these arguments should be seperated by
space. For example, for a command:
gradsdods -l -b -c "run temps.gs 15:00 PM 30 Jan 2005 "
In the script, you should have:
------------------------------------
function main(args)
'reinit'
say "temps.gs " args
* Get arguments
if (args='?')
say 'temps.gs requires 5 argument: hh apm day month year'
say 'hh = hour'
say 'apm = AM or PM'
say 'day = day'
say 'month = month'
say 'year = year'
return
else
hh=subwrd(args,1);if(hh='');hh="";endif
apm=subwrd(args,2);if(hh='');apm="";endif
day=subwrd(args,3);if(hh='');day="";endif
month=subwrd(args,4);if(hh='');month="";endif
year=subwrd(args,5);if(hh='');year="";endif
endif
'draw title Current Temperatures as of 'hh' 'apm' 'day' 'month' 'year
--------------------
Then, it should work.
Ben
----- Original Message -----
From: "Daniel Leins" <Daniel.Leins at NOAA.GOV>
To: <GRADSUSR at LIST.CINECA.IT>
Sent: Tuesday, February 01, 2005 1:34 PM
Subject: Re: Passing arguments to Grads script
> Ok, this works fine. Now, what if I get greedy and want to pass an "AM"
> or "PM" timestamp to the title as well, i.e. I've passed a "3", now I
> want to pass "PM"
> so the title reads "Current Temperatures as of 3 PM. Or, what if I want
> to pass the month/day/year and add that into the title as well. I've
> been successful in getting this data into the script and getting it to
> display in the title, however, how do I add spaces between these
> arguments? Right now, it's coming out like this:
>
> Current Temps as of 10:00PM020105
>
> What if I wanted a space between the PM and the 02? What's the best way
> to accomplish this?
>
> Thanks,
> Dan
>
> Ben-Jei Tsuang wrote:
>
>> Dear Dan:
>>
>> You can put the following script in the top of the script
>> ------------------------------------
>> function main(args)
>> 'reinit'
>> say "temps.gs " args
>> * Get arguments
>> if (args='?')
>> say 'temps.gs requires 1 argument: hh'
>> say 'hh = local time'
>> return
>> else
>> hh=subwrd(args,1);if(hh='');hh="";endif
>> endif
>>
>>
>> 'draw title Current Temperatures as of 'hh
>>
>> --------------------------------------------
>> Ben
>>
>> Ben-Jei Tsuang, Prof
>> Nat'l Chung-Hsing Univ.
>> Dept. of Environmental Engineering
>> email: tsuang at nchu.edu.tw
>>
>>
>>
>> ----- Original Message -----
>> From: "Daniel Leins" <daniel.leins at NOAA.GOV>
>> To: <GRADSUSR at LIST.CINECA.IT>
>> Sent: Tuesday, February 01, 2005 9:37 AM
>> Subject: Passing arguments to Grads script
>>
>>
>>> All,
>>> I have written a script to plot temperatures across a given area.
>>> When it
>>> comes to titling the images, I would like to pass the current time to
>>> the
>>> script, then have this argument displayed through 'draw title'. For
>>> example,
>>>
>>> If it is 15:00, I would like to pass the time to my script, and do
>>> something
>>> like
>>>
>>> draw title Current Temperatures as of @ARGV[0]
>>>
>>> where @ARGV[0] comes from gradsdods -l -b -c "run temps.gs 15:00"
>>>
>>> (i am aware that @ARGV[0] is not correct, I am simply using this
>>> syntax as
>>> an example).
>>>
>>> OR
>>>
>>> If I wanted to pass the title itself to the script instead of the time,
>>> for
>>> example:
>>>
>>> draw title @ARGV[0]
>>>
>>> where @ARGV[0] comes from gradsdods -l -b -c "run temps.gs Dewpoints"
>>>
>>> I've looked through several scripts online which involve passed
>>> arguments,
>>> however I haven't been able to find anything that pertains to this. I
>>> don't
>>> need to perform any sort of calculations on the passed argument, I
>>> simply
>>> need to pass it into the script, and have it passed back out in the
>>> title
>>> section. What is the best way to accomplish this?
>>>
>>> Thanks,
>>>
>>> Dan Leins
>>> DOC/NOAA/NWS/EAX
>>
More information about the gradsusr
mailing list