C C++/Matlab/Fortran 77Dictionary 327
Functions and subroutines
The structure of functions in C++ was discussed in this book, and the
structure of functions inMatlabis discussed in Appendix F.
Fortran 77uses functions and subroutines. The structure of a subrou-
tine is:
subroutine poulaki (a, b,...,s)
...
return
end
The parentheses enclose input and output arguments listed in arbitrary order,
and the three dots indicate additional lines of code. The statement calling the
subroutine is:
call poulaki (peace, train, ..., cat)
All arguments inFortran 77are passed by reference. Thus, aFortran
77 function or subroutine is able to change any input argument.
Fortran 77subroutines are written either in the file hosting the main
program or in other files contain one subroutine or multiple subroutines, listed in
arbitrary order. The names of the files containing the subroutines are arbitrary
and bear no relationship to the names of the subroutines.includefiles are not
necessary inFortran 77.
In contrast,Matlabfunctions are placed in individual files, one function
per file. Strangely, the name of the function is determined by the file name,
with the function name stated in the function declaration inside the file being
irrelevant. This explains why each file must contain only one function, possibly
resulting in a huge collection.includefiles are not necessary inMatlab.
Translation tables
Table C.1 displays the relational and logical operands in the three lan-
guages. The similarities betweenMatlaband C++ are noteworthy.
AMatlaborFortran 77code can be translated into C++ code using
the language syntax explained in Tables C.2-4.
Examples
The following C++ code prints on the screen the greeting “Hello Themis-
tocles” and moves the cursor to the next line: