49 lines
1.7 KiB
Plaintext
49 lines
1.7 KiB
Plaintext
/* Modified 19 November 2011 to meet requirement that there be at */
|
|
/* least 3 items in a run. */
|
|
range_extraction: /* 17 August 2010 */
|
|
procedure options (main);
|
|
declare (c, d) character (1);
|
|
declare (old, new, initial) fixed binary (31);
|
|
declare in file;
|
|
declare out file output;
|
|
|
|
open file (in) title ('/range2.dat,type(text),recsize(80)' );
|
|
open file (out) output title ('/range2.out,type(text),recsize(70)');
|
|
|
|
c = ' '; d = ',';
|
|
get file (in) list (old);
|
|
do forever;
|
|
initial = old;
|
|
on endfile (in) begin;
|
|
put file (out) edit (c, trim(old)) (a);
|
|
stop;
|
|
end;
|
|
get file (in) list (new);
|
|
if new = old+1 then
|
|
do; /* we have a run. */
|
|
on endfile (in) begin;
|
|
if old > initial+1 then d = '-';
|
|
put file (out) edit (c, trim(initial), d, trim(old) ) (a);
|
|
stop;
|
|
end;
|
|
do while (new = old+1);
|
|
old = new;
|
|
get file (in) list (new);
|
|
end;
|
|
/* At this point, old holds the last in a run; */
|
|
/* initial holds the first in a run. */
|
|
/* if there are only two members in a run, don't use the */
|
|
/* range notation. */
|
|
if old > initial+1 then d = '-';
|
|
put file (out) edit (c, trim(initial), d, trim(old) ) (a);
|
|
old = new;
|
|
end;
|
|
else /* we have an isolated value. */
|
|
do;
|
|
put file (out) edit (c, trim(old)) (a);
|
|
old = new;
|
|
end;
|
|
c, d = ',';
|
|
end;
|
|
end range_extraction;
|