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

Initialize Arrays

onkelhotte
新規コントリビューター II
1,311件の閲覧回数

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 件の賞賛
1 解決策
Les_Neilson
高評価コントリビューター II
1,311件の閲覧回数

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

元の投稿で解決策を見る

2 返答(返信)
Les_Neilson
高評価コントリビューター II
1,312件の閲覧回数

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
新規コントリビューター II
1,311件の閲覧回数
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

返信