Monday 22 June 2009

Formatted Read Statements again.

Grrr. I'm trying to read in a formatted file of integers such as:
1 1 1
10 10 10
100 100 100
(... three characters wide, one space between each column)
Fortran is giving me junk unless I format my read statement with
10 format(I3,A1,I3,A1,I3)
where I read the single space into a temporary variable declared as:
character(1) :: tmp
This is why I am in a bad mood with Fortran today. I put faith in it, and this is how it repays me. Plus, the fridge has frozen my tomatoes. I wonder if they are in league.

Friday 19 June 2009

Compiling modules separately

When I have a module declared in mymodule.f90, I can compile it like so:
gfortran -m32 -c mymodule.f90
... I can also compile the main file this way:
gfortran -m32 -c mainfile.f90
Finally I must link it, possibly also with the NAG library:
gfortran -m32 mymodule.o mainfile.o /opt/NAG/fll3a21dfl/lib/libnag_nag.a -o mainfile

Thursday 18 June 2009

Fortran array initialization

This webpage here is very helpful for fortran arrays.

I'd forgotten that you can initialize vectors like this:
x = (/(i,i=0,maxx-1)/)
Instead of:
do i=1,maxx
x(i) = i-1
enddo