/* Mode=Run */ /* *********************************************************************** UPDATE SCHEDULE FILE PROGRAM FOR FOOTBALL REXX SUITE ---------------------------------------------------- Copyright Mark Naughton 1998 Version Date History -------------------------------------------------------------------------- 1.0 011098 Created. Found problem where the updates are not successfully made - fixed. Updated messages. 1.1 050599 Added code to check the schedule file to see if it contains the right number of matches for the number of teams playing a specified number of times. Added support for playing an odd number of times and for schedules for teams playing more than twice. 250899 Added error msg for file check. 050999 Converted to use locale. Some error messages, before reading the locale, will still be in English. Converted to use a global date format file. 190999 Changed schedule directory. ************************************************************************** Procedure --------- 1. Check files exist. Get schedule definition filename from '.df' file. 2. Read specified schedule definition file. Check schedule contains the right number of matches before proceeding. 3. Read schedules and store dates/weeks. 4. Give error if the number of teams does not equal the number of lines in the schedule file. 5. Write the dates/weeks to a file then use an external program to sort them, writing back to the file. 6. Read dates into array and delete file. 7. Format dates array with season start date. 8. Format and write '.sf' files. 9. Read all data from Learn (without '*') into an array. Close file. 10.Open Schedule file and read into an array. Close file. 11.Update Schedule array with data from Learn but only if a match hasn't been played. 12.Write to Schedule file. Close file. Exit. ************************************************************************** */ PARSE ARG league_file version = 1 league_file = "Data/" || strip(league_file) input_file = '.df' input2_file = '.schd' input3_file = '.sflearn' output_file = '.sf' title = '*LEAGUE_NAME=' autosched = "*AUTOSCHD=" playother = '*PLAY_OTHER=' teams. = '???' dateweeks. = '???' tdateweeks. = '???' schedules2. = '???' schedules4. = '???' schedules6. = '???' schedules8. = '???' schedules0. = '???' selines. = '???' sdlines. = '???' autos = 0 tcount = 0 ttc = 0 separator = '*' not_played = '__ __' refdays = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" /* used for word positions */ if open(datafile,"Data/Football.locale",'r') then do line = readln(datafile) locdir = strip(line) close(datafile) end else do say say "ERROR : (UpdateScheduleScores)" say say "Cannot read 'Data/Football.locale' for the locale settings." exit end dfordir = locdir"Football.locale_data" locdir = locdir"User/UpdateScheduleScores.data" if open(datafile,"ENV:FootballRXPath",'r') then do line = readln(datafile) rxdir = strip(line) close(datafile) end else rxdir = "SYS:Rexxc/" if exists(locdir) > 0 then do address command rxdir'rx 'locdir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end else do say say "ERROR : (UpdateScheduleScores)" say say "Cannot find '"locdir"' to read locale settings." exit end if exists(dfordir) > 0 then do address command rxdir'rx 'dfordir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end else do say say "ERROR : (UpdateScheduleScores)" say say "Cannot find '"dfordir"' to read date locale settings." exit end if exists(league_file || input_file) = 0 then do say say uss_error say say fl_canfd"'"league_file || input_file"'." exit end tcount = 0 if open(datafile,league_file || input_file,'r') then do do while ~eof(datafile) line = readln(datafile) line = strip(line) if pos(separator,line) > 0 then do if pos(autosched,line) > 0 then do autofile = delstr(line,1,10) autos = 1 end if pos(title,line) > 0 then do parse var line "*LEAGUE_NAME=" league_title league_title = strip(league_title) end if pos(playother,line) > 0 then playo = delstr(line,1,12) end if pos(separator,line) = 0 & line ~="" then do tcount = tcount + 1 teams.tcount = line end end close(datafile) end else do say say uss_error say say fl_canop"'"league_file || input_file"'"fl_foread exit end /* Automatic Schedule creation */ if autos = 1 then do if exists("Data/Schedules/"autofile||input2_file) = 0 then do say say uss_error say say fl_canfd"'Data/Schedules/"autofile||input2_file"'." exit end ct = 0 sct2= 0 sct4= 0 sct6= 0 sct8= 0 sct0= 0 weeks = 0 dates = 0 sch = 1 if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do mkct = ((tcount - 1) * playo) * (tcount/2) kmct = 0 do while ~eof(datafile) line = readln(datafile) if line ~= '' & pos(separator,line) = 0 then do counter = words(line) do i=1 to counter if word(line,i) ~= 0 then kmct = kmct + 1 end end end close(datafile) end else do say say uss_error say say fl_canfd"'Data/Schedules/"autofile||input2_file"'"fl_foread say say say uss_t6", '"league_file || input_file"' "uss_t7 exit end if mkct ~= kmct then do say say uss_error say say uss_t8" 'Data/Schedules/"autofile||input2_file"'" say uss_t9" "tcount" "uss_t10 say playo" "uss_t11" "kmct" "uss_t12" "mkct" "uss_t13 say uss_t14 say uss_t15 exit end if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do do while ~eof(datafile) line = readln(datafile) if pos("*WEEKS",line) then do weeks=1 end if pos("*DATES=",line) then do startdate=substr(line,8,8) dates = 1 end if pos("*NEXT",line) > 0 then sch = sch + 1 if line ~= '' & pos(separator,line) = 0 then do if sch = 1 then do sct2 = sct2 + 1 schedules2.sct2 = line end if sch = 2 then do sct4 = sct4 + 1 schedules4.sct4 = line end if sch = 3 then do sct6 = sct6 + 1 schedules6.sct6 = line end if sch = 4 then do sct8 = sct8 + 1 schedules8.sct8 = line end if sch = 5 then do sct0 = sct0 + 1 schedules0.sct0 = line end counter = words(line) do i=1 to counter sdate = word(line,i) if sdate = 0 then iterate if ct = 0 then do ct = ct + 1 dateweeks.ct = sdate end else do ij = 0 do j=1 to ct if sdate = dateweeks.j then do ij = 1 leave end end if ij = 0 then do ct = ct + 1 dateweeks.ct = sdate end end end end end close(datafile) end else do say say uss_error say say fl_canfd"'Data/Schedules/"autofile||input2_file"'"fl_foread exit end sct = (sct2 + sct4 + sct6 + sct8 + sct0) / sch if counter ~= sct then do say say uss_error say say uss_t16" "sct" "uss_t17 say uss_t18" "tcount" "uss_t19 say say uss_t20 say say uss_t21" "league_file||input_file say uss_t22" Data/Schedules/"autofile||input2_file say exit end if open(datafile2,"RAM:schd.temp",'w') then do do j=1 to ct writeln(datafile2,dateweeks.j) end close(datafile2) end else do say say uss_error say say fl_canctem exit end if weeks = 1 then address command 'sort RAM:schd.temp RAM:schd.temp' if dates = 1 then address command 'Exec/SortWkDts' if open(datafile2,"RAM:schd.temp",'r') then do do j=1 to ct dateweeks.j = readln(datafile2) end close(datafile2) end else do say say uss_error say say fl_canrtem exit end address command 'delete >NIL: RAM:schd.temp' if dates = 1 then do do j=1 to ct if dateweeks.j = startdate then do do i=1 to j-1 tdateweeks.i = dateweeks.i end k = 1 do i=j to ct dateweeks.k = dateweeks.i k = k + 1 end do i=1 to j-1 dateweeks.k = tdateweeks.i k = k + 1 end leave end end end if open(outfile,league_file || output_file,"w") then do writeln(outfile,"*") writeln(outfile,"**" league_title) writeln(outfile,"*") writeln(outfile,"*") matches = 0 do i=1 to ct if weeks = 1 then writeln(outfile,"*Week: "dateweeks.i) if dates = 1 then do mnth = substr(dateweeks.i,3,2) ndate= substr(dateweeks.i,5,4)||mnth||substr(dateweeks.i,1,2) weekd= date('w',ndate,'s') do kw=1 to 7 if weekd = word(refdays,kw) then do weekd = word(days,kw) leave end end parse var date_format "day" sp1 "number" sp2 "month" sp3 "year" . /* DATE */ writeln(outfile,"*Date: "weekd||sp1||substr(dateweeks.i,1,2)||sp2||word(months,mnth)||sp3||substr(dateweeks.i,5,4)) end writeln(outfile,"*") do k=1 to counter do j=1 to counter do l=1 to sch if l=1 then sdate = word(schedules2.k,j) if l=2 then sdate = word(schedules4.k,j) if l=3 then sdate = word(schedules6.k,j) if l=4 then sdate = word(schedules8.k,j) if l=5 then sdate = word(schedules0.k,j) if dateweeks.i = sdate then do writech(outfile,left(teams.k,30)) writeln(outfile," __ __ " teams.j) matches = matches + 1 leave end end end end writeln(outfile,"*") end writeln(outfile,"*") close(outfile) end else do say say uss_error say say fl_canwrit"'"league_file || output_file"'." exit end end else do say say uss_error say say uss_t6", "league_file||input_file", "uss_t25 say uss_t26 say uss_t27 say exit end secount = 0 if open(datafile,league_file||input3_file,'r') then do do while ~eof(datafile) line = readln(datafile) line = strip(line) if pos(separator,line) = 0 & line ~= "" then do secount = secount + 1 selines.secount = line end end close(datafile) end else do say say uss_error say say fl_canop"'"league_file||input3_file"'"fl_foread exit end sdcount = 0 if open(datafile3,league_file || output_file,'r') then do do while ~eof(datafile3) line = readln(datafile3) line = strip(line) if line ~= "" then do sdcount = sdcount + 1 sdlines.sdcount = line end end close(datafile3) end else do say say uss_error say say fl_canop"'"league_file || output_file"'"fl_foread exit end i = 0 done = 0 do i=1 to secount shome = strip(substr(selines.i,1,30)) saway = strip(substr(selines.i,41,30)) do j=1 to sdcount home = strip(substr(sdlines.j,1,30)) away = strip(substr(sdlines.j,41,30)) if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do sdlines.j = selines.i leave end end end /* do j=1 to sdcount shome = strip(substr(sdlines.j,1,30)) saway = strip(substr(sdlines.j,41,30)) do i=1 to secount home = strip(substr(selines.i,1,30)) away = strip(substr(selines.i,41,30)) if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do sdlines.j = selines.i k = k + 1 leave end end if k = secount then leave end */ if open(datafile3,league_file || output_file,'w') then do do j=1 to sdcount writeln(datafile3,sdlines.j) end close(datafile3) end else do say say uss_error say say fl_canop"'"league_file || output_file"'"fl_forwrit exit end say say uss_t28 say say uss_t29 say "'Data/Schedules/"autofile||input2_file"' "uss_t30" '"league_file||input3_file"'" say uss_t31" '"league_file||output_file"'." say exit