           db.close()
   ).parse()
 
+
+################################################################################
+#
+# main
+#
+################################################################################
+
 main = ->
   if program.railreference
     console.log "loading rail reference form #{program.railreference}"
     readRailReferenceCsv(program.railreference)
-  else if program.schedule
-    console.log "loading schedule from #{program.schedule}"
-    fs.readFile program.schedule, (error, data) ->
-      if error
-        throw error
-      importSchedule(data)
+  else if program.schedules
+    for schedule in program.schedules
+      console.log "loading schedule from #{schedule}"
+      fs.readFile schedule, (error, data) ->
+        if error
+          throw error
+        importSchedule(data)
   else
-    getSchedule (error, data) ->
-      if error
-        console.log error
-      fs.writeFile '/tmp/schedule.txt', data, (error) ->
-        if error
-          console.log error
-        else
-          console.log 'Saved'
+    for toc_code in config.datafeed.schedule_toc_codes
+      do (toc_code) ->
+        saveSchedule = (error, data) ->
+          if error
+            console.log error
+          path = "/tmp/schedule-#{toc_code}.txt"
+          fs.writeFile path, data, (error) ->
+            if error
+              console.log error
+            else
+              console.log "Saved to #{path}"
+        getSchedule(saveSchedule, toc_code)
 
 if require.main == module
   main()

      data.latitude = latLon.latitude
      data.longitude = latLon.longitude
      data._id = data.TiplocCode
      console.log(data)
      rows.push(data)
    ).on('end', ->
      getMongoDb (db) ->

  for char in daysRunString
    char == '1'

getScheduleCompositeUID = (jsonScheduleV1) ->
  cifTrainUid = jsonScheduleV1['CIF_train_uid']
  scheduleStartDate = jsonScheduleV1['schedule_start_date']
  cifStopIndicator = jsonScheduleV1['CIF_stp_indicator']
  return "#{cifTrainUid}#{scheduleStartDate}#{cifStopIndicator}"


importSchedule = (scheduleData) ->
  entries = []
  scheduleEntries = []
