This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cannot initialize a two-d array


> Gfortran is right, Intel is wrong. The result of an array constructor
> expression is always a 1D array. Use the RESHAPE intrinsic if you wish
> to assign to a multi-dimensional array.
> 

Thanks for pointing out my mistake. I have been using the above type
of initialization for ages and did not know that I was not confirming
to the standard. Actually, I am 'porting' a large code to gfortran and
am stumped at another problem now. Consider the following test case


$cat using_reshape.f90
program using_reshape
  implicit none
  real :: k(8,2) = reshape((/1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,16/), (/8,2/))
  real :: n(8,2), o(8,2)

  write(*,*) 'corner turning from rows into columns'
  n = reshape(transpose(k), (/8,2/))

  write(*,*) 'the above can be achieved without using transpose'
  o = reshape(reshape(k, (/2,8/), order=(/2,1/)), (/8,2/))
end program

This program compiles fine but segfaults when executed.

So I commented out the 7 th line where I take the transpose and
compile+executed it again. This time it gives the following error.

Fortran runtime error: shape and target do not conform

Does the standard also prohibit from using "nested reshape" and
"reshape+transpose" combination? or am I doing something stupid again?
I cheked the code with ifort and it executes fine.

thanks in advance
raju

-- 
friends don't  let friends use windows.

Kamaraju S Kusumanchi
Cornell University
http://people.cornell.edu/pages/kk288/
http://groups.yahoo.com/group/flumech


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]