Template:CMI Example CMI initialize CXX: Difference between revisions

From CSDMS
Automated import of articles
 
Automated import of articles *** existing text overwritten ***
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang=cpp>
<syntaxhighlight lang=cpp>


  this->log.info ("Initializing");
   if (this->status >= CMI_STATUS_INITIALIZING)
   if (this->status >= CMI_STATUS_INITIALIZING)
     return TRUE;
     return TRUE;
Line 6: Line 7:
     this->status = CMI_STATUS_INITIALIZING;
     this->status = CMI_STATUS_INITIALIZING;


   ::std::cerr << CMI_COMPONENT_NAME ": Status is "
   this->log.info (this->CMI_get_status ());
              << this->CMI_get_status () << ::std::endl;


   fprintf (stderr, "%s: Create PortQueue.
   this->log.info ("Create port queue.");
", CMI_COMPONENT_NAME);
   { // Create port queue.
   { // Create port queue.
     ::edu::csdms::ports::CMIPort port =
     ::edu::csdms::ports::CMIPort port =
Line 23: Line 22:
     this->ports.connect_ports ();
     this->ports.connect_ports ();
   }
   }
  this->log.info ("Created port queue.");


   fprintf (stderr, "%s: Read config dialog.
   this->log.info ("Parse config file.");
", CMI_COMPONENT_NAME);
   { // Read parameters from the config dialog.
   { // Read parameters from the config dialog.
     ::edu::csdms::tools::TemplateFiles tmpls;
     ::edu::csdms::tools::TemplateFiles tmpls;
Line 44: Line 43:
         val);
         val);
   }
   }
  this->log.info ("Parsed config file.");


  fprintf (stderr, "%s: Call BMI initialize.
", CMI_COMPONENT_NAME);
   /* The contents of this file will be something like,
   /* The contents of this file will be something like,
   * Child Child.in
   * Child Child.in
Line 52: Line 50:
   this->state.initialize ("Child_command_line.txt");
   this->state.initialize ("Child_command_line.txt");


   fprintf (stderr, "%s: Create PrintQueue.
   this->log.info ("Create print queue.");
", CMI_COMPONENT_NAME);
   { // Set up the print queue.
   { // Set up the print queue.
     ::edu::csdms::ports::CMIPort port =
     ::edu::csdms::ports::CMIPort port =
Line 63: Line 60:
     this->print_q.add_files_from_list (CMI_OUTPUT_FILE_NS);
     this->print_q.add_files_from_list (CMI_OUTPUT_FILE_NS);
   }
   }
  this->log.info ("Created print queue.");


#if CMI_TURN_OFF_PORTS
#if CMI_TURN_OFF_PORTS
   fprintf (stderr, "%s: Forgetting ports for now.
   this->log.warning ("Forgetting ports for now.");
", CMI_COMPONENT_NAME);
#else
#else
   fprintf (stderr, "%s: Initialize ports.
   this->log.info ("Initialize ports.");
", CMI_COMPONENT_NAME);
   this->ports.initialize_ports (0);
   this->ports.initialize_ports (0);
#endif
#endif
#if CMI_TURN_OFF_MAPPING
#if CMI_TURN_OFF_MAPPING
   fprintf (stderr, "%s: Mapping is turned off.
   this->log.warning ("Mapping is turned off.");
", CMI_COMPONENT_NAME);
#else
#else
   fprintf (stderr, "%s: Initialize mappers.
   this->log.info ("Initialize mappers.");
", CMI_COMPONENT_NAME);
   this->ports.add_mappers (CMI_MAPPERS);
   this->ports.add_mappers (CMI_MAPPERS);


   fprintf (stderr, "%s: Map initial values.
   this->log.info ("Map initial values.");
", CMI_COMPONENT_NAME);
   this->ports.run_mappers ();
   this->ports.run_mappers ();
#endif
#endif
Line 87: Line 81:
   this->status = CMI_STATUS_INITIALIZED;
   this->status = CMI_STATUS_INITIALIZED;


   ::std::cerr << CMI_COMPONENT_NAME ": Status is "
   this->log.info ("Initialized.");
              << this->CMI_get_status () << ::std::endl;
  this->log.info (this->CMI_get_status ());
 
   return TRUE;
   return TRUE;
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 11:53, 6 February 2012

  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;