program generate;

**********************************************************************
*                                                                    *
* SURVEY OF CONSUMER FINANCES            EMPLOYER SPONSORED PENSIONS *
*                                                                    *
*                     BENEFIT ESTIMATION PROGRAM                     *
*                                                                    *
* RICHARD CURTIN                                     PAUL PICKELMANN *
*                                                    SCOT ALLEN      *
*                                                                    *
*                (c) 1986  THE UNIVERSITY OF MICHIGAN                *
*                                                                    *
**********************************************************************

const
  maxnumvar =  4500;
  maxvarnum = 13202;
  linelength= 18470;
  maxnumdate=    20;10<x<20
  n = 'n';  x = 'x';  z = 'z';
type
  normal   = packed 0..32767;
  defkinds = (defxxx,defasy,defbeg,defdat,deflng,defras,defred,defrot);
  defnums  = 0..18;
  deftypes = (undef,adddef,multdef,absdef,reldef,nulldef);
  formx    = 1..120;
def
  failfile: text;
var
  name: string(5);  nn: defnums;  namekind: defkinds;
  id: string(6);
  time,
  date: alfa;
  notefile,
  passfail: text;
  cv,fv,
  cc,
  numform,
  numprob,
  numnote,
  numvar,
  lastvar,
  nextcol,
  totcase,
  totfail,
  totnote,
  totpass,
   nrpass,
   lrpass,
   erpass,
   vdpass,
   drpass,
   dspass,
   cnpass,
   vspass,
   a6pass,
  totprob: normal;
  totform,
  profcnt, fortcnt,
  totpfrm: integer;
  caseok,
  dbenifit,
  dcontrib,
  firstline,
  listing,
  listname: boolean;
  defined:  arraydefkinds,defnums of deftypes;
  numdate:  0..maxnumdate;
  dname:    array0..maxnumdate of string(5);
  ddate:    array0..maxnumdate of integer;
  lastgroup: string(255);
  lastvalue: string(132);
  listvar: packed array1..maxnumvar of 1..maxvarnum;
  cl,width: packed array1..maxvarnum of normal;
  vdbasy: string(2);
static
  line:string(32720);
%page
function   welldef(const  id: string): boolean;  external;
procedure  defineer(const id: string; iserr: boolean);  external;
procedure  addaform(const name,form,ras,dat,
   rot,beg,lng: string; isred, isopt: boolean);  external;
procedure  addform(const  name,form: string);    external;
procedure  begcase(const  code,seq,ppid,plan: string);  external;
function   endcase:  integer;   external;
procedure  emitinit;  external;
function   itos( i: integer): string(12);  external;
function   stoi(const s: string):integer;  external;


REPLACE:  Replaces part of a string
function replace(var source:string; const rep,new: string):boolean;
var
  i:integer;
begin
i := index(source,rep);
replace := false;
if i<>0 then begin
  replace := true;
  source := substr(source,1,i-1)!!new!!substr(source,i+length(rep));
  end;
end;
%page
REPLACE2:  Deletes a the character if found
function replace2(var source:string; const rep,new: string):boolean;
var
  i:integer;
begin
i := index(source,rep);
replace2 := false;
if i<>0 then begin
  replace2 := true;
  source := substr(source,1,i-1)!!new!!substr(source,i+1);
  end;
end;
procedure scansectf(var form:string);
var dummyvar : boolean;
begin
  dummyvar := replace(form,'MAN7','ANMAN7');
  dummyvar := replace(form,'MAN8','ANMAN8');
  dummyvar := replace(form,'MAN9','ANMAN9');
  dummyvar := replace(form,'VOL7','ANVOL7');
  dummyvar := replace(form,'VOL8','ANVOL8');
  dummyvar := replace(form,'VOL9','ANVOL9');
end;
%page
procedure scandcf(var form:string);
var dummyvar : boolean;
begin
  while replace(form,'CNT','ANCONT') do continue;
  dummyvar := replace(form,'MAN1','ANMAN1');
  dummyvar := replace(form,'MAN2','ANMAN2');
  dummyvar := replace(form,'VOL','ANVOL');
  dummyvar := replace(form,'COE1','ANCOE1');
  dummyvar := replace(form,'COE2','ANCOE2');
  dummyvar := replace(form,'CTE','ANCTE');
  dummyvar := replace(form,'MMAN','ANMMAN');
  dummyvar := replace(form,'MVOL','ANMVOL');
end;
%page
function vnum: string(6);
var t,z: string(6);
begin
t := itos(lastvar);
z := '';  if length(t)<4  then z := substr('000',length(t));
vnum := 'V'!!z!!t;
end;
%skip 2
ERROR:  Writes out current error in -problems file
procedure error(const mess: string);  external;
procedure error;
begin
numprob := numprob + 1;
write(failfile,'-ID=',id,' ',name:maxlength(name),' ',vnum,' ',mess);
if length(lastvalue)<40 then write(failfile,' ',lastvalue);
writeln(failfile);
writeln(failfile,' ':11,lastgroup);
end;
%skip 2
procedure reject(const mess: string);
begin
error(mess);
defineer(name,true);
end;
%skip 2
procedure note(const mess:string);
begin
numnote := numnote + 1;
writeln(notefile, 'ID=', id, ' ', name:maxlength(name), ' ', vnum,
                             ' ', mess, ' ', lastvalue);
end;
%page
ZERO:  Gets the next group of data and returns true if all zeros
function zero(n:normal):boolean;
var
  vwide,col,p,w,i: normal;  c:char;
begin
nextcol := cc + n;
lastgroup := substr(line,cc,n);
p := 1;  while (p<=n) and (lastgroupp='0') do p := p + 1;
if fv<>0 then begin
   lastgroup := lastgroup !! '!' !! substr(line,clfv,120);
   w := length(lastgroup);
   i := n+2;  c := lastgroupi;
   if (c=' ')or(c='.')or(c='0')
      then while (i<=w) and (lastgroupi=c) do i := i + 1;
   if i<= w then p := 0;
   end;
if p>n then
   zero := true
else begin
   definednamekind,nn := adddef;
   zero := listing;
   if listing then begin
      if listname then begin
         if cols(output)>1 then writeln(output);
         write(output,name);  end;
      while cc<nextcol do begin
         w := widthcv;
         assert w<1000;
         assert clcv=cc;
         p := w;
         while (p>0) and (linecc+p-1='.') do p := p - 1;
         while (p>0) and (linecc+p-1=' ') do p := p - 1;
         i := 0;
         while (i<p) and (linecc+i='0') do i := i + 1;
         if i<p then begin
            if cv>=10000 then i := 5 else
            if cv>=1000  then i := 4 else
            if cv>=100   then i := 3 else
            if cv>=10    then i := 2 else i := 1;
            col := cols(output);
            vwide := 12 - (col+i) mod 11;
            if col + vwide + i + p > 132 then
               begin  writeln(output);  vwide := 12 - i;  end;
            write(output, 'V':vwide, cv:1, '=',substr(line,cc,p));
            end;
         cc := cc + w;
         widthcv := w + 1000;
         cv := cv + 1;
         if (cv=9143) or (cv=9343) or (cv=9543) then cv := cv + 58;
         if (cc=nextcol) and (fv<>0) then begin
            cv := fv;  fv := 0;  cc := clcv;  nextcol := cc + 120; end;

   end;end;end;
end;
%page
NOGET:  Gets the next variable from data file and returns true if illegal data
function noget(var s:string):boolean;
var
  b,e,clcv: normal;
  allblank,allzero,ab,a9,a0,a1t8,ax,am: boolean;
  m: string(30);
begin
clcv := clcv;
assert cc=clcv;
assert maxlength(s)=widthcv;
m := '';
ab := false; a9:=false; a0:=false; a1t8:=false; ax:=false; am:=false;
b  := cc;  e := cc + maxlength(s);
while cc<e do begin
  case linecc of
         '0': begin a0 := true; if b=cc then b := b + 1; end;
         ' ': ab := true;
         '-': if cc=clcv then am := true else ax := true;
         '9': a9 := true;
    '1'..'8': a1t8 := true;
    otherwise ax := true end;
  cc := cc + 1;
  end;
allblank := not (a0 or a1t8 or a9 or am or ax);
allzero  := b=e;
if allzero then b := b-1;
if s1='c' then b := clcv;
lastvar := cv;  lastvalue := substr(line,b,cc-b);
cv := cv + 1;
if (s<>'p') and (s<>'y') and a9 and not (a0 or a1t8 or am or ax) then m := 'Is nines';
case s1 of
    'c': if     allblank then m := 'Should not be blank';
    'b': if not allblank then m := 'Should be blank';
    'z': if not allzero  then m := 'Should be zero';
    '-': if     allzero  then m := 'Should not be zero';
'p','n': if     allzero  then m := 'Should not be zero'
         else if am      then m := 'Should not be negative';
    'q': if am then m := 'Should not be negative';
    'x','y': ;
    otherwise;
  end;
if (s<>'c')and(s<>'b')and (ab or ax) then m := 'Is not a number';
if m<>'' then reject(m);
s := lastvalue;
noget := m<>'';
end;
%page
function nogetd(var d:string(8);  r:integer): boolean;
label 1;
var
   mo,yr: string(2); l: 0..8;  i: 1..maxnumdate;  idate: integer;
   equal: boolean;
begin
nogetd := true;
mo := d;  yr := d;
if noget(mo) then goto 1;
if noget(yr) then goto 1;
if d='z' then
   d := ''
else begin
   idate := (1900+stoi(yr))*1000 + (stoi(mo)*1000 + r) div 12;
   equal := false;
   if numdate>0 then for i := numdate downto 1 do
      if (ddatei=idate) then equal := true
      else if (abs(ddatei-idate)<167) then begin
           reject('Date inconsistant with '!!dnamei);  goto 1;  end;
   if not equal then begin
      numdate := numdate + 1;
      ddatenumdate := idate;  dnamenumdate := name;  end;
   d := itos(idate);
   d := substr(d,1,4)!!'.'!!substr(d,5);
   l := length(d);  while dl='0' do l := l - 1;
   if dl='.' then l := l - 1;
   d := substr(d,1,l);
   end;
nogetd := false;
1:end;
%skip 3
function nogetdates(var time:string(1); var d1,d2:string(8)): boolean;
label 1;
var
   r: integer; dotime:boolean;
begin
nogetdates := true;
d1 := 'n';  r := 6-1000;  d2 := 'z';
dotime := false;
if (substr(name,1,3) = 'CTE') or (substr(name,1,3) = 'COE')
then begin if time = 'w' then dotime := true; end;
if (dotime) or ((namekind<>defrot) and (substr(name,1,3)<>'MMA') and
   (substr(name,1,3)<>'MVO') and (substr(name,1,3)<> 'CTE') and (substr(name,1,3)<>'COE')) then
   begin  time := 'p';  if noget(time) then goto 1;  end;
case time1 of
    '1': d1 := 'z';
'o','2': ;
    '3': r := 6;
    '4': d2 := 'n';
  '7','9': begin note('Time period'); time1 := '1'; d1 := 'z'; end;
  otherwise  reject('Time period');  goto 1;  end;
if nogetd(d1,r) then goto 1;
if nogetd(d2,6-1000) then goto 1;
if (time='4') and (d2<=d1) then
   begin  reject('Dates out of order');  goto 1;  end;
if time='2' then
   begin  d2 := d1;  d1 := '';  end;
nogetdates := false;
1:end;
%page
function nogetform(var form: string(120)): boolean;
label 1;
var
  i,n,b,e: formx;  p:normal; msg: string(120);
begin
nogetform := true;
assert cc=nextcol;
cv := fv;  cc := clcv;  nextcol := cc + 120;
if noget(form) then goto 1;
b :=   1;  if substr(form,1,3)='IF ' then b := 4;
e := 120;  while forme='.' do begin if e=1 then begin reject('No Formula]'); goto 1; end; e := e - 1; end;
n := 120;
for i := b to e do if formi<>' ' then begin
    n := n mod 120 + 1;
    formn := formi; end;
form := substr(form,1,n);
while replace(form, 'AGE',   'age')  do continue;
while replace(form, 'GE',    '>=')   do continue;
while replace(form, 'LE',    '<=')   do continue;
while replace(form, 'OR',    ',')    do continue;
while replace(form, 'CNRT#1','CNT')  do continue;
while replace(form, 'DRT#1', 'DRT')  do continue;
while replace(form, 'DST#1', 'DST')  do continue;
while replace(form, 'ERT#1', 'ERT')  do continue;
while replace(form, 'NRT#1', 'NRT')  do continue;
while replace(form, 'VDT#1', 'VDT')  do continue;
while replace(form, 'age',   'AGE')  do continue;
b := index(lastgroup,'!');
lastgroup := substr(lastgroup,1,b)!!form;
nogetform := false;
1:end;
%page
function nogetnum(var num: string(2)): boolean;
label 1;
var
  defkind: defkinds;  kind: string(4);  inum,cnum: normal;
begin
nogetnum := true;
if num='z' then num := 'za';
case num2 of
  'a': begin  kind := 'ASY#';  defkind := defasy;  end;
  's': begin  kind := 'RAS#';  defkind := defras;  end;
  'd': begin  kind := 'DAT#';  defkind := defdat;  end;
  't': begin  kind := 'ROT#';  defkind := defrot;  end;
  'l': begin  kind := 'LNG#';  defkind := deflng;  end;
  'b': begin  kind := 'BEG#';  defkind := defbeg;  end;
  end;
num  := delete(num,2);
if noget(num) then goto 1;
inum := stoi(num);  cnum := inum;
if (defkind=defasy) and (cnum>18) then cnum := cnum+100;
case cnum of
  0,96,151..173: ;
     95: num := '';
  1..18: if defineddefkind,inum=undef then begin
         reject(kind!!' is not defined');  goto 1;  end;
  otherwise reject(kind);  goto 1;  end;
nogetnum := false;
1:end;
%page
type  tablex = 1..5;
      table = arraytablex of record
        from,tooo: string(6); amount: string(8);  end;
function nogettab(s: string(1); var t: table): boolean;
label 1;
var  i: tablex;  n: 0..5;  lastto: string(6);  len: normal;
     lastamount: string(8);
     upperlim, lowerlim, match, skip1, skip2: boolean;

function  nogetskip(var s: string(6)): boolean;
label 1;
var  s3: string(3);  s4: string(4);  s6: string(6);
begin
nogetskip := true;
if  skip1  then begin  s6 := z;  if  noget(s6)  then goto 1;  end;
case  len  of
   3: begin  s3 := s;  if  noget(s3)  then  goto 1;  s := s3;  end;
   4: begin  s4 := s;  if  noget(s4)  then  goto 1;  s := s4;  end;
   6: begin  s6 := s;  if  noget(s6)  then  goto 1;  s := s6;  end;
 end;
if  skip2  then begin  s4 := z;  if  noget(s4)  then goto 1;  end;
nogetskip := false;
1: end;

begin
nogettab := true;
upperlim := substr(name,1,3)='RED';
lowerlim := name='LRQ';
match := (substr(name,1,3)='MMA') or (substr(name,1,3)='MVO');
skip1 := match and (lastvalue='5');
skip2 := match and (lastvalue<>'5');
if  upperlim or lowerlim  then  len := 3
          else if  skip1  then  len := 4
                          else  len := 6;
lastto := '0';  n := 0;  lastamount := '0';
for i := 1 to 5 do with ti do begin
  amount := s;
  if amount<>'z' then begin
     amount := 'x';
     case i of
      1: if  lowerlim  then  amount := 'z';
      5: if  upperlim  then  amount := 'z';
      2,3,4: ;
    end;  end;
  if noget(amount) then goto 1;
  if amount='0'  then begin  from := 'z';  tooo := 'z';  end
    else begin  n := n + 1;  from := 'n';  tooo := 'n';
      if lastamount=amount then
         begin reject('Duplicate in table');  goto 1;  end; end;
  if i=1  then  from := '0'
          else  if nogetskip(from) then goto 1;
  if (from<>'0')and(lastto<>'0')and(from<>lastto) then
     begin  reject('Hole in table');  goto 1;  end;
  if i=5  then  tooo := '0'
          else  if nogetskip(tooo) then goto 1;
  if tooo<>'0'  then  lastto := tooo;
  end;
if (s<>'z')and(n<2) then begin reject('Missing part of table'); goto 1;  end;
nogettab := false;
1:end;
%page
function dp(const num,pc: string): string(12);
var  s: string(12);  d: normal;
begin
if pc='2' then  d := 2  else  d := 0;
s := substr('00',1,max(0,d+1-length(num)))!!num;
s := substr(s,1,length(s)-d)!!'.'!!substr(s,1+length(s)-d);
while slength(s)='0' do s := delete(s,length(s));
if slength(s)='.' then s := delete(s,length(s));
dp := s !! '%';
end;
%skip 2
function pp(const s: string): string(12);
begin  pp := dp(s,'2');  end;
%skip 3
function bbase(const base,asy: string): string(12);
begin
case base1 of
  '1': bbase := 'AGE';
  '2': bbase := 'ASY'!!asy;
  '3': bbase := '(AGE+ASY'!!asy!!')';
  end;
end;
%skip 3
function cbase(const base,asy: string): string(20);
begin
case base1 of
  '1': cbase := 'WAGE(SURVEYD)';
  '2': cbase := 'AGE';
  '3': cbase := 'ASY' !! asy;
  '4': cbase := '(AGE+ASY' !! asy !! ')';
  '5': cbase := 'PC' !! substr(name,2);
  otherwise reject('Bad cbase');
end; end;
%skip 3
function btable(tab:table; const pc,b,asy: string): string(120);
var  f: string(120);  t: string(40);  base: string(12);
     i: tablex;  dec, check: boolean;
