2009年7月8日 星期三

Octave's hello world

今天貼一個在 OCTAVE 上用 C 來寫程式
Octave 是一個數學運匴軟體,相當好用, 功能類似 matlab, 但它是自由軟體.學工程的決不能錯過, 且灌完後內建 C++ compiler, 可以用 C 來寫程式, 用 mkoctfile 來 complie, 之後會產生 .oct 檔, 該檔便可直接在命令列上呼叫, 如果要移除已載入的 .oct 程式, 可以下命令 clear all 或 clear 該oct 檔名即可

/*
Refer to URL: http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
use following syntax to compile under octave command line:
> mkoctfile hello.cc
Then it will generate a OCT file called hello.oct in the same directory
type
> p=hello
will execute the program, and the return message will be stored to variable 'p'
type
> help hello
will display the help message about the hello
In the end, it will return a string "OK" back to octave
type
>clear all
or
>clear hello
will unload the oct file
*/

// hello.cc
#include "octave/oct.h"
#include "windows.h"
#include "stdio.h"
DEFUN_DLD(hello,args,nargout,"Hello world\n")
{
octave_value_list OctRet;
printf("This is OCT file\n");
OctRet(0)="OK";
return OctRet;
}

沒有留言: