@@ -515,15 +515,21 @@ void set_save_biofvm_cell_data_as_custom_matlab( bool newvalue )
515515
516516/* writing parts of BioFVM to a MultiCellDS file */
517517
518+ static bool BioFVM_substrates_initialized_in_dom = false ;
519+
520+ void reset_BioFVM_substrates_initialized_in_dom ( void )
521+ {
522+ BioFVM_substrates_initialized_in_dom = false ;
523+ }
524+
525+
518526void add_BioFVM_substrates_to_open_xml_pugi ( pugi::xml_document& xml_dom , std::string filename_base, Microenvironment& M )
519527{
520528 add_MultiCellDS_main_structure_to_open_xml_pugi ( xml_dom );
521529
522530 pugi::xml_node root = biofvm_doc.child ( " MultiCellDS" );
523531 pugi::xml_node node = root.child ( " microenvironment" );
524532
525- static bool BioFVM_substrates_initialized_in_dom = false ;
526-
527533 // if the TME has not yet been initialized in the DOM, create all the
528534 // right data elements, and populate the meshes.
529535 if ( !BioFVM_substrates_initialized_in_dom )
@@ -564,36 +570,9 @@ void add_BioFVM_substrates_to_open_xml_pugi( pugi::xml_document& xml_dom , std::
564570 // if Cartesian, add the x, y, and z coordinates
565571 if ( M.mesh .Cartesian_mesh == true )
566572 {
567- char temp [10240 ];
568- int position = 0 ;
569- for ( unsigned int k=0 ; k < M.mesh .x_coordinates .size ()-1 ; k++ )
570- { position += sprintf ( temp+position, " %f " , M.mesh .x_coordinates [k] ); }
571- sprintf ( temp+position , " %f" , M.mesh .x_coordinates [ M.mesh .x_coordinates .size ()-1 ] );
572- node = node.append_child ( " x_coordinates" );
573- node.append_child ( pugi::node_pcdata ).set_value ( temp );
574- attrib = node.append_attribute (" delimiter" );
575- attrib.set_value ( " " );
576-
577- node = node.parent ();
578- position = 0 ;
579- for ( unsigned int k=0 ; k < M.mesh .y_coordinates .size ()-1 ; k++ )
580- { position += sprintf ( temp+position, " %f " , M.mesh .y_coordinates [k] ); }
581- sprintf ( temp+position , " %f" , M.mesh .y_coordinates [ M.mesh .y_coordinates .size ()-1 ] );
582- node = node.append_child ( " y_coordinates" );
583- node.append_child ( pugi::node_pcdata ).set_value ( temp );
584- attrib = node.append_attribute (" delimiter" );
585- attrib.set_value ( " " );
586-
587- node = node.parent ();
588- position = 0 ;
589- for ( unsigned int k=0 ; k < M.mesh .z_coordinates .size ()-1 ; k++ )
590- { position += sprintf ( temp+position, " %f " , M.mesh .z_coordinates [k] ); }
591- sprintf ( temp+position , " %f" , M.mesh .z_coordinates [ M.mesh .z_coordinates .size ()-1 ] );
592- node = node.append_child ( " z_coordinates" );
593- node.append_child ( pugi::node_pcdata ).set_value ( temp );
594- attrib = node.append_attribute (" delimiter" );
595- attrib.set_value ( " " );
596- node = node.parent ();
573+ write_coordinates_node (node, M.mesh .x_coordinates , " x_coordinates" );
574+ write_coordinates_node (node, M.mesh .y_coordinates , " y_coordinates" );
575+ write_coordinates_node (node, M.mesh .z_coordinates , " z_coordinates" );
597576 }
598577 // write out the voxels -- minimal data, even if redundant for cartesian
599578 if ( save_mesh_as_matlab == false )
@@ -744,7 +723,7 @@ void add_BioFVM_substrates_to_open_xml_pugi( pugi::xml_document& xml_dom , std::
744723 { filename_start++; }
745724 strcpy ( filename_without_pathing , filename_start );
746725
747- node.append_child ( pugi::node_pcdata ).set_value ( filename_without_pathing ); // filename );
726+ node.append_child ( pugi::node_pcdata ).set_value ( filename_without_pathing ); // filename );
748727
749728 node = node.parent ();
750729 }
@@ -812,6 +791,21 @@ void add_BioFVM_substrates_to_open_xml_pugi( pugi::xml_document& xml_dom , std::
812791 return ;
813792}
814793
794+ void write_coordinates_node (pugi::xml_node &node, const std::vector<double > &coordinates, std::string name)
795+ {
796+ std::ostringstream oss;
797+ for (size_t i = 0 ; i < coordinates.size (); ++i)
798+ {
799+ if (i != 0 )
800+ { oss << " " ; }
801+ oss << coordinates[i];
802+ }
803+ pugi::xml_node coord_node = node.append_child (name.c_str ());
804+ coord_node.append_child (pugi::node_pcdata).set_value (oss.str ().c_str ());
805+ pugi::xml_attribute attrib = coord_node.append_attribute (" delimiter" );
806+ attrib.set_value (" " );
807+ }
808+
815809// not yet implemented
816810void add_BioFVM_basic_agent_to_open_xml_pugi ( pugi::xml_document& xml_dom, Basic_Agent& BA );
817811
0 commit comments