12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

26 <strong>GNU</strong> <strong>Octave</strong>then runs the interpreter with the given argument and the full argument list of the executedprogram. The first argument in the list is the full file name of the <strong>Octave</strong> program. Therest of the argument list will either be options to <strong>Octave</strong>, or data files, or both. The ‘-qf’option is usually specified in stand-alone <strong>Octave</strong> programs to prevent them from printingthe normal startup message, and to keep them from behaving differently depending onthe contents of a particular user’s ‘~/.octaverc’ file. See Section 2.1 [Invoking <strong>Octave</strong>],<strong>page</strong> 13. Note that some operating systems may place a limit on the number of charactersthat are recognized after ‘#!’.Self-contained <strong>Octave</strong> scripts are useful when you want to write a program which userscan invoke without knowing that the program is written in the <strong>Octave</strong> language.If you invoke an executable <strong>Octave</strong> script with command line arguments, the argumentsare available in the built-in variable argv. See Section 2.1.1 [Command Line Options],<strong>page</strong> 13. For example, the following program will reproduce the command line that is usedto execute it.#! /bin/octave -qfprintf ("%s", program_name);for i = 1:narginprintf (" %s", argv{i});endforprintf ("\n");2.7 Comments in <strong>Octave</strong> ProgramsA comment is some text that is included in a program for the sake of human readers, andthat is not really part of the program. Comments can explain what the program does, andhow it works. Nearly all programming languages have provisions for comments, becauseprograms are typically hard to understand without them.In the <strong>Octave</strong> language, a comment starts with either the sharp sign character, ‘#’, orthe percent symbol ‘%’ and continues to the end of the line. The <strong>Octave</strong> interpreter ignoresthe rest of a line following a sharp sign or percent symbol. For example, we could have putthe following into the function f:function xdot = f (x, t)# usage: f (x, t)## This function defines the right hand# side functions for a set of nonlinear# differential equations.r = 0.25;...endfunctionThe help command (see Section 2.3 [Getting Help], <strong>page</strong> 16) is able to find the firstblock of comments in a function (even those that are composed directly on the commandline). This means that users of <strong>Octave</strong> can use the same commands to get help for built-infunctions, and for functions that you have defined. For example, after defining the functionf above, the command help f produces the output

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!