1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Interfacing with Fortran</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-B-4.html">Previous</A> <A HREF="AA-C.html">Next</A></P>
<HR>
<H1> B.5 Interfacing with Fortran</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> <A NAME="I6582"></A><A NAME="I6583"></A>The facilities
relevant to interfacing with the Fortran language are the package Interfaces.Fortran
and support for the Import, Export and Convention pragmas with <I>convention</I>_<FONT FACE="Arial, Helvetica">identifier</FONT>
Fortran.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> The package Interfaces.Fortran defines Ada types
whose representations are identical to the default representations of
the Fortran intrinsic types Integer, Real, Double Precision, Complex,
Logical, and Character in a supported Fortran implementation. These Ada
types can therefore be used to pass objects between Ada and Fortran programs.
</DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> The library package
Interfaces.Fortran has the following declaration: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Ada.Numerics.Generic_Complex_Types; <I>-- see <A HREF="AA-G-1-1.html">G.1.1</A></I><BR>
<B>pragma</B> Elaborate_All(Ada.Numerics.Generic_Complex_Types);<BR>
<B>package</B> Interfaces.Fortran <B>is</B><A NAME="I6584"></A><A NAME="I6585"></A><A NAME="I6586"></A><BR>
<B>pragma</B> Pure(Fortran);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6587"></A><A NAME="I6588"></A>Fortran_Integer <B>is</B> <B>range</B> <I>implementation-defined</I>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6589"></A><A NAME="I6590"></A>Real <B>is</B> <B>digits</B> <I>implementation-defined</I>;<BR>
<B>type</B> <A NAME="I6591"></A><A NAME="I6592"></A>Double_Precision <B>is</B> <B>digits</B> <I>implementation-defined</I>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6593"></A><A NAME="I6594"></A>Logical <B>is</B> <B>new</B> Boolean;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Examples"><TT> <B>package</B> <A NAME="I6595"></A>Single_Precision_Complex_Types <B>is</B><BR>
<B>new</B> Ada.Numerics.Generic_Complex_Types (Real);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6596"></A><A NAME="I6597"></A>Complex <B>is</B> <B>new</B> Single_Precision_Complex_Types.Complex;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Examples"><TT> <B>subtype</B> <A NAME="I6598"></A>Imaginary <B>is</B> Single_Precision_Complex_Types.Imaginary;<BR>
<A NAME="I6599"></A>i : Imaginary <B>renames</B> Single_Precision_Complex_Types.i;<BR>
<A NAME="I6600"></A>j : Imaginary <B>renames</B> Single_Precision_Complex_Types.j;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6601"></A><A NAME="I6602"></A>Character_Set <B>is</B> <I>implementation-defined character type</I>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> <A NAME="I6603"></A><A NAME="I6604"></A>Fortran_Character <B>is</B> <B>array</B> (Positive <B>range</B> <>) <B>of</B> Character_Set;<BR>
<B>pragma</B> Pack (Fortran_Character);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Examples"><TT> <B>function</B> <A NAME="I6605"></A><A NAME="I6606"></A>To_Fortran (Item : <B>in</B> Character) <B>return</B> Character_Set;<BR>
<B>function</B> <A NAME="I6607"></A><A NAME="I6608"></A>To_Ada (Item : <B>in</B> Character_Set) <B>return</B> Character;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Examples"><TT> <B>function</B> <A NAME="I6609"></A><A NAME="I6610"></A>To_Fortran (Item : <B>in</B> String) <B>return</B> Fortran_Character;<BR>
<B>function</B> <A NAME="I6611"></A><A NAME="I6612"></A>To_Ada (Item : <B>in</B> Fortran_Character) <B>return</B> String;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Examples"><TT> <B>procedure</B> <A NAME="I6613"></A><A NAME="I6614"></A>To_Fortran (Item : <B>in</B> String;<BR>
Target : <B>out</B> Fortran_Character;<BR>
Last : <B>out</B> Natural);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Examples"><TT> <B>procedure</B> <A NAME="I6615"></A><A NAME="I6616"></A>To_Ada (Item : <B>in</B> Fortran_Character;<BR>
Target : <B>out</B> String;<BR>
Last : <B>out</B> Natural);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Examples"><TT><B>end</B> Interfaces.Fortran;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B><U>The
types Fortran_Integer, Real, Double_Precision, and Character_Set in Interfaces.Fortran.</U></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The means
by which the Complex type is provided in Interfaces.Fortran creates a
dependence of Interfaces.Fortran on Numerics.Generic_Complex_Types (see
<A HREF="AA-G-1-1.html">G.1.1</A>). This dependence is intentional and
unavoidable, if the Fortran-compatible Complex type is to be useful in
Ada code without duplicating facilities defined elsewhere. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal"> The types Fortran_Integer, Real, Double_Precision,
Logical, Complex, and Fortran_Character are Fortran-compatible.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Normal"> The To_Fortran and To_Ada functions map between
the Ada type Character and the Fortran type Character_Set, and also between
the Ada type String and the Fortran type Fortran_Character. The To_Fortran
and To_Ada procedures have analogous effects to the string conversion
subprograms found in Interfaces.COBOL. </DIV>
<H4 ALIGN=CENTER>Implementation Requirements</H4>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Normal"> An implementation shall support <FONT FACE="Arial, Helvetica">pragma</FONT>
Convention with a Fortran <I>convention</I>_<FONT FACE="Arial, Helvetica">identifier</FONT>
for a Fortran-eligible type (see <A HREF="AA-B-1.html">B.1</A>). </DIV>
<H4 ALIGN=CENTER>Implementation Permissions</H4>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Normal"> An implementation may add additional declarations
to the Fortran interface packages. For example, the Fortran interface
package for an implementation of Fortran 77 (ANSI X3.9-1978) that defines
types like Integer*<I>n</I>, Real*<I>n</I>, Logical*<I>n</I>, and Complex*<I>n</I>
may contain the declarations of types named Integer_Star_<I>n</I>, Real_Star_<I>n</I>,
Logical_Star_<I>n</I>, and Complex_Star_<I>n</I>. (This convention should
not apply to Character*<I>n</I>, for which the Ada analog is the constrained
array subtype Fortran_Character (1..<I>n</I>).) Similarly, the Fortran
interface package for an implementation of Fortran 90 that provides multiple
<I>kinds</I> of intrinsic types, e.g. Integer (Kind=<I>n</I>), Real (Kind=<I>n</I>),
Logical (Kind=<I>n</I>), Complex (Kind=<I>n</I>), and Character (Kind=<I>n</I>),
may contain the declarations of types with the recommended names Integer_Kind_<I>n</I>,
Real_Kind_<I>n</I>, Logical_Kind_<I>n</I>, Complex_Kind_<I>n</I>, and
Character_Kind_<I>n</I>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Implementations
may add auxiliary declarations as needed to assist in the declarations
of additional Fortran-compatible types. For example, if a double precision
complex type is defined, then Numerics.Generic_Complex_Types may be instantiated
for the double precision type. Similarly, if a wide character type is
defined to match a Fortran 90 wide character type (accessible in Fortran
90 with the Kind modifier), then an auxiliary character set may be declared
to serve as its component type. </FONT></DIV>
<H4 ALIGN=CENTER>Implementation Advice</H4>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> An Ada implementation
should support the following interface correspondences between Ada and
Fortran: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>An Ada procedure corresponds to a Fortran subroutine.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>An Ada function corresponds to a Fortran function.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>An Ada parameter of an elementary, array, or record type
T is passed as a T<SUB><FONT SIZE=+1><FONT SIZE=-2>F</FONT></FONT></SUB>
argument to a Fortran procedure, where T<SUB><FONT SIZE=+1><FONT SIZE=-2>F</FONT></FONT></SUB>
is the Fortran type corresponding to the Ada type T, and where the INTENT
attribute of the corresponding dummy argument matches the Ada formal
parameter mode; the Fortran implementation's parameter passing conventions
are used. For elementary types, a local copy is used if necessary to
ensure by-copy semantics.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>An Ada parameter of an access-to-subprogram type is passed
as a reference to a Fortran procedure whose interface corresponds to
the designated subprogram's specification. </LI></UL>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>17 An object of a Fortran-compatible
record type, declared in a library package or subprogram, can correspond
to a Fortran common block; the type also corresponds to a Fortran ``derived
type''. </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Example of Interfaces.Fortran:</I>
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Interfaces.Fortran;<BR>
<B>use</B> Interfaces.Fortran;<BR>
<B>procedure</B> Ada_Application <B>is</B></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<DIV Class="Examples"><TT> <B>type</B> Fortran_Matrix <B>is</B> <B>array</B> (Integer <B>range</B> <>,<BR>
Integer <B>range</B> <>) <B>of</B> Double_Precision;<BR>
<B>pragma</B> Convention (Fortran, Fortran_Matrix); <I>-- stored in Fortran's</I><BR>
<I>-- column-major order</I><BR>
<B>procedure</B> Invert (Rank : <B>in</B> Fortran_Integer; X : <B>in</B> <B>out</B> Fortran_Matrix);<BR>
<B>pragma</B> Import (Fortran, Invert); <I>-- a Fortran subroutine</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<DIV Class="Examples"><TT> Rank : <B>constant</B> Fortran_Integer := 100;<BR>
My_Matrix : Fortran_Matrix (1 .. Rank, 1 .. Rank);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<DIV Class="Examples"><TT><B>begin</B></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<DIV Class="Examples"><TT> ...<BR>
My_Matrix := ...;<BR>
...<BR>
Invert (Rank, My_Matrix);<BR>
...</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<DIV Class="Examples"><TT><B>end</B> Ada_Application;</TT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-B-4.html">Previous</A> <A HREF="AA-C.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|