When mixing Fortran source code with C source code, without using the C interoperability features of Fortran 2003, the following points should be noted.
main
’.
Module variables and module procedure names are formed by taking the module
name (in lower case), appending ‘_MP_
’ and then appending the
entity's name (in lower case).
These conventions differ when the -compatible option is used. On Windows this causes external procedures and common blocks to be in upper case with no trailing underscore, while module entities have the module name in upper case instead of lower case (64-bit Windows is always -compatible). On most other platforms this option adds an extra underscore (after the one that is always added) for names that already had an underscore.
__NAGf90_rts_init(int argc,char*argv[])or the i/o initialisation routine
__NAGf90_io_init(void)should be called from C. The
__NAGf90_rts_init
routine initialises the Fortran floating-point environment
as well as allowing command-line arguments to be accessed via the Fortran 2003
intrinsic functions and also via the F90_UNIX
module.
Additionally, the program should be terminated with
__NAGf90_finish(int status)
, or alternatively __NAGf90_io_finish(void)
may
be called before the usual C termination routine to close all Fortran files
and flush the Fortran i/o buffers (failing to do this might corrupt an output
file that is still open).
The conventions used for the Fortran 77 subset of Modern Fortran
are compatible with the de facto UNIX f77 conventions (except for COMPLEX
functions compiled without the -compatible option).
dope.h
and nagfortran.h
, which are located in the
compiler library directory (usually /usr/local/lib/NAG_Fortran
on
UNIX-like systems).
Fortran Data Type | Fortran Precision | C typedef name |
INTEGER | 8 bits | Integer1 |
16 bits | Integer2 | |
32 bits | Integer or Integer3 | |
64 bits | Integer4 | |
LOGICAL | 8 bits | Logical1 |
16 bits | Logical2 | |
32 bits | Logical | |
64 bits | Logical4 | |
REAL | half | __NAGf90_HReal |
single | Real | |
double | Double | |
double-double | DDReal | |
quadruple | QReal | |
COMPLEX | half | __NAGf90_HComplex |
single | Complex | |
double | DComplex | |
double-double | DDComplex | |
quadruple | QComplex |
Note that DDReal and QReal are the same on most systems; on Sun Solaris these are different (the latter being an IEEE-conformant 128-bit floating-point type).
POINTER
types are simply C pointers
to the object.
An array POINTER
is a dope vector describing the array pointed to.
Unlike a simple address, these dope vectors are capable of directly
describing non-contiguous array sections of contiguous arrays.
See below (Dope
N and ChDope
N) for further details.
Polymorphic dope vectors are NPDope
N except for CLASS(*)
pointers which are CSDope
N.
struct
s.
If BIND(C)
or SEQUENCE
is used, the order of the items within the
struct is the same as the order within the derived type definition.
Otherwise, the order of items is permuted to put larger types at the front of
the struct so as to improve alignment and reduce storage; the C output code
can be inspected to determine the ordering used.
Char
unsigned char
Char2
unsigned short
Char4
unsigned int
Substring
struct { Char *addr; Chrlen len;}
CHARACTER
string; used for
deferred-length default CHARACTER
variables and as the return
type of variable-length scalar non-POINTER
default CHARACTER
functions and all POINTER
default CHARACTER
functions.
Substring2
struct { Char2 *addr; Chrlen len;}
CHARACTER
string; used for
deferred-length 16-bit CHARACTER
variables and as the return
type of variable-length scalar non-POINTER
16-bit CHARACTER
functions and all POINTER
16-bit CHARACTER
functions.
Substring4
struct { Char4 *addr; Chrlen len;}
CHARACTER
string; used for
deferred-length 32-bit CHARACTER
variables and as the return
type of variable-length scalar non-POINTER
UCS-4 CHARACTER
functions and all POINTER
UCS-4 CHARACTER
functions.
Offset
int
, long
or long long
int
(32-bit) on 32-bit systems and small model 64-bit systems, and a 64-bit integer
type on large model 64-bit systems.
Chrlen
int
, or long long
on 64-bit Windows.
Pointer
char *
.
Triplet
struct { Offset extent,mult,lower;}
extent
is the
size of that dimension, mult
is the stride (i.e., the distance
between successive elements in bytes) and lower
is the lower
bound. It is a component of the Dope
N and
ChDope
N structs.
Dope
Nstruct { Pointer addr; Offset offset; Triplet dim[N];}
CHARACTER
arrays (including
arrays of derived type). N is the rank and is from 1 to 7. addr
is
the address of the first element, dim
describes each dimension
and offset
is the offset to add to the subscript calculation,
i.e., SUM(mult*lower)
. This is used as the return type
for POINTER
array functions; a pointer to it is used as the
argument type for assumed-shape and POINTER
array arguments.
An array pointer which has been nullified has an addr
field which is
a null pointer; note that zero-sized arrays have an addr
field which
is not a null pointer.
ChDope
Nstruct { Pointer addr; Chrlen len; Offset offset; Triplet dim[N];}
Dope
N structs with the addition
of the len
component which specifies the CHARACTER
length.
ArrayTemp_type
struct { type *addr; Offset extent[7];}
Integer1
,
Integer2
, Integer
, Integer4
, Logical1
,
Logical2
, Logical
, Logical4
, Real
, Double
,
QReal
, Complex
, DComplex
or QComplex
.
It is used as the return type for non-POINTER
array functions.
Note that extent
values after the rank of the array being described are
undefined.
ArrayTemp_Character
struct { Char *addr; Chrlen len; Offset extent[7];}
CHARACTER
array; it is the same as the other array
types with the addition of the len
component for the CHARACTER
length.
ArrayTemp_Derived
ArrayTemp_Character
.
len
field in this case is the size of the derived type array element.
int
; its value is the index of the label to which
control is to be transferred (1 for the first label, etc.).
Zero or an out-of-range value indicates no control transfer is to take place.
void
.
INTEGER
, LOGICAL
and REAL
.
COMPLEX
, -compatible option not used, and not Windows 64-bit mode.
Complex
or DComplex
according to the precision.
COMPLEX
, -compatible option used, or Windows 64-bit mode.
void
.
The address of a temporary of type Complex
or DComplex
is passed
as the initial argument of the function (the result is written to this
location).
CHARACTER
with fixed or assumed length.
void
.
Two additional initial arguments are passed to the function, the first
(Char*
, Char2*
or Char4*
) being the address to which the
result is to be written and the second (Chrlen
) being the length of the
result (in case the called function is of assumed length).
CHARACTER
with variable length.
Substring
, Substring2
or Substring4
(described above).
The called function allocates the storage for the string being returned; it is
the caller's responsibility to deallocate it when it is no longer required.
POINTER
functionsPOINTER
-valued functions the storage to which the
result points may have been allocated within the called function or the result
may point to pre-existing storage.
INTEGER
, LOGICAL
, REAL
and COMPLEX
.
Complex*
).
CHARACTER
Substring
, Substring2
or Substring4
.
POINTER
functionsArrayTemp_
struct for the intrinsic type, as described
above.
ArrayTemp_Derived
is returned with the len
component set to the
size of the derived-type struct.
POINTER
functionsCLASS(*)
CSDope1
, CSDope2
, ... or CSDope7
, depending on the rank of
the array.
CLASS(
derived-type-name)
NPDope1
, NPDope2
, ... or NPDope7
, depending on the rank of
the array.
CHARACTER
type.
Dope1
, Dope2
, ... or Dope7
, depending on the rank of the
array.
CHARACTER
.
ChDope1
, ChDope2
, ... or ChDope7
, depending on the rank of
the array.
Note that non-polymorphic derived-type arrays are returned as Dope
N
structs.
CHARACTER
typeCHARACTER
type, whether default CHARACTER
or multi-byte CHARACTER
, have an additional Chrlen
argument being the length of the CHARACTER
entity; this
additional argument is passed at the end of the argument list after
all the normal arguments. When there are several CHARACTER
arguments their lengths are passed in order from left to right.
This is except on 32-bit Windows when the -compatible option is
specified, the additional argument immediately follows the CHARACTER
argument.
The other exception to this rule is for assumed-shape CHARACTER
arrays;
in this case the
length of the dummy argument is taken directly from the field in the dope
vector and is not passed separately.
POINTER
non-ALLOCATABLE
ScalarCHARACTER
type.
Integer*
for an
INTEGER
argument).
CHARACTER
.
Chrlen
argument at the end of the
argument list.
POINTER
and ALLOCATABLE
ScalarInteger**
for an INTEGER POINTER
).
POINTER
ArrayCSDope
N*
, NPDope
N*
,
Dope
N*
or a ChDope
N*
,
depending on the polymorphism and type of the dummy argument). There is no
need for the array to be contiguous as long as it can be described by an array
section.
CHARACTER
arrays the length of each array element is passed as an
Chrlen
at the end of the argument list, the same as for scalars.
The array must be contiguous.
POINTER
ArrayCHARACTER
arrays the length is passed at the end as a separate
argument.
CHARACTER
functions have the length passed as a separate argument at
the end of the list; if the function is of variable length this length will
be negative.
OPTIONAL
argumentsOPTIONAL
argument is .NOT.PRESENT()
a null pointer of
the appropriate type is passed (e.g., for an INTEGER
scalar, an
(Integer*)0
is passed).