File: node147.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 (241 lines) | stat: -rw-r--r-- 9,268 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
<!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>Accessing SIDL Arrays From FORTRAN 90</TITLE>
<META NAME="description" CONTENT="Accessing SIDL Arrays 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="previous" HREF="node146.html">
<LINK REL="up" HREF="node140.html">
<LINK REL="next" HREF="node148.html">
</HEAD>

<BODY >

<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html2900"
  HREF="node148.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2894"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2890"
  HREF="node146.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2896"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2898"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2901"
  HREF="node148.html">Java Bindings</A>
<B> Up:</B> <A NAME="tex2html2895"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2891"
  HREF="node146.html">Implementing Classes in FORTRAN</A>
 &nbsp; <B>  <A NAME="tex2html2897"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2899"
  HREF="node317.html">Index</A></B> 
<BR>
<BR></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION03470000000000000000"></A><A NAME="c:f90:arrayaccess"></A><A NAME="8158"></A>
<BR>
Accessing SIDL Arrays From FORTRAN 90
</H1>

<P>
SIDL r-arrays are passed to and from methods as normal FORTRAN 90
arrays. You do not need to include the index variables because the
values are determined from the FORTRAN 90 array extents in each
dimension.

<P>
The client-side interface for the <TT>solve</TT> example introduced in
Section&nbsp;<A HREF="node60.html#ss:r-arrays">5.4</A> behaves as if it is a FORTRAN 77 function
with the following overloaded interface:

<P>
<BR>
<PRE  CLASS="verbatim">  private :: solve_1s, solve_2s
  interface solve
    module procedure solve_1s, solve_2s
  end interface

  recursive subroutine solve_1s(self, A, x, b)
    implicit none
    type(num_Linsol_t) , intent(in) :: self ! in num.Linsol self
    ! in array&lt;double,2,column-major&gt; A
    type(sidl_double_2d) , intent(in) :: A
    ! inout array&lt;double,column-major&gt; x
    type(sidl_double_1d) , intent(inout) :: x
    ! in array&lt;double,column-major&gt; b
    type(sidl_double_1d) , intent(in) :: b
    ! details deleted
  end subroutine solve_1s

  recursive subroutine solve_2s(self, A, x, b)
    implicit none
    type(num_Linsol_t) , intent(in) :: self ! in num.Linsol self
    ! in rarray&lt;double,2&gt; A(m,n)
    real (selected_real_kind(15, 307)) , intent(in), dimension(:, :) :: A
    ! inout rarray&lt;double&gt; x(n)
    real (selected_real_kind(15, 307)) , intent(inout), dimension(:) :: x
    ! in rarray&lt;double&gt; b(m)
    real (selected_real_kind(15, 307)) , intent(in), dimension(:) :: b
    ! details deleted
  end subroutine solve_2s
</PRE></td></tr></table></blockquote>
<P>
You can use either normal FORTRAN 90 arrays or normal SIDL arrays when
calling a FORTRAN 90 method, but you cannot use a mixture.

<P>
The server-side interface for <TT>solve</TT> is similar. Note, the lower
index each dimension of every incoming array is always zero.

<P>
<BR>
<PRE  CLASS="verbatim">recursive subroutine num_Linsol_solve_mi(self, A, x, b, m, n)
  use num_Linsol
  use sidl_double_array
  use num_Linsol_impl
  ! DO-NOT-DELETE splicer.begin(num.Linsol.solve.use)
  ! DO-NOT-DELETE splicer.end(num.Linsol.solve.use)
  implicit none
  type(num_Linsol_t) :: self ! in
  integer (selected_int_kind(9)) :: m ! in
  integer (selected_int_kind(9)) :: n ! in
  real (selected_real_kind(15, 307)), dimension(0:m-1, 0:n-1) :: A ! in
  real (selected_real_kind(15, 307)), dimension(0:n-1) :: x ! inout
  real (selected_real_kind(15, 307)), dimension(0:m-1) :: b ! in

