X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mothur.h;h=c5afe86a79a9e92c789735ea3b1be3d33accf66a;hb=952a85d59a12e664f5efa6d01681be189e4fff9c;hp=20d3b4b64725d0428248b47b22a3146a0a3a52c9;hpb=510b1cfc25cd79391d6973ca20c5ec25fb1bb3b2;p=mothur.git diff --git a/mothur.h b/mothur.h index 20d3b4b..c5afe86 100644 --- a/mothur.h +++ b/mothur.h @@ -45,22 +45,23 @@ #include #include -using namespace std; -#ifdef _WIN32 - #define exp(x) (exp((double) x)) - #define sqrt(x) (sqrt((double) x)) - #define log10(x) (log10((double) x)) - #define log2(x) (log10(x)/log10(2)) - #define isnan(x) ((x) != (x)) - #define isinf(x) (fabs(x) == std::numeric_limits::infinity()) -#else +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) #include #include #endif +using namespace std; + +#define exp(x) (exp((double) x)) +#define sqrt(x) (sqrt((double) x)) +#define log10(x) (log10((double) x)) +#define log2(x) (log10(x)/log10(2)) +#define isnan(x) ((x) != (x)) +#define isinf(x) (fabs(x) == std::numeric_limits::infinity()) -typedef unsigned long long ull; + +typedef unsigned long ull; struct IntNode { int lvalue; @@ -96,6 +97,7 @@ inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){ if (!(i >> x) || (failIfLeftoverChars && i.get(c))) throw BadConversion(s); } + //********************************************************************************************************************** template @@ -153,14 +155,13 @@ string toString(const T&x, int i){ return output.str(); } - /***********************************************************************/ inline int openOutputFileAppend(string fileName, ofstream& fileHandle){ fileHandle.open(fileName.c_str(), ios::app); if(!fileHandle) { - cerr << "Error: Could not open " << fileName << endl; + cout << "Error: Could not open " << fileName << endl; return 1; } else { @@ -168,7 +169,30 @@ inline int openOutputFileAppend(string fileName, ofstream& fileHandle){ } } +/***********************************************************************/ +inline string getline(ifstream& fileHandle) { + try { + + string line = ""; + + while (!fileHandle.eof()) { + //get next character + char c = fileHandle.get(); + + //are you at the end of the line + if ((c == '\n') || (c == '\r') || (c == '\f')){ break; } + else { line += c; } + } + + return line; + + } + catch(exception& e) { + cout << "Error in mothur function getline" << endl; + exit(1); + } +} /**************************************************************************************************/ @@ -233,12 +257,14 @@ inline void errorOut(exception& e, string object, string function) { mothurOut("Error: "); mothurOut(toString(e.what())); - mothurOut(" has occurred in the " + object + " class function " + function + "Please contact Pat Schloss at pschloss@microbio.umass.edu, and be sure to include the mothur.logFile with your inquiry."); + mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at pschloss@umich.edu, and be sure to include the mothur.logFile with your inquiry."); mothurOutEndLine(); } + + /***********************************************************************/ inline void gobble(istream& f){ @@ -394,7 +420,7 @@ inline int openInputFile(string fileName, ifstream& fileHandle){ fileHandle.open(fileName.c_str()); if(!fileHandle) { - cerr << "Error: Could not open " << fileName << endl; + mothurOut("Error: Could not open " + fileName); mothurOutEndLine(); return 1; } else { @@ -409,7 +435,7 @@ inline int openOutputFile(string fileName, ofstream& fileHandle){ fileHandle.open(fileName.c_str(), ios::trunc); if(!fileHandle) { - cerr << "Error: Could not open " << fileName << endl; + mothurOut("Error: Could not open " + fileName); mothurOutEndLine(); return 1; } else {