begin
dec := (length(name)>3) and (substr(name,1,3)='RED');
assert dec or (name='LRQ');
f := '';
check := false;
base := bbase(b,asy);
for i := 1 to 5  do with  tabi  do if  amount<>'0' then begin
  if dec then if from='0'  then begin  check := true;
         t := tooo!!''!!tooo!!'>' !!base  end
    else t := base!!''!!tooo!!'>'!!base!!'>='!!from
  else if tooo='0'
    then t := base!!''!!base!!'>' !!from
    else t := base!!''!!from!!'<' !!base!!'<='!!tooo;
  f := f!!'+'!!dp(amount,pc)!!'*'!!t!!'';
  end;
f1 := '(';  f := f!!')';
if pc='2' then begin
  if dec then t := '-' else t := '+';
  f := '(1'!!t!!f!!')';
  if check then f := 'NN'!!f;
  end;
btable := f;
end;
%page
function ctable(tab:table; const pc1,b,asy:string): string(300);
var f:string(300); t:string(60); base: string(20); i : integer;
    pc2 : string(1);
begin
f := '';
if pc1 <> '1' then pc2 := '2' else pc2 := '1';
base := cbase(b,asy);
for i := 1 to 5 do with tabi do if amount<>'0' then begin
  if from='0' then begin
    t :=  '(' !! tooo !! '>' !! base end
  else if tooo<>'0' then t :=  '((' !! tooo !! '>' !! base !! ')&(' !! base !! '>=' !! from !! ')'
    else t := '(' !! base !! '>=' !! from;
  f := f !! '+(' !! t !! ')->' !! dp(amount,pc2) !! ')'; end;
ctable := substr(f,2);
end;
%page
procedure readdict;
var
  v:normal; p:0..32720;
begin
if listing then for p := 1 to maxvarnum do widthp := 1000;
while not eof(input) do begin
  readln(input,line);
  p := 0;
  while p<length(line) do begin
    if linep+1='T' then begin
       v := stoi(substr(line,p+2,5));
       clv := stoi(substr(line,p+42,5));
       width v := stoi(substr(line,p+47,3));
       end;
    p := p + 80;
    end;
  assert p=length(line);
  end;
if listing then begin
   for v := 1507 to  1514 do widthv := 1000;
   for v := 1519 to  1526 do widthv := 1000;
   for v := 1531 to  1538 do widthv := 1000;
   for v := 1543 to  1550 do widthv := 1000;
   for v := 1607 to  1614 do widthv := 1000;
   for v := 1619 to  1626 do widthv := 1000;
   for v := 1631 to  1638 do widthv := 1000;
   for v := 1643 to  1650 do widthv := 1000;
   for v := 1849 to  1856 do widthv := 1000;
   for v := 2907 to  2914 do widthv := 1000;
   for v := 2919 to  2926 do widthv := 1000;
   for v := 2931 to  2938 do widthv := 1000;
   for v := 3007 to  3014 do widthv := 1000;
   for v := 3019 to  3026 do widthv := 1000;
   for v := 3252 to  3259 do widthv := 1000;
   for v := 4907 to  4914 do widthv := 1000;
   for v := 4919 to  4926 do widthv := 1000;
   for v := 4931 to  4938 do widthv := 1000;
   for v := 5007 to  5014 do widthv := 1000;
   for v := 5019 to  5026 do widthv := 1000;
   for v := 5217 to  5224 do widthv := 1000;
   for v := 6308 to  6315 do widthv := 1000;
   for v := 6321 to  6328 do widthv := 1000;
   for v := 6334 to  6341 do widthv := 1000;
   for v := 6408 to  6415 do widthv := 1000;
   for v := 6421 to  6428 do widthv := 1000;
   for v := 6717 to  6724 do widthv := 1000;
   for v := 7508 to  7515 do widthv := 1000;
   for v := 7521 to  7528 do widthv := 1000;
   for v := 7534 to  7541 do widthv := 1000;
   for v := 7608 to  7615 do widthv := 1000;
   for v := 7621 to  7628 do widthv := 1000;
   for v := 7917 to  7924 do widthv := 1000;
   for v :=11801 to 11808 do widthv := 1000;
   numvar := 0;
   for v := 1 to maxvarnum do if widthv<1000 then
       begin numvar := numvar + 1;  listvarnumvar := v;  end;
end;end;
%skip 3
procedure finishlisting;
var
  i: 1..maxnumvar; v:1..maxvarnum;
begin
listname := false;
writeln(output);
write(output,'UNUSED');
for i := 1 to numvar do begin
  v := listvari;
  if widthv<1000 then  begin
     cv := v;
     cc := clv;
     if zero(widthv) then name := '';
     end;
  if widthv>1000 then widthv := widthv - 1000
  end;
listname := true;
end;
%page
procedure asy;
label 1;
var howd,time,max,wfrmtype: string(1);
    dage,dyrs,mage,myrs,acc,wkyr,hrwk,moyr:string(2);
    msum,hrmo:string(3);
    hryr: string(4);
    fromd,tilld: string(8);
    newaform : string(200);
    sd,fd,wkhrform:string(54);
    hrsreq : string(20);
    fn: string(6);
    check,needsd,isvest: boolean;
begin
isvest := name='ASYV';
if zero(37-8*ord(isvest)) then goto 1;
howd := 'n';  max := 'n'; acc := 'p';
dage := 'z'; dyrs := 'z'; mage := 'z'; myrs := 'z'; msum := 'z';
hryr := 'z'; wkyr := 'z'; moyr := 'z';
if noget(howd) then goto 1;
case howd1 of
  '1': ;
  '2': dage := 'n';
  '6',
  '3': dyrs := 'n';
  '4',
  '5': begin  dage := 'n'; dyrs := 'n';  end;
  '7':begin note('Defined'); howd1 := '1'; end;
  otherwise  reject('Defined');  goto 1;  end;
if noget(dage) then goto 1;  if noget(dyrs) then goto 1;
if nogetdates(time,fromd,tilld) then goto 1;
if isvest then
   begin max := '6';  mage := '0'; myrs := '0';  msum := '0';  end
else begin
   if noget(max)  then goto 1;  case max1 of
     '1': mage := 'n';
     '2': myrs := 'n';
     '3': msum := 'n';
     '4',
     '5': begin mage := 'n';  myrs := 'n';  end;
     '6': ;
     otherwise  reject('Maximum');  goto 1;  end;
   if noget(mage) then goto 1;  if noget(myrs) then goto 1;
   if noget(msum) then goto 1;  end;
if noget(acc)  then goto 1;
case stoi(acc) of
      1:  ;
  2,5,8:  hryr := 'n';
  3,6,9:  wkyr := 'n';
  4,7,10: moyr := 'n';
  97,99:begin note('Hrs worked'); acc := '01'; end;
  otherwise reject('Accrual'); goto 1; end;
hrwk := wkyr;  hrmo := moyr;
if noget(hryr) then goto 1;  if noget(wkyr) then goto 1;
if noget(hrwk) then goto 1;  if noget(moyr) then goto 1;
if noget(hrmo) then goto 1;
case stoi(acc) of
  1: wkhrform := '1.0';
  2: wkhrform := '((WRKHRS>=' !! hryr !! ')->1.0)';
  3: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '((WRKHRS>=' !! hrsreq !! ')->1.0)'; end;
  4: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '((WRKHRS>=' !! hrsreq !! ')->1.0)'; end;
  5: begin wkhrform := '(NNMIN(1,WRKHRS/' !! hryr !! '))'; end;
  6: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '(NNMIN(1,WRKHRS/' !! hrsreq !! '))'; end;
  7: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '(NNMIN(1,WRKHRS/' !! hrsreq !! '))'; end;
  8: begin wkhrform := '(MIN(2,NN(WRKHRS/' !! hryr !! ')))'; end;
  9: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '(MIN(2,NN(WRKHRS/' !! hrsreq !! ')))'; end;
  10: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '(MIN(2,NN(WRKHRS/' !! hrsreq !! ')))'; end;
end;
check := true;  needsd := max='5';
case howd1 of
  '1': begin  check := false;
       sd := 'HIRED';  end;
  '2': sd := 'HIRED,BIRTHD+'!!dage;
  '3': sd := 'HIRED+'!!dyrs;
  '4': sd := 'HIRED,MIN(HIRED+'!!dyrs!!',BIRTHD+'!!dage!!')';
  '5': sd := 'HIRED+'!!dyrs!!',BIRTHD+'!!dage;
  '6': begin  check := false;
       sd := 'HIRED,QUITD-'!!dyrs;  end;
  end;
if fromd<>'' then begin  sd := sd!!','!!fromd;  check := true;  end;
if index(sd,',')<>0 then sd := 'MAX('!!sd!!')';
if not needsd or (length(sd)<9) then
   sd := '('!!sd!!')'
else begin
   addform('SD'!!name,sd);
   sd := 'SD'!!name  end;
case max1 of
'1','4': begin fd := 'QUITD,BIRTHD+'!!mage;  check := true;  end;
'2','3',
    '6': fd := 'QUITD';
    '5': fd := 'QUITD,MAX(BIRTHD+'!!mage!!','!!sd!!'+'!!myrs!!')';
    end;
if tilld<>'' then begin  fd := fd!!','!!tilld;  check := true;  end;
if index(fd,',')<>0 then fd := 'MIN('!!fd!!')';
if max1 in '2'..'4'
   then if check then fn := 'NNMIN('
                 else fn := 'MIN('
   else if check then fn := 'NN('
                 else fn := '';
case max1 of
  '2','4': fd :=fn!!myrs!!','!!fd;
      '3': fd :=fn!!msum!!'-AGE,'!!fd;
 otherwise fd :=fn!!fd;  end;
if fn<>'' then sd := sd !! ')';
newaform := '(' !! fd !! '-' !! sd !! ')*' !! wkhrform;
addaform(name,newaform,'','','','','',false,nn in 16,17,18);
assert cc=nextcol;
1:end;
%page
procedure beg;
label 1;
var
  howd,asy,age1,age2: string(2);
  sum: string(3);  idef: normal;
  b: string(48);
begin
if zero(11) then goto 1;
howd := 'p';
asy := 'z';  age1 := 'z';  age2 := 'z';  sum := 'z';
if noget(howd) then goto 1;  idef := stoi(howd);
if nn in 13..15 then case idef of
   2: begin idef := 9; note('Defined DS BEG 2');  end;
         5: idef := 8;
         6: idef := 9;
      7..9: idef := idef + 100;
1,3,12,19..24: ;
 97,99:begin note('Dis ben begin'); howd := '01'; idef := 1; end;
  otherwise idef := idef + 900;  end;
case idef of
 107,1,2,8,9,19..21,23,51: ;
 97,99:begin note('Dis ben begin'); howd := '01'; idef := 1; end;
      109,108,3,4,5,22,24: age1 := 'n';
                        6: begin  age1 := 'n';  age2 := 'n';   end;
                        7: begin  sum  := 'n';   asy := 'na';  end;
                       12: begin sum := 'n'; asy := 'na'; age2 := 'n'; end;
  otherwise  reject('Defined BEG');  goto 1;  end;
if nogetnum(asy) then goto 1;  if noget(age1) then goto 1;
if noget(age2) then goto 1;    if noget(sum)  then goto 1;
case  idef  of
   23,
    1: definednamekind,nn := nulldef;
107,2: b := 'ANYTIME(0,0)';
 24,
108,3: b := 'MAX(BIRTHD+'!!age1!!',QUITD)';
109,4: b := 'ANYTIME(BIRTHD+'!!age1!!',0)';
    5: b := 'ANYTIME(0,BIRTHD+'!!age1!!')';
    6: b := 'ANYTIME(BIRTHD+'!!age1!!',BIRTHD+'!!age2!!')';
    7: b := 'MAX(BIRTHD+'!!sum!!'-ASY'!!asy!!',QUITD)';
    8: b := 'MAX(NRD,QUITD)';
    9: b := 'MAX(ERD,QUITD)';
   12: b := 'ANYTIME(BIRTHD+'!!sum!!'-ASY'!!asy!!',BIRTHD+'!!age1!!')';
   19: b := 'QUITD+10';
   20: b := 'QUITD+2';
   21: b := 'QUITD+5';
   22: b := 'QUITD+AGE'!!age1!!'>AGE>='!!itos(stoi(age1)-5)!!'';
   51: b := 'MAX(MIN(BIRTHD+65,BENIFITD+ASY10/4),QUITD)';
  end;
if  definednamekind,nn<>nulldef then
  addform(name,b);
assert cc=nextcol;
1:end;
%page
procedure cls;
label 1;

begin
if  zero(118)  then  goto 1;
cc := nextcol;
addaform(name,'0','','','','','',false,false);
assert cc=nextcol;
1:end;
%page
type  manvoltab = record
  kind,base: string(1);  hd,asynum: string(2);  pc: string(4);
  dollar: string(6);  tab: table;   end;
function  manvolnoget(var t: manvoltab; var x: string(1);
  var  usess: boolean): boolean; forward;
procedure ctecoe;
label 1;
var stage,styrs,fnage,fnasy,fnasynum,ssyr,basis,alloc,
    moyr,wkyr,hrwk,acc,mannum,volnum,seryrs,rot:string(2);
    prepost,sswb,fixfluc,anmin,anmax,start,finish,time,time2:string(1);
    allocdol,ffdol,mindol,maxdol:string(6);
    hryr,hrsyrs,allocpc,ffpc,minpc,maxpc:string(4);
    usess,iscte : boolean; fnsum,hrmo:string(3);
    fromd,tilld,fromd2,tilld2:string(8);
    srstr,startstr,finstr,sdstr,fdstr:string(50);
    wkhrform:string(60); hrsreq:string(20);
    pcstr,sumform:string(200);
    maxstr,newpc:string(30);
    mintab:manvoltab;
begin
iscte := true; maxstr := '0'; usess := false;
if (substr(name,1,3) = 'CTE')
 then begin if zero(109) then goto 1; end
 else begin iscte := false; if zero(157) then goto 1; end;
basis := 'p'; fixfluc := 'p'; anmin := 'p'; anmax := 'p'; rot := 'p';
alloc := 'p'; sswb := 'p'; start := 'p'; finish := 'p'; time := n;
stage := z; styrs := z; fnage := z; fnasy := z; fnsum := z;
acc := 'p'; hryr := z; wkyr := z; moyr := z;
prepost := n;
if iscte then begin
if noget(basis) then goto 1;
case stoi(basis) of
1..11: ;
97,99:begin note('Basis'); basis := '03'; end;
 otherwise reject('Bad basis'); goto 1; end;
if noget(fixfluc) then goto 1;
case fixfluc1 of
'2': begin ffdol := z; ffpc := n; end;
'3': begin ffdol := z; ffpc := z; end;
'7','9':begin note('Fix/Flux'); fixfluc1 := '3'; ffdol := z; ffpc := z; end;
otherwise reject('Bad fixed/fluc'); goto 1; end;
if noget(ffdol) then goto 1; if noget(ffpc) then goto 1;
if noget(anmin) then goto 1;
case anmin1 of
'1': begin mindol := z; minpc := z; end;
'2': begin mindol := n; minpc := z; end;
'3': begin mindol := z; minpc := n; end;
'7','9':begin note('Annual Min'); anmin1 := '1'; mindol := z; minpc := z; end;
otherwise reject('Bad Annual Min'); goto 1; end;
if noget(mindol) then goto 1; if noget(minpc) then goto 1;
if noget(anmax) then goto 1;
case anmax1 of
'1': begin maxdol := z; maxpc := z; end;
'2': begin maxdol := n; maxpc := z; end;
'3': begin maxdol := z; maxpc := n; end;
'7','9':begin note('Annual Max'); anmax1 := '1'; maxdol := z; maxpc := z; end;
otherwise reject('Bad Annual Max'); goto 1; end;
if noget(maxdol) then goto 1; if noget(maxpc) then goto 1;
if noget(alloc) then goto 1;
hrsyrs := z; seryrs := z; allocdol := z; mannum := z; volnum := z; allocpc := z;
case stoi(alloc) of
1,2,4,6,8,9,11,17:; 3:hrsyrs := n; 5:seryrs := n; 7,10:allocdol := n;
12:begin allocdol := n; seryrs := n; end; 13:mannum := n; 14:volnum := n;
15:begin volnum := n; allocdol := n; end; 16:begin volnum := n;allocpc := n; end;
97,99:begin note('Allocation'); alloc := '06'; end;
18:allocdol := n; 19:allocpc := n; otherwise reject('Bad allocation'); goto 1; end;
if noget(hrsyrs) then goto 1; if noget(seryrs) then goto 1;
if noget(allocdol) then goto 1; if noget(mannum) then goto 1;
if noget(volnum) then goto 1; if noget(allocpc) then goto 1;
if noget(sswb) then goto 1;
if (stoi(alloc) >= 8) and (stoi(alloc) <= 10) then usess := true;
end else begin
if manvolnoget(mintab,prepost,usess) then goto 1;
if noget(sswb) then goto 1;
end;
if usess<>(sswb<>'4') then begin reject('Wagebase not used'); goto 1; end;
case sswb1 of
'7','9':begin note('SSWB'); sswb1 := '1'; ssyr := z; end;
'1','2','4':ssyr := z; '3': ssyr := n; otherwise reject('SS Wage Base'); goto 1; end;
if noget(ssyr) then goto 1;
time := 'w';
if nogetdates(time,fromd,tilld) then goto 1;
if noget(acc)  then goto 1;
case stoi(acc) of
      1:  ;
  2,5,8:  hryr := 'n';
  3,6,9:  wkyr := 'n';
  4,7,10: moyr := 'n';
  97,99:begin note('Hrs worked'); acc := '01'; end;
  otherwise reject('Accrual'); goto 1; end;
