File: node146.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 (261 lines) | stat: -rw-r--r-- 9,857 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
253
254
255
256
257
258
259
260
261
<!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>Implementing Classes in FORTRAN 90</TITLE>
<META NAME="description" CONTENT="Implementing Classes in 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="node147.html">
<LINK REL="previous" HREF="node145.html">
<LINK REL="up" HREF="node140.html">
<LINK REL="next" HREF="node147.html">
</HEAD>

<BODY >

<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html2888"
  HREF="node147.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2882"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2876"
  HREF="node145.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2884"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2886"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2889"
  HREF="node147.html">Accessing SIDL Arrays From</A>
<B> Up:</B> <A NAME="tex2html2883"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2877"
  HREF="node145.html">Invoking Babel to Generate</A>
 &nbsp; <B>  <A NAME="tex2html2885"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2887"
  HREF="node317.html">Index</A></B> 
<BR>
<BR></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION03460000000000000000"></A>
<A NAME="8125"></A>
<BR>
Implementing Classes in FORTRAN 90
</H1>

<P>
Much of the information from the previous section is 
pertinent to implementing a SIDL class in FORTRAN 90. 
The types of the arguments are as indicated in Table&nbsp;<A HREF="node142.html#tbl:f90:types">9.1</A>.
Your implementation can call other SIDL methods in which case follow 
the rules for client calls.

<P>
You should invoke Babel:
<BLOCKQUOTE>
<TT> <TT>%</TT> <TT><B>babel -server=f90 file.sidl</B></TT>
<BR>
</TT></BLOCKQUOTE>or simply
<BLOCKQUOTE>
<TT> <TT>%</TT> <TT><B>babel -s=f90 file.sidl</B></TT>
<BR>
</TT></BLOCKQUOTE>
<P>
This will create a babel.make, numerous C headers, numerous C source
files and some FORTRAN 90 source files.  Your job is to fill in the
FORTRAN 90 source files with the implementation of the methods.  The
files you need to edit all end with <TT>_Impl.F90</TT> and
<TT>_Mod.F90</TT>.  All your changes to the file should be made between
code splicer pairs.  Code between splicer pairs is retained by
subsequent invocations of Babel; code outside splicer pairs is not.

<P>
Here is an example of the standard code splicer pairs in generated FORTRAN 90 
code.  You would replace the comment "Insert extra code here... " associated
with the "miscellaneous code start" splicer pair with code needed for your 
implementation such as additional abbreviation file(s) and any local, or 
private, subroutines.  For the subroutine's "use" splicer pair, you would 
replace the "Insert use statements here..." comment with any use statements 
that are needed by the subroutine.  Finally, you would add the implementation 
between the subroutine body's splicer pairs in the place of the "Insert the 
implementation here..." comment.

<P>
<BR>
<PRE  CLASS="verbatim">! DO-NOT-DELETE splicer.begin(_miscellaneous_code_start)
! Insert extra code here...
! DO-NOT-DELETE splicer.end(_miscellaneous_code_start)

.
.
.

subroutine Pkg_Class_name_mi(args)
  ! DO-NOT-DELETE splicer.begin(Pkg.Class.name.use)
  ! Insert use statements here...
  ! DO-NOT_DELETE splicer.end(Pkg.Class.name.use)
  implicit none
  integer (selected_int_kind(18)) :: arg

! DO-NOT-DELETE splicer.begin(Pkg.Class.name)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(Pkg.Class.name)
</PRE></td></tr></table></blockquote>
<P>
Each _Impl.F90 file contains numerous partially implemented subroutines. 
The <TT>SUBROUTINE</TT> and <TT>END SUBROUTINE</TT> statements have been generated 
and the types of the arguments declared.  As mentioned above, you must provide 
any needed use statements and the body of each subroutine to implement the 
expected behavior of the method.

<P>
There are two implicit methods (i.e., methods that did not appear in
the SIDL file) that must also be implemented if the object is to have
state (i.e., data associated with the instance).  The <TT>_ctor()</TT>
method is a constructor function that is run whenever an object is
created.  The <TT>_dtor()</TT> method is a destructor function that is
run whenever an object is destroyed.  If there is not state then these
functions are typically empty.

