<<

Linux Commands / Fortran compilation

Moving around directories A Linux environment is composed of a directory tree structure. A user will generally work in his or her home directory /home/myname and will never such directory.

/home/myname /home/myname/DIR1 /home/myname/DIR2 /home/myname/DIR3 /home/myname/DIR3 /home/myname/DIR3/example1

To move from one directory to another we use the ’change directory’

/home/myname > cd DIR3 /home/myname/DIR3 > cd example1 /home/myname/DIR3/example1 > cd .. /home/myname/DIR3 > cd .. /home/myname >

We will work in a common home directory called /home/lab1 or /home/lab2 and each user will only move within his or her subdirectory:

/home/lab1 /home/lab1/U1_ROSSI /home/lab1/U2_BIANCHI /home/lab1/U2_BIANCHI/example1

Copying moving and deleting files In order to copy a file from one place to another (one directory to another) we use the ’copy’ com- mand . Suppose we have a file called STANDARD_ATMOSPHERE.eps we wish to copy into directory FIGS/

/home/lab1/U2_BIANCHI/example1/OUT > cp STANDARD_ATMOSPHERE.eps FIGS/.

Note that this will leave a copy of the file where it was copied from. Equivalently we cound

/home/lab1/U2_BIANCHI/example1/OUT > cp STANDARD_ATMOSPHERE.eps FIGS/STANDARD_ATMOSPHERE.eps or, if we wish to change the file name in the process we can write

/home/lab1/U2_BIANCHI/example1/OUT > cp STANDARD_ATMOSPHERE.eps FIGS/STANDARD_ATMOSPHERE_1.eps The ’move’ command is used to rename files and directories. Suppose we want to rename STANDARD_ATMOSPHERE.eps to STANDARD_ATMOSPHERE_1.eps

/home/lab1/U2_BIANCHI/example1/OUT > mv STANDARD_ATMOSPHERE.eps STANDARD_ATMOSPHERE_1.eps

Note that the old file will not exist anymore under the old name!

We can use the cp and mv commands to copy and move files as well as whole directories. For example this will copy the directory FIGS/ to a new directory called FIGS1/ (the old directory FIGS/ will still exist because we used a copy command not a move command):

/home/lab1/U2_BIANCHI/example1/OUT > cp -rf FIGS FIGS1

Creating a new directory

If we wish to create a completely new directory we will use the ’ directory’ command . For example, in order to make the FIGS/ directory we will :

/home/lab1/U2_BIANCHI/example1/OUT > mkdir FIGS

File editing Writing a program or modifying it falls under the ’file editing’ task. Any text editor will do. Linux has a number of very efficient editors, any of them will do. We will use gedit. In order to launch it simply type

/home/lab1/U2_BIANCHI/example1 > gedit

Compiling a program

All Fortran files are supplied with an extra file called Makefile. We are not required to learn what Makefile is. It is sufficient to know that it allows us to compile a set of Fortran files into a single executable file. In order to compile we will use the make command executes the Makefile. In almost all of our problems it will be sufficient to invoke the following:

/home/lab1/U2_BIANCHI/example1 > make

This will generate an executable file, which, in most cases will be called main_cycle. To execute (run) main_cycle just type:

/home/lab1/U2_BIANCHI/example1 > ./main_cycle