Programming

From NA-Wiki

(Difference between revisions)
Jump to: navigation, search
m (Fortran 90 goes back to the seventies)
m
Line 11: Line 11:
== Fortran ==
== Fortran ==
-
=== Fortran 90 goes back to the seventies ===
+
* [[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.
-
 
+
-
This is how you can use Fortran 90 without having to use the <i>highly non-portable</i> MODULE system.  
+
-
 
+
-
You will shoot down any Fortran MODULE on sight after you have seen this solution.(*)
+
-
 
+
-
Include file:
+
-
<pre>
+
-
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
+
-
</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.
+
-
 
+
-
(*) There might be some reasons to use MODULE files but I cannot think of one right now. :-)
+
== Links ==
== Links ==

Revision as of 02:45, 12 July 2007

Contents

Howtos in programming

General programming topics

  • Why use Eclipse or a similar development environment?

Fortran

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