hrwk := wkyr;  hrmo := moyr;
if noget(hryr) then goto 1;  if noget(wkyr) then goto 1;
if noget(hrwk) then goto 1;  if noget(moyr) then goto 1;
if noget(hrmo) then goto 1;
case stoi(acc) of
  1: wkhrform := '1.0';
  2: wkhrform := '((WRKHRS>=' !! hryr !! ')->1.0)';
  3: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '((WRKHRS>=' !! hrsreq !! ')->1.0)'; end;
  4: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '((WRKHRS>=' !! hrsreq !! ')->1.0)'; end;
  5: begin wkhrform := '(NNMIN(1,WRKHRS/' !! hryr !! '))'; end;
  6: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '(NNMIN(1,WRKHRS/' !! hrsreq !! '))'; end;
  7: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '(NNMIN(1,WRKHRS/' !! hrsreq !! '))'; end;
  8: begin wkhrform := '(MIN(2,NN(WRKHRS/' !! hryr !! ')))'; end;
  9: begin hrsreq := itos(stoi(wkyr)*stoi(hrwk));
       wkhrform := '(MIN(2,NN(WRKHRS/' !! hrsreq !! ')))'; end;
  10: begin hrsreq := itos(stoi(moyr)*stoi(hrmo));
       wkhrform := '(MIN(2,NN(WRKHRS/' !! hrsreq !! ')))'; end;
end;
time2 := '1';
if  noget(rot)  then  goto 1;  case  stoi(rot)  of
       4: time2 := 'o'; 5: time2 := '2'; 6: time2 := '3'; 7: time2 := '4';
      97,99:begin note('Other ROT'); rot := '01'; end;
   1,2,3: ;  otherwise  reject('Other');  goto 1;  end;
if  nogetdates(time2,fromd2,tilld2)  then  goto 1;
case stoi(rot) of
 1: srstr := '';
 2: srstr := 'QAPPROVL->';
 3: srstr := 'QPASTSRV->';
 4: srstr := '((HIRED<=' !! fromd2 !! ')&(QUITD>=' !! fromd2 !! '))->';
 5: srstr := '(HIRED<=' !! tilld2 !! ')->';
 6: srstr := '(QUITD>=' !! fromd2 !! ')->';
 7: srstr := '((HIRED<=' !! fromd2 !! ')&(QUITD>=' !! tilld2 !! '))->';
otherwise reject('Bad special requirement'); goto 1; end;
if noget(start) then goto 1; case start1 of
'1':; '3':styrs := n; '2':stage := n;
'4','5':begin stage := n; styrs :=n; end;
'7','9':begin note('When Begin'); start1 := '1'; end;
otherwise reject('When begin'); goto 1; end;
if noget(stage) then goto 1; if noget(styrs) then goto 1;
if noget(finish) then goto 1; case finish1 of
'7','9':begin note('Bad finish'); finish1 := '6'; end;
'1':fnage := n; '2': fnasy := n; '3':fnsum := n; '4','5':begin fnage := n;
fnasy := n; end; '6':; otherwise reject('Max age asy'); goto 1; end;
fnasynum := fnasy!!'a';
if nogetnum(fnasynum) then goto 1; if noget(fnage) then goto 1;
if noget(fnasy) then goto 1; if noget(fnsum) then goto 1;
case stoi(start) of
 1: startstr := 'HIRED';
 2: startstr := 'BIRTHD+' !! stage;
 3: startstr := 'BIRTHD+' !! styrs;
 4: startstr := 'MIN(BIRTHD+' !! stage !! ',HIRED+' !! styrs !! ')';
 5: startstr := 'MAX(BIRTHD+' !! stage !! ',HIRED+' !! styrs !! ')';
end;
case stoi(finish) of
 1: finstr := 'BIRTHD+' !! fnage;
 2: finstr := 'SD' !! name !! '+' !! fnasy;
 3: finstr := '(BIRTHD+SD' !! name !! '+' !! fnsum !! ')*50%';
 4: finstr := 'MIN(BIRTHD+' !! fnage !! ',SD' !! name !! '+' !! fnasy !! ')';
 5: finstr := 'MAX(BIRTHD+' !! fnage !! ',SD' !! name !! '+' !! fnasy !! ')';
 6: finstr := 'QUITD';
end;
case stoi(time) of
 1: begin
       if start = '1' then sdstr := startstr
       else sdstr := 'MAX(HIRED,' !! startstr !! ')';
       if finish = '6' then fdstr := finstr
       else fdstr := 'MIN(QUITD,' !! finstr !! ')';
      end;
 2: begin
       if start = '1' then sdstr := startstr
       else sdstr := 'MAX(HIRED,' !! startstr !! ')';
       if finish = '6' then fdstr := 'MIN(QUITD,' !! tilld !! ')'
       else fdstr := 'MIN(QUITD,' !! finstr !! ',' !! tilld !! ')';
      end;
 3: begin
       if start = '1' then sdstr := 'MAX(HIRED,' !! fromd !! ')'
       else sdstr := 'MAX(HIRED,' !! startstr !! ',' !! fromd !! ')';
       if finish = '6' then fdstr := finstr
       else fdstr := 'MIN(QUITD,' !! finstr !! ')';
      end;
 4: begin
       if start = '1' then sdstr := 'MAX(HIRED,' !! fromd !! ')'
       else sdstr := 'MAX(HIRED,' !! startstr !! ',' !! fromd !! ')';
       if finish = '6' then fdstr := 'MIN(QUITD,' !! tilld !! ')'
       else fdstr := 'MIN(QUITD,' !! finstr !! ',' !! tilld !! ')';
      end;
 otherwise reject('Bad Man/Vol Time'); goto 1;
end;
addform('SD'!!substr(name,1,4),sdstr);
addform('FD'!!substr(name,1,4),fdstr);
if iscte
then begin
case fixfluc1 of
'2': begin newpc := dp(ffpc,'2');  if (anmin = '3') then
     newpc := 'MIN(' !! dp(minpc,'2') !! ',' !! newpc !! ')';
     if (anmax = '3') then newpc := 'MAX(' !! dp(maxpc,'2') !! ',' !! newpc !! ')';
     end;
'3': begin
     if maxpc = '0' then newpc := '5%'
     else newpc := '(' !! dp(maxpc,'2') !! '+' !! dp(minpc,'2') !! ')/2';
     end;
otherwise reject('Unknown fix/fluc='!!fixfluc); goto 1; end;
case stoi(basis) of
1..3,5..10:begin profcnt:=profcnt+1;pcstr:='CRPROF'!!itos(profcnt);end;4:pcstr:=newpc;11:begin fortcnt:=fortcnt+1;pcstr:='CRFORT'!!itos(fortcnt);end;
otherwise reject('Bad basis='!!basis); goto 1; end;
addform('PC'!!name,pcstr);
sumform := 'SUMI(PC' !! name !! ',' !! '7,0,SD' !! name !! ',FD' !! name !! ')';
end
else begin
with mintab do begin
if stoi(hd) = 7 then begin
 addform('VR1'!!substr(name,1,4),ctable(tab,kind,base,asynum));
 case stoi(kind) of
   1: begin hd := '2'; pcstr := 'VR1'!!name!!'/WAGE(SURVEYD)'; end;
   2: begin hd := '7'; pcstr := 'VR1'!!name; end;
   3: begin hd := '5'; pcstr := 'VR1'!!name; end;
   4: begin hd := '4'; pcstr := 'VR1'!!name; end;
 otherwise reject('Bad amount box='!!kind); goto 1;
 end; end
else begin
case stoi(hd) of
 2: pcstr := dollar !! '/WAGE(SURVEYD)';
 3,6: begin pcstr := dp(pc,'2'); maxstr := dollar; end;
 4,5,7,8: if pc = '9999' then pcstr := 'COENAR' else pcstr := dp(pc,'2');
 97,99:pcstr := 'COENAR';
 otherwise reject('MAN hd='!!hd); goto 1;
end; end;
addform('PC'!!name,pcstr);
sumform := 'SUMI(PC' !! name !! ',' !! hd !! ',' !! maxstr !! ',SD' !! name !! ',FD' !! name !! ')';
end; end;
sumform := srstr !! '(' !! sumform !! ')*' !! wkhrform;
sumform := sumform !! '*V' !! substr(name,1,2) !! substr(name,4,1);
addaform(name,sumform,'','','','','',false,false);
assert cc=nextcol;
1:end;
%page
procedure dat;
label 1;
var
  time: string(1);  fromd,tilld: string(8);  req: string(35);
begin
if zero(9) then goto 1;
if nogetdates(time,fromd,tilld) then goto 1;
case time1 of
  '1': req := '1';
  '2': req :=                'QUITD<'!!tilld;
  '3': req := fromd!!'<=QUITD';
  '4': req := fromd!!'<=QUITD&QUITD<'!!tilld;
  end;
if req='1'
   then definednamekind,nn := nulldef
   else addform(name,req);
assert cc=nextcol;
1:end;
%page
procedure fap;
label 1;
var
  defp,usep,time,max,lim: string(1);
  howd: string(2);
  asy,mage,masy: string(2);
  x1,x2,msum: string(3);
  n1,n2: string(6);
  mpay: string(6);
  fromd,tilld: string(8);
  sd,fd: string(54);
  fp: string(80);
  needfd,check: boolean;
begin
if zero(36) then goto 1;
howd := 'n'; defp := 'n'; usep := 'n';  max := 'n';  asy := 'na';
lim  := 'n';
x1   := 'z';   x2 := 'z'; mage := 'z'; masy := 'z'; msum := 'z';
mpay := 'z';
if noget(howd) then goto 1;  case stoi(howd) of
     1,2,3,8: ;
    10,4,5,9: x1 := 'n';
     6,7: begin  x1 := 'n';  x2 := 'n';  end;
   otherwise  reject('Defined');  goto 1;  end;
if noget(defp) then goto 1;
case defp1 of
   '1','2': ;
   otherwise  reject('Defined mo/yr');  goto 1;  end;
if noget(x1)   then goto 1;  if noget(x2) then goto 1;
if noget(usep) then goto 1;
if (howd='2')and(usep='3') then usep := '0';
case usep1 of
   '0','1','2': ;
   otherwise  reject('Used mo/yr');  goto 1;  end;
if nogetdates(time,fromd,tilld) then goto 1;
if noget(max) then goto 1;  case max1 of
    '1': begin  mage := 'n';  asy := 'z';  end;
    '2': masy := 'n';
    '3': msum := 'n';
    '8': begin  mage := 'n';  masy := 'n';  asy := 'z';  end;
'4','5': begin  mage := 'n';  masy := 'n';  end;
    '6': asy := 'z';
    otherwise  reject('Max time');  goto 1;  end;
if nogetnum(asy) then goto 1;
if noget(mage) then goto 1;  if noget(masy) then goto 1;
if noget(msum) then goto 1;  if noget(lim)  then goto 1;  case lim1 of
   '1': mpay := 'n';
   '2': ;
   otherwise  reject('Max pay');  goto 1;  end;
if noget(mpay) then goto 1;
case defp1 of
  '1': begin n1 := x1!!'/12'; n2 := x2!!'/12' end;
  '2': begin n1 := x1;        n2 := x2;       end;
  end;
check := false;
case stoi(howd) of
  1,2,3,5,8:  begin needfd:=false; sd:='HIRED' end;
  4,6,7,9,10: begin needfd:=true;  sd:='HIRED,FD'!!name!!'-'!!n1 end;
  end;
case max1 of
  '1': begin  check := true;
       fd := 'QUITD,BIRTHD+'!!mage;  end;
  '2': fd := 'QUITD,QUITD-ASY'!!asy!!'+'!!masy;
  '3': begin check := true;
       fd := 'QUITD,(BIRTHD+'!!msum!!'+QUITD-ASY'!!asy!!')/2';  end;
  '4': begin check := true;
       fd := 'QUITD,BIRTHD+'!!mage!!',QUITD-ASY'!!asy!!'+'!!masy; end;
  '5': fd := 'QUITD,MAX(BIRTHD+'!!mage!!',QUITD-ASY'!!asy!!'+'!!masy!!')';
  '6': fd := 'QUITD';
  '8': begin check := true;
       fd := 'QUITD,BIRTHD+' !! masy;
       sd :=  sd !! ',BIRTHD+' !! mage;  end;
  end;
if fromd<>'' then begin  sd := sd!!','!!fromd;  check := true;  end;
if tilld<>'' then begin  fd := fd!!','!!tilld;  check := true;  end;
if index(sd,',')<>0 then sd := 'MAX('!!sd!!')';
if index(fd,',')<>0 then fd := 'MIN('!!fd!!')';
if needfd or (check and (fd<>'QUITD')) then begin
   addform('FD'!!name,fd);
   fd := 'FD'!!name;
   end;
if check and (sd<>'HIRED') then begin
   addform('SD'!!name,sd);
   sd := 'SD'!!name;
   end
else if (substr(sd,1,3)<>'MAX')and(index(sd,'+')<>0) then
   sd := '('!!sd!!')';
case lim1 of
  '1': fp := 'MIN('!!mpay!!',WAGE';
  '2': fp := '(WAGE';
  end;
case stoi(howd) of
  1,5,8:  fp := fp!!'('!!fd!!'))';
  2:      fp := 'SUM'!!fp!!','!!sd!!','!!fd!!')';
  3,4,6,
  7,9,10: fp := 'AVG'!!fp!!','!!sd!!','!!fd!!')';
  end;
if check then
   fp := fd!!'>'!!sd!!'->'!!fp;
if usep='1' then fp := fp!!'/12';
addform(name,fp);
assert cc=nextcol;
1: end;
%page
%page
procedure frm;
label 1;
var
  ras,dat,rot,lng,beg: string(2);
  form: string(120);
  isvd,isne: boolean;  realname: string(5);
  b,e: deftypes;  bb: string(5);  ee:string(11);  ok: boolean;
begin
isne :=(substr(name,1,2)='NR') or (substr(name,1,2)='ER');
isvd := substr(name,1,2)='VD';
if zero(10-2*ord(isne)-2*ord(isvd)) then goto 1;
numform := numform + 1;
realname := name;
form := 'c';
ras := '';   dat := 'nd'; rot := 'nt'; lng := 'nl'; beg := '';
if not isvd then
   begin  ras := 'ns';  if nogetnum(ras) then goto 1;  end;
if nogetnum(dat) then goto 1;
if nogetnum(rot) then goto 1;
if nogetnum(lng) then goto 1;
if not isne then
   begin  beg := 'nb';  if nogetnum(beg) then goto 1;  end;
if nogetform(form) then goto 1;
if (dbenifit) and (dcontrib) then scandcf(form);
if (dbenifit) then scansectf(form);
addform(name,form);
if (ras<>'')or(rot<>'')or(dat<>'')or(beg<>'')or(lng<>'') then begin
   name := substr(name,1,2)!!substr(name,4)!!'Q';
   form := '';
   if (ras='96') or ((ras<>'') and (defineddefras,stoi(ras)<>nulldef)) then
      form := 'RAS'!!ras!!'&';
   if (dat='96') or (defineddefdat,stoi(dat)<>nulldef) then
      form := form!!'DAT'!!dat!!'&';
   if (rot='96') or (defineddefrot,stoi(rot)<>nulldef) then
      form := form!!'ROT'!!rot!!'&';
   if form<>'' then begin
      formlength(form) := '-';
      form := form !! '>';  end;
   if  beg='96'   then b := undef
   else if beg='' then b := nulldef  else b := defineddefbeg,stoi(beg);
   if  lng='96'   then e := undef    else e := defineddeflng,stoi(lng);
   bb := 'BEG'!!beg;  ee := 'LNG'!!lng;
   if  b=nulldef  then  bb := 'QUITD';
   case  e  of
     absdef: begin  ok := true;    end;
     reldef: begin  ok := true;    ee := ee!!'+'!!bb;  end;
    multdef: begin  ok := beg='';                 bb := 'BGN'!!lng;  end;
     adddef: begin  ok := beg='';  ee := '0';     bb := 'BGN'!!lng;  end;
    nulldef: begin  ok := true;    ee := '0';  end;
      undef: begin  ok := b=undef; end;
     end;
   if  (beg<>'96')and(lng<>'96')and(not ok)  then begin
     reject('Can not do BEG LNG combination');  goto 1;  end;
   if  (bb<>'QUITD') or (ee<>'0')  then
     form := form!!'AA('!!bb!!','!!ee!!')*';
   form := form !! realname;
   addaform(name,form,'','','','','',false,true);
   end;
assert cc=nextcol;
1:fv := 0; end;
%page
procedure frmc;
label 1;
var
  form: string(120);  x1,annrate: string(1); pcrate:string(4);
  asynum : string(2); crasfrm:string(200);
  crasform: array 1..11 of string(120); i:integer;
  s3a:string(1); s3b,s3c,s3d1,s3d2,s3e1,s3e2,s3f1,s3f2,s3h2:string(2);
  s3g,s3h1,s3i1,s3j1:string(3); s3i2,s3j2,s3j3:string(2); s3z:string(1);
begin
for i := 1 to 11 do crasformi := '';
if  zero(46)  then goto 1;
form := 'c'; x1 := 'p'; annrate := z; pcrate := z; asynum := 'y';
if  noget(x1)  then  goto 1;  case x11 of
 '1': annrate := n; '5','9' : annrate := z;
 otherwise reject('Bad hd rate'); goto 1; end;
