next up previous contents
Next: Java Bindings Up: FORTRAN 90 Bindings Previous: Implementing Classes in FORTRAN   Contents

Accessing SIDL Arrays From FORTRAN 90

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.BaseException, the array module is name SIDL_BaseException_array, and the array module is defined in the SIDL_BaseException_array.F90.

For SIDL types dcomplex, double, fcomplex , float, int, and long, SIDL provides a method to get direct access to the array elements. For the other types, you must use the functional API to access array elements.

In the module for a base types, for example, there is a FORTRAN 90 function called access to provide a method to get direct access. This is illustrated in the example below. Of course, this will not work if your FORTRAN 90 compiler does array bounds checking.


  type(SIDL_int_a) :: intarray
  integer (selected_int_kind(9))  :: lower(1), upper(1), stride(1), i, index(1)
  integer (selected_int_kind(9))  :: value, refindex, refarray(1), modval
  integer (selected_int_kind(18)) :: nextprime, tmp
  lower(1) = 0
  value    = 0
  upper(1) = len - 1
  call createCol(lower, upper, intarray) ! dimension determined by lower
  call access(intarray, refarray, lower, upper, stride, refindex)
  do i = 0, len - 1
    tmp    = value
    value  = nextprime(tmp)
    modval = mod(i, 3)
    if (modval .eq. 0) then
      call set(intarray, i, value)
    else
      if (modval .eq. 1) then
         index(1) = i
         call set(intarray, index, value)
      else
        !
        ! equivalent to the set(intarray, index, value)
        !
        refarray(refindex + stride(1)*(i - lower(1))) = value
      endif
    endif
  enddo

To access a two dimensional array, the expression referring to element i, j is


  refarray(refindex + stride(1) * (i - lower(1)) + stride(2) * (j - lower(2))    

To access a three dimensional array, the expression referring to element i, j, k is


  refarray(refindex + stride(1) * (i - lower(1)) + stride(2) * (j - lower(2)) + stride(3) * (k - lower(3))

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, and when an array is a slice of another array, there may be no dimension with a stride of 1.

For a dcomplex array, the reference array should be a FORTRAN array of REAL (SELECTED_REAL_KIND(15, 307)) instead of a FORTRAN array of double complex to avoid potential alignment problems. For a fcomplex array, the reference array is a COMPLEX (SELECTED_REAL_KIND(15, 307)) because we don't anticipate an alignment problem in this case.


next up previous contents
Next: Java Bindings Up: FORTRAN 90 Bindings Previous: Implementing Classes in FORTRAN   Contents


babel-0.8.4
users_guide Last Modified 2003-04-03

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