tags:

views:

71

answers:

1

hi,

I have a module in Fortran called QFoo. It defines a type QFooType.

I want to initialize all the elements of integer array 'is_n' to 0 and want to do it within the module. Could someone help? Thank you!

  module QFoo
      type QFooType              
          integer::i              
          integer, dimension(50) :: is_n                         
      end type QFooType

     !-----------
     ! I know the following code is wrong
     ! but I want to initialize all the is_n elements to 0
     !-----------
     ! do i = 1, 50
     !    is_n(i) = 0
     ! enddo
     !-----------
  end module QFoo
+2  A: 

Hi

integer, dimension(50) :: is_n = 0

works on the latest version of the Intel Fortran compiler. My reading of the Fortran 95 standard suggests that this is standard behaviour.

Regards

Mark

High Performance Mark
great! it worked.. thanks! I didn't think that the syntax we use for non array assignment will work here! Thanks again
apt
Ahh, so you would initialise an array with a loop in your Fortran code ? Go back to your introductory text: since Fortran 90 you can assign to all the elements in an array in one statement. Measurements differ on whether it is more efficient to do so.
High Performance Mark