Commit 6deb168a8182fbe105f21635422ee353d487725a

Authored by Laila Saadatifard
1 parent f74c9f43

add save to cellset.h

Showing 1 changed file with 20 additions and 0 deletions   Show diff stats
stim/biomodels/cellset.h
@@ -167,6 +167,26 @@ public: @@ -167,6 +167,26 @@ public:
167 cells.push_back(newcell); //push the new memory entry into the cell array 167 cells.push_back(newcell); //push the new memory entry into the cell array
168 } 168 }
169 169
  170 +void save(std::string filename){
  171 +
  172 +
  173 + size_t ncells = cells.size(); // get the number of cells
  174 + std::ofstream file(filename); //open a file to store the cell's coordinates
  175 + if (file.is_open()) {
  176 +
  177 + file << "x y z radius\n"; //write the file header
  178 + for (size_t c=0; c < ncells; c++){ //for each cell
  179 + if (cells[c][ip[3]] != NULL) //check if for the current cell, radius has been assigned
  180 + file << cells[c][ip[0]] << delim << cells[c][ip[1]] << delim << cells[c][ip[2]] << delim << cells[c][ip[3]] << '\n' ;
  181 + else //check if for the current cell, radius has not been assigned, set radius to zero
  182 + file << cells[c][ip[0]] << delim << cells[c][ip[1]] << delim << cells[c][ip[2]] << delim << 0 << '\n' ;
  183 + }
  184 +
  185 + }
  186 + file.close();
  187 +
  188 + }
  189 +
170 190
171 }; //end class cellset 191 }; //end class cellset
172 }; //end namespace stim 192 }; //end namespace stim