Template:CMI Example CMI initialize C
From CSDMS
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;