]> git.donarmstrong.com Git - mothur.git/blobdiff - validparameter.cpp
1.12.0
[mothur.git] / validparameter.cpp
index 4ea677f4df472014321ee8d00fc7bf45d5e322f3..e82a9e8d4446430d125c168d66e0ababc8651655 100644 (file)
@@ -197,7 +197,7 @@ bool ValidParameters::isValidParameter(string parameter, vector<string> cParams,
 
 /******************************************************/
 
-string ValidParameters::validFile(map<string, string> container, string parameter, bool isFile) {
+string ValidParameters::validFile(map<string, string>& container, string parameter, bool isFile) {
        try {
                int ableToOpen;
                ifstream in;
@@ -209,23 +209,43 @@ string ValidParameters::validFile(map<string, string> container, string paramete
                        if(isFile == true) {
                        
                        #ifdef USE_MPI  
-                               int pid;
+                               int pid, processors;
+                               MPI_Status status;
                                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+                               MPI_Comm_size(MPI_COMM_WORLD, &processors);
                                
                                if (pid == 0) {
                        #endif
 
-                               ableToOpen = openInputFile(it->second, in);
+                               ableToOpen = openInputFile(it->second, in, "noerror");
+                               
+                               //if you can't open it, try default location
+                               if (ableToOpen == 1) {
+                                       if (m->getDefaultPath() != "") { //default path is set
+                                               string tryPath = m->getDefaultPath() + getSimpleName(it->second);
+                                               m->mothurOut("Unable to open " + it->second + ". Trying default " + tryPath); m->mothurOutEndLine();
+                                               ableToOpen = openInputFile(tryPath, in, "noerror");
+                                               container[parameter] = tryPath;
+                                       }
+                               }
+                               
                                in.close();
 
                        #ifdef USE_MPI  
-                                       MPI_Bcast(&ableToOpen, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send ableToOPen
+                                       for(int i = 1; i < processors; i++) { 
+                                               MPI_Send(&ableToOpen, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
+                                       }
                                }else {
-                                       MPI_Bcast(&ableToOpen, 1, MPI_INT, 0, MPI_COMM_WORLD); //get ableToOPen
+                                       MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
                                }
+                               
+                               MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
                        #endif
                        
-                               if (ableToOpen == 1) { return "not open"; }
+                               if (ableToOpen == 1) { 
+                                       m->mothurOut("Unable to open " + container[parameter]); m->mothurOutEndLine();
+                                       return "not open"; 
+                               }
                        }
                }else { return "not found"; }