Commit 7d31ed2d authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

added some Fortran interface documentation

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1237
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 3d682c21
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.21 2002-12-23 18:07:32 forbrig Exp $
* $Id: README.changelog,v 1.22 2002-12-27 13:12:17 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,12 +21,15 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.21 2002-12-23 18:07:32 forbrig Exp $
$Id: README.changelog,v 1.22 2002-12-27 13:12:17 forbrig Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 27/12/2002 (thof)
- continued with Fortran interface documentation (\ref page_fortran)
- \b 23/12/2002 (thof)
- coded class aff::Subarray
- coded class aff::Slice
......@@ -93,7 +96,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.21 2002-12-23 18:07:32 forbrig Exp $
$Id: README.changelog,v 1.22 2002-12-27 13:12:17 forbrig Exp $
\sa \ref page_changelog
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README,v 1.7 2002-12-23 14:32:04 forbrig Exp $
* $Id: README,v 1.8 2002-12-27 13:12:20 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -18,6 +18,8 @@
* - 08/12/2002 V1.0 copied from libcontxx
* - 20/12/2002 V1.1 (thof)
* - complete revision of this file
* - 27/12/2002 V1.2 (thof)
* - continued with Fortran considerations
*
* ============================================================================
*/
......@@ -120,13 +122,120 @@ deep copy (elementwise copy) and a shallow copy (copying the representation).
/*! \page page_fortran Interfacing Fortran 77
Contents of this page:
- \ref sec_fortran_links
- \ref sec_fortran_general
- \ref sec_fortran_call
- \ref sec_fortran_common
- \ref sec_fortran_links
After switching to C++ many numerical routines coded in Fortran 77 will stay
in use. Recoding them in C++ should not generally be considered. It involves
a lot of extra work and potentially introduces new bugs and errors to code
that was well tested before. Thus some of our C++ functions have to call
underlying Fortran 77 code and must exchange data with this code, in
particular. Exchanging data also involves passing arrays to and from
Fortran.
The example tests/f77test.cc and its associates demonstrates how AFF data
may be passed to Fortran and how Fortran arrays may be integrated into AFF.
\sa namespace f77interface
\sa tests/f77interface.cc
\sa tests/f77proto.h
\sa tests/f77procs.f
\sa tests/f77common.inc
\sa tests/Makefile
\section sec_fortran_links Links to other helpful information
/*----------------------------------------------------------------------*/
\section sec_fortran_general Some general considerations
\par Compiler
There are two common Fortran 77 compilers available on Linux platforms:
The GNU Fortran 77 (g77) from the GNU compiler collection
("http://www.gnu.org/software/gcc/gcc.html") and
the Fortran to C compiler (f2c) published through netlib
("http://netlib.bell-labs.com/netlib/f2c/index.html").
\par
When compiling the C++ part with the g++ from the GNU compiler collection it
may seem natural to use g77 for the Fortran part. However, when interfacing
the Fortran components, we have to know about the internals of the compiled
Fortran code so that the linker will find the components, that we wish to
access. g77 does not expose these internals, in particular it may operate in
different modes (f2c compatible or not) and is subject to future changes.
f2c on the other hand exposes the intermediate C code, which is then
compiled by gcc from the GNU compiler collection and may easily be linked to
C++ code.
\par
\b Decision:
We use f2c and gcc in our examples of interoparting Fortran code and AFF.
\par Prototypes
Source code is usually separated into different compilation units (source
files). These code fragmemts must be kept synchronous, i.e. all calls to a
function must use the same (and correct) formal parameters, all access to
global data (e.g. common blocks) must use the same declaration.
\par
While C offers a control mechanism to ensure snychronous code (through
prototypes and header files), Fortran 77 does not. A common technique with
Fortran is to read common block definitions from extra files (using the
include statement), thus ensuring that every function and subroutine uses
the same definition. How can we ensure that later changes applied to the
Fortran code will be recognized in the interoperating C++ code?
\par
\b Decision:
We make extensive use of header files and prototypes that can be generated
with f2c. This makes interface code more complicated (i.e. splits it into
more different compilation units) and introduces more header files (e.g.
tests/f77common_com.P and tests/f77procs.P) but introduces more safety too.
Aspects to consider:
-# Passing pointers of Fortran type to pointer of C++ type
(reinterpret_cast)
-# Creating function call prototypes
-# factoring out interfacing issues to seperate compilation unit and
interface functions
-# creating function call prototypes with extern "C" linkage
-# creating common block declarations with extern linkage
-# passing fixed array dimensions from Fortran to C++
-# passing variable array dimensions from Fortran common block to C++
-# how to satisfy linker with a MAIN__ function
-# compiling f2c output with gcc (using -C++ option)
/*----------------------------------------------------------------------*/
\section sec_fortran_call Passing arrays through function calls
/*----------------------------------------------------------------------*/
\section sec_fortran_common Accessing arrays in common blocks
/*----------------------------------------------------------------------*/
\section sec_fortran_links Links to other helpful information
- In the manual of the GNU Fortran 77 compiler you will find a section
discussing "Interoperating with C and C++".
- http://gcc.gnu.org/onlinedocs/g77/Interoperating-with-C-and-C--.html#Interoperating%20with%20C%20and%20C++
- http://gcc.gnu.org/onlinedocs/
- Burkhard D. Steinmacher-Burow provides cfortran.h for "Interfacing C or C++
and Fortran".
- http://www-zeus.desy.de/~burow/cfortran/index.htm
- http://www-zeus.desy.de/~burow/cfortran/cfortran.html
- A very usefull tool for coding interfaces to Fortran 77 is the f2c
compiler. Its documentation provides a lot of useful information about
the way Fortran code objects may be accessed from C and C++.
- http://netlib.bell-labs.com/netlib/f2c/index.html
- Further discussions may be found at other places:
- http://wwwinfo.cern.ch/asdcgi/listcernlibfaqs.pl/3
- http://home.online.no/~arnholm/cppf77.htm
- http://www.llnl.gov/CASC/components/babel.html
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment