First of all, I need to thank all friends helping me here. Those days I learn a lot from your advices.
The basic idea of my code is to read velocity file into domain[i].velocity[k] seperately.
Start!!!
Is the allocation of velocity wrong? How can I fix it? HIGHLY appriciated!!!
The basic idea of my code is to read velocity file into domain[i].velocity[k] seperately.
Start!!!
Code:
typedef struct
{int nx, ny, nz;
float *velocity;
}
void a(Model *domain, int i);
void init(Model *domain, int steps);
void main()
{int i, j;
int STEPS = 10;
Model *Domain;
Domain=(Model *)malloc(sizeof(Model));
init(Domain, STEPS);
for(i=0; i<STEPS; i++)
a(Domain, i);
return;
}
void init(Model *domain, int steps)
{int n=100;
int k;
for (k=0; i<n; i++)
{ domain[steps].nx=domain[steps].ny=domain[steps].nz=50;
domain[steps].velocity=NULL;
}
return;
}
void a(Model *domain, int i)
{short buff_v;
int j,m;
buff_v=(short *)malloc(domain[i].nz*sizeof(short);
read(fd,vel_buf,domain[il].nz * sizeof(short)); /* fd is my original velocity file, it has been created by other program*/
for(dz=0, j=0; dz<domain[i].nz; dz++,j++)
domain[i].veocity[j] = buff_v[dz] * 0.001 ; /* segmentation fault comes out here*/
return;
}
Comment