ValleyFlyer/main.rs
1// -!- rust -!- **************************************************************
2//
3// System :
4// Module :
5// Object Name : $RCSfile$
6// Revision : $Revision$
7// Date : $Date$
8// Author : $Author$
9// Created By : Robert Heller
10// Created : 2025-10-14 16:15:25
11// Last Modified : <251015.2051>
12//
13// Description
14//
15// Notes
16//
17// History
18//
19//****************************************************************************
20// Copyright (C) 2025 Robert Heller D/B/A Deepwoods Software
21// 51 Locke Hill Road
22// Wendell, MA 01379-9728
23//
24// This program is free software; you can redistribute it and/or modify
25// it under the terms of the GNU General Public License as published by
26// the Free Software Foundation; either version 2 of the License, or
27// (at your option) any later version.
28//
29// This program is distributed in the hope that it will be useful,
30// but WITHOUT ANY WARRANTY; without even the implied warranty of
31// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32// GNU General Public License for more details.
33//
34// You should have received a copy of the GNU General Public License
35// along with this program; if not, write to the Free Software
36// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37//
38//
39//****************************************************************************
40
41#![doc = include_str!("README.md")]
42
43use time_table::TimeTableSystem;
44
45/// Insert the stations from Greenfield, MA to Springfield, MA. The miles
46/// are guesses assuming an average speed of 60 MPH and were picked to
47/// create a time table that exactly matches the Amtrak's real schedule.
48fn InsertStations(time_table: &mut TimeTableSystem) {
49 time_table.AddStation(String::from("Greenfield, MA"),0.0);
50 time_table.AddStation(String::from("Northampton, MA"),25.0);
51 time_table.AddStation(String::from("Holyoke, MA"),15.0+25.0);
52 time_table.AddStation(String::from("Springfield, MA"),28.0+15.0+25.0);
53}
54
55/// Insert the southbound (forward) trains. There are two of them daily.
56fn InsertSouthboundTrains(time_table: &mut TimeTableSystem) {
57 time_table.AddTrain(String::from("Valley Flyer"),String::from("479"),60,1,
58 18*60+5,0,3).expect("Failed to insert 479");
59 time_table.AddTrain(String::from("Valley Flyer"),String::from("425"),60,1,
60 6*60+5,0,3).expect("Failed to insert 425");
61}
62/// Insert the northbound (backward) trains. There are two of them.
63fn InsertNorthboundTrains(time_table: &mut TimeTableSystem) {
64 time_table.AddTrain(String::from("Valley Flyer"),String::from("494"),60,1,
65 21*60+25,3,0).expect("Failed to insert 494");
66 time_table.AddTrain(String::from("Valley Flyer"),String::from("486"),60,1,
67 15*60+15,3,0).expect("Failed to insert 486");
68}
69
70
71/// Main program. Constrict the TimeTableSystem structure, Insert the
72/// stations, then insert the trains and then set the one print option.
73/// Then create the time table LaTeX file.
74fn main() {
75 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
76 1440,15);
77 InsertStations(&mut valley_flyer);
78 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
79 InsertSouthboundTrains(&mut valley_flyer);
80 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
81 InsertNorthboundTrains(&mut valley_flyer);
82 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
83 valley_flyer.SetPrintOption("DirectionName","Southbound");
84 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
85 .expect("Failed to create time table LaTeX file");
86}