Structure FORTRAN MATLAB MAPLE C
============ ==================== ===================== ======================= ========================
case sensitive no yes yes yes
comment line c or * in 1st column % # /* ... */
comment inline ! comments % comments # comments /* comments */
special spaces ignored ; suppress output : suppress output
: next statement ; end statement ; next statement
Variables REAL A,B all variables complex, types set by assignment int, float, double, char
INTEGER I,J double precision i:=2; x:=2.0; static
CHAR*5 Label Label:=`abc`; void, struct
Dimensions DIMENSION A(10) auto dim'd as used; A:=array(1..10); float A[10]
REAL B(10,5) up to two dimensions B:=array(1..10,1..5); float B[10][5]
REAL*8 C(-2:5) C:=array(-2..5); double C[7]
(any index) (index >=1) (any index) (index >=0 )
Array Elements A(3), B(3,2), C(-1) A(3), B(3,2) A[3], B[3,2], C[-1] A[3], B[3][2]
Arithmetic + - * / ** + - * / ^ + - * / ** (or ^) + - * / **
.* ./ .^ (element-wise) &* (matrix product)
Do Loop DO I = 1,10,2 for i = 1:2:10 for i from 1 to 10 by 2 do for (i=1; i<=10; ++2)
.... .... ; ....; { .... ;
ENDDO end od; }
While Loop DO WHILE (A.EQ.0) while a==0 while a=0 do while (a=0)
... ... ; ...; { ... ;
ENDDO end od; }
If-Then-Else IF (A.EQ.0) THEN if a==0 if a=0 then if (a==0)
.... .... ....; { ...... }
ELSEIF(a.GT.2) THEN elseif a>2 elif a>2 then elseif (a>2) then
.... .... ....; { ...... }
ELSE else else else
.... .... ....; { ...... }
ENDIF end fi
Comparisons .EQ. .NE. == ~= = <> == !=
.LT. .LE. < <= < <= < <=
.GT. .GE. > >= > >= > >=
read variable READ*, a a=input('a: ') readline readstat scanf
sscanf
Output WRITE < var >, disp printf printf
PRINT fprintf write, writeto, appendto fprintf
global vars COMMON /foo/ a, x(3) global a,x[3] declared before main()
extern float x[];
Functions FUNCTION fn(x,y) function y=fn(x,y) f:= (x,y) -> fn(x,y) <rtn> fn(int n, float x)
fn=... y=... {...; }
return rtn = void | int | float
Subroutines SUBROUTINE foo(N,a,x) foo:=proc()
... ...;
return end:
end
program files code.f code.m code (code.m) code.c
compile f77 code.f (interpreted) (interpreted) cc -c code.c
mint code (debug) cc -c code.c -lm (math lib)
execute a.out >> code > read(code); a.out
or: matlab < code.m or: maple < code > out
I/O to files a.out < dat > out >> load dat a.out < dat > out
>> diary out