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!

Program Runtime Problem after Modulizing

Status
Not open for further replies.

dac5039

Programmer
Aug 12, 2009
22
US
Hello,

The code outlined below is a section I put into a subroutine to clear up my flow a little bit. The problem is, the prgram stalls once it calls the subroutine and never prints out the output I need (after about 20 minutes at least). The block worked fine when I had it within another subroutine, but failed once I moved it to its own. The entire code is attached.

Thanks!

Code:
subroutine yearly_stats(allruns) 
			implicit none
			integer :: k, updown, year, indicies, allrunscounter, sortstep_a, &
								& sortstep_b, mymax, mymaxpos, rank, midpoint, median, &
								& counter
			integer, allocatable :: allruns(:,:), runs(:)
			real :: totalcount, totalrun, mean, yrstats(0:1,1926:2009,1:4)			
			
			k = size(allruns)
			allocate(runs(k))
			do updown = 0, 1
				do year = 1926, 2009
					counter = 0 
					do indicies = 1, k
						runs(indicies) = 0
					end do
					do allrunscounter = 1, k
						if(allruns(allrunscounter,1) == year .AND. &
							& allruns(allrunscounter,3) == updown) then
							counter = counter + 1
							runs(counter) = allruns(allrunscounter,4)
						end if
					end do
					do sortstep_a = 1, k-1
						mymax = runs(sortstep_a)
						mymaxpos = sortstep_a
						do sortstep_b = sortstep_a+1, k
							if(runs(sortstep_b) > mymax) then	
								mymax = runs(sortstep_b)
								mymaxpos = sortstep_b
							end if
						end do
						rank = runs(sortstep_a)
						runs(sortstep_a) = runs(mymaxpos)
						runs(mymaxpos) = rank
					end do
					totalcount = counter !real
					totalrun = sum(runs(:)) !real
					mean = totalrun/totalcount !real
					midpoint = ceiling(counter/2.0) 
					median = runs(midpoint)
					yrstats(updown,year,1) = totalcount
					yrstats(updown,year,2) = totalrun
					yrstats(updown,year,3) = mean
					yrstats(updown,year,4) = median
				end do
			end do
			write(*,fmt='(1XI4,1XI1,1XF3.0,1Xf4.0,1XF6.4,1XF2.0)') yrstats(:,:,1:4)
			
		end subroutine yearly_stats
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top