// Calculates rates of growth, mortality and fecundity for individual with size m. Memory for GMR[5] must be allocated elsewhere // Env[] contains estimates of light environment at different depths in the canopy used in calculating production. void Strategy::Grow_Mort_Repro(vector<double>& GMR, double m, const double Env[], double t) { GMR[3] = Production(Env, m); // GPP GMR[6] = Respiration(m); // Maintenance respiration GMR[4] = (*p).Y * (GMR[3] - GMR[6]); // NPP GMR[5] = Turnover(m); // Tissue turnover double dmdt = GMR[4] - GMR[5]; // NET PRODUCTION GMR[0] = (1 - r_alloc(m)) / dTotalMass_dm(m) * max(0.0, dmdt); // GROWTH - only positive growth allowed GMR[1] = mortality(dmdt, m); // MORTALITY GMR[2] = (*p).Pi_0 * (max(0.0, dmdt) * r_alloc(m)) / ((*p).c_acc * total_mass_at_birth); // REPRODUCTION // Check for NaN in mortality if ((!(GMR[1] >= 0) && !(GMR[1] < 0))) cout << "Mort " << lma << "\t" << GMR[1] << "\t" << dmdt << "\t" << m << "\t" << LfAr(m) << "\t" << dmdt / LfAr(m) << "\t" << exp((*p).c_d1 * rho + (*p).c_d2 * dmdt / LfAr(m)) << endl; }
/* * Vm_CopyValid. Copy a variable's valid structure * * return FAIL if out of pooled memory. If you * pass NULL for pool, then it's ok to ignore * the return code (because tae_alloc always * returns with memory or aborts). * */ FUNCTION CODE Vm_CopyValid( FUNINT type, /* in: variable type */ GENPTR in, /* in: valid structure */ GENPTR out, /* out: valid structure */ GENPTR pool /* in: NULL for tae_allocation */ /* or pool for r_allocation */ ) { FAST struct R_VALID *vin, *vout; /* use any type to get count */ struct S_VALID *svalidIn; struct S_VALID *svalidOut; COUNT i, length; TEXT *s; /* valid string pointer */ vin = (struct R_VALID *)in; vout = (struct R_VALID *)out; bytmov (in, out, Vm_ValidSize (type, (*vin).count)); (*vout).count = (*vin).count; #ifdef POINTER_VALIDS if (type == V_STRING) { svalidIn = (struct S_VALID *) vin; svalidOut = (struct S_VALID *) vout; for (i=0; i < (*svalidIn).count; i++) { length = s_length ((*svalidIn).slist[i].string); if (pool) { s = (TEXT *) r_alloc ((ALIGN *)pool, length+1); /* pooled allocation */ if (s == NULL) return (FAIL); } else s = (TEXT *) tae_alloc (1, length+1); /* free allocation */ s_copy ((*svalidIn).slist[i].string, s); (*svalidOut).slist[i].string = s; } } #endif return(SUCCESS); }
void r_hash_init(struct r_hash_table *ht, uint32_t order) { R_PRE(order < 32); ht->ht_chain = r_alloc((1 << order) * sizeof ht->ht_chain[0]); ht->ht_order = order; }