if noget(annrate) then goto 1; case annrate1 of
 '1','3': pcrate := n; '2','4','7','9','0': ;
 otherwise reject('Bad pc rate'); goto 1; end;
 s3a := 'y'; s3b := 'y'; s3c := 'y'; s3d1 := 'y'; s3d2 := 'y'; s3e1 := 'y';
 s3e2 := 'y'; s3f1 := 'y'; s3f2 := 'y'; s3g := 'y'; s3h1 := 'y'; s3h2 := 'y';
 s3i1 := 'y'; s3i2 := 'y'; s3j1 := 'y'; s3j2 := 'y'; s3j3 := 'y'; s3z := 'y';
if noget(pcrate) then goto 1; if noget(asynum) then goto 1;
if noget(s3a) then goto 1; if noget(s3b) then goto 1;
if noget(s3c) then goto 1; if noget(s3d1) then goto 1;
if noget(s3d2) then goto 1; if noget(s3e1) then goto 1;
if noget(s3e2) then goto 1; if noget(s3f1) then goto 1;
if noget(s3f2) then goto 1; if noget(s3g) then goto 1;
if noget(s3h1) then goto 1; if noget(s3h2) then goto 1;
if noget(s3i1) then goto 1; if noget(s3i2) then goto 1;
if noget(s3j1) then goto 1; if noget(s3j2) then goto 1;
if noget(s3j3) then goto 1; if noget(s3z) then goto 1;
if (s3a <> '0') and (s3a <> '9') then crasform1 := '';
if (s3b <> '0') and (s3b <> '99') then crasform2 := 'AGE>='!!s3b;
if (s3c <> '0') and (s3c <> '99') then crasform3 := 'ASY'!!asynum!!'>='!!s3c;
if (s3d1 <> '0') and (s3d1 <> '99') then crasform4 := 'AGE>='!!s3d1!!'&ASY'!!asynum!!'>='!!s3d2;
if (s3e1 <> '0') and (s3e1 <> '99') then crasform5 := 'AGE>='!!s3e1!!'&ASY'!!asynum!!'>='!!s3e2;
if (s3f1 <> '0') and (s3f1 <> '99') then crasform6 := 'AGE>='!!s3f1!!'&ASY'!!asynum!!'>='!!s3f2;
if (s3g <> '0') and (s3g <> '999') then crasform7 := 'AGE+ASY'!!asynum!!'>='!!s3g;
if (s3h1 <> '0') and (s3h1 <> '999') then crasform8 := 'AGE+ASY'!!asynum!!'>='!!s3h1!!'&AGE>='!!s3h2;
if (s3i1 <> '0') and (s3i1 <> '999') then crasform9 := 'AGE+ASY'!!asynum!!'>='!!s3i1!!'&ASY'!!asynum!!'>='!!s3i2;
if (s3j1 <> '0') and (s3j1 <> '999') then crasform10 := 'AGE+ASY'!!asynum!!'>='!!s3j1!!'&AGE>='!!s3j2!!'&ASY'!!asynum!!'>='!!s3j3;
if (s3z <> '0') and (s3z <> '9') then crasform11 := '';
crasfrm := '';
for i := 1 to 11 do begin
 if crasformi <> '' then
   crasfrm := crasfrm !! '!('!! crasformi !! ')'; end;
if crasfrm <> '' then crasfrm := '(' !! substr(crasfrm,2) !! ')' !! '->CNT'
else crasfrm := 'CNT';
if  nogetform(form)  then goto 1;
addaform(name,form,'','','','','',false,false);
addaform('CNQ',crasfrm,'','','','','',false,true);
assert cc=nextcol;
1:fv := 0; end;
%page
procedure frmt;
label 1;
var
  blank: boolean;  nf: string(2);  moyr: string(1);  fact: string(4);
  form: string(120);
begin
blank := zero(3);
if listing then goto 1;
nf := 'x';  moyr := 'n';  form := 'c';
if noget(nf) then begin end;
if stoi(nf)<>numform then
   error('Number of formula found was '!!itos(numform));
numform := 0;
if blank then goto 1;
if noget(moyr) then goto 1;  case moyr1 of
   '1': fact := ')*12';
   '2': fact := ')';
   otherwise  reject('Benifits mo/yr');  goto 1;  end;
if nogetform(form) then goto 1;
if (dbenifit) and (dcontrib) then scandcf(form);
if (dbenifit) then scansectf(form);
addaform(name,form,'','','','','',false,true);
name := substr(name,1,2)!!substr(name,4)!!'Q';
   while replace(form, 'NRT', 'NRQ') do continue;
   while replace(form, 'ERT', 'ERQ') do continue;
   while replace(form, 'VDT', 'VDQ') do continue;
   while replace(form, 'DRT', 'DRQ') do continue;
   while replace(form, 'DST', 'DSQ') do continue;
   while replace(form, '#1',  '1Q') do continue;
   while replace(form, '#2',  '2Q') do continue;
   while replace(form, '#3',  '3Q') do continue;
   while replace(form, '#4',  '4Q') do continue;
   while replace(form, '#5',  '5Q') do continue;
   while replace(form, '#6',  '6Q') do continue;
   while replace(form, '#7',  '7Q') do continue;
   while replace(form, '#8',  '8Q') do continue;
addform(name,'('!!form!!fact);
assert cc=nextcol;
1:fv := 0; end;
%page
procedure ids;
label 1;
var
  seq,ppid: string(4);
  plan: string(3);
  kind: string(1);
begin
dbenifit := true;  dcontrib := true;
if zero(18) and listing then goto 1;
id := 'n';  seq :='n';  ppid := 'n';  plan := 'p';  kind := 'n';
if noget(id)   then id   := '????';
if noget(seq)  then seq  := '????';
if noget(ppid) then ppid := '????';
if noget(plan) then plan := '???';
if length(id)<4 then id := substr('000',length(id))!!id;
begcase(id,seq,ppid,plan);
if noget(kind) then goto 1;
case kind1 of
 '1': begin
      dcontrib := false;
      addaform('CNQ','0','','','','','',false,true);  end;
 '2': begin
      dbenifit := false;
      addform('NRQ','0');  addform('LRQ','0');  addform('ERQ','0');
      addform('VDQ','0');  addform('DRQ','0');  addform('DSQ','0');
      addform('VEDB','0');
      end;
 '3': ;
 otherwise  error('Invalid code')  end;
assert cc=nextcol;
1:end;
%page
procedure lng;
label 1;
var
   ss: string(1);  idef: normal;
   howd,yrs,age1,age2: string(2);
   b,e: string(40);  d: deftypes;
begin
if zero(9) then goto 1;
howd := 'p';
yrs := 'z';  age1 := 'z';  age2 := 'z';  ss := 'z';
if noget(howd) then goto 1;  idef := stoi(howd);
if nn in 10..12 then case idef of
       9: idef := 18;
 8,10,11: idef := 100 + idef;
      12: idef := 8;
   otherwise end;
if nn in 13..15 then case idef of
       9: idef := 100;
   otherwise end;
case idef of
100,108,110,111,1,8,
 18,19,30,50,51: ;
           2,20: yrs := 'n';
         3,4,23: age1 := 'n';
              5: begin  age1 := 'n';  age2 := 'n';  end;
            6,7: ss := 'n';
          21,22: begin age1 := 'n';  yrs := 'n';  end;
 97,99:begin note('Dis ben begin'); howd := '01'; idef := 1; end;
    otherwise  reject('Defined LNG');  goto 1;  end;
if noget(yrs)  then goto 1;  if noget(age1) then goto 1;
if noget(age2) then goto 1;  if noget(ss) then goto 1;
case ss1 of
  '0','1','2': ;
   otherwise  reject('SS reduced/unreduced for LNG');  goto 1;  end;
b := '';  e := '';
case  idef  of
111,100,1: ;
   2: e := '+'!!yrs;
   3: e := 'BIRTHD+'!!age1;
   4: b := 'MAX(BIRTHD+'!!age1!!',QUITD)';
   5: begin  b := 'MAX(BIRTHD+'!!age1!!',QUITD)';  e := 'BIRTHD+'!!age2;  end;
   6: e := 'BIRTHD+SSAGE('!!ss!!')';
   7: b := 'BIRTHD+SSAGE('!!ss!!')';
   8: e := '+1';
 108: e := 'ERD';
  23,
 110: e := 'QUITD';
  18: e := 'NRD';
  19: b := 'NRD';
  20: b := 'BENIFITD+'!!yrs;
  21: e := 'MIN(BIRTHD+'!!age1!!',BENIFITD+'!!yrs!!')';
  22: b := 'MAX(MIN(BIRTHD+'!!age1!!',BENIFITD+'!!yrs!!'),BENIFITD)';
  30: e := 'BIRTHD+50';
  50: e := 'MIN(BIRTHD+65,BENIFITD+ASY1/2)';
  51: e := 'MIN(BIRTHD+65,BENIFITD+ASY10/4)';
  end;
if  (b<>'')and(e<>'')  then  d := multdef
else if    b<>''       then  d := adddef
else if    e=''        then  d := nulldef
else if    e1<>'+'   then  d := absdef
else                  begin  d := reldef;  e := substr(e,2);  end;
definednamekind,nn := d;
if  b<>'' then  addform('BGN'!!itos(nn),b);
if  e<>'' then  addform(name,e);
assert cc=nextcol;
1:end;
%page
procedure lrmr;
label 1;
var mr, lr, lrdef, aibase, fitype, fibase,
    vitype, vibase, viflag: string(1);
    mrage, asynum: string(2);
    aifrom, aito, fifrom, fito: string(3);
    fivalue: string(8);
    vitable: table;
    asyvar: normal;  useasy: boolean;
    f: string(120);
begin
if zero(96) then  begin reject('No late/manditory'); goto 1  end;
useasy := false;
mr     := 'n';  lr     := 'n';
asynum := 'x';
lrdef  := 'z';  mrage := 'z';   aito := 'z';     fito := 'z';
aibase := 'z';  fibase := 'z';  vibase  := 'z';  mrage  := 'z';
if noget(mr) then goto 1;  case mr1 of
  '1': mrage := 'n';
  '5': ;
  otherwise  reject('Mandatory');  goto 1;  end;
if noget(mrage) then goto 1;
if noget(lr) then goto 1;  case lr1 of
  '1': lrdef := 'n';
  '5': ;
  otherwise  reject('Late');  goto 1;  end;
if noget(lrdef) then goto 1;  case lrdef1 of
  '0': ;
  '1': begin aibase := 'n'; aito := 'x'; end;
  '2': begin fibase := 'n'; fito := 'x'; end;
  '3': vibase := 'n';
  otherwise  reject('Late Defined');  goto 1;  end;
viflag := vibase; vitype := vibase;
fifrom := fibase; fitype := fibase; fivalue := fibase;
aifrom := aibase;
if noget(asynum) then goto 1;  asyvar := lastvar;
if noget(aibase) then goto 1;  case aibase1 of
  '0','1': ;
  otherwise reject('AI based on');  goto 1;  end;
if noget(aifrom) then goto 1;  if noget(aito) then goto 1;
if noget(fitype) then goto 1;  case fitype1 of
  '0','2': ;
  otherwise reject('FI type');  goto 1;  end;
if noget(fibase) then goto 1;  case fibase1 of
  '0','1': ;
  otherwise reject('FI based on');  goto 1;  end;
if noget(fivalue) then goto 1;  if noget(fifrom) then goto 1;
if noget(fito)  then goto 1;
if noget(vitype) then goto 1;  case vitype1 of
  '0','2': ;
  otherwise reject('VI type');  goto 1;  end;
if noget(vibase) then goto 1;  case vibase1 of
  '0','1': ;
  otherwise reject('VI based on');  goto 1;  end;
if nogettab(viflag,vitable) then goto 1;
if asynum='0' then begin
if ((asynum='0')=useasy) then begin
  lastvar := asyvar;  lastvalue := asynum;
  reject('ASY# should should not be zero');  goto 1;  end; end;
if lrdef='2' then with vitable1 do begin
   from := fifrom;  tooo := fito;  amount := fivalue;
   vitype := fitype;  vibase := fibase;  end;
if aito = '0' then aito := '999';
case lrdef1 of
    '0': f := 'NRQ';
    '1': f := 'AI('!!bbase(aibase,asynum)!!','
              !!aifrom!!','!!aito!!')*NRQ';
'2','3': f := btable(vitable,vitype,vibase,asynum)!!'*NRQ';
    end;
addaform(name,f,'','','','','',false,false);
case mr1 of
  '1': f := mrage;
  '5': f := '999';
  end;
addaform('MRAGE',f,'','','','','',false,true);
assert cc=nextcol;
1:end;
%page
function  manvolnoget(var t: manvoltab; var x: string(1);
  var  usess: boolean): boolean;
label 1;
var
  s: string(1);  asyvar: normal;  useasy: boolean;  isman: boolean;
begin with  t  do begin
manvolnoget := true; useasy := false; isman := (substr(name,1,3)='MAN') or (substr(name,1,3)='COE');
hd := 'p';
asynum := 'xa';
dollar := z;    pc := z;  s := z;
if  noget(hd)  then  goto 1;  if  isman and (hd='1')  then hd := '99';
case  stoi(hd)  of
  1: if  x='x'  then  x := z;
  2:        dollar := n;
  3: begin  dollar := n;  pc := n;  end;
4,5: begin                pc := n;  usess := true;  end;
  6: begin  dollar := n;  pc := n;  usess := true;  end;
  7:         s:= n;
  97,99:  ;
  otherwise  reject('Defined MAN/VOL');  goto 1;  end;
x := 'y';
base := s;  kind := s;
if  noget(x)  then  goto 1;  case  x1  of
 '0': ;  '9' : begin note('Pre/Pos--Ann/Car'); x1 := '1'; end;
 '1','2': ;
  otherwise  reject('Pre/Post--Annual/Career');  goto 1;  end;
if stoi(hd) = 7 then begin
if  nogetnum(asynum)  then  goto 1;  asyvar := lastvar; end
else begin asynum := 'y'; if noget(asynum) then goto 1; end;
if  noget(dollar)  then  goto 1;
if (dollar='999996')and(hd='3')  then
    begin  dollar := '0';  hd := '8';  end;
if  dollar>'999995'  then
    begin  reject('Max dollar amt.');  goto 1  end;
if  noget(pc)  then  goto 1;
if  noget(kind)  then  goto 1;  case  kind1  of
  '0','1','2': ;
      '3','4': usess := true;
  otherwise  reject('$Ammount box');  goto 1;  end;
if  noget(base)  then  goto 1;  case  base1  of
  '0','1','2': ;
      '3','4': useasy := true;
  otherwise  reject('Pay box');  goto 1;  end;
if  nogettab(s,tab)  then  goto 1;
if asynum = '0' then begin
if  useasy<>(asynum<>'0')  then begin
    lastvar := asyvar;  lastvalue := asynum;
    reject('ASY# should should not be zero');  goto 1;  end; end;
manvolnoget := false;
1:end;end;
%page
procedure manvol;
label 1;
var
  prepost,antotal,sswb,time,start,finish,wdint: string(1);
  ssyr,stage,styrs,fnasynum,fnage,fnasy,wd,wdasynum,wdage,wdasy,
       ac,acasynum,acage,acasy: string(2);
  fnsum,wdsum,acsum: string(3);
  wdpc: string(4);
  fromd,tilld: string(8);
  mintab,maxtab: manvoltab;
  isdb,isdc,isvol,usess: boolean;
  startstr,finstr,fdstr,sdstr,pcstr,volmin,volmax,sumform :string(200);
  maxstr,newpc : string(30);
begin
name := substr(name,1,4);
isdc := ('1'<=name4)and(name4<='3');
isdb := not isdc;
isvol:= substr(name,1,3)='VOL';
if zero(132+ord(isdb)*3+ord(isvol)*(105+ord(isdc)*11)) then goto 1;
usess := false;
sswb  := 'p';   start := 'p';   finish := 'p';  wd := 'p';     wdint := 'p';
ac    := 'p';   prepost := n;
ssyr  := z;   stage := z;   styrs := z;   fnage := z;  fnasy := z;
fnsum := z;   wdage := z;   wdasy := z;   wdsum := z;  wdpc  := z;
acage := z;   acasy := z;   acsum := z;
antotal := x;
if  manvolnoget(mintab,prepost,usess)  then  goto 1;
if  isvol  then if  manvolnoget(maxtab,antotal,usess)  then  goto 1;
if  isvol and isdc  then  cv := cv + 58;
if  noget(sswb)  then  goto 1;
if  usess<>(sswb<>'4')  then
    begin  reject('Wagebase not used');  goto 1;  end;
case  sswb1  of
  '1','2','4': ;
  '7','9': begin note('SSWB'); sswb1 := '4'; end;
          '3': ssyr := n;
  otherwise  reject('SS Wage Base');  goto 1;  end;
if  noget(ssyr)  then  goto 1;
if  isdc  then begin
  if  nogetdates(time,fromd,tilld)  then  goto 1;
  if  noget(start)  then  goto 1;  case  start1  of
    '1': ;                '3': styrs := n;
    '2': stage := n;  '4','5': begin  stage := n;  styrs := n;  end;
    '7','9':begin note('When Begin'); start1 := '1'; end;
    otherwise  reject('When begin');  goto 1;  end;
  if  noget(stage)  then  goto 1;  if  noget(styrs)  then goto 1;
  if  noget(finish)  then goto 1;  case  finish1  of
    '1': fnage := n;      '2': fnasy := n;
    '3': fnsum := n;  '4','5': begin  fnage := n;  fnasy := n;  end;
  '7','9': begin note('When end'); finish1 := '6'; end;
    '6': ;  otherwise  reject('Max age asy');  goto 1;  end;
  fnasynum := fnasy!!'a';
  if  nogetnum(fnasynum) then  goto 1;  if  noget(fnage)  then goto 1;
  if  noget(fnasy)       then  goto 1;  if  noget(fnsum)  then goto 1;
  end;
