Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fill array in module

Status
Not open for further replies.

DaPhil

Technical User
Jun 24, 2011
6
DE
Hi,
following problem: I want to fill an array within a module. My Code:

module myModule
implicit none
save

integer :: l

integer, parameter :: nt = 4524
real*8, parameter :: tMin = 0.0d0
real*8, parameter :: tMax = 6.0d0
real*8, parameter :: dt = (tMax - tMin) / (nt - 1)
real*8, dimension(nt) :: t

do l = 1, nt
t(l) = tMin + (l - 1) * dt
end do

end module myModule

I get an error: This statement must not appear in the specification part of a module

Is it not possible to fill that array in the module?

Thanks for any help
 
A module never contains instructions directly but is, on the contrary, a container for data and procedures containing instructions.

In addition, every program needs a main procedure. This is true with many languages like C, C++, FORTRAN, JAVA...

So I suggest something like :

Code:
module myModule

  implicit none
  save
  private
  
  public :: compute_t,dp
  
  integer ,parameter :: dp=selected_real_kind(15)
  real(dp),parameter :: tMin = 0.0_dp
  real(dp),parameter :: tMax = 6.0_dp
  
  contains
  
  subroutine compute_t(t)
    real(dp),intent(out) :: t(:)
    integer :: i,nt
    real(dp) :: dt
    nt=SIZE(t)
    dt = (tMax - tMin) / (nt - 1)
    do i=1,nt
      t(i) = tMin + i*dt
    enddo
  end subroutine
  
end module myModule

program test
  use myModule
  implicit none
  real(dp) :: table(4524)
  call compute_t(table)
  write(*,*) table(4000)
end program

I put that in the file "t44.f90". To test :

Code:
[lcoul@localhost test]$ ifort t44.f90
[lcoul@localhost test]$ ./a.out
   5.30621269069202



François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top