[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]
Fortran 90 Lessons for Computational Chemistry
The main aims of this session consist of:
giving a short introduction on programming and programming languages.
emphasize the importance of a clear understanding of the problem under study and the use of flow diagrams for achieving structured and clear source code.
a brief presentation of the main features of the Fortran
programming language.
installation of the GNU Fortran compiler, gfortran.
Studying two simple codes.
Presenting possible sources of information for the interested student.
By default we will use the emacs text editor. The first examples
are the simple programs excode_1_1.f90,
Section 1.3.1 y excode_1_2.f90, Section
1.3.2.
Using the examples the student should be aware of the main sections included in a program::
Head of the code with the statement PROGRAM program_name.
Variable definition.
Main program body, including I/O operations.
End of the program: END PROGRAM program_name.
Things to take into account:
Importance of remarks and comments. Include many comments in your code, trying
to be as clear as possible. Fortran remarks are introduced with
the character !. A correct indentation also improves the code
readability. The emacs text editor greatly helps in this task.
The importance of the IMPLICIT NONE statement. Declare and initialize properly all variables as in example excode_1_2.f90, Section 1.3.2.
Distinguish the I/O operations.
PROGRAM ex_1_1
!
! This program reads and displays a string.
!
IMPLICIT NONE
CHARACTER(LEN=50) :: Name
!
PRINT *,' Write your name. Do not forget quoting it:'
PRINT *,' (max 50 characters)'
READ(*,*), Name
PRINT *, Name
!
END PROGRAM ex_1_1
PROGRAM ex_1_2
!
! This program reads three numbers and compute their sum and mean value
!
IMPLICIT NONE
REAL :: N1, N2, N3, Average = 0.0, Total = 0.0
INTEGER :: N = 3
PRINT *,' Input three numbers (return, coma, or space separated).'
PRINT *,' '
READ *,N1,N2,N3
Total = N1 + N2 + N3
Average = Total/N
PRINT *,'Sum: ',Total
PRINT *,'Mean value: ',Average
END PROGRAM ex_1_2
[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]
Fortran 90 Lessons for Computational Chemistry
mailto:francisco.perez@dfaie.uhu.es