Template:CMI Example CMI initialize C: Difference between revisions

From CSDMS
Automated import of articles *** existing text overwritten ***
Automated import of articles *** existing text overwritten ***
 
Line 3: Line 3:
             edu_csdms_models_Sedflux3D__get_data (self);
             edu_csdms_models_Sedflux3D__get_data (self);


     fprintf (stderr, "%s: Initializing.
     edu_csdms_tools_Verbose_info (this->log, "Initializing.", _ex);
", CMI_COMPONENT_NAME);
 
     if (this->status >= CMI_STATUS_INITIALIZING)
     if (this->status >= CMI_STATUS_INITIALIZING)
       return TRUE;
       return TRUE;
Line 11: Line 9:
       this->status = CMI_STATUS_INITIALIZING;
       this->status = CMI_STATUS_INITIALIZING;


     fprintf (stderr, "%s: Create port queue.
     edu_csdms_tools_Verbose_info (this->log, "Create port queue.", _ex);
", CMI_COMPONENT_NAME);
     { // Create port queue.
     { // Create port queue.
       edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
       edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
Line 18: Line 15:
         edu_csdms_tools_CMIConfigFile_get_array (this->cfg_file,
         edu_csdms_tools_CMIConfigFile_get_array (this->cfg_file,
             "CMI_PORT_NAMES", _ex);
             "CMI_PORT_NAMES", _ex);
      this->ports = edu_csdms_tools_CMIPortQueue__create (_ex);


       this->ports = edu_csdms_tools_CMIPortQueue__create (_ex);
       edu_csdms_tools_Verbose_info (this->log, "Initialize port queue.", _ex);
      fprintf (stderr, "%s: Initialize port queue.
", CMI_COMPONENT_NAME);
       edu_csdms_tools_CMIPortQueue_initialize (this->ports,
       edu_csdms_tools_CMIPortQueue_initialize (this->ports,
           this->d_services, port, _ex);
           this->d_services, port, _ex);
       fprintf (stderr, "%s: %s: Add ports to queue.
 
",
       edu_csdms_tools_Verbose_info (this->log, "Add ports to queue.", _ex);
          CMI_COMPONENT_NAME, CMI_PORT_NAMES);
       edu_csdms_tools_CMIPortQueue_add_ports (this->ports, CMI_PORT_NAMES,
       edu_csdms_tools_CMIPortQueue_add_ports (this->ports, CMI_PORT_NAMES,
           _ex);
           _ex);
       fprintf (stderr, "%s: Connect ports.
 
", CMI_COMPONENT_NAME);
       edu_csdms_tools_Verbose_info (this->log, "Connect ports.", _ex);
       edu_csdms_tools_CMIPortQueue_connect_ports (this->ports, _ex);
       edu_csdms_tools_CMIPortQueue_connect_ports (this->ports, _ex);
     }
     }
    edu_csdms_tools_Verbose_info (this->log, "Created port queue.", _ex);


     fprintf (stderr, "%s: Open log.
     edu_csdms_tools_Verbose_info (this->log, "Read parameters.", _ex);
", CMI_COMPONENT_NAME);
    if (!this->log)
    {
      this->log = edu_csdms_tools_Verbose__create (_ex);
      edu_csdms_tools_Verbose_set_log_level (this->log, 1, _ex);
    }
 
    fprintf (stderr, "%s: Read parameters.
", CMI_COMPONENT_NAME);
     { /* Read parameters from the config dialog. */
     { /* Read parameters from the config dialog. */
       edu_csdms_tools_TemplateFiles template;
       edu_csdms_tools_TemplateFiles template;
Line 101: Line 88:
           "/Sedflux3D/SimulationName", val, _ex);
           "/Sedflux3D/SimulationName", val, _ex);
     }
     }
/*
 
This is what Sedflux3D.txt will look like,
     edu_csdms_tools_Verbose_info (this->log, "BMI initialize.", _ex);
"sedflux -3 --silent --no-signals --init-file=${INIT_FILE} --input-dir=${INPUT_DIR} --working-dir=${WORKING_DIR}"
*/
     fprintf (stderr, "%s: BMI initialize
", CMI_COMPONENT_NAME);
     this->state = BMI_Initialize (CMI_COMPONENT_NAME"_command_line.txt");
     this->state = BMI_Initialize (CMI_COMPONENT_NAME"_command_line.txt");


     fprintf (stderr, "%s: Set up PrintQueue.
     edu_csdms_tools_Verbose_info (this->log, "Create print queue.", _ex);
", CMI_COMPONENT_NAME);
    PRINT (2, "Set up PrintQueue");
     {
     {
       edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
       edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
      fprintf (stderr, "Create PrintQueue
"); fflush (stderr);
       this->print_queue = edu_csdms_tools_PrintQueue__create (_ex);
       this->print_queue = edu_csdms_tools_PrintQueue__create (_ex);
       fprintf (stderr, "Initialize PrintQueue
 
"); fflush (stderr);
       edu_csdms_tools_Verbose_info (this->log, "Initialize print queue.", _ex);
       edu_csdms_tools_PrintQueue_initialize (this->print_queue,
       edu_csdms_tools_PrintQueue_initialize (this->print_queue,
           this->userinput, "/"CMI_COMPONENT_NAME, port, _ex);
           this->userinput, "/"CMI_COMPONENT_NAME, port, _ex);
       fprintf (stderr, "Add file to PrintQueue
 
"); fflush (stderr);
       edu_csdms_tools_Verbose_info (this->log, "Add file to print queue.", _ex);
       edu_csdms_tools_PrintQueue_add_files_from_list (this->print_queue,
       edu_csdms_tools_PrintQueue_add_files_from_list (this->print_queue,
           CMI_OUTPUT_FILE_NS, _ex);
           CMI_OUTPUT_FILE_NS, _ex);
      fprintf (stderr, "Created PrintQueue
"); fflush (stderr);
     }
     }
    edu_csdms_tools_Verbose_info (this->log, "Created print queue.", _ex);


     fprintf (stderr, "%s: Initialize uses ports.
     edu_csdms_tools_Verbose_info (this->log, "Initialize uses ports.", _ex);
", CMI_COMPONENT_NAME);
    PRINT (2, "Initialize model uses ports");
     edu_csdms_tools_CMIPortQueue_initialize_ports (this->ports, NULL, _ex);
     edu_csdms_tools_CMIPortQueue_initialize_ports (this->ports, NULL, _ex);


#if CMI_TURN_OFF_MAPPING
#if CMI_TURN_OFF_MAPPING
     fprintf (stderr, "%s: Forgetting mappers.
     edu_csdms_tools_Verbose_warning (this->log, "Forgetting mappers.", _ex);
", CMI_COMPONENT_NAME);
#else
#else
     fprintf (stderr, "%s: Set up mappers.
     edu_csdms_tools_Verbose_info (this->log, "Set up mappers.", _ex);
", CMI_COMPONENT_NAME);
     edu_csdms_tools_CMIPortQueue_add_mappers (this->ports, CMI_MAPPERS, _ex);
     edu_csdms_tools_CMIPortQueue_add_mappers (this->ports, CMI_MAPPERS, _ex);
#endif
#endif
    //fprintf (stderr, "%s: Run mappers.
", CMI_COMPONENT_NAME);
    //edu_csdms_tools_CMIPortQueue_run_mappers (this->ports, _ex);


     fprintf (stderr, "%s: Initialized.
     edu_csdms_tools_Verbose_info (this->log, "Initialized.", _ex);
", CMI_COMPONENT_NAME);
     this->status = CMI_STATUS_INITIALIZED;
     this->status = CMI_STATUS_INITIALIZED;
     return TRUE;
     return TRUE;
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 11:52, 6 February 2012

    struct edu_csdms_models_Sedflux3D__data *this =
             edu_csdms_models_Sedflux3D__get_data (self);

    edu_csdms_tools_Verbose_info (this->log, "Initializing.", _ex);
    if (this->status >= CMI_STATUS_INITIALIZING)
      return TRUE;
    else
      this->status = CMI_STATUS_INITIALIZING;

    edu_csdms_tools_Verbose_info (this->log, "Create port queue.", _ex);
    { // Create port queue.
      edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
      struct sidl_string__array* ports =
        edu_csdms_tools_CMIConfigFile_get_array (this->cfg_file,
            "CMI_PORT_NAMES", _ex);
      this->ports = edu_csdms_tools_CMIPortQueue__create (_ex);

      edu_csdms_tools_Verbose_info (this->log, "Initialize port queue.", _ex);
      edu_csdms_tools_CMIPortQueue_initialize (this->ports,
          this->d_services, port, _ex);

      edu_csdms_tools_Verbose_info (this->log, "Add ports to queue.", _ex);
      edu_csdms_tools_CMIPortQueue_add_ports (this->ports, CMI_PORT_NAMES,
          _ex);

      edu_csdms_tools_Verbose_info (this->log, "Connect ports.", _ex);
      edu_csdms_tools_CMIPortQueue_connect_ports (this->ports, _ex);
    }
    edu_csdms_tools_Verbose_info (this->log, "Created port queue.", _ex);

    edu_csdms_tools_Verbose_info (this->log, "Read parameters.", _ex);
    { /* Read parameters from the config dialog. */
      edu_csdms_tools_TemplateFiles template;
      char **src;
      char **dest;
      const char *src_files = CMI_TEMPLATE_SOURCE_FILES;
      const char *dest_files = CMI_TEMPLATE_DEST_FILES;
      char * val;
      //struct sidl_string__array* src_files =
      //  gov_cca_TypeMap_getStringArray (this->cmi_data,
      //      "CMI_TEMPLATE_SOURCE_FILES", NULL, _ex);
      //sidl_string__array dst_files = gov_cca_TypeMap_getStringArray (
      //    this->cmi_data, "CMI_TEMPLATE_DEST_FILES", NULL, _ex);

      template = edu_csdms_tools_TemplateFiles__create (_ex);
      edu_csdms_tools_TemplateFiles_add_files (template, src_files,
          dest_files, _ex);

      val = gov_cca_TypeMap_getString (this->userinput,
          "/Sedflux3D/Input/Var/InputDir", "GUI", _ex);
      if (g_ascii_strcasecmp (val, "GUI")==0)
        gov_cca_TypeMap_putString (this->userinput,
            "/Sedflux3D/Input/Var/InputDir", ".", _ex);

      val = gov_cca_TypeMap_getString (this->userinput,
          "/Sedflux3D/Input/Var/InitializationFile", "GUI", _ex);
      if (g_ascii_strcasecmp (val, "GUI")==0)
        gov_cca_TypeMap_putString (this->userinput,
            "/Sedflux3D/Input/Var/InitializationFile",
            "${SimulationName}_init.kvf", _ex);

      val = gov_cca_TypeMap_getString (this->userinput,
          "/Sedflux3D/Input/Var/RiverFile", "GUI", _ex);
      if (g_ascii_strcasecmp (val, "GUI")==0)
        gov_cca_TypeMap_putString (this->userinput,
            "/Sedflux3D/Input/Var/RiverFile",
            "${SimulationName}_river.kvf", _ex);

      val = gov_cca_TypeMap_getString (this->userinput,
          "/Sedflux3D/Input/Var/SedimentFile", "GUI", _ex);
      if (g_ascii_strcasecmp (val, "GUI")==0)
        gov_cca_TypeMap_putString (this->userinput,
            "/Sedflux3D/Input/Var/SedimentFile",
            "${SimulationName}_sediment.kvf", _ex);

      gov_cca_TypeMap_putString (this->userinput,
          "/Sedflux3D/Input/Var/ProcessFile",
          "${SimulationName}_process.kvf", _ex);

      edu_csdms_tools_TemplateFiles_substitute (template,
          this->userinput, "/"CMI_COMPONENT_NAME"/Input/Var/", ".",
          _ex);

      val = gov_cca_TypeMap_getString (this->userinput,
          "/Sedflux3D/Input/Var/SimulationName", CMI_COMPONENT_NAME, _ex);
      gov_cca_TypeMap_putString (this->userinput,
          "/Sedflux3D/SimulationName", val, _ex);
    }

    edu_csdms_tools_Verbose_info (this->log, "BMI initialize.", _ex);
    this->state = BMI_Initialize (CMI_COMPONENT_NAME"_command_line.txt");

    edu_csdms_tools_Verbose_info (this->log, "Create print queue.", _ex);
    {
      edu_csdms_ports_CMIPort port = edu_csdms_ports_CMIPort__cast (self, _ex);
      this->print_queue = edu_csdms_tools_PrintQueue__create (_ex);

      edu_csdms_tools_Verbose_info (this->log, "Initialize print queue.", _ex);
      edu_csdms_tools_PrintQueue_initialize (this->print_queue,
          this->userinput, "/"CMI_COMPONENT_NAME, port, _ex);

      edu_csdms_tools_Verbose_info (this->log, "Add file to print queue.", _ex);
      edu_csdms_tools_PrintQueue_add_files_from_list (this->print_queue,
          CMI_OUTPUT_FILE_NS, _ex);
    }
    edu_csdms_tools_Verbose_info (this->log, "Created print queue.", _ex);

    edu_csdms_tools_Verbose_info (this->log, "Initialize uses ports.", _ex);
    edu_csdms_tools_CMIPortQueue_initialize_ports (this->ports, NULL, _ex);

#if CMI_TURN_OFF_MAPPING
    edu_csdms_tools_Verbose_warning (this->log, "Forgetting mappers.", _ex);
#else
    edu_csdms_tools_Verbose_info (this->log, "Set up mappers.", _ex);
    edu_csdms_tools_CMIPortQueue_add_mappers (this->ports, CMI_MAPPERS, _ex);
#endif

    edu_csdms_tools_Verbose_info (this->log, "Initialized.", _ex);
    this->status = CMI_STATUS_INITIALIZED;
    return TRUE;