/* **************************************************** iLand Spinup Library Werner Rammer, 2017 see details: iland.boku.ac.at/spinup **************************************************** */ console.log("loading spinuplib.js"); // helper function that simplifies to execute a function in the context of a particular stand // e.g.: run_as(123, function() { fmengine.log(stand.id); } ); function run_as(stand_id, what) { var old = fmengine.standId; fmengine.standId=stand_id; what(); fmengine.standId=old; } /** create a String representation of an Javascript object */ function toString(obj) { return JSON.stringify(obj, null, 4); } /** create a String representation of an Javascript object */ function toFlatString(obj) { return toString(obj).replace(/(?:\r\n|\r|\n)/g, ' '); } /** print a string representation of an Javascript object to the console */ function printObj( obj) { console.log(JSON.stringify(obj, null, 4)); } /** simple function to duplicate an object. Note that functions are not copied! */ function cloneObj( obj ) { return JSON.parse(JSON.stringify(obj)); } function speciesShareString() { var s=""; for (var i=0;i=0.1) { if (current[s]==undefined) current[s] = target[s]; else current[s] += curr_diff; // save species which show strong overestimating if (current[s]<-0.1) res.extra[s] = -current[s]; } } for (s in state) { if (state[s]>0.1 && target[s]===undefined) res.extra[s] = 0.1; } // fix/rescale current var csum = 0; for (s in current) csum += Math.max(current[s],0); for (s in current) current[s] = Math.max(current[s]/csum,0); res['current'] = current; return res; } // Tending, from WBT project function calculateSpeciesProbabilities(plan_rel, pct_reduction, min_value_remaining) { // collect basal areas var state_abs = {}; var total = 0; for (var i=0;i0) plan[s] /= state_abs[s]; else plan[s] = 1; // do nothing when nothing is in state } return plan; }