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

passing TYPE variables to fortran subroutine

Status
Not open for further replies.

fishytiger

Technical User
Jan 11, 2005
8
0
0
CA
I am writing an aplication where I have to pass a TYPE variable to a subroutine, but my code gives me a " More than one part reference of this data reference has a rank greater than zero." which sucks. Somehow I am able to use this in the main program but not in subroutines!, help!

! Particle variable
type particle
character(len=2) :: symbol=''
double precision, dimension(3) :: r=0.0d0
double precision, dimension(3) :: v=0.0d0
integer :: Nnb=0
integer, dimension(40) :: neighlist=0
end type



subroutine setpos(nats,artie)
use variables
integer, intent(in) :: nats
TYPE(particle), dimension(nats) , intent(out) :: artie
! Global Variables
! ===============================
 
The problem is probably
Code:
TYPE(particle), dimension(nats) , intent(out) :: artie
Try
Code:
TYPE(particle), dimension(:) , intent(out) :: artie
You are probably just passing nats for loops so the way you have declared it is OK. The compiler doesn't really need to know how big artie is in the subroutine.
 
try to allocate artie in the main program
allocate(artie(nats))

and declare in the subroutine :
TYPE(particle), dimension(*) , intent(out) :: artie

let me know

flav256
 


Hey thanks for your Repply, both xwb and flav256!!,....I had decided to make a rondeavouz and code the program diferently....It seems that the problem I had, has to do with initialization of variables.

character(len=2) :: symbol=''
double precision, dimension(3) :: r=0.0d0
double precision, dimension(3) :: v=0.0d0
integer :: Nnb=0
integer, dimension(40) :: neighlist=0


The compiler did not tell me such thing was wrong :(. Initialization of variables, is accepted when the array is NOT allocatable. wonder why.

Also, using :)) was useful.


fishytiger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top