GNU Octave/Начало работы

Материал из Викиучебника — открытых книг для открытого мира

Эта глава посвящена некоторым основным возможностям Octave: как начать сеанс Octave, как вызвать справку из командной строки, как редактировать команды в командной строке и писать Octave-программы, которые могут быть выполнены как команды из командной оболочки.

Запуск Octave из командной оболочки[править]

Обычно Octave используется в интерактивном режиме, в который можно перейти набрав без аргументов `octave'. После запуска, Octave будет читать команды с терминала до тех пор, пока вы не выйдете из программы.

Если вы хотите выполнить команды, содержащиеся в файле «имя_файла», наберите в командной оболочке `octave имя_файла'.

Параметры командной строки описываются в следующем разделе. Octave сама может напоминать о доступных параметрах. Наберите `octave --help' (можно использовать более компактный вариант `octave -h'), чтобы получить список всех доступных параметров и краткое описание для их использования.

Параметры командной строки[править]

Здесь находится полный список всех параметров командной строки, которые может принимать Octave.

Параметры командной строки Описание
--debug, -d Переводит парсер в режим отладки. Использование этого параметра заставит Octave печатать много информации о командах, которые он читает, скорее всего это может оказаться полезным лишь в том случае, если вы пытаетесь отладить парсер.
--echo-commands, -x Выводить все команды на экран.
--eval code Вычислить код и выйти по завершении, если только не определён параметр --persist.
--exec-path path Specify the path to search for programs to run. The value of path specified on the command line will override any value of OCTAVE_EXEC_PATH found in the environment, but not any commands in the system or user startup files that set the built-in variable EXEC_PATH.
--help, -h, -? Вывести короткую справку и выйти.
--image-path path Определить путь для поиска изображений. Значение пути, установленное в командной строке, установит значение переменной окружения IMAGE_PATH.
--info-file filename Specify the name of the info file to use. The value of filename specified on the command line will override any value of OCTAVE_INFO_FILE found in the environment, but not any commands in the system or user startup files that use the info_file function.
--info-program program Specify the name of the info program to use. The value of program specified on the command line will override any value of OCTAVE_INFO_PROGRAM found in the environment, but not any commands in the system or user startup files that use the info_program function.
--interactive, -i Force interactive behavior. This can be useful for running Octave via a remote shell command or inside an Emacs shell buffer. For another way to run Octave within Emacs, see Emacs.
--no-history, -H Отключить историю командной строки.
--no-init-file Не выполнять чтение файлов ~/.octaverc или .octaverc.
--no-line-editing Отключить редактирование в командной строке.
--no-site-file Don't read the site-wide octaverc file.
--norc, -f Don't read any of the system or user initialization files at startup. This is equivalent to using both of the options --no-init-file and --no-site-file.
--path path, -p path Specify the path to search for function files. The value of path specified on the command line will override any value of OCTAVE_PATH found in the environment, but not any commands in the system or user startup files that set the internal load path through one of the path functions.
--persist После --eval или чтения файла, указанного в командной строке, перейти в интерактивный режим.
--silent, --quiet, -q Не печатать стандартное сообщение с приветствием и версией программы при запуске.
--traditional, --braindead For compatibility with Matlab, set initial values for user-preferences to the following values

           PS1                             = ">> "
           PS2                             = ""
           beep_on_error                   = true
           crash_dumps_octave_core         = false
           default_save_options            = "-mat-binary"
           fixed_point_format              = true
           history_timestamp_format_string = "%%-- %D %I:%M %p --%%"
           page_screen_output              = false
           print_empty_dimensions          = false

and disable the following warnings

           Octave:fopen-file-in-path
           Octave:function-name-clash
           Octave:load-file-in-path

--verbose, -V Turn on verbose output.
--version, -v Вывести версию программы и выйти.
file Выполнить команды из файла. Выйти по завершении, если только не определён параметр --persist.

Стартовые файлы[править]

При запуске Octave, производится поиск команд для выполнения из файлов, перечисленных ниже. Эти файлы могут содержать любые команды Octave, включая определения функций.

Файл Описание
octave-home/share/octave/site/m/startup/octaverc Where octave-home is the directory in which all of Octave is installed (the default is /usr/local/octave/cvs). This file is provided so that changes to the default Octave environment can be made globally for all users at your site for all versions of Octave you have installed. Some care should be taken when making changes to this file, since all users of Octave at your site will be affected.
octave-home/share/octave/version/m/startup/octaverc Where octave-home is the directory in which all of Octave is installed (the default is /usr/local/octave/cvs), and version is the version number of Octave. This file is provided so that changes to the default Octave environment can be made globally for all users for a particular version of Octave. Some care should be taken when making changes to this file, since all users of Octave at your site will be affected.
~/.octaverc This file is normally used to make personal changes to the default Octave environment.
.octaverc This file can be used to make changes to the default Octave environment for a particular project. Octave searches for this file in the current directory after it reads ~/.octaverc. Any use of the cd command in the ~/.octaverc file will affect the directory that Octave searches for the file .octaverc.

If you start Octave in your home directory, commands from from the file ~/.octaverc will only be executed once.

A message will be displayed as each of the startup files is read if you invoke Octave with the --verbose option but without the --silent option.

Завершение работы Octave[править]

— Встроенная функция: exit (status)
— Встроенная функция: quit (status)

Exit the current Octave session. If the optional integer value status is supplied, pass that value to the operating system as the Octave's exit status. The default value is zero.

— Встроенная функция: atexit (fcn)

Register a function to be called when Octave exits. For example this code will print the message "Bye bye" when Octave exits.
function bye_bye ()
disp ("Bye bye");
endfunction
atexit ("bye_bye");

— Встроенная функция: atexit (fcn, flag)

Register or unregister a function to be called when Octave exits, depending on flag. If flag is true, the function is registered, if flag is false, it is unregistered. For example, after registering the function bye_bye as above,
atexit ("bye_bye", false);
will remove the function from the list and Octave will not call the function bye_by when it exits.
Note that atexit only removes the first occurence of a function from the list, so if a function was placed in the list multiple times with atexit, it must also be removed from the list multiple times.

Getting Help[править]

Command Line Editing[править]

Errors[править]

Executable Octave Programs[править]

Comments[править]