#!/usr/bin/perl

# This script takes the user data input and generates two plots.  The first plot shows
# the times for each match and the judging.   The second plot shows which teams play
# which and is used to make sure that no team plays too often or little.
# The text output has the team pairings, schedule, and a list of which teams are
# played by each team.  The script also creates a tab delimited file with the competition
# and judging schedule that can be read directly into the scoring spread sheet.  The team
# names are then pulled into the schedule and it is ready for formatting, printing, and then
# handing out to the teams.  The file name is MatchAndJudgeTimes.tab.
# 
# We started with pairings developed by Tim Burks and then worked with them until
# we had judging times that were not too close to competition matches and so that
# they do not compete in subsequent matches.
#
# Use this script by simply running it on a unix machine or cygwin Windows machine
# and ploting the resulting MatchTimes.gnu file with gnuplot.  Gnuplot sends two
# plots to the default x11 screen.  It also generates MatchTimes.ps and MatchPairings.ps.
# These can be converted with Acrobat to pdf's.  This conversion can also be done
# under cygwin with the "convert" command with
#   convert MatchTimes.ps MatchTimes.pdf
#   convert MatchPairings.ps MatchPairings.pdf
#
# The times for the Judging and team matches are not connected.  They must work
# in concert with eachother at the event.  The only way I have figured out how
# to do this is to make a set of plots and then figure out where things should go
# and then update the lists below by hand.
# 
# The script works for any number of matchs, teams, and rounds.
#
#
# Michael and Wyn Schuh
# Los Altos, CA
# Michael@Boardsailor.com
#
# $Id: MatchTimes16opt.perl,v 1.3 2011/11/04 05:24:31 Michael Exp Michael $
#
# $Log: MatchTimes16opt.perl,v $
# Revision 1.3  2011/11/04 05:24:31  Michael
# This is the version I used to make the V1.2 schedule that I sent to the Board of Directors.
#
# Revision 1.2  2011/11/04 04:14:50  Michael
# Works but two teams are on the same table twice.
#
# Revision 1.1  2011/11/03 05:48:13  Michael
# Initial revision
#
# Revision 1.5  2007/11/19 01:26:50  Michael
# Last version before sending comments to Tom Sartor.  He came up with the schedule
# and asked for our input on it.
#
# Revision 1.4  2007/11/19 00:54:37  Michael
# This version works and has Tom's times in it.  We suggest swapping teams 1-8 run times
# in round 2 with teams 18-26 because teams 1-8 will be running right after judging
# by the current schedule.
#
# Revision 1.3  2007/11/19 00:30:28  Michael
# Has everything.  Before deleting all but 26 team set.
#
# Revision 1.2  2007/11/18 23:31:04  Michael
# Have first set of judging and all matches in.
#
# Revision 1.1  2007/11/18 23:26:09  Michael
# Initial revision
#
# Revision 1.2  2006/11/10 23:25:51  Michael
# This is the first good version that I sent Tim.  Michael, Travis, and Wyn
# worked on it.
#
# Revision 1.1  2006/11/10 01:45:29  Michael
# Initial revision
#
# Revision 1.5  2006/11/09 22:13:45  Michael
# Working on finding a new set.  Before changing team pairs for match 2 to have 3 play 4.
#
# Revision 1.4  2006/11/03 06:10:51  Michael
# First workable 13 team schedule.
#
# Revision 1.3  2006/11/03 04:30:49  Michael
# First cut at scheduling 13 teams.
#
# Revision 1.2  2006/10/31 05:45:52  Michael
# First cut at pairings.
#
#

#
# Start of user data input.
#

$StartTime = 675;  # Start time in minutes.  60 is 1:00 PM.

#   Round     a   b   c   d   e
@Break   = ( 20,  14,  39, 3 );  # Break time before each round
@Break   = ( 20,  14,  10, 3, 30 );  # Break time before each round - 26
@Break   = ( 20,  10,  10, 0, 30 );  # Break time before each round - 26 Opt 
@Break   = ( 20,  10,  10, 0, 30 );  # Break time before each round - 26 Opt 
@Break   = ( 135,  10, 15, 15, 30, 0, 30 );  # Break time before each round - 26 Opt 

