Template:CMI Example CMI initialize CXX

From CSDMS
Revision as of 11:53, 6 February 2012 by CSDMSBot (talk | contribs) (Automated import of articles *** existing text overwritten ***)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  this->log.info ("Initializing");
  if (this->status >= CMI_STATUS_INITIALIZING)
    return TRUE;
  else
    this->status = CMI_STATUS_INITIALIZING;

  this->log.info (this->CMI_get_status ());

  this->log.info ("Create port queue.");
  { // Create port queue.
    ::edu::csdms::ports::CMIPort port =
      ::babel_cast<edu::csdms::ports::CMIPort>(*this);

    this->ports = ::edu::csdms::tools::CMIPortQueue::_create ();

    this->ports.initialize (this->d_services, port);

    this->ports.add_ports (CMI_PORT_NAMES);

    this->ports.connect_ports ();
  }
  this->log.info ("Created port queue.");

  this->log.info ("Parse config file.");
  { // Read parameters from the config dialog.
    ::edu::csdms::tools::TemplateFiles tmpls;
    const char *src_files = CMI_TEMPLATE_SOURCE_FILES;
    const char *dest_files = CMI_TEMPLATE_DEST_FILES;
    string val;

    tmpls = ::edu::csdms::tools::TemplateFiles::_create ();
    tmpls.add_files (CMI_TEMPLATE_SOURCE_FILES, CMI_TEMPLATE_DEST_FILES);
    tmpls.substitute (this->userinput, "/"CMI_COMPONENT_NAME"/Input/Var/",
        ".");

    val = this->userinput.getString (
        "/"CMI_COMPONENT_NAME"/Input/Var/SimulationName",
        CMI_COMPONENT_NAME);
    this->userinput.putString (
        "/"CMI_COMPONENT_NAME"/SimulationName",
        val);
  }
  this->log.info ("Parsed config file.");

  /* The contents of this file will be something like,
   * Child Child.in
   * */
  this->state.initialize ("Child_command_line.txt");

  this->log.info ("Create print queue.");
  { // Set up the print queue.
    ::edu::csdms::ports::CMIPort port =
      ::babel_cast<edu::csdms::ports::CMIPort>(*this);
    this->print_q = ::edu::csdms::tools::PrintQueue::_create ();

    this->print_q.initialize (this->userinput, "/"CMI_COMPONENT_NAME,
        port);
    this->print_q.add_files_from_list (CMI_OUTPUT_FILE_NS);
  }
  this->log.info ("Created print queue.");

#if CMI_TURN_OFF_PORTS
  this->log.warning ("Forgetting ports for now.");
#else
  this->log.info ("Initialize ports.");
  this->ports.initialize_ports (0);
#endif

#if CMI_TURN_OFF_MAPPING
  this->log.warning ("Mapping is turned off.");
#else
  this->log.info ("Initialize mappers.");
  this->ports.add_mappers (CMI_MAPPERS);

  this->log.info ("Map initial values.");
  this->ports.run_mappers ();
#endif

  this->status = CMI_STATUS_INITIALIZED;

  this->log.info ("Initialized.");
  this->log.info (this->CMI_get_status ());
  return TRUE;