write a main program into a subroutine
- From: "PCAT" <pcatchen@xxxxxxxxx>
- Date: 15 Nov 2005 09:18:41 -0800
My main program is divided into two parts:
first part produces some values and followed by the 2nd part.
The second part of the main program can produce the result I want:
count= 3.000000
t= 1
cid= 3 flag= 1 sum= 0.0000000E+00 t= 1
Press any key to continue
However, when I modify it into a subroutine, the result is not what I
want:
count= 3.000000
t= 1
t= 3
t= 2
cid= 4 flag= 1 sum= 2.000000 t= 2
Press any key to continue
When it founds the t=1, it should not go to find the t=3, t=2. It
should report the cid, flag value when t=1.
I wonder if there is anything I need to modfiy when I write a main
program into a subroutine. I double checked it several times and they
are all the same.
This main program has previous values from the first part of the main
program: count, order(j), j, and I call the subroutine right after the
first part of the main program.
Please help me !
This is the second part of the main program.
if (count ==1 .and. vwz(v,w,j) .ne. 0) then
cid=j
flag=1
else if (count ==1 .and. vwz(v,w,j)==0) then
flag=0
cid=0
elseif (count .gt. 1 ) then
c cindx(j)=0: content j is not selected so far
do i=1,count
cindx(i)=0
enddo
cid=0
sum=0
flag=0
do while (sum .lt. real(count+1) .and. flag==0)
call digran(dseed,p,count,t)
if (cindx(t) ==0) then
write(*,*)'t=',t
inner: do j=1,n1
if(t==order(j) .and. vwz(v,w,j) .ne. 0) then
flag=1
cid=j
cindx(order(j))=1
exit
elseif (t==order(j) .and. vwz(v,w,j) ==0) then
cindx(t)=1
sum=sum+1
exit
else
endif
17 enddo inner
else
endif
if (sum== real(count)) exit
enddo
else
endif
This is my subroutine:
subroutine search(v,w,n1,order,count,p,dseed,flag,cid,sum,t )
real sum,p,count,vwz(v,w,n1)
integer j,cid,flag,n1,cindx(0:count),order(0:n1),t
double precision dseed
if (count ==1 .and. vwz(v,w,j) .ne. 0) then
cid=j
flag=1
else if (count ==1 .and. vwz(v,w,j)==0) then
flag=0
cid=0
else if (count .gt. 1 ) then
do i=1,count
cindx(i)=0
enddo
cid=0
sum=0
flag=0
do while (sum .lt. real(count+1) .and. flag==0)
call digran(dseed,p,count,t)
if (cindx(t) ==0) then
write(*,*)'t=',t
inner: do j=1,n1
if(t==order(j) .and. vwz(v,w,j) .ne. 0) then
flag=1
cid=j
cindx(t)=1
exit
elseif (t==order(j) .and. vwz(v,w,j) ==0) then
cindx(t)=1
sum=sum+1
exit
else
endif
77 enddo inner
else
endif
if (sum== real(count)) exit
enddo
else
endif
return
end
.
- Follow-Ups:
- Re: write a main program into a subroutine
- From: Michael Metcalf
- Re: write a main program into a subroutine
- From: Duane Bozarth
- Re: write a main program into a subroutine
- Prev by Date: Re: Converting unformatted data
- Next by Date: write a main program into a subroutine
- Previous by thread: Re: random_number
- Next by thread: Re: write a main program into a subroutine
- Index(es):
Relevant Pages
|
|