2525#include < fstream>
2626#include < iostream>
2727#include < string>
28+ #include < unistd.h>
29+ #include < cstdlib>
30+
2831using namespace std ;
2932
33+ // Function to check whether there is a file given at a specific path
34+ bool findFile (string path) {
35+
36+ // Opens the file at specified path
37+ ifstream newFile (path);
38+
39+ // Checks if file is opened properly, otherwise results in an error and returns false
40+ if (newFile.is_open ()) {
41+
42+ // Use good() to check if the file exists
43+ bool found = newFile.good ();
44+ newFile.close ();
45+ return found;
46+
47+ } else {
48+ cerr << " ERROR opening file." << endl;
49+ }
50+
51+ return false ;
52+ }
53+
54+
3055// / Main function calls the Core's runSimulation method which
3156// / handles command line arguments and running the simulation.
3257// /
@@ -35,14 +60,26 @@ using namespace std;
3560// / @return -1 if error, else 0 if success.
3661int main (int argc, char *argv[])
3762{
63+
3864 // Clear logging files at the start of each simulation
3965 fstream (" Output/Debug/logging.txt" , ios::out | ios::trunc);
4066 fstream (" Output/Debug/vertices.txt" , ios::out | ios::trunc);
4167 fstream (" Output/Debug/edges.txt" , ios::out | ios::trunc);
4268
4369 // Initialize log4cplus and set properties based on configure file
4470 ::log4cplus::initialize ();
45- ::log4cplus::PropertyConfigurator::doConfigure (" RuntimeFiles/log4cplus_configure.ini" );
71+
72+ // This is to find the absolute path of the home directory log4cplus file
73+ string absPath = getenv (" HOME" );
74+ absPath = absPath + " /log4cplus_configure.ini" ;
75+
76+ // Checks whether the file is in the home directory
77+ // otherwise uses the file in RuntimeFiles
78+ if (findFile (absPath)) {
79+ ::log4cplus::PropertyConfigurator::doConfigure (absPath);
80+ } else {
81+ ::log4cplus::PropertyConfigurator::doConfigure (" RuntimeFiles/log4cplus_configure.ini" );
82+ }
4683
4784 // storing command line arguments as string
4885 // required to pass as an argument to setupSimulation
0 commit comments