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
|
<!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>FORTRAN 77 objects with state</TITLE>
<META NAME="description" CONTENT="FORTRAN 77 objects with state">
<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="previous" HREF="node138.html">
<LINK REL="up" HREF="node131.html">
<LINK REL="next" HREF="node140.html">
</HEAD>
<BODY >
<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html2783"
HREF="node140.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2777"
HREF="node131.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2773"
HREF="node138.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2779"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html2781"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2784"
HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Up:</B> <A NAME="tex2html2778"
HREF="node131.html">FORTRAN 77 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2774"
HREF="node138.html">Accessing SIDL Arrays From</A>
<B> <A NAME="tex2html2780"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html2782"
HREF="node317.html">Index</A></B>
<BR>
<BR></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION03380000000000000000"></A><A NAME="sec:F77:state"></A><A NAME="7349"></A>
<BR>
FORTRAN 77 objects with state
</H1>
<P>
If you need to implement a FORTRAN 77 class with state, you can use
SIDL arrays to store the state information. This is certainly not the
only way to implement a FORTRAN 77 class with state, but it's one
that will work wherever Babel works. For example, if you have a class
whose state requires three boolean variables and two double precision
variables, your constructor might look something like the following:
<P>
<BR>
<PRE CLASS="verbatim"> subroutine example_withState__ctor_fi(self)
implicit none
integer*8 self
C DO-NOT-DELETE splicer.begin(example.withState._ctor)
integer*8 statearray, logarray, dblarray
call sidl_opaque__array_create1d_f(2, statearray)
call sidl_bool__array_create1d_f(3, logarray)
call sidl_double__array_create1d_f(2, dblarray)
if ((statearray .ne. 0) .and. (logarray .ne. 0) .and.
$ (dblarray .ne. 0)) then
call sidl_opaque__array_set1_f(statearray, 0, logarray)
call sidl_opaque__array_set1_f(statearray, 1, dblarray)
else
C a real implementation would not leak memory like this one
statearray = 0
endif
call example_withState__set_data_f(self, statearray)
C DO-NOT-DELETE splicer.end(example.withState._ctor)
end
</PRE></td></tr></table></blockquote>
<P>
Of course, it is up to your application make the association between
elements of the arrays and particular state variables. For example,
you could say that element 0 of the double array is the kinematic
viscosity and element 1 could be the airspeed velocity of an unladen
swallow.<A NAME="7351"></A> Element 0 of the boolean array could specify African (true) or
European (false). The destructor for this class could look something
like this:
<P>
<BR>
<PRE CLASS="verbatim"> subroutine example_withState__dtor_fi(self)
implicit none
integer*8 self
C DO-NOT-DELETE splicer.begin(example.withState._dtor)
integer*8 statearray, logarray, dblarray
call example_withState__get_data_f(self, statearray)
if (statearray .ne. 0) then
call sidl_opaque__array_get1_f(statearray, 0, logarray)
call sidl_opaque__array_get1_f(statearray, 1, dblarray)
call sidl_bool__array_deleteRef_f(logarray)
call sidl_double__array_deleteRef_f(dblarray)
call sidl_opaque__array_deleteRef_f(statearray)
C the following two lines are not strictly necessary
statearray = 0
call example_withState__set_data_f(self, statearray)
endif
C DO-NOT-DELETE splicer.end(example.withState._dtor)
end
</PRE></td></tr></table></blockquote>
<P>
In this example, an accessor function for the airspeed velocity of an
unladen swallow could be implemented as follows:
<P>
<BR>
<PRE CLASS="verbatim"> subroutine example_withState_getAirspeedVelocity_fi(
$ self, velocity)
implicit none
integer*8 self
real*8 velocity
C DO-NOT-DELETE splicer.begin(example.withState.getAirspeedVelocity)
integer*8 statearray, dblarray
call example_withState__get_data_f(self, statearray)
if (statearray .ne. 0) then
call sidl_opaque__array_get1_f(statearray, 1, dblarray)
call sidl_double__array_get1_f(dblarray, 1, velocity)
endif
C DO-NOT-DELETE splicer.end(example.withState.getAirspeedVelocity)
end
</PRE></td></tr></table></blockquote>
<P>
<P>
<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html2783"
HREF="node140.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2777"
HREF="node131.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2773"
HREF="node138.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2779"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html2781"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2784"
HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Up:</B> <A NAME="tex2html2778"
HREF="node131.html">FORTRAN 77 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2774"
HREF="node138.html">Accessing SIDL Arrays From</A>
<B> <A NAME="tex2html2780"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html2782"
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>
|