if  isdb or isvol  then begin
  if  noget(wd)  then  goto 1;  case  stoi(wd)  of
    2: wdage := n;    6: wdsum := n;
    3: wdasy := n;  4,5: begin  wdage := n;  wdasy := n;  end;
    8:begin note('Withdraw'); wd := '01'; end;
    97,99:begin note('Withdraw'); wd := '07'; end;
    1,7: ;  otherwise  reject('Withdraw');  goto 1;  end;
  wdasynum := wdasy!!'a';
  if  nogetnum(wdasynum) then  goto 1;  if  noget(wdage)  then goto 1;
  if  noget(wdasy)       then  goto 1;  if  noget(wdsum)  then goto 1;
  if  isdb  then  begin
    if  noget(wdint)  then  goto 1;  case  wdint1  of
      '1': wdpc := x;  Should be = n if this var is used '2': ;    '3': ;
     '4': begin note('Interest'); wdint1 := '2'; end;
     '7','9': begin note('Interest'); wdint1 := '2'; end;
      otherwise  reject('Interest');  goto 1;  end;
    if  noget(wdpc)  then goto 1;
    if  noget(ac)  then  goto 1;  case  stoi(ac)  of
        3: acage := x;  Should be =n if this var is used        4: acasy := n;
        5: acsum := n;      6,7: begin  acage := n;  acasy := n;  end;
        1,2: ;
        8,97,99: begin note('Accrue over'); ac := '02'; end;
       otherwise  reject('Accrue over');  goto 1;  end;
    acasynum := wdasy!!'a';
    if  nogetnum(acasynum) then goto 1; if  noget(acage)  then goto 1;
    if  noget(acasy)       then goto 1; if  noget(acsum)  then goto 1;
  end;end;
if not isdc then begin start := '1'; finish := '6'; time := '1'; end;
case stoi(start) of
 1: startstr := 'HIRED';
 2: startstr := 'BIRTHD+' !! stage;
 3: startstr := 'BIRTHD+' !! styrs;
 4: startstr := 'MIN(BIRTHD+' !! stage !! ',HIRED+' !! styrs !! ')';
 5: startstr := 'MAX(BIRTHD+' !! stage !! ',HIRED+' !! styrs !! ')';
end;
case stoi(finish) of
 1: finstr := 'BIRTHD+' !! fnage;
 2: finstr := 'SD' !! name !! '+' !! fnasy;
 3: finstr := '(BIRTHD+SD' !! name !! '+' !! fnsum !! ')*50%';
 4: finstr := 'MIN(BIRTHD+' !! fnage !! ',SD' !! name !! '+' !! fnasy !! ')';
 5: finstr := 'MAX(BIRTHD+' !! fnage !! ',SD' !! name !! '+' !! fnasy !! ')';
 6: finstr := 'QUITD';
end;
case stoi(time) of
 1: begin
       if start = '1' then sdstr := startstr
       else sdstr := 'MAX(HIRED,' !! startstr !! ')';
       if finish = '6' then fdstr := finstr
       else fdstr := 'MIN(QUITD,' !! finstr !! ')';
      end;
 2: begin
       if start = '1' then sdstr := startstr
       else sdstr := 'MAX(HIRED,' !! startstr !! ')';
       if finish = '6' then fdstr := 'MIN(QUITD,' !! tilld !! ')'
       else fdstr := 'MIN(QUITD,' !! finstr !! ',' !! tilld !! ')';
      end;
 3: begin
       if start = '1' then sdstr := 'MAX(HIRED,' !! fromd !! ')'
       else sdstr := 'MAX(HIRED,' !! startstr !! ',' !! fromd !! ')';
       if finish = '6' then fdstr := finstr
       else fdstr := 'MIN(QUITD,' !! finstr !! ')';
      end;
 4: begin
       if start = '1' then sdstr := 'MAX(HIRED,' !! fromd !! ')'
       else sdstr := 'MAX(HIRED,' !! startstr !! ',' !! fromd !! ')';
       if finish = '6' then fdstr := 'MIN(QUITD,' !! tilld !! ')'
       else fdstr := 'MIN(QUITD,' !! finstr !! ',' !! tilld !! ')';
      end;
 otherwise reject('Bad Man/Vol Time'); goto 1;
end;
addform('SD'!!substr(name,1,4),sdstr);
addform('FD'!!substr(name,1,4),fdstr);
maxstr := '0';
if not isvol then begin
 with mintab do begin
 if stoi(hd) = 7 then begin
  addform('VR1'!!substr(name,1,4),ctable(tab,kind,base,asynum));
  case stoi(kind) of
    1: begin hd := '2'; pcstr := 'VR1'!!name!!'/WAGE(SURVEYD)'; end;
    2: begin hd := '7'; pcstr := 'VR1'!!name; end;
    3: begin hd := '5'; pcstr := 'VR1'!!name; end;
    4: begin hd := '4'; pcstr := 'VR1'!!name; end;
  otherwise reject('Bad amount box'); goto 1;
  end; end
 else begin
 case stoi(hd) of
  2: pcstr := dollar !! '/WAGE(SURVEYD)';
  3,6: begin pcstr := dp(pc,'2'); maxstr := dollar; end;
  4,5,7,8: pcstr := dp(pc,'2');
  97,99: pcstr := 'MANNAR';
  otherwise reject('MAN hd='!!hd); goto 1;
 end; end;
 addform('PC'!!substr(name,1,4),pcstr);
 sumform := 'SUMI(PC' !! name !! ',' !! hd !! ',' !! maxstr !! ',SD' !! name !! ',FD' !! name !! ')';
 addaform(name,sumform,'','','','','',false,isdb); end; end
else begin
  with mintab do begin
  if stoi(hd) = 7 then begin
   addform('VR1'!!substr(name,1,4),ctable(tab,kind,base,asynum));
   case stoi(kind) of
    1: begin hd := '2'; dollar := 'VR1'!!name; end;
    2: begin hd := '7'; newpc := 'VR1'!!name; end;
    3: begin hd := '5'; newpc := 'VR1'!!name; end;
    4: begin hd := '4'; newpc := 'VR1'!!name; end;
   otherwise reject('Bad amount box'); goto 1; end; end
  else newpc := dp(pc,'2');
  case stoi(hd) of
   1: volmin :=  '0';
   2: volmin :=  dollar;
   3: volmin :=  'MAX(' !! dollar !! ',' !! newpc !! '*WAGE(SURVEYD))';
   4: volmin :=  newpc !! '*MIN(SSBASE(SURVEYD),WAGE(SURVEYD))';
   5: volmin :=  newpc !! '*MAX(0,WAGE(SURVEYD)-SSBASE(SURVEYD))';
   6: volmin :=  'MIN(' !! dollar !! ',' !! newpc !! '*MAX(0,WAGE(SURVEYD)-SSBASE(SURVEYD))';
   7,8: volmin :=  newpc !! '*WAGE(SURVEYD)';
   97,99: volmin := 'VOL1NAR*WAGE(SURVEYD)';
   otherwise reject('MinVol hd=' !! hd); goto 1;
  end; end;
  with maxtab do begin
  if stoi(hd) = 7 then begin
   addform('VR2'!!substr(name,1,4),ctable(tab,kind,base,asynum));
   case stoi(kind) of
    1: begin hd1 := '2'; dollar := 'VR2'!!name; end;
    2: begin hd := '7'; newpc := 'VR2'!!name; end;
    3: begin hd := '5'; newpc := 'VR2'!!name; end;
    4: begin hd := '4'; newpc := 'VR2'!!name; end;
   otherwise reject('Bad amount box'); goto 1; end; end
  else newpc := dp(pc,'2');
  case stoi(hd) of
   1: volmax :=  '0';
   2: volmax :=  dollar;
   3: volmax :=  'MAX(' !! dollar !! ',' !! newpc !! '*WAGE(SURVEYD))';
   4: volmax :=  newpc !! '*MIN(SSBASE(SURVEYD),WAGE(SURVEYD))';
   5: volmax :=  newpc !! '*MAX(0,WAGE(SURVEYD)-SSBASE(SURVEYD))';
   6: volmax :=  'MAX(' !! dollar !! ',' !! newpc !! '*MAX(0,WAGE(SURVEYD)-SSBASE(SURVEYD))';
   7,8: volmax :=  newpc !! '*WAGE(SURVEYD)';
   97,99: volmax := 'VOL2NAR*WAGE(SURVEYD)';
   otherwise reject('MaxVol hd='!!hd); goto 1;
  end; end;
  if volmax = '0' then pcstr := 'MAX(' !! volmin !! ',CRVOL*WAGE(SURVEYD))/WAGE(SURVEYD)'
  else pcstr := 'MAX(' !! volmin !! ',MIN(' !! volmax !! ',CRVOL*WAGE(SURVEYD)))/WAGE(SURVEYD)';
  addform('PC'!!substr(name,1,4),pcstr);
  sumform := 'SUMI(PC' !! name !! ',2,0,SD' !! name !! ',FD' !! name !! ')';
  addaform(substr(name,1,4),sumform,'','','','','',false,isdb);
  end;

assert cc=nextcol;
1:end;
%page
procedure match;
label 1;
var
  hd,s,base,kind,maxhd,time: string(1);  asynum,rot: string(2);
  hdpc,maxpc: string(4);   maxdollar: string(6);
  fromd,tilld: string(8);  tab: table;  useasy,isdecimal: boolean;
  asyvar: normal;
  matchstr : string(200);  startm, finishm, pcmstr, maxstr, srstr : string(50);
begin
if zero(150) then goto 1;
hd := 'p';    maxhd := n;  rot := 'p';  asynum := 'xa';  time := '1';
hdpc := z;  s := z;      maxdollar := z;  maxpc := z;
if  noget(hd)  then  goto 1;  case  hd1  of
  '1': hdpc := n;  '2': s := n;
  '7','9':;
  otherwise  reject('Match');  goto 1;  end;
base := s;  kind := s;
if  nogetnum(asynum)  then goto 1;  asyvar := lastvar;
if  noget(hdpc)  then  goto 1;
if  noget(kind)  then  goto 1;  case  kind1  of
  '0': if hd1 = '2' then begin reject('Dollar/PC'); goto 1; end;
  '1','2': ;  otherwise  reject('Dollar/PC');  goto 1;  end;
useasy := false;
if  noget(base)  then  goto 1;  case  base1  of
  '0': if hd1 = '2' then begin reject('Dollar/PC'); goto 1; end;
    '3','4': useasy := true;
  '1','2','5': ;  otherwise  reject('Pay Box');  goto 1;  end;
if asynum = '0' then begin
if useasy<>(asynum<>'0')  then begin
   lastvar := asyvar;  lastvalue := asynum;
   reject('ASY# should not be zero'); goto 1;  end; end;
if  nogettab(s,tab)  then  goto 1;
if  noget(maxhd)  then  goto 1;  case  maxhd1  of
   '1': maxdollar := n;  '2':  maxpc := n;
  '7','9':begin note('Max Match'); maxhd1 := '3'; end;
   '3': ;  otherwise  reject('Max Match');  goto 1;  end;
if  noget(maxdollar)  then  goto 1;  if  noget(maxpc)  then  goto 1;
if  noget(rot)  then  goto 1;  case  stoi(rot)  of
     97,99:begin note('Bad rot'); rot := '1'; end;
       4: time := 'o'; 5: time := '2'; 6: time := '3'; 7: time := '4';
   1,2,3: ;  otherwise  reject('Other');  goto 1;  end;
if  nogetdates(time,fromd,tilld)  then  goto 1;
case stoi(rot) of
 1: srstr := '';
 2: srstr := 'QAPPROVL->';
 3: srstr := 'QPASTSRV->';
 4: srstr := '((HIRED<=' !! fromd !! ')&(QUITD>=' !! fromd !! '))->';
 5: srstr := '(HIRED<=' !! tilld !! ')->';
 6: srstr := '(QUITD>=' !! fromd !! ')->';
 7: srstr := '((HIRED<=' !! fromd !! ')&(QUITD>=' !! tilld !! '))->';
otherwise reject('Bad special requirement'); goto 1; end;
case maxhd1 of
 '1': maxstr := maxdollar !! '/WAGE(SURVEYD)';
 '2': maxstr := dp(maxpc,'2');
 '3': ;
otherwise reject('Bad max match'); goto 1; end;
case hd1 of
 '1': begin pcmstr := dp(hdpc,'2') !! '*PC' !! substr(name,2);
      isdecimal := replace2(pcmstr,'.',''); if not isdecimal
      then isdecimal := replace(pcmstr,'%','0%'); end;
 '2': begin addform('VR1'!!name,ctable(tab,kind,base,asynum));
      case kind1 of
       '1': pcmstr := 'VR1' !! name !! '/WAGE(SURVEYD)';
       '2': pcmstr := 'VR1' !! name !! '*PC' !! substr(name,2);
      otherwise reject('Bad kind'); goto 1; end; end;
 '7','9': pcmstr := substr(name,1,4) !! 'NAR*PC' !! substr(name,2);
otherwise reject('Bad match hd'); goto 1; end;
if (maxhd1 = '1') or (maxhd1 = '2')
  then pcmstr := 'MIN(' !! maxstr !! ',' !! pcmstr !! ')';
addform('PC'!!name,pcmstr);
startm := 'SD' !! substr(name,2); finishm := 'FD' !! substr(name,2);
matchstr := srstr !! 'SUMI(PC' !! name !! ',7,0,' !! startm !! ',' !! finishm !! ')';
matchstr := matchstr !! '*V' !! substr(name,1,2) !! substr(name,5,1);
addaform(name,matchstr,'','','','','',false,false);
assert cc=nextcol;
1:end;
%page
procedure post;
label 1;
var  adj,hfreq,cpi,cpiuse,pay,payuse: string(1);
     freq,fixed: string(2);
     cpi1,cpi2,cpi3,pay1,pay2: string(4);
     b,lfrom,rfrom: string(8);  prag: string(80);
     t : string(24);  deffreq:boolean;
begin
if  zero(30) and listing  then  goto 1;
adj := 'p';
cpiuse := z;  cpi1 := z;  cpi2 := z;  cpi3 := z;
payuse := z;  pay1 := z;  pay2 := z;
if  noget(adj)  then  goto 1;  case  adj1  of
  '1': begin  hfreq := 'p';  cpi := 'y';  end;
  '5': begin  hfreq := z;  cpi := z;  end;
  '9': begin note('C.O.L.A.'); adj1 := '5'; hfreq := z; cpi := z; end;
   otherwise  reject('J1');  goto 1;  end;
pay := cpi;  freq := hfreq;  fixed := hfreq;
deffreq := false;
if  noget(hfreq)  then  goto 1;  case  hfreq1  of
  '0','1','2': ;
  '7','9': begin note('J1A freq'); hfreq1 := '2'; deffreq := true; freq := 'y'; end;
   otherwise  reject('J1A');  goto 1;  end;
if  noget(freq)  then  goto 1;
if deffreq then freq := '01';
if  noget(cpi)  then  goto 1;  case  cpi1  of
  '0','5': ;
  '9': begin note('Cpi'); cpi1 := '5'; end;
  '1': begin  cpiuse := 'p';  pay := z;  fixed := z;  end;
  '3': begin note('J1B CPI'); cpi1 := '1'; cpiuse := 'p'; pay := z; fixed := z; end;
   otherwise  reject('J1B');  goto 1;  end;
if  noget(cpiuse)  then  goto 1;  case  cpiuse1  of
  '0': ;
  '1','2': begin  cpi1 := n;  end;
  '3','4': begin  cpi2 := n;  cpi1 := n;  end;
      '5': begin  cpi1 := n;  cpi2 := n;  cpi3 := 'n';  end;
  '7','9': begin note('J1C Use'); cpiuse1 := '1'; cpi1 := z; end;
   otherwise  reject('J1C');  goto 1;  end;
if  noget(cpi1)  then  goto 1;  if  noget(cpi2)  then  goto 1;
if  noget(cpi3)  then  goto 1;
if  noget(pay)   then  goto 1;  case  pay1  of
  '0','5': ;
  '1': begin  payuse := n;  fixed := z;  end;
  '9': begin note('J2 - pay'); pay1 := '5'; end;
   otherwise  reject('J2');  goto 1;  end;
if  noget(payuse)  then  goto 1;  case  payuse1 of
  '0': ;
  '1': begin  pay1 := n;  end;
  '2': begin  pay1 := n;  pay2 := 'n';  end;
  '7': begin note('J2A Payuse'); pay1 := z; end;
   otherwise  reject('J2A');  goto 1;  end;
if  noget(pay1)   then  goto 1;  if  noget(pay2)  then  goto 1;
if  noget(fixed)  then  goto 1;  case  stoi(fixed)  of
   0,1: ;
   97,99:begin note('J3'); fixed := '01'; end;
   otherwise  reject('J3');  goto 1;  end;
if  adj='5'  then  prag := '0'  else begin
  t := freq;
  if  hfreq='1'  then  t := t !!'/12';
  if  (t='1')or(t='12/12')
    then  begin lfrom := '';  rfrom := '';  end
    else  begin lfrom := 'FAR(';  rfrom := ','!!t!!')';  end;
  if      cpi='1'  then  b := 'ACPIG'
  else if pay='1'  then  b := 'AWAGEG'
                   else  b := '';
  t := lfrom !! b !! rfrom;
  case  cpiuse1  of
   '0': ;
   '1': prag :=  'NN('!! t !!'-'!! pp(cpi1) !!')';
   '2': prag :=            pp(cpi1) !!'*' !! t;
   '3': prag :=   'MIN('!! pp(cpi1) !!'*' !! t !!','!! pp(cpi2) !!')';
   '4': prag := t !!'>='!! pp(cpi2) !!'->'!! pp(cpi1) !!'*'!! t;
   '5': prag := t !!'>='!! pp(cpi3) !!'->'!!
                  'MIN('!! pp(cpi1) !!'*' !! t !!','!! pp(cpi2) !!')';
   end;
  case  payuse1  of
   '0': ;
   '1': prag :=            pp(pay1) !!'*' !! t;
   '2': prag :=   'MIN('!! pp(pay1) !!'*' !! t !!','!! pp(pay2) !!')';
   '7': prag := '100%*' !! t;
   end;
  case  stoi(fixed)  of
     0: ;
     1: prag := '3%';
   end;
  if  lfrom='FAR('  then  prag := 'TAR('!! prag !! rfrom;
  end;
