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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an array - everywhere?

Status
Not open for further replies.

grappleone

Programmer
May 10, 2008
1
GB
Could anyone help here?
I am developing a program in F90 to simulate a problem in solid state physics. I have a couple of largish arrays representing the positions of atoms in a solid whose sizes are set at at compile using parameter values. These arrays need to be passed to many subroutines for diverse processing.

e.g
SUBROUTINE Populate_Lattice(Lattice, xmax, ymax, zmax)
INTEGER, INTENT (IN) :: xmax, ymax, zmax
Integer, INTENT (OUT) :: Lattice(xmax,ymax,zmax,5)

Do I have to redeclare them for each subroutine. I've looked at COMMON blocks but that seems rather `unstylish' in terms of code reuse.

Am I on the right track here?

Cheers

Ian
 
Stick it into a module and then it magically becomes global to the module
Code:
module SolidStatePhysics
   integer, dimension(:,:,:,:):: Lattice
   integer:: xmax, ymax, zmax
contains
   subroutine Initialize
      ! Allocate the array here
   end subroutine

   subroutine populate_lattice
      ! whatever
   end subroutine
end module

program main
   use SolidStatePhysics
   call Initialize

   ...
end program
The module SolidStatePhysics can be in a different file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top