2D array to 1D array 
Author Message
 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 (A-H,O-Z)
      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  
 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 (A-H,O-Z)
>       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  
 2D array to 1D array
The Fortran standard specifies that arrays handled in
a column-wise order when passed by 'sequence association'
to a procedure.  That is, as if the leftmost index of the
multi-dimensional 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  
 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 (A-H,O-Z)
>       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 single-dimension one.
You have to declare A as a double-dimension 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,...)

- Show quoted text -

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  
 
 [ 4 post ] 

 Relevant Pages 

1. convert 2d array to 1d array without using shift registers and build array

2. 1D binairy array (I16) to 2D array

3. Change a 2D Array into a 1D Array.

4. 1d array containing means of a 2d array

5. Join 1D three arrays together become a 1d array

6. creating a new 2D array with two 2D arrays

7. array 2D to 1D

8. finding 1d index in 2d array of indices

9. Numeric and PIL: 1D array from 2D-tuple

10. Convert 1D string Array to Numeric Array

11. how to use 1D array as a multidimensional array

12. Optimizing 2D tables for speed - 2D array vs. 1D array vs. vector-of-vectors

 

 
Powered by phpBB® Forum Software