<P>
The SIDL IOR keeps a pointer for each object
that is intended to hold a pointer to the object's internal data.  The
FORTRAN 90 skeleton provides two functions that the FORTRAN 90
developer will need to use to access the private pointer.  The name of
the function is derived from the fully qualified type name by
replacing periods with underscores and appending
<TT>__get_data_m</TT> or <TT>__set_data_m</TT>.  The first
argument is the object pointer (i.e., self), and the second is a
derived type defined in the <TT>_Mod.F90</TT> file.   Here is an
excerpt from a <TT>_Mod.F90</TT> file for an object whose state requires a
single integer value.

<P>
<BR>
<PRE  CLASS="verbatim">#include"sort_SimpleCounter_fAbbrev.h"
module sort_SimpleCounter_impl

type sort_SimpleCounter_private
   sequence
  ! DO-NOT-DELETE splicer.begin(sort.SimpleCounter.private_data)
   integer(selected_int_kind(9)) :: count
  ! DO-NOT-DELETE splicer.end(sort.SimpleCounter.private_data)
end type sort_SimpleCounter_private

type sort_SimpleCounter_wrap
   sequence
   type(sort_SimpleCounter_private), pointer :: d_private_data
end type sort_SimpleCounter_wrap

end module sort_SimpleCounter_impl
</PRE></td></tr></table></blockquote>
<P>
The derived type <TT>sort_SimpleCounter_private</TT> is the type where
the developer adds data to store the object's state, and
<TT>sort_SimpleCounter_wrap</TT> exists simply to facilitate transferring
the pointer to a
<BR><TT>sort_SimpleCounter_private</TT> to and from the
IOR. 

<P>
<A NAME="8148"></A>
Typically for a class with state, the developer needs to
<TT>allocate(pd%d_private_data)</TT> in the constructor, <TT>_ctor</TT>,
and <TT>deallocate(pd%d_private_data)</TT> in the destructor,
<TT>_dtor</TT>. Here is a concrete example of a constructor.

<P>
<BR>
<PRE  CLASS="verbatim">recursive subroutine sort_SimpleCounter__ctor_mi(self)
  use sort_SimpleCounter
  use sort_SimpleCounter_private
  ! DO-NOT-DELETE splicer.begin(sort.SimpleCounter._ctor.use)
  ! DO-NOT-DELETE splicer.end(sort.SimpleCounter._ctor.use)
  implicit none
  type(sort_SimpleCounter_t) :: self

! DO-NOT-DELETE splicer.begin(sort.SimpleCounter._ctor)
  type(sort_SimpleCounter_wrap) :: dp
  allocate(dp%d_private_data)
  dp%d_private_data%count = 0
  call sort_SimpleCounter__set_data_m(self, dp)
! DO-NOT-DELETE splicer.end(sort.SimpleCounter._ctor)
end subroutine sort_SimpleCounter__ctor_mi
</PRE></td></tr></table></blockquote>
<P>
Here is the corresponding destructor.
<A NAME="8154"></A>

<P>
<BR>
<PRE  CLASS="verbatim">recursive subroutine sort_SimpleCounter__dtor_mi(self)
  use sort_SimpleCounter
  use sort_SimpleCounter_private
  ! DO-NOT-DELETE splicer.begin(sort.SimpleCounter._dtor.use)
  ! DO-NOT-DELETE splicer.end(sort.SimpleCounter._dtor.use)
  implicit none
  type(sort_SimpleCounter_t) :: self

! DO-NOT-DELETE splicer.begin(sort.SimpleCounter._dtor)
  type(sort_SimpleCounter_wrap) :: dp
  call sort_SimpleCounter__get_data_m(self, dp)
  deallocate(dp%d_private_data)
! DO-NOT-DELETE splicer.end(sort.SimpleCounter._dtor)
end subroutine sort_SimpleCounter__dtor_mi
</PRE></td></tr></table></blockquote>
<P>

<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html2888"
  HREF="node147.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2882"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2876"
  HREF="node145.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2884"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2886"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2889"
  HREF="node147.html">Accessing SIDL Arrays From</A>
<B> Up:</B> <A NAME="tex2html2883"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2877"
  HREF="node145.html">Invoking Babel to Generate</A>
 &nbsp; <B>  <A NAME="tex2html2885"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2887"
  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>