How To Access 3/4 Dimensional Arrays Using Pointers

From: Christopher M. Lusardi (clusardi2k_at_aol.com)
Date: 01/29/04


Date: 29 Jan 2004 12:12:41 -0800

Hello,

   Can you tell me (with good examples) how to access 3 and 4 dimensional
Fortran arrays using pointers in C/C++? My program uses two languages. I have
arrays defined in Fortran. In C I am given the base address of the Fortran
arrays. How do I get the address of individual elements

EG: The following is the lower half of the addresses of a three dimensional
array.

Fortran declaration
int_tes (3,2,2)

Addresses
int_tes (1,1,1) = 548
int_tes (1,1,2) = 656
int_tes (1,2,1) = 602
int_tes (1,2,2) = 710
int_tes (2,1,1) = 566
int_tes (2,1,2) = 674
int_tes (2,2,1) = 620
int_tes (2,2,2) = 728
int_tes (3,1,1) = 584
int_tes (3,1,2) = 692
int_tes (3,2,1) = 638
int_tes (3,2,2) = 746

548 + 108 = 656 to go from element 1,1,1 to 1,1,2
548 + 18 = 566 to go from element 1,1,1 to 2,1,1
548 + 54 = 602 to go from element 1,1,1 to 1,2,1

The size of an integer is 3 bytes.

(1,,) (2,,) (3,,)
548 656 566 674 584 692
602 710 620 728 638 746

                   Thank you,
                   Christopher Lusardi



Relevant Pages

  • Re: best practices for structuring ASCII input
    ... I'm maintaining a number of smallengineering/scientific Fortran ... data consists of a mixture of variables, arrays, ... the input files are not human readable. ...
    (comp.lang.fortran)
  • Re: bivariate interpolation
    ... > interpolated using Akima's Bivariate Interpolation for Smooth Surface ... > rewrite the code form its original Fortran V to much cleaner C. ... > The routine has numerous 2-dimensional arrays that are being accessed ...
    (comp.lang.c)
  • Re: seeking advice for "translate" Fortran code to Java code
    ... redefine a common block as needed for each subroutine. ... Still, Java has no pointers, so I ... Java arrays are always what C would call arrays of pointers ... Fortran intrinsics in Java appropriately. ...
    (comp.lang.fortran)
  • Re: which language?
    ... Of course other languages can and are used for scientific computing. ... Many engineering and physics calculations use arrays as their ... Fortran compilers have implemented ... programmer to avoid overspecifying the order of operations. ...
    (comp.programming)
  • Re: INTERFACE problem
    ... I have an integer at Fortran side, pass it by reference to C function, treat here as pointer, allocate memory and this C-pointer at Fortran side now is an integer which has represents address allocated at C side. ... I did something like this many years ago to allow dynamic allocation ... Then it was converted into a subroutine with the arrays and ... it called the sub by way of Pascal with those "pointers". ...
    (comp.lang.fortran)