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!

Access Violation while attempting to Sort Allocatable Array...

Status
Not open for further replies.

dac5039

Programmer
Aug 12, 2009
22
US
The attached .f95 code does a range of statistical manipulations to a large data set. The program had successfully deduced all instances of x > threshold and x < threshold for each of the 42,000+ instances and written them to file. The specific application is daily high temperatures exceeding or falling short of the 30-year average high temperature.

Furthermore, the code computes the lengths of runs above or below the average over the entire period of record. That is, 5 days above average, 3 days below, 10 days above, etc ... from 1896 to 2009. I want to find the MEAN and MEDIAN run length values for EACH YEAR, which requires me to store the run values per year and sort them (to find median). I'm having a hard time sorting the array. All of the scripts I found on line were much more sophisticated that my intentions, and so I tried to build a sorting block, but to no avail.

The attached code uses a .txt data file, which is also attached. Thanks for any help you can offer!

Dave
 
I don't see in your code, where you try to sort the array.
 
Hi mikrom,

It's within the "high_norm_runs" subroutine:

Code:
do j = 0, 1
				do p = 1926, 2009
					rcount = 0
					do i = 1, 185
						rlens(i) = 0
					end do
					do m = 1, k
						if(allruns(m,1) == p .AND. allruns(m,3) == j) then	
							rcount = rcount + 1
							rlens(rcount) = allruns(m,4)
						end if
					end do
					do i = 1, k-1
						imin = rlens(i)
						iminp = i
						do q = i+1, k
							if(rlens(q) < imin) then
								imin = rlens(q)
								iminp = q
							end if
						end do
						t = rlens(i)
						rlens(i) = rlens(iminp)
						rlens(iminp) = t
					end do
					write(*,*) rlens
				end do
			end do
 
Hi dac5039,

You are probably not clear what you do. You declared in you program the array
Code:
integer :: rlens(185)
and then you use it inside of this loop
Code:
						do q = i+1, k
							if(rlens(q) < imin) then
								imin = rlens(q)
								iminp = q
							end if
						end do
The problem is that your k is more greater than 185 (what you declared). My debugger shows me that
Code:
k = 8493
Therefore yur program stops at line 169 with Exception: Access Violation

Next time if you have such error, which you don't understand try to use a debugger. I'm using insight. It's free.
 
mikrom,

Thanks for the input. I was getting an error at line 100, back by where I allocate rlens, so that's why I wasn't able to find the problem.
 
Hi dac6039,

By running your program I got the error at line 100 too. But in debugger I found it at line 169.
Funny - I don't know why it's so. But you see, to figuring out such errors you need to be familar with debugger.
 
Can you recommend a debugger for g95 in Windows?
 
As I wrote above in my answer from 1.November, I'm using gdb with GUI called insight. The link is above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top