%externalroutine dumpgec(%string(63) s)

%conststring (25) vsn = "  Version  1.3"

%owninteger print all = 0;        ! prints lau data if <>0
%owninteger mon line = -1;       ! line to monitor
%owninteger mon con = 0
%owninteger print this = 0

%constinteger our exchange = 1
%owninteger this exchange = 0, fix exch
%constinteger scd = 0
%constinteger ecd = 1
%constinteger dcd = 2
%constinteger laustats = 3
%constinteger unitstats = 4
%routinespec dumpaddr(%bytearrayname a, %byte l)
%routinespec writehex(%integer n,d)
!Routine for dumping GEC Network Management logs
%routinespec dat(%integer dat)
%routinespec tod(%integer d)
%externalroutinespec define(%string(63) s)
%externalintegerfnspec smaddr(%integer chan,%integername l)
%externalintegerfnspec exist(%string(63) s)
%conststring (7) %array units(0:4) = "Max Bf:", "Cur Bf:", "Vcs", "Min Bf:", "Req Dl:"
%integer ina,inl,idunit, idexch,idtype, oup
%string(63) t,u
%owninteger old t = 1
%owninteger atod = 0
      %ownintegerarray overdes(1:32) = %c
     -1(7), 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,
      13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2

       %constinteger max lines = 55;    ! nb: Top Line+2 for g/w (+margin)
      %constinteger kb lines = 50
      %constinteger gs lines = 42
      %constinteger small lines = 20

      %constinteger low name = -3
      %constinteger high name = kb lines+gs lines+small lines
      %constinteger George Sq = kb lines
      %constinteger small cpse = kb lines + gs lines

     %constintegerarray max no lines(0:3) = 50, kb lines, gs lines, small lines

      %conststring (6) %array names(low name:high name) = 
         "Spssgw", "Srsx11", "SjanGw", "??????",
         "TrkGsq", "2972-2", "40Cpse",
         "Xcall ", "JanG/W", "CS Vax", "Xgate ", "GScpse", "2972-1",
         "ERCVax", "2988-2", "StrX25", "TCP M ", "ForrCo", "Scri-i",
         "Phy #2", "Abro  ", "Arcus ", "EE Vax", "Info  ", "Forr  ",
         "Jcmb  ", "Slow2 ", "PhyVax", "Chem  ", "Siae  ",
         "Engin ", "Pollck", "Bush  ", "SiaeRS", "IGS   ", "Scri-p", 
         "HFRO  ", "Wscoa ", "PrcPri",
         "CsTVax", "MRCVax", "RehPAD", "ESAVax",
         "Psse  ", "TCP A ", "TCP D ", "EMAS-a",
         "11/40 ", "AmdFe3", "KbPAD1", "PadSwi", "Lau 48",
         "Lau 49", "Janet ",
         "EMV35 ", "TrkKB0", "Bu g-2", "KBcpse", "Mcsu  ",
         "Geac  ", "DPUibm", "AdaDG ", "GS0Pad", "CSa1  ",
         "CS a2 ", "Atb  1", "Atb  2", "Atb  3", "GeoVax",
         "Elib  ", "GSqt 1", "Socs  ", "Ersk  ", "BsPad ",
         "GSqt 2", "DVet T", "OC Pad", "EDAI  ",
         "DEC 10", "AIGR  ", "AIVA  ", "Episte",
         "Lb  29", "AtbPad", "CstPad", "ArcPad", "Em g2 ",
         "Em g1 ", "LibPad", "Lb  36", "Lb  37", "Lb  38",
         "Lb  39", "Lb  40", "Lb  41", "Lb  42",
         "Erte  ", "Dev mc", "TCP C ", "DevPAD",
         "Oslan ", "GENPad", "Gec 63", "KBcpse",
         "ZooPad", "VmDev ", "TCP S ", "KB3Pad", "VetPad",
         "LC14  ", "GEC/40", "88-2b ", "LC17  ", "Fstore",
         "LC19  ", "LC20  "

      %ownintegerarray address(low name:high name) =
      71000005, 71000016, 71000004,
      11111111,
      11111111, 15000002, 11111111,
      15000004, 15000019, 15000006, 15000007, 15000008, 15000009,
      15000010, 15000003, 15000012, 15000013, 15000014, 15000015,
      15000016, 15000017, 15000018, 15000019, 15000020, 15000021,
      15000022, 15000023, 15000024, 15000025,  15000026, 15000027,
      15000028, 15000029, 15000030, 15000031, 15000032, 15000033,
      15000034, 15000035,
      15000036, 15000037, 15000038, 15000039,
      15000040, 15000041, 15000042, 15000043,
      15000044, 15000045, 15000011, 15000047, 15000048, 
      15000049, 15000050,
      16000001, 16000002, 16000003, 16000004, 16000005,
      16000006, 16000007, 16000008, 16000009, 16000010,
      16000011, 16000012, 16000013, 16000014, 16000015,
      16000016, 16000017, 16000018, 16000019, 16000020,
      16000021, 16000022, 16000023, 16000024,
      16000025, 16000026, 16000027, 16000028,
      16000029, 16000030, 16000031, 16000032,
      16000001, 16000002, 16000035, 16000036, 16000037,
      16000038, 16000039, 16000040, 16000041, 16000042,
      15001001, 15001002, 15001003, 15001004,
      15001005, 15001006, 15001007, 15001008,
      15001008, 15001010, 15001011, 15001012,
      15001013, 15001014, 15001015, 15001016,
      15001017, 15001018, 15001019, 15001020

      %constinteger max hosts = 40
      %constinteger max calls = 30
      %recordformat startcf(%integer ind, start, host)
      %recordformat lsf(%record (startcf) %array l(1:max calls))
      %record (lsf) %array lsa(1:max lines)

      %recordformat hosf(%integer calls, rx, tx, dur, host)
      %recordformat per linef(%record (hosf) %array l(1:max hosts))
      %record (per linef) %array hosta(1:maxlines)
      %record (per linef) %name hos
      %record (hosf) %name hr

      %string (*) %fn itos(%integer n)
         %integer i,j,k
         %string (5) s
         k = n//10
         %if n < 10 %then s = " " %else %start
            s = tostring(k+'0')
            n = n-k*10
         %finish
         s = s.tostring(n+'0')
         %result = s
      %end

      %integerfn stoi(%string (*) %name s)
         %integer i, n, k
         n = 0
         %result = 0 %if length(s) = 0
         %cycle i = 1, 1, length(s)
            k = charno(s, i)-'0'
            %unless 0<=k<=9 %then %result = n
            n = n*10+k
            %result = -1 %if n > 150000000
         %repeat
         %result = n
      %end


      %routine an options(%string (255) s)
          %string (63) u
           printstring("option ="); printstring(s); newline
         %if s -> s.(":N").u %then old t = 0 %and s = s.u
         %if s -> s.(":P").u %then print all = 1
         %if s -> s.(":L").u %then mon line = stoi(u)
         %if s -> s.(":C").u %then mon con = 1
         %if s -> s.(":E").u %then fix exch = stoi(u)
      %end

      %if s->s.(":").t %start
         %cycle
            %unless t -> t.(":").u %then %exit
            an options(":".t)
            t = u
         %repeat
         an options(":".t)
      %finish


