Example #1
0
// The main routine.  Basically just used to parse out some parameters before handing
// things off to other functions.
int main(int argc, char *argv[])
{
  // Define characters that are used as comments:
  // TODO: Update the documentation to reflect these characters are all valid comment chars.
  const string comment_chars("\\#~$&£%");

  // Define a few variables for the simulation.
  Target target;
  string output_fname;

  Array array;
  Combiner combiner;
  SpectralMode spec_mode;
  vector <Observation *> observation_list;

  // TODO: For now we only have one noise model, so we load it by default
  NoiseModel *noisemodel = new NoiseModel_Tatulli2006();

  int n_params = 0;

  if (argc == 1)
    PrintHelp();

  cout << "Here" << endl;

  for (int i = 1; i < argc; i++)
  {
    // First see if the user is requesting help:
    if (strcmp(argv[i], "-h") == 0)
    {
      PrintHelp();
    }

    // We need to know some information about the target:
    if ((strcmp(argv[i], "-t") == 0) && (i < argc - 1))
    {
      target.ImportFile(string(argv[i + 1]), comment_chars);
      target.ParseFileOptions(argv, i + 2, argc);
      n_params += 1;
    }

    // And the image file we're going to use for the simulation:
    if ((strcmp(argv[i], "-i") == 0) && (i < argc - 1))
    {
      target.SetImage(string(argv[i + 1]));
      target.ParseImageOptions(argv, i + 2, argc);
      n_params += 1;
    }

    // And where we're going to write the output:
    if ((strcmp(argv[i], "-o") == 0) && (i < argc - 1))
    {
      try
      {
        output_fname = string(argv[i + 1]);
        n_params += 1;
      }
      catch (...)
      {
        throw std::runtime_error("Invalid Output File Definition");
      }
    }

    //
    // After this there are two cases:
    //

    // ################
    // (1) we use an existing OIFITS data file.  Really this has everything
    // needed to run the simulation, but I don't want to write a module to parse
    // the OIFITS array and wavelength tables.  So, we'll just require
    // that the array and spectral mode be specified too.
    if ((strcmp(argv[i], "-d") == 0) && (i < argc - 1))
    {
      observation_list = Obs_OIFITS::ReadObservation_OIFITS(string(argv[i + 1]));
      n_params += 1;
    }

    // ################
    // or (2) we are simulating something from scratch in which case we need
    // the array
    if ((strcmp(argv[i], "-a") == 0) && (i < argc - 1))
    {
      array.ImportFile(string(argv[i + 1]), comment_chars);
      array.ParseOptions(argv, i, argc);
      n_params += 1;
    }

    // the combiner
    if ((strcmp(argv[i], "-c") == 0) && (i < argc - 1))
    {
      combiner.ImportFile(string(argv[i + 1]), comment_chars);
      n_params += 1;
    }

    // the spectral mode.  Note, the combiner must be specified first so we can check that
    // the two are indeed to be used with eachother.
    if ((strcmp(argv[i], "-m") == 0) && (i < argc - 1))
    {
      if (combiner.name == "")
      {
        cout << "The combiner, -c, must be specified before the spectral mode, -m.\n";
        exit(0);
      }

      spec_mode.ImportFile(string(argv[i + 1]), combiner.GetName(), comment_chars);
      n_params += 1;

    }

    // Now for observation_list
    if ((strcmp(argv[i], "-obs") == 0) && (i < argc - 1))
    {
      // First ensure that the array has been defined.  If not, quit.
      if (array.GetArrayName() == "")
      {
        cout << "The array, -a, must be specified before the observation list, -obs.\n";
        exit(0);
      }

      // Observations are a little funny.  We permit both files and command line options.
      // Just pass things off to the observation class so it can decide what to do:
      observation_list = Observation::ParseCommandLine(&array, argv, i, argc, comment_chars);
      n_params += 1;
    }
  }

  // Check that all parameters were specified
  // TODO: Better checking here should be implemented
  if (n_params == 7)
    run_sim(&target, &array, &combiner, &spec_mode, noisemodel, observation_list, output_fname);
  else
    cout << "Something is missing on the command line, quitting!" << endl;

  // Clean up memory
  delete noisemodel;

  return 0;
}