Information Technology Reference
In-Depth Information
3. Setting a , b ,and n , calling the numerical integration function, and printing the
result
We will present small applications running a loop over different n values and calling
up the four methods for each value of n .
Libraries and Compiled Languages
How you technically create the library depends on the programming language used
to implement the algorithms. In Fortran, C, and C CC you must compile the library
file and place it in a directory that acts as a repository for your libraries. Most real-
life libraries are made up of many files, since it would naturally be inconvenient to
put all the library code in one big file. These individual files must be compiled, one
by one, and then a tool for merging the compiled files into one library file must be
invoked. Here is a typical manual procedure, in a Unix environment, for compiling
three Fortran 77 files file1.f , file2.f ,and file3.f and making a library mylib
out of them:
unix> f77 -O3 -c file1.f file2.f file3.f
unix> ar libmylib.a file1.o file2.o file3.o
The first line compiles the files, resulting in three object files file1.o , file2.o ,
and file3.o . The second line runs the ar utility to merge the object files into a
library file libmylib.a . The name of the library file must always start with lib ,
and this is not a part of the library name (just mylib is the library name in this case).
There are many variants of this theme; the purpose here is to give a brief description
of how classic subroutine libraries are created. The library file libmylib.a must be
located in a directory for libraries. On a Unix system, /usr/lib is such a directory,
but only system administrators have write access to this directory, so one probably
needs to create one's own library directory, e.g., $HOME/lib . In the following we
assume that libmylib.a is located in $HOME/lib .
An application can now be written that calls up functionality in the library:
real * 8 function g(x)
real * 8x
g=x * tanh(x)
return
end
real * 8a,b,I
integer n
program test
a=0
b=10
n = 200
I = trapezoidal(a, b, g, n)
write( * , * )I
end
Search WWH ::




Custom Search