Template:CMI Example CMI run CXX

From CSDMS
Revision as of 00:49, 1 February 2012 by CSDMSBot (talk | contribs) (Automated import of articles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  ::std::cerr << CMI_COMPONENT_NAME ": Status is "
              << this->CMI_get_status () << ::std::endl;

  if (this->status == CMI_STATUS_UPDATING)
    return TRUE;
  else
    this->status = CMI_STATUS_UPDATING;

  fprintf (stderr, "%s: Updating until %f.
", CMI_COMPONENT_NAME, time_interval);
  {
    double print_time = this->print_q.next_print_time ();
    fprintf (stderr, "%s: Next print time is %f.
", CMI_COMPONENT_NAME, print_time);
    while (print_time>0 && print_time<time_interval)
    {
      this->status = CMI_STATUS_UPDATED;
      fprintf (stderr, "%s: Running until print time %f.
", CMI_COMPONENT_NAME, print_time);
      this->CMI_run (print_time);
      this->print_q.print_all (print_time);
      print_time = this->print_q.next_print_time ();
      fprintf (stderr, "%s: Print time is now %f.
", CMI_COMPONENT_NAME, print_time);
    }
  }
/*
  if (time_interval > this->state.get_end_time ())
    time_interval = this->state.get_end_time ();
*/

  fprintf (stderr, "%s: Updating (0) ports until %f.
", CMI_COMPONENT_NAME, time_interval);
  { // Run model until the stop time
    double now = this->state.get_current_time ();
    double port_queue_dt = CMI_PORT_QUEUE_DT;
    double t = now + port_queue_dt;
    for (; t<time_interval; t+=port_queue_dt)
    {
      //this->print_q.print_all (now);

#if CMI_TURN_OFF_PORTS
      fprintf (stderr, "%s: Forgetting ports for now.
", CMI_COMPONENT_NAME);
#else
      fprintf (stderr, "%s: Updating (1) ports until %f.
", CMI_COMPONENT_NAME, now);
      fflush (stderr);
      this->ports.run_ports (now);
#endif

#if CMI_TURN_OFF_MAPPING
      fprintf (stderr, "%s: Not mapping values (0).
", CMI_COMPONENT_NAME);
#else
      fprintf (stderr, "%s: Map values.
", CMI_COMPONENT_NAME);
      fflush (stderr);

      this->ports.run_mappers ();
#endif

      fprintf (stderr, "%s: Updating myself until %f.
", CMI_COMPONENT_NAME, t);
      fflush (stderr);
      this->state.update_until (t);
      now = this->state.get_current_time ();
    }

    if (t>time_interval)
    { // The last partial time step (if necessary).
      //this->print_q.print_all (time_interval);
#if CMI_TURN_OFF_PORTS
      fprintf (stderr, "%s: Forgetting ports for now.
", CMI_COMPONENT_NAME);
#else
      fprintf (stderr, "%s: Updating (2) ports until %f.
", CMI_COMPONENT_NAME, now);
      fflush (stderr);
      this->ports.run_ports (now);
#endif

#if CMI_TURN_OFF_MAPPING
      fprintf (stderr, "%s: Not mapping values (1).
", CMI_COMPONENT_NAME);
#else
      fprintf (stderr, "%s: Map values.
", CMI_COMPONENT_NAME);
      fflush (stderr);
      this->ports.run_mappers ();
#endif

      fprintf (stderr, "%s: Updating myself until %f.
", CMI_COMPONENT_NAME, time_interval);
      fflush (stderr);
      // NOTE: Child.run may accept a dt not a time.
      this->state.update_until (time_interval);
    }
  }

  // NOTE: We may need to mask nodes below sea level.
  // this->state.MaskNodesBelowElevation (0);

  this->status = CMI_STATUS_UPDATED;
  ::std::cerr << CMI_COMPONENT_NAME ": Status is "
              << this->CMI_get_status () << ::std::endl;

  return TRUE;