-
-
Save Robadob/c6a341ca34cdc94f6bff1fd23858be1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add <nowarn/> to the root of init files to disable warnings about missing agent properties | |
void readInitialStates(char* inputpath, xmachine_memory_keratinocyte_list* h_keratinocytes, int* h_xmachine_memory_keratinocyte_count) | |
{ | |
//These values aren't used | |
int temp = 0; | |
int* itno = &temp; | |
/* Initialise variables */ | |
agent_maximum.x = 0; | |
agent_maximum.y = 0; | |
agent_maximum.z = 0; | |
agent_minimum.x = 0; | |
agent_minimum.y = 0; | |
agent_minimum.z = 0; | |
//set all keratinocyte values to 0 | |
//If this is not done then it will cause errors in emu mode where undefined memory is not 0 | |
for (int k=0; k<xmachine_memory_keratinocyte_MAX; k++) | |
{ | |
h_keratinocytes->id[k] = 0; | |
h_keratinocytes->type[k] = 0; | |
h_keratinocytes->x[k] = 0; | |
h_keratinocytes->y[k] = 0; | |
h_keratinocytes->z[k] = 0; | |
h_keratinocytes->force_x[k] = 0; | |
h_keratinocytes->force_y[k] = 0; | |
h_keratinocytes->force_z[k] = 0; | |
h_keratinocytes->num_xy_bonds[k] = 0; | |
h_keratinocytes->num_z_bonds[k] = 0; | |
h_keratinocytes->num_stem_bonds[k] = 0; | |
h_keratinocytes->cycle[k] = 0; | |
h_keratinocytes->diff_noise_factor[k] = 0; | |
h_keratinocytes->dead_ticks[k] = 0; | |
h_keratinocytes->contact_inhibited_ticks[k] = 0; | |
h_keratinocytes->motility[k] = 0; | |
h_keratinocytes->dir[k] = 0; | |
h_keratinocytes->movement[k] = 0; | |
} | |
/* Open file for parsing */ | |
rapidxml::xml_document<> doc; // character type defaults to char | |
std::ifstream file(inputpath); | |
if (!file.is_open()) | |
{ | |
printf("ERROR: Could not open initialisation file %s\n", inputpath); | |
exit(0); | |
} | |
std::stringstream buffer; | |
buffer << file.rdbuf(); | |
std::string content(buffer.str()); | |
doc.parse<0>(&content[0]); | |
//Allocate buffers for array properties | |
//Allocate nodes | |
rapidxml::xml_node<> *root_node = doc.first_node("states"); | |
rapidxml::xml_node<> *xagent_node = root_node->first_node("xagent"); | |
rapidxml::xml_node<> *env_node = root_node->first_node("environment"); | |
rapidxml::xml_node<> *name_node=0, *t_node=0; | |
bool noWarn = doc.first_node("nowarn")!=0; | |
//Set itno | |
t_node = root_node->first_node("itno"); | |
if(t_node) | |
(*itno) = atoi(t_node->value()); | |
//Iterate all xagent nodes | |
while (xagent_node) | |
{ | |
//Extract name of xagent | |
name_node = xagent_node->first_node("name"); | |
//Check: Name node missing | |
if(!name_node){ | |
printf("ERROR: Agent node missing name property.\n"); | |
exit(0); | |
} | |
if (strcmp(name_node->value(), "keratinocyte") == 0) | |
{ | |
//Check: Too many agents | |
if (*h_xmachine_memory_keratinocyte_count > xmachine_memory_keratinocyte_MAX){ | |
printf("ERROR: MAX Buffer size (%i) for agent keratinocyte exceeded whilst reading data\n", xmachine_memory_keratinocyte_MAX); | |
exit(0); | |
} | |
//Extract the agent properties | |
t_node = xagent_node->first_node("id"); | |
if(t_node){ | |
h_keratinocytes->id[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'id' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("type"); | |
if(t_node){ | |
h_keratinocytes->type[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'type' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("x"); | |
if(t_node){ | |
h_keratinocytes->x[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'x' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("y"); | |
if(t_node){ | |
h_keratinocytes->y[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'y' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("z"); | |
if(t_node){ | |
h_keratinocytes->z[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'z' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("force_x"); | |
if(t_node){ | |
h_keratinocytes->force_x[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'force_x' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("force_y"); | |
if(t_node){ | |
h_keratinocytes->force_y[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'force_y' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("force_z"); | |
if(t_node){ | |
h_keratinocytes->force_z[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'force_z' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("num_xy_bonds"); | |
if(t_node){ | |
h_keratinocytes->num_xy_bonds[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'num_xy_bonds' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("num_z_bonds"); | |
if(t_node){ | |
h_keratinocytes->num_z_bonds[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'num_z_bonds' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("num_stem_bonds"); | |
if(t_node){ | |
h_keratinocytes->num_stem_bonds[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'num_stem_bonds' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("cycle"); | |
if(t_node){ | |
h_keratinocytes->cycle[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'cycle' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("diff_noise_factor"); | |
if(t_node){ | |
h_keratinocytes->diff_noise_factor[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'diff_noise_factor' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("dead_ticks"); | |
if(t_node){ | |
h_keratinocytes->dead_ticks[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'dead_ticks' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("contact_inhibited_ticks"); | |
if(t_node){ | |
h_keratinocytes->contact_inhibited_ticks[*h_xmachine_memory_keratinocyte_count] = (int) atoi(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'contact_inhibited_ticks' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("motility"); | |
if(t_node){ | |
h_keratinocytes->motility[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'motility' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("dir"); | |
if(t_node){ | |
h_keratinocytes->dir[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'dir' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
t_node = xagent_node->first_node("movement"); | |
if(t_node){ | |
h_keratinocytes->movement[*h_xmachine_memory_keratinocyte_count] = (float) atof(t_node->value()); | |
}else if(!noWarn){printf("WARNING: Agent keratinocyte[%d] is missing property 'movement' in init file, 0 used.\n",(*h_xmachine_memory_keratinocyte_count));} | |
//Calculate agent min/max | |
//Check maximum x value | |
if(agent_maximum.x < h_keratinocytes->x[*h_xmachine_memory_keratinocyte_count]) | |
agent_maximum.x = (float)h_keratinocytes->x[*h_xmachine_memory_keratinocyte_count]; | |
//Check minimum x value | |
if(agent_minimum.x > h_keratinocytes->x[*h_xmachine_memory_keratinocyte_count]) | |
agent_minimum.x = (float)h_keratinocytes->x[*h_xmachine_memory_keratinocyte_count]; | |
//Check maximum y value | |
if(agent_maximum.y < h_keratinocytes->y[*h_xmachine_memory_keratinocyte_count]) | |
agent_maximum.y = (float)h_keratinocytes->y[*h_xmachine_memory_keratinocyte_count]; | |
//Check minimum y value | |
if(agent_minimum.y > h_keratinocytes->y[*h_xmachine_memory_keratinocyte_count]) | |
agent_minimum.y = (float)h_keratinocytes->y[*h_xmachine_memory_keratinocyte_count]; | |
//Check maximum z value | |
if(agent_maximum.z < h_keratinocytes->z[*h_xmachine_memory_keratinocyte_count]) | |
agent_maximum.z = (float)h_keratinocytes->z[*h_xmachine_memory_keratinocyte_count]; | |
//Check minimum z value | |
if(agent_minimum.z > h_keratinocytes->z[*h_xmachine_memory_keratinocyte_count]) | |
agent_minimum.z = (float)h_keratinocytes->z[*h_xmachine_memory_keratinocyte_count]; | |
//Increment keratinocyte agent count | |
(*h_xmachine_memory_keratinocyte_count)++; | |
} | |
//Find next xagent node | |
xagent_node = xagent_node->next_sibling("xagent"); | |
} | |
//Parse environment variables | |
if(env_node) | |
{ | |
t_node = env_node->first_node("calcium_level"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_calcium_level(&t); | |
} | |
t_node = env_node->first_node("CYCLE_LENGTH"); | |
if(t_node) | |
{ | |
int t = (int)atoi(t_node->value()); | |
set_CYCLE_LENGTH(&t); | |
} | |
t_node = env_node->first_node("SUBSTRATE_FORCE"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_SUBSTRATE_FORCE(&t); | |
} | |
t_node = env_node->first_node("DOWNWARD_FORCE"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_DOWNWARD_FORCE(&t); | |
} | |
t_node = env_node->first_node("FORCE_MATRIX"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_FORCE_MATRIX(&t); | |
} | |
t_node = env_node->first_node("FORCE_REP"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_FORCE_REP(&t); | |
} | |
t_node = env_node->first_node("FORCE_DAMPENER"); | |
if(t_node) | |
{ | |
float t = (float)atof(t_node->value()); | |
set_FORCE_DAMPENER(&t); | |
} | |
t_node = env_node->first_node("BASEMENT_MAX_Z"); | |
if(t_node) | |
{ | |
int t = (int)atoi(t_node->value()); | |
set_BASEMENT_MAX_Z(&t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment