diff --git a/src/HttpCommandServer.hpp b/src/HttpCommandServer.hpp index 6134a799..22ff23c9 100644 --- a/src/HttpCommandServer.hpp +++ b/src/HttpCommandServer.hpp @@ -72,14 +72,14 @@ namespace http_command { running = true; server_thread = std::thread(&HttpCommandServer::acceptLoop, this); std::cout - << "\033[32m" // start green - << "HTTP command server listening at http://localhost:" << port + << "\033[35m" // start color + << "ForeFire HTTP command server listening at http://localhost:" << port << "\033[0m" << std::endl; std::cout << "\033[33m" // start yellow - << "To stop the server, press Ctrl-C or type exit in the ForeFire shell." + << "To stop the server, press Ctrl-C or type quit in the ForeFire shell." << "\033[0m" << std::endl; diff --git a/tests/runff/run.ff b/tests/runff/run.ff new file mode 100644 index 00000000..5fa7d2d7 --- /dev/null +++ b/tests/runff/run.ff @@ -0,0 +1,26 @@ +# ForeFire Basic Simulation Example +# REQUIRES: data.nc and fuels.csv in the current directory. + +# --- Parameters --- +setParameter[ForeFireDataDirectory=.] +setParameter[fuelsTableFile=fuels.csv] +setParameter[propagationModel=Rothermel] +setParameter[dumpMode=geojson] + +# Optional Tuning Params +setParameter[perimeterResolution=10] +setParameter[spatialIncrement=3] +setParameter[propagationSpeedAdjustmentFactor=0.6] +setParameter[windReductionFactor=0.4] + +# --- Load Data & Domain --- +loadData[data.nc;2025-02-10T17:35:54Z] +# --- Ignition --- +startFire[lonlat=(8.70, 41.952, 0);t=0] + +# --- Run Simulation --- +goTo[t=3600] + +# --- End --- +print[] +# Omit quit[] if using listenHTTP \ No newline at end of file diff --git a/tools/forefire/ForeFire.cpp b/tools/forefire/ForeFire.cpp index 334c79f7..35c39452 100644 --- a/tools/forefire/ForeFire.cpp +++ b/tools/forefire/ForeFire.cpp @@ -33,33 +33,72 @@ ForeFire::ForeFire() : executor() {} ForeFire::~ForeFire() {} void ForeFire::usage(const char* name) { - cout << "usage: " << name << " [-i file] [-o file]" << endl; - cout << " -i: input command file" << endl; - cout << " -o: output command file" << endl; + cout << "usage: " << name << " [-i file] [-l] [-v] [-w file]" << endl; + cout << " -i file: input command file" << endl; + cout << " -l : Start directly in listenHTTP mode" << endl; + cout << " -v : print version" << endl; + cout << " -w file: web shell mode" << endl; + } int ForeFire::startShell(int argc, char* argv[]) { ifstream* inputStream = nullptr; int fileopt; int EOO = -1; - while ((fileopt = getopt(argc, argv, "w:i:o:v")) != EOO) { - if (fileopt == 'v') { - cout << ff_version << endl; - return 1; + bool startListenHttpMode = false; + while ((fileopt = getopt(argc, argv, "w:i:o:vl")) != EOO) { + switch (fileopt) { + case 'l': + startListenHttpMode = true; + goto end_option_parsing; + + case 'v': + cout << ff_version << endl; + return 1; + case 'w': + FFWebShell(optarg); + return 1; + case 'i': + inputStream = new ifstream(optarg); + if (!inputStream || !inputStream->is_open()) { + cerr << "Error: Could not open input file: " << optarg << endl; + delete inputStream; + return 1; + } + break; + case '?': // Handle unknown options or missing args for options requiring one + default: + usage(argv[0]); + return 1; } - if (fileopt == 'w') { - FFWebShell(optarg); - return 1; - } else if (fileopt == 'i') { - inputStream = new ifstream(optarg); - if (!inputStream) { - cout << "wrong input file, check your settings..." << optarg << endl; - } + } + + end_option_parsing:; + + if (startListenHttpMode) { + + cout << "" << endl; + + string standAlone = "setParameter[runmode=standalone]"; + executor.ExecuteCommand(standAlone); + + string listenCommand = "listenHTTP[]"; + executor.ExecuteCommand(listenCommand); + + // Keep the main thread alive indefinitely + cout << "(Press Ctrl+C to exit)" << endl; + while (true) { + sleep(3600); } + + return 0; + + } else { + + FFShell(inputStream); + delete inputStream; + return 0; // Normal exit for non-server mode } - FFShell(inputStream); - delete inputStream; - return 1; } void ForeFire::FFWebShell(char* path) { @@ -89,10 +128,28 @@ void ForeFire::FFShell(ifstream* inputStream) { executor.ExecuteCommand(line); } } else { - cout << "Wildfire solver ForeFire Version :" << ff_version << endl; - cout << "Copyright (C) 2025 CNRS/Univ.Corsica " << endl; - cout << "Comes with ABSOLUTELY NO WARRANTY " << endl; - cout << "Type 'help[]' for commands" << endl; + + const char* logoFF = R"( + ██████╗ ██████╗ + ██╔═══╝ ██╔═══╝ + ██████╗ ██████╗ + ██╔═══╝ ██╔═══╝ + ██║ ██║ + ╚═╝ ╚═╝ + )"; + + cout << logoFF << endl; + cout << " =================================================" << endl; + cout << " ForeFire - Wildfire Propagation Simulator" << endl; + cout << " =================================================" << endl; + cout << " Version: " << ff_version << endl; + cout << " License: See LICENSE file (ABSOLUTELY NO WARRANTY)" << endl; + cout << " Copyright (C) 2025 CNRS/Univ.Corsica" << endl; + cout << endl; + cout << " Type 'help[]' for a list of commands." << endl; + cout << " Use Tab for auto-completion." << endl; // Add hint about completion + cout << endl; + std::string line; while (true) { line = advanced_editor::LineEditor::getLine("forefire> ");