public InputParameters() { prescriptions = new List <Prescription>(); managementAreas = new ManagementAreaDataset(); }
//--------------------------------------------------------------------- /// <summary> /// Reads harvest implementations: which prescriptions are applied to /// which management areas. /// </summary> protected void ReadHarvestImplementations(ManagementAreaDataset mgmtAreas, List <Prescription> prescriptions) { ReadName(Names.HarvestImplementations); InputVar <ushort> mgmtAreaMapCode = new InputVar <ushort>("Mgmt Area"); InputVar <string> prescriptionName = new InputVar <string>("Prescription"); InputVar <int> beginTimeVar = new InputVar <int>("Begin Time"); InputVar <int> endTimeVar = new InputVar <int>("End Time"); InputVar <Percentage> areaToHarvest = new InputVar <Percentage>("Area To Harvest"); while (!AtEndOfInput && CurrentName != Names.PrescriptionMaps) { StringReader currentLine = new StringReader(CurrentLine); // Mgmt Area column ReadValue(mgmtAreaMapCode, currentLine); ushort mapCode = mgmtAreaMapCode.Value.Actual; ManagementArea mgmtArea = mgmtAreas.Find(mapCode); if (mgmtArea == null) { //add the management area, and add it to the collection of management areas mgmtArea = new ManagementArea(mapCode); mgmtAreas.Add(mgmtArea); } // Prescription column ReadValue(prescriptionName, currentLine); string name = prescriptionName.Value.Actual; Prescription prescription = prescriptions.Find(new MatchName(name).Predicate); if (prescription == null) { throw new InputValueException(prescriptionName.Value.String, prescriptionName.Value.String + " is an unknown prescription name"); } // Area to Harvest column ReadValue(areaToHarvest, currentLine); //get percentage to harvest (type Percentage ensures that it is in percent format) Percentage percentageToHarvest = areaToHarvest.Value.Actual; //check for valid percentage if (percentageToHarvest <= 0.0 || percentageToHarvest > 1.0) { throw new InputValueException(areaToHarvest.Value.String, "Percentage must be between 0% and 100%"); } // Begin Time and End Time columns // They are optional, so the possibilities are: // // Begin Time End Time // ---------- -------- // 1) present present // 2) present missing // 3) missing missing // The default values for the starting and ending times for // an applied prescription. int beginTime = scenarioStart; int endTime = scenarioEnd; TextReader.SkipWhitespace(currentLine); if (currentLine.Peek() != -1) { ReadValue(beginTimeVar, currentLine); beginTime = beginTimeVar.Value.Actual; if (beginTime < scenarioStart) { throw new InputValueException(beginTimeVar.Value.String, string.Format("Year {0} is before the scenario start year ({1})", beginTimeVar.Value.String, scenarioStart)); } if (beginTime > scenarioEnd) { //throw new InputValueException(beginTimeVar.Value.String, // string.Format("Year {0} is after the scenario' end year ({1})", // beginTimeVar.Value.String, // scenarioEnd)); string line1 = string.Format(" NOTE: Begin year {0} is after the scenario' end year {1}", beginTimeVar.Value.String, scenarioEnd); string line2 = string.Format(" on line {0} of the harvest input file...", LineNumber); List <string> noteList = new List <string>(); noteList.Add(line1); noteList.Add(line2); parserNotes.Add(noteList); } TextReader.SkipWhitespace(currentLine); if (currentLine.Peek() != -1) { ReadValue(endTimeVar, currentLine); endTime = endTimeVar.Value.Actual; if (endTime < beginTime) { throw new InputValueException(endTimeVar.Value.String, string.Format("Year {0} is before the Begin Time ({1})", endTimeVar.Value.String, beginTimeVar.Value.String)); } if (endTime > scenarioEnd) { // throw new InputValueException(endTimeVar.Value.String, // string.Format("Year {0} is after the scenario' end year ({1})", // endTimeVar.Value.String, // scenarioEnd)); string line1 = string.Format(" NOTE: End Year {0} is after the scenario' end year {1}", endTimeVar.Value.String, scenarioEnd); string line2 = string.Format(" on line {0} of the harvest input file...", LineNumber); List <string> noteList = new List <string>(); noteList.Add(line1); noteList.Add(line2); parserNotes.Add(noteList); } CheckNoDataAfter("the " + endTimeVar.Name + " column", currentLine); } } //if the perscription has already been applied to this management area //NOTE: .IsApplied has been modified, and this has been moved to AFTER the //begin and end times are founded. if (mgmtArea.IsApplied(prescriptionName.Value.String, beginTime, endTime)) { throw new InputValueException(prescriptionName.Value.String, "Prescription {0} has already been applied to management area {1} with begin time = {2} and end time = {3}", prescriptionName.Value.String, mgmtArea.MapCode, beginTime, endTime); } //begin applying prescription to this management area mgmtArea.ApplyPrescription(prescription, percentageToHarvest, beginTime, endTime); CheckNoDataAfter("the " + prescriptionName.Name + " column", currentLine); GetNextLine(); } }
//--------------------------------------------------------------------- /// <summary> /// Reads harvest implementations: which prescriptions are applied to /// which management areas. /// </summary> protected void ReadHarvestImplementations(ManagementAreaDataset mgmtAreas, List <Prescription> prescriptions) { ReadName(Names.HarvestImplementations); InputVar <ushort> mgmtAreaMapCode = new InputVar <ushort>("Mgmt Area"); InputVar <string> prescriptionName = new InputVar <string>("Prescription"); InputVar <int> beginTimeVar = new InputVar <int>("Begin Time"); InputVar <int> endTimeVar = new InputVar <int>("End Time"); InputVar <Percentage> areaToHarvest = new InputVar <Percentage>("Area To Harvest"); InputVar <Percentage> standsToHarvest = new InputVar <Percentage>("Stands To Harvest"); StringReader sr100 = new StringReader("100%"); while (!AtEndOfInput && CurrentName != Names.PrescriptionMaps) { StringReader currentLine = new StringReader(CurrentLine); // Mgmt Area column ReadValue(mgmtAreaMapCode, currentLine); ushort mapCode = mgmtAreaMapCode.Value.Actual; ManagementArea mgmtArea = mgmtAreas.Find(mapCode); if (mgmtArea == null) { //add the management area, and add it to the collection of management areas mgmtArea = new ManagementArea(mapCode); mgmtAreas.Add(mgmtArea); } // Prescription column ReadValue(prescriptionName, currentLine); string name = prescriptionName.Value.Actual; Prescription prescription = prescriptions.Find(new MatchName(name).Predicate); if (prescription == null) { throw new InputValueException(prescriptionName.Value.String, prescriptionName.Value.String + " is an unknown prescription name"); } TextReader.SkipWhitespace(currentLine); // Area to Harvest column string strVal = TextReader.ReadWord(currentLine); sr100 = new StringReader("100%"); //If the keyword 'Stands' is attached to the area %, then applies to % of stands to harvest instead of area if (strVal.Contains("Stands")) { char[] trimChar = { 'S', 't', 'a', 'n', 'd', 's' }; string clipText = strVal.TrimEnd(trimChar); StringReader testRead = new StringReader(clipText); ReadValue(standsToHarvest, testRead); ReadValue(areaToHarvest, sr100); } else { StringReader testRead = new StringReader(strVal); // Area to Harvest column ReadValue(areaToHarvest, testRead); ReadValue(standsToHarvest, sr100); } //get percentage to harvest (type Percentage ensures that it is in percent format) Percentage percentageToHarvest = areaToHarvest.Value.Actual; //check for valid percentage if (percentageToHarvest <= 0.0 || percentageToHarvest > 1.0) { throw new InputValueException(areaToHarvest.Value.String, "Percentage must be between 0% and 100%"); } //get percentage of stands to harvest (type Percentage ensures that it is in percent format) Percentage percentStandsToHarvest = standsToHarvest.Value.Actual; //check for valid percentage if (percentStandsToHarvest <= 0.0 || percentStandsToHarvest > 1.0) { throw new InputValueException(standsToHarvest.Value.String, "Percentage must be between 0% and 100%"); } // Begin Time and End Time columns // They are optional, so the possibilities are: // // Begin Time End Time // ---------- -------- // 1) present present // 2) present missing // 3) missing missing // The default values for the starting and ending times for // an applied prescription. int beginTime = scenarioStart; int endTime = scenarioEnd; TextReader.SkipWhitespace(currentLine); if (currentLine.Peek() != -1) { ReadValue(beginTimeVar, currentLine); beginTime = beginTimeVar.Value.Actual; if (beginTime < scenarioStart) { throw new InputValueException(beginTimeVar.Value.String, string.Format("Year {0} is before the scenario start year ({1})", beginTimeVar.Value.String, scenarioStart)); } if (beginTime > scenarioEnd) { throw new InputValueException(beginTimeVar.Value.String, string.Format("Year {0} is after the scenario' end year ({1})", beginTimeVar.Value.String, scenarioEnd)); } TextReader.SkipWhitespace(currentLine); if (currentLine.Peek() != -1) { ReadValue(endTimeVar, currentLine); endTime = endTimeVar.Value.Actual; if (endTime < beginTime) { throw new InputValueException(endTimeVar.Value.String, string.Format("Year {0} is before the Begin Time ({1})", endTimeVar.Value.String, beginTimeVar.Value.String)); } if (endTime > scenarioEnd) { throw new InputValueException(endTimeVar.Value.String, string.Format("Year {0} is after the scenario' end year ({1})", endTimeVar.Value.String, scenarioEnd)); } CheckNoDataAfter("the " + endTimeVar.Name + " column", currentLine); } } //if the perscription has already been applied to this management area //NOTE: .IsApplied has been modified, and this has been moved to AFTER the //begin and end times are founded. if (mgmtArea.IsApplied(prescriptionName.Value.String, beginTime, endTime)) { throw new InputValueException(prescriptionName.Value.String, "Prescription {0} has already been applied to management area {1} with begin time = {2} and end time = {3}", prescriptionName.Value.String, mgmtArea.MapCode, beginTime, endTime); } //begin applying prescription to this management area mgmtArea.ApplyPrescription(prescription, percentageToHarvest, percentStandsToHarvest, beginTime, endTime); CheckNoDataAfter("the " + prescriptionName.Name + " column", currentLine); GetNextLine(); } }