Professional Documents
Culture Documents
Fortran: Énergétique 2 Groupe 3 TP2
Fortran: Énergétique 2 Groupe 3 TP2
𝑇𝑃0 FORTRAN
Énergétique 2 Groupe 3 TP2
Souayedd Mayssem
Yahya Siwar
Trabelsi Bt Adel Emna
Solaani Zakarya
1. Basic program structure in Fortran
• The program
• statement (which tells the compiler where the program
be- gins)
• Variable•declarations (which tells the compiler what variables will be used,
and what type they are)
• Instructions as to what to do
• An end statement (which tells the program where the program ends)
Wich looks like the following :
program nameofprogram
implicit none
integer a,b
real x,y
parameter nom variable=valeur
character h
instructions
end program
2. Outputting data
a. To print the results to the screen
b. To print the results to a file
Open (n
file=filename)
Write(n,*)Z
Close (n)
3. Reading data
• To read information, the command is very similar to that
of the write statements : they usually take the form of
read (X, Y) Z. For instance, to read the value of x from a
screen prompt, and then write it back to the screen, you
could add the following command to the code :
• If inst then
Else inst exécuté si condition logique fausse
Endif
• Do inst
End do
• Do while condition
End do
6. Subroutines
subroutine nameofroutine(arg1,arg2,arg3,...,argn)
implicit none
declarations
instructions
end subroutine
nameofroutine
7. Application TP0
▪ Ouverture du logiciel :
On déclenche le logiciel Fortran
File →new file → Fortran Fixed Format File
Exercice 1 : calculer z = x+y
Pour lire une variable à l’écran
read *, ‘ Commentaire ‘, nom variables
Pour afficher une variable à l’écran
print *, ‘ Commentaire ‘, nom variables
Programmation :
Instructions
End do
Cas 1 : Pas =1
Cas 2 : Pas=2
Exercice 4 : utilisation d’un opérateur de comparaison :
Exercice 5: calcul d’une somme de deux matrices