Author 
Message 
d.. #1 / 4

2D array to 1D array
I have a fortran program I am trying to convert to another language and there are some lines that I can't quite understand whats happening. Basiclaly there is a two dimension array A(15,15), which has values placed into it, then the array is passed as an argument to a subroutine where it appears to be redimensioned as a single dimension array. I am unfamiliar how Fortran rearranges the order of the array elements. Some sample code is below; main program  IMPLICIT REAL*8 (AH,OZ) DIMENSION ETA(32), THETAT(32), CCLCA(32), A(15,15), 1 X(32), ALPHAI(32), CCDCA(32) . . . A(N,J) = "values" CALL DGELG(X,A,NN,MM,EPS,IER) . . . SUBROUTINE DGELG(R,A,M,N,EPS,IER) DIMENSION A(1),R(1) DOUBLE PRECISION R,A,PIV,TB,TOL,PIVI,DABS,EPS . A is now a single dimension array 7 PIVI=1.D0/A(I) Any help is much appreciated dan Sent via Deja.com http://www.***.com/ Before you buy.

Wed, 18 Jun 1902 08:00:00 GMT 


d.. #2 / 4

2D array to 1D array
I previously printed out the values of the array before and after the subroutine call and couldn't seem to identify a pattern, however I repeated this exercise and it appears as if the array is 'read' down the columns, vice row by row. I'd be interested in some feedback to make me feel a little more comfortable about what I am seeing as well as tips on good references. dan
Quote:
> I have a Fortran program I am trying to convert to another language and > there are some lines that I can't quite understand whats happening. > Basiclaly there is a two dimension array A(15,15), which has values > placed into it, then the array is passed as an argument to a subroutine > where it appears to be redimensioned as a single dimension array. I am > unfamiliar how Fortran rearranges the order of the array elements. > Some sample code is below; > main program  > IMPLICIT REAL*8 (AH,OZ) > DIMENSION ETA(32), THETAT(32), CCLCA(32), A(15,15), > 1 X(32), ALPHAI(32), CCDCA(32) > . > . > . > A(N,J) = "values" > CALL DGELG(X,A,NN,MM,EPS,IER) > . > . > . > SUBROUTINE DGELG(R,A,M,N,EPS,IER) > DIMENSION A(1),R(1) > DOUBLE PRECISION R,A,PIV,TB,TOL,PIVI,DABS,EPS > . > A is now a single dimension array > 7 PIVI=1.D0/A(I) > Any help is much appreciated > dan > Sent via Deja.com http://www.deja.com/ > Before you buy.
Sent via Deja.com http://www.deja.com/ Before you buy.

Wed, 18 Jun 1902 08:00:00 GMT 


James Gile #3 / 4

2D array to 1D array
The Fortran standard specifies that arrays handled in a columnwise order when passed by 'sequence association' to a procedure. That is, as if the leftmost index of the multidimensional array varied fastest as you progress in memory order. Some of the other contexts where this is important are in COMMON and EQUIVALENCE associations and reading or writing whole arrays. All of these are collectively called storage associations. By the way, declaring an array with dimension one (1) in the subroutine is not a standard conforming method. You should declare them with their actual lengths as passed in, or with an asterisk (*) as their size. Hence: SUBROUTINE DGELG(R,A,M,N,EPS,IER) DIMENSION A(*),R(*) DOUBLE PRECISION R,A,PIV,TB,TOL,PIVI,DABS,EPS or SUBROUTINE DGELG(R,A,M,N,EPS,IER) DIMENSION A(M*N),R(M) DOUBLE PRECISION R,A,PIV,TB,TOL,PIVI,DABS,EPS (I don't know what the arguments M and N correspond to in your particular program, so you should determine how long you program really thinks the arrays are and use the correct sizes calculated from the argument variables.) Most implementations still work with 1 as the declared size unless you have array bounds checking turned on. Other style sugestions might be made here, though I suspect your concern is in getting the code working rather than making it stylish.  J. Giles

Wed, 18 Jun 1902 08:00:00 GMT 


Tesin #4 / 4

2D array to 1D array
Quote: > I have a Fortran program I am trying to convert to another language and > there are some lines that I can't quite understand whats happening. > Basiclaly there is a two dimension array A(15,15), which has values > placed into it, then the array is passed as an argument to a subroutine > where it appears to be redimensioned as a single dimension array. I am > unfamiliar how Fortran rearranges the order of the array elements. > Some sample code is below; > main program  > IMPLICIT REAL*8 (AH,OZ) > DIMENSION ETA(32), THETAT(32), CCLCA(32), A(15,15), > 1 X(32), ALPHAI(32), CCDCA(32) > . > . > . > A(N,J) = "values" > CALL DGELG(X,A,NN,MM,EPS,IER) > . > . > . > SUBROUTINE DGELG(R,A,M,N,EPS,IER) > DIMENSION A(1),R(1)
The problem could be placed here. You are rearranging the two dimension array (A) into a singledimension one. You have to declare A as a doubledimension array like: DIMENSION A(m,n) where m and n are input variables containing known dimensions of the array. For example: . . . m=15 n=15 CALL DGELG(R,A,m,n,...) Quote: > DOUBLE PRECISION R,A,PIV,TB,TOL,PIVI,DABS,EPS > . > A is now a single dimension array > 7 PIVI=1.D0/A(I) > Any help is much appreciated > dan > Sent via Deja.com http://www.deja.com/ > Before you buy.

Wed, 18 Jun 1902 08:00:00 GMT 


