#!/bin/bash

# This template generates passenger files for acceptance testing the elevator.
#
# Passengers all enter on floor one in a randomized hall, and exit on floor 2.
# You should update this so that passengers can begin and end in any valid 
# hallway. If you want to add additional parameters (e.g. timing, uppeak 
# bias, etc.) you may do so. Be sure that your usage accurately describes all
# parameters used. 
#
# .Pass files should start with a comment describing the test, including what 
# arguments were used to generate it. 
# Subsequent lines are passenger injections and have the following format:
#
#           Time	Start Floor	Start Hallway	End Floor	End Hallway 

MIN_ARG_NUM=2;

if [ $# -lt $MIN_ARG_NUM ] 
    then 
        #Replace these with actual usage directions
        echo "<USAGE INFO>";
        echo "<EXAMPLE COMMAND LINE CALL>";
else
        PASS_NUM=$1; #Read the arguments into local variables
        OUTFILE=$2;
        
        echo ";Random Generated Pass file. Number of Passengers = $PASS_NUM" > $OUTFILE;
        for ((i = 1; i <= $PASS_NUM; i++));
            do
                n=$(($RANDOM % 2 )); 
                s="$((i * 5))s "; #Passenger insertion time
                s="$s 1 "; #Passenger starts on floor 1...
                case $n in #... in a random hallway
                    0 )
                        s="$s FRONT ";
                        ;;
                    1 )
                        s="$s BACK ";
                        ;;
                esac
                s="$s 2 BACK "; # and ends on floor 2
                echo "$s" >> $OUTFILE
            done
                
fi

