Skip to content

Commit

Permalink
Merge pull request #309 from drbergman/make-output-folder-finalized
Browse files Browse the repository at this point in the history
make output folder if it does not exist
  • Loading branch information
MathCancer authored Oct 15, 2024
2 parents ee154ee + 84d6a99 commit 8684729
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions modules/PhysiCell_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
###############################################################################
*/

#include <sys/stat.h>
#include "./PhysiCell_settings.h"

using namespace BioFVM;
Expand Down Expand Up @@ -108,6 +109,8 @@ bool load_PhysiCell_config_file( std::string filename )

parameters.read_from_pugixml( physicell_config_root );

create_output_directory( PhysiCell_settings.folder );

return true;
}

Expand Down Expand Up @@ -320,6 +323,45 @@ void PhysiCell_Settings::read_from_pugixml( void )
return;
}

bool create_directories(const std::string &path)
{
std::vector<std::string> directories;
size_t pos = 0;
std::string currentPath;

while ((pos = path.find_first_of("/\\", pos)) != std::string::npos) {
currentPath = path.substr(0, pos++);
if (!create_directory(currentPath)) {
return false;
}
}
return create_directory(path);
}

bool create_directory(const std::string &path)
{
#if defined(__MINGW32__) || defined(__MINGW64__)
bool success = mkdir(path.c_str()) == 0;
#else
bool success = mkdir(path.c_str(), 0755) == 0;
#endif
return success || errno == EEXIST;
}

void create_output_directory(const std::string& path)
{
if (!create_directories(path))
{
std::cout << "ERROR: Could not create output directory " << path << " ! Quitting." << std::endl;
exit(-1);
}
}

void create_output_directory(void)
{
create_output_directory(PhysiCell_settings.folder);
}

PhysiCell_Globals PhysiCell_globals;

/* parameters functions */
Expand Down
6 changes: 6 additions & 0 deletions modules/PhysiCell_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class PhysiCell_Settings
void read_from_pugixml( void );
};

bool create_directories(const std::string &path);
bool create_directory(const std::string &path);

void create_output_directory(const std::string& path);
void create_output_directory(void);

class PhysiCell_Globals
{
private:
Expand Down

0 comments on commit 8684729

Please sign in to comment.