24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 25. Escape Sequences <strong>for</strong> Character Strings (continued)<br />

Escape<br />

Meaning<br />

\x x, where x is any other character (the backslash is ignored)<br />

If you do not want the backslash interpreted as an escape character within strings,<br />

you can compile with the -qnoescape option.<br />

Passing Arrays between Languages<br />

<strong>Fortran</strong> stores array elements in ascending storage units in column-major order. C<br />

and Pascal store array elements in row-major order. <strong>Fortran</strong> and Pascal array<br />

indexes start at 1, while C array indexes start at 0.<br />

The following example shows how a two-dimensional array that is declared by<br />

A(3,2) is stored in <strong>Fortran</strong>, C, and Pascal:<br />

Table 26. Corresponding Array Layouts <strong>for</strong> <strong>Fortran</strong>, C, and Pascal. The <strong>Fortran</strong> array<br />

reference A(X,Y,Z) can be expressed in C as a[Z-1][Y-1][X-1] and in Pascal as A[Z,Y,X].<br />

Keep in mind that although C passes individual scalar array elements by value, it passes<br />

arrays by reference.<br />

<strong>Fortran</strong> Element<br />

Name<br />

C Element Name<br />

Lowest storage unit A(1,1) A[0][0] A[1,1]<br />

A(2,1) A[0][1] A[1,2]<br />

A(3,1) A[1][0] A[2,1]<br />

A(1,2) A[1][1] A[2,2]<br />

A(2,2) A[2][0] A[3,1]<br />

Highest storage unit A(3,2) A[2][1] A[3,2]<br />

Pascal Element<br />

Name<br />

To pass all or part of a <strong>Fortran</strong> array to another language, you can use <strong>Fortran</strong><br />

90/<strong>Fortran</strong> 95 array notation:<br />

REAL, DIMENSION(4,8) :: A, B(10)<br />

! Pass an entire 4 x 8 array.<br />

CALL CFUNC( A )<br />

! Pass only the upper-left quadrant of the array.<br />

CALL CFUNC( A(1:2,1:4) )<br />

! Pass an array consisting of every third element of A.<br />

CALL CFUNC( A(1:4:3,1:8) )<br />

! Pass a 1-dimensional array consisting of elements 1, 2, and 4 of B.<br />

CALL CFUNC( B( (/1,2,4/) ) )<br />

Where necessary, the <strong>Fortran</strong> program constructs a temporary array and copies all<br />

the elements into contiguous storage. In all cases, the C routine needs to account<br />

<strong>for</strong> the column-major layout of the array.<br />

Any array section or noncontiguous array is passed as the address of a contiguous<br />

temporary unless an explicit interface exists where the corresponding dummy<br />

argument is declared as an assumed-shape array or a pointer. To avoid the creation<br />

of array descriptors (which are not supported <strong>for</strong> interlanguage calls) when calling<br />

non-<strong>Fortran</strong> procedures with array arguments, either do not give the non-<strong>Fortran</strong><br />

procedures any explicit interface, or do not declare the corresponding dummy<br />

arguments as assumed-shape or pointers in the interface:<br />

352 <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong> <strong>AIX</strong> : User’s <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!