addaform(name,prag,'','','','','',false,true);
assert  cc=nextcol;
1:end;
%page
procedure psy;
label 1;
var howd,time,max: string(1);
    tage,dage,dyrs,myrs:string(2);
    fromd,tilld: string(8);
    sd,fd: string(54);
    check: boolean;
begin
if zero(19) then goto 1;
howd := 'n'; tage := 'n'; max := 'n';
dage := 'z'; dyrs := 'z'; myrs := 'z';
if noget(howd) then goto 1;  case howd1 of
  '1': ;
  '2': dage := 'n';
  '3': dyrs := 'n';
  '4',
  '5': begin  dage := 'n';  dyrs := 'n';  end;
  otherwise  reject('Defined');  goto 1;  end;
if noget(tage) then goto 1;  if noget(dage) then goto 1;
if noget(dyrs) then goto 1;
if nogetdates(time,fromd,tilld) then goto 1;
if noget(max)  then goto 1;  case max1 of
   '1': myrs := 'n';
   '2': ;
   otherwise  reject('Maximum');  goto 1;  end;
if noget(myrs) then goto 1;
check := true;
case howd1 of
  '1': begin  check := false;
       sd := 'HIRED';  end;
  '2': sd := 'HIRED,BIRTHD+'!!dage;
  '3': sd := 'HIRED+'!!dyrs;
  '4': sd := 'HIRED,MIN(HIRED+'!!dyrs!!',BIRTHD+'!!dage!!')';
  '5': sd := 'HIRED+'!!dyrs!!',BIRTHD+'!!dage;
  end;
fd := 'BIRTHD+'!!tage;
if fromd<>'' then  begin  sd := sd!!','!!fromd;  check := true;  end;
if tilld<>'' then  begin  fd := fd!!','!!tilld;  check := true;  end;
if index(sd,',')<>0 then sd := 'MAX('!!sd!!')';
if index(fd,',')<>0 then fd := 'MIN('!!fd!!')';
if check then begin fd := 'NN('!!fd;  sd := sd!!')';  end;
if max='1' then begin fd :='MIN('!!myrs!!','!!fd; sd := sd!!')';  end;
addform(name,fd!!'-'!!sd);
assert cc=nextcol;
1:end;
%page
procedure ras;
label 1;
var
  nomin, other: string(1);
  age,asy,asynum: string(2);
  sum: string(3);
  i,asyvar: normal;
  useasy,b: boolean;
  req: string(120);
begin
if zero(40) then goto 1;
useasy := false; req := '';
asynum := 'xa';  if nogetnum(asynum) then goto 1;  asyvar := lastvar;
nomin := 'x';   if noget(nomin)  then goto 1;  case nomin1 of
   '0': nomin := 'x';
   '1': begin nomin := 'z';  req := '1';  end;
   otherwise  reject('RAS no minimum');  goto 1;  end;
for i := 2 to 10 do begin
  sum := nomin;  age := nomin;  asy := nomin;  b := false;
  if i in 7..10 then begin
     if noget(sum) then goto 1;
     if sum<>'0' then begin
        if req<>'' then req := req !! '!';
        req := req!!'AGE+ASY'!!asynum!!'>='!!sum;
        b := true;  age := 'n';  asy := 'n';  useasy := true;
     end;end;
  if i in 2,4,5,6,8,10 then begin
     if noget(age) then goto 1;
     if age<>'0' then begin
        if b then req := req !!'&'
        else if req<>'' then req := req !! '!';
        req := req !!'AGE>='!!age;
        b := true;  asy := 'n';
     end;end;
  if i in 3,4,5,6,9,10 then begin
     if noget(asy) then goto 1;
     if asy<>'0' then begin
        if b then req := req !!'&'
        else if req<>'' then req := req!!'!';
        req := req!!'ASY'!!asynum!!'>='!!asy;
        b := true;  useasy := true;
     end;end;
  end;
other := 'z';  if noget(other) then goto 1;
if asynum = '0' then begin
if useasy<>(asynum<>'0')  then begin
   lastvar := asyvar;  lastvalue := asynum;
   reject('ASY# should not be zero'); goto 1;  end; end;
if req='1'
   then definednamekind,nn := nulldef
   else addform(name,req);
assert cc=nextcol;
1:end;
%page
procedure red;

 Howd (reduction factors) after adjustment:
  '0' Workers Comp.
  '1' Actuarial Reduction
  '2' Fixed reduction
  '3' Varying reduction
  '4' Unspecified
  '6' Cost of optional coverage.
  '7' Other
  '9' NA

label 1;
var
  howd,arhow,frtype,frhow,vrtype,vrhow,vrflag,vrt: string(1);
  asy,arage: string(2);
  arsum,frsum: string(3);
  framt: string(8);
  vrtable: table;
  idef,asyvar: normal;
  i: 1..5;
  useasy,isds,isdr: boolean;
  rf: string(120);
begin
isds := nn in 13..15;
isdr := nn in 10..12;
if zero(88-6*ord(isds))
   then goto 1;
defineddefred,nn := multdef;
howd  := 'n';
asy   := 'xa'; useasy := false;
arhow := 'z';  arage  := 'z';  arsum := 'z';  frhow := 'z';
vrhow := 'z';  vrflag := 'z';  framt := 'z';
if noget(howd) then goto 1;
idef := stoi(howd);  howd := '#';
if isdr then case idef of
  2: idef := 10;
  3: idef := 2;
  4: idef := 3;
  5: idef := 4;
  6: idef := 11;
  otherwise  end;
if isds then case idef of
  1: idef := 12;
  6: idef := 11;
  otherwise  end;
case idef of
    1: arhow := 'n';
    2: begin  frhow := 'n';  framt := 'n';  end;
    3: vrhow := 'n';
  4,7: note('Defined RED');
   10: defineddefred,nn := adddef;
   11: framt := '-';
   12: ;
  otherwise reject('Defined RED');  goto 1;  end;
frtype := frhow;  frsum := frhow;
vrtype := vrhow;  vrflag := vrhow;
if nogetnum(asy) then goto 1;  asyvar := lastvar;
if isds then begin
   arhow := '0';  arage := '0';  arsum := '0'; end
else begin
   if noget(arhow) then goto 1;  case arhow1 of
     '0': ;
     '5': begin arage := 'n';  useasy := true;  end;
     '1': begin arage := 'n';  end;
     '2': begin arsum := 'n';  useasy := true;  end;
     '3',
     '4': note('AR to Age');
     otherwise reject('AR to Age');  goto 1;  end;
   if noget(arage)  then goto 1;  if noget(arsum) then goto 1;
   end;
if noget(frtype) then goto 1;  case frtype1 of
  '0','2': ;
  '1': defineddefred,nn := adddef;
  otherwise  reject('FR type $/%');  goto 1;  end;
if noget(frhow) then goto 1;  case frhow1 of
  '0','1': ;
  '2','3': useasy := true;
  otherwise  reject('FR before age/asy/sum');  goto 1;  end;
if noget(framt)  then goto 1;  if noget(frsum) then goto 1;
if noget(vrtype) then goto 1;  case vrtype1 of
  '0','2': ;
  '1': defineddefred,nn := adddef;
  otherwise  reject('VR type $/%');  goto 1;  end;
if noget(vrhow) then goto 1;  case vrhow1 of
  '0','1': ;
  '2','3': useasy := true;
  otherwise  reject('VR before age/asy/sum');  goto 1;  end;
if nogettab(vrflag,vrtable) then goto 1;
if asy = '0' then begin
if ((asy='0')=useasy) then begin
   lastvar := asyvar;  lastvalue := asy;
   reject('ASY# should not be zero');  goto 1;  end; end;
case  idef  of
  4: arhow := '3';
  2: begin
     vrtype  := frtype;
     vrhow   := frhow;
     vrtable1.amount:= framt;
     vrtable1.tooo := frsum;  end;
  otherwise end;
case  idef  of
 10: rf := 'OTHERB';
 11: rf := 'COSTRED';
 12: rf := 'JSRED';
2,3: rf := btable(vrtable,vrtype,vrhow,asy);
4,1: begin
     case  arhow1 of
       '1': rf := arage!!'-AGE';
       '2': rf := arsum!!'-AGE-ASY'!!asy;
       '3': rf := 'NRD-BENIFITD';
       '4': rf := 'ERD-BENIFITD';
       '5': rf := arage!!'-ASY'!!asy;
       end;
     rf := 'AR('!!rf!!')';
     end;
  otherwise  reject('Can not handle RED '!!itos(idef));  goto 1;  end;
addaform(name,rf,'','','','','',defineddefred,nn=multdef,false);
assert cc=nextcol;
1:end;
%page
procedure rot;
label 1;
var
   time: string(1);
   howd: string(2);  idef: normal;
   fromd,tilld: string(8);
   form: string(120);
   req: string(80);
begin
if zero(10) then goto 1;
howd := 'n';  if noget(howd) then goto 1;
idef := stoi(howd);
if nn in 7..9 then case idef of
    3..6: idef := idef - 3 + 101;
    7..9: idef := idef - 2;
    otherwise  end;
if nn in 10..12 then case idef of
   4.. 7: idef := idef - 4 + 105;
   8..11: idef := idef - 3;
   otherwise  end;
if nn in 13..15 then case idef of
   9..12: idef := idef - 9 + 109;
   otherwise  end;
form := 'b';  if idef in 39,41,45,60..64,72,96 then form := 'c';
case idef of
     1..4,20..23,30..36,40..43,72..74,
    101..112,24,39,45,46,64,96: time := '1';
                         97,99:begin note('Def Rot'); time := '1'; end;
                       5,60,69: time := 'o';
                    7,62,67,76: time := '3';
     6,38,47,61,66,70,71,75,77: time := '2';
                8, 63,65,78,79: time := '4';
                     otherwise  reject('Defined ROT');  goto 1;  end;
if nogetdates(time,fromd,tilld) then goto 1;
if nogetform(form) then goto 1;
case time1 of
   '1': req := '';
   '2': req := 'PARTD<'!!tilld;
   '3': req :=                       fromd!!'<=QUITD';
   '4': req := 'PARTD<'!!fromd!!'&'!!tilld!!'<=QUITD';
   'o': req := 'PARTD<'!!fromd!!'&'!!fromd!!'<=QUITD';
   end;
case idef of
     1: req := '1';
     2: req :=  'QAPPROVL';
     3: req :=  'QVOLCNTR';
     4: req :=  'QPASTSRV';
  5..8: ;
   101: req := '^QWDMAN';
   102: req := '^QWDVOL';
   103: req :=  'QWDMAN';
   104: req :=  'QWDVOL';
   105: req :=  'QJRDABLE';
   106: req := '^QJRDABLE';
   107: req :=  'QSSDABLE';
   108: req := '^QSSDABLE';
   109: req :=  'QJRDEATH';
   110: req := '^QJRDEATH';
   111: req :=  'QSSBENIF';
   112: req := '^QSSBENIF';
    20: req :=  'QVETERAN';
    21: req := '^QVETERAN';
    22: req := '^QJRDABLE&QVETERAN';
    23: req := '^QJRDABLE&^QVETERAN';
    24: req :=  'QCHILD21';
    30: req :=  'QCODABLE';
    31: req := '^QCODABLE';
    32: req :=  'QCODABLE!QSSDABLE';
    33: req :=  'QCODABLE&QSSDABLE';
    34: req := '^QSSBENIF';
    35: req := '^QCODABLE&QSSDABLE';
    36: req := '^QSSDABLE';
    38: req :=  'QCODABLE&'!!req;
    39: req :=  'QCODABLE&('!!form!!')';
    40: req :=  'QHAZDUTY';
    41: req :=  'QHAZDUTY&('!!form!!')';
    42: req :=  'QHAZDUTY&QJRDABLE';
    43: req :=  'QHAZDUTY&^QJRDABLE';
    45: req :=  'QAPPROVL&('!!form!!')';
    46: req :=  'QAPPROVL&QVOLCNTR';
    47: req :=  'QAPPROVL&' !!req;
60..63: req:= req!!'&('!!form!!')';
    64: req :=  'QVOLCNTR&('!!form!!')';
    65: req :=  'QVOLCNTR&' !!req;
    66: req := '^QWDVOL&' !!req;
    67: req :=  'QWDVOL!' !!req;
 69,70: req :=  'QSSDABLE&' !!req;
    71: req := '^QSSDABLE&' !!req;
    72: req :=  'QSSDABLE&('!!form!!')';
    73: req :=  'QSSDABLE&QVOLCNTR';
    74: req :=  'QSSDABLE&QJRDABLE';
    79,
 75,76: req :=  'QJRDABLE&' !!req;
 77,78: req := '^QJRDABLE&' !!req;
    96: req := form;
    97,99: req := '1';
   end;
if req='1'
   then definednamekind,nn := nulldef
   else addform(name,req);
assert cc=nextcol;
1:fv := 0; end;
%page
procedure sect;
label 1;
var
  there: string(1);
begin
if zero(1) then goto 1;
there := 'p';
if noget(there) then goto 1;
case there1 of
  '1': ;
  '2': defineer(name,false);
  '5': addform(name,'0');
  '9': begin note('Dis ret ben'); there1 := '5'; addform(name,'0'); end;
  otherwise  error('Invalid code');  end;
assert cc=nextcol;
1:end;
%page
procedure ss;
label 1;
var
  howd,primjoint,reduced,wagebase,estact,yrormo,time,hest: string(1);
  estyr,max,asy,mage,masy,eage: string(2);
  msum: string(3);
  maxpc,estpc: string(4);
  dollars: string(6);
  fromd,tilld: string(8);
  maxok,nohest,check: boolean;
  sd,fd: string(54);
  val: string(70);
  idef: normal;
begin
nohest := nn in 13..15;
if zero(45-ord(nohest)*7) then goto 1;
max  := 'n';  howd := 'n';   hest   := 'n';  yrormo   := 'n';
msum := 'z';  eage  := 'z';  dollars:= 'z';  primjoint:= 'z';
asy  := 'z';  maxpc := 'z';  estyr  := 'z';  wagebase := 'z';
mage := 'z';  masy  := 'z';  estpc  := 'z';
if noget(howd) then goto 1;
idef := stoi(howd);
if idef=3 then case nn of
   10..12: idef := 10;
   13..15: idef := 11;
   otherwise end;
case idef of
    1: primjoint := 'n';
    2: wagebase := 'n';
10,11: ;
  otherwise  reject('Defined');  goto 1;  end;
reduced := primjoint;  estact := wagebase;
if noget(primjoint) then goto 1;  case primjoint1 of
    '0','1','2': ;
    '3': begin   note('Primary/Joint');  primjoint := '1';  end;
    otherwise  reject('Primary/Joint');  goto 1;  end;
 if noget(reduced) then goto 1;  case reduced1 of
    '0','1','2': ;
    '3': begin   note('Reduced/Unreduced');  reduced := '1';  end;
    otherwise  reject('Reduced/Unreduced');  goto 1;  end;
if noget(wagebase) then goto 1;  case wagebase1 of
    '0','1','2','3': ;
    otherwise  reject('Wagebase');  goto 1;  end;
if noget(estact) then goto 1;  case estact1 of
   '0','1','2': ;
   '3': estyr := 'n';
   otherwise  reject('Estimated/Actual');  goto 1;  end;
if noget(estyr) then goto 1;  if noget(yrormo) then goto 1;
case yrormo1 of
   '1'..'3': ;
   otherwise  reject('Yr/mo');  goto 1;  end;
if nogetdates(time,fromd,tilld) then goto 1;
if noget(max) then goto 1;  maxok := false;  case stoi(max) of
   1: begin  maxpc := 'n';  if wagebase='0' then maxok := true;  end;
   2: begin  dollars:='n';  if wagebase='0' then maxok := true;  end;
   3: begin  mage := 'n';   if wagebase>'1' then maxok := true;  end;
   4: begin  masy := 'n';  asy := 'na';
                            if wagebase='0' then maxok := true;  end;
   5: begin  msum := 'n';  asy := 'na';  end;
 6,7: begin  mage := 'n';  asy := 'na';  masy := 'n';  end;
   8: maxok := true;
   otherwise end;
if not maxok then begin reject('Maximum');  goto 1;  end;
if max<>'8' then note('Maximum');
if nogetnum(asy) then goto 1;
if noget(maxpc) then goto 1;  if noget(dollars) then goto 1;
if noget(mage)  then goto 1;  if noget(masy) then goto 1;
if noget(msum)  then goto 1;
if nohest
   then begin  hest := '1';  eage := '0';  estpc := '0';  end
   else begin  if noget(hest) then goto 1;  case hest1 of
       '1': ;
   '2','3': eage := 'n';
       '4': begin eage := 'n';  estpc := 'n';  end;
       '5': begin   note('How estimated');  hest := '1';  end;
       otherwise  reject('How estimated');  goto 1;  end;
   if noget(eage) then goto 1;  if noget(estpc) then goto 1;  end;
if (time<>'1') and ((idef<>2)or(wagebase='1'))
or (idef<>1)and(hest<>'1')
or ((wagebase='2')<>(yrormo='3')) then
   begin  reject('Seems inconsistant');  goto 1;  end;

