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

Initialize Arrays

onkelhotte
New Contributor II
926 Views

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 Solution
Les_Neilson
Valued Contributor II
926 Views

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

View solution in original post

0 Kudos
2 Replies
Les_Neilson
Valued Contributor II
927 Views

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

0 Kudos
onkelhotte
New Contributor II
926 Views
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

0 Kudos
Reply