X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=setdircommand.cpp;h=67a1f59f8388dbfec55ae7b552f02640b5d6b93f;hb=8dd3c225255d7084e3aff8740aa4f1f1cabb367a;hp=fc411ae61120ae90c4efb396de928b028432965f;hpb=1d898dc6edaf9e9f287fab53bf1f21fb29757a17;p=mothur.git diff --git a/setdircommand.cpp b/setdircommand.cpp index fc411ae..67a1f59 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -59,6 +59,7 @@ SetDirectoryCommand::SetDirectoryCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { vector myArray = setParameters(); @@ -100,13 +101,23 @@ int SetDirectoryCommand::execute(){ commandFactory = CommandFactory::getInstance(); + string tag = ""; +#ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are + + tag = toString(pid); +#endif + + m->mothurOut("Mothur's directories:"); m->mothurOutEndLine(); + //redirect output if ((output == "clear") || (output == "")) { output = ""; commandFactory->setOutputDirectory(output); } else if (output == "default") { string exepath = m->argv; output = exepath.substr(0, (exepath.find_last_of('m'))); - m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine(); + m->mothurOut("outputDir=" + output); m->mothurOutEndLine(); commandFactory->setOutputDirectory(output); }else { //add / to name if needed @@ -119,15 +130,15 @@ int SetDirectoryCommand::execute(){ //test to make sure directory exists output = m->getFullPathName(output); - string outTemp = output + "temp"; + string outTemp = output + tag + "temp"; ofstream out; out.open(outTemp.c_str(), ios::trunc); if(!out) { m->mothurOut(output + " directory does not exist or is not writable."); m->mothurOutEndLine(); }else{ out.close(); - remove(outTemp.c_str()); - m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine(); + m->mothurRemove(outTemp); + m->mothurOut("outputDir=" + output); m->mothurOutEndLine(); commandFactory->setOutputDirectory(output); } } @@ -138,7 +149,7 @@ int SetDirectoryCommand::execute(){ string exepath = m->argv; input = exepath.substr(0, (exepath.find_last_of('m'))); - m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine(); + m->mothurOut("inputDir=" + input); m->mothurOutEndLine(); commandFactory->setInputDirectory(input); }else { //add / to name if needed @@ -151,15 +162,15 @@ int SetDirectoryCommand::execute(){ //test to make sure directory exists input = m->getFullPathName(input); - string inTemp = input + "temp"; + string inTemp = input + tag + "temp"; ofstream in; in.open(inTemp.c_str(), ios::trunc); if(!in) { m->mothurOut(input + " directory does not exist or is not writable."); m->mothurOutEndLine(); }else{ in.close(); - remove(inTemp.c_str()); - m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine(); + m->mothurRemove(inTemp); + m->mothurOut("inputDir=" + input); m->mothurOutEndLine(); commandFactory->setInputDirectory(input); } } @@ -168,7 +179,7 @@ int SetDirectoryCommand::execute(){ if (tempdefault == "clear") { #ifdef MOTHUR_FILES string temp = MOTHUR_FILES; - m->mothurOut("Resetting default directory to " + temp); m->mothurOutEndLine(); + m->mothurOut("tempDefault=" + temp); m->mothurOutEndLine(); m->setDefaultPath(temp); #else string temp = ""; @@ -180,7 +191,7 @@ int SetDirectoryCommand::execute(){ string exepath = m->argv; tempdefault = exepath.substr(0, (exepath.find_last_of('m'))); - m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine(); + m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine(); m->setDefaultPath(tempdefault); }else { //add / to name if needed @@ -191,8 +202,19 @@ int SetDirectoryCommand::execute(){ if (lastChar != "\\") { tempdefault += "\\"; } #endif - m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine(); - m->setDefaultPath(tempdefault); + //test to make sure directory exists + tempdefault = m->getFullPathName(tempdefault); + string inTemp = tempdefault + tag + "temp"; + ofstream in; + in.open(inTemp.c_str(), ios::trunc); + if(!in) { + m->mothurOut(tempdefault + " directory does not exist or is not writable."); m->mothurOutEndLine(); + }else{ + in.close(); + m->mothurRemove(inTemp); + m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine(); + m->setDefaultPath(tempdefault); + } } return 0;