check := false; sd := 'HIRED';  fd := 'QUITD';
if fromd<>'' then begin sd := sd!!','!!fromd;  check := true;  end;
if tilld<>'' then begin fd := fd!!','!!tilld;  check := true;  end;
case stoi(max) of
1,2,8: ;
  3: begin check := true;
     fd := fd!!',BIRTHD+'!!mage;  end;
  4: fd := fd!!',QUITD-ASY'!!asy!!'+'!!masy;
  5: fd := fd!!',(BIRTHD+'!!msum!!'+QUITD-ASY'!!asy!!')/2';
  6: begin check := true;
     fd := fd!!',BIRTHD+'!!mage!!',QUITD-ASY'!!asy!!'+'!!masy;  end;
  7: fd := fd!!'MAX(BIRTHD+'!!mage!!',QUITD-ASY'!!asy!!'+'!!masy!!')';
  end;
if index(sd,',')<>0 then sd := 'MAX('!!sd!!')';
if index(fd,',')<>0 then fd := 'MIN('!!fd!!')';
case idef of
 10: val := 'SS(5,BENIFITD)';
 11: val := 'SS(6,BENIFITD)';
  1: begin
     val := 'SSPU';
     if primjoint1<>'2'
     then if reduced1<>'2' then val := 'SS(1,'
                             else val := 'SS(2,'
     else if reduced1<>'2' then val := 'SS(3,'
                             else val := 'SS(4,';
     case hest1 of
     '5','1':     val := val!!'BENIFITD)';
     '2','3','4': val := val!!'MAX(BENIFITD,BIRTHD+'!!eage!!'))';
    end;end;
  2: begin
     if check and (fd<>'QUITD') then begin
        addform('FD'!!name,fd);
        fd := 'FD'!!name;
        end;
     if check and (sd<>'HIRED') then begin
        addform('SD'!!name,sd);
        sd := 'SD'!!name;  end
     else if (substr(sd,1,3)<>'MAX') and (index(sd,'+')<>0) then
        sd := '('!!sd!!')';
     case estact1 of
       '1':;
       '2': val := 'BENIFITD';
       '3': val := '19'!!estyr;
       end;
     if estact='1' then case wagebase1 of
        '1': val := 'SSBASE(BENIFITD)';
        '2': val := 'SUM(SSBASE,'!!sd!!','!!fd!!')';
        '3': val := 'AVG(SSBASE,'!!sd!!','!!fd!!')';
        end
     else case wagebase1 of
        '3',
        '1': val := 'SSBASE('!!val!!')';
        '2': val := '('!!fd!!'-'!!sd!!')*SSBASE('!!val!!')';
  end;end;end;
if yrormo='1' then val := val!!'/12';
if max='2' then  val := 'MIN('!!dollars!!','!!val!!')';
if check then val := fd!!'>'!!sd!!'->'!!val;
addform(name,val);
assert cc=nextcol;
1:end;
%page
procedure vest;
label 1;
var  newasy: string(1);  asynum: string(2);
begin
vdbasy := 'V';
if zero(3) then goto 1;
newasy := n;  asynum := 'za';
if noget(newasy) then goto 1;
case newasy1 of
  '1': ;
  '5': asynum := 'na';
  otherwise reject('New asy for vesting?');  goto 1;  end;
if  nogetnum(asynum) then goto 1;
if  asynum<>'0'  then  vdbasy := asynum;
assert cc=nextcol;
1:end;
%page
procedure vtab;
label 1;
var  hd: string(1);  asynum,same: string(2);
      table: array1..4 of record
             ageage,asyasy,orage,orasy,andage,andasy: string(2);
             sumsum: string(3);  pc: string(4);  end;
      asyge: string(8);  vestx: string(100);  vested: string(300);
     vestpc: string(6);  asyvar: normal;  i:1..4;
     isdb, useasy: boolean;
begin
isdb := name='VEDB';
if zero(73-4*ord(isdb)) then goto 1;
hd := n;    asynum := 'xa';  useasy := false;
same := z;  for i := 1 to 4 do tablei.pc := z;
if noget(hd) then goto 1;  if isdb and (hd='1')  then  hd := '9';
  case hd1 of
  '1': same := n;
  '2': ;
  '3': table1.pc := n;
  '4': begin table2.pc := n; table4.pc := n; table3.pc := x end;
  '5': begin note('Vesting Type'); hd1 := '2'; end;
  '7': begin note('Vesting Type'); hd1 := '2'; end;
  otherwise  reject('Vesting Type');  goto 1;  end;
asyvar := lastvar;
if  isdb  then begin  asynum := vdbasy;  same := '0';  end else begin
  if  nogetnum(asynum)  then goto 1;  asyvar := lastvar;
  if  noget(same)  then  goto 1;  case  stoi(same)  of
    0..13: ;  otherwise  reject('Same as');  goto 1;  end;  end;
for i := 1 to 4 do with  tablei  do begin
  case  i  of
    1,4: if  pc=z  then  pc := '0'  else  pc := 'FULL';
    2,3: if  noget(pc)  then  goto 1;
    end;
  if  pc='0'  then  orage := z  else  orage := x;
  ageage := orage; asyasy := orage; andage := orage; sumsum := orage;
  if  noget(ageage)  then  goto 1;  if  noget(asyasy)  then  goto 1;
  if  noget(sumsum)  then  goto 1;  if  noget(orage)   then  goto 1;
  if  orage='0'   then  orasy := z   else  orasy := n;
  if  noget(orasy)   then goto 1;
  if  (ageage='0')and(asyasy='0')and(sumsum='0')and(orage='0')and
      (pc<>'0')  then  andage := 'n';
  if  noget(andage)  then goto 1;
  if  andage='0'  then  andasy := z  else  andasy := n;
  if  noget(andasy)  then goto 1;
  if  (asyasy<>'0')or(sumsum<>'0')or(andasy<>'0')or(orasy<>'0')
      then  useasy := true;
  end;
if asynum = '0' then begin
if ((asynum<>'0')<>useasy) then begin
  lastvar := asyvar;  lastvalue := asynum;
  reject('ASY# should should not be zero');  goto 1;  end; end;
if (hd1 = '2') then vested := 'VOPT(1)' else if (hd1 = '1') then
begin case stoi(same) of 1:vested := 'VMM1'; 2:vested := 'VMM2'; 3:vested := 'VMM3';
4:vested := 'VMV1'; 5:vested := 'VMV2'; 6:vested := 'VMV3';
7:vested := 'VCT1'; 8:vested := 'VCT2'; 9:vested := 'VCT3';
10:vested := 'VCO1'; 11:vested := 'VCO2'; 12:vested := 'VCO3';
13:vested := 'VEDB'; otherwise reject('Bad vest same='!!same); goto 1; end;
end else begin
vested := '';  asyge := 'ASY'!!asynum!!'>=';
for  i := 1 to 4  do with  tablei  do if  pc<>'0'  then begin
  vestx := '';
  if  ageage<>'0'  then  vestx := vestx!! '!QUITAGE>=' !! ageage;
  if  asyasy<>'0'  then  vestx := vestx!! '!'      !! asyge !! asyasy;
  if  sumsum<>'0'  then  vestx := vestx!! '!QUITAGE+'  !! asyge !! sumsum;
  if  orage <>'0'  then  vestx := vestx!! '!QUITAGE>=' !! orage
                                       !! '!'      !! asyge !! orasy;
  if  andage<>'0'  then  vestx := vestx!! '!QUITAGE>=' !! andage
                                       !! '&'      !! asyge !! andasy;
  if  pc='FULL'  then  vestpc := '1'  else  vestpc := pp(pc);
  vestx := substr(vestx,2)!!'->'!!vestpc;
  if  i=1  then  vested := '('!!vestx
  else begin
    vested := vested!!',';  if  vested=','  then  vested := 'MAX(';
    vested := vested!!vestx;  end;
  end;
vested := 'VOPT(' !! vested !! '))'; end;
addaform(name,vested,'','','','','',false,not isdb);
assert cc=nextcol;
1:end;
%page
procedure  check(tp: string(8);  var n: normal);
begin
if  not welldef(tp)  then begin
  caseok := false;
  write(passfail,' ****') end
else begin
  write(passfail,' =',substr(tp,1,2),'=');
  n := n + 1;  end;
end;
%skip 2
SUMMARY:  Prints out how many formulas passed/failed
procedure summary(var f:text; const title:string);
begin
writeln(f,' ':9,title,' at ',time,' on ',date);
writeln(f,'0',' ':9,' NR   LR   ER   VD   DR   DS   CN   VE  Full');
write  (f,' ':9,nrpass:4,lrpass:5,erpass:5,vdpass:5,drpass:5,dspass:5,
            cnpass:5,vspass:5,a6pass:5,totpass:5,' Passed,',totpfrm:6,
          ' formulas,');
if totpfrm<>0 then
  write(f,round(totpfrm/totpass):5,' per case.');
writeln(f);
write  (f,' ':9,totcase-nrpass:4,totcase-lrpass:5,totcase-erpass:5,
                totcase-vdpass:5,totcase-drpass:5,totcase-dspass:5,
                totcase-cnpass:5,totcase-vspass:5,totcase-a6pass:5,
                totfail:5,' Failed,',totprob:6,' problems,');
if totfail<>0 then
  write(f, round(totprob/totfail):5,' per case.');
writeln(f);
writeln(f,' ':9,totcase:4,totcase:5,totcase:5,totcase:5,totcase:5,
                totcase:5,totcase:5,totcase:5,totpass+totfail:5,
          ' Cases, ',totform:6,' formulas,',totnote:5,' Notes.');
end;
%page
begin extract program
listing := parms<>'';
datetime(date,time);
if listing then begin
   rewrite(output);
   listname := true;  end
else begin
   rewrite(passfail);
   rewrite(notefile);
   rewrite(failfile, 'unit=3,nocc');
   writeln(failfile, ':');
   emitinit;  end;
rewrite(input,'unit=sercom');
reset(input,'unit=0');
readdict;
reset(input,'unit=1');
totcase:=0; totfail:=0; totform:=0;  totnote:=0; totprob:=0;
totpfrm:=0; totpass:=0; nrpass:=0;  lrpass:=0;  erpass:=0;  vdpass:=0;
 drpass:=0; dspass:=0;  cnpass:=0;  vspass:=0;  a6pass:=0;
