Compile Programs by f77 or f90
Run Jobs Interactively, in Background or in Batch
Link and Run Several Programs
Construct a Script File
Set Up a Console Reading File
To run Fortran jobs in JGSM research machine, you need to compile the program first and create an executable file, and then to run the executable file interactively, in background or in batch. While the small jobs and testing programs can be run interactively, the big jobs should be run in batch to avoid locking up the terminals.
Compile Programs by f77 or f90
f77 compile sFortran 77 source files with suffix .f and f90 compiles Fortran90 source files with suffix .f90. Suppose you have two Fortran program, prog.f that is written by Fortran 77 and prog.f90 that is written by Fortran 90, and you can compile them with "f77 prog.f" and " f90 prog.f90 ". By default, either f77 or f90 command will produce an executable file named a.out in the current directory. To create an executable file with a different name instead of a.out, use -o command, which specifies a name for the executable file. "f77 prog.f -o prog" will produce an executable file named prog. In the following, the a.out and prog are assumed to be executable files.
Run Jobs Interactively, in Background or in Batch
1). To run a job interactively, type "a.out" or "prog" in your terminal.
2). To run a job in background, type "a.out &" or "prog & " in your terminal. In this case, you can do something else in the same terminal while the job is running.
3). You may use nohup command to run programs in the background after logged off, i.e. "nohup a.out &" or "nohup prog &". The console output is then directed to the nohup.out file in current directory.
4). To run a job named a.out in batch, do following:
batch << !
a.out
!
You will receive a message " job #####.b at ? day, ? date and ? time, ? year" . To check the status of your program use " ps -u userid " command that will generate a table with titles UID PID TTY TIME CMD in your screen. If the program is running, you will see your program name appears under CMD. The number in the same line under PID is your program ID which is the only number you can use if you want to kill the job. The output now is directed to your mail queue. You can read the output by just type " mail ". To exit mail list, type " q ". All mails you just read are saved on /home/mbox. You should delete the mails accumulated in your mailbox once in a while.
Link and Run Several Programs
To link several Fortran programs, you do not need to do anything because the linker is invoked automatically to produce an executable output file by compiling:
F77 prog1.f prog2.f prog3.f # compiles and links the three programs
# & produces an executable file a.out
To run the produced executive file, simply type:
a.out # runs the executive file
To produce object files that can be linked later, use -c option.
f77 -c prog1.f # produces an object file for prog1.f
f77 -c prog2.f # produces an object file for prog2.f
f77 -c prog3.f # produces an object file for prog3.f
f77 prog1.o prog2.o prog3.o # links the object files & produces a.out
a.out # runs the executable file a.out
If you want to produce an executable file named test rather than a.out, use -o command such that " f77 prog1.o prog2.o prog3.o -o prog".
Construct a Script File
The easiest way to compile and link several programs is to create a script file which contains all compiling and linking statements. Using the above example, you first create a file named prog.scr which contains compiling and linking prog1.f, prog2.f and prog3.f, and creating an executable file named prog. You can also put a run command in this file to run the program. The prog.scr in this case looks like this:
f77 -c prog1.f # produces an object file for prog1.f
f77 -c prog2.f # produces an object file for prog2.f
f77 -c prog3.f # produces an object file for prog3.f
f77 prog1.o prog2.o prog3.o -o prog
# links the object files & produces prog
prog # runs the executable file prog
Now, you just execute the prog.scr file. If prog.scr is not executable use "chmod" to change it.
Set Up a Console Reading File
Sometimes, the program asks the inputs from console. This can be easily handled in batch by creating a file say " prog.in " which contains all inputs needed by the program sequentially. Then add <prog.in> and prog.out following the prog in prog.scr file. The prog.out file contains all outputs from console. The prog.scr now becomes:
f77 -c prog1.f # produces an object file for prog1.f
f77 -c prog2.f # produces an object file for prog2.f
f77 -c prog3.f # produces an object file for prog3.f
f77 prog.o prog2.o prog3.o -o prog
# links the object files & produces prog
prog <prog.in> prog.out # runs prog and reads console input from
# prog.in & write console output to
# prog.out