home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 126 / af126a.adf / Football.lzx / football / user / Combination.rexx next >
OS/2 REXX Batch file  |  1999-05-22  |  40KB  |  1,303 lines

  1. /* ***********************************************************************
  2.  
  3.    COMBINATION PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------------
  5.     Copyright  Mark Naughton 1999
  6.                                         From an idea by Kevin Lambert
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       200499   After lifting code from other programs and tailoring
  11.                     it for this, this is now ready for testing.
  12.                     All working ok.
  13.            240499   Added league information from LStats.rexx.
  14.            250499   Fixed bug where percentages couldn't be calculated if
  15.                     the results/matches were zero - from LStats.
  16.  
  17.  
  18. **************************************************************************
  19.  
  20. Procedure
  21. ---------
  22.  
  23. 1. Check files exist.
  24. 2. Check options.
  25. 3. Read league name from 'df' file.
  26. 4. Depending on options selected, run the appropriate routine. These have
  27.    not been documented as they are covered in other files.
  28. 5. Display information.
  29. 6. IF option to write the files to a directory has not been chosen,
  30.    display data.
  31.  
  32. ************************************************************************** */
  33. PARSE ARG league_stuff
  34.  
  35. version      = 1
  36. input_file   = '.df'
  37. input2_file  = '.sf'
  38. league_file  = "Data/" || league_stuff
  39. league_title = '*LEAGUE_NAME='
  40. separator    = '*'
  41.  
  42.  
  43. /*******************************************************************/
  44. /* ** THESE PARAMETERS CAN BE CHANGED TO SUIT YOUR REQUIREMENTS ** */
  45. /*******************************************************************/
  46.  
  47. select_fixtures   = "YES"     /* or "NO" */
  48. select_statistics = "NO"
  49. select_table      = "NO"
  50. select_leaginfo   = "YES"
  51.  
  52. output_dir        = "NONE"    /* NONE redirects output to the   */
  53.                               /* console or enter complete path */
  54.                               /* for files to be written        */
  55.  
  56. /*******************************************************************/
  57.  
  58.  
  59. if exists(league_file || input_file) = 0  then exit
  60. if exists(league_file || input2_file) = 0 then exit
  61.  
  62.  
  63. select_fixtures   = upper(select_fixtures)
  64. select_statistics = upper(select_statistics)
  65. select_table      = upper(select_table)
  66. select_leaginfo   = upper(select_leaginfo)
  67.  
  68. if select_fixtures ~= "YES" & select_statistics ~= "YES" & select_table ~= "YES" & select_leaginfo ~= "YES" then do
  69.    say
  70.    say "ERROR :    (Combination)"
  71.    say
  72.    say "No options were selected."
  73.    exit
  74. end
  75.  
  76.  
  77. if open(datafile,league_file||input_file,'r') then do
  78.    do while ~eof(datafile)
  79.       line = readln(datafile)
  80.       if pos(league_title,line) > 0 then
  81.          title = delstr(line,1,13)
  82.    end
  83.    close(datafile)
  84. end
  85. else do
  86.    say
  87.    say "ERROR :    (Combination)"
  88.    say
  89.    say "Cannot open '"league_file||input_file"' for reading."
  90.    exit
  91. end
  92.  
  93.  
  94. if select_fixtures = "YES" then
  95.    call create_fixs(league_stuff,output_dir)
  96.  
  97. if select_statistics = "YES" then
  98.    tcount = create_statistics(league_stuff,output_dir)
  99.  
  100. if select_table = "YES" then
  101.    call create_table(league_stuff,output_dir)
  102.  
  103. if select_leaginfo = "YES" then
  104.    call create_linfo(league_stuff,output_dir)
  105.  
  106.  
  107. osl = 1
  108. say
  109. say center("Combination",78)
  110. say "-----------------------------------------------------------------------------------------"
  111. say
  112. say
  113. say center("League: "title,78)
  114. say
  115. say
  116. say
  117. if select_leaginfo = "YES" then do
  118.    if osl=1 then say "Options Selected:   League Information"
  119.    osl = 0
  120. end
  121. if select_statistics = "YES" then do
  122.    if osl=1 then say "Options Selected:   Team Statistics"
  123.             else say "                    Team Statistics"
  124.    osl = 0
  125. end
  126. if select_fixtures = "YES" then do
  127.    if osl=1 then say "Options Selected:   League Fixtures"
  128.             else say "                    League Fixtures"
  129.    osl = 0
  130. end
  131. if select_table = "YES" then do
  132.    if osl=1 then say "Options Selected:   League Table"
  133.             else say "                    League Table"
  134. end
  135. say
  136. if output_dir ~= "NONE" then do
  137.    say "The following files have been written to '"output_dir"' :"
  138.    say
  139.    if select_fixtures   = "YES" then say "        "league_stuff".fix"
  140.    if select_statistics = "YES" then say "        "league_stuff".Team<number 1-"tcount">.stat"
  141.    if select_table      = "YES" then say "        "league_stuff".tab"
  142.    if select_leaginfo   = "YES" then say "        "league_stuff".linf"
  143. end
  144. else do
  145.    say
  146.    say
  147.    say
  148.    if select_leaginfo = "YES" then do
  149.       say
  150.       say center("League Information",78)
  151.       say "-----------------------------------------------------------------------------------------"
  152.       say
  153.       say
  154.       if open(datafile,"RAM:"league_stuff".linf",'r') then do
  155.          do while ~eof(datafile)
  156.             line = readln(datafile)
  157.             say line
  158.          end
  159.          close(datafile)
  160.          say
  161.          say
  162.       end
  163.       else do
  164.          say
  165.          say "ERROR :    (Combination)"
  166.          say
  167.          say "Unable to open 'RAM:"league_stuff".linf' file."
  168.       end
  169.       say
  170.       filen = "RAM:"league_stuff".linf"
  171.       address command 'delete >NIL: 'filen
  172.    end
  173.    if select_statistics = "YES" then do
  174.       say
  175.       say
  176.       say center("Team Statistics",78)
  177.       say "-------------------------------------------------------------------------------"
  178.       say
  179.       say
  180.       do kk=1 to tcount
  181.          if open(datafile,"RAM:"league_stuff"_Team"kk".stat",'r') then do
  182.             do while ~eof(datafile)
  183.                line = readln(datafile)
  184.                say line
  185.             end
  186.             close(datafile)
  187.          end
  188.          else do
  189.             say
  190.             say "ERROR :    (Combination)"
  191.             say
  192.             say "Unable to open 'RAM:"league_stuff"_Team"kk".stat' file."
  193.          end
  194.          say
  195.          filen = "RAM:"league_stuff"_Team"kk".stat"
  196.          address command 'delete >NIL: 'filen
  197.       end
  198.    end
  199.    if select_fixtures = "YES" then do
  200.       say
  201.       say
  202.       say center("League Fixtures",78)
  203.       say "-----------------------------------------------------------------------------------------"
  204.       say
  205.       say
  206.       if open(datafile,"RAM:"league_stuff".fix",'r') then do
  207.          do while ~eof(datafile)
  208.             line = readln(datafile)
  209.             say line
  210.          end
  211.          close(datafile)
  212.       end
  213.       else do
  214.          say
  215.          say "ERROR :    (Combination)"
  216.          say
  217.          say "Unable to open 'RAM:"league_stuff".fix' file."
  218.       end
  219.       say
  220.       filen = "RAM:"league_stuff".fix"
  221.       address command 'delete >NIL: 'filen
  222.    end
  223.    if select_table = "YES" then do
  224.       say
  225.       say
  226.       say
  227.       say center("League Table",78)
  228.       say "-----------------------------------------------------------------------------------------"
  229.       say
  230.       say
  231.       say
  232.       say "    Team                               Pl Won Drw Lst GoalsF GoalsA    Pts     GoalDiff"
  233.       say "-----------------------------------------------------------------------------------------"
  234.       a = 1
  235.       if open(datafile,"RAM:"league_stuff".tab",'r') then do
  236.          do while ~eof(datafile)
  237.             line = readln(datafile)
  238.             if line ~= '' then do
  239.                if strip(substr(line,76,5)) = 0 then line=overlay("",line,76,5," ")
  240.                if a<10 then do
  241.                   if a = 1 then line = upper(line)
  242.                   say " "a") "line
  243.                end
  244.                else
  245.                   say a") "line
  246.                a = a + 1
  247.             end
  248.          end
  249.          close(datafile)
  250.       end
  251.       else do
  252.          say
  253.          say "ERROR :    (Combination)"
  254.          say
  255.          say "Unable to open 'RAM:"league_stuff".tab' file."
  256.       end
  257.       say
  258.       filen = "RAM:"league_stuff".tab"
  259.       address command 'delete >NIL: 'filen
  260.    end
  261. end
  262.  
  263. exit
  264.  
  265. /* Procedure --------------------------------------------------------- */
  266.  
  267. create_fixs : procedure
  268. parse arg league_table,output_dr
  269.  
  270. league_file = "Data/"league_table
  271. input_file  = '.df'
  272. input2_file = '.sf'
  273. autosched   = '*AUTOSCHD='
  274. separator   = '*'
  275. autos = 0
  276.  
  277. if open(datafile,league_file||input_file,'r') then do
  278.    do while ~eof(datafile)
  279.       line = readln(datafile)
  280.       if pos(autosched,line) > 0 then do
  281.          autofile = delstr(line,1,10)
  282.          autos = 1
  283.       end
  284.    end
  285.    close(datafile)
  286. end
  287. else do
  288.    say
  289.    say "ERROR :    (Combination)"
  290.    say
  291.    say "Cannot open '"league_file||input_file"' for reading."
  292.    exit
  293. end
  294.  
  295. file_string = "RAM:"league_table".fix"
  296. if output_dr ~= "NONE" then
  297.    file_string = output_dr"/"league_table".fix"
  298.  
  299. if autos = 0 then do
  300.    if open(datafile,league_file || input2_file,'r') then do
  301.       if open(datafile2,file_string,'w') then do
  302.          do while ~eof(datafile)
  303.             line = readln(datafile)
  304.             if pos(separator,line) = 0 then do
  305.                t1 = right(strip(substr(line,1,30)),30,' ')
  306.                writeln(datafile2,t1||substr(line,31))
  307.             end
  308.             else do
  309.                if words(line) > 1 then do
  310.                   chas = subword(line,2)
  311.                   writeln(datafile2,chas)
  312.                   uline = ''
  313.                   do i=1 to length(chas)
  314.                      uline = insert('-',uline,i,1)
  315.                   end
  316.                   writeln(datafile2,strip(uline))
  317.                end
  318.                else
  319.                   if words(line) = 1 then
  320.                      writeln(datafile2," ")
  321.             end
  322.          end
  323.          close(datafile2)
  324.       end
  325.       else do
  326.          say
  327.          say "ERROR :    (Combination)"
  328.          say
  329.          say "Cannot write to '"file_string"'."
  330.       end
  331.       close(datafile)
  332.    end
  333.    else do
  334.       say
  335.       say "ERROR :    (Combination)"
  336.       say
  337.       say "Cannot open '"league_file||input2_file"' for reading."
  338.    end
  339.    exit
  340. end
  341.  
  342. if open(datafile,league_file || input2_file,'r') then do
  343.    if open(datafile2,file_string,'w') then do
  344.       do while ~eof(datafile)
  345.          line = readln(datafile)
  346.          if pos(separator,line) = 0 then do
  347.             t1 = right(strip(substr(line,1,30)),30,' ')
  348.             writeln(datafile2,t1||substr(line,31))
  349.          end
  350.          else do
  351.             if words(line) > 1 then do
  352.                if pos("*Week",line) > 0 then do
  353.                   chas = subword(line,2)
  354.                   do mm=1 to length(chas)
  355.                      if substr(chas,mm,1) = "0" then
  356.                         chas = overlay(" ",chas,mm,1)
  357.                      else
  358.                         leave
  359.                   end
  360.                   chas = "Week "strip(chas)
  361.                end
  362.                else
  363.                   chas = subword(line,2)
  364.                writeln(datafile2,chas)
  365.                uline = ''
  366.                do i=1 to length(chas)
  367.                   uline = insert('-',uline,i,1)
  368.                end
  369.                writeln(datafile2,strip(uline))
  370.             end
  371.             else
  372.                if words(line) = 1 then
  373.                   writeln(datafile2," ")
  374.          end
  375.       end
  376.       close(datafile2)
  377.    end
  378.    else do
  379.       say
  380.       say "ERROR :    (Combination)"
  381.       say
  382.       say "Cannot write to '"file_string"'."
  383.    end
  384.    close(datafile)
  385. end
  386. else do
  387.    say
  388.    say "ERROR :    (Combination)"
  389.    say
  390.    say "Cannot open '"league_file||input2_file"' for reading."
  391. end
  392.  
  393. return
  394.  
  395. /* Procedure --------------------------------------------------------- */
  396.  
  397. create_statistics : procedure
  398. parse arg league_stuff,output_dr
  399.  
  400. PARSE ARG league_stuff
  401.  
  402. version      = 1
  403. input_file   = '.df'
  404. input2_file  = '.sflearn'
  405. title        = '*LEAGUE_NAME='
  406. points_win   = '*POINTS_PER_WIN='
  407. points_drw   = '*POINTS_PER_DRW='
  408. points_lse   = '*POINTS_PER_LSE='
  409. points_gls   = '*POINTS_PER_GLS='
  410. separator    = '*'
  411. teams.       = '???'
  412. tcounter     = 0
  413. not_played   = '__   __'
  414. hplay        = 0
  415. hwin         = 0
  416. hdraw        = 0
  417. hloss        = 0
  418. hgoals       = 0
  419. hagoals      = 0
  420. hpts         = 0
  421. hcls         = 0
  422. aplay        = 0
  423. awin         = 0
  424. adraw        = 0
  425. aloss        = 0
  426. agoals       = 0
  427. aagoals      = 0
  428. apts         = 0
  429. acls         = 0
  430. ptsgls       = 0
  431. league_file  = "Data/" || league_stuff
  432.  
  433. if exists(league_file || input_file) = 0  then exit
  434. if exists(league_file || input2_file) = 0 then exit
  435.  
  436. if open(datafile,league_file || input_file,'r') then do
  437.    do while ~eof(datafile)
  438.       line = readln(datafile)
  439.       if pos(title,line) > 0 then       league_title = delstr(line,1,13)
  440.       if pos(points_win,line) > 0 then  ptswin=delstr(line,1,16)
  441.       if pos(points_drw,line) > 0 then  ptsdrw=delstr(line,1,16)
  442.       if pos(points_lse,line) > 0 then  ptslse=delstr(line,1,16)
  443.       if pos(points_gls,line) > 0 then  ptsgls=delstr(line,1,16)
  444.       if pos(separator,line) = 0 then do
  445.          line = strip(line)
  446.          if tcounter = 0 then do
  447.             teams.1 = line
  448.             tcounter = 1
  449.          end
  450.          else do
  451.             tcounter      = tcounter + 1
  452.             teams.tcounter = line
  453.          end
  454.       end
  455.    end
  456.    close(datafile)
  457.  
  458.    do jj=1 to tcounter
  459.       hplay        = 0
  460.       hwin         = 0
  461.       hdraw        = 0
  462.       hloss        = 0
  463.       hgoals       = 0
  464.       hagoals      = 0
  465.       hpts         = 0
  466.       hcls         = 0
  467.       aplay        = 0
  468.       awin         = 0
  469.       adraw        = 0
  470.       aloss        = 0
  471.       agoals       = 0
  472.       aagoals      = 0
  473.       apts         = 0
  474.       acls         = 0
  475.       file_string = "RAM:"league_stuff"_Team"jj".stat"
  476.       if output_dr ~= "NONE" then
  477.          file_string = output_dr"/"league_stuff"_Team"jj".stat"
  478.       if open(datafile2,file_string,'w') then do
  479.          writeln(datafile2," ")
  480.          writeln(datafile2,"  Statistics For: "teams.jj)
  481.          writeln(datafile2," ")
  482.          writeln(datafile2," ")
  483.          writeln(datafile2," ")
  484.          matches = 0
  485.          lrecord = ''
  486.          awayperf= ''
  487.          homeperf= ''
  488.          if open(datafile,league_file || input2_file,'r') then do
  489.             do while ~eof(datafile)
  490.                line = readln(datafile)
  491.                if pos(separator,line) = 0 then do
  492.                   if pos(not_played,line) = 0 then do
  493.                      home_team = strip(substr(line,1,30))
  494.                      goals_for = substr(line,32,2)
  495.                      goals_aga = substr(line,37,2)
  496.                      away_team = strip(substr(line,41,30))
  497.                      strng     = strip(teams.jj)
  498.  
  499.                      if strng = home_team then do
  500.                         if goals_aga = 0 then
  501.                            hcls = hcls + 1
  502.                         if goals_for > goals_aga then do
  503.                            hwin = hwin + 1
  504.                            ltemp = 'W'
  505.                            hpts = hpts + ptswin
  506.                         end
  507.                         if goals_for = goals_aga then do
  508.                            hdraw = hdraw + 1
  509.                            ltemp = 'D'
  510.                            hpts = hpts + ptsdrw
  511.                         end
  512.                         if goals_for < goals_aga then do
  513.                            hloss = hloss + 1
  514.                            ltemp = 'L'
  515.                            hpts = hpts + ptslse
  516.                         end
  517.                         lrecord = insert(ltemp,lrecord,matches+1,1)
  518.                         homeperf= insert(ltemp,homeperf,hplay+1,1)
  519.                         hgoals  = hgoals + goals_for
  520.                         hagoals = hagoals+ goals_aga
  521.                         hplay   = hplay + 1
  522.                         matches = matches + 1
  523.                         hpts    = hpts + (goals_for * ptsgls)
  524.                      end
  525.                      if strng = away_team then do
  526.                         if goals_for = 0 then
  527.                            acls = acls + 1
  528.                         if goals_for > goals_aga then do
  529.                            aloss = aloss + 1
  530.                            ltemp = 'L'
  531.                            apts  = apts + ptslse
  532.                         end
  533.                         if goals_for = goals_aga then do
  534.                            adraw = adraw + 1
  535.                            ltemp = 'D'
  536.                            apts  = apts + ptsdrw
  537.                         end
  538.                         if goals_for < goals_aga then do
  539.                            awin  = awin + 1
  540.                            ltemp = 'W'
  541.                            apts  = apts + ptswin
  542.                         end
  543.                         lrecord = insert(ltemp,lrecord,matches+1,1)
  544.                         awayperf= insert(ltemp,awayperf,aplay+1,1)
  545.                         agoals  = agoals + goals_aga
  546.                         aagoals = aagoals+ goals_for
  547.                         aplay   = aplay + 1
  548.                         matches = matches + 1
  549.                         apts    = apts + (goals_aga * ptsgls)
  550.                      end
  551.                   end
  552.                end
  553.             end
  554.             close(datafile)
  555.             if matches = 0 then do
  556.                writeln(datafile2,"  No matches yet played.")
  557.                writeln(datafile2," ")
  558.             end
  559.             else do
  560.                writeln(datafile2,"  Home                                       Away")
  561.                writeln(datafile2," ")
  562.                writeln(datafile2,"  Pl  W   D   L   Cln  Gf   Ga   Pts         Pl  W   D   L   Cln  Gf   Ga   Pts")
  563.                writeln(datafile2,"  --------------------------------------     --------------------------------------")
  564.                h1 = "  "left(hplay,3)" "
  565.                h2 = left(hwin,3)" "
  566.                h3 = left(hdraw,3)" "
  567.                h4 = left(hloss,3)" "
  568.                h5 = left(hgoals,4)" "
  569.                h6 = left(hagoals,4)" "
  570.                h7 = left(hpts,6)"      "
  571.                h8 = left(hcls,4)" "
  572.                a1 = left(aplay,3)" "
  573.                a2 = left(awin,3)" "
  574.                a3 = left(adraw,3)" "
  575.                a4 = left(aloss,3)" "
  576.                a5 = left(agoals,4)" "
  577.                a6 = left(aagoals,4)" "
  578.                a7 = left(apts,6)
  579.                a8 = left(acls,4)" "
  580.                writeln(datafile2,h1||h2||h3||h4||h8||h5||h6||h7||a1||a2||a3||a4||a8||a5||a6||a7)
  581.                writeln(datafile2," ")
  582.                writeln(datafile2," ")
  583.                writeln(datafile2," ")
  584.                writeln(datafile2," ")
  585.                writeln(datafile2," ")
  586.                re  = 0
  587.                lre = 0
  588.                do i=1 to matches+1
  589.                   if substr(lrecord,i,1) = 'W' then re = re + 1
  590.                   if substr(lrecord,i,1) = 'D' then re = re + 1
  591.                   if substr(lrecord,i,1) = 'L' then do
  592.                      if re > lre then lre = re
  593.                      re = 0
  594.                   end
  595.                end
  596.                if lre = 0 then lre = re
  597.  
  598.                lrecord = strip(lrecord)
  599.                countr = (matches * 2) - 1
  600.                if matches > 8 then do
  601.                   lrecord = right(lrecord,8)
  602.                   countr  = 15
  603.                end
  604.                call format_perf(lrecord,countr)
  605.                if countr = 1 then ptemp = lrecord
  606.                if matches < 9 then
  607.                   writeln(datafile2,"  Performance over last "matches" games: "ptemp)
  608.                else
  609.                   writeln(datafile2,"  Performance over last 8 games: "ptemp)
  610.  
  611.                homeperf=strip(homeperf)
  612.                hcountr = (hplay * 2) - 1
  613.                if hplay > 8 then do
  614.                   homeperf = right(homeperf,8)
  615.                   hcountr  = 15
  616.                end
  617.                call format_perf(homeperf,hcountr)
  618.                if hplay = 1 then ptemp = homeperf
  619.                writeln(datafile2," ")
  620.                writeln(datafile2,"                Home Record    : "ptemp)
  621.  
  622.                awayperf=strip(awayperf)
  623.                acountr = (aplay * 2) - 1
  624.                if aplay > 8 then do
  625.                   awayperf = right(awayperf,8)
  626.                   acountr  = 15
  627.                end
  628.                call format_perf(awayperf,acountr)
  629.                if aplay = 1 then ptemp = awayperf
  630.                writeln(datafile2," ")
  631.                writeln(datafile2,"                Away Record    : "ptemp)
  632.                writeln(datafile2," ")
  633.                writeln(datafile2," ")
  634.                writeln(datafile2,"     Current undefeated run    : "re" games.")
  635.                writeln(datafile2,"     Longest undefeated run    : "lre" games.")
  636.                writeln(datafile2," ")
  637.                writeln(datafile2," ")
  638.                writeln(datafile2," ")
  639.             end
  640.          end
  641.          else do
  642.             say
  643.             say "ERROR :    (Combination)"
  644.             say
  645.             say "Cannot read '"league_file || input2_file"' datafile."
  646.          end
  647.          close(datafile2)
  648.       end
  649.       else do
  650.          say
  651.          say "ERROR :    (Combination)"
  652.          say
  653.          say "Cannot write to '"file_string"'."
  654.          exit
  655.       end
  656.    end
  657. end
  658. else do
  659.    say
  660.    say "ERROR :    (Combination)"
  661.    say
  662.    say "Cannot read '"league_file || input_file"' datafile."
  663. end
  664.  
  665. return tcounter
  666.  
  667. /* Procedure --------------------------------------------------------- */
  668.  
  669. create_linfo : procedure
  670. parse arg league_stuff,output_dr
  671.  
  672. input_file   = '.df'
  673. input2_file  = '.sflearn'
  674. points_win   = '*POINTS_PER_WIN='
  675. points_drw   = '*POINTS_PER_DRW='
  676. points_lse   = '*POINTS_PER_LSE='
  677. points_gls   = '*POINTS_PER_GLS='
  678. releg        = '*RELEGATION='
  679. playother    = '*PLAY_OTHER='
  680. promoted     = '*PROMOTED='
  681. num_divs     = '*NUM_DIVISIONS='
  682. divisions    = '*DIVISIONS='
  683. pkauthor     = '*  Author ='
  684. pkversion    = '*  Version='
  685. pkdate       = '*  Date   ='
  686. separator    = '*'
  687. not_played   = '__   __'
  688. teams.       = '???'
  689. records.     = '???'
  690. undefeat.    = '???'
  691. ustring.     = '???'
  692. rstring.     = '???'
  693. mats.        = '???'
  694. pct.         = '???'
  695. tcountr      = 0
  696. lversion     = '1.0'
  697. lreg         = 2
  698. lplayo       = 2
  699. ptsgls       = 0
  700. ndivs        = 1
  701. promo        = 0
  702. divs         = ''
  703.  
  704.  
  705. league_file = "Data/"league_stuff
  706.  
  707. if exists(league_file || input_file) = 0  then exit
  708. if exists(league_file || input2_file) = 0 then exit
  709.  
  710. if open(datafile,league_file || input_file,'r') then do
  711.    do while ~eof(datafile)
  712.       line = readln(datafile)
  713.       if pos(pkauthor,line) > 0 then     author       = delstr(line,1,12)
  714.       if pos(pkversion,line) > 0 then    lversion     = delstr(line,1,12)
  715.       if pos(pkdate,line) > 0 then       ddate        = delstr(line,1,12)
  716.       if pos(points_win,line) > 0 then   ptswin       = delstr(line,1,16)
  717.       if pos(points_drw,line) > 0 then   ptsdrw       = delstr(line,1,16)
  718.       if pos(points_lse,line) > 0 then   ptslse       = delstr(line,1,16)
  719.       if pos(points_gls,line) > 0 then   ptsgls       = delstr(line,1,16)
  720.       if pos(releg,line) > 0 then        lreg         = delstr(line,1,12)
  721.       if pos(playother,line) > 0 then    lplayo       = delstr(line,1,12)
  722.       if pos(promoted,line) > 0 then     promo        = delstr(line,1,10)
  723.       if pos(num_divs,line) > 0 then     ndivs        = delstr(line,1,15)
  724.       if pos(divisions,line) > 0 then    divs         = delstr(line,1,11)
  725.       if pos(separator,line) = 0 then do
  726.          line = strip(line)
  727.          tcountr         = tcountr + 1
  728.          teams.tcountr   = strip(line)
  729.          records.tcountr = 0
  730.          undefeat.tcountr= ''
  731.          mats.tcountr    = 0
  732.          pct.tcountr     = 0
  733.       end
  734.    end
  735.    close(datafile)
  736. end
  737. else do
  738.    say
  739.    say "ERROR :    (Combination)"
  740.    say
  741.    say "Cannot open '"league_file||input_file"' for reading."
  742.    exit
  743. end
  744.  
  745. line_ct = 0
  746. matches = 0
  747. high_df = 0
  748. high_ht = ''
  749. high_at = ''
  750. high_hw = 0
  751. high_aw = 0
  752. high_hs = 0
  753. high_as = 0
  754. draws   = 0
  755. hwins   = 0
  756. awins   = 0
  757. type    = 0
  758. hcls    = 99
  759. acls    = 99
  760. nlines. = '???'
  761. nlcnt   = 0
  762. if open(datafile,league_file || input2_file,'r') then do
  763.    do while ~eof(datafile)
  764.       line_ct = line_ct + 1
  765.       line = readln(datafile)
  766.       if pos(separator,line) = 0 then do
  767.          if pos(not_played,line) = 0 then do
  768.             home_team = strip(substr(line,1,30))
  769.             goals_for = substr(line,32,2)
  770.             goals_aga = substr(line,37,2)
  771.             away_team = strip(substr(line,41,30))
  772.  
  773.             h = 0
  774.             a = 0
  775.             do i=1 to tcountr
  776.                if pos(strip(home_team),teams.i) > 0 then do
  777.                   h = i
  778.                   mats.i = mats.i + 1
  779.                end
  780.                if pos(strip(away_team),teams.i) > 0 then do
  781.                   mats.i = mats.i + 1
  782.                   a = i
  783.                end
  784.             end
  785.  
  786.             if a ~= 0 & h ~= 0 then do
  787.                if goals_for > goals_aga then do
  788.                   records.h = records.h + ptswin
  789.                   records.a = records.a + ptslse
  790.                   undefeat.h = insert('W',undefeat.h,length(undefeat.h),1)
  791.                   undefeat.a = ''
  792.                end
  793.                if goals_for < goals_aga then do
  794.                   records.a = records.a + ptswin
  795.                   records.h = records.h + ptslse
  796.                   undefeat.a = insert('W',undefeat.a,length(undefeat.a),1)
  797.                   undefeat.h = ''
  798.                end
  799.                if goals_for = goals_aga then do
  800.                   records.a = records.a + ptsdrw
  801.                   records.h = records.h + ptsdrw
  802.                   undefeat.a = insert('D',undefeat.a,length(undefeat.a),1)
  803.                   undefeat.h = insert('D',undefeat.h,length(undefeat.h),1)
  804.                end
  805.             end
  806.  
  807.  
  808.             if home_team ~= away_team & home_team ~= '' & away_team ~= '' then
  809.                matches   = matches + 1
  810.             diff = 0
  811.             if goals_for = goals_aga & home_team ~= away_team then do
  812.                draws = draws + 1
  813.                type = 0
  814.             end
  815.             if goals_for > goals_aga then do
  816.                hwins = hwins + 1
  817.                diff  = goals_for - goals_aga
  818.                type  = 1
  819.             end
  820.             if goals_for < goals_aga then do
  821.                awins = awins + 1
  822.                diff  = goals_aga - goals_for
  823.                type  = 2
  824.             end
  825.             if type = 1 then do
  826.                if diff >= high_hw then do
  827.                   nlcnt = nlcnt + 1
  828.                   nlines.nlcnt = line
  829.                   if ((goals_for > high_hs) | (diff = goals_for)) | (diff = high_hw & goals_aga <= hcls) then do
  830.                      high_hw = diff
  831.                      hcls    = goals_aga
  832.                      high_hs = goals_for
  833.                      high_ht = line
  834.                   end
  835.                end
  836.             end
  837.             if type = 2 then do
  838.                if diff >= high_aw then do
  839.                   nlcnt = nlcnt + 1
  840.                   nlines.nlcnt = line
  841.                   if ((goals_aga > high_as) | (diff = goals_aga)) | (diff = high_aw & goals_for <= acls) then do
  842.                      high_as = goals_aga
  843.                      high_at = line
  844.                      high_aw = diff
  845.                      acls    = goals_for
  846.                   end
  847.                end
  848.             end
  849.             type = 0
  850.          end
  851.       end
  852.    end
  853.    close(datafile)
  854.  
  855.    r   = 0
  856.    rcs = 0
  857.    u   = 1
  858.    ucs = 0
  859.    do i=1 to tcountr
  860.       if records.i ~= 0 | mats.i ~= 0 then do
  861.          pct.i = trunc((records.i/(mats.i*ptswin) * 100),1)
  862.          if pct.i > r then r = pct.i
  863.       end
  864.       else
  865.          pct.i = "0.0"
  866.    end
  867.    do i=1 to tcountr
  868.       if pct.i = r then do
  869.          rcs = rcs + 1
  870.          rstring.rcs = teams.i || " with " || records.i || "pts from " || mats.i || " matches. ( " || pct.i || "% )"
  871.       end
  872.    end
  873.  
  874.    do i=1 to tcountr
  875.       if length(undefeat.i) > u then
  876.          u  = length(undefeat.i)
  877.    end
  878.  
  879.    do i=1 to tcountr
  880.       if length(undefeat.i) = u then do
  881.          ucs = ucs + 1
  882.          undefeat.i=strip(undefeat.i)
  883.          ucn = (length(undefeat.i) * 2) - 1
  884.          call format_perf(undefeat.i,ucn)
  885.          if ucn = 1 then ptemp = undefeat.i
  886.          if length(ptemp) > 0 then
  887.             ustring.ucs = "           " || left(teams.i,30) || " (" || ptemp || ")"
  888.       end
  889.    end
  890.  
  891.    hmw   = trunc((hwins/matches) * 100,1)
  892.    dm    = trunc((draws/matches) * 100,1)
  893.    amw   = trunc((awins/matches) * 100,1)
  894.    hwins = centre(hwins,5)
  895.    draws = centre(draws,5)
  896.    awins = centre(awins,5)
  897.  
  898.    file_string = "RAM:"league_stuff".linf"
  899.    if output_dr ~= "NONE" then
  900.       file_string = output_dr"/"league_stuff".linf"
  901.  
  902.  
  903.    if open(datafile2,file_string,'w') then do
  904.       writeln(datafile2," ")
  905.       writeln(datafile2,"                                               Author : "author)
  906.       writeln(datafile2,"                                               Created: "ddate)
  907.       writeln(datafile2,"                                               Version: "lversion)
  908.       writeln(datafile2," ")
  909.       writeln(datafile2,"Matches played : "matches)
  910.       writeln(datafile2," ")
  911.       writeln(datafile2,"Home Wins      : "hwins"  ( "hmw"% )")
  912.       writeln(datafile2,"Draws          : "draws"  ( "dm"% )")
  913.       writeln(datafile2,"Away Wins      : "awins"  ( "amw"% )")
  914.       writeln(datafile2," ")
  915.       writeln(datafile2,"Points For Win  : "ptswin)
  916.       writeln(datafile2,"Points For Draw : "ptsdrw)
  917.       writeln(datafile2,"Points For Loss : "ptslse)
  918.       writeln(datafile2,"Points Per Goal : "ptsgls"    (NOT used for Best Record/Undefeated Run)")
  919.       writeln(datafile2," ")
  920.       writeln(datafile2,"Number of Teams Promoted   : "promo)
  921.       writeln(datafile2,"Number of Teams Relegated  : "lreg)
  922.       writeln(datafile2,"Play Each Team             : "lplayo)
  923.       writeln(datafile2," ")
  924.       writeln(datafile2,"Number of Related Divisions: "ndivs - 1)
  925.       writeln(datafile2,"Related Divisions          : "divs)
  926.       writeln(datafile2,"_______________________________________________________________________________")
  927.       writeln(datafile2," ")
  928.       writeln(datafile2,"Biggest Home Win       (Priority given to teams with less goals scored against)")
  929.       writeln(datafile2,"----------------")
  930.       writeln(datafile2," ")
  931.       hline = substr(high_ht,32,2)"   "substr(high_ht,37,2)
  932.       if hline ~= "" then do
  933.          do i=1 to nlcnt
  934.             if pos(hline,nlines.i) > 0 then
  935.                writeln(datafile2,nlines.i)
  936.          end
  937.       end
  938.       else
  939.          writeln(datafile2,"None found.")
  940.       writeln(datafile2," ")
  941.       writeln(datafile2,"Biggest Away Win")
  942.       writeln(datafile2,"----------------")
  943.       writeln(datafile2," ")
  944.       aline = substr(high_at,32,2)"   "substr(high_at,37,2)
  945.       if aline ~= "" then do
  946.          do i=1 to nlcnt
  947.             if pos(aline,nlines.i) > 0 then
  948.                writeln(datafile2,nlines.i)
  949.          end
  950.       end
  951.       else
  952.          writeln(datafile2,"None found.")
  953.       writeln(datafile2,"_______________________________________________________________________________")
  954.       writeln(datafile2," ")
  955.       writeln(datafile2,"Best Record")
  956.       writeln(datafile2,"-----------")
  957.       writeln(datafile2," ")
  958.       do i=1 to rcs
  959.          writeln(datafile2,rstring.i)
  960.       end
  961.       writeln(datafile2," ")
  962.       writeln(datafile2," ")
  963.       writeln(datafile2,"Current Best Undefeated Run")
  964.       writeln(datafile2,"---------------------------")
  965.       writeln(datafile2," ")
  966.       ustring.1 = overlay(u || " games :",ustring.1,1)
  967.       do i=1 to ucs
  968.          writeln(datafile2,ustring.i)
  969.       end
  970.       writeln(datafile2," ")
  971.       writeln(datafile2,"-------------------------------------------------------------------------------")
  972.       close(datafile2)
  973.    end
  974.    else do
  975.       say
  976.       say "ERROR :    (Combination)"
  977.       say
  978.       say "Cannot open '"file_string"' for writing."
  979.       exit
  980.    end
  981. end
  982. else do
  983.    say
  984.    say "ERROR :    (Combination)"
  985.    say
  986.    say "Cannot open '"league_file||input2_file"' for reading."
  987.    exit
  988. end
  989.  
  990. return
  991.  
  992. /* Routine ---------------------------------------------------------- */
  993.  
  994. save_data:
  995. PARSE ARG homet,awayt,gf,ga
  996.  
  997. h = 0
  998. a = 0
  999. do i=1 to tcountr
  1000.    if pos(strip(homet),teams.i) > 0 then do
  1001.       h = i
  1002.       mats.i = mats.i + 1
  1003.    end
  1004.    if pos(strip(awayt),teams.i) > 0 then do
  1005.       mats.i = mats.i + 1
  1006.       a = i
  1007.    end
  1008. end
  1009. if a = 0 | h = 0 then return
  1010.  
  1011. if gf > ga then do
  1012.    records.h = records.h + ptswin
  1013.    records.a = records.a + ptslse
  1014.    undefeat.h = insert('W',undefeat.h,length(undefeat.h),1)
  1015.    undefeat.a = ''
  1016. end
  1017. if gf < ga then do
  1018.    records.a = records.a + ptswin
  1019.    records.h = records.h + ptslse
  1020.    undefeat.a = insert('W',undefeat.a,length(undefeat.a),1)
  1021.    undefeat.h = ''
  1022. end
  1023. if gf = ga then do
  1024.    records.a = records.a + ptsdrw
  1025.    records.h = records.h + ptsdrw
  1026.    undefeat.a = insert('D',undefeat.a,length(undefeat.a),1)
  1027.    undefeat.h = insert('D',undefeat.h,length(undefeat.h),1)
  1028. end
  1029. return
  1030.  
  1031.  
  1032. /* Procedure --------------------------------------------------------- */
  1033.  
  1034. create_table : procedure
  1035. parse arg league_stuff,output_dr
  1036.  
  1037. input_file   = '.df'
  1038. input2_file  = '.sf'
  1039. not_played   = '__   __'
  1040. input3_file  = '.stats'
  1041. league_table = "Data/"league_stuff
  1042. output_file  = 'Data/League.output'
  1043. points_win   = '*POINTS_PER_WIN='
  1044. points_drw   = '*POINTS_PER_DRW='
  1045. points_lse   = '*POINTS_PER_LSE='
  1046. points_gls   = '*POINTS_PER_GLS='
  1047. team         = '*TEAM='
  1048. played       = '*PLY='
  1049. won          = '*WIN='
  1050. drawn        = '*DRW='
  1051. lost         = '*LST='
  1052. goalsf       = '*GOF='
  1053. goalsa       = '*GOA='
  1054. points       = '*PTS='
  1055. separator    = '*'
  1056. teams.       = '???'
  1057. teams2.      = '???'
  1058. m_ply.       = '???'
  1059. m_win.       = '???'
  1060. m_drw.       = '???'
  1061. m_lost.      = '???'
  1062. m_gof.       = '???'
  1063. m_goa.       = '???'
  1064. m_pts.       = '???'
  1065. ptsgls       = 0
  1066. ptswin       = 2
  1067. ptsdrw       = 1
  1068. ptslse       = 0
  1069.  
  1070.  
  1071. if exists(league_table || input3_file) = 0 then do
  1072.    say
  1073.    say "ERROR :    (Combination)"
  1074.    say
  1075.    say "Cannot find '"league_table||input3_file"' for table creation."
  1076.    exit
  1077. end
  1078.  
  1079. tcount = 0
  1080. if open(datafile,league_table || input_file,'r') then do
  1081.    do while ~eof(datafile)
  1082.       line = readln(datafile)
  1083.       if pos(points_win,line) > 0 then   ptswin=delstr(line,1,16)
  1084.       if pos(points_drw,line) > 0 then   ptsdrw=delstr(line,1,16)
  1085.       if pos(points_lse,line) > 0 then   ptslse=delstr(line,1,16)
  1086.       if pos(points_gls,line) > 0 then   ptsgls=delstr(line,1,16)
  1087.       if pos(separator,line) = 0 then do
  1088.          line = strip(line)
  1089.          tcount       = tcount + 1
  1090.          teams.tcount = line
  1091.       end
  1092.    end
  1093.    close(datafile)
  1094. end
  1095. else do
  1096.    say
  1097.    say "ERROR :    (Combination)"
  1098.    say
  1099.    say "Unable to open '"league_table || input_file"' file."
  1100.    exit
  1101. end
  1102.  
  1103. team_ctr = 0
  1104. if open(datafile,league_table || input3_file,'r') then do
  1105.    do while ~eof(datafile)
  1106.       line = readln(datafile)
  1107.       if pos(team,line) > 0 then    team_ctr = team_ctr + 1
  1108.       if pos(played,line) > 0 then  m_ply.team_ctr  = delstr(line,1,5)
  1109.       if pos(won,line) > 0 then     m_won.team_ctr  = delstr(line,1,5)
  1110.       if pos(drawn,line) > 0 then   m_drw.team_ctr  = delstr(line,1,5)
  1111.       if pos(lost,line) > 0 then    m_lost.team_ctr = delstr(line,1,5)
  1112.       if pos(goalsf,line) > 0 then  m_gof.team_ctr  = delstr(line,1,5)
  1113.       if pos(goalsa,line) > 0 then  m_goa.team_ctr  = delstr(line,1,5)
  1114.       if pos(points,line) > 0 then  m_pts.team_ctr  = delstr(line,1,5)
  1115.    end
  1116.    close(datafile)
  1117. end
  1118. else do
  1119.    say
  1120.    say "ERROR :    (Combination)"
  1121.    say
  1122.    say "Unable to open '"league_table || input3_file"'."
  1123.    exit
  1124. end
  1125.  
  1126. if open(datafile,league_table || input2_file,'r') then do
  1127.    do while ~eof(datafile)
  1128.       line = readln(datafile)
  1129.       if pos(separator,line) = 0 then do
  1130.          if pos(not_played,line) = 0 then do
  1131.             home_team = strip(substr(line,1,30))
  1132.             goals_for = substr(line,32,2)
  1133.             goals_aga = substr(line,37,2)
  1134.             away_team = strip(substr(line,41,30))
  1135.  
  1136.             do i=1 to tcount
  1137.                if home_team = teams.i then do
  1138.                   m_ply.i = m_ply.i + 1
  1139.                   m_gof.i = m_gof.i + goals_for
  1140.                   m_goa.i = m_goa.i + goals_aga
  1141.                   if goals_for = goals_aga then do
  1142.                      m_drw.i = m_drw.i + 1
  1143.                      m_pts.i = m_pts.i + ptsdrw
  1144.                   end
  1145.                   if goals_for < goals_aga then do
  1146.                      m_lost.i= m_lost.i + 1
  1147.                      m_pts.i = m_pts.i + ptslse
  1148.                   end
  1149.                   if goals_for > goals_aga then do
  1150.                      m_won.i = m_won.i + 1
  1151.                      m_pts.i = m_pts.i + ptswin
  1152.                   end
  1153.                   m_pts.i = m_pts.i + (goals_for * ptsgls)
  1154.                end
  1155.             end
  1156.             do i=1 to tcount
  1157.                if away_team = teams.i then do
  1158.                   m_ply.i = m_ply.i + 1
  1159.                   m_gof.i = m_gof.i + goals_aga
  1160.                   m_goa.i = m_goa.i + goals_for
  1161.                   if goals_for = goals_aga then do
  1162.                      m_drw.i = m_drw.i + 1
  1163.                      m_pts.i = m_pts.i + ptsdrw
  1164.                   end
  1165.                   if goals_for < goals_aga then do
  1166.                      m_won.i = m_won.i + 1
  1167.                      m_pts.i = m_pts.i + ptswin
  1168.                   end
  1169.                   if goals_for > goals_aga then do
  1170.                      m_lost.i= m_lost.i + 1
  1171.                      m_pts.i = m_pts.i + ptslse
  1172.                   end
  1173.                   m_pts.i = m_pts.i + (goals_aga * ptsgls)
  1174.                end
  1175.             end
  1176.          end
  1177.       end
  1178.    end
  1179.    close(datafile)
  1180. end
  1181. else do
  1182.    say
  1183.    say "ERROR :    (Combination)"
  1184.    say
  1185.    say "Unable to open '"league_table || input2_file"'."
  1186.    exit
  1187. end
  1188.  
  1189. if open(outfile,output_file,"w") then do
  1190.    do i=1 to tcount
  1191.       line = teams.i
  1192.       line = insert(" ",line,length(line)+1,30-length(line))
  1193.       mp = right(m_ply.i,3)
  1194.       mw = right(m_won.i,3)
  1195.       md = right(m_drw.i,3)
  1196.       ml = right(m_lost.i,3)
  1197.       mgf = right(m_gof.i,5)
  1198.       mga = right(m_goa.i,5)
  1199.       mpts = right(m_pts.i,7)
  1200.       writech(outfile,line"   "mp" "mw" "md" "ml" "mgf" "mga"  "mpts"      ")
  1201.       itemp=mgf-mga
  1202.       if itemp>0 then
  1203.          itemp=insert("+",itemp,0,1)
  1204.       itemp=right(itemp,4)
  1205.       writeln(outfile,itemp)
  1206.    end
  1207.    close(outfile)
  1208. end
  1209. else do
  1210.    say
  1211.    say "ERROR :    (Combination)"
  1212.    say
  1213.    say "Unable to update the League. Cannot write to '"output_file"'."
  1214.    exit
  1215. end
  1216.  
  1217. address command 'Exec/footsort '
  1218.  
  1219. if open(datafile2,output_file,'r') then do
  1220.    do i=1 to tcount
  1221.       line = readln(datafile2)
  1222.       teams.i  = line
  1223.       teams2.i = line
  1224.    end
  1225.    close(datafile2)
  1226. end
  1227. else do
  1228.    say
  1229.    say "ERROR :    (Combination)"
  1230.    say
  1231.    say "Cannot read '"output_file"'."
  1232.    exit
  1233. end
  1234.  
  1235. ctr = 0
  1236. do while swapctr > 0
  1237.    swapctr=9
  1238.    do i=1 to tcount-1                               /* was 64,4 and 77,4 */
  1239.       swapdone=0
  1240.       j = i + 1
  1241.       if strip(substr(teams.i,64,7)) = strip(substr(teams.j,64,7)) then do
  1242.          goaldiffa = strip(substr(teams.i,77,5))
  1243.          goaldiffb = strip(substr(teams.j,77,5))
  1244.          if goaldiffa < goaldiffb then do
  1245.             teams.i = teams2.j
  1246.             teams.j = teams2.i
  1247.             teams2.i= teams.i
  1248.             teams2.j= teams.j
  1249.             swapdone= 1
  1250.             ctr = ctr + 1
  1251.          end
  1252.       end
  1253.       if swapdone = 1 then
  1254.          break
  1255.    end
  1256.    if ctr = 0 then
  1257.       swapctr = 0
  1258.    else
  1259.       ctr = 0
  1260. end
  1261.  
  1262. file_string = "RAM:"league_stuff".tab"
  1263. if output_dr ~= "NONE" then
  1264.    file_string = output_dr"/"league_stuff".tab"
  1265.  
  1266. if open(datafile2,file_string,'w') then do
  1267.    do i=1 to tcount
  1268.       if strip(substr(teams.i,76,5)) = 0 then teams.i=overlay("",teams.i,76,5," ")
  1269.       writeln(datafile2,teams.i)
  1270.    end
  1271.    close(datafile2)
  1272. end
  1273. else do
  1274.    say
  1275.    say "ERROR :    (Combination)"
  1276.    say
  1277.    say "Cannot write to '"file_string"'."
  1278.    exit
  1279. end
  1280.  
  1281. return
  1282.  
  1283. /* Routine ----------------------------------------------------------- */
  1284.  
  1285. format_perf:
  1286. ARG fstrg,counter
  1287.  
  1288. ptemp = ''
  1289. ii = 1
  1290. ji = 1
  1291. do while ii <= counter
  1292.    ptemp = insert(substr(fstrg,ji,1),ptemp,ii,1)
  1293.    ii = ii + 1
  1294.    ji = ji + 1
  1295.    if ii < counter then do
  1296.       ptemp = insert(".",ptemp,ii,1)
  1297.       ii = ii + 1
  1298.    end
  1299. end
  1300. ptemp = strip(ptemp)
  1301. return
  1302.  
  1303. /*******************************************************************************/