/** Adds a parameter to a light curve specification if the appropriate * command line argument was used * * @param[in] range the @ref models::RangeList "RangeList" to update * @param[in] paramName the name of the parameter * @param[in] paramValue the command-line argument to translate into a range * @param[in] distrib the distribution values follow within the range * * @post If @p paramValue was specified on the command line, the corresponding * parameter range is added to @p range. Otherwise, @p range is unchanged. * * @exception lcmc::utils::except::UnexpectedNan Thrown if either element of * @p paramValue is NaN * @exception lcmc::stats::except::ExtraParam Thrown if a value for the parameter is * already in the list * @exception lcmc::stats::except::NegativeRange Thrown if * @p paramValue.second > @p paramValue.first * @exception std::invalid_argument Thrown if @p distrib is not a valid value. * * @exception std::bad_alloc Thrown if there is not enough memory to * add an element to the list. * * @exceptsafe The arguments are unchanged in the event of an exception. */ void addParam(RangeList& range, const ParamType& paramName, ValueArg< std::pair<double, double> >& paramValue, RangeList::RangeType distrib) { if (paramValue.isSet()) { range.add(paramName, paramValue.getValue(), distrib); } }
/** Parses the command line parameters that describe model parameter ranges * * @param[in] cmd The command-line parser used by the program * @param[out] range A rangelist to contain the parameter ranges. * * @exception std::logic_error Thrown if the expected parameters are missing from @p cmd. * * @exceptsafe All arguments are left in valid states in the event * of an exception. */ void parseModelParams(CmdLineInterface& cmd, RangeList& range) { range.clear(); addParam(range, "a", getParam<ValueArg<Range> >(cmd, "amp"), RangeList::LOGUNIFORM); addParam(range, "p", getParam<ValueArg<Range> >(cmd, "period"), RangeList::LOGUNIFORM); // Include default phase if no user input range.add("ph", getParam<ValueArg<Range> >(cmd, "ph").getValue(), RangeList::UNIFORM); addParam(range, "width", getParam<ValueArg<Range> >(cmd, "width"), RangeList::LOGUNIFORM); addParam(range, "width2", getParam<ValueArg<Range> >(cmd, "width2"), RangeList::LOGUNIFORM); addParam(range, "d", getParam<ValueArg<Range> >(cmd, "diffus"), RangeList::LOGUNIFORM); addParam(range, "amp2", getParam<ValueArg<Range> >(cmd, "amp2"), RangeList::LOGUNIFORM); addParam(range, "period2", getParam<ValueArg<Range> >(cmd, "period2"), RangeList::LOGUNIFORM); }
RangeList<T> subtract (Range<T> range, RangeList<T> sub) { /* Start with the input range */ RangeList<T> result; result.add (range); if (sub.empty () || range.empty()) { return result; } typename RangeList<T>::List s = sub.get (); /* The basic idea here is to keep a list of the result ranges, and subtract the bits of `sub' from them one by one. */ for (typename RangeList<T>::List::const_iterator i = s.begin(); i != s.end(); ++i) { /* Here's where we'll put the new current result after subtracting *i from it */ RangeList<T> new_result; typename RangeList<T>::List r = result.get (); /* Work on all parts of the current result using this range *i */ for (typename RangeList<T>::List::const_iterator j = r.begin(); j != r.end(); ++j) { switch (coverage (j->from, j->to, i->from, i->to)) { case OverlapNone: /* The thing we're subtracting (*i) does not overlap this bit of the result (*j), so pass it through. */ new_result.add (*j); break; case OverlapInternal: /* Internal overlap of the thing we're subtracting (*i) from this bit of the result, so we should end up with two bits of (*j) left over, from the start of (*j) to the start of (*i), and from the end of (*i) to the end of (*j). */ assert (j->from < i->from); assert (j->to > i->to); new_result.add (Range<T> (j->from, i->from - 1)); new_result.add (Range<T> (i->to + 1, j->to)); break; case OverlapStart: /* The bit we're subtracting (*i) overlaps the start of the bit of the result (*j), * so we keep only the part of of (*j) from after the end of (*i) */ assert (i->to < j->to); new_result.add (Range<T> (i->to + 1, j->to)); break; case OverlapEnd: /* The bit we're subtracting (*i) overlaps the end of the bit of the result (*j), * so we keep only the part of of (*j) from before the start of (*i) */ assert (j->from < i->from); new_result.add (Range<T> (j->from, i->from - 1)); break; case OverlapExternal: /* total overlap of the bit we're subtracting with the result bit, so the result bit is completely removed; do nothing */ break; } } new_result.coalesce (); result = new_result; } return result; }