Information Technology Reference
In-Depth Information
This code is placed in a file, say, gint.f . The file must be compiled, resulting in the
object file gint.o . This object file must thereafter be linked with the library file.
The typical manual steps on a Unix computer read
unix> f77 -O3 -c gint.f
unix> f77 -L$HOME/lib -o app gint.o -lmylib
The first command is the compilation step. The second command is the linking step.
The -L option tells f77 where to search for library files, and -o specifies the name
of the executable (here app , for application). The rest of the arguments are object
files and library files that should be linked together to form the executable. Observe
that library files are written with a special syntax, a prefix -l (for library) followed
by the name of the library.
CandC CC libraries are created in the same way as explained for Fortran
libraries.
Java Libraries
Java libraries consist of classes, and each publicly available class is placed in a
file. These files are conveniently organized in directory hierarchies. In the present
example with numerical integration, we would typically implement the integra-
tion methods as classes Trapezoidal , Simpson , etc., stored, respectively, in files
Trapezoidal.java , Simpson.java , and so on. The files are naturally located in a
directory, say /home/me/java/int . The application code must import one or more
of these methods, and Java searches for classes to import in the directories con-
tained in the CLASSPATH environment variable. In a Bash Unix environment, the
CLASSPATH variable is typically initialized in a Bash start-up file .bashrc in your
home directory. The initialization statement reads
export CLASSPATH=$CLASSPATH:/home/me/java/int
There is a utility called jar for packing a set of Java source code files in a single
file ( jar can be viewed as Java's counterpart to the Unix tar utility).
Matlab Libraries
Matlab functions are stored in so-called M-files with extension .m .OneM-file
defines a single function to be used outside the file. For example, the file X.m
defines a function X , with as many input arguments and return arguments as desired.
Other functions can be placed after the function X in the file X.m , but these func-
tions are only local to the file, so they cannot be accessed from the calling Matlab
environment (or script).
In the present example, we would put the various integration methods in separate
M-files, i.e., Trapezoidal.m , Simpson.m , and so on. These M-files are conve-
niently stored in a directory whose name reflects the numerical integration, say
/home/me/matlab/int . The name of this directory must be contained in Matlab's
Search WWH ::




Custom Search