help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getopt


From: Martin Helm
Subject: Re: getopt
Date: Sat, 10 Oct 2009 17:20:04 +0200
User-agent: KMail/1.10.3 (Linux/2.6.27.29-0.1-default; KDE/4.1.3; x86_64; ; )

Am Samstag, 10. Oktober 2009 23:16:25 schrieb Juergen Rose:
> Am Samstag, den 10.10.2009, 10:48 +0000 schrieb address@hidden:
> > did you see   varargin?
> >
> > Doug
> >
> > > Subject: getopt
> > > From: address@hidden
> > > To: address@hidden
> > > Date: Sat, 10 Oct 2009 19:55:35 +0200
> > >
> > > Hi,
> > >
> > > I am looking for a possibility to evaluate the arguments passed to a
> > > octave script similar to getopt[s] in bash or Getopt::Std in perl.
> > >
> > > Any hints are appreciated.
>
> Hi Doug,
>
> I don't understand, what 'varargin' has to do with 'getopt'.
>
> octave:1> help varargin
>
>  -- Keyword: varargin
>      Pass an arbitrary number of arguments into a function.
>
>      See also: varargout, nargin, nargout
>
> I need a function, which I can use to parse arg_list = argv() and which
> can distinguish between allowed and not allowed options, and between
> options with and without additional parameter.
> I.e., I look for something like in Perl:
>
> use Getopt::Std;
> my $opts="dhS:o:N:n:";
> my $options={};
> getopts($opts,$options);
> if (defined $options->{d}) {$DBG_LVL=$options->{d};}
> if (defined $options->{h}) {usage();   exit 0;}
> if (defined $options->{S}) {$Seed=$options->{S};}
> ..
>
> Regards Juergen
>
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

If you want to get the command line options for the script you should take a 
look at the argv function

here is a simple octave script from the octave manual which shows its usage, 
since it is short I reproduce it here (look at 
http://www.gnu.org/software/octave/doc/interpreter/Executable-Octave-
Programs.html#Executable-Octave-Programs)

#! /usr/bin/octave -qf
     printf ("%s", program_name ());
     arg_list = argv ();
     for i = 1:nargin
       printf (" %s", arg_list{i});
     endfor
     printf ("\n");

Hope that helps, checking of the command line parameters for type correctness 
and so on has to be done by yourself.

- mh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]