//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int cohortsKilled = 0; int standPrescriptionNumber = 0; double biomassRemoved = 0.0; double biomassRemovedPerHa = 0.0; //ModelCore.UI.WriteLine("BiomassHarvest: PlugIn.cs: WriteLogEntry: mgmtArea {0}, Stand {1} ", mgmtArea.Prescriptions.Count, stand.MapCode); foreach (ActiveSite site in stand) { //set the prescription name for this site if (BaseHarvest.SiteVars.Prescription[site] != null) { standPrescriptionNumber = BaseHarvest.SiteVars.Prescription[site].Number; BaseHarvest.SiteVars.PrescriptionName[site] = BaseHarvest.SiteVars.Prescription[site].Name; BaseHarvest.SiteVars.TimeOfLastEvent[site] = modelCore.CurrentTime; } cohortsDamaged += SiteVars.CohortsPartiallyDamaged[site]; cohortsKilled += BaseHarvest.SiteVars.CohortsDamaged[site]; if (SiteVars.CohortsPartiallyDamaged[site] > 0 || BaseHarvest.SiteVars.CohortsDamaged[site] > 0) { damagedSites++; //Conversion from [g m-2] to [Mg ha-1] to [Mg] biomassRemoved += SiteVars.BiomassRemoved[site] / 100.0 * modelCore.CellArea; } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; totalCohortsDamaged[standPrescriptionNumber] += cohortsDamaged; totalCohortsKilled[standPrescriptionNumber] += cohortsKilled; //csv string for log file, contains species kill count string species_count = ""; //if this is the right species match, add it's count to the csv string foreach (ISpecies species in modelCore.Species) { bool assigned = false; //loop through dictionary of species kill count foreach (KeyValuePair<string, int> kvp in stand.DamageTable) { if (species.Name == kvp.Key) { assigned = true; species_count += "," + kvp.Value; totalSpeciesCohorts[standPrescriptionNumber, species.Index] += kvp.Value; } } if (!assigned) { //put a 0 there if it's not assigned (because none were found in the dictionary) species_count += ",0"; totalSpeciesCohorts[standPrescriptionNumber, species.Index] += 0; } } //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: biomassRemovedPerHa = biomassRemoved / (double) damagedSites / modelCore.CellArea; if(biomassRemoved <= 0.0) return; log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9:0.000},{10:0.000},{11},{12}{13}", modelCore.CurrentTime, mgmtArea.MapCode, stand.PrescriptionName, stand.MapCode, stand.EventId, stand.Age, stand.HarvestedRank, stand.SiteCount, damagedSites, biomassRemoved, // Mg biomassRemovedPerHa, // Mg/ha cohortsDamaged, cohortsKilled, species_count); }
//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int standPrescriptionNumber = 0; foreach (ActiveSite site in stand) { //set the prescription name for this site if (SiteVars.Prescription[site] != null) { standPrescriptionNumber = SiteVars.Prescription[site].Number; SiteVars.PrescriptionName[site] = SiteVars.Prescription[site].Name; SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime; } int cohortsDamagedAtSite = SiteVars.CohortsDamaged[site]; cohortsDamaged += cohortsDamagedAtSite; if (cohortsDamagedAtSite > 0) { damagedSites++; } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; //csv string for log file, contains species kill count string species_count = ""; //if this is the right species match, add it's count to the csv string foreach (ISpecies species in PlugIn.ModelCore.Species) { bool assigned = false; //loop through dictionary of species kill count foreach (KeyValuePair<string, int> kvp in stand.DamageTable) { if (species.Name == kvp.Key) { assigned = true; species_count += kvp.Value + ","; totalSpeciesCohorts[standPrescriptionNumber, species.Index] += kvp.Value; } } if (!assigned) { //put a 0 there if it's not assigned (because none were found in the dictionary) species_count += "0,"; } } //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: //current time //management area's map code //the prescription that caused this harvest //stand's map code //stand's age //stand's current rank //total sites in the stand //damaged sites from this stand //cohorts killed in this stand, by this harvest //and only record stands where a site has been damaged log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", PlugIn.ModelCore.CurrentTime, mgmtArea.MapCode, stand.PrescriptionName, stand.MapCode, stand.EventId, stand.Age, stand.HarvestedRank, stand.SiteCount, damagedSites, cohortsDamaged, species_count); }
//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int cohortsKilled = 0; int standPrescriptionNumber = 0; double biomassRemoved = 0.0; double biomassRemovedPerHa = 0.0; foreach (ActiveSite site in stand) { //set the prescription name for this site if (BaseHarvest.SiteVars.Prescription[site] != null) { standPrescriptionNumber = BaseHarvest.SiteVars.Prescription[site].Number; BaseHarvest.SiteVars.PrescriptionName[site] = BaseHarvest.SiteVars.Prescription[site].Name; BaseHarvest.SiteVars.TimeOfLastEvent[site] = modelCore.CurrentTime; } cohortsDamaged += SiteVars.CohortsPartiallyDamaged[site]; cohortsKilled += BaseHarvest.SiteVars.CohortsDamaged[site]; if (SiteVars.CohortsPartiallyDamaged[site] > 0 || BaseHarvest.SiteVars.CohortsDamaged[site] > 0) { damagedSites++; //Conversion from [g m-2] to [Mg] biomassRemoved += SiteVars.BiomassRemoved[site] / 100.0 * modelCore.CellArea; } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; totalCohortsDamaged[standPrescriptionNumber] += cohortsDamaged; totalCohortsKilled[standPrescriptionNumber] += cohortsKilled; //string for log file, contains species harvest count double[] species_count = new double[modelCore.Species.Count]; //if this is the right species match, add it's count to the csv string foreach (ISpecies species in modelCore.Species) { bool assigned = false; //loop through dictionary of species kill count foreach (KeyValuePair<string, int> kvp in stand.DamageTable) { if (species.Name == kvp.Key) { assigned = true; species_count[species.Index] += kvp.Value; } } if (!assigned) { //put a 0 there if it's not assigned (because none were found in the dictionary) species_count[species.Index] = 0.0; } totalSpeciesCohorts[standPrescriptionNumber, species.Index] += (double) species_count[species.Index]; } //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: biomassRemovedPerHa = biomassRemoved / (double)damagedSites / modelCore.CellArea; if (biomassRemoved <= 0.0) return; eventLog.Clear(); EventsLog el = new EventsLog(); el.Time = modelCore.CurrentTime; el.ManagementArea = mgmtArea.MapCode; el.Prescription = stand.PrescriptionName; el.StandMapCode = stand.MapCode; el.EventID = stand.EventId; el.StandAge = stand.Age; el.StandRank = stand.HarvestedRank; el.StandSiteCount = stand.SiteCount; el.HarvestedSites = damagedSites; el.MgBiomassRemoved = biomassRemoved; // Mg el.MgBioRemovedPerDamagedHa = biomassRemovedPerHa; // Mg/ha el.CohortsHarvestedPartial = cohortsDamaged; el.CohortsHarvestedComplete = cohortsKilled; el.CohortsHarvested_ = species_count; eventLog.AddObject(el); eventLog.WriteToFile(); }