This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: cannot initialize a two-d array
- From: Kamaraju Kusumanchi <kamaraju at gmail dot com>
- To: gfortran <fortran at gcc dot gnu dot org>
- Date: Wed, 9 Mar 2005 08:49:01 -0500
- Subject: Re: cannot initialize a two-d array
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=NV0bnGjuspt9lJWEqNlhmDdsxHspgfLrwwnM1m7wd3BNH3XGPzNho21983qwpJAVPDxeFnJAyZKPhsdYE5vJTOqjT6up2BupZqNgW1llYpajnUJuXlFpDm11X8PmD+OOVyaInbFAlsxzcjIz7RDX3TRzoG5T9jVjTkUggnkeK3c=
- References: <ba497515050308210320f64d75@mail.gmail.com> <20050309092417.GA20895@vipunen.hut.fi>
- Reply-to: Kamaraju Kusumanchi <kamaraju at gmail dot com>
> 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