Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Initialize Arrays

onkelhotte
Neuer Beitragender II
1.332Aufrufe

Hi there,

I want to set an Array, that is declared in a module,to a default value. Forone dimensional Arrays I use

real(kind=4) 1Darray(3)
1Darray = [1.,2.,3.]

The only way I know to declare atwo dimensional Array is this:

real(kind=4) 2Darray(3,2)
2Darray(:,1) = [1.,2.,3.]
2Darray(:,2) = [4.,5.,6.]

I would prefer a way like the data statement

data 2Darray /1.,2.,3.,4.,5.,6./

but the data statement wont work, because my variables are declared in a module.

Thanks in advance,
Markus

0 Kudos
1 Lösung
Les_Neilson
Geschätzter Beitragender II
1.332Aufrufe

I think you need RESHAPE

e.g.

2darray = RESHAPE ((/3, 4, 5, 6, 7, 8, 9, 10/), (/2, 4/))

has the value

[ 3 4 5 6 ]
[ 7 89 10 ].

Les

Lösung in ursprünglichem Beitrag anzeigen

2 Antworten
Les_Neilson
Geschätzter Beitragender II
1.333Aufrufe

I think you need RESHAPE

e.g.

2darray = RESHAPE ((/3, 4, 5, 6, 7, 8, 9, 10/), (/2, 4/))

has the value

[ 3 4 5 6 ]
[ 7 89 10 ].

Les

onkelhotte
Neuer Beitragender II
1.332Aufrufe
Quoting - Les Neilson

I think you need RESHAPE

e.g.

2darray = RESHAPE ((/3, 4, 5, 6, 7, 8, 9, 10/), (/2, 4/))

has the value

[ 3 4 5 6 ]
[ 7 89 10 ].

Les


Thanks Les,

reshape did the trick!

Markus

Antworten