Re: optional argument for function / procedure

From: Brücher Tim <tim.bruecher_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 04 2013 - 05:49:19 MST

Oli, thanks for your fast reply...

but I would favour a definition of a subroutine or function which could deal with:

mytest(var1)

or:

mytest(var1,MyOption1=xxx,MyOption2=zzz)

or:

mytest(var1,MyOption2=zzz)

etc.

This would imply, that updates / extensions to already used subroutines in my private ncl-lib would be downward compatible and work in older scripts.

Cheers,
Tim

On Mar 4, 2013, at 1:39 PM, "Oliver Fuhrer (MeteoSwiss)" <oliver.fuhrer@ginko.ch> wrote:

> Hi Tim,
>
> You can achieve this easily using resources...
>
> undef("mytest")
> procedure mytest( var, res )
> local var, res
> begin
>
> if (res) then
> r = res
> else
> r = True
> end if
>
> if (isatt(r,"option1")) then
> ;; use r@option1 here
> end if
>
> ;; rest of code
>
> end
>
> You can then call this procedure similar to the gsn_XXX functions, for
> example...
>
> mytest(var, False)
>
> r = True
> r@option1 = "this is option 1"
> mytest(var, r)
>
> ...and add as many options as you like.
>
>
> Cheers,
> Oli
>
> On 04.03.2013 13:34, Brücher Tim wrote:
>> Dear all,
>>
>> is there a way to pass one (or several) optional argument(s) to a
>> function or procedure like in e.g. f90?
>>
>> If I look at "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> there are functions waiting for an option, but the opts-argument has
>> to be given all the time the function / subroutine is called, so it
>> is
>> not really optional.
>>
>>
>> Thanks for your help,
>>
>> Tim
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> _________
>
> Oliver Fuhrer
> Numerical Models
>
> Federal Departement of Home Affairs FDHA
> Federal Office of Meteorology and Climatology MeteoSwiss
>
> Kraehbuehlstrasse 58, P.O. Box 514, CH-8044 Zurich, Switzerland
>
> Tel. +41 44 256 93 59
> Fax +41 44 256 92 78
> oliver.fuhrer@ginko.ch
> www.meteoswiss.ch - First-hand information
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 4 05:49:31 2013

This archive was generated by hypermail 2.1.8 : Thu Mar 07 2013 - 08:55:58 MST