12.07.2015 Views

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

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.

Passing ArraysPassing ArraysBecause C stores multidimensional arrays in row-major order, and Fortran stores them in column-majororder, there are some special considerations in processing a Fortran array.Excluding a single-dimension array (which is stored the same in C as in Fortran), you willneed to reverse the indices when accessing a Fortran array in C. The reason for this is that inC, the right-most index varies most quickly and in Fortran the left-most index varies mostquickly (multi-dimensional). In an array of arrays, the columns are stored sequentially: row1-column 1 is followed by row 1-column 2, etc. In a multi-dimensional array, the rows arestored sequentially: row 1-column 1 is followed by row 2-column 1, etc.Also note that all C arrays start at 0. We do not recommend that you use a lower dimensionbound other than zero (0) as your C code will have to modify the indices based on the valueused. We strongly recommend that you do not use negative lower and upper dimensionbounds!If the subscript ranges are not known at compile time, they can be passed at runtime, but youwill have to provide the code to scale the indices to access the proper members of the array.Some sample code may help explain the array differences. Your Fortran code would looklike:subroutine test(real_array)real :: real_array(0:4,0:5,0:6,0:7,0:8,0:9,0:10)integer :: i,j,k,l,m,n,odo o = 0, 10do n = 0, 9do m = 0, 8do l = 0, 7do k = 0, 6do j = 0, 5do i = 0, 4real_array(i,j,k,l,m,n,o) = 12.00end doend doend doend doend doend doend doend subroutine testThe equivalent C code would look like:<strong>Lahey</strong>/Fujitsu <strong>Linux</strong>64 Fortran User’s <strong>Guide</strong> 59

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

Saved successfully!

Ooh no, something went wrong!