/// <summary> /// Handles the commandline parameters (if any). /// </summary> private void HandleCommandLineParameters() { string configFilename = null; string inputFilename = null; int inputSignal = -1; string outputFilename = null; bool showHelp = false; string usage = string.Empty; double lp = double.NaN; double hp = double.NaN; if (Environment.GetCommandLineArgs().Length > 0) { //// First check the getopt() way.... //CommandlineParserGetOpt commandLineParserGetOpt = new CommandlineParserGetOpt(); //commandLineParserGetOpt.AddOption("c", "configfilename", "Configuration file containing analysis parameters", // CommandlineOptionFlags.HasParameter | CommandlineOptionFlags.Required, // (p, v) => { configFilename = v; }); //commandLineParserGetOpt.AddOption("h", "help", "Show usage help", // CommandlineOptionFlags.HideInUsage, // (p, v) => { showHelp = true; }); //commandLineParserGetOpt.Parse(); //if (showHelp) // usage = commandLineParserGetOpt.GetHelp(); //if (!showHelp && commandLineParserGetOpt.MissingRequiredOptions.Count > 0) //{ // CommandlineParser commandlineParser = new CommandlineParser(); // commandlineParser.AddOption("EdfInputFilename", string.Empty, "EDF(+) input filename", string.Empty, // CommandlineOptionFlags.Required, (p, v) => // { inputFilename = v; }, 0); // commandlineParser.AddOption("SignalIndex", string.Empty, "Index (0 - N) of signal to be analysed", // string.Empty, CommandlineOptionFlags.Required, // (p, v) => int.TryParse(v, out inputSignal), 1); // commandlineParser.AddOption("OutputFilename", string.Empty, "Analysis output filename", string.Empty, // CommandlineOptionFlags.Required, (p, v) => // { outputFilename = v; }, 2); // commandlineParser.AddOption("ConfigurationFilename", string.Empty, "Configuration filename", string.Empty, // CommandlineOptionFlags.None, (p, v) => // { configFilename = v; }, 3); // commandlineParser.AddOption("Batch", string.Empty, "Batchmode, no user interaction", // (p, v) => { BatchMode = true; }); // commandlineParser.AddOption("LP", string.Empty, "Low Pass filter value (Hz)", // CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out lp)); // commandlineParser.AddOption("HP", string.Empty, "High Pass filter value (Hz)", // CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out hp)); // commandlineParser.AddOption("?", string.Empty, "Show usage help", // CommandlineOptionFlags.HideInUsage, // (p, v) => { showHelp = true; }); // commandlineParser.Parse(); // if (showHelp) // usage = commandlineParser.GetHelp(); //} CommandlineParser commandlineParser = new CommandlineParser(); commandlineParser.AddOption("Input", string.Empty, "EDF(+) input filename", "EdfInputFilename", CommandlineOptionFlags.HasParameter, (p, v) => { inputFilename = v; }); commandlineParser.AddOption("SignalIndex", string.Empty, "Index (0 - N-1" + ") of signal to be analysed", "SignalIndex", CommandlineOptionFlags.HasParameter, (p, v) => int.TryParse(v, out inputSignal)); commandlineParser.AddOption("Output", string.Empty, "Analysis output filename", "OutputFilename", CommandlineOptionFlags.HasParameter, (p, v) => { outputFilename = v; }); commandlineParser.AddOption("ConfigFile", string.Empty, "Configuration filename", "ConfigurationFilename", CommandlineOptionFlags.HasParameter, (p, v) => { configFilename = v; }); commandlineParser.AddOption("LP", string.Empty, "Low Pass filter value (Hz)","LowestLowPassFrequency", CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out lp)); commandlineParser.AddOption("HP", string.Empty, "High Pass filter value (Hz)", "HighestHighPassFrequency", CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out hp)); commandlineParser.AddOption("Batch", string.Empty, "Batchmode, no user interaction", (p, v) => { BatchMode = true; }); commandlineParser.AddOption("?", string.Empty, "Show usage help", CommandlineOptionFlags.HideInUsage, (p, v) => { showHelp = true; }); commandlineParser.Parse(); if (showHelp) { MessageBox.Show(commandlineParser.GetHelp(), Strings.UsageInformation); Application.Exit(); } } // Read configuration settings from file; use default settings if no configuration file was set if (string.IsNullOrEmpty(configFilename)) ErrorLogger.WriteLog("Configuration file not provided, using default configuration parameters"); else ErrorLogger.WriteLog("Using configuration parameters from file " + configFilename); _configuration = new MCconfiguration(configFilename); if (!string.IsNullOrEmpty(outputFilename)) _configuration.OutputFileName = outputFilename; if (File.Exists(inputFilename)) textBoxInputFilename.Text = inputFilename; if (inputSignal >= 0) signalsComboBox.SelectedIndex = inputSignal; if (!double.IsNaN(lp)) textBoxLP.Text = lp.ToString(); if (!double.IsNaN(hp)) textBoxHP.Text = hp.ToString(); NeuroLoopGainController.AppController.AppConf = _configuration; // Default values for textBoxes textBoxF0.Text = _configuration.F0.ToString(FormatProvider); textBoxB.Text = _configuration.BandWidth.ToString(FormatProvider); textBoxFc.Text = _configuration.FC.ToString(FormatProvider); textBoxSmootherrate.Text = _configuration.SmoothRate.ToString(FormatProvider); textBoxAnalysisPeriod.Text = _configuration.SmoothTime.ToString(FormatProvider); textBoxOutputFileName.Text = _configuration.OutputFileName; if (!BatchMode) return; // Batchmode requested; perform analysis without user input and close application after processing buttonStart_Click(this, new EventArgs()); Application.Exit(); }
/// <summary> /// Handles the commandline parameters (if any). /// </summary> private void HandleCommandLineParameters() { string configFilename = null; string inputFilename = null; int inputSignal = -1; string outputFilename = null; bool showHelp = false; string usage = string.Empty; double lp = double.NaN; double hp = double.NaN; if (Environment.GetCommandLineArgs().Length > 0) { //// First check the getopt() way.... //CommandlineParserGetOpt commandLineParserGetOpt = new CommandlineParserGetOpt(); //commandLineParserGetOpt.AddOption("c", "configfilename", "Configuration file containing analysis parameters", // CommandlineOptionFlags.HasParameter | CommandlineOptionFlags.Required, // (p, v) => { configFilename = v; }); //commandLineParserGetOpt.AddOption("h", "help", "Show usage help", // CommandlineOptionFlags.HideInUsage, // (p, v) => { showHelp = true; }); //commandLineParserGetOpt.Parse(); //if (showHelp) // usage = commandLineParserGetOpt.GetHelp(); //if (!showHelp && commandLineParserGetOpt.MissingRequiredOptions.Count > 0) //{ // CommandlineParser commandlineParser = new CommandlineParser(); // commandlineParser.AddOption("EdfInputFilename", string.Empty, "EDF(+) input filename", string.Empty, // CommandlineOptionFlags.Required, (p, v) => // { inputFilename = v; }, 0); // commandlineParser.AddOption("SignalIndex", string.Empty, "Index (0 - N) of signal to be analysed", // string.Empty, CommandlineOptionFlags.Required, // (p, v) => int.TryParse(v, out inputSignal), 1); // commandlineParser.AddOption("OutputFilename", string.Empty, "Analysis output filename", string.Empty, // CommandlineOptionFlags.Required, (p, v) => // { outputFilename = v; }, 2); // commandlineParser.AddOption("ConfigurationFilename", string.Empty, "Configuration filename", string.Empty, // CommandlineOptionFlags.None, (p, v) => // { configFilename = v; }, 3); // commandlineParser.AddOption("Batch", string.Empty, "Batchmode, no user interaction", // (p, v) => { BatchMode = true; }); // commandlineParser.AddOption("LP", string.Empty, "Low Pass filter value (Hz)", // CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out lp)); // commandlineParser.AddOption("HP", string.Empty, "High Pass filter value (Hz)", // CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out hp)); // commandlineParser.AddOption("?", string.Empty, "Show usage help", // CommandlineOptionFlags.HideInUsage, // (p, v) => { showHelp = true; }); // commandlineParser.Parse(); // if (showHelp) // usage = commandlineParser.GetHelp(); //} CommandlineParser commandlineParser = new CommandlineParser(); commandlineParser.AddOption("Input", string.Empty, "EDF(+) input filename", "EdfInputFilename", CommandlineOptionFlags.HasParameter, (p, v) => { inputFilename = v; }); commandlineParser.AddOption("SignalIndex", string.Empty, "Index (0 - N-1" + ") of signal to be analysed", "SignalIndex", CommandlineOptionFlags.HasParameter, (p, v) => int.TryParse(v, out inputSignal)); commandlineParser.AddOption("Output", string.Empty, "Analysis output filename", "OutputFilename", CommandlineOptionFlags.HasParameter, (p, v) => { outputFilename = v; }); commandlineParser.AddOption("ConfigFile", string.Empty, "Configuration filename", "ConfigurationFilename", CommandlineOptionFlags.HasParameter, (p, v) => { configFilename = v; }); commandlineParser.AddOption("LP", string.Empty, "Low Pass filter value (Hz)", "LowestLowPassFrequency", CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out lp)); commandlineParser.AddOption("HP", string.Empty, "High Pass filter value (Hz)", "HighestHighPassFrequency", CommandlineOptionFlags.HasParameter, (p, v) => TryParseToDouble(v, out hp)); commandlineParser.AddOption("Batch", string.Empty, "Batchmode, no user interaction", (p, v) => { BatchMode = true; }); commandlineParser.AddOption("?", string.Empty, "Show usage help", CommandlineOptionFlags.HideInUsage, (p, v) => { showHelp = true; }); commandlineParser.Parse(); if (showHelp) { MessageBox.Show(commandlineParser.GetHelp(), Strings.UsageInformation); Application.Exit(); } } // Read configuration settings from file; use default settings if no configuration file was set if (string.IsNullOrEmpty(configFilename)) { ErrorLogger.WriteLog("Configuration file not provided, using default configuration parameters"); } else { ErrorLogger.WriteLog("Using configuration parameters from file " + configFilename); } _configuration = new MCconfiguration(configFilename); if (!string.IsNullOrEmpty(outputFilename)) { _configuration.OutputFileName = outputFilename; } if (File.Exists(inputFilename)) { textBoxInputFilename.Text = inputFilename; } if (inputSignal >= 0) { signalsComboBox.SelectedIndex = inputSignal; } if (!double.IsNaN(lp)) { textBoxLP.Text = lp.ToString(); } if (!double.IsNaN(hp)) { textBoxHP.Text = hp.ToString(); } NeuroLoopGainController.AppController.AppConf = _configuration; // Default values for textBoxes textBoxF0.Text = _configuration.F0.ToString(FormatProvider); textBoxB.Text = _configuration.BandWidth.ToString(FormatProvider); textBoxFc.Text = _configuration.FC.ToString(FormatProvider); textBoxSmootherrate.Text = _configuration.SmoothRate.ToString(FormatProvider); textBoxAnalysisPeriod.Text = _configuration.SmoothTime.ToString(FormatProvider); textBoxOutputFileName.Text = _configuration.OutputFileName; if (!BatchMode) { return; } // Batchmode requested; perform analysis without user input and close application after processing buttonStart_Click(this, new EventArgs()); Application.Exit(); }