arnaudtemme
02-15-2006, 07:14 AM
Ladies and gentlemen,
In my model, I use grids:typedef double matelems;
typedef matelems *grid; and structs like struct tillage_parameters
{
grid *till_result;
int_grid *tillfields;
char fieldfile[30];
double tilc, plough_depth;
}; to store values for and pass values to modules that model a different process each. I practically have that running, thanks to bwkaz and others. Now, the different modules are in a time loop, so that for every year we can model changes to the landscape. The weird thing is that process "tillage", with its associated struct till_pars (see below) runs smoothly the first year, but then looses the grids from that struct before the second year. The error message is "access violation at etc.." , indicating that the grids from struct "till" that I use no longer exist or no longer occupy memory space. Below is the section within the timeloop that I found is responsible for the loss:
// before the timeloop: struct tillage_parameters till_pars;
// also before the timeloop: allocating memory space to grids in till_pars.
if (normal.use_tillage == 1) {
sprintf(ch, "1result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "1field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
till(&dtm, &ero_pars.soildepth, &till_pars,ascii,ero_pars);
add_double_grid(&dtm,till_pars.till_result,ascii.nr,ascii.nc);
sprintf(ch, "2result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "2field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
}
printf(till_pars.fieldfile);
sprintf(ch, "4result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "4field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
if (normal.use_water_erosion == 1) {
define_cellstatus(dtm, &dep.status_map, numberofsinks, ascii);
define_depressions(dtm, &dep.status_map, ascii, &dep);
define_fillheight(ascii, &dep);
erode(dtm, &waterflow, &ero_pars, &dep, ascii, evaporation, infiltration, rainfall);
add_double_grid(&dtm,ero_pars.erosion,ascii.nr,ascii.nc);
add_double_grid(&dtm,ero_pars.sedimentation,ascii.nr,ascii.nc);
}
write_asc_dbl(dtm,"dtm_4",ascii);
write_asc_dbl(ero_pars.erosion,"w_erosion",ascii);
write_asc_dbl(ero_pars.sedimentation,"w_sedimentation",ascii);
printf(" calculated water_erosion\n");
printf(till_pars.fieldfile);
sprintf(ch, "5result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "5field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
} // end run time loopWith output to screen:
calculated tectonics
1result 0 40 = 0
1field 0 40 = 1
2result 0 40 = 0.030841
2field 0 40 = 1
tilfield 4result 0 40 = 0.030841
4field 0 40 = 1
calculated water_erosion
tilfield And then the error message I mentioned above. My direct question is: how is it possible that the grids from till_pars loose the space they occupy in memory, whereas they are never mentioned in / passed to the other submodule for water erosion? And if it is a memory problem, why did it not occur before, because all the structs are initiated and all memory is allocated much earlier than this section of the code.
In my model, I use grids:typedef double matelems;
typedef matelems *grid; and structs like struct tillage_parameters
{
grid *till_result;
int_grid *tillfields;
char fieldfile[30];
double tilc, plough_depth;
}; to store values for and pass values to modules that model a different process each. I practically have that running, thanks to bwkaz and others. Now, the different modules are in a time loop, so that for every year we can model changes to the landscape. The weird thing is that process "tillage", with its associated struct till_pars (see below) runs smoothly the first year, but then looses the grids from that struct before the second year. The error message is "access violation at etc.." , indicating that the grids from struct "till" that I use no longer exist or no longer occupy memory space. Below is the section within the timeloop that I found is responsible for the loss:
// before the timeloop: struct tillage_parameters till_pars;
// also before the timeloop: allocating memory space to grids in till_pars.
if (normal.use_tillage == 1) {
sprintf(ch, "1result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "1field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
till(&dtm, &ero_pars.soildepth, &till_pars,ascii,ero_pars);
add_double_grid(&dtm,till_pars.till_result,ascii.nr,ascii.nc);
sprintf(ch, "2result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "2field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
}
printf(till_pars.fieldfile);
sprintf(ch, "4result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "4field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
if (normal.use_water_erosion == 1) {
define_cellstatus(dtm, &dep.status_map, numberofsinks, ascii);
define_depressions(dtm, &dep.status_map, ascii, &dep);
define_fillheight(ascii, &dep);
erode(dtm, &waterflow, &ero_pars, &dep, ascii, evaporation, infiltration, rainfall);
add_double_grid(&dtm,ero_pars.erosion,ascii.nr,ascii.nc);
add_double_grid(&dtm,ero_pars.sedimentation,ascii.nr,ascii.nc);
}
write_asc_dbl(dtm,"dtm_4",ascii);
write_asc_dbl(ero_pars.erosion,"w_erosion",ascii);
write_asc_dbl(ero_pars.sedimentation,"w_sedimentation",ascii);
printf(" calculated water_erosion\n");
printf(till_pars.fieldfile);
sprintf(ch, "5result 0 40 = %f\n", till_pars.till_result[0][40]);printf(ch);
sprintf(ch, "5field 0 40 = %d\n", till_pars.tillfields[0][40]);printf(ch);
} // end run time loopWith output to screen:
calculated tectonics
1result 0 40 = 0
1field 0 40 = 1
2result 0 40 = 0.030841
2field 0 40 = 1
tilfield 4result 0 40 = 0.030841
4field 0 40 = 1
calculated water_erosion
tilfield And then the error message I mentioned above. My direct question is: how is it possible that the grids from till_pars loose the space they occupy in memory, whereas they are never mentioned in / passed to the other submodule for water erosion? And if it is a memory problem, why did it not occur before, because all the structs are initiated and all memory is allocated much earlier than this section of the code.