Skip to content

Commit

Permalink
Many and poorly formatted debug print statements
Browse files Browse the repository at this point in the history
- addressing #126
- revert commit (or comment printf's out) once issue is resolved

- to recreate my output in the comments, run with `model.in`:
 # niter nyrs  seed
 1 100 3
  • Loading branch information
dschlaep committed Jun 1, 2018
1 parent 6072ad6 commit bf452a5
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 46 deletions.
40 changes: 35 additions & 5 deletions ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,19 @@ void indiv_proportion_Recovery( IndivType *ndv, int killType,RealF proportionRec

// using individual killing year old real size and reduction for making base for calculating proportional recovery
RealF prev_reduction = ndv->prv_yr_relsize * proportionKilled;
RealF increase = prev_reduction * proportionRecovery;
RealF increase = prev_reduction * proportionRecovery;
ndv->relsize = ndv->relsize + increase;
Species_Update_Newsize(ndv->myspecies, increase);

if (ZERO(ndv->relsize) || LT(ndv->relsize, 0.0))
{
// this should never happend because `increase` should always be positive
LogError(logfp, LOGWARN, "'indiv_proportion_Recovery': an individual of "\
"%s reached relsize of 0 and is removed (increase = %.3f): for " \
"killType = %d, proportionKilled = %.2f, proportionRecovery = %.2f",
Species[ndv->myspecies]->name, increase,
killType, proportionKilled, proportionRecovery);

_delete(ndv);
}
#undef xF_DELTA
Expand Down Expand Up @@ -343,16 +350,35 @@ void indiv_Kill_Complete( IndivType *ndv, int killType) {
// if(!UseGrid)
// insertIndivKill(ndv->id,killType);
species_Update_Kills(ndv->myspecies, ndv->age);

if (Species[ndv->myspecies]->res_grp == 6 && Species[ndv->myspecies]->sp_num == 11) {
printf("'indiv_Kill_Complete' after 'species_Update_Kills': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, ndv->relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, ndv->relsize, Species[11]->est_count);
}

Species_Update_Newsize(ndv->myspecies, -ndv->relsize);
_delete(ndv);

if (Species[ndv->myspecies]->res_grp == 6 && Species[ndv->myspecies]->sp_num == 11) {
printf("'indiv_Kill_Complete' after 'Species_Update_Newsize': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
}

_delete(ndv); // `_delete` updates the Species[ndv->myspecies]->est_count, i.e., removes one individual

}

/**************************************************************/
void _delete (IndivType *ndv) {
/*======================================================*/
/* PURPOSE */
/* Local routine to remove the data object of an individual.
/* Local routine to remove the data object of an individual and update
* the number of individuals `Species[ndv->myspecies]->est_count`
* Called from indiv_Kill_Complete().
*/
/* HISTORY */
Expand Down Expand Up @@ -387,9 +413,13 @@ void _delete (IndivType *ndv) {
ndv->Next->Prev = ndv->Prev;
}

if( --s->est_count == 0)
// update Species[ndv->myspecies]->est_count, i.e.,
// remove one individual from tally
if( --s->est_count == 0) {
// if there are no individual left of this species, then remove species
// from resource group and update `est_count` of the resource group
rgroup_DropSpecies(sp);

}

if ((s->est_count > 0 && s->IndvHead == NULL)
|| (s->est_count == 0 && s->IndvHead != NULL))
Expand Down
86 changes: 81 additions & 5 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,45 +195,121 @@ int main(int argc, char **argv) {
/* ------ Begin running the model ------ */
for (year = 1; year <= Globals.runModelYears; year++) {

//printf("------------------------Repetition/year = %d / %d\n", iter, year);
printf("------------------------Repetition/year = %d / %d\n", iter, year);

Globals.currYear = year;

rgroup_Establish();
printf("'main' after 'rgroup_Establish': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'rgroup_Establish'");

Env_Generate();

rgroup_PartResources();
printf("'main' after 'rgroup_PartResources': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'rgroup_PartResources'");

#ifdef STEPWAT
if (!isnull(SXW.debugfile) ) SXW_PrintDebug(0);
#endif

rgroup_Grow();
printf("'main' after 'rgroup_Grow': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'rgroup_Grow'");

mort_Main(&killedany);
printf("'main' after 'mort_Main': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'mort_Main'");

rgroup_IncrAges();
printf("'main' after 'rgroup_IncrAges': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'rgroup_IncrAges'");

// Added functions for Grazing and mort_end_year as proportional killing effect before exporting biomass end of the year
grazing_EndOfYear();
save_annual_species_relsize();
printf("'main' after 'grazing_EndOfYear': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'grazing_EndOfYear'");


save_annual_species_relsize();
printf("'main' after 'save_annual_species_relsize': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'save_annual_species_relsize'");


mort_EndOfYear();
printf("'main' after 'mort_EndOfYear': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'mort_EndOfYear'");

stat_Collect(year);
printf("'main' after 'stat_Collect': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'stat_Collect'");

if (BmassFlags.yearly)
output_Bmass_Yearly(year);

// Moved kill annual and kill extra growth after we export biomass, and recovery of biomass after fire before the next year
_kill_annuals();
proportion_Recovery();
printf("'main' after '_kill_annuals': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after '_kill_annuals'");

proportion_Recovery();
printf("'main' after 'proportion_Recovery': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
check_sizes("'main' after 'proportion_Recovery'");

_kill_extra_growth();

// Check that relsizes match up at end of year after extra growth is removed
// may want to wrap this in #ifdef DEBUG once problem is fixed
check_sizes("'main' at end of year");
printf("'main' after '_kill_extra_growth': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
} /* end model run for this year*/

if (MortFlags.summary) {
Expand Down Expand Up @@ -550,15 +626,15 @@ void check_sizes(const char *chkpt) {

if (LT(diff, fabs(spsize - Species[sp]->relsize)) ) {
LogError(stdout, LOGWARN, "%s (%d:%d): SP: \"%s\" size error: "
"SP=%.9f, ndv=%.9f\n",
"SP=%.3f, ndv=%.3f",
chkpt, Globals.currIter, Globals.currYear,
Species[sp]->name, Species[sp]->relsize, spsize);
}
}

if ( LT(diff, fabs(rgsize -RGroup[rg]->relsize)) ) {
LogError(stdout, LOGWARN, "%s (%d:%d): RG \"%s\" size error: "
"RG=%.9f, ndv=%.9f\n",
"RG=%.3f, ndv=%.3f",
chkpt, Globals.currIter, Globals.currYear,
RGroup[rg]->name, RGroup[rg]->relsize, rgsize);
}
Expand Down
66 changes: 66 additions & 0 deletions ST_mortality.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ void mort_Main( Bool *killed) {
if ( GT(g->pr, 1.0) ) {
if (++g->yrs_neg_pr >= g->max_stretch)
_no_resources( rg);

if (rg == 6) printf("'mort_Main' after '_no_resources': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);

} else {
g->yrs_neg_pr = 0;
}
Expand All @@ -157,7 +164,21 @@ void mort_Main( Bool *killed) {
/* Take care of mortality types 1 and 2*/
if ( g->use_mort ) {
_age_independent( sp );

if (rg == 6 && sp == 11) printf("'mort_Main' after '_age_independent': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);

_slow_growth( sp );

if (rg == 6 && sp == 11) printf("'mort_Main' after '_slow_growth': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);

}
/* now deal with succulents problems*/
if (g->succulent
Expand All @@ -176,6 +197,13 @@ void mort_Main( Bool *killed) {
case Burrow:
_burrow( sp);
break;

if (rg == 6 && sp == 11) printf("'mort_Main' after 'Plot.disturbance': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);

}

} /* end for each species*/
Expand Down Expand Up @@ -598,14 +626,52 @@ static void _age_independent( const SppIndex sp) {
kills[++k] = ndv;
}

if (Species[sp]->res_grp == 6 && sp == 11) {
int kk = 0;
printf("'_age_independent': individuals of %s/%s with relsize = %.2f\n",
RGroup[6]->name, Species[11]->name, Species[11]->relsize);

ForEachIndiv (ndv, Species[sp]) {
printf("\t%d, relsize = %.2f\n",
kk, ndv->relsize);
kk++;
}

printf("'_age_independent': individuals of %s/%s slated to kill\n",
RGroup[6]->name, Species[11]->name);

for( n=0; n <= k; n++ ) {
printf("\t%d, relsize = %.2f\n", n, kills[n]->relsize);
}
}


for( n=0; n <= k; n++ ) {
printf("'_age_independent' calling 'indiv_Kill_Complete': n=%d <= k=%d\n", n, k);
indiv_Kill_Complete(kills[n], 9);
}

if (Species[sp]->res_grp == 6 && sp == 11) {
printf("'_age_independent' after 'indiv_Kill_Complete': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
}

if (k >= 0) _SomeKillage = TRUE;

Mem_Free(kills);


if (Species[sp]->res_grp == 6 && sp == 11) {
printf("'_age_independent' after 'Mem_Free': \n" \
"\t%s, relsize = %.2f, est_count = %d\n" \
"\t%s, relsize = %.2f, est_count = %d\n",
RGroup[6]->name, RGroup[6]->relsize, RGroup[6]->est_count,
Species[11]->name, Species[11]->relsize, Species[11]->est_count);
}

}

/***********************************************************/
Expand Down
Loading

0 comments on commit bf452a5

Please sign in to comment.