//--------------------------------------------------------------------- /// <summary> /// Reads a cohort age or a range of ages (format: age-age) followed /// by an optional percentage for partial thinning. /// </summary> /// <remarks> /// The optional percentage is bracketed by parenthesis. /// </remarks> public static InputValue <AgeRange> ReadAgeOrRange(StringReader reader, out int index) { TextReader.SkipWhitespace(reader); index = reader.Index; string word = ReadWord(reader, '('); if (word == "") { throw new InputValueException(); // Missing value } AgeRange ageRange = AgeRangeParsing.ParseAgeOrRange(word); // Does a percentage follow? TextReader.SkipWhitespace(reader); if (reader.Peek() == '(') { int ignore; InputValue <Percentage> percentage = ReadPercentage(reader, out ignore); percentages[ageRange.Start] = percentage; } return(new InputValue <AgeRange>(ageRange, word)); }
//--------------------------------------------------------------------- /// <summary> /// Reads a cohort age or a range of ages (format: age-age) followed /// by an optional percentage for partial thinning. /// </summary> /// <remarks> /// The optional percentage is bracketed by parenthesis. /// </remarks> public static InputValue <AgeRange> ReadAgeOrRange(StringReader reader, out int index) { TextReader.SkipWhitespace(reader); index = reader.Index; string word = ReadWord(reader, '('); if (word == "") { throw new InputValueException(); // Missing value } AgeRange ageRange = AgeRangeParsing.ParseAgeOrRange(word); // Does a percentage follow? TextReader.SkipWhitespace(reader); if (reader.Peek() == '(') { InputValue <uint> removal = ReadTreeRemoval(reader); if (removal.String != "(100%)") { treeremovals[ageRange.Start] = removal; } } return(new InputValue <AgeRange>(ageRange, word)); }
//--------------------------------------------------------------------- static PartialThinning() { // Force the harvest library to register its read method for age // ranges. Then replace it with this project's read method that // handles percentages for partial thinning. AgeRangeParsing.InitializeClass(); InputValues.Register <AgeRange>(PartialThinning.ReadAgeOrRange); percentages = new Dictionary <ushort, Percentage>(); CohortSelectors = new PartialCohortSelectors(); }