This is a short rust program to count the number of departing and arriving flights per hour in a specific airport.
Use it by entering the airport code (KATL, LEBL etc.) as a parameter to the exe you created with cargo build
Note that you may need to change the path variable to match your Tower3D install folder
Also, some airports use a different name for the schedule file and the actual airport name inside that file. The code handles EDDM and LEBL (which I own). You may need to add others.
use std::{env, process, fs};
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("error: missing airport name");
process::exit(1);
}
let airport_name = &args[1].to_uppercase();
let path = "D:\\Program Files (x86)\\FeelThere\\Tower!3D Pro\\Extensions\\Airfields";
let filename = format!("{}\\{}\\{}_schedule.txt", path, airport_name, airport_name.to_lowercase());
let airport = if airport_name == "EDDM" {
"MUC"
} else if airport_name == "LEBL" {
"BCN"
} else {
&airport_name[1..]
};
let contents = fs::read_to_string(filename)
.expect("error: failed to open file");
let mut departures: [u32; 24] = [0; 24];
let mut arrivals: [u32; 24] = [0; 24];
for line in contents.lines() {
if line.len() == 0 {
continue;
}
if line.len() >= 2 && &line[0..2] == "//" {
continue;
}
let tokens: Vec<&str> = line.split(",").collect();
let origin_ap = tokens[0].trim();
if origin_ap == airport {
let token6 = tokens[6].trim();
let hour: usize = token6[0..2].parse()
.expect("illegal number in dep.hour");
departures[hour] += 1;
} else {
let token5 = tokens[5].trim();
let hour: usize = token5[0..2].parse()
.expect("illegal number in arr.hour");
arrivals[hour] += 1;
}
}
println!(" Hour | Dep | Arr |Total|");
println!("-------------------------");
for hour in 0..24 {
println!(" {:02} | {:03} | {:03} | {:03} |",
hour, departures[hour], arrivals[hour], arrivals[hour] + departures[hour]);
}
}