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!

Data overflow

Status
Not open for further replies.

thursdays

Programmer
May 6, 2008
3
US
I haven't had much luck searching for an answer, maybe a guru here has one.

This is the basic structure of my program:

program main
open(42,file='output.dat')
do while(x)
process a bunch of data
call output_function
end do
close(42)
end program
subroutine output_function
write(42,y) data_set N
end subroutine

The problem: the program writes many many data sets... but then stops. A new file, 'fort.42' is created, and the last data sets are written here - but many intermediate data sets are lost! This problem persists using Absoft fortran, gfortran, and g95.

Why is this, and how do I work around it? Is it simply a matter of writing too much data to a single datafile?

Thank you for your help.
 
Has your data gone out of bounds an started overwriting the stack?
 
How would I know if my data is overwriting the stack?

This is along the line of what I thought the problem would be, but do you know of any way to detect when my data is or is about to overwrite the stack?
 
Basically if an array goes outside its bounds, it will overwrite the stack or other variables. eg
Code:
integer mmm(5)
integer kkk

kkk = 25
mmm(6) = 99
mmm(7) = 1025
At runtime, this may or may not cause a crash. Depending on how the variables are arranged in memory, you might find that kkk is 99 and that the program returns to somewhere else.
 
Well, for those who are curious...

As embarrassing as it is to disclose, I have discovered the problem.

My program has a subroutine for writing a data file in case I want to continue where the last computation left off. I later decided it would be nice to call the continuation subroutine at regular intervals in the main loop in case of a power failure or some similar catastrophe.

Turns out the continuation subroutine also used write(42,*). Whoops.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top