next up previous contents
Next: FORTRAN 77 objects with Up: FORTRAN 77 Bindings Previous: Implementing Classes in FORTRAN   Contents

Accessing SIDL Arrays From FORTRAN 77

The normal SIDL C function API is available from FORTRAN 77 to create, destroy and access array elements and meta-data. The function name from FORTRAN has _f appended.

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.

For type X, there is a FORTRAN 77 function called SIDL_X__array_access_f to provide a method to get direct access. An example is given below. Of course, this will not work if your FORTRAN 77 compiler does array bounds checking.


        integer*4 lower(1), upper(1), stride(1), i, index(1)
        integer*4 value, refindex, refarray(1), modval
        integer*8 nextprime, tmp
        lower(1) = 0
        value = 0
        upper(1) = len - 1
        call SIDL_int__array_create_f(1, lower, upper, retval)
        call SIDL_int__array_access_f(retval, 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 SIDL_int__array_set1_f(retval, i, value)
           else
              if (modval .eq. 1) then
                 index(1) = i
                 call SIDL_int__array_set_f(retval, index, value)
              else
C this is equivalent to the SIDL_int__array_set_f(retval, 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))    

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 you need it to be. stride(i) 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 a FORTRAN array of REAL*8 instead of a FORTRAN array of double complex to avoid potential alignment problems. For a fcomplex array, the reference array is a COMPLEX*8 because we don't anticipate an alignment problem in this case.


next up previous contents
Next: FORTRAN 77 objects with Up: FORTRAN 77 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