Here is an example of modular programming; compilation is performed in three alternative ways: 1. From all sources: g95 mod1.f90 mod2.f90 main.f90 -o main 2. From object files: g95 mod1.o mod2.o main.f90 -o main 3. From a library: g95 main.f90 -o main -L. -lmods The example sources are main.f90, mod1.f90, mod2.f90 main.f90 -------------------------- PROGRAM MAIN USE mod1 USE mod2 PRINT *, Message call sub1(A) call sub2(A) call sub3(A) END PROGRAM MAIN --------------------------- mod1.f90 --------------------------- MODULE mod1 CONTAINS subroutine sub1(X) print *,X end subroutine sub1 subroutine sub2(X) print *,X**2 end subroutine sub2 END MODULE mod1 --------------------------- mod2.f90 --------------------------- MODULE mod2 REAL :: A=3.0 CHARACTER(LEN=36) :: Message="This is an example of using modules." CONTAINS subroutine sub3(X) print *,X**3 end subroutine sub3 END MODULE mod2 --------------------------- The program can be compiled as follows. From all source files: $ g95 mod1.f90 mod2.f90 main.f90 -o main Or we can compile the modules to objects: $ g95 -c mod1.f90 $ g95 -c mod2.f90 (these commands generate the object files mod1.o and mod2.o, also mod1.mod and mod2.mod). and compile by linking the objects $ g95 mod1.o mod2.o main.f90 -o main (the files mod1.mod and mod2.mod are needed for linking) Or the module objects can be placed inside a library: $ ar rcvf libmods.a mod1.o mod2.o ar rcvf libmods.a another.o - to add another object ar tv libmods.a - to list the contents of the library ar dv libmods.a mod2.o - to delete object mod2.o nm libmods.a - to list the subprograms it contains and compiled by linking the library $ g95 main.f90 -o main -L. -lmods (the files mod1.mod and mod2.mod are still needed for linking) 02/10/2006