File: node143.html

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (252 lines) | stat: -rw-r--r-- 9,402 bytes parent folder | download | duplicates (2)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Calling Methods From FORTRAN 90</TITLE>
<META NAME="description" CONTENT="Calling Methods From FORTRAN 90">
<META NAME="keywords" CONTENT="users_guide">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<LINK REL="STYLESHEET" HREF="users_guide.css">

<LINK REL="next" HREF="node144.html">
<LINK REL="previous" HREF="node142.html">
<LINK REL="up" HREF="node140.html">
<LINK REL="next" HREF="node144.html">
</HEAD>

<BODY >

<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html2846"
  HREF="node144.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2840"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2834"
  HREF="node142.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2842"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2844"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2847"
  HREF="node144.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html2841"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2835"
  HREF="node142.html">Basic Types</A>
 &nbsp; <B>  <A NAME="tex2html2843"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2845"
  HREF="node317.html">Index</A></B> 
<BR>
<BR></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION03430000000000000000"></A>
<A NAME="8047"></A>
<BR>
Calling Methods From FORTRAN 90
</H1>

<P>
All SIDL methods are implemented as <A NAME="8048"></A>FORTRAN 90 subroutines regardless
of whether they have a return value or not.  For object methods, the
object or interface pointer is passed as the first argument to the
subroutine before all the formally declared arguments.  The exception
is static methods, where the object or interface pointer does not
appear in the argument list at all.

<P>
When a method has a return value, a variable to hold the return value
should be passed as an argument following the formally declared
arguments.

<P>
The name of the module that holds the method definitions is derived
from the fully qualified name of the class or interface. You can
generate the module name by replacing all the periods with
underscores. For example, the methods for <TT><I CLASS="slanted">sidl.SIDLException</I></TT>
are defined in a module named <TT>sidl_SIDLException</TT> in the file
<TT>sidl_SIDLException.F90</TT>. The name of the module holding the
derived type of the class or interface is the same as the one holding
the methods except that it has <TT>_type</TT> appended to it. The types
for <TT><I CLASS="slanted">sidl.SIDLException</I></TT> are called <TT>sidl_SIDLException_t</TT>
and <TT>sidl_SIDLException_a</TT>, for the array, and they are defined
in the file <TT>sidl_SIDLException_type.F90</TT>.

<P>
The name of the subroutine that FORTRAN 90 clients is the method's
full name from the SIDL description. If the method is specified as
overloaded (i.e., has a name extension), the method's full name will
be used.  That is, the concatenation of the short name and the name
extension will be used for a unique method name.

<P>
For example, to call the <TT>deleteRef()</TT> method on a 
<TT><I CLASS="slanted">SIDL.BaseInterface</I></TT> interface, you would write:

<P>
<BR>
<PRE  CLASS="verbatim">  use sidl_BaseInterface
  type(sidl_BaseInterface_t) :: interface1, interface2
  logical                    :: areSame
  !
  ! code to initialize interface1 &amp; interface 2 here
  !
  call deleteRef(interface1)
</PRE></td></tr></table></blockquote>
<P>
To call the isSame method on a <TT><I CLASS="slanted">sidl.BaseInterface</I></TT>, you would write:

<P>
<BR>
<PRE  CLASS="verbatim">  use sidl_BaseInterface
  ! later in the code
  call isSame(interface1, interface2, areSame)
  ! areSame holds the return value
</PRE></td></tr></table></blockquote>
<P>
To call the queryInt method on a <TT><I CLASS="slanted">sidl.BaseInterface</I></TT>, you would write:

<P>
<BR>
<PRE  CLASS="verbatim">  use sidl_BaseInterface
  ! later
  call queryInt(interface1, 'My.Interface.Name', interface2)
  ! interface2 holds the return value now
</PRE></td></tr></table></blockquote>
<P>
<A NAME="8064"></A>
Examples of calls to SIDL overloaded methods are based on the 
<TT>overload_sample.sidl</TT> file shown in Section&nbsp;<A HREF="node107.html#sec:overloading">5.6</A>.  
Recall that the file describes three versions of the <TT>getValue</TT> method.  
The first takes no arguments, the second takes an integer argument, and the 
third takes a boolean.  Each is called in the code snippet below:

<P>
<BR>
<PRE  CLASS="verbatim">  use Overload_Sample
  type(Overload_Sample_t)         :: t
  logical                         :: b1, bretval
  integer (selected_int_kind(9))  :: i1, iretval

  call new(t)

  call getValue (t, iretval)
  call getValueInt (t, i1, iretval)
  call getValueBool (t, b1, bretval)
</PRE></td></tr></table></blockquote>
<P>
Here is an example of what Babel will produce for an enumerated type
with some of the whitespace and comments reduced for brevity.

<P>
<BR>
<PRE  CLASS="verbatim">! File:          enums_car.F90
! Symbol:        enums.car-v1.0
! Symbol Type:   enumeration
! Babel Version: 0.8.2
! Description:   Client-side module for enums.car
 
module enums_car
! Symbol "enums.car" (version 1.0)

  integer (selected_int_kind(9)), parameter :: porsche = 911
  integer (selected_int_kind(9)), parameter :: ford = 150
  integer (selected_int_kind(9)), parameter :: mercedes = 550
end module enums_car
</PRE></td></tr></table></blockquote>
<P>
For interfaces and classes, there is an implicit method called
<A NAME="8070"></A><TT>cast()</TT>.  There are actually a set of overloaded methods that
support every allowable cast between a type an all its parent types
(objects and interfaces). The first argument is the object/interface
to be cast, and the second argument is a variable of the desired
type. If the value of the second argument after the call is
<TT>not_null</TT>, the cast was successful; otherwise, the cast failed.
<TT>cast()</TT> is similar to the queryInt method in
<TT><I CLASS="slanted">sidl.BaseInterface</I></TT> except it does not increment the reference
count of the return object or interface, and it may return an object
or an interface pointer.  The <TT>queryInt()</TT> method always returns
an interface pointer.

<P>
For non-abstract classes, there is an implicit method called
<A NAME="8076"></A> <TT>new()</TT>. 
It creates and returns an instance of the class.

<P>
Here are examples of the use of these two methods:

<P>
<BR>
<PRE  CLASS="verbatim">  use sidl_BaseClass
  use sidl_BaseInterface
  type(sidl_BaseClass_t)     :: object
  type(sidl_BaseInterface_t) :: interface
  ! perhaps other code here
  call new(object)
  call cast(object, interface)
</PRE></td></tr></table></blockquote>
<P>
Here is an example call to the <TT>addSearchPath()</TT>, a static
method, in the <TT><I CLASS="slanted">sidl.Loader</I></TT> class:

<P>
<BR>
<PRE  CLASS="verbatim">  use sidl_Loader
  ! later
  call addSearchPath('/try/looking/here')
      </PRE></td></tr></table></blockquote>
<P>
Your FORTRAN 90 must manage any object references created by the calls you make.

<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html2846"
  HREF="node144.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2840"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2834"
  HREF="node142.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2842"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2844"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2847"
  HREF="node144.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html2841"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2835"
  HREF="node142.html">Basic Types</A>
 &nbsp; <B>  <A NAME="tex2html2843"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2845"
  HREF="node317.html">Index</A></B> </DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<br><br>babel-0.10.2<br>users_guide Last Modified 2005-03-23<br><br><a href="http://www.llnl.gov/CASC/components">http://www.llnl.gov/CASC/components</a><br><a href="mailto:components@llnl.gov">components@llnl.gov</a>
</ADDRESS>
</BODY>
</HTML>