%if s->s.("/").t  %start
      %unless t -> t.(",").u %then u=""
%finish %else t = ".out" %and u = ""
print all = -1 %if u = ""

 
define("1,".s)
%if old t # 0 %start
   ina=smaddr(1,inl)
   printstring("Length discrepancy
")    %and inl = inl & x'ffffff00' %unless inl & 255 = 0
%finish
%if u="" %then printall = -1 %and u = ".Null"
define("2,".u) 
define("3,".t)
%cycle oup = 2, 1, 3
      selectoutput(oup)
newpage
printstring("
Dump GEC logfile"); printstring(vsn)
printstring("

Log:"); printstring(s); printstring("
 To:"); printstring(t); newlines(5)
%repeat
select output(2)
!
!
%begin
!
%recordformat logf(%integer tod, seqno, %c
((%halfinteger date, exchno) %or %c
(%halfinteger l, %byte type, spare1, %integer id, %c
 (%halfinteger callid, spare, %c
      ((%bytearray called, caller(0:7), %byte cdl, crl, facs, res, scause, sdiags, spare2, spare3) %c
      %or (%integer segs tx, segs rx, %halfinteger ints tx, ints rx, res tx, res rx, retries, ecause, ediags)) %c
      %or (%halfintegerarray l stats(0:11)) %c
         %or ((%integer oflo, %halfinteger l ctrl rx, l ctrl tx, l 1seg rx, l 2seg rx, %c
      l 3seg rx, l 4seg rx, l 1seg tx, l 2seg tx, l 3seg tx, l 4seg tx, l frms rx, %c
      l frms tx, l calls rx, l calls tx, l retries, l ints rx, l ints tx, %c
      l res rx, l res tx, l sups rx, l sups tx, l fcs rx, l abrts rx, %c
      l idle errors, ldcd,lshort,lunder,l l2res, %c
      %integer l bytes rx, l bytes tx %or %halfintegerarray lust(0:42))))) %c
))

      %recordformat log2f(%integerarray lust(0:42), %c
       %integer l bytes rx, l bytes tx)

%record (logf) %name a
%record (logf) %name la, mal
%constinteger gate start = kb lines
%owninteger last tod = 0
%owninteger unitfl, unittotal, cpsecalls
%owninteger count = 0
%owninteger last item = 0
%owninteger valid = 0

%ownbyteintegerarray ar(0:511)

%constinteger maxad = 60
%ownrecord (logf) %array lastl(0:max lines)
%ownrecord (logf) %array max l(0:max lines)
%ownrecord (log2f) %array overl(0:max lines)
%record (log2f) %name tl

%conststring(4) %array types(0:4) = "CON ","END ","CHK ","Link","Unit"
%integer l,n,j,i,ll,inla,seq,blkno,laun, ins, free, k, ww
%integer rx, tx, calls, dur

      %string (14) %array addsou(1:maxad)
      %string (14) %array addsnk(1:maxad)
      %ownintegerarray conna(0:maxad,0:maxad)
      %ownintegerarray connf(0:maxad,0:maxad)
      %owninteger ptr = 1
      %integerarray maxp, maxc, maxd(1:300)




      %routine dump line figs(%record (logf) %name l)
         %integer i, n
         printstring("Dump of Line figs:
")
         %cycle i = 0, 1, 42
            write(i, 2)
            write(l_lust(i), 8); spaces(5)
            writehex(l_lust(i), 8)
            newline
         %repeat
      %end

      %routine clear over
         %integer n, x
         %if atod > (23*60+45)*60 %then atod = 0
         %cycle n = 1, 1, max lines
            overl(n) = 0; lastl(n) = 0
            lastl(n)_tod = atod
         %repeat
      %end

      %routine check for max(%integer l)
         %integer rx, tx, rxm, txm, tot, i, x, q, tott

         mal == max l(l)
         tott = atod-la_tod
         %if a_oflo # 0 %start
            q = a_oflo
            %cycle i = 1, 1, 32
               %if q&1 # 0 %start
                  %if overdes(i) < 0 %start
                     select output(0); printstring("Overflow marker:")
                        writehex(a_oflo, 8); newline
                       printstring("Over ?
")
                        select output(2)
                        printstring("
**************************************************************************
")
                        printstring("Dump of last record, then current
")
                        dump line figs(la); dump line figs(a)
                        newlines(2)
                  %finishelsestart
                     x = overdes(i)
                     overl(l)_lust(x) = overl(l)_lust(x)+65536
                  %finish
               %finish
               q = q>>1
            %repeat
         %finish
         rx = a_l frms rx; tx = a_l frms tx
         rxm = rx-la_l frms rx; txm = tx-la_l frms tx
         %if rxm < 0 %then rxm = rxm+65536
         unit total = unit total+rxm
         %if tott <= 0 %or tott > 3000 %then %return;    ! not a 1/2 hr statistic
         %if mal_tod = 0 %or rxm > mal_l frms rx %start
                          ! ie, if first max figure OR per sec rate is greater
            %cycle i = 0, 1, 42
junk2:
               mal_lust(i) <- a_lust(i)-la_lust(i)
            %repeat
            mal_l bytes rx = a_l bytes rx-la_l bytes rx
            mal_l bytes tx = a_l bytes tx-la_l bytes tx
            mal_lust(34) = a_lust(34);     ! vcs operating
            mal_tod = atod-la_tod
            mal_seq no = atod;         ! hide actual time here
         %finish
      %end

      %routine print line stats(%record (logf) %name l, %c
        %record (log2f) %name tl,  %integer secs)
         %integer i,j, tod, z, frx, ftx, rxd, txd, t

         frx = tl_lust(12); ftx = tl_lust(13);  ! l frms rx & l frms tx
         %if tl_lust(2) > frx %start;    ! overflow is missing !
             frx = frx+65536; tl_lust(12) = frx
          %finish
         %if tl_lust(3) > ftx %start
            ftx = ftx+65536; tl_lust(13) = ftx;  ! gec can miss periods !!
         %finish

         rxd = tl_lust(4)+tl_lust(5); txd = tl_lust(8)+tl_lust(9);         ! l 1seg rx+l 1seg tx
         tod = l_tod
         z=tod-secs; %if z<0 %then z=-z
         %if (secs>10000 %and z>2000) %or (secs<10000 %and z > 250) %start
            select output(0)
            printstring("secs ="); write(secs, 1)
            printstring(", in tod ="); write(tod, 1); newline
            tod = secs %if tod=0
            select output(3)
         %finish
         print(frx/tod, 3, 1)
         %if frx = 0 %then write(0, 6) %else %c
         print((tl_lust(2)*100)/frx, 6, 0); printsymbol('%')
               ! l_ ctrl rx
         %if ftx = 0 %then write(0, 6) %else %c
         print((tl_lust(3)*100)/ftx, 6, 0); printsymbol('%')
         %if rxd = 0 %then write(0, 6) %else %c
         print((tl_lust(4)*100)/rxd, 6, 0); printsymbol('%')
         %if txd = 0 %then write(0, 6) %else %c
         print((tl_lust(8)*100)/txd, 6, 0);  ! 1seg tx
         printsymbol('%')
         write(tl_lust(14), 6); write(tl_lust(15), 6); ! calls rx, tx
         write(tl_lust(19)+tl_lust(20), 3); ! res rx, tx
         print(tl_l bytes rx/tod, 5, 0); print(tl_l bytes tx/tod, 5, 0)
         j = 0
         %cycle i = 35, 1, 42; j = j+tl_lust(i); %repeat
         write(j, 6)
         write(frx, 8); write(ftx, 8)
         write(rxd, 8); write(txd, 8)
         t = tl_lust(2)*6
         j = tl_l bytes rx-t
         z = tl_lust(4)+tl_lust(5)
         print(j/z, 3, 0) %unless z = 0
         j = tl_l bytes tx-(tl_lust(3)*6)
         print(j/txd, 3, 0) %unless txd = 0
         newline
      %end

      %routine heading
         newline
         printstring("        Frames       Control  ")
         printstring("       1 seg          Calls   RESETS  Bytes/Sec")
         printstring("  ERRORS  Total Frames     Total Data F  Av Bytes
")
         printstring(" Line    In/sec    %Out   %In     ")
         printstring("%Out   %In     Out     In  Total  Out   ")
         printstring("  In   Total    Out      In        Out     In  Out  In
")
      %end

       %routine print this name(%integer n)
         %integer ind
            %if n > gate start %then printstring("Gw  01   ") %else %start
               ind = 0;   !KB CPse
               %if this exchange = 2 %then ind = george sq
               %if this exchange = 3 %then ind = small cpse
               %if this exchange # 0 %start
                  printstring(names(n+ind))
               %finish %else %start
                  printstring("Lau"); printstring(itos(n))
               %finish
               spaces(3)
            %finish
       %end

      %routine print out(%integer flag)

         %record (logf) %name l
         %integer i, j, n, t, rxm, txm, rbm, tbm, tlx, lx, ind
         heading
         last l(0) = 0
         overl(0) = 0
         %if flag = 0 %then t = 24*60*60 %else t = 30*60
         %if flag = 2 %then t = last tod
         %cycle n = 1, 1, max lines
            %if flag#1 %then l == last l(n) %else l == max l(n)
            tl == overl(n)

            %cycle j = 1, 1, 42
                  tlx = tl_lust(j)
                  lx = l_lust(j)
                  tl_lust(j) = tlx+lx
            %repeat

            tl_l bytes rx = l_l bytes rx; tl_l bytes tx = l_l bytes tx
            overl(0)_l bytes rx = overl(0)_l bytes rx+l_l bytes rx
            overl(0)_l bytes tx = overl(0)_l bytes tx+l_l bytes tx
junk label:
            %if tl_lust(12)+tl_lust(13) # 0 %start
               print this name(n)
               print line stats(l, tl, t)
            %finish

            ! now add to switch running total
            %cycle j = 1, 1, 42
               overl(0)_lust(j) = overl(0)_lust(j)+tl_lust(j)
            %repeat
         %repeat
         %cycle j = 1, 1, 129; printsymbol('-'); %repeat
         printstring("
Total:   ")
         last l(0)_tod = t;    ! not accurate for max period counts
         l == last l(0); tl == overl(0)
         print line stats(l, tl, t)
         %cycle j = 1, 1, 129; printsymbol('-'); %repeat
         newlines(5)
      %end
      %string (12) %fn gets(%byteintegerarrayname a, %integer l)
         %integer i, n
         %string (23) s
         s = "000000000000"
         %if l > 12 %then l = 12;      ! delete sub-address
         n = 12-l+1
         %if l > 1 %start
            %cycle i = 0, 1, l>>1-1
               charno(s, n) = (a(i)&x'f0')>>4+'0'
               charno(s, n+1) = (a(i)&x'f')+'0'
               n = n+2
            %repeat
         %finish
         %if l&1 # 0 %then charno(s, n) = a(l>>1)>>4+'0'
         %result = s
      %end

      %integerfn find(%string(*) %name s, %string (*) %arrayname addsou)
         %integer i
         %cycle i = 1, 1, maxad
            %if s = addsou(i) %then %result = i
            %if addsou(i) = "" %start
               addsou(i) = s; %result = i
            %finish
         %repeat
         addsou(i) = s
         %result = i
      %end

      %routine add conn(%record (logf) %name a)
         %integer f, t, ww, i
         %record (lsf) %name ls
         %string (12) ca, cl
         ww <- a_callid
         ca = gets(a_caller, a_crl)
         cl = gets(a_called, a_cdl)
         f = find(ca, addsou)
         t = find(cl, addsnk)
         %if a_scause = 0 %then conna(f, t) = conna(f, t)+1 %c
           %else connf(f,t) = connf(f, t)+1
         %if a_scause = 0 %and laun > 0 %start
            ls == lsa(laun)
            %cycle i = 1, 1, max calls
               %if ls_l(i)_ind = 0 %start
                  ls_l(i)_ind = ww
                  ls_l(i)_start = atod
                  ls_l(i)_host = t
                  %return
              %finish
            %repeat
            printstring("too many calls on line"); write(laun, 1); newline
         %finish
      %end

      %routine end conn(%record (logf) %name a)
         %record (lsf) %name ls
         %record (startcf) %name l
         %record (per linef) %name hos
         %record (hosf) %name pl
         %integer ww, i, j
      
         ww <- a_callid
         %return %if laun < 0
         ls == lsa(laun)
         %cycle i = 1, 1, max calls
            %if ls_l(i)_ind = ww %start
            l == ls_l(i); hos == hosta(laun)
                %if l_start > atod %then l_start = l_start-60*60*24; ! wrap around
               %cycle j = 1, 1, max hosts
                  pl == hos_l(j)
                  %if pl_host = 0 %then pl_host = l_host
                  %if pl_host = l_host %start
                     pl_calls = pl_calls+1
                     pl_rx = pl_rx+a_segs rx; pl_tx = pl_tx+a_segs tx
                     pl_dur = pl_dur+atod-l_start
                     l_ind = 0
                     %return
                  %finish
                %repeat
                %exit
             %finish
         %repeat
      %end

      %routine print grid(%integerarrayname conna)
         %integer i, j, maxp

      %routine p grid2(%integerarrayname conna, %integer a, b)

      %cycle i = 5, 1, 12
         spaces(18)
         %cycle j = a, 1, b
            printsymbol(charno(addsnk(j), i)); spaces(3)
         %repeat
         newline
      %repeat
      spaces(14); printsymbol('-') %for i = 1, 1, 100
      newline

      %cycle i = 1, 1, maxad
         %exit %if addsou(i) = ""
         printstring(addsou(i)); spaces(3)
         %cycle j = a, 1, b
            n = conna(i, j)
            %if n = 0 %then printstring("   .") %elsestart
               %if n>1000 %then write(n//1000, 2) %and printsymbol('k') %c
                %else write(n, 3)
            %finish
         %repeat
         newline
      %repeat
      %end

      %if free > 29 %start
         p grid2(conna, 1, 29); newlines(5)
         newpage
         p grid2(conna, 30, free)
      %finish %else %start
         p grid2(conna, 1, free)
      %finish
      newpage
%end


      %integerfn get block into ar
%end


         %cycle i = 1, 1, max lines; lsa(i) = 0; %repeat
         %cycle i = 1, 1, max lines; hosta(i) = 0; %repeat

%for i=1,1, maxad %cycle; addsnk(i) = ""; addsou(i) = ""; %repeat
%on 9 %start
      -> eof
%finish

%if old t = 0 %then n = 99999 %else %c
n = inl >> 9 ;!No of blocks

Printstring("    No.       Time

")
%if old t = 0 %start
      select input(1)
      skipsymbol %if nextsymbol='*'
%finish

seq = -1
      blkno = 0
!%for blkno = 0, 1, n-1 %cycle
      %if old t # 0 %start
            inla = ina + blkno * 512
      %finishelsestart
!         %if get block into ar # 0 %then %exit
         inla = addr(ar(0)); ina = inla
      %finish

     this exchange = fix exch

   %cycle
      a == record(inla)
         ins = 0
      %if a_seqno = -1 %start
         %if valid # 0 %start
         valid = 0
         newlines(2)
         spaces(9) ;tod(a_tod)
         !Initialising log
         printstring("  Date:")
         spaces(3) ;dat(a_date) ;spaces(3) ;writehex(a_exchno,4)
         select output(3)
         newpage
         printstring("
Date Covered was:"); dat(a_date)
         spaces(5); tod(atod)
         printstring(" Exchange"); write(this exchange, 1); newline
         print out(0)
         select output(2)
         %finish
         ll = 12
         clear over
   
      %finishelsestart

         seq = a_seqno
          atod = a_tod; atod = 0 %if atod < 0

         !Anything else
!  inside:
         ll = a_l
         -> invalid %if ll = 0
         idtype = (a_id >>24) & 255
         idexch = (a_id >>16) & 255
         idunit = (a_id >>8) & 255
         %if seq > 150000 %or ll > x'100' %or a_tod > 24*60*60 %start
invalid:
            %if a_tod = x'04040404' %then %exit;  ! eof (pdp11 eof)
            select output(0)
            writehex(inla, 8)
            printstring(" Invalid Element, skipping
")
            select output(2)
            inla = inla+4; -> try again
         %finish

      %if count = 0 %start
         select output(3); printstring("First record at ")
         tod(atod); newlines(2)
         select output(2)
      %finish %else %start
         %if last tod > 100000 %or a_tod - last tod > 30*60 %start;    ! gap of more than 30 mins
            select output(3)
            printstring("

Time gap:  Old time:"); tod(last tod)
            printstring(", New time:"); tod(a_tod); newlines(2)
            select output(2)
         %finish
      %finish
      count = count+1

      last tod = atod; last tod = 0 %if last tod < 0

      laun = -1
      %if idtype&255 = 2 %then laun = idunit
      %if idtype&255 = 3 %then laun = gate start+idunit
      print this = 0;     ! dont print info
      %if print all > 0 %or mon line = laun %then print this = 1
      %if print this = 0 %and mon con # 0 %then print this = -1

      %if print this > 0 %or (print this < 0 %and a_type = scd) %start
         %if ins = 0 %start
            write(seq, 5)
            %if print all > 0 %start
               printstring(" ("); writehex(seq, 3); printsymbol(')')
            %finish
            spaces(3) ;tod(atod)
         %finish
         %if print all > 0 %start
            spaces(3); writehex(inla,8)
         %finish
         spaces(2)
         %if 0 <= a_type <= 4 %then printstring(types(a_type)) %else %c
           write(a_type, 3)
         spaces(3)
         %if idtype & 255 = 2 %start
            !LAU
            laun = idunit
               printstring("LAU") ;writehex(idunit, 2)
               %if idexch # our exchange %start
                  printsymbol('/'); writehex(idexch, 2)
               %finishelse spaces(3)

         %finishelseif idtype = 3 %start
            !GW
            printstring(" GW") ;writehex(idunit, 2)
            %if idexch # our exchange %start
               printsymbol('/'); writehex(idexch, 2)
            %finishelse spaces(3)

         %finishelsestart
            writehex(a_id, 8)

         %finish
         %finish
   

         %if a_type = scd %or a_type = ecd %or a_type = dcd %start
            %if a_type = ecd %then end conn(a)
            %if print this = 0 %start
               %if a_type = scd %then add conn(a)
            %finishelsestart
               %if a_type = scd %start
                  ww <- a_callid; write(ww, 5); space
                  add conn(a)
                     dumpaddr(a_caller, a_crl) ;printstring(" -> ")
                     dumpaddr(a_called, a_cdl)
                     space ;writehex(a_facs, 2) ;space ;writehex(a_res, 2)
                     space ;writehex(a_scause, 2) ;space ;writehex(a_sdiags, 2)

            %finishelsestart
              %if print this > 0 %start
                ww <- a_callid; write(ww, 5); space
                  printstring("Segs,Ints,resets (RX/TX):")
                  write(a_segs tx, 5) ;write(a_segs rx, 5) ;write(a_ints tx, 2)
                  write(a_ints rx, 2) ;write(a_res tx, 2) ;write(a_res rx, 2)
                  printstring(", Retran:")
                  write(a_retries, 2)
                  %if a_type = ecd %start
                     space ;writehex(a_ecause, 2) ;printsymbol('/') ;writehex(a_ediags, 2)
                  %finish
           %finish
            %finish
            newline
           %finish
         %finishelseif a_type = laustats %start
            valid = 1
            %if print this # 0 %start
            %if a_l bytes rx+a_l bytes tx = 0 %then printstring(" Zero") %elsestart
            printstring("   Frms (RX/TX):")
            write(a_l frms rx, 6); write(a_l frms tx, 6)
            printstring(", Calls:")
            write(a_l calls rx, 4); write(a_l calls tx, 4)
            printstring(", Bytes:")
            write(a_l bytes rx, 6); write(a_l bytes tx, 6)
               printstring(" da 1-3"); write(a_l 1segrx, 1)
               write(a_l 2seg rx, 1); write(a_l 3seg rx, 1)
            %finish
            newline
            %finish

            %if laun > 0 %start
               la == lastl(laun)
               check for max(laun)
               la = a;                     ! copy 'current' to 'last'
               la_tod = atod
            %finish

         %finishelseif a_type = unitstats %start
            %for i = 0, 1, 4 %cycle
               space; printstring(units(i))
               write(a_lust(i), 4)
            %repeat
            %if cpsecalls < a_lust(2) %then cpsecalls = a_lust(2)
            %if unitfl = 0 %start
               select output(3)
               %for i = 0, 1, 4 %cycle
                  spaces(3); printstring(units(i))
                  write(a_lust(i), 4)
               %repeat
               newline
               select output(2)
               unit fl = 1
            %finish

            select output(0);; tod(atod); space; write(unit total, 1)
            print(unit total/(40*60), 5, 1)
            newline; select output(2)
            maxc(ptr) = a_lust(2)
            maxp(ptr) = unit total; maxd(ptr) = atod; ptr = ptr+1
            unit total = 0

            newline
         %finish
      %finish
      inla = (inla + ll + 10)&x'fffffffc'
!      inla = (inla>>2)<<2
!      %if inla > (ina+(blkno+1)*512) %or (inla-ina > last item %c
!         %and oldt = 0) %then %exit
try again:
      a == record(inla)
!      %if a_tod&x'fff00000'#0 %start;   ! sub-record
!         inla = inla-8
!         a == record(inla)
!         ins = 1; spaces(23)
!         -> inside
                   ! the above code is necessary for interpreting a raw
                   ! GEC log file, but in this case it has been tidied up
                   ! by the pdp 11 program, so is always in complete records
!      %finish
      inla = inla+4 %if a_tod = 0;             ! skip the zero word
   %repeat
!%repeat
eof:
      select output(3)
      newpage
      printstring("Totals to last record   ("); tod(atod); printstring(")

")
      print out(2)
      newlines(4)

      clear over

      newpage
      printstring("
Last Record at "); tod(last tod); newlines(2)
      printstring("Max No. of Calls observed was "); write(cpsecalls, 1)
      newlines(2)

      printstring("Max 30 Min period of traffic for each Line

")
      print out(1)
      %cycle i = 1, 1, 28
         write(i, 2); spaces(2);  tod(max l(i)_seq no); newline
      %repeat
      newpage
      free = maxad
      %cycle i = 1, 1, maxad
         %if addsnk(i) = "" %and free = maxad %then free = i-1
         k = stoi(addsou(i))
         l = stoi(addsnk(i))
         %cycle j = low name, 1, high name
            %if k = address(j) %then addsou(i) = "      ".names(j)
            %if l = address(j) %then addsnk(i) = "      ".names(j)
         %repeat
      %repeat

      printstring("
Connection Grid        from/to

")
      print grid(conna)
      printstring("Failed Connection Grid    FROM/TO
")
      print grid(connf)
      newpage
      printstring("Calls from each host
              Host      Calls   Rx      Tx       Rx/call   Tx/call  Mins/call  Rx/min    Tx/Min
")
      %cycle i = 1, 1, max no lines(this exchange)
         hos == hosta(i)
         printstring("host:"); print this name(i); newline
         rx = 0; tx = 0; calls = 0; dur = 0
         %cycle j = 1, 1, max hosts
            hr == hos_l(j)
            n = hr_calls
            %if n = 0 %then %exit
            spaces(5)
            k = hr_host
            printstring(addsnk(k))
            write(hr_calls, 8)
            write(hr_rx, 8); write(hr_tx, 8)
            print(hr_rx/hr_calls, 8, 0); print(hr_tx/hr_calls, 8, 0)
            print(hr_dur/(hr_calls*60), 8, 1)
            %if hr_dur = 0 %then hr_dur = 1
            print(hr_rx*60/hr_dur, 8, 1)
            print(hr_tx*60/hr_dur, 6, 1)
            newline
            rx = rx+hr_rx; tx = tx+hr_tx; calls = calls+hr_calls; dur = dur+hr_dur
        %repeat
         %if calls # 0 %start
            printstring("  ** Total:      ")
            write(calls, 8); write(rx, 8); write(tx, 8)
            print(rx/calls, 8, 0); print(tx/calls, 8, 0)
            print(dur/(calls*60), 8, 1)
            print(rx*60/dur, 8, 1)
            print(tx*60/dur, 6, 1)
            newlines(2)
         %finish
      %repeat
      newpage


      printstring("Histogram of Calls and No of packets through switch
")
      %cycle i = 1, 1, ptr
         tod(maxd(i)); space
         write(maxc(i), 4)
          print(maxp(i)/(40*60), 5, 0); printstring(" !")
         k = maxc(i)//5
         k = 40 %if k > 40
         %cycle j = 1, 1, k; printsymbol('c'); %repeat
         spaces(40-k)

         k = int(maxp(i)/(40*60))//2; %if k > 60 %then k = 60
         %if k > 0 %start
            %cycle j = 1, 1, k
               printsymbol('*')
            %repeat
         %finish
         newline
      %repeat
%end


%routine dumpaddr(%bytearrayname add, %byte l)
   %integer i
   %if l < 14 %then spaces(14-l)
      %if l>14 %then l=14;   ! horrible *************************************
   %if l > 1 %start
      %for i = 0, 1, l>>1-1 %cycle
         writehex(add(i), 2)
      %repeat
   %finish
   %if l & 1 # 0 %then writehex(add(l>>1) >> 4, 1)
%end

%routine tod(%integer secs)
   %integer hour, min
   hour = secs//3600
   min = (secs - hour*3600)//60
   secs = secs - (hour *60 + min)* 60
   printsymbol(hour//10 + '0') ;printsymbol(hour - (hour//10)*10 + '0')
   printsymbol(':')
   printsymbol(min//10 + '0') ;printsymbol(min - (min//10)*10 + '0')
  printsymbol(':')
   printsymbol(secs//10 + '0') ;printsymbol(secs - (secs//10)*10 + '0')
%end

%routine writehex(%integer n,d)
%integer i,j,mask
mask=15<<((d-1)<<2)
%cycle i=0,1,d-1
j=(n&mask)>>((d-i-1)<<2) ;mask=mask>>4
%if j>9 %then j=j+7
j=j+'0'
printsymbol(j)
%repeat
%end


%routine dat(%integer dat)
   %integer d, m, y
   d = dat & 31 ;m = (dat>>5) & 15 ;y = (dat>>9) & 63
   y = y + 1972
   write(d, 2); printsymbol('/') ;write(m, 2) ;printsymbol('/') ;write(y, 4)

%end
%end
%endoffile