$JudgingTimeSlotLength = 15;  # This is the amount of time given to each judging session.
$FirstBreak = $Break[0] +   0;  # Used to have the judging start five minutes after the first competition match starts.
$FirstBreak = $Break[0] - 135;  # Used to have the judging start five minutes after the first competition match starts.
@Cycle   = (  4,  4,  4,  4, 4 );  # 26 Teams # Time between matches in each round
@Cycle   = (  5,  5,  5,  5, 5 );  # 16 Teams # Time between matches in each round
# 16 Teams with four Judging periods
#                      Break  J1  J2   J3 P
@Judgings = ( [ $FirstBreak,  11, 12, 13, ],  # First Set   PRoject, RoBot, Core Values
              [           0,  12, 13, 11, ],  #          
              [           0,  13, 11, 12, ],  #         
              [           0,  14, 15, 16, ],  #         
              [           0,  15, 16, 14, ],  #         
              [           0,  16, 14, 15, ],  #         
              [          45,   1,  3,  4  ],  # Second Set
              [           0,   2,  4,  1  ],
              [           0,   3,  1,  2  ],
              [           0,   4,  2,  3  ],
              [          15,   5,  7,  8 ],  # Third Set   PR
              [           0,   6,  8,  5 ],
              [           0,   7,  5,  6 ],
              [           0,   8,  6,  7 ] );

@Judgings = ( [ $FirstBreak,  11, 12, 13, ],  # First Set   PRoject, RoBot, Core Values
              [           0,  12, 13, 11, ],  #          
              [           0,  13, 11, 12, ],  #         
              [           0,  14, 15, 16, ],  #         
              [           0,  15, 16, 14, ],  #         
              [           0,  16, 14, 15, ],  #         
              [          45,   1,  3,  4  ],  # Second Set
              [           0,   2,  4,  1  ],
              [           0,   3,  1,  2  ],
              [           0,   4,  2,  3  ],
              [          15,   5,  6,  7 ],  # Third Set
              [           0,   6,  7,  5 ],
              [           0,   7,  5,  6 ],
              [          15,   8,  9, 10 ],  # Fourth Set
              [           0,   9, 10,  8 ], 
              [           0,  10,  8,  9 ] );

@Matchings = (
[                   # Round a, # Judging 1-8
      [  5,  6 ],
      [  7,  8 ],
      [  9, 10 ],
      [ 11, 12 ],
      [ 13, 14 ],
      [ 15, 16 ],
 ], [               # Round b, # Judging 9-16
      [  7,  5 ],
      [  8,  6 ],
      [ 11,  9 ],
      [ 12, 10 ],
 ], [               # Round b, # Judging 9-16
      [ 15, 13 ],
      [  1,  2 ],
      [  3,  4 ],
      [ 14,  9 ],
      [  8, 16 ],
      [ 10, 11 ],
 ], [               # Round c, # Judging 17-26
      [  4,  2 ],
      [  3,  1 ],
      [ 14, 15 ],
      [ 16, 13 ],
      [  5, 12 ],
      [  6,  7 ],
      [  4,  1 ],
      [  2,  3 ],
# ], [               # Round d
#      [  3,  7 ],
# ], [               # Round e
#      [ 2, 16 ],
 ]
     );

$NumberOfTeams = 0;  # Number of the highest team.  This is assumed to be the number of teams.
foreach $i ( 0 .. $#Matchings ) {
  push @Matches, $#{$Matchings[$i]} + 1;   # Number of matches in each round.
  foreach $match ( 0 .. $#{$Matchings[$i]} ) {
     $NumberOfTeams = $Matchings[$i][$match][0] if $Matchings[$i][$match][0] > $NumberOfTeams; 
     $NumberOfTeams = $Matchings[$i][$match][1] if $Matchings[$i][$match][1] > $NumberOfTeams; 
  }
} 

