Fortran 90 goes back to the seventies

From NA-Wiki

Jump to: navigation, search

I no longer endorse most things below... People change and so does definitions :-) /holst, 2008 AD

The binary compatibility between different Fortran compilers is near nil. This is especially true if you are using modules. Modules where introduced in Fortran 90. Many other good things where added to Fortran 90, while in my meaning the implementation of some of them could have been better... Let's just leave it at that. :-)

It's not strictly nessicary to write Fortran 90 code in UPPER CASE but I like it. FORTRANcase.vim is a script for Vim to make all text (except comments and strings) in UPPER CASE.

Include file:

TYPE STUFFS                   ! We can use Fortran 90 constructs
    REAL VALUE
END TYPE
INTERFACE FOO                 ! Even the Fortran 90 interfaces!
    SUBROUTINE BAR(X)
    INTEGER X
    END SUBROUTINE
END INTERFACE
INTEGER GLOBAL                ! Now we make use of an old friend:
                              ! The COMMON BLOCK!
COMMON /GLOBAL/ GLOBAL        ! GLOBAL variable is named global_ in .o file

Main program:

PROGRAM TEST
    INCLUDE 'test.inc'
    PRINT*,'GLOBAL:',GLOBAL   ! GLOBAL=0 (or compiler dependent)
    CALL FOO(1)               ! CALL FOO(1.0) will not work. 
                              ! We are in strongly typed land now!
    PRINT*,'GLOBAL:',GLOBAL   ! GLOBAL=1
END PROGRAM TEST

("external") subroutine which access and modify shared (global or common) data:

SUBROUTINE BAR(X)
    INTEGER X
    INCLUDE 'test.inc'
    PRINT*,'INSIDE THE BAR'
    GLOBAL=GLOBAL+1
END SUBROUTINE

Compile the test with

f90 -c test.f90
f90 -c bar.f90
f90 -o test test.o bar.o

I also recommend that you analyze the object files with the nm command.

You can also find an interesting discussion raised about this in the comp.lang.fortran Usenet group.

Personal tools