Parameters to executable Octave programs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Parameters to executable Octave programs

Matthias Roessler


Octave-Version: 1.1.1


After reading the FAQ, the manual and the mailing-list archives I
haven't found a solution to this problem:


As described in section "1.3 Executable Octave Programs" I made my
octave programs executable. How do I pass parameters from the command
line to my program? I would like to do something like this:



#!/local/octave/bin/octave -qf

temperature = $1;
pressure    = $2;
epsilon     = $3;

result = Start_my_calculation_with(temperature, pressure, epsilon);

save resultfile result;



My current solution is to write a sh-wrapper. Any other ideas?

Matthias

- ------------------------------------------------------------------------------
Dipl.-Inf. Matthias Roessler                            Phone: 49 9131 85 8027
IMMD IV,  Universitaet Erlangen-Nuernberg               Fax1:  49 9131 85 8732
Martensstrasse 1; D-91058 Erlangen                      Fax2:  49 9131 39 388
                                     [hidden email]
                             http://www4.informatik.uni-erlangen.de/~roessler/
- ------------------------------------------------------------------------------
"Es geht auch anders, aber so geht es auch!"                                  
"You can do this differently, but you can also do it like this!" (Lotti Huber)


Reply | Threaded
Open this post in threaded view
|

Parameters to executable Octave programs

John W. Eaton-6
Matthias Roessler <[hidden email]> wrote:

: As described in section "1.3 Executable Octave Programs" I made my
: octave programs executable. How do I pass parameters from the command
: line to my program? I would like to do something like this:
:
: #!/local/octave/bin/octave -qf
:
: temperature = $1;
: pressure    = $2;
: epsilon     = $3;
:
: result = Start_my_calculation_with(temperature, pressure, epsilon);

It isn't possible to do this directly with released versions of
Octave, but it works in my current sources and will be in the next
release:

  $ cat print-args
  #! /usr/local/octave-ss/bin/octave -qf

  printf ("%s\n%s\n", program_invocation_name, program_name);

  for i = 1:nargin
    printf ("arg #%d: %s\n", i, argv(i,:));
  end

  $ ./print-args foo bar baz
  ./print-args
  print-args
  arg #1: foo
  arg #2: bar
  arg #3: baz


Thanks,

jwe