if ( $NumberOfTeams != ($#Judgings+1) ) {  # Check to make sure we have the right number of Judgings.
   printf "\nERROR:  The number of teams, $NumberOfTeams, does not equal the number of Judgings, %d\n\n",$#Judgings+1;
   # exit(-5);
}

#
# End of user data input.
#

#  t1 t2     # t1 and t2 are filled with the number of times at each table.
for ( 0 .. $NumberOfTeams ) {
    push @TableCountForEachTeam , [0, 0];   # Used to count the number of times a team plays at table 1 and table 2.
}
foreach $i ( 0 .. $NumberOfTeams ) {
  foreach $j ( 0 .. $NumberOfTeams ) {
    $PairingsTable[$i][$j] = 0;   # 2D Used to keep track of the number of times a team plays each other team.
  }
}

$time = $StartTime;

GP_CommandFile_HeaderFill();   # Write the first part of the plot command file.

push @JudgeTimesAndTeamsTabs, "Competition Round Schedule\n";           # Build the contents for the MatchAndJudgeTimes.tab file.
push @JudgeTimesAndTeamsTabs, "Round\tMatch\tTime\tTable 1\tTable 2\n"; 

@RoundNames = (qw(A B C D E)); # Used to label matches with letters.

# Make the plot command lines and data files for showing when each team competes and for the pairings chart.
foreach $RoundNumber ( 0 .. $#Matches ) {
  open(GP,">MatchTimes$RoundNumber.data");
  open(GPP,">MatchPairings$RoundNumber.data");
  $RoundMatches = $Matches[$RoundNumber];
  $time += $Break[$RoundNumber];
  foreach $Match ( 1 .. $RoundMatches ) { 
     $timeEnd = $time + $Cycle[$RoundNumber];
     $GPtimeStart = sprintf "%d:%2.2d",int($time/60), $time%60;        # Set the match start and end times.
     $GPtimeEnd   = int($timeEnd/60) . ":" . $timeEnd%60;
     $GPtimeCent  = int(($time+$timeEnd)/120) . ":" . (($time+$timeEnd)/2)%60;
     $Table1team = $Matchings[$RoundNumber][$Match-1][0];     # Get the team names.
     $Table2team = $Matchings[$RoundNumber][$Match-1][1];
     $TableCountForEachTeam[$Table1team][0] += 1;             # Keep track of how many times the
     $TableCountForEachTeam[$Table2team][1] += 1;             # teams play at each table.
     push @MatchTimesAndTeams, sprintf "  $RoundNames[$RoundNumber] %6d       $GPtimeStart  %6d  %6d\n",$Match,$Table1team,$Table2team;
     push @JudgeTimesAndTeamsTabs, sprintf "$RoundNames[$RoundNumber]\t%d\t$GPtimeStart\t=Team%d\t=Team%d\n",$Match,$Table1team,$Table2team;
     push @{ $TableCountForEachTeam[$Table1team] }, $Table2team;   # Add the competing team to the list.
     push @{ $TableCountForEachTeam[$Table2team] }, $Table1team;   # Add the competing team to the list.

     printf GP "$GPtimeStart   %5.1f\n",  $Table1team - .4;   # Box for competition schedule.
     printf GP "$GPtimeEnd     %5.1f\n",  $Table1team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n",  $Table1team + .4; 
     printf GP "$GPtimeStart   %5.1f\n",  $Table1team + .4; 
     printf GP "$GPtimeStart   %5.1f\n\n",$Table1team - .4; 

     printf GP "$GPtimeStart   %5.1f\n",  $Table2team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n",  $Table2team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n",  $Table2team + .4; 
     printf GP "$GPtimeStart   %5.1f\n",  $Table2team + .4; 
     printf GP "$GPtimeStart   %5.1f\n\n",$Table2team - .4; 

     $textColor = $RoundNumber+1;
     $textColor = 4 if $RoundNumber==4;
     printf GPC "set label \"a1\" at \"$GPtimeCent\", $Table1team center tc lt %d\n",$textColor if $Match%2;
     printf GPC "set label \"a2\" at \"$GPtimeCent\", $Table2team center tc lt %d\n",$textColor if $Match%2;
     printf GPC "set label \"b1\" at \"$GPtimeCent\", $Table1team center tc lt %d\n",$textColor if $Match%2 == 0;
     printf GPC "set label \"b2\" at \"$GPtimeCent\", $Table2team center tc lt %d\n",$textColor if $Match%2 == 0;

     printf GPP "%5.1f   %5.1f\n",   $Table1team-.5, $Table2team-.5;     # Box for pairings chart
     printf GPP "%5.1f   %5.1f\n",   $Table1team-.5, $Table2team+.5; 
     printf GPP "%5.1f   %5.1f\n",   $Table1team+.5, $Table2team+.5; 
     printf GPP "%5.1f   %5.1f\n",   $Table1team+.5, $Table2team-.5; 
     printf GPP "%5.1f   %5.1f\n\n", $Table1team-.5, $Table2team-.5; 

     printf GPP "%5.1f   %5.1f\n",   $Table2team-.5, $Table1team-.5;     # Box for pairings chart
     printf GPP "%5.1f   %5.1f\n",   $Table2team-.5, $Table1team+.5; 
     printf GPP "%5.1f   %5.1f\n",   $Table2team+.5, $Table1team+.5; 
     printf GPP "%5.1f   %5.1f\n",   $Table2team+.5, $Table1team-.5; 
     printf GPP "%5.1f   %5.1f\n\n", $Table2team-.5, $Table1team-.5; 

     $PairingsTable[$Table1team][$Table2team] += 1;  # Increment the number of times each team is paired with the other.
     $PairingsTable[$Table2team][$Table1team] += 1;
     $ErrorString = ($PairingsTable[$Table1team][$Table2team] > 1) ? " Error" : "";  # Check to see if they have more than 1 pairing.
     $TextColor = ($PairingsTable[$Table1team][$Table2team] > 1) ? 0 : $RoundNumber+1;  # Use black text if they have more than 1 pairing. 
     push @GPC, sprintf "set label \"$RoundNames[$RoundNumber]%d$ErrorString\" at $Table1team, $Table2team center tc lt %d\n",$Match,$TextColor;
     push @GPC, sprintf "set label \"$RoundNames[$RoundNumber]%d$ErrorString\" at $Table2team, $Table1team center tc lt %d\n",$Match,$TextColor;

     $time = $timeEnd
  }
  close(GP);
  close(GPP);
}

push @JudgeTimesAndTeamsTabs, " \n", " \n", "\tJudging Schedule\n"; 
push @JudgeTimesAndTeamsTabs, "\tSession\tTime\tRobot Design Go to Judging Room\tTeam Categories Go to Judging Room\tPresentation Go to Judging Room\tProgramming Go to your Pit Table\n"; 
$time = $StartTime;
open(GP,">MatchJudgeTimes.data");
foreach $JudgingRoundNumber ( 0 .. $#Judgings ) {
     $time += $Judgings[$JudgingRoundNumber][0]; # Add in the time for the break

     $timeEnd = $time + $JudgingTimeSlotLength;
     $GPtimeStart = sprintf "%d:%2.2d",int($time/60), $time%60;        # Set the Judging start and end times.
     $GPtimeEnd   = int($timeEnd/60) . ":" . $timeEnd%60;
     $GPtimeCent  = int(($time+$timeEnd)/120) . ":" . (($time+$timeEnd)/2)%60;
     $Judge1team = $Judgings[$JudgingRoundNumber][1];
     $Judge2team = $Judgings[$JudgingRoundNumber][2];
     $Judge3team = $Judgings[$JudgingRoundNumber][3];
     $Judge4team = $Judgings[$JudgingRoundNumber][4];
     $Judge5team = $Judgings[$JudgingRoundNumber][5];
     $Judge6team = $Judgings[$JudgingRoundNumber][6];
     $Judge7team = $Judgings[$JudgingRoundNumber][7];
     $Judge8team = $Judgings[$JudgingRoundNumber][8];
     #push @JudgeTimesAndTeams, sprintf "%4d      $GPtimeStart %8d %10d %10d %10d %10d %10d %10d %10d\n",$JudgingRoundNumber+1,$Judge1team,$Judge2team,$Judge3team,$Judge4team,$Judge5team,$Judge6team,$Judge7team,$Judge8team;
     push @JudgeTimesAndTeams, sprintf "%4d      $GPtimeStart %8d %10d %10d\n",$JudgingRoundNumber+1,$Judge1team,$Judge2team,$Judge3team;
     push @JudgeTimesAndTeamsTabs, sprintf "\t%d\t$GPtimeStart\t=Team%d\t=Team%d\t=Team%d\t=Team%d\t=Team%d\t=Team%d\t=Team%d\t=Team%d\n",$JudgingRoundNumber+1,$Judge1team,$Judge2team,$Judge3team,$Judge4team,$Judge5team,$Judge6team,$Judge7team,$Judge8team;

     printf GP "$GPtimeStart   %5.1f\n", $Judge1team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge1team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge1team + .4; 
     printf GP "$GPtimeStart   %5.1f\n", $Judge1team + .4; 
     printf GP "$GPtimeStart   %5.1f\n\n", $Judge1team - .4; 

     printf GP "$GPtimeStart   %5.1f\n", $Judge2team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge2team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge2team + .4; 
     printf GP "$GPtimeStart   %5.1f\n", $Judge2team + .4; 
     printf GP "$GPtimeStart   %5.1f\n\n", $Judge2team - .4; 

     printf GP "$GPtimeStart   %5.1f\n", $Judge3team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge3team - .4; 
     printf GP "$GPtimeEnd     %5.1f\n", $Judge3team + .4; 
     printf GP "$GPtimeStart   %5.1f\n", $Judge3team + .4; 
     printf GP "$GPtimeStart   %5.1f\n\n", $Judge3team - .4; 

#     printf GP "$GPtimeStart   %5.1f\n", $Judge4team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge4team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge4team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n", $Judge4team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n\n", $Judge4team - .4; 
#
#     printf GP "$GPtimeStart   %5.1f\n", $Judge5team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge5team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge5team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n", $Judge5team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n\n", $Judge5team - .4; 
#
#     printf GP "$GPtimeStart   %5.1f\n", $Judge6team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge6team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge6team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n", $Judge6team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n\n", $Judge6team - .4; 
#
#     printf GP "$GPtimeStart   %5.1f\n", $Judge7team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge7team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge7team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n", $Judge7team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n\n", $Judge7team - .4; 
#
#     printf GP "$GPtimeStart   %5.1f\n", $Judge8team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge8team - .4; 
#     printf GP "$GPtimeEnd     %5.1f\n", $Judge8team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n", $Judge8team + .4; 
#     printf GP "$GPtimeStart   %5.1f\n\n", $Judge8team - .4; 

     printf GPC "set label \"PR\" at \"$GPtimeCent\", $Judge1team center tc lt 7\n";
     printf GPC "set label \"RB\" at \"$GPtimeCent\", $Judge2team center tc lt 7\n";
     printf GPC "set label \"CV\" at \"$GPtimeCent\", $Judge3team center tc lt 7\n";
#     printf GPC "set label \"Team\" at \"$GPtimeCent\", $Judge4team center tc lt 7\n";
#     printf GPC "set label \"Pres\" at \"$GPtimeCent\", $Judge5team center tc lt 4\n";
#     printf GPC "set label \"Des\"  at \"$GPtimeCent\", $Judge6team center tc lt 4\n";
#     printf GPC "set label \"Prog\" at \"$GPtimeCent\", $Judge7team center tc lt 4\n";
#     printf GPC "set label \"Team\" at \"$GPtimeCent\", $Judge8team center tc lt 4\n";

     $time = $timeEnd
}
close (GP);

GP_CommandFile_TrailerFill();

print "Check the list below to make sure that each team competes on each table half the time.\n";
print "The Table_1 and Table_2 columns contain the number of time they compete on the two tables.\n\n";
print "  Team#   Table_1  Table_2 | Teams Competing against this team.\n";
for $i ( 1 .. $NumberOfTeams ) {
    #printf "%5d  %8d  %7d %5d\n",$i,$TableCountForEachTeam[$i][0],$TableCountForEachTeam[$i][1],$#{$TableCountForEachTeam[$i]};
    #printf "%5d  %8d  %7d %5d\n",$i,$TableCountForEachTeam[$i][0],$TableCountForEachTeam[$i][1],$TableCountForEachTeam[$i][2];
    printf "%5d  %8d  %7d   |",$i,$TableCountForEachTeam[$i][0],$TableCountForEachTeam[$i][1];
    for $j ( 2 .. $#{$TableCountForEachTeam[$i]} ) { printf "%6d",$TableCountForEachTeam[$i][$j]; } print "\n";
}

print "\n\nMatch Start times and team numbers\n";
print "Round  Match  StartTime  Team_1  Team_2\n"; 
print @MatchTimesAndTeams;

print "\n\nJudging Start times and team numbers\n";
print "Round  StartTime  Programing  Robot    Core Values\n"; 
print @JudgeTimesAndTeams;

# Create a tab delimited file for the match and judging schedule.
# Read this file into Microsoft Excel by using the Data/ImportExternalData/ImportData tool.
open(MSE,">MatchAndJudgeTimes.tab");
print MSE  @JudgeTimesAndTeamsTabs;
close(MSE);

# Check to see if teams play each other more than once.
foreach $i ( 0 .. $NumberOfTeams ) {
  foreach $j ( $i .. $NumberOfTeams ) {
    print "\nError: Teams $i and $j play each other more than once.\n"  if $PairingsTable[$i][$j] > 1;
  }
}

# Print out the current date and time.
print "\n"; system ("date");


# End
#
#================================================================================
#================================================================================
#================================================================================
#

sub GP_CommandFile_HeaderFill {
open(GPC,">MatchTimes.gnu");
print GPC '
# Tell gnuplot that the x data is in time format
set xdata time

# Set the time format which will be used for xrange and maybe other things.
set timefmt "%H"

set style data lines

# %R = %H:%M   (hours:minutes)
set format x "%R"
 
set xrange ["0:0":"3:00"]
set autoscale x
set xtic  600  # A tic and label every 10 minutes
set xtic  900  # A tic and label every 15 minutes
set mxtic   3  # This many minor tic segments between the major tics.
';
printf GPC "
set yrange [0:%d] rever
set yti 1,1,$NumberOfTeams
",$NumberOfTeams+1;
print GPC '

set timefmt "%H:%M"
unset label  # Clear any labels that might have been set from a privious loading of this file.
';
}

#
#================================================================================
#================================================================================
#================================================================================
#
sub GP_CommandFile_TrailerFill {
print GPC '
set time
set tit "Match Times"
set xlab "Time"
set ylab "Team Number"
plot "MatchTimes0.data" using 1:2 notit, \
     "MatchTimes1.data" using 1:2 notit, \
     "MatchTimes2.data" using 1:2 notit, \
     "MatchTimes3.data" using 1:2 notit, \
     "MatchJudgeTimes.data"  using 1:2 notit
     #"MatchTimes4.data" using 1:2 notit 4,  \
     # "MatchTimes4.data" using 1:2 notit, 
pause -1 
set term post color solid land 8
set output "MatchTimes.ps"
replot
set output

unset label  # Clear any labels that might have been set from a privious loading of this file.
';

print GPC "@GPC";

print GPC '
set term x11
set xdata
set format x
';
printf GPC "
set xrange [0:%d]
set xti 1,1,$NumberOfTeams
",$NumberOfTeams+1;
print GPC '
set tit "Team Pairings\nErrors are noted by \'Error\' in the pairings label."
set xlab "Team Number"
plot "MatchPairings0.data" using 1:2 notit, \
     "MatchPairings1.data" using 1:2 notit, \
     "MatchPairings2.data" using 1:2 notit, \
     "MatchPairings3.data" using 1:2 notit lt 4
#     "MatchTimes4.data" using 1:2 notit,  \
#     "MatchJudgeTimes.data"  using 1:2 notit
pause -1
set term post color solid
set term post color solid land 8
set output "MatchPairings.ps"
replot;
';
close(GPC);
}
