@@ -96,13 +96,13 @@ more than 45% of scientific applications are in Fortran
---
# How to Build a FORTRAN Program
# How to build a FORTRAN program
FORTRAN is a compiled language (like C) so the source code (what you write) must be converted into machine code before it can be executed (e.g. Make command)
It is possible to pre-define the structure of input and output data using `NAMELIST` in order to make it easier to process with `READ` and `WRITE` statements
...
...
@@ -645,15 +657,15 @@ On input, the `NAMELIST` data must be structured as follows:
---
# Internal `WRITE` Statement
# Internal `WRITE` statement
Internal `WRITE` does same as `ENCODE` in F77 : **a cast to string**
```fortran
INTEGER*4J,K
CHARACTER*50CHAR50
DATAJ,K/1,2/
...
INTEGERJ,K
CHARACTER(50)CHAR50
J=1
K=2
WRITE(CHAR50,*)J,K
```
...
...
@@ -665,16 +677,17 @@ CHAR50=' 1 2'
---
# Internal `READ` Statement
# Internal `READ` statement
Internal `READ` does same as `DECODE` in F77 : **a cast from string**
@@ -851,22 +863,6 @@ How do you tell subprogram how large the array is ?
---
# Data layout in multi-dimensional arrays
- always increment the left-most index of multi-dimensional arrays in the innermost loop (i.e. fastest)
-**column major** ordering in Fortran vs. **row major** ordering in C
- a compiler (with sufficient optimization flags) may re-order loops automatically
```fortran
doj=1,M
doi=1,N! innermost loop
y(i)=y(i)+a(i,j)*x(j)! left-most index is i
enddo
enddo
```
---
# Arrays - dynamic allocation
Using `ALLOCATABLE` on declaration, and using `ALLOCATE` and `DEALLOCATE` later
...
...
@@ -912,6 +908,7 @@ Text file [08_ChristmasTree.txt](https://forge.uclouvain.be/barriat/learning-for
---
<!--
# Modular programming (>F90)
Modular programming is about separating parts of programs into independent and interchangeable modules :
...
...
@@ -925,6 +922,7 @@ Modular programming is about separating parts of programs into independent and i
The principle is that making significant parts of the code independent, replaceable and independently testable makes your programs **more maintainable**