firstline := true;
while not eof(input) do begin
  readln(input,line);
  if firstline and(length(line)=80)and(substr(line,1,5)='HDR F') then continue;
  assert length(line)=linelength;
  firstline := false;
  totcase := totcase + 1;  caseok := true;
  numdate := 0;  numnote := 0;  numprob := 0;  numform := 0;
  profcnt := 0; fortcnt := 0;
  for namekind := lowest(defkinds) to highest(defkinds)
     do for nn := lowest(defnums)  to highest(defnums)
         do definednamekind,nn := undef;
  if listing then page(output);
  namekind:=defxxx;
  fv:=0000;cc:=cl 0001; cv:= 0001; nn:=0;  name:='IDNUM'; ids;
  namekind:=defasy;
      if dbenifit then begin
           cc:=cl 3303; cv:= 3303; nn:=0;  name:='ASYV';  asy;
           cc:=cl 0706; cv:= 0706; nn:=1;  name:='ASY1';  asy;
           cc:=cl 0806; cv:= 0806; nn:=2;  name:='ASY2';  asy;
           cc:=cl 0906; cv:= 0906; nn:=3;  name:='ASY3';  asy;
           cc:=cl 2004; cv:= 2004; nn:=4;  name:='ASY4';  asy;
           cc:=cl 2022; cv:= 2022; nn:=5;  name:='ASY5';  asy;
           cc:=cl 2040; cv:= 2040; nn:=6;  name:='ASY6';  asy;
           cc:=cl 4003; cv:= 4003; nn:=7;  name:='ASY7';  asy;
           cc:=cl 4021; cv:= 4021; nn:=8;  name:='ASY8';  asy;
           cc:=cl 4039; cv:= 4039; nn:=9;  name:='ASY9';  asy;
           cc:=cl 5403; cv:= 5403; nn:=10; name:='ASY10'; asy;
           cc:=cl 5421; cv:= 5421; nn:=11; name:='ASY11'; asy;
           cc:=cl 5439; cv:= 5439; nn:=12; name:='ASY12'; asy;
           cc:=cl 6803; cv:= 6803; nn:=13; name:='ASY13'; asy;
           cc:=cl 6821; cv:= 6821; nn:=14; name:='ASY14'; asy;
           cc:=cl 6839; cv:= 6839; nn:=15; name:='ASY15'; asy;
  end;if dcontrib then begin
           cc:=cl 8106; cv:= 8106; nn:=16; name:='ASY16'; asy;
           cc:=cl 8124; cv:= 8124; nn:=17; name:='ASY17'; asy;
           cc:=cl 8142; cv:= 8142; nn:=18; name:='ASY18'; asy;
  end;namekind:=defxxx;
      if dbenifit then begin
           cc:=cl 1003; cv:= 1003; nn:=1;  name:='PSY1';  psy;
           cc:=cl 1014; cv:= 1014; nn:=2;  name:='PSY2';  psy;
           cc:=cl 1025; cv:= 1025; nn:=3;  name:='PSY3';  psy;
           cc:=cl 2103; cv:= 2103; nn:=4;  name:='PSY4';  psy;
           cc:=cl 2114; cv:= 2114; nn:=5;  name:='PSY5';  psy;
           cc:=cl 2125; cv:= 2125; nn:=6;  name:='PSY6';  psy;
           cc:=cl 4103; cv:= 4103; nn:=7;  name:='PSY7';  psy;
           cc:=cl 4114; cv:= 4114; nn:=8;  name:='PSY8';  psy;
           cc:=cl 4125; cv:= 4125; nn:=9;  name:='PSY9';  psy;
           cc:=cl 5503; cv:= 5503; nn:=10; name:='PSY10'; psy;
           cc:=cl 5514; cv:= 5514; nn:=11; name:='PSY11'; psy;
           cc:=cl 5525; cv:= 5525; nn:=12; name:='PSY12'; psy;
           cc:=cl 6903; cv:= 6903; nn:=13; name:='PSY13'; psy;
           cc:=cl 6914; cv:= 6914; nn:=14; name:='PSY14'; psy;
           cc:=cl 6925; cv:= 6925; nn:=15; name:='PSY15'; psy;
           cc:=cl 1103; cv:= 1103; nn:=1;  name:='FAP1';  fap;
           cc:=cl 1120; cv:= 1120; nn:=2;  name:='FAP2';  fap;
           cc:=cl 1137; cv:= 1137; nn:=3;  name:='FAP3';  fap;
           cc:=cl 2203; cv:= 2203; nn:=4;  name:='FAP4';  fap;
           cc:=cl 2220; cv:= 2220; nn:=5;  name:='FAP5';  fap;
           cc:=cl 2237; cv:= 2237; nn:=6;  name:='FAP6';  fap;
           cc:=cl 4203; cv:= 4203; nn:=7;  name:='FAP7';  fap;
           cc:=cl 4220; cv:= 4220; nn:=8;  name:='FAP8';  fap;
           cc:=cl 4237; cv:= 4237; nn:=9;  name:='FAP9';  fap;
           cc:=cl 5603; cv:= 5603; nn:=10; name:='FAP10'; fap;
           cc:=cl 5620; cv:= 5620; nn:=11; name:='FAP11'; fap;
           cc:=cl 5637; cv:= 5637; nn:=12; name:='FAP12'; fap;
           cc:=cl 7003; cv:= 7003; nn:=13; name:='FAP13'; fap;
           cc:=cl 7020; cv:= 7020; nn:=14; name:='FAP14'; fap;
           cc:=cl 7037; cv:= 7037; nn:=15; name:='FAP15'; fap;
  end;if dcontrib then begin
           cc:=cl 8601; cv:= 8601; nn:=0;  name:='VMM1';  vtab;
           cc:=cl 8801; cv:= 8801;         name:='VMM2';  vtab;
           cc:=cl 9001; cv:= 9001;         name:='VMM3';  vtab;
           cc:=cl 9801; cv:= 9801;         name:='VMV1';  vtab;
           cc:=cl10001; cv:=10001;         name:='VMV2';  vtab;
           cc:=cl10201; cv:=10201;         name:='VMV3';  vtab;
           cc:=cl10401; cv:=10401;         name:='VCT1';  vtab;
           cc:=cl10601; cv:=10601;         name:='VCT2';  vtab;
           cc:=cl10801; cv:=10801;         name:='VCT3';  vtab;
           cc:=cl11001; cv:=11001;         name:='VCO1';  vtab;
           cc:=cl11201; cv:=11201;         name:='VCO2';  vtab;
           cc:=cl11401; cv:=11401;         name:='VCO3';  vtab;
           cc:=cl 8204; cv:= 8204; nn:=1;  name:='MAN1';  manvol;
           cc:=cl 8304; cv:= 8304; nn:=2;  name:='MAN2';  manvol;
           cc:=cl 8404; cv:= 8404; nn:=3;  name:='MAN3';  manvol;
  end;if dbenifit then begin
           cc:=cl 3404; cv:= 3404; nn:=7;  name:='MAN7X'; manvol;
           cc:=cl 3504; cv:= 3504; nn:=8;  name:='MAN8X'; manvol;
           cc:=cl 3604; cv:= 3604; nn:=9;  name:='MAN9X'; manvol;
  end;if dcontrib then begin
           cc:=cl 8503; cv:= 8503; nn:=1;  name:='MMAN1'; match;
           cc:=cl 8703; cv:= 8703; nn:=2;  name:='MMAN2'; match;
           cc:=cl 8903; cv:= 8903; nn:=3;  name:='MMAN3'; match;
           cc:=cl 9103; cv:= 9103; nn:=1;  name:='VOL1';  manvol;
           cc:=cl 9303; cv:= 9303; nn:=2;  name:='VOL2';  manvol;
           cc:=cl 9503; cv:= 9503; nn:=3;  name:='VOL3';  manvol;
  end;if dbenifit then begin
           cc:=cl 3702; cv:= 3702; nn:=7;  name:='VOL7X'; manvol;
           cc:=cl 3802; cv:= 3802; nn:=8;  name:='VOL8X'; manvol;
           cc:=cl 3902; cv:= 3902; nn:=9;  name:='VOL9X'; manvol;
  end;if dcontrib then begin
           cc:=cl 9703; cv:= 9703; nn:=1;  name:='MVOL1'; match;
           cc:=cl 9903; cv:= 9903; nn:=2;  name:='MVOL2'; match;
           cc:=cl10103; cv:=10103; nn:=3;  name:='MVOL3'; match;
           cc:=cl10305; cv:=10305; nn:=1;  name:='CTE1';  ctecoe;
           cc:=cl10505; cv:=10505; nn:=2;  name:='CTE2';  ctecoe;
           cc:=cl10705; cv:=10705; nn:=3;  name:='CTE3';  ctecoe;
           cc:=cl10903; cv:=10903; nn:=1;  name:='COE1';  ctecoe;
           cc:=cl11103; cv:=11103; nn:=2;  name:='COE2';  ctecoe;
           cc:=cl11303; cv:=11303; nn:=3;  name:='COE3';  ctecoe;
           cc:=cl11503; cv:=11503; nn:=1;  name:='CLS1';  cls;
           cc:=cl11603; cv:=11603; nn:=2;  name:='CLS2';  cls;
           cc:=cl11703; cv:=11703; nn:=3;  name:='CLS3';  cls;
           cc:=cl12003; cv:=12003; nn:=4;  name:='CLS4';  cls;
           cc:=cl12103; cv:=12103; nn:=5;  name:='CLS5';  cls;
           cc:=cl12203; cv:=12203; nn:=6;  name:='CLS6';  cls;
           cc:=cl12403; cv:=12403; nn:=7;  name:='CLS7';  cls;
           cc:=cl12503; cv:=12503; nn:=8;  name:='CLS8';  cls;
           cc:=cl12603; cv:=12603; nn:=9;  name:='CLS9';  cls;
           cc:=cl12803; cv:=12803; nn:=10; name:='CLS10'; cls;
           cc:=cl12903; cv:=12903; nn:=11; name:='CLS11'; cls;
           cc:=cl13003; cv:=13003; nn:=12; name:='CLS12'; cls;
  end;if dbenifit  then begin
           cc:=cl 1203; cv:= 1203; nn:=1;  name:='SS1';   ss;
           cc:=cl 1303; cv:= 1303; nn:=2;  name:='SS2';   ss;
           cc:=cl 1403; cv:= 1403; nn:=3;  name:='SS3';   ss;
           cc:=cl 2303; cv:= 2303; nn:=4;  name:='SS4';   ss;
           cc:=cl 2403; cv:= 2403; nn:=5;  name:='SS5';   ss;
           cc:=cl 2503; cv:= 2503; nn:=6;  name:='SS6';   ss;
           cc:=cl 4303; cv:= 4303; nn:=7;  name:='SS7';   ss;
           cc:=cl 4403; cv:= 4403; nn:=8;  name:='SS8';   ss;
           cc:=cl 4503; cv:= 4503; nn:=9;  name:='SS9';   ss;
           cc:=cl 5703; cv:= 5703; nn:=10; name:='SS10';  ss;
           cc:=cl 5803; cv:= 5803; nn:=11; name:='SS11';  ss;
           cc:=cl 5903; cv:= 5903; nn:=12; name:='SS12';  ss;
           cc:=cl 7103; cv:= 7103; nn:=13; name:='SS13';  ss;
           cc:=cl 7122; cv:= 7122; nn:=14; name:='SS14';  ss;
           cc:=cl 7141; cv:= 7141; nn:=15; name:='SS15';  ss;
  namekind:=defred;
           cc:=cl 2603; cv:= 2603; nn:=4;  name:='RED4';  red;
           cc:=cl 2703; cv:= 2703; nn:=5;  name:='RED5';  red;
           cc:=cl 2803; cv:= 2803; nn:=6;  name:='RED6';  red;
           cc:=cl 4603; cv:= 4603; nn:=7;  name:='RED7';  red;
           cc:=cl 4703; cv:= 4703; nn:=8;  name:='RED8';  red;
           cc:=cl 4803; cv:= 4803; nn:=9;  name:='RED9';  red;
           cc:=cl 6003; cv:= 6003; nn:=10; name:='RED10'; red;
           cc:=cl 6103; cv:= 6103; nn:=11; name:='RED11'; red;
           cc:=cl 6203; cv:= 6203; nn:=12; name:='RED12'; red;
           cc:=cl 7203; cv:= 7203; nn:=13; name:='RED13'; red;
           cc:=cl 7303; cv:= 7303; nn:=14; name:='RED14'; red;
           cc:=cl 7403; cv:= 7403; nn:=15; name:='RED15'; red;
  namekind:=defras;
           cc:=cl 1702; cv:= 1702; nn:=1;  name:='RAS1';  ras;
           cc:=cl 1721; cv:= 1721; nn:=2;  name:='RAS2';  ras;
           cc:=cl 1740; cv:= 1740; nn:=3;  name:='RAS3';  ras;
           cc:=cl 3102; cv:= 3102; nn:=4;  name:='RAS4';  ras;
           cc:=cl 3121; cv:= 3121; nn:=5;  name:='RAS5';  ras;
           cc:=cl 3140; cv:= 3140; nn:=6;  name:='RAS6';  ras;
           cc:=cl 6503; cv:= 6503; nn:=10; name:='RAS10'; ras;
           cc:=cl 6522; cv:= 6522; nn:=11; name:='RAS11'; ras;
           cc:=cl 6541; cv:= 6541; nn:=12; name:='RAS12'; ras;
           cc:=cl 7703; cv:= 7703; nn:=13; name:='RAS13'; ras;
           cc:=cl 7722; cv:= 7722; nn:=14; name:='RAS14'; ras;
           cc:=cl 7741; cv:= 7741; nn:=15; name:='RAS15'; ras;
  namekind:=defdat;
           cc:=cl 1802; cv:= 1802; nn:=1;  name:='DAT1';  dat;
           cc:=cl 1807; cv:= 1807; nn:=2;  name:='DAT2';  dat;
           cc:=cl 1812; cv:= 1812; nn:=3;  name:='DAT3';  dat;
           cc:=cl 3203; cv:= 3203; nn:=4;  name:='DAT4';  dat;
           cc:=cl 3208; cv:= 3208; nn:=5;  name:='DAT5';  dat;
           cc:=cl 3213; cv:= 3213; nn:=6;  name:='DAT6';  dat;
           cc:=cl 5103; cv:= 5103; nn:=7;  name:='DAT7';  dat;
           cc:=cl 5108; cv:= 5108; nn:=8;  name:='DAT8';  dat;
           cc:=cl 5113; cv:= 5113; nn:=9;  name:='DAT9';  dat;
           cc:=cl 6603; cv:= 6603; nn:=10; name:='DAT10'; dat;
           cc:=cl 6608; cv:= 6608; nn:=11; name:='DAT11'; dat;
           cc:=cl 6613; cv:= 6613; nn:=12; name:='DAT12'; dat;
           cc:=cl 7803; cv:= 7803; nn:=13; name:='DAT13'; dat;
           cc:=cl 7808; cv:= 7808; nn:=14; name:='DAT14'; dat;
           cc:=cl 7813; cv:= 7813; nn:=15; name:='DAT15'; dat;
  namekind:=defrot;
  fv:=1890;cc:=cl 1818; cv:= 1818; nn:=1;  name:='ROT1';  rot;
  fv:=1891;cc:=cl 1823; cv:= 1823; nn:=2;  name:='ROT2';  rot;
  fv:=1892;cc:=cl 1828; cv:= 1828; nn:=3;  name:='ROT3';  rot;
  fv:=3290;cc:=cl 3220; cv:= 3220; nn:=4;  name:='ROT4';  rot;
  fv:=3291;cc:=cl 3225; cv:= 3225; nn:=5;  name:='ROT5';  rot;
  fv:=3292;cc:=cl 3230; cv:= 3230; nn:=6;  name:='ROT6';  rot;
  fv:=5190;cc:=cl 5120; cv:= 5120; nn:=7;  name:='ROT7';  rot;
  fv:=5191;cc:=cl 5125; cv:= 5125; nn:=8;  name:='ROT8';  rot;
  fv:=5192;cc:=cl 5130; cv:= 5130; nn:=9;  name:='ROT9';  rot;
  fv:=6690;cc:=cl 6620; cv:= 6620; nn:=10; name:='ROT10'; rot;
  fv:=6691;cc:=cl 6625; cv:= 6625; nn:=11; name:='ROT11'; rot;
  fv:=6692;cc:=cl 6630; cv:= 6630; nn:=12; name:='ROT12'; rot;
  fv:=7890;cc:=cl 7820; cv:= 7820; nn:=13; name:='ROT13'; rot;
  fv:=7891;cc:=cl 7825; cv:= 7825; nn:=14; name:='ROT14'; rot;
  fv:=7892;cc:=cl 7830; cv:= 7830; nn:=15; name:='ROT15'; rot;
  namekind:=deflng;
           cc:=cl 1834; cv:= 1834; nn:=1;  name:='LNG1';  lng;
           cc:=cl 1839; cv:= 1839; nn:=2;  name:='LNG2';  lng;
           cc:=cl 1844; cv:= 1844; nn:=3;  name:='LNG3';  lng;
           cc:=cl 3237; cv:= 3237; nn:=4;  name:='LNG4';  lng;
           cc:=cl 3242; cv:= 3242; nn:=5;  name:='LNG5';  lng;
           cc:=cl 3247; cv:= 3247; nn:=6;  name:='LNG6';  lng;
           cc:=cl 5137; cv:= 5137; nn:=7;  name:='LNG7';  lng;
           cc:=cl 5142; cv:= 5142; nn:=8;  name:='LNG8';  lng;
           cc:=cl 5147; cv:= 5147; nn:=9;  name:='LNG9';  lng;
           cc:=cl 6637; cv:= 6637; nn:=10; name:='LNG10'; lng;
           cc:=cl 6642; cv:= 6642; nn:=11; name:='LNG11'; lng;
           cc:=cl 6647; cv:= 6647; nn:=12; name:='LNG12'; lng;
           cc:=cl 7837; cv:= 7837; nn:=13; name:='LNG13'; lng;
           cc:=cl 7842; cv:= 7842; nn:=14; name:='LNG14'; lng;
           cc:=cl 7847; cv:= 7847; nn:=15; name:='LNG15'; lng;
  namekind:=defbeg;
           cc:=cl 5202; cv:= 5202; nn:=7;  name:='BEG7';  beg;
           cc:=cl 5207; cv:= 5207; nn:=8;  name:='BEG8';  beg;
           cc:=cl 5212; cv:= 5212; nn:=9;  name:='BEG9';  beg;
           cc:=cl 6702; cv:= 6702; nn:=10; name:='BEG10'; beg;
           cc:=cl 6707; cv:= 6707; nn:=11; name:='BEG11'; beg;
           cc:=cl 6712; cv:= 6712; nn:=12; name:='BEG12'; beg;
           cc:=cl 7902; cv:= 7902; nn:=13; name:='BEG13'; beg;
           cc:=cl 7907; cv:= 7907; nn:=14; name:='BEG14'; beg;
           cc:=cl 7912; cv:= 7912; nn:=15; name:='BEG15'; beg;
  namekind:=defxxx;
end;if dcontrib then begin
 fv:=11809;cc:=cl11810; cv:=11810; nn:=0;  name:='CNT';   frmc;
end;if dbenifit then begin
  fv:=1858;cc:=cl 1503; cv:= 1503; nn:=1;  name:='NR#1';  frm;
  fv:=1859;cc:=cl 1515; cv:= 1515; nn:=2;  name:='NR#2';  frm;
  fv:=1860;cc:=cl 1527; cv:= 1527; nn:=3;  name:='NR#3';  frm;
  fv:=1861;cc:=cl 1539; cv:= 1539; nn:=4;  name:='NR#4';  frm;
  fv:=1862;cc:=cl 1603; cv:= 1603; nn:=5;  name:='NR#5';  frm;
  fv:=1863;cc:=cl 1615; cv:= 1615; nn:=6;  name:='NR#6';  frm;
  fv:=1864;cc:=cl 1627; cv:= 1627; nn:=7;  name:='NR#7';  frm;
  fv:=1865;cc:=cl 1639; cv:= 1639; nn:=8;  name:='NR#8';  frm;
  fv:=1857;cc:=cl 1501; cv:= 1501; nn:=0;  name:='NRT';   frmt;
           cc:=cl 1901; cv:= 1901;         name:='LRQ';   lrmr;
  fv:=3261;cc:=cl 2903; cv:= 2903; nn:=1;  name:='ER#1';  frm;
  fv:=3262;cc:=cl 2915; cv:= 2915; nn:=2;  name:='ER#2';  frm;
  fv:=3263;cc:=cl 2927; cv:= 2927; nn:=3;  name:='ER#3';  frm;
  fv:=3264;cc:=cl 3003; cv:= 3003; nn:=4;  name:='ER#4';  frm;
  fv:=3265;cc:=cl 3015; cv:= 3015; nn:=5;  name:='ER#5';  frm;
  fv:=3260;cc:=cl 2901; cv:= 2901; nn:=0;  name:='ERT';   frmt;
           cc:=cl 2001; cv:= 2001;         name:='ERQ';   sect;
  fv:=5226;cc:=cl 4903; cv:= 4903; nn:=1;  name:='VD#1';  frm;
  fv:=5227;cc:=cl 4915; cv:= 4915; nn:=2;  name:='VD#2';  frm;
  fv:=5228;cc:=cl 4927; cv:= 4927; nn:=3;  name:='VD#3';  frm;
  fv:=5229;cc:=cl 5003; cv:= 5003; nn:=4;  name:='VD#4';  frm;
  fv:=5230;cc:=cl 5015; cv:= 5015; nn:=5;  name:='VD#5';  frm;
  fv:=5225;cc:=cl 4901; cv:= 4901; nn:=0;  name:='VDT';   frmt;
  fv:=6726;cc:=cl 6303; cv:= 6303; nn:=1;  name:='DR#1';  frm;
  fv:=6727;cc:=cl 6316; cv:= 6316; nn:=2;  name:='DR#2';  frm;
  fv:=6728;cc:=cl 6329; cv:= 6329; nn:=3;  name:='DR#3';  frm;
  fv:=6729;cc:=cl 6403; cv:= 6403; nn:=4;  name:='DR#4';  frm;
  fv:=6730;cc:=cl 6416; cv:= 6416; nn:=5;  name:='DR#5';  frm;
  fv:=6725;cc:=cl 6301; cv:= 6301; nn:=0;  name:='DRT';   frmt;
           cc:=cl 5301; cv:= 5301;         name:='DRQ';   sect;
  fv:=7926;cc:=cl 7503; cv:= 7503; nn:=1;  name:='DS#1';  frm;
  fv:=7927;cc:=cl 7516; cv:= 7516; nn:=2;  name:='DS#2';  frm;
  fv:=7928;cc:=cl 7529; cv:= 7529; nn:=3;  name:='DS#3';  frm;
  fv:=7929;cc:=cl 7603; cv:= 7603; nn:=4;  name:='DS#4';  frm;
  fv:=7930;cc:=cl 7616; cv:= 7616; nn:=5;  name:='DS#5';  frm;
  fv:=7925;cc:=cl 7501; cv:= 7501; nn:=0;  name:='DST';   frmt;
           cc:=cl 6731; cv:= 6731;         name:='DSQ';   sect;
           cc:=cl 8001; cv:= 8001;         name:='PRAG';  post;
           cc:=cl 3301; cv:= 3301;         name:='VSTD';  vest;
           cc:=cl 3317; cv:= 3317;         name:='VEDB';  vtab;
end;
name := '';  lastvalue := '';  lastgroup := '';  lastvar := 0;
%page
  if listing then
     finishlisting
  else begin
     write(passfail,'ID=',id);
     check('NRQ',nrpass);
     check('LRQ',lrpass);
     check('ERQ',erpass);
     check('VDQ',vdpass);
     check('DRQ',drpass);
     check('DSQ',dspass);
     check('CNQ',cnpass);
     check('VEDB',vspass);
     if caseok then a6pass := a6pass + 1;
     numform := endcase;
     if numprob<>0 then  begin
        totfail := totfail + 1;
        totprob := totprob + numprob;
        write(passfail,' Failed. ');  end
     else begin
        totpass := totpass + 1;
        totpfrm := totpfrm + numform;
        write(passfail,' Passed. '); end;
     writeln(passfail,numprob:2,' Problems, ',numform:2,' Formulas, ',
                      numnote:2,' Notes.');
     totform := totform + numform;
     totnote := totnote + numnote;  end;
  end input loop;
if not listing then begin
   rewrite(output,'file=*sink*,noempty,nocc');
   summary(output,'Summary');
   reset(notefile);
   reset(passfail);
   writeln(failfile, ':');
   while not eof(notefile) do begin
      readln(notefile,line);
      writeln(failfile,' ',line);  end;
   rewrite(output,'unit=2,nocc');
   summary(output,'Case list');
   writeln(output,' ');
   while not eof(passfail) do begin
      readln(passfail,line);
      writeln(output,' ',line); end;
   end;
end.
