I do not know how to express the array I am going to work with, but some codes can describe them.
If I define an array and a struct with member :
float velocity;
MODEL.VELOCITY;
VELOCITY in struct MODEL is also float.
then I alocate memory for them;
velocity = malloc( NX*NY*NZ*sizeof(float); /* in 3D case, NX,NY,NZ are the length, here it is original velocity file*/
MODEL->VELOCITY = malloc(NX*NY*NZ*sizeof(float);
the question is that if I need to split MODEL->VELOCITY into layer-cake model, how can I read my original "velocity" file into MODEL->VELOCITY layer by layer.
I tried this method, but it is "segmentation fault":
for (i=0;i<N_subdomain_num; i++)
{
for (dy=0; dy < NY ; dy++)
for (dx=0; dx < NX; dx++)
{
if ( i == 0){
for (dz=0; dz< domain[i].nz_comp; dz++) /*domain[i].nz_comp is the depth of every layer, i from 0 to 10, and depths are different in each layer*/
MODEL[i].VELOCITY[dz]= velocity[dz];
}
else {
for (dz=domain[i-1].nz_comp; dz< domain[i].nz_comp; dz++) domain[i].velocity[dz1] = velocity1[dz1];
}
}
I donot know how to modify or other method can do it. If you have some other ideas, I am HIGHLY appriciated.