! DO-NOT-DELETE splicer.begin(num.Linsol.solve)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(num.Linsol.solve)
end subroutine num_Linsol_solve_mi
</PRE></td></tr></table></blockquote>
<P>
For normal SIDL arrays, the normal SIDL C function API is available
from FORTRAN 90 to create, destroy, and access array elements and
meta-data. The array routines are in a module. For
<TT><I CLASS="slanted">sidl.SIDLException</I></TT>, the array module is named
<TT>sidl_SIDLException_array</TT>, and the array module is defined in
the <TT>sidl_SIDLException_array.F90</TT>.

<P>
For SIDL types dcomplex, double, fcomplex , float, int, and long, 
SIDL provides an array pointer to get direct access to the array elements. 
For the other types, you must use the functional API to access array
elements.

<P>
The SIDL derived type for a SIDL array is named after the class,
interface or basic type that it holds and the dimension of the
array. For <TT><I CLASS="slanted">sidl.SIDLException</I></TT>, the array derived types are
named <TT>sidl_SIDLException_1d</TT>, <TT>sidl_SIDLException_2d</TT>,
<TT>sidl_SIDLException_3d</TT>, <SPAN CLASS="MATH"><IMG
 WIDTH="22" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="img25.png"
 ALT="$\ldots$"></SPAN> up to
<TT>sidl_SIDLException_7d</TT>. For the basic types, they are treated
as <TT><I CLASS="slanted">sidl.dcomplex</I></TT>, <TT><I CLASS="slanted">sidl.double</I></TT>, <TT><I CLASS="slanted">sidl.fcomplex</I></TT>,
etc. Each of these derived types has a 64 bit integer to hold an
opaque pointer.

<P>
The derived type for SIDL types dcomplex, double, fcomplex , float,
int, and long also has a pointer to an array of the appropriate type
and dimension. For example, here is the derived type for 2d and 3d
arrays of doubles.

<P>
<BR>
<PRE  CLASS="verbatim">  type sidl_double_2d
    sequence
    integer (selected_int_kind(18)) :: d_array
    real (selected_real_kind(15, 307)), pointer, &amp;
      dimension(:,:) :: d_data
  end type sidl_double_2d

  type sidl_double_3d
    sequence
    integer (selected_int_kind(18)) :: d_array
    real (selected_real_kind(15, 307)), pointer, &amp;
      dimension(:,:,:) :: d_data
  end type sidl_double_3d
</PRE></td></tr></table></blockquote>
<P>
You can access the array with the F90 array pointer <TT>d_data</TT>
just like any other F90 array. However, you <EM>must not</EM> use the F90
builtins <TT>allocate</TT> or <TT>deallocate</TT> on <TT>d_data</TT>. You
must use SIDL functions <TT>createCol</TT>, <TT>createRow</TT>,
<TT>create1d</TT>, <TT>create2dRow</TT>, <TT>create2dCol</TT> to create a
new array. These SIDL routines initialize <TT>d_data</TT> to refer to
the data allocated in <TT>d_array</TT>.

<P>
You can call things like LINPACK or BLAS if you want, 
but you should check the stride to make sure the array 
is packed as needed.  You can check 
<TT>stride(i)</TT>, which indicates the distance between elements in dimension 
<TT>i</TT>. 
A value of 1 means elements are packed densely in dimension <TT>i</TT>. 
Negative stride values are possible. When an array is sliced, the
resulting array might not even have one densely packed dimension.

<P>

<P>

<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html2900"
  HREF="node148.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html2894"
  HREF="node140.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html2890"
  HREF="node146.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html2896"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html2898"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2901"
  HREF="node148.html">Java Bindings</A>
<B> Up:</B> <A NAME="tex2html2895"
  HREF="node140.html">FORTRAN 90 Bindings</A>
<B> Previous:</B> <A NAME="tex2html2891"
  HREF="node146.html">Implementing Classes in FORTRAN</A>
 &nbsp; <B>  <A NAME="tex2html2897"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html2899"
  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>