Programming

From NA-Wiki

(Difference between revisions)
Jump to: navigation, search
Line 8: Line 8:
* Why [[use Eclipse]] or a similar development environment?
* Why [[use Eclipse]] or a similar development environment?
 +
 +
== Fortran ==
 +
 +
=== Fortran 90 goes back to the seventies ===
 +
 +
This is how you can use Fortran 90 without having to use the <i>highly non-portable</i> module system.
 +
There might be some reasons to use MODULE files but I cannot think of one right now. :-)
 +
 +
Include file:
 +
<pre>
 +
TYPE STUFFS
 +
    REAL VALUE
 +
END TYPE
 +
INTEGER GLOBAL
 +
COMMON /GLOBAL/ GLOBAL        ! GLOBAL variable is named global_ in .o file
 +
INTERFACE FOO
 +
    SUBROUTINE BAR(X)
 +
    INTEGER X
 +
    END SUBROUTINE
 +
END INTERFACE
 +
</pre>
 +
 +
Main program:
 +
<pre>
 +
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
 +
</pre>
 +
 +
("external") subroutine which access and
 +
modify shared (global or common) data:
 +
<pre>
 +
SUBROUTINE BAR(X)
 +
    INTEGER X
 +
    INCLUDE 'test.inc'
 +
    PRINT*,'INSIDE THE BAR'
 +
    GLOBAL=GLOBAL+1
 +
END SUBROUTINE
 +
</pre>
 +
 +
Compile the test with
 +
<pre>
 +
f90 -c test.f90
 +
f90 -c bar.f90
 +
f90 -o test test.o bar.o
 +
</pre>
 +
I also recommend that you analyze the object files with the <tt>nm</tt> command.
== Links ==
== Links ==

Revision as of 02:32, 12 July 2007

Contents

Howtos in programming

General programming topics

  • Why use Eclipse or a similar development environment?

Fortran

Fortran 90 goes back to the seventies

This is how you can use Fortran 90 without having to use the highly non-portable module system. There might be some reasons to use MODULE files but I cannot think of one right now. :-)

Include file:

TYPE STUFFS
    REAL VALUE
END TYPE
INTEGER GLOBAL
COMMON /GLOBAL/ GLOBAL        ! GLOBAL variable is named global_ in .o file
INTERFACE FOO
    SUBROUTINE BAR(X)
    INTEGER X
    END SUBROUTINE
END INTERFACE

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.

Links

  • Software carpentry - an on-line course on how to work more like a developer when you write your research code.
  • Freely available software for linear algebra on the web link.
Personal tools