Accessing SIDL Arrays From FORTRAN 90

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.

The client-side interface for the solve example introduced in Section 5.4 behaves as if it is a FORTRAN 77 function with the following overloaded interface:


  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<double,2,column-major> A
    type(sidl_double_2d) , intent(in) :: A
    ! inout array<double,column-major> x
    type(sidl_double_1d) , intent(inout) :: x
    ! in array<double,column-major> 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<double,2> A(m,n)
    real (selected_real_kind(15, 307)) , intent(in), dimension(:, :) :: A
    ! inout rarray<double> x(n)
    real (selected_real_kind(15, 307)) , intent(inout), dimension(:) :: x
    ! in rarray<double> b(m)
    real (selected_real_kind(15, 307)) , intent(in), dimension(:) :: b
    ! details deleted
  end subroutine solve_2s

You can use either normal FORTRAN 90 arrays or normal SIDL arrays when calling a FORTRAN 90 method, but you cannot use a mixture.

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


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

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 sidl.SIDLException, the array module is named sidl_SIDLException_array, and the array module is defined in the sidl_SIDLException_array.F90.

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.

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 sidl.SIDLException, the array derived types are named sidl_SIDLException_1d, sidl_SIDLException_2d, sidl_SIDLException_3d, $\ldots$ up to sidl_SIDLException_7d. For the basic types, they are treated as sidl.dcomplex, sidl.double, sidl.fcomplex, etc. Each of these derived types has a 64 bit integer to hold an opaque pointer.

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.


  type sidl_double_2d
    sequence
    integer (selected_int_kind(18)) :: d_array
    real (selected_real_kind(15, 307)), pointer, &
      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, &
      dimension(:,:,:) :: d_data
  end type sidl_double_3d

You can access the array with the F90 array pointer d_data just like any other F90 array. However, you must not use the F90 builtins allocate or deallocate on d_data. You must use SIDL functions createCol, createRow, create1d, create2dRow, create2dCol to create a new array. These SIDL routines initialize d_data to refer to the data allocated in d_array.

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 stride(i), which indicates the distance between elements in dimension i. A value of 1 means elements are packed densely in dimension i. Negative stride values are possible. When an array is sliced, the resulting array might not even have one densely packed dimension.



babel-0.10.2
users_guide Last Modified 2005-03-23

http://www.llnl.gov/CASC/components
components@llnl.gov