]> git.donarmstrong.com Git - mothur.git/blobdiff - mothurout.cpp
1.23.0
[mothur.git] / mothurout.cpp
index bc5e24efffc6d79291112870d74ac4686c39d42b..9dcdc80e761f1483059297dbcd996a0a06b43e5b 100644 (file)
@@ -1182,7 +1182,6 @@ vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& n
 
 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
        try{
-       
                vector<unsigned long long> filePos;
                filePos.push_back(0);
                
@@ -1190,7 +1189,7 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                unsigned long long size;
                
                filename = getFullPathName(filename);
-               
+       
                //get num bytes in file
                pFile = fopen (filename.c_str(),"rb");
                if (pFile==NULL) perror ("Error opening file");
@@ -1199,7 +1198,9 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                        size=ftell (pFile);
                        fclose (pFile);
                }
-       
+               
+       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               
                //estimate file breaks
                unsigned long long chunkSize = 0;
                chunkSize = size / proc;
@@ -1219,7 +1220,10 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                        unsigned long long newSpot = spot;
                        while (!in.eof()) {
                           char c = in.get();
+                               
                           if (c == '>') {   in.putback(c); newSpot = in.tellg(); break;  }
+                          else if (int(c) == -1) { break; }
+                               
                        }
                
                        //there was not another sequence before the end of the file
@@ -1240,7 +1244,11 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                }
 
                proc = (filePos.size() - 1);
-               
+#else
+               mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
+               proc=1;
+               filePos.push_back(size);
+#endif
                return filePos;
        }
        catch(exception& e) {
@@ -1469,6 +1477,26 @@ int MothurOut::getNumNames(string names){
 }
 /***********************************************************************/
 
+int MothurOut::getNumChar(string line, char c){
+       try {
+               int count = 0;
+               
+               if(line != ""){
+                       for(int i=0;i<line.size();i++){
+                               if(line[i] == c){
+                                       count++;
+                               }
+                       }
+               }
+               
+               return count;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "getNumChar");
+               exit(1);
+       }
+}
+/***********************************************************************/
 int MothurOut::mothurRemove(string filename){
        try {
                filename = getFullPathName(filename);
@@ -1486,6 +1514,84 @@ int MothurOut::mothurRemove(string filename){
                exit(1);
        }
 }
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, int& num){
+       try {
+               bool error = false;
+               
+               if (isNumeric1(item)) {
+                       convert(item, num);
+               }else {
+                       num = 0;
+                       error = true;
+                       mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
+                       commandInputsConvertError = true;
+               }
+               
+               return error;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "mothurConvert");
+               exit(1);
+       }
+}
+/***********************************************************************/
+bool MothurOut::isNumeric1(string stringToCheck){
+       try {
+               bool numeric = false;
+               
+               if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
+                       
+               return numeric;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "isNumeric1");
+               exit(1);
+       }
+       
+}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, float& num){
+       try {
+               bool error = false;
+               
+               if (isNumeric1(item)) {
+                       convert(item, num);
+               }else {
+                       num = 0;
+                       error = true;
+                       mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
+                       commandInputsConvertError = true;
+               }
+               
+               return error;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "mothurConvert");
+               exit(1);
+       }
+}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, double& num){
+       try {
+               bool error = false;
+               
+               if (isNumeric1(item)) {
+                       convert(item, num);
+               }else {
+                       num = 0;
+                       error = true;
+                       mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
+                       commandInputsConvertError = true;
+               }
+               
+               return error;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "mothurConvert");
+               exit(1);
+       }
+}
 /**************************************************************************************************/
 
 vector<vector<double> > MothurOut::binomial(int maxOrder){