Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Strange behavior in data assignment/output

$
0
0

Hi,

I'm sorry for this unspecific subject but it's hard to find a title for this problem. I have the following minimal example:

File: base.f90

module m_type
  implicit none

  type mytype
    real(kind=8) :: array(6)
  end type mytype

  type (mytype) :: te

  data te%array /1.d0, 1.d0, 1.d0, 0.d0, 0.d0, 0.d0/

contains

  subroutine output_0(number, name)
    implicit none
    real(kind=8) :: number
    character(*) :: name

    write(*,*) name, number

  end subroutine output_0

  subroutine output_1(typ, name)
    implicit none
    type(mytype) :: typ
    character(*) :: name

    write(*,*) name, typ%array

  end subroutine output_1

end module m_type

 

File: main.f90

program test
  use m_type
  implicit none
      integer, parameter :: steps = 10, periods = 10
      integer :: i1
      type(mytype) :: t(steps*periods)

      do i1 = 1, steps*periods
        t(i1) = te
      enddo

      call output_0(t(2)%array(1), "t2(1) = ")
      call output_1(te, "te = ")
!      call output_1(t(2), "t(2) = ")
!      write(*,*) t(steps)%array(1)

end program test

I would expect the following output:

 t2(1) =    1.00000000000000
 te =    1.00000000000000        1.00000000000000        1.00000000000000
  0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000 

Instead, I get the following:

ifort --version
ifort (IFORT) 13.0.0 20120731
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

ifort base.f90 main.f90 -o Test
./Test

 t2(1) =   0.000000000000000E+000
 te =    1.00000000000000        1.00000000000000        1.00000000000000
  0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000

This does not occur in the following cases:

  • -debug full
  • uncomment one of the two last lines in main.f90
  • use a single file for the code
  • only use "steps" as an upper boundary in the do-loop

Is there something wrong with the data-statement in module m_type (by the way, is there a way to define a type as a parameter?)? Or is this a compiler bug? gfortran works as expected, even if I use optimization.

Thank you!


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>