Silverfrost Forums

Welcome to our forums

Copying into array slices - new error?

13 Jun 2007 10:41 #1965

Hi All,

In a product that has always appeared to work fine up till now I have some code a bit like this:

integer :: a(10,10,10,10), b(10)
do i = 1,10
  a(:,:,1:10,i) = b(1:10)
end do

The code is supposed to be copying the contents of the array b into the relevant 3rd dimension elements of array a such that a(i,j,k,l) = b(k) for any values of i and j (for fixed l).

Compiling the following program:

      program test
      implicit none
      
      integer :: i
      integer :: a(10,10,10,10), b(10)
      
      do i = 1,10
        a(:,:,1:10,i) = b(1:10)
      end do
      
      end program test

leads to the error message: 0008) a(:,:,1:10,i) = b(1:10) *** Rank 1 arrays cannot be mixed with rank 3 arrays in an array expression

Now, I know that this code compiles under 4.9.1 and pretty sure it comppiled fine under 5.01. I am now using 5.10 and the code does not compile.

Am I trying to do something that should never have worked?

Mark.

13 Jun 2007 11:57 #1966

There is a new test in the compiler and it looks like it needs refining.

In the mean time, if you are sure that the code has the desired result then you could get the error number <n> for this particular error and use /IGNORE <n> on the FTN95 command line.

26 Jun 2007 1:02 #1991

We have checked this out and the array assignment is not valid Fortran. The arrays must have the same 'shape' or the RHS must be a scalar.

A previous version of FTN95 allowed this but only gave the expected result in exceptional circumstances (perhaps when the shape was uniform, i.e. the same length on each dimension).

You should be able to use

a(j,k,1:10,i) = b(1:10)

and range over i, j and k.

The current version of FTN95 is correct in not allowing this construction.

Please login to reply.