*! 1.2.0 05Aug1997 jw/ics STB-45 ip14.1 * -- default formatting of real numbers %9.0g * -- fixed rounding bug in case of negative increments * -- replaced insertion-sort by quicksort * 1.1.1 30 Jul 1997 jw/ics * -- fixed bug: empty numlist combined with options * 1.1.0 03 Jan 1997 (submitted with STB) * -- added -sort- * -- added -format- * 1.0.0 Apr 96, Jeroen Weesie/ICS program define numlist version 5.0 * parse off and check options parse "`*'", p(",") if "`1'" == "," { global S_1 global S_2 0 exit } local terms "`1'" if "`2'" ~= "" & "`2'" ~= "," { exit 198 } local options "Display MIn(str) MAx(str) Real Sort Format(str)" parse ",`3'" * type of numbers if "`real'" == "" { local nmbtype "integer" } else local nmbtype * restrictions on number of terms if "`min'" ~= "" { confirm integer number `min' } if "`max'" ~= "" { confirm integer number `max' } if "`min'" ~= "" & "`max'" ~= "" { if `min' > `max' { di in re "numlist: invalid (min, max)" exit 198 } } if "`format'" ~= "" { capture local f : display `format' 1 if _rc { di in re "invalid format `format'" exit 120 } } else local format "%9.0g" * parse the terms parse "`terms'", p(" ") while "`1'" ~= "" { local term `1' local inc local rng2 * term = number * = number-number * = number-number/number * split [term] in [term / inc] local pinc = index("`term'","/") if `pinc' > 0 { local inc = substr("`term'",`pinc'+1,.) confirm `nmbtype' number `inc' if `inc' == 0 { di in re "numlist: Increment is zero!" exit 198 } local term = substr("`term'", 1, `pinc'-1) } * check if range is specified; beware of trailing - local prng = index(substr("`term'",2,.),"-")+1 if `prng' > 1 { local rng1 = substr("`term'",1,`prng'-1) local rng2 = substr("`term'",`prng'+1,.) confirm `nmbtype' number `rng1' confirm `nmbtype' number `rng2' if "`inc'" == "" { local inc 1 } local nincr = 1 + int((float(`rng2')-float(`rng1'))/float(`inc')+1E-6) if `nincr' <= 0 { di in re "range n-m/incr should imply an infinite number of terms" exit 1000 /* "system limit exceeded */ } * loop rng1-rng2/inc while `nincr' > 0 { local f : display `format' `rng1' local f = trim("`f'") local nlist "`nlist'`f' " local rng1 = `rng1' + `inc' local nincr = `nincr' - 1 } } else { * no increment expected at this point if "`inc'" ~= "" { di in re "numlist : invalid /" exit 198 } confirm `nmbtype' number `term' local nlist "`nlist'`term' " } mac shift } * sort list in ascending order if "`sort'" ~= "" { capture qsort "`nlist'" , a if _rc { di in re "error in sorting. Was -qsort- installed?" exit 198 } local nlist "$S_1" } * check min <= #terms <= max local nnl : word count `nlist' if "`min'" ~= "" { if `nnl' < `min' { di in re "numlist: at least `min' values required, `nnl' specified" exit 198 } } if "`max'" ~= "" { if `nnl' > `max' { di in re "numlist: at most `max' values allowed, `nnl' specified" exit 198 } } if "`display'" ~= "" { di in gr "numlist: " in ye "`nlist'" } global S_1 "`nlist'" global S_2 "`nnl'" end