Board index » cppbuilder » thread stopped

thread stopped


2003-09-23 11:09:59 AM
cppbuilder35
I run the following code which calls several subroutines and
then writes intermediate data to files. After calling the
subroutine "convect" for the 47th time (that's right, the 47th)
-- I get an error "Thread stopped. Fault: access violation at
0x426440: read of address 0xffffffff" I also get a standard error message on my screen that the file hydro3.txt can't be
opened. I programmed this message into my code.
I don't know what the run time error message means. I have checked to make sure that the data I am writing is good, but if I remove the subroutine convect, evrything works fine. Ideas?
Thanks.
===============================================================
#include "includes.h"
int main()
{
FILE *fp;
// Define types
double *rho; // mass density
double *m; // momentum density
double *E; // total energy density
double *E_field; // electric field
double *phi; // potential
double *D; // doping profile
double dt; // temp{*word*203}step size
double dx; // spatial step size
double *a; // interpolation coeffcient
int i;
int j;
// Read in initial densities and electric field
D = dvector(0,N+1);
rho = dvector(0,N+1);
m = dvector(0,N+1);
E = dvector(0,N+1);
E_field = dvector(0,N+1);
phi = dvector(0,N+1);
a = dvector(0,N+1);
dx = initial(D, rho, phi, E_field, m, E, N);
if ((fp = fopen("hydro1.txt","w")) == NULL)
fprintf(stderr, "Error opening file%s.", "hydro1.txt");
for (i=0; i <= N+1 ; ++i )
fprintf(fp, "%-e\t%-e\t%-e\t%-e\t%-e\n\n", rho[i], m[i],
E[i], phi[i], E_field[i]);
fclose(fp);
for (j=1;j<=200;j++)
{
// Step One: Relaxation and Electric Field update
dt = relax(D, rho, phi, E_field, m, E, dx, a, N);
if ((fp = fopen("hydro2.txt","w")) == NULL)
fprintf(stderr, "Error opening file %
s.", "hydro2.txt");
for (i=0; i <= N+1 ; ++i )
fprintf(fp, "%-e\t%-e\t%-e\t%-e\t%-e\n\n",rho[i], m[i],
E[i], phi[i], E_field[i]);
fclose(fp);
//Step Two: Convection
convect(rho, m, E, E_field, N, dt, dx, a);
if ((fp = fopen("hydro3.txt","w")) == NULL)
fprintf(stderr, "Error opening file%
s.", "hydro3.txt");
for (i=0; i <= N+1 ; i++ )
fprintf(fp, "%-e\t%-e\t%-e\t%-e\t%-e\n\n", rho[i], m[i],
E[i], phi[i], E_field[i]);
fclose(fp);
printf("%-d\n",j);
}
return 0;
}//end main
 
 

Re:thread stopped

cory wrote:
Quote
I also get a standard error message on my screen that the file hydro3.txt can't be
opened. I programmed this message into my code.
Look at the documentation for fopen(). It tells you how to find out
the cause of the non-opening.
Quote
-- I get an error "Thread stopped. Fault: access violation at
0x426440: read of address 0xffffffff"
I don't know what the run time error message means.
It means, if you look in the CPU mode of the De{*word*81}, at address
0x426440, you will see the code that generated the error. The cause
will either be right there, before it, or elsewhere that set up the
error-waiting-to-happen.
In this particular case, it's likely cause by the fprintf() on the
invalid fp because the file couldn't be opened.
Quote
I have checked to make sure that the data I am writing is good,
but if I remove the subroutine convect, evrything works fine. Ideas?
Could be something wrong with convect() but you didn't show that.
Quote
D = dvector(0,N+1);
rho = dvector(0,N+1);
dx = initial(D, rho, phi, E_field, m, E, N);
for (j=1;j<=200;j++)
{
if ((fp = fopen("hydro2.txt","w")) == NULL)
fprintf(stderr, "Error opening file %
s.", "hydro2.txt");
Hmmm.. you write to fp even if you can't open it......
You might want to break the for(j) loop on error.
You need to handle the open-error better, including reporting
why it fails.
I think "i" goes too high in all these "for" loops.
Probably meant i<=N;
If N+1 is the number of doubles in the vector, then the index values
go from 0 to N not N+1;
Quote
for (i=0; i <= N+1 ; ++i )
fprintf(fp, "%-e\t%-e\t%-e\t%-e\t%-e\n\n",rho[i], m[i],
E[i], phi[i], E_field[i]);
fclose(fp);