Index: trunk/src/tmcsim/client/ATMSDriverClient.java
===================================================================
--- trunk/src/tmcsim/client/ATMSDriverClient.java	(revision 109)
+++ trunk/src/tmcsim/client/ATMSDriverClient.java	(revision 112)
@@ -11,4 +11,8 @@
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.InputMismatchException;
 import java.util.LinkedList;
 import java.util.Properties;
@@ -34,5 +38,7 @@
  * to fire update commands at the desired time.
  * Note: Sim Mgr must be running before starting this application.
- *
+ * TODO: We probably want to be able to "override" a command, to force 
+ * clearing an incident.
+
  * @author jdalbey
  */
@@ -42,4 +48,5 @@
     private static final String CONFIG_FILE_NAME = "cad_client_config.properties";
     private final static int ONE_SECOND = 1000;
+    private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
     /**
      * Error logger.
@@ -126,8 +133,4 @@
         // READ THE BATCH FILE OF COMMANDS and put in a queue
         readBatchFile();
-        // Consider special cases:  1) time to fire first command
-        // has already past when application starts.
-        // 2.  Two commands have same fire time specified.
-        // 3.  How to "override" a command, to clear an incident.
         
         // Create a timer that fetches the simulation time every second.
@@ -137,8 +140,17 @@
             {
                 String currentClock = "";
+                Date simClock = new Date();                
+                // Obtain the simulation time from the CAD server
                 try
                 {
                     long simtime = theCoorInt.getCurrentSimulationTime();
                     currentClock = formatInterval(simtime);
+                    try {
+                        simClock = formatter.parse(currentClock);
+                    } catch (ParseException ex) {
+                        Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex);
+                        System.out.println("Invalid simulation clock time found in ATMSDriverClient");
+                        System.exit(-1);
+                    }                    
                     System.out.println("Current clock: " + currentClock);
                 } catch (RemoteException ex)
@@ -146,17 +158,29 @@
                     Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex);
                 }
+                // If we have any events left to process
                 if (!eventQueue.isEmpty())
                 {
-                    // Check the queue of commands to see if the first
-                    // item matches the current time.  IF so, 
+                    // Get the time to launch the next event
+                    String nextEvent = eventQueue.peek();
+                    String eventTimeField = nextEvent.substring(0,8);
+                    Date eventTime = new Date();
+                    try {
+                        eventTime = formatter.parse(eventTimeField);
+                    } catch (ParseException ex) {
+                        Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.WARNING, null, ex);
+                        System.out.println("Unable to parse event time: " + nextEvent + " skipping.");
+                        eventQueue.remove();
+                    }
+                    System.out.println("Next event will be launched at: " + formatter.format(eventTime));
+                    // Check the queue of events to see if the first
+                    // item should be launched.  IF so, 
                     // issue that command and remove it from queue.
-                    String nextEvent = eventQueue.peek();
-                    String eventTime = nextEvent.substring(0,8);
-                    System.out.println("Next event will be launched at: " + eventTime);
-                    if (eventTime.equals(currentClock))
+                    if (eventTime.before(simClock) || eventTime.equals(simClock))
                     {
                         System.out.println("LAUNCHING EVENT at " + nextEvent );
                         // Extract fields from event and prepare them 
                         Scanner lineScan = new Scanner(nextEvent);
+                        try
+                        {
                         lineScan.next(); // skip time field
                         int routeNumber = lineScan.nextInt();
@@ -169,4 +193,10 @@
                         // Remove this event from the queue, we're done with it.
                         eventQueue.remove();
+                        }
+                        catch (InputMismatchException ex)
+                        {
+                            System.out.println("Wrong format data in batch event file: " + nextEvent + " \nskipping.");
+                            eventQueue.remove();
+                        }
                     }
                 }
