]> git.donarmstrong.com Git - mothur.git/commitdiff
paralellized chimera.uchime for windows for both by group and with a template.
authorwestcott <westcott>
Wed, 26 Oct 2011 16:14:31 +0000 (16:14 +0000)
committerwestcott <westcott>
Wed, 26 Oct 2011 16:14:31 +0000 (16:14 +0000)
14 files changed:
aligncommand.h
chimeraslayercommand.h
chimerauchimecommand.cpp
chimerauchimecommand.h
classifyseqscommand.h
getoturepcommand.cpp
getoturepcommand.h
mothurout.cpp
myutils.cpp
phylotree.cpp
preclustercommand.h
shhhercommand.h
timing.h
trimflowscommand.h

index 6236958a42a886bf5178aab8571f1513c596e00f..fa1bf57468e31c114224841019b338020e574b21 100644 (file)
@@ -78,7 +78,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct alignData {
+struct alignData {
        string alignFName; 
        string reportFName; 
        string accnosFName;
index 815cb367c70dd844013fa9d53ca42800887342f6..54b8fa182894fd448dff3e5a7b6548532334b258 100644 (file)
@@ -79,7 +79,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct slayerData {
+struct slayerData {
        string outputFName; 
        string fasta; 
        string accnos;
index caddc27d9853299e8777998db09da3d148abba62..e08909bc89993db47ed80836a417b7020f68d068 100644 (file)
@@ -543,12 +543,9 @@ int ChimeraUchimeCommand::execute(){
                                if (chimealns) { m->openOutputFile(alnsFileName, out2); out2.close(); }
                                int totalSeqs = 0;
                                
-       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                                if(processors == 1)     {       totalSeqs = driverGroups(parser, outputFileName, newFasta, accnosFileName, alnsFileName, 0, groups.size(), groups);     }
                                else                            {       totalSeqs = createProcessesGroups(parser, outputFileName, newFasta, accnosFileName, alnsFileName, groups);                      }
-       #else
-                               totalSeqs = driverGroups(parser, outputFileName, newFasta, accnosFileName, alnsFileName, 0, groups.size(), groups);
-       #endif
+
                                if (m->control_pressed) {  for (int j = 0; j < outputNames.size(); j++) {       m->mothurRemove(outputNames[j]);        }  return 0;    }                               
 
                                int totalChimeras = deconvoluteResults(parser, outputFileName, accnosFileName, alnsFileName);
@@ -563,12 +560,12 @@ int ChimeraUchimeCommand::execute(){
                        
                                int numSeqs = 0;
                                int numChimeras = 0;
-       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+       //#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                                if(processors == 1){ numSeqs = driver(outputFileName, fastaFileNames[s], accnosFileName, alnsFileName, numChimeras); }
                                else{   numSeqs = createProcesses(outputFileName, fastaFileNames[s], accnosFileName, alnsFileName, numChimeras); }
-       #else
-                               numSeqs = driver(outputFileName, fastaFileNames[s], accnosFileName, alnsFileName, numChimeras);
-       #endif
+       //#else
+       //                      numSeqs = driver(outputFileName, fastaFileNames[s], accnosFileName, alnsFileName, numChimeras);
+       //#endif
                                if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) {        m->mothurRemove(outputNames[j]);        } return 0; }
                        
                                //remove file made for uchime
@@ -1286,9 +1283,10 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                processIDS.clear();
                int process = 1;
                int num = 0;
+               vector<string> files;
+               
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)          
                //break up file into multiple files
-               vector<string> files;
                m->divideFile(filename, processors, files);
                
                if (m->control_pressed) {  return 0;  }
@@ -1341,7 +1339,89 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                        }
                        in.close(); m->mothurRemove(tempFile);
                }
+#else
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               //Windows version shared memory, so be careful when passing variables through the preClusterData struct. 
+               //Above fork() will clone, so memory is separate, but that's not the case with windows, 
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               
+               //divide file
+               int count = 0;
+               int spot = 0;
+               map<int, ofstream*> filehandles;
+               map<int, ofstream*>::iterator it3;
+               
+               ofstream* temp;
+               for (int i = 0; i < processors; i++) {
+                       temp = new ofstream;
+                       filehandles[i] = temp;
+                       m->openOutputFile(filename+toString(i)+".temp", *(temp));
+                       files.push_back(filename+toString(i)+".temp");
+               }
+               
+               ifstream in;
+               m->openInputFile(filename, in);
+               
+               while(!in.eof()) {
+                       
+                       if (m->control_pressed) { in.close(); for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(it3->second)).close(); delete it3->second; } return 0; }
+                       
+                       Sequence tempSeq(in); m->gobble(in); 
+                       
+                       if (tempSeq.getName() != "") {
+                               tempSeq.printSequence(*(filehandles[spot])); 
+                               spot++; count++;
+                               if (spot == processors) { spot = 0; }
+                       }
+               }
+               in.close();
+               
+               //delete memory
+               for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+                       (*(it3->second)).close();
+                       delete it3->second;
+               }
+               
+               //sanity check for number of processors
+               if (count < processors) { processors = count; }
+               
+               vector<uchimeData*> pDataArray; 
+               DWORD   dwThreadIdArray[processors-1];
+               HANDLE  hThreadArray[processors-1]; 
+               vector<string> dummy; //used so that we can use the same struct for MyUchimeSeqsThreadFunction and MyUchimeThreadFunction
+               
+               //Create processor worker threads.
+               for( int i=1; i<processors; i++ ){
+                       // Allocate memory for thread data.
+                       string extension = toString(i) + ".temp";
+                       
+                       uchimeData* tempUchime = new uchimeData(outputFileName+extension, templatefile, files[i], "", "", "", accnos+extension, alns+extension, dummy, m, 0, 0,  i);
+                       tempUchime->setBooleans(useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract);
+                       tempUchime->setVariables(abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract);
+                       
+                       pDataArray.push_back(tempUchime);
+                       processIDS.push_back(i);
+                       
+                       //MySeqSumThreadFunction is in header. It must be global or static to work with the threads.
+                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+                       hThreadArray[i-1] = CreateThread(NULL, 0, MyUchimeSeqsThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]);   
+               }
+               
+               
+               //using the main process as a worker saves time and memory
+               num = driver(outputFileName, files[0], accnos, alns, numChimeras);
                
+               //Wait until all threads have terminated.
+               WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
+               
+               //Close all thread handles and free memory allocations.
+               for(int i=0; i < pDataArray.size(); i++){
+                       num += pDataArray[i]->count;
+                       numChimeras += pDataArray[i]->numChimeras;
+                       CloseHandle(hThreadArray[i]);
+                       delete pDataArray[i];
+               }
+#endif         
                
                //append output files
                for(int i=0;i<processIDS.size();i++){
@@ -1359,7 +1439,6 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                
                //get rid of the file pieces.
                for (int i = 0; i < files.size(); i++) { m->mothurRemove(files[i]); }
-#endif         
                return num;     
        }
        catch(exception& e) {
@@ -1424,7 +1503,6 @@ int ChimeraUchimeCommand::createProcessesGroups(SequenceParser& parser, string o
                        int temp = processIDS[i];
                        wait(&temp);
                }
-#endif         
                
                for (int i = 0; i < processIDS.size(); i++) {
                        ifstream in;
@@ -1433,8 +1511,50 @@ int ChimeraUchimeCommand::createProcessesGroups(SequenceParser& parser, string o
                        if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
                        in.close(); m->mothurRemove(tempFile);
                }
+                               
+#else
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               //Windows version shared memory, so be careful when passing variables through the preClusterData struct. 
+               //Above fork() will clone, so memory is separate, but that's not the case with windows, 
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               
+               vector<uchimeData*> pDataArray; 
+               DWORD   dwThreadIdArray[processors-1];
+               HANDLE  hThreadArray[processors-1]; 
+               
+               //Create processor worker threads.
+               for( int i=1; i<processors; i++ ){
+                       // Allocate memory for thread data.
+                       string extension = toString(i) + ".temp";
+                       
+                       uchimeData* tempUchime = new uchimeData(outputFName+extension, templatefile, filename+extension, fastafile, namefile, groupfile, accnos+extension, alns+extension, groups, m, lines[i].start, lines[i].end,  i);
+                       tempUchime->setBooleans(useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract);
+                       tempUchime->setVariables(abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract);
+                       
+                       pDataArray.push_back(tempUchime);
+                       processIDS.push_back(i);
+                       
+                       //MySeqSumThreadFunction is in header. It must be global or static to work with the threads.
+                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+                       hThreadArray[i-1] = CreateThread(NULL, 0, MyUchimeThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]);   
+               }
+               
                
+               //using the main process as a worker saves time and memory
+               num = driverGroups(parser, outputFName, filename, accnos, alns, lines[0].start, lines[0].end, groups);
+               
+               //Wait until all threads have terminated.
+               WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
+               
+               //Close all thread handles and free memory allocations.
+               for(int i=0; i < pDataArray.size(); i++){
+                       num += pDataArray[i]->count;
+                       CloseHandle(hThreadArray[i]);
+                       delete pDataArray[i];
+               }
+#endif         
                
+                               
                //append output files
                for(int i=0;i<processIDS.size();i++){
                        m->appendFiles((outputFName + toString(processIDS[i]) + ".temp"), outputFName);
index 1f86a98973ba8c88c20de4678866a70db35efe05..359b68c9c97f144f0914f4ff309c973ca2ec5d60 100644 (file)
@@ -64,6 +64,706 @@ private:
 };
 
 /***********************************************************/
+/**************************************************************************************************/
+//custom data structure for threads to use.
+// This is passed by void pointer so it can be any data type
+// that can be passed using a single void pointer (LPVOID).
+struct uchimeData {
+       string fastafile; 
+       string namefile; 
+       string groupfile;
+       string outputFName;
+       string accnos, alns, filename, templatefile;
+       MothurOut* m;
+       int start;
+       int end;
+       int threadID, count, numChimeras;
+       vector<string> groups;
+       bool useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
+       string abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract;
+       
+       uchimeData(){}
+       uchimeData(string o, string t, string file, string f, string n, string g, string ac,  string al, vector<string> gr, MothurOut* mout, int st, int en, int tid) {
+               fastafile = f;
+               namefile = n;
+               groupfile = g;
+               filename = file;
+               outputFName = o;
+               templatefile = t;
+               accnos = ac;
+               alns = al;
+               m = mout;
+               start = st;
+               end = en;
+               threadID = tid;
+               groups = gr;
+               count = 0;
+               numChimeras = 0;
+       }
+       void setBooleans(bool Abskew, bool calns, bool MinH, bool Mindiv, bool Xn, bool Dn, bool Xa, bool Chunks, bool Minchunk, bool Idsmoothwindow, bool Minsmoothid, bool Maxp, bool skipgap, bool skipgap2, bool Minlen, bool Maxlen, bool uc, bool Queryfract) {
+               useAbskew = Abskew;
+               chimealns = calns;
+               useMinH = MinH;
+               useMindiv = Mindiv;
+               useXn = Xn;
+               useDn = Dn;
+               useXa = Xa;
+               useChunks = Chunks;
+               useMinchunk = Minchunk;
+               useIdsmoothwindow = Idsmoothwindow;
+               useMinsmoothid = Minsmoothid;
+               useMaxp = Maxp;
+               skipgaps = skipgap;
+               skipgaps2 = skipgap2;
+               useMinlen = Minlen;
+               useMaxlen = Maxlen;
+               ucl = uc;
+               useQueryfract = Queryfract;
+       }
+       
+       void setVariables(string abske, string min, string mindi, string x, string d, string xa2, string chunk, string minchun, string idsmoothwindo, string minsmoothi, string max, string minle, string maxle, string queryfrac) {
+               abskew = abske;
+               minh = min;
+               mindiv = mindi;
+               xn = x;
+               dn = d;
+               xa = xa2;
+               chunks = chunk;
+               minchunk = minchun;
+               idsmoothwindow = idsmoothwindo;
+               minsmoothid = minsmoothi;
+               maxp = max;
+               minlen = minle;
+               maxlen = maxle;
+               queryfract = queryfrac;
+       }
+};
+
+/**************************************************************************************************/
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#else
+static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){ 
+       uchimeData* pDataArray;
+       pDataArray = (uchimeData*)lpParam;
+       
+       try {
+               
+               //clears files
+               ofstream out, out1, out2;
+               pDataArray->m->openOutputFile(pDataArray->outputFName, out); out.close(); 
+               pDataArray->m->openOutputFile(pDataArray->accnos, out1); out1.close();
+               if (pDataArray->chimealns) { pDataArray->m->openOutputFile(pDataArray->alns, out2); out2.close(); }
+               
+               //parse fasta and name file by group
+               SequenceParser* parser;
+               if (pDataArray->namefile != "") { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile, pDataArray->namefile);      }
+               else                                                    { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile);                                            }
+               
+               int totalSeqs = 0;
+               int numChimeras = 0;
+               
+               for (int i = pDataArray->start; i < pDataArray->end; i++) {
+                       int start = time(NULL);  if (pDataArray->m->control_pressed) {  delete parser; return 0; }
+                       
+                       int error = parser->getSeqs(pDataArray->groups[i], pDataArray->filename, true); if ((error == 1) || pDataArray->m->control_pressed) {  delete parser; return 0; }
+                       
+                       //int numSeqs = driver((outputFName + groups[i]), filename, (accnos+ groups[i]), (alns+ groups[i]), numChimeras);
+                       ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+                       
+                       //to allow for spaces in the path
+                       string outputFName = "\"" + pDataArray->outputFName+pDataArray->groups[i] + "\"";
+                       string filename = "\"" + pDataArray->filename + "\"";
+                       string alns = "\"" + pDataArray->alns+pDataArray->groups[i] + "\"";
+                       string accnos = pDataArray->accnos+pDataArray->groups[i];
+                       
+                       vector<char*> cPara;
+                       
+                       char* tempUchime;
+                       tempUchime= new char[8]; 
+                       *tempUchime = '\0';
+                       strncat(tempUchime, "uchime ", 7); 
+                       cPara.push_back(tempUchime);
+                       
+                       char* tempIn = new char[8]; 
+                       *tempIn = '\0'; strncat(tempIn, "--input", 7);
+                       //strcpy(tempIn, "--input"); 
+                       cPara.push_back(tempIn);
+                       char* temp = new char[filename.length()+1];
+                       *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
+                       //strcpy(temp, filename.c_str());
+                       cPara.push_back(temp);
+                       
+                       char* tempO = new char[12]; 
+                       *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
+                       //strcpy(tempO, "--uchimeout"); 
+                       cPara.push_back(tempO);
+                       char* tempout = new char[outputFName.length()+1];
+                       //strcpy(tempout, outputFName.c_str());
+                       *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
+                       cPara.push_back(tempout);
+                       
+                       if (pDataArray->chimealns) {
+                               char* tempA = new char[13]; 
+                               *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
+                               //strcpy(tempA, "--uchimealns"); 
+                               cPara.push_back(tempA);
+                               char* tempa = new char[alns.length()+1];
+                               //strcpy(tempa, alns.c_str());
+                               *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
+                               cPara.push_back(tempa);
+                       }
+                       
+                       if (pDataArray->useAbskew) {
+                               char* tempskew = new char[9];
+                               *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
+                               //strcpy(tempskew, "--abskew"); 
+                               cPara.push_back(tempskew);
+                               char* tempSkew = new char[pDataArray->abskew.length()+1];
+                               //strcpy(tempSkew, abskew.c_str());
+                               *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
+                               cPara.push_back(tempSkew);
+                       }
+                       
+                       if (pDataArray->useMinH) {
+                               char* tempminh = new char[7]; 
+                               *tempminh = '\0'; strncat(tempminh, "--minh", 6);
+                               //strcpy(tempminh, "--minh"); 
+                               cPara.push_back(tempminh);
+                               char* tempMinH = new char[pDataArray->minh.length()+1];
+                               *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
+                               //strcpy(tempMinH, minh.c_str());
+                               cPara.push_back(tempMinH);
+                       }
+                       
+                       if (pDataArray->useMindiv) {
+                               char* tempmindiv = new char[9]; 
+                               *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
+                               //strcpy(tempmindiv, "--mindiv"); 
+                               cPara.push_back(tempmindiv);
+                               char* tempMindiv = new char[pDataArray->mindiv.length()+1];
+                               *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
+                               //strcpy(tempMindiv, mindiv.c_str());
+                               cPara.push_back(tempMindiv);
+                       }
+                       
+                       if (pDataArray->useXn) {
+                               char* tempxn = new char[5]; 
+                               //strcpy(tempxn, "--xn"); 
+                               *tempxn = '\0'; strncat(tempxn, "--xn", 4);
+                               cPara.push_back(tempxn);
+                               char* tempXn = new char[pDataArray->xn.length()+1];
+                               //strcpy(tempXn, xn.c_str());
+                               *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
+                               cPara.push_back(tempXn);
+                       }
+                       
+                       if (pDataArray->useDn) {
+                               char* tempdn = new char[5]; 
+                               //strcpy(tempdn, "--dn"); 
+                               *tempdn = '\0'; strncat(tempdn, "--dn", 4);
+                               cPara.push_back(tempdn);
+                               char* tempDn = new char[pDataArray->dn.length()+1];
+                               *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
+                               //strcpy(tempDn, dn.c_str());
+                               cPara.push_back(tempDn);
+                       }
+                       
+                       if (pDataArray->useXa) {
+                               char* tempxa = new char[5]; 
+                               //strcpy(tempxa, "--xa"); 
+                               *tempxa = '\0'; strncat(tempxa, "--xa", 4);
+                               cPara.push_back(tempxa);
+                               char* tempXa = new char[pDataArray->xa.length()+1];
+                               *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
+                               //strcpy(tempXa, xa.c_str());
+                               cPara.push_back(tempXa);
+                       }
+                       
+                       if (pDataArray->useChunks) {
+                               char* tempchunks = new char[9]; 
+                               //strcpy(tempchunks, "--chunks"); 
+                               *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
+                               cPara.push_back(tempchunks);
+                               char* tempChunks = new char[pDataArray->chunks.length()+1];
+                               *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
+                               //strcpy(tempChunks, chunks.c_str());
+                               cPara.push_back(tempChunks);
+                       }
+                       
+                       if (pDataArray->useMinchunk) {
+                               char* tempminchunk = new char[11]; 
+                               //strcpy(tempminchunk, "--minchunk"); 
+                               *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
+                               cPara.push_back(tempminchunk);
+                               char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
+                               *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
+                               //strcpy(tempMinchunk, minchunk.c_str());
+                               cPara.push_back(tempMinchunk);
+                       }
+                       
+                       if (pDataArray->useIdsmoothwindow) {
+                               char* tempidsmoothwindow = new char[17]; 
+                               *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
+                               //strcpy(tempidsmoothwindow, "--idsmoothwindow"); 
+                               cPara.push_back(tempidsmoothwindow);
+                               char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
+                               *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
+                               //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
+                               cPara.push_back(tempIdsmoothwindow);
+                       }
+                       
+                       /*if (useMinsmoothid) {
+                        char* tempminsmoothid = new char[14]; 
+                        //strcpy(tempminsmoothid, "--minsmoothid"); 
+                        *tempminsmoothid = '\0'; strncat(tempminsmoothid, "--minsmoothid", 13);
+                        cPara.push_back(tempminsmoothid);
+                        char* tempMinsmoothid = new char[minsmoothid.length()+1];
+                        *tempMinsmoothid = '\0'; strncat(tempMinsmoothid, minsmoothid.c_str(), minsmoothid.length());
+                        //strcpy(tempMinsmoothid, minsmoothid.c_str());
+                        cPara.push_back(tempMinsmoothid);
+                        }*/
+                       
+                       if (pDataArray->useMaxp) {
+                               char* tempmaxp = new char[7]; 
+                               //strcpy(tempmaxp, "--maxp"); 
+                               *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
+                               cPara.push_back(tempmaxp);
+                               char* tempMaxp = new char[pDataArray->maxp.length()+1];
+                               *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
+                               //strcpy(tempMaxp, maxp.c_str());
+                               cPara.push_back(tempMaxp);
+                       }
+                       
+                       if (!pDataArray->skipgaps) {
+                               char* tempskipgaps = new char[13]; 
+                               //strcpy(tempskipgaps, "--[no]skipgaps");
+                               *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
+                               cPara.push_back(tempskipgaps);
+                       }
+                       
+                       if (!pDataArray->skipgaps2) {
+                               char* tempskipgaps2 = new char[14]; 
+                               //strcpy(tempskipgaps2, "--[no]skipgaps2"); 
+                               *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
+                               cPara.push_back(tempskipgaps2);
+                       }
+                       
+                       if (pDataArray->useMinlen) {
+                               char* tempminlen = new char[9]; 
+                               *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
+                               //strcpy(tempminlen, "--minlen"); 
+                               cPara.push_back(tempminlen);
+                               char* tempMinlen = new char[pDataArray->minlen.length()+1];
+                               //strcpy(tempMinlen, minlen.c_str());
+                               *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
+                               cPara.push_back(tempMinlen);
+                       }
+                       
+                       if (pDataArray->useMaxlen) {
+                               char* tempmaxlen = new char[9]; 
+                               //strcpy(tempmaxlen, "--maxlen"); 
+                               *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
+                               cPara.push_back(tempmaxlen);
+                               char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
+                               *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
+                               //strcpy(tempMaxlen, maxlen.c_str());
+                               cPara.push_back(tempMaxlen);
+                       }
+                       
+                       if (pDataArray->ucl) {
+                               char* tempucl = new char[5]; 
+                               strcpy(tempucl, "--ucl"); 
+                               cPara.push_back(tempucl);
+                       }
+                       
+                       if (pDataArray->useQueryfract) {
+                               char* tempqueryfract = new char[13]; 
+                               *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
+                               //strcpy(tempqueryfract, "--queryfract"); 
+                               cPara.push_back(tempqueryfract);
+                               char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
+                               *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
+                               //strcpy(tempQueryfract, queryfract.c_str());
+                               cPara.push_back(tempQueryfract);
+                       }
+                       
+                       
+                       char** uchimeParameters;
+                       uchimeParameters = new char*[cPara.size()];
+                       string commandString = "";
+                       for (int j = 0; j < cPara.size(); j++) {  uchimeParameters[j] = cPara[j];  commandString += toString(cPara[j]) + " "; } 
+                       //int numArgs = cPara.size();
+                       
+                       //uchime_main(numArgs, uchimeParameters); 
+                       //cout << "commandString = " << commandString << endl;
+                       system(commandString.c_str());
+                       
+                       //free memory
+                       for(int j = 0; j < cPara.size(); j++)  {  delete cPara[j];  }
+                       delete[] uchimeParameters; 
+                       
+                       //remove "" from filenames
+                       outputFName = outputFName.substr(1, outputFName.length()-2);
+                       filename = filename.substr(1, filename.length()-2);
+                       alns = alns.substr(1, alns.length()-2);
+                       
+                       if (pDataArray->m->control_pressed) { delete parser; return 0; }
+                       
+                       //create accnos file from uchime results
+                       ifstream in; 
+                       pDataArray->m->openInputFile(outputFName, in);
+                       
+                       ofstream out;
+                       pDataArray->m->openOutputFile(accnos, out);
+                       
+                       int num = 0;
+                       numChimeras = 0;
+                       while(!in.eof()) {
+                               
+                               if (pDataArray->m->control_pressed) { break; }
+                               
+                               string name = "";
+                               string chimeraFlag = "";
+                               in >> chimeraFlag >> name;
+                               
+                               //fix name 
+                               name = name.substr(0, name.length()-1); //rip off last /
+                               name = name.substr(0, name.find_last_of('/'));
+                               
+                               for (int j = 0; j < 15; j++) {  in >> chimeraFlag; }
+                               pDataArray->m->gobble(in);
+                               
+                               if (chimeraFlag == "Y") {  out << name << endl; numChimeras++; }
+                               num++;
+                       }
+                       in.close();
+                       out.close();
+                       
+                       
+                       ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+                       totalSeqs += num;
+                       pDataArray->numChimeras += numChimeras;
+                       
+                       if (pDataArray->m->control_pressed) { delete parser; return 0; }
+                       
+                       //remove file made for uchime
+                       pDataArray->m->mothurRemove(filename);
+                       
+                       //append files
+                       pDataArray->m->appendFiles(outputFName, pDataArray->outputFName); pDataArray->m->mothurRemove(outputFName);
+                       pDataArray->m->appendFiles(accnos, pDataArray->accnos); pDataArray->m->mothurRemove(accnos);
+                       if (pDataArray->chimealns) { pDataArray->m->appendFiles(alns, pDataArray->alns); pDataArray->m->mothurRemove(alns); }
+                       
+                       pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(num) + " sequences from group " + pDataArray->groups[i] + ".");    pDataArray->m->mothurOutEndLine();                                      
+                       
+               }       
+               
+               pDataArray->count = totalSeqs;
+               delete parser;
+               return totalSeqs;
+               
+       }
+       catch(exception& e) {
+               pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeThreadFunction");
+               exit(1);
+       }
+} 
+/**************************************************************************************************/
+
+static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){ 
+       uchimeData* pDataArray;
+       pDataArray = (uchimeData*)lpParam;
+       
+       try {
+               
+               int totalSeqs = 0;
+               int numChimeras = 0;
+       
+               int start = time(NULL);  if (pDataArray->m->control_pressed) { return 0; }
+                       
+               //to allow for spaces in the path
+               string outputFName = "\"" + pDataArray->outputFName + "\"";
+               string filename = "\"" + pDataArray->filename + "\"";
+               string alns = "\"" + pDataArray->alns+ "\"";
+               string templatefile = "\"" + pDataArray->templatefile + "\"";
+               string accnos = pDataArray->accnos;
+               
+               vector<char*> cPara;
+               
+               char* tempUchime;
+               tempUchime= new char[8]; 
+               *tempUchime = '\0';
+               strncat(tempUchime, "uchime ", 7); 
+               cPara.push_back(tempUchime);
+               
+               char* tempIn = new char[8]; 
+               *tempIn = '\0'; strncat(tempIn, "--input", 7);
+               //strcpy(tempIn, "--input"); 
+               cPara.push_back(tempIn);
+               char* temp = new char[filename.length()+1];
+               *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
+               //strcpy(temp, filename.c_str());
+               cPara.push_back(temp);
+       
+               //add reference file
+               char* tempRef = new char[5]; 
+               //strcpy(tempRef, "--db"); 
+               *tempRef = '\0'; strncat(tempRef, "--db", 4);
+               cPara.push_back(tempRef);  
+               char* tempR = new char[templatefile.length()+1];
+               //strcpy(tempR, templatefile.c_str());
+               *tempR = '\0'; strncat(tempR, templatefile.c_str(), templatefile.length());
+               cPara.push_back(tempR);
+               
+               char* tempO = new char[12]; 
+               *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
+               //strcpy(tempO, "--uchimeout"); 
+               cPara.push_back(tempO);
+               char* tempout = new char[outputFName.length()+1];
+               //strcpy(tempout, outputFName.c_str());
+               *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
+               cPara.push_back(tempout);
+               
+               if (pDataArray->chimealns) {
+                       char* tempA = new char[13]; 
+                       *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
+                       //strcpy(tempA, "--uchimealns"); 
+                       cPara.push_back(tempA);
+                       char* tempa = new char[alns.length()+1];
+                       //strcpy(tempa, alns.c_str());
+                       *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
+                       cPara.push_back(tempa);
+               }
+               
+               if (pDataArray->useAbskew) {
+                       char* tempskew = new char[9];
+                       *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
+                       //strcpy(tempskew, "--abskew"); 
+                       cPara.push_back(tempskew);
+                       char* tempSkew = new char[pDataArray->abskew.length()+1];
+                       //strcpy(tempSkew, abskew.c_str());
+                       *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
+                       cPara.push_back(tempSkew);
+               }
+               
+               if (pDataArray->useMinH) {
+                       char* tempminh = new char[7]; 
+                       *tempminh = '\0'; strncat(tempminh, "--minh", 6);
+                       //strcpy(tempminh, "--minh"); 
+                       cPara.push_back(tempminh);
+                       char* tempMinH = new char[pDataArray->minh.length()+1];
+                       *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
+                       //strcpy(tempMinH, minh.c_str());
+                       cPara.push_back(tempMinH);
+               }
+               
+               if (pDataArray->useMindiv) {
+                       char* tempmindiv = new char[9]; 
+                       *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
+                       //strcpy(tempmindiv, "--mindiv"); 
+                       cPara.push_back(tempmindiv);
+                       char* tempMindiv = new char[pDataArray->mindiv.length()+1];
+                       *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
+                       //strcpy(tempMindiv, mindiv.c_str());
+                       cPara.push_back(tempMindiv);
+               }
+               
+               if (pDataArray->useXn) {
+                       char* tempxn = new char[5]; 
+                       //strcpy(tempxn, "--xn"); 
+                       *tempxn = '\0'; strncat(tempxn, "--xn", 4);
+                       cPara.push_back(tempxn);
+                       char* tempXn = new char[pDataArray->xn.length()+1];
+                       //strcpy(tempXn, xn.c_str());
+                       *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
+                       cPara.push_back(tempXn);
+               }
+               
+               if (pDataArray->useDn) {
+                       char* tempdn = new char[5]; 
+                       //strcpy(tempdn, "--dn"); 
+                       *tempdn = '\0'; strncat(tempdn, "--dn", 4);
+                       cPara.push_back(tempdn);
+                       char* tempDn = new char[pDataArray->dn.length()+1];
+                       *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
+                       //strcpy(tempDn, dn.c_str());
+                       cPara.push_back(tempDn);
+               }
+               
+               if (pDataArray->useXa) {
+                       char* tempxa = new char[5]; 
+                       //strcpy(tempxa, "--xa"); 
+                       *tempxa = '\0'; strncat(tempxa, "--xa", 4);
+                       cPara.push_back(tempxa);
+                       char* tempXa = new char[pDataArray->xa.length()+1];
+                       *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
+                       //strcpy(tempXa, xa.c_str());
+                       cPara.push_back(tempXa);
+               }
+               
+               if (pDataArray->useChunks) {
+                       char* tempchunks = new char[9]; 
+                       //strcpy(tempchunks, "--chunks"); 
+                       *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
+                       cPara.push_back(tempchunks);
+                       char* tempChunks = new char[pDataArray->chunks.length()+1];
+                       *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
+                       //strcpy(tempChunks, chunks.c_str());
+                       cPara.push_back(tempChunks);
+               }
+               
+               if (pDataArray->useMinchunk) {
+                       char* tempminchunk = new char[11]; 
+                       //strcpy(tempminchunk, "--minchunk"); 
+                       *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
+                       cPara.push_back(tempminchunk);
+                       char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
+                       *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
+                       //strcpy(tempMinchunk, minchunk.c_str());
+                       cPara.push_back(tempMinchunk);
+               }
+               
+               if (pDataArray->useIdsmoothwindow) {
+                       char* tempidsmoothwindow = new char[17]; 
+                       *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
+                       //strcpy(tempidsmoothwindow, "--idsmoothwindow"); 
+                       cPara.push_back(tempidsmoothwindow);
+                       char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
+                       *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
+                       //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
+                       cPara.push_back(tempIdsmoothwindow);
+               }
+               
+               if (pDataArray->useMaxp) {
+                       char* tempmaxp = new char[7]; 
+                       //strcpy(tempmaxp, "--maxp"); 
+                       *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
+                       cPara.push_back(tempmaxp);
+                       char* tempMaxp = new char[pDataArray->maxp.length()+1];
+                       *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
+                       //strcpy(tempMaxp, maxp.c_str());
+                       cPara.push_back(tempMaxp);
+               }
+               
+               if (!pDataArray->skipgaps) {
+                       char* tempskipgaps = new char[13]; 
+                       //strcpy(tempskipgaps, "--[no]skipgaps");
+                       *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
+                       cPara.push_back(tempskipgaps);
+               }
+               
+               if (!pDataArray->skipgaps2) {
+                       char* tempskipgaps2 = new char[14]; 
+                       //strcpy(tempskipgaps2, "--[no]skipgaps2"); 
+                       *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
+                       cPara.push_back(tempskipgaps2);
+               }
+               
+               if (pDataArray->useMinlen) {
+                       char* tempminlen = new char[9]; 
+                       *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
+                       //strcpy(tempminlen, "--minlen"); 
+                       cPara.push_back(tempminlen);
+                       char* tempMinlen = new char[pDataArray->minlen.length()+1];
+                       //strcpy(tempMinlen, minlen.c_str());
+                       *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
+                       cPara.push_back(tempMinlen);
+               }
+               
+               if (pDataArray->useMaxlen) {
+                       char* tempmaxlen = new char[9]; 
+                       //strcpy(tempmaxlen, "--maxlen"); 
+                       *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
+                       cPara.push_back(tempmaxlen);
+                       char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
+                       *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
+                       //strcpy(tempMaxlen, maxlen.c_str());
+                       cPara.push_back(tempMaxlen);
+               }
+               
+               if (pDataArray->ucl) {
+                       char* tempucl = new char[5]; 
+                       strcpy(tempucl, "--ucl"); 
+                       cPara.push_back(tempucl);
+               }
+               
+               if (pDataArray->useQueryfract) {
+                       char* tempqueryfract = new char[13]; 
+                       *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
+                       //strcpy(tempqueryfract, "--queryfract"); 
+                       cPara.push_back(tempqueryfract);
+                       char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
+                       *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
+                       //strcpy(tempQueryfract, queryfract.c_str());
+                       cPara.push_back(tempQueryfract);
+               }
+               
+               
+               char** uchimeParameters;
+               uchimeParameters = new char*[cPara.size()];
+               string commandString = "";
+               for (int j = 0; j < cPara.size(); j++) {  uchimeParameters[j] = cPara[j];  commandString += toString(cPara[j]) + " "; } 
+               //int numArgs = cPara.size();
+               
+               //uchime_main(numArgs, uchimeParameters); 
+               //cout << "commandString = " << commandString << endl;
+               system(commandString.c_str());
+               
+               //free memory
+               for(int j = 0; j < cPara.size(); j++)  {  delete cPara[j];  }
+               delete[] uchimeParameters; 
+               
+               //remove "" from filenames
+               outputFName = outputFName.substr(1, outputFName.length()-2);
+               filename = filename.substr(1, filename.length()-2);
+               alns = alns.substr(1, alns.length()-2);
+               
+               if (pDataArray->m->control_pressed) { return 0; }
+               
+               //create accnos file from uchime results
+               ifstream in; 
+               pDataArray->m->openInputFile(outputFName, in);
+               
+               ofstream out;
+               pDataArray->m->openOutputFile(accnos, out);
+               
+               numChimeras = 0;
+               while(!in.eof()) {
+                       
+                       if (pDataArray->m->control_pressed) { break; }
+                       
+                       string name = "";
+                       string chimeraFlag = "";
+                       in >> chimeraFlag >> name;
+                       
+                       for (int j = 0; j < 15; j++) {  in >> chimeraFlag; }
+                       pDataArray->m->gobble(in);
+                       
+                       if (chimeraFlag == "Y") {  out << name << endl; numChimeras++; }
+                       totalSeqs++;
+               }
+               in.close();
+               out.close();
+               
+               if (pDataArray->m->control_pressed) { return 0; }
+               
+               pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(totalSeqs) + " sequences.");       pDataArray->m->mothurOutEndLine();                                      
+       
+               pDataArray->count = totalSeqs;
+               pDataArray->numChimeras = numChimeras;
+               return totalSeqs;
+               
+       }
+       catch(exception& e) {
+               pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeSeqsThreadFunction");
+               exit(1);
+       }
+} 
+
+#endif
+
+/**************************************************************************************************/
+
 
 #endif
 
index 58de96937d995d5eb8a2169fcda3950a5f34b4d2..eef96ffbe5d32f88f9f9552165b299f0247505dc 100644 (file)
@@ -89,7 +89,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct classifyData {
+struct classifyData {
        string taxFName; 
        string tempTFName; 
        string filename;
index 9742bcbd3b0ea952e3a5b5b54428bee701c5191f..2f6f810e0add659c6c661cef7e383fd36b2f8ad2 100644 (file)
@@ -40,7 +40,7 @@ inline bool compareGroup(repStruct left, repStruct right){
 vector<string> GetOTURepCommand::setParameters(){      
        try {
                CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist);
-               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta);
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta);
                CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
                CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip);
                CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname);
@@ -68,7 +68,7 @@ vector<string> GetOTURepCommand::setParameters(){
 string GetOTURepCommand::getHelpString(){      
        try {
                string helpString = "";
-               helpString += "The get.oturep command parameters are phylip, column, list, fasta, name, group, large, weighted, cutoff, precision, groups, sorted and label.  The fasta and list parameters are required, as well as phylip or column and name, unless you have valid current files.\n";
+               helpString += "The get.oturep command parameters are phylip, column, list, fasta, name, group, large, weighted, cutoff, precision, groups, sorted and label.  The list parameter is required, as well as phylip or column and name, unless you have valid current files.\n";
                helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n";
                helpString += "The phylip or column parameter is required, but only one may be used.  If you use a column file the name filename is required. \n";
                helpString += "If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n";
@@ -197,11 +197,7 @@ GetOTURepCommand::GetOTURepCommand(string option)  {
                        
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
-                       if (fastafile == "not found") {                                 
-                               fastafile = m->getFastaFile(); 
-                               if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
-                               else {  m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
-                       }
+                       if (fastafile == "not found") { fastafile = ""; }
                        else if (fastafile == "not open") { abort = true; }     
                        else { m->setFastaFile(fastafile); }
                
@@ -537,21 +533,30 @@ int GetOTURepCommand::execute(){
                
                if (!weighted) { nameFileMap.clear(); }
                
-               //read fastafile
-               fasta = new FastaMap();
-               fasta->readFastaFile(fastafile);
-               
-               //if user gave a namesfile then use it
-               if (namefile != "") {   readNamesFile();        }
-               
-               //output create and output the .rep.fasta files
-               map<string, string>::iterator itNameFile;
-               for (itNameFile = outputNameFiles.begin(); itNameFile != outputNameFiles.end(); itNameFile++) {
-                       processNames(itNameFile->first, itNameFile->second);
+                               
+               if (fastafile != "") {
+                       //read fastafile
+                       fasta = new FastaMap();
+                       fasta->readFastaFile(fastafile);
+                       
+                       //if user gave a namesfile then use it
+                       if (namefile != "") {   readNamesFile();        }
+                       
+                       //output create and output the .rep.fasta files
+                       map<string, string>::iterator itNameFile;
+                       for (itNameFile = outputNameFiles.begin(); itNameFile != outputNameFiles.end(); itNameFile++) {
+                               processFastaNames(itNameFile->first, itNameFile->second);
+                       }
+               }else {
+                       //output create and output the .rep.fasta files
+                       map<string, string>::iterator itNameFile;
+                       for (itNameFile = outputNameFiles.begin(); itNameFile != outputNameFiles.end(); itNameFile++) {
+                               processNames(itNameFile->first, itNameFile->second);
+                       }
                }
                
-               delete fasta;
-               if (groupfile != "") { delete groupMap;  }
+                               
+               if (groupfile != "") { delete groupMap; }
                
                if (m->control_pressed) {  return 0; }
                
@@ -858,7 +863,7 @@ int GetOTURepCommand::process(ListVector* processList) {
        }
 }
 //**********************************************************************************************************************
-int GetOTURepCommand::processNames(string filename, string label) {
+int GetOTURepCommand::processFastaNames(string filename, string label) {
        try{
 
                //create output file
@@ -962,6 +967,40 @@ int GetOTURepCommand::processNames(string filename, string label) {
                return 0;
 
        }
+       catch(exception& e) {
+               m->errorOut(e, "GetOTURepCommand", "processFastaNames");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int GetOTURepCommand::processNames(string filename, string label) {
+       try{
+               
+               //create output file
+               if (outputDir == "") { outputDir += m->hasPath(listfile); }
+               
+               ofstream out2;
+               string tempNameFile = filename + ".temp";
+               m->openOutputFile(tempNameFile, out2);
+               
+               ifstream in;
+               m->openInputFile(filename, in);
+               
+               int i = 0;
+               string rep, binnames;
+               while (!in.eof()) {
+                       if (m->control_pressed) { break; }
+                       in >> i >> rep >> binnames; m->gobble(in);
+                       out2 << rep << '\t' << binnames << endl;
+               }
+               in.close();
+               out2.close();
+               
+               m->mothurRemove(filename);
+               rename(tempNameFile.c_str(), filename.c_str());
+               
+               return 0;
+       }
        catch(exception& e) {
                m->errorOut(e, "GetOTURepCommand", "processNames");
                exit(1);
index 07cccde36aaae2e7c0f8f3687901caaa02557974..41680008c7dc27b28eb7e9a50ea8e9e621bfeb72 100644 (file)
@@ -81,6 +81,7 @@ private:
        SeqMap getMap(int);
        string findRep(vector<string>);         // returns the name of the "representative" sequence of given bin or subset of a bin, for groups
        int processNames(string, string);
+       int processFastaNames(string, string);
 };
 
 #endif
index 1920221fd8c64a0c98e21c8ba71c19e7e49e906b..90d6f37434d7cb4df231817be6d1759df80b45bb 100644 (file)
@@ -434,7 +434,7 @@ void MothurOut::gobble(istream& f){
                
                char d;
                while(isspace(d=f.get()))               { ;}
-               f.putback(d);
+               if(!f.eof()) { f.putback(d); }
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "gobble");
@@ -446,7 +446,7 @@ void MothurOut::gobble(istringstream& f){
        try {
                char d;
                while(isspace(d=f.get()))               {;}
-               f.putback(d);
+               if(!f.eof()) { f.putback(d); }
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "gobble");
index 6e10a85ce27e6b6448b8416060b1b151a48428f9..226b0f63560b04348ea425290c98b48b1abc4de6 100755 (executable)
 #include <signal.h>\r
 #include <float.h>\r
 \r
-#ifdef _MSC_VER\r
-#include <crtdbg.h>\r
-#include <process.h>\r
-#include <windows.h>\r
-#include <psapi.h>\r
-#include <io.h>\r
-#else\r
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
 #include <sys/time.h>\r
 #include <sys/resource.h>\r
 #include <unistd.h>\r
 #include <errno.h>\r
 #include <fcntl.h>\r
 #include <stdlib.h>\r
+#else\r
+//#include <crtdbg.h>\r
+#include <process.h>\r
+#include <windows.h>\r
+#include <psapi.h>\r
+#include <io.h>\r
 #endif\r
 \r
 #include "myutils.h"\r
@@ -46,11 +46,11 @@ static double g_PeakMemUseBytes;
 \r
 #if    TEST_UTILS\r
 void TestUtils()\r
-       {\r
+{\r
        const int C = 100000000;\r
        for (int i = 0; i < C; ++i)\r
                ProgressStep(i, C, "something or other");\r
-\r
+       \r
        Progress("\n");\r
        Progress("Longer message\r");\r
        Sleep(1000);\r
@@ -63,30 +63,30 @@ void TestUtils()
        const unsigned N = 10;\r
        unsigned M = 10;\r
        for (unsigned i = 0; i < N; ++i)\r
-               {\r
+       {\r
                ProgressStep(i, N, "Allocating 1MB blocks");\r
                for (unsigned j = 0; j < M; ++j)\r
-                       {\r
+               {\r
                        ProgressStep(j, M, "Inner loop"); \r
                        malloc(100000);\r
                        Sleep(500);\r
-                       }\r
                }\r
        }\r
+}\r
 #endif // TEST_UTILS\r
 \r
 static void AllocBuffer(FILE *f)\r
-       {\r
+{\r
        int fd = fileno(f);\r
        if (fd < 0 || fd >= 256)\r
                return;\r
        if (g_IOBuffers[fd] == 0)\r
                g_IOBuffers[fd] = myalloc(char, MY_IO_BUFSIZ);\r
        setvbuf(f, g_IOBuffers[fd], _IOFBF, MY_IO_BUFSIZ);\r
-       }\r
+}\r
 \r
 static void FreeBuffer(FILE *f)\r
-       {\r
+{\r
        int fd = fileno(f);\r
        if (fd < 0 || fd >= 256)\r
                return;\r
@@ -94,12 +94,12 @@ static void FreeBuffer(FILE *f)
                return;\r
        myfree(g_IOBuffers[fd]);\r
        g_IOBuffers[fd] = 0;\r
-       }\r
+}\r
 \r
 unsigned GetElapsedSecs()\r
-       {\r
+{\r
        return (unsigned) (time(0) - g_StartTime);\r
-       }\r
+}\r
 \r
 static unsigned g_NewCalls;\r
 static unsigned g_FreeCalls;\r
@@ -110,7 +110,7 @@ static double g_NetBytes;
 static double g_MaxNetBytes;\r
 \r
 void LogAllocStats()\r
-       {\r
+{\r
        Log("\n");\r
        Log("       Allocs  %u\n", g_NewCalls);\r
        Log("        Frees  %u\n", g_FreeCalls);\r
@@ -120,37 +120,47 @@ void LogAllocStats()
        Log("    Net bytes  %s\n", MemBytesToStr(g_NetBytes));\r
        Log("Max net bytes  %s\n", MemBytesToStr(g_MaxNetBytes));\r
        Log("   Peak total  %s\n", MemBytesToStr(g_MaxNetBytes + g_InitialMemUseBytes));\r
-       }\r
+}\r
 \r
 bool StdioFileExists(const string &FileName)\r
-       {\r
+{\r
        struct stat SD;\r
        int i = stat(FileName.c_str(), &SD);\r
        return i == 0;\r
-       }\r
+}\r
 \r
 void myassertfail(const char *Exp, const char *File, unsigned Line)\r
-       {\r
+{\r
        Die("%s(%u) assert failed: %s", File, Line, Exp);\r
-       }\r
+}\r
 \r
 bool myisatty(int fd)\r
-       {\r
+{\r
        return isatty(fd) != 0;\r
-       }\r
+}\r
 \r
-#ifdef _MSC_VER\r
-#include <io.h>\r
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
+#else\r
+//#ifdef BIT_VERSION\r
+//#include <io.h>\r
+//int fseeko(FILE *stream, off_t offset, int whence)\r
+////   {\r
+//     off_t FilePos = _fseeki64(stream, offset, whence);\r
+//     return (FilePos == -1L) ? -1 : 0;\r
+//     }\r
+//#define ftello(fm) (off_t) _ftelli64(fm)\r
+//#else \r
 int fseeko(FILE *stream, off_t offset, int whence)\r
-       {\r
-       off_t FilePos = _fseeki64(stream, offset, whence);\r
+{\r
+       off_t FilePos = fseek(stream, offset, whence);\r
        return (FilePos == -1L) ? -1 : 0;\r
-       }\r
-#define ftello(fm) (off_t) _ftelli64(fm)\r
+}\r
+#define ftello(fm) (off_t) ftell(fm)\r
+//#endif\r
 #endif\r
 \r
 void LogStdioFileState(FILE *f)\r
-       {\r
+{\r
        unsigned long tellpos = (unsigned long) ftello(f);\r
        long fseek_pos = fseek(f, 0, SEEK_CUR);\r
        int fd = fileno(f);\r
@@ -164,95 +174,102 @@ void LogStdioFileState(FILE *f)
        fpos_t fpos;\r
        int fgetpos_retval = fgetpos(f, &fpos);\r
        Log("fpos       %ld (retval %d)\n", (long) fpos, fgetpos_retval);\r
-//     Log("eof        %d\n", _eof(fd));\r
+       //      Log("eof        %d\n", _eof(fd));\r
 #endif\r
-#ifdef _MSC_VER\r
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
+#else\r
+#ifdef BIT_VERSION\r
        __int64 pos64 = _ftelli64(f);\r
        Log("_ftelli64  %lld\n", pos64);\r
+#else\r
+       __int32 pos32 = ftell(f);\r
+       Log("ftell  %lld\n", pos32);\r
+       \r
 #endif\r
-       }\r
+#endif\r
+}\r
 \r
 FILE *OpenStdioFile(const string &FileName)\r
-       {\r
+{\r
        const char *Mode = "rb";\r
        FILE *f = fopen(FileName.c_str(), Mode);\r
        if (f == 0)\r
-               {\r
+       {\r
                if (errno == EFBIG)\r
-                       {\r
+               {\r
                        if (sizeof(off_t) == 4)\r
                                Die("File too big, off_t is 32 bits, recompile needed");\r
                        else\r
                                Die("Cannot open '%s', file too big (off_t=%u bits)",\r
-                                 FileName.c_str(), sizeof(off_t)*8);\r
-                       }\r
-               Die("Cannot open %s, errno=%d %s",\r
-                 FileName.c_str(), errno, strerror(errno));\r
+                                       FileName.c_str(), sizeof(off_t)*8);\r
                }\r
+               Die("Cannot open %s, errno=%d %s",\r
+                       FileName.c_str(), errno, strerror(errno));\r
+       }\r
        AllocBuffer(f);\r
        return f;\r
-       }\r
+}\r
 \r
 FILE *CreateStdioFile(const string &FileName)\r
-       {\r
+{\r
        FILE *f = fopen(FileName.c_str(), "wb+");\r
        if (0 == f)\r
                Die("Cannot create %s, errno=%d %s",\r
-                 FileName.c_str(), errno, strerror(errno));\r
+                       FileName.c_str(), errno, strerror(errno));\r
        AllocBuffer(f);\r
        return f;\r
-       }\r
+}\r
 \r
 void SetStdioFilePos(FILE *f, off_t Pos)\r
-       {\r
+{\r
        if (0 == f)\r
                Die("SetStdioFilePos failed, f=NULL");\r
        int Ok = fseeko(f, Pos, SEEK_SET);\r
        off_t NewPos = ftello(f);\r
        if (Ok != 0 || Pos != NewPos)\r
-               {\r
+       {\r
                LogStdioFileState(f);\r
                Die("SetStdioFilePos(%d) failed, Ok=%d NewPos=%d",\r
-                 (int) Pos, Ok, (int) NewPos);\r
-               }\r
+                       (int) Pos, Ok, (int) NewPos);\r
        }\r
+}\r
 \r
 void ReadStdioFile(FILE *f, off_t Pos, void *Buffer, unsigned Bytes)\r
-       {\r
+{\r
        if (0 == f)\r
                Die("ReadStdioFile failed, f=NULL");\r
        SetStdioFilePos(f, Pos);\r
        unsigned BytesRead = fread(Buffer, 1, Bytes, f);\r
        if (BytesRead != Bytes)\r
-               {\r
+       {\r
                LogStdioFileState(f);\r
                Die("ReadStdioFile failed, attempted %d bytes, read %d bytes, errno=%d",\r
-                 (int) Bytes, (int) BytesRead, errno);\r
-               }\r
+                       (int) Bytes, (int) BytesRead, errno);\r
        }\r
+}\r
 \r
 void ReadStdioFile(FILE *f, void *Buffer, unsigned Bytes)\r
-       {\r
+{\r
        if (0 == f)\r
                Die("ReadStdioFile failed, f=NULL");\r
        unsigned BytesRead = fread(Buffer, 1, Bytes, f);\r
        if (BytesRead != Bytes)\r
-               {\r
+       {\r
                LogStdioFileState(f);\r
                Die("ReadStdioFile failed, attempted %d bytes, read %d bytes, errno=%d",\r
-                 (int) Bytes, (int) BytesRead, errno);\r
-               }\r
+                       (int) Bytes, (int) BytesRead, errno);\r
        }\r
+}\r
 \r
 // Return values from functions like lseek, ftell, fgetpos are\r
 // "undefined" for files that cannot seek. Attempt to detect\r
 // whether a file can seek by checking for error returns.\r
 bool CanSetStdioFilePos(FILE *f)\r
-       {\r
-// Common special cases\r
+{\r
+       // Common special cases\r
        if (f == stdin || f == stdout || f == stderr)\r
                return false;\r
-\r
+       \r
        fpos_t CurrPos;\r
        int ok1 = fgetpos(f, &CurrPos);\r
        if (ok1 < 0)\r
@@ -266,14 +283,14 @@ bool CanSetStdioFilePos(FILE *f)
        if (!ok3 || !ok4)\r
                return false;\r
        return true;\r
-       }\r
+}\r
 \r
 byte *ReadAllStdioFile(FILE *f, unsigned &FileSize)\r
-       {\r
+{\r
        const unsigned BUFF_SIZE = 1024*1024;\r
-\r
+       \r
        if (CanSetStdioFilePos(f))\r
-               {\r
+       {\r
                off_t Pos = GetStdioFilePos(f);\r
                off_t FileSize = GetStdioFileSize(f);\r
                if (FileSize > UINT_MAX)\r
@@ -284,51 +301,51 @@ byte *ReadAllStdioFile(FILE *f, unsigned &FileSize)
                SetStdioFilePos(f, Pos);\r
                FileSize = unsigned(FileSize);\r
                return Buffer;\r
-               }\r
-\r
-// Can't seek, read one buffer at a time.\r
+       }\r
+       \r
+       // Can't seek, read one buffer at a time.\r
        FileSize = 0;\r
-\r
-// Just to initialize so that first call to realloc works.\r
+       \r
+       // Just to initialize so that first call to realloc works.\r
        byte *Buffer = (byte *) malloc(4);\r
        if (Buffer == 0)\r
                Die("ReadAllStdioFile, out of memory");\r
        for (;;)\r
-               {\r
+       {\r
                Buffer = (byte *) realloc(Buffer, FileSize + BUFF_SIZE);\r
                unsigned BytesRead = fread(Buffer + FileSize, 1, BUFF_SIZE, f);\r
                FileSize += BytesRead;\r
                if (BytesRead < BUFF_SIZE)\r
-                       {\r
+               {\r
                        Buffer = (byte *) realloc(Buffer, FileSize);\r
                        return Buffer;\r
-                       }\r
                }\r
        }\r
+}\r
 \r
 byte *ReadAllStdioFile(const std::string &FileName, off_t &FileSize)\r
-       {\r
+{\r
 #if    WIN32\r
        FILE *f = OpenStdioFile(FileName);\r
        FileSize = GetStdioFileSize(f);\r
        CloseStdioFile(f);\r
-\r
+       \r
        HANDLE h = CreateFile(FileName.c_str(), GENERIC_READ, FILE_SHARE_READ,\r
-         NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r
+                                                 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r
        if (h == INVALID_HANDLE_VALUE)\r
                Die("ReadAllStdioFile:Open(%s) failed", FileName.c_str());\r
-\r
+       \r
        unsigned uFileSize = (unsigned) FileSize;\r
        if ((off_t) uFileSize != FileSize)\r
                Die("File too big (%.1f Gb): %s", double(FileSize)/1e9, FileName.c_str());\r
-\r
+       \r
        byte *Buffer = myalloc(byte, uFileSize);\r
        DWORD BytesRead;\r
        ReadFile(h, Buffer, uFileSize, &BytesRead, NULL);\r
        if (FileSize != BytesRead)\r
                Die("ReadAllStdioFile:Error reading %s, attempted %u got %u",\r
-                 FileName.c_str(), FileSize, (unsigned) BytesRead);\r
-\r
+                       FileName.c_str(), FileSize, (unsigned) BytesRead);\r
+       \r
        CloseHandle(h);\r
        return Buffer;\r
 #else\r
@@ -349,56 +366,56 @@ byte *ReadAllStdioFile(const std::string &FileName, off_t &FileSize)
        size_t n = read(h, Buffer, stBytes);\r
        if (n != FileSize)\r
                Die("ReadAllStdioFile, Error reading %s, attempted %g got %g",\r
-                 FileName.c_str(), (double) FileSize, (double) n);\r
+                       FileName.c_str(), (double) FileSize, (double) n);\r
        close(h);\r
        return Buffer;\r
 #endif\r
-       }\r
+}\r
 \r
 void WriteStdioFile(FILE *f, off_t Pos, const void *Buffer, unsigned Bytes)\r
-       {\r
+{\r
        if (0 == f)\r
                Die("WriteStdioFile failed, f=NULL");\r
        SetStdioFilePos(f, Pos);\r
        unsigned BytesWritten = fwrite(Buffer, 1, Bytes, f);\r
        if (BytesWritten != Bytes)\r
-               {\r
+       {\r
                LogStdioFileState(f);\r
                Die("WriteStdioFile failed, attempted %d bytes, wrote %d bytes, errno=%d",\r
-                 (int) Bytes, (int) BytesWritten, errno);\r
-               }\r
+                       (int) Bytes, (int) BytesWritten, errno);\r
        }\r
+}\r
 \r
 void WriteStdioFile(FILE *f, const void *Buffer, unsigned Bytes)\r
-       {\r
+{\r
        if (0 == f)\r
                Die("WriteStdioFile failed, f=NULL");\r
        unsigned BytesWritten = fwrite(Buffer, 1, Bytes, f);\r
        if (BytesWritten != Bytes)\r
-               {\r
+       {\r
                LogStdioFileState(f);\r
                Die("WriteStdioFile failed, attempted %d bytes, wrote %d bytes, errno=%d",\r
-                 (int) Bytes, (int) BytesWritten, errno);\r
-               }\r
+                       (int) Bytes, (int) BytesWritten, errno);\r
        }\r
+}\r
 \r
 // Return false on EOF, true if line successfully read.\r
 bool ReadLineStdioFile(FILE *f, char *Line, unsigned Bytes)\r
-       {\r
+{\r
        if (feof(f))\r
                return false;\r
        if ((int) Bytes < 0)\r
                Die("ReadLineStdioFile: Bytes < 0");\r
        char *RetVal = fgets(Line, (int) Bytes, f);\r
        if (NULL == RetVal)\r
-               {\r
+       {\r
                if (feof(f))\r
                        return false;\r
                if (ferror(f))\r
                        Die("ReadLineStdioFile: errno=%d", errno);\r
                Die("ReadLineStdioFile: fgets=0, feof=0, ferror=0");\r
-               }\r
-\r
+       }\r
+       \r
        if (RetVal != Line)\r
                Die("ReadLineStdioFile: fgets != Buffer");\r
        unsigned n = strlen(Line);\r
@@ -409,37 +426,37 @@ bool ReadLineStdioFile(FILE *f, char *Line, unsigned Bytes)
        if (n > 1 && (Line[n-2] == '\r' || Line[n-2] == '\n'))\r
                Line[n-2] = 0;\r
        return true;\r
-       }\r
+}\r
 \r
 // Return false on EOF, true if line successfully read.\r
 bool ReadLineStdioFile(FILE *f, string &Line)\r
-       {\r
+{\r
        Line.clear();\r
        for (;;)\r
-               {\r
+       {\r
                int c = fgetc(f);\r
                if (c == -1)\r
-                       {\r
+               {\r
                        if (feof(f))\r
-                               {\r
+                       {\r
                                if (!Line.empty())\r
                                        return true;\r
                                return false;\r
-                               }\r
-                       Die("ReadLineStdioFile, errno=%d", errno);\r
                        }\r
+                       Die("ReadLineStdioFile, errno=%d", errno);\r
+               }\r
                if (c == '\r')\r
                        continue;\r
                if (c == '\n')\r
                        return true;\r
                Line.push_back((char) c);\r
-               }\r
        }\r
+}\r
 \r
 // Copies all of fFrom regardless of current\r
 // file position, appends to fTo.\r
 void AppendStdioFileToFile(FILE *fFrom, FILE *fTo)\r
-       {\r
+{\r
        off_t SavedFromPos = GetStdioFilePos(fFrom);\r
        off_t FileSize = GetStdioFileSize(fFrom);\r
        const off_t BUFF_SIZE = 1024*1024;\r
@@ -447,108 +464,109 @@ void AppendStdioFileToFile(FILE *fFrom, FILE *fTo)
        SetStdioFilePos(fFrom, 0);\r
        off_t BytesRemaining = FileSize;\r
        while (BytesRemaining > 0)\r
-               {\r
+       {\r
                off_t BytesToRead = BytesRemaining;\r
                if (BytesToRead > BUFF_SIZE)\r
                        BytesToRead = BUFF_SIZE;\r
                ReadStdioFile(fFrom, Buffer, (unsigned) BytesToRead);\r
                WriteStdioFile(fTo, Buffer, (unsigned) BytesToRead);\r
                BytesRemaining -= BytesToRead;\r
-               }\r
-       SetStdioFilePos(fFrom, SavedFromPos);\r
        }\r
+       SetStdioFilePos(fFrom, SavedFromPos);\r
+}\r
 \r
 void RenameStdioFile(const string &FileNameFrom, const string &FileNameTo)\r
-       {\r
+{\r
        int Ok = rename(FileNameFrom.c_str(), FileNameTo.c_str());\r
        if (Ok != 0)\r
                Die("RenameStdioFile(%s,%s) failed, errno=%d %s",\r
-                 FileNameFrom.c_str(), FileNameTo.c_str(), errno, strerror(errno));\r
-       }\r
+                       FileNameFrom.c_str(), FileNameTo.c_str(), errno, strerror(errno));\r
+}\r
 \r
 void FlushStdioFile(FILE *f)\r
-       {\r
+{\r
        int Ok = fflush(f);\r
        if (Ok != 0)\r
                Die("fflush(%p)=%d,", f, Ok);\r
-       }\r
+}\r
 \r
 void CloseStdioFile(FILE *f)\r
-       {\r
+{\r
        if (f == 0)\r
                return;\r
        int Ok = fclose(f);\r
        if (Ok != 0)\r
                Die("fclose(%p)=%d", f, Ok);\r
        FreeBuffer(f);\r
-       }\r
+}\r
 \r
 off_t GetStdioFilePos(FILE *f)\r
-       {\r
+{\r
        off_t FilePos = ftello(f);\r
        if (FilePos < 0)\r
                Die("ftello=%d", (int) FilePos);\r
        return FilePos;\r
-       }\r
+}\r
 \r
 off_t GetStdioFileSize(FILE *f)\r
-       {\r
+{\r
        off_t CurrentPos = GetStdioFilePos(f);\r
-       int Ok = fseeko(f, 0, SEEK_END);\r
+       off_t zeroPos = 0;\r
+       int Ok = fseeko(f, zeroPos, SEEK_END);\r
        if (Ok < 0)\r
                Die("fseek in GetFileSize");\r
-\r
+       \r
        off_t Length = ftello(f);\r
        if (Length < 0)\r
                Die("ftello in GetFileSize");\r
        SetStdioFilePos(f, CurrentPos);\r
        return Length;\r
-       }\r
+}\r
 \r
 void DeleteStdioFile(const string &FileName)\r
-       {\r
+{\r
        int Ok = remove(FileName.c_str());\r
        if (Ok != 0)\r
                Die("remove(%s) failed, errno=%d %s", FileName.c_str(), errno, strerror(errno));\r
-       }\r
+}\r
 \r
 void myvstrprintf(string &Str, const char *Format, va_list ArgList)\r
-       {\r
+{\r
        static char szStr[MAX_FORMATTED_STRING_LENGTH];\r
        vsnprintf(szStr, MAX_FORMATTED_STRING_LENGTH-1, Format, ArgList);\r
        szStr[MAX_FORMATTED_STRING_LENGTH - 1] = '\0';\r
        Str.assign(szStr);\r
-       }\r
+}\r
 \r
 void myvstrprintf(string &Str, const char *Format, ...)\r
-       {\r
+{\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        myvstrprintf(Str, Format, ArgList);\r
        va_end(ArgList);\r
-       }\r
+}\r
 \r
 FILE *g_fLog = 0;\r
 \r
 void SetLogFileName(const string &FileName)\r
-       {\r
+{\r
        if (g_fLog != 0)\r
                CloseStdioFile(g_fLog);\r
        g_fLog = 0;\r
        if (FileName.empty())\r
                return;\r
        g_fLog = CreateStdioFile(FileName);\r
-       }\r
+}\r
 \r
 void Log(const char *Format, ...)\r
-       {\r
+{\r
        if (g_fLog == 0)\r
                return;\r
-\r
+       \r
        static bool InLog = false;\r
        if (InLog)\r
                return;\r
-\r
+       \r
        InLog = true;\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
@@ -556,97 +574,85 @@ void Log(const char *Format, ...)
        va_end(ArgList);\r
        fflush(g_fLog);\r
        InLog = false;\r
-       }\r
+}\r
 \r
 void Die(const char *Format, ...)\r
-       {\r
+{\r
        static bool InDie = false;\r
        if (InDie)\r
                exit(1);\r
        InDie = true;\r
        string Msg;\r
-\r
+       \r
        if (g_fLog != 0)\r
                setbuf(g_fLog, 0);\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        myvstrprintf(Msg, Format, ArgList);\r
        va_end(ArgList);\r
-\r
+       \r
        fprintf(stderr, "\n\n");\r
        Log("\n");\r
        time_t t = time(0);\r
        Log("%s", asctime(localtime(&t)));\r
        for (unsigned i = 0; i < g_Argv.size(); i++)\r
-               {\r
+       {\r
                fprintf(stderr, (i == 0) ? "%s" : " %s", g_Argv[i].c_str());\r
                Log((i == 0) ? "%s" : " %s", g_Argv[i].c_str());\r
-               }\r
+       }\r
        fprintf(stderr, "\n");\r
        Log("\n");\r
-\r
+       \r
        time_t CurrentTime = time(0);\r
        unsigned ElapsedSeconds = unsigned(CurrentTime - g_StartTime);\r
        const char *sstr = SecsToStr(ElapsedSeconds);\r
        Log("Elapsed time: %s\n", sstr);\r
-\r
+       \r
        const char *szStr = Msg.c_str();\r
        fprintf(stderr, "\n---Fatal error---\n%s\n", szStr);\r
        Log("\n---Fatal error---\n%s\n", szStr);\r
-\r
-#ifdef _MSC_VER\r
-       if (IsDebuggerPresent())\r
-               __debugbreak();\r
-       _CrtSetDbgFlag(0);\r
+       \r
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
+#else\r
+       //if (IsDebuggerPresent())\r
+       //      __debugbreak();\r
+       //_CrtSetDbgFlag(0);\r
 #endif\r
-\r
+       \r
        exit(1);\r
-       }\r
+}\r
 \r
 void Warning(const char *Format, ...)\r
-       {\r
+{\r
        string Msg;\r
-\r
+       \r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        myvstrprintf(Msg, Format, ArgList);\r
        va_end(ArgList);\r
-\r
+       \r
        const char *szStr = Msg.c_str();\r
-\r
+       \r
        fprintf(stderr, "\nWARNING: %s\n", szStr);\r
        if (g_fLog != stdout)\r
-               {\r
+       {\r
                Log("\nWARNING: %s\n", szStr);\r
                fflush(g_fLog);\r
-               }\r
        }\r
+}\r
 \r
-#ifdef _MSC_VER\r
-double GetMemUseBytes()\r
-       {\r
-       HANDLE hProc = GetCurrentProcess();\r
-       PROCESS_MEMORY_COUNTERS PMC;\r
-       BOOL bOk = GetProcessMemoryInfo(hProc, &PMC, sizeof(PMC));\r
-       if (!bOk)\r
-               return 1000000;\r
-       double Bytes = (double) PMC.WorkingSetSize;\r
-       if (Bytes > g_PeakMemUseBytes)\r
-               g_PeakMemUseBytes = Bytes;\r
-       return Bytes;\r
-       }\r
-#elif  linux || __linux__\r
+#if defined linux || __linux__\r
 double GetMemUseBytes()\r
-       {\r
+{\r
        static char statm[64];\r
        static int PageSize = 1;\r
        if (0 == statm[0])\r
-               {\r
+       {\r
                PageSize = sysconf(_SC_PAGESIZE);\r
                pid_t pid = getpid();\r
                sprintf(statm, "/proc/%d/statm", (int) pid);\r
-               }\r
-\r
+       }\r
+       \r
        int fd = open(statm, O_RDONLY);\r
        if (-1 == fd)\r
                return 1000000;\r
@@ -654,19 +660,19 @@ double GetMemUseBytes()
        int n = read(fd, Buffer, sizeof(Buffer) - 1);\r
        close(fd);\r
        fd = -1;\r
-\r
+       \r
        if (n <= 0)\r
                return 1000000;\r
-\r
+       \r
        Buffer[n] = 0;\r
        double Pages = atof(Buffer);\r
-\r
+       \r
        double Bytes = Pages*PageSize;\r
        if (Bytes > g_PeakMemUseBytes)\r
                g_PeakMemUseBytes = Bytes;\r
        return Bytes;\r
-       }\r
-#elif defined(__MACH__)\r
+}\r
+#elif defined(__APPLE__) || (__MACH__)\r
 #include <memory.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
@@ -688,7 +694,7 @@ double GetMemUseBytes()
 #define DEFAULT_MEM_USE        100000000.0\r
 \r
 double GetMemUseBytes()\r
-       {\r
+{\r
        task_t mytask = mach_task_self();\r
        struct task_basic_info ti;\r
        memset((void *) &ti, 0, sizeof(ti));\r
@@ -696,29 +702,29 @@ double GetMemUseBytes()
        kern_return_t ok = task_info(mytask, TASK_BASIC_INFO, (task_info_t) &ti, &count);\r
        if (ok == KERN_INVALID_ARGUMENT)\r
                return DEFAULT_MEM_USE;\r
-\r
+       \r
        if (ok != KERN_SUCCESS)\r
                return DEFAULT_MEM_USE;\r
-\r
+       \r
        double Bytes = (double ) ti.resident_size;\r
        if (Bytes > g_PeakMemUseBytes)\r
                g_PeakMemUseBytes = Bytes;\r
        return Bytes;\r
-       }\r
+}\r
 #else\r
 double GetMemUseBytes()\r
-       {\r
+{\r
        return 0;\r
-       }\r
+}\r
 #endif\r
 \r
 double GetPeakMemUseBytes()\r
-       {\r
+{\r
        return g_PeakMemUseBytes;\r
-       }\r
+}\r
 \r
 const char *SecsToHHMMSS(int Secs)\r
-       {\r
+{\r
        int HH = Secs/3600;\r
        int MM = (Secs - HH*3600)/60;\r
        int SS = Secs%60;\r
@@ -728,13 +734,13 @@ const char *SecsToHHMMSS(int Secs)
        else\r
                sprintf(Str, "%02d:%02d:%02d", HH, MM, SS);\r
        return Str;\r
-       }\r
+}\r
 \r
 const char *SecsToStr(double Secs)\r
-       {\r
+{\r
        if (Secs >= 10.0)\r
                return SecsToHHMMSS((int) Secs);\r
-\r
+       \r
        static char Str[16];\r
        if (Secs < 1e-6)\r
                sprintf(Str, "%.2gs", Secs);\r
@@ -743,12 +749,12 @@ const char *SecsToStr(double Secs)
        else\r
                sprintf(Str, "%.3fs", Secs);\r
        return Str;\r
-       }\r
+}\r
 \r
 const char *MemBytesToStr(double Bytes)\r
-       {\r
+{\r
        static char Str[32];\r
-\r
+       \r
        if (Bytes < 1e6)\r
                sprintf(Str, "%.1fkb", Bytes/1e3);\r
        else if (Bytes < 10e6)\r
@@ -762,12 +768,12 @@ const char *MemBytesToStr(double Bytes)
        else\r
                sprintf(Str, "%.3gb", Bytes);\r
        return Str;\r
-       }\r
+}\r
 \r
 const char *IntToStr(unsigned i)\r
-       {\r
+{\r
        static char Str[32];\r
-\r
+       \r
        double d = (double) i;\r
        if (i < 10000)\r
                sprintf(Str, "%u", i);\r
@@ -784,25 +790,25 @@ const char *IntToStr(unsigned i)
        else\r
                sprintf(Str, "%.3g", d);\r
        return Str;\r
-       }\r
+}\r
 \r
 const char *FloatToStr(double d)\r
-       {\r
+{\r
        static char Str[32];\r
-\r
+       \r
        double a = fabs(d);\r
        if (a < 0.01)\r
                sprintf(Str, "%.3g", a);\r
        else if (a >= 0.01 && a < 1)\r
                sprintf(Str, "%.3f", a);\r
        else if (a <= 10 && a >= 1)\r
-               {\r
+       {\r
                double intpart;\r
                if (modf(a, &intpart) < 0.05)\r
                        sprintf(Str, "%.0f", d);\r
                else\r
                        sprintf(Str, "%.1f", d);\r
-               }\r
+       }\r
        else if (a > 10 && a < 10000)\r
                sprintf(Str, "%.0f", d);\r
        else if (a < 1e6)\r
@@ -818,7 +824,7 @@ const char *FloatToStr(double d)
        else\r
                sprintf(Str, "%.3g", d);\r
        return Str;\r
-       }\r
+}\r
 \r
 bool opt_quiet = false;\r
 bool opt_version = false;\r
@@ -846,48 +852,48 @@ static unsigned g_StepCalls;
 static time_t g_TimeLastOutputStep;\r
 \r
 static string &GetProgressPrefixStr(string &s)\r
-       {\r
+{\r
        double Bytes = GetMemUseBytes();\r
        unsigned Secs = GetElapsedSecs();\r
        s = string(SecsToHHMMSS(Secs));\r
        if (Bytes > 0)\r
-               {\r
+       {\r
                s.push_back(' ');\r
                char Str[32];\r
                sprintf(Str, "%5.5s", MemBytesToStr(Bytes));\r
                s += string(Str);\r
-               }\r
+       }\r
        s.push_back(' ');\r
        return s;\r
-       }\r
+}\r
 \r
 void ProgressLog(const char *Format, ...)\r
-       {\r
+{\r
        string Str;\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        myvstrprintf(Str, Format, ArgList);\r
        va_end(ArgList);\r
-\r
+       \r
        Log("%s", Str.c_str());\r
        Progress("%s", Str.c_str());\r
-       }\r
+}\r
 \r
 void Progress(const char *Format, ...)\r
-       {\r
+{\r
        if (opt_quiet)\r
                return;\r
-\r
+       \r
        string Str;\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        myvstrprintf(Str, Format, ArgList);\r
        va_end(ArgList);\r
-\r
+       \r
 #if    0\r
        Log("Progress(");\r
        for (unsigned i = 0; i < Str.size(); ++i)\r
-               {\r
+       {\r
                char c = Str[i];\r
                if (c == '\r')\r
                        Log("\\r");\r
@@ -895,26 +901,26 @@ void Progress(const char *Format, ...)
                        Log("\\n");\r
                else\r
                        Log("%c", c);\r
-               }\r
+       }\r
        Log(")\n");\r
 #endif //0\r
-\r
+       \r
        for (unsigned i = 0; i < Str.size(); ++i)\r
-               {\r
+       {\r
                if (g_CurrProgressLineLength == 0)\r
-                       {\r
+               {\r
                        string s;\r
                        GetProgressPrefixStr(s);\r
                        for (unsigned j = 0; j < s.size(); ++j)\r
-                               {\r
+                       {\r
                                fputc(s[j], stderr);\r
                                ++g_CurrProgressLineLength;\r
-                               }\r
                        }\r
-\r
+               }\r
+               \r
                char c = Str[i];\r
                if (c == '\n' || c == '\r')\r
-                       {\r
+               {\r
                        for (unsigned j = g_CurrProgressLineLength; j < g_LastProgressLineLength; ++j)\r
                                fputc(' ', stderr);\r
                        if (c == '\n')\r
@@ -923,77 +929,77 @@ void Progress(const char *Format, ...)
                                g_LastProgressLineLength = g_CurrProgressLineLength;\r
                        g_CurrProgressLineLength = 0;\r
                        fputc(c, stderr);\r
-                       }\r
+               }\r
                else\r
-                       {\r
+               {\r
                        fputc(c, stderr);\r
                        ++g_CurrProgressLineLength;\r
-                       }\r
                }\r
        }\r
+}\r
 \r
 void ProgressExit()\r
-       {\r
+{\r
        time_t Now = time(0);\r
        struct tm *t = localtime(&Now);\r
        const char *s = asctime(t);\r
        unsigned Secs = GetElapsedSecs();\r
-\r
+       \r
        Log("\n");\r
        Log("Finished %s", s); // there is a newline in s\r
        Log("Elapsed time %s\n", SecsToHHMMSS((int) Secs));\r
        Log("Max memory %s\n", MemBytesToStr(g_PeakMemUseBytes));\r
 #if    WIN32 && DEBUG\r
-// Skip exit(), which can be very slow in DEBUG build\r
-// VERY DANGEROUS practice, because it skips global destructors.\r
-// But if you know the rules, you can break 'em, right?\r
-       ExitProcess(0);\r
+       // Skip exit(), which can be very slow in DEBUG build\r
+       // VERY DANGEROUS practice, because it skips global destructors.\r
+       // But if you know the rules, you can break 'em, right?\r
+       //ExitProcess(0);\r
 #endif\r
-       }\r
+}\r
 \r
 const char *PctStr(double x, double y)\r
-       {\r
+{\r
        if (y == 0)\r
-               {\r
+       {\r
                if (x == 0)\r
                        return "100%";\r
                else\r
                        return "inf%";\r
-               }\r
+       }\r
        static char Str[16];\r
        double p = x*100.0/y;\r
        sprintf(Str, "%5.1f%%", p);\r
        return Str;\r
-       }\r
+}\r
 \r
 string &GetProgressLevelStr(string &s)\r
-       {\r
+{\r
        unsigned Index = g_ProgressIndex;\r
        unsigned Count = g_ProgressCount;\r
        if (Count == UINT_MAX)\r
-               {\r
+       {\r
                if (Index == UINT_MAX)\r
                        s = "100%";\r
                else\r
-                       {\r
+               {\r
                        char Tmp[16];\r
                        sprintf(Tmp, "%u", Index); \r
                        s = Tmp;\r
-                       }\r
                }\r
+       }\r
        else\r
                s = string(PctStr(Index+1, Count));\r
        s += string(" ") + g_ProgressDesc;\r
        return s;\r
-       }\r
+}\r
 \r
 void ProgressStep(unsigned i, unsigned N, const char *Format, ...)\r
-       {\r
+{\r
        if (opt_quiet)\r
                return;\r
-\r
+       \r
        if (i == 0)\r
-               {\r
+       {\r
                string Str;\r
                va_list ArgList;\r
                va_start(ArgList, Format);\r
@@ -1007,61 +1013,61 @@ void ProgressStep(unsigned i, unsigned N, const char *Format, ...)
                g_TimeLastOutputStep = 0;\r
                if (g_CurrProgressLineLength > 0)\r
                        Progress("\n");\r
-               }\r
-\r
+       }\r
+       \r
        if (i >= N && i != UINT_MAX)\r
                Die("ProgressStep(%u,%u)", i, N);\r
        bool IsLastStep = (i == UINT_MAX || i + 1 == N);\r
        if (!IsLastStep)\r
-               {\r
+       {\r
                ++g_StepCalls;\r
                if (g_StepCalls%g_CountsInterval != 0)\r
                        return;\r
-\r
+               \r
                time_t Now = time(0);\r
                if (Now == g_TimeLastOutputStep)\r
-                       {\r
+               {\r
                        if (g_CountsInterval < 128)\r
                                g_CountsInterval = (g_CountsInterval*3)/2;\r
                        else\r
                                g_CountsInterval += 64;\r
                        return;\r
-                       }\r
+               }\r
                else\r
-                       {\r
+               {\r
                        time_t Secs = Now - g_TimeLastOutputStep;\r
                        if (Secs > 1)\r
                                g_CountsInterval = unsigned(g_CountsInterval/(Secs*8));\r
-                       }\r
-\r
+               }\r
+               \r
                if (g_CountsInterval < 1)\r
                        g_CountsInterval = 1;\r
-\r
+               \r
                g_TimeLastOutputStep = Now;\r
-               }\r
-\r
+       }\r
+       \r
        g_ProgressIndex = i;\r
-\r
+       \r
        if (i > 0)\r
-               {\r
+       {\r
                va_list ArgList;\r
                va_start(ArgList, Format);\r
                myvstrprintf(g_ProgressDesc, Format, ArgList);\r
-               }\r
-\r
+       }\r
+       \r
        string LevelStr;\r
        GetProgressLevelStr(LevelStr);\r
        Progress(" %s\r", LevelStr.c_str());\r
-\r
+       \r
        if (IsLastStep)\r
-               {\r
+       {\r
                g_CountsInterval = 1;\r
                fputc('\n', stderr);\r
-               }\r
        }\r
+}\r
 \r
 enum OptType\r
-       {\r
+{\r
        OT_Flag,\r
        OT_Tog,\r
        OT_Int,\r
@@ -1069,10 +1075,10 @@ enum OptType
        OT_Str,\r
        OT_Float,\r
        OT_Enum\r
-       };\r
+};\r
 \r
 struct OptInfo\r
-       {\r
+{\r
        void *Value;\r
        bool *OptSet;\r
        string LongName;\r
@@ -1084,84 +1090,84 @@ struct OptInfo
        double dMin;\r
        double dMax;\r
        map<string, unsigned> EnumValues;\r
-\r
+       \r
        bool bDefault;\r
        int iDefault;\r
        unsigned uDefault;\r
        double dDefault;\r
        string strDefault;\r
-\r
+       \r
        string Help;\r
-\r
+       \r
        bool operator<(const OptInfo &rhs) const\r
-               {\r
+       {\r
                return LongName < rhs.LongName;\r
-               }\r
-       };\r
+       }\r
+};\r
 \r
 static set<OptInfo> g_Opts;\r
 \r
 void Help()\r
-       {\r
+{\r
        printf("\n");\r
-\r
+       \r
        void Usage();\r
        Usage();\r
-\r
+       \r
        for (set<OptInfo>::const_iterator p = g_Opts.begin(); p != g_Opts.end(); ++p)\r
-               {\r
+       {\r
                const OptInfo &Opt = *p;\r
-\r
+               \r
                printf("\n");\r
                string LongName = Opt.LongName.c_str();\r
                if (Opt.Type == OT_Tog)\r
                        LongName = string("[no]") + LongName;\r
                printf("  --%s ", LongName.c_str());\r
-\r
+               \r
                switch (Opt.Type)\r
-                       {\r
-               case OT_Flag:\r
-                       break;\r
-               case OT_Tog:\r
-                       break;\r
-               case OT_Int:\r
-                       printf("<int>");\r
-                       break;\r
-               case OT_Uns:\r
-                       printf("<uint>");\r
-                       break;\r
-               case OT_Str:\r
-                       printf("<str>");\r
-                       break;\r
-               case OT_Float:\r
-                       printf("<float>");\r
-                       break;\r
-               case OT_Enum:\r
-                       printf("<enum>");\r
-                       break;\r
-               default:\r
-                       printf("??type");\r
-                       break;\r
-                       }\r
-\r
+               {\r
+                       case OT_Flag:\r
+                               break;\r
+                       case OT_Tog:\r
+                               break;\r
+                       case OT_Int:\r
+                               printf("<int>");\r
+                               break;\r
+                       case OT_Uns:\r
+                               printf("<uint>");\r
+                               break;\r
+                       case OT_Str:\r
+                               printf("<str>");\r
+                               break;\r
+                       case OT_Float:\r
+                               printf("<float>");\r
+                               break;\r
+                       case OT_Enum:\r
+                               printf("<enum>");\r
+                               break;\r
+                       default:\r
+                               printf("??type");\r
+                               break;\r
+               }\r
+               \r
                printf("  ");\r
                const string &s = Opt.Help;\r
                for (string::const_iterator q = s.begin(); q != s.end(); ++q)\r
-                       {\r
+               {\r
                        char c = *q;\r
                        if (c == '\n')\r
                                printf("\n   ");\r
                        else\r
                                printf("%c", c);\r
-                       }\r
-               printf("\n");\r
                }\r
+               printf("\n");\r
+       }\r
        printf("\n");\r
        exit(0);\r
-       }\r
+}\r
 \r
 void CmdLineErr(const char *Format, ...)\r
-       {\r
+{\r
        va_list ArgList;\r
        va_start(ArgList, Format);\r
        string Str;\r
@@ -1173,41 +1179,42 @@ void CmdLineErr(const char *Format, ...)
        fprintf(stderr, "For list of command-line options use --help.\n");\r
        fprintf(stderr, "\n");\r
        exit(1);\r
-       }\r
+}\r
 \r
 static set<OptInfo>::iterator GetOptInfo(const string &LongName,\r
-  bool ErrIfNotFound)\r
-       {\r
+                                                                                bool ErrIfNotFound)\r
+{\r
        for (set<OptInfo>::iterator p = g_Opts.begin();\r
-         p != g_Opts.end(); ++p)\r
-               {\r
+                p != g_Opts.end(); ++p)\r
+       {\r
                const OptInfo &Opt = *p;\r
                if (Opt.LongName == LongName)\r
                        return p;\r
                if (Opt.Type == OT_Tog && "no" + Opt.LongName == LongName)\r
                        return p;\r
-               }\r
+       }\r
        if (ErrIfNotFound)\r
                CmdLineErr("Option --%s is invalid", LongName.c_str());\r
        return g_Opts.end();\r
-       }\r
+}\r
 \r
 static void AddOpt(const OptInfo &Opt)\r
-       {\r
+{\r
        if (GetOptInfo(Opt.LongName, false) != g_Opts.end())\r
                Die("Option --%s defined twice", Opt.LongName.c_str());\r
        g_Opts.insert(Opt);\r
-       }\r
+}\r
 \r
-#ifdef _MSC_VER\r
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
+#else\r
 #pragma warning(disable: 4505) // unreferenced local function\r
 #endif\r
 \r
 static void DefineFlagOpt(const string &LongName, const string &Help,\r
-  void *Value, bool *OptSet)\r
-       {\r
+                                                 void *Value, bool *OptSet)\r
+{\r
        *(bool *) Value = false;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1216,13 +1223,13 @@ static void DefineFlagOpt(const string &LongName, const string &Help,
        Opt.Help = Help;\r
        Opt.Type = OT_Flag;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void DefineTogOpt(const string &LongName, bool Default, const string &Help,\r
-  void *Value, bool *OptSet)\r
-       {\r
+                                                void *Value, bool *OptSet)\r
+{\r
        *(bool *) Value = Default;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1231,13 +1238,13 @@ static void DefineTogOpt(const string &LongName, bool Default, const string &Hel
        Opt.Help = Help;\r
        Opt.Type = OT_Tog;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void DefineIntOpt(const string &LongName, int Default, int Min, int Max,\r
-  const string &Help, void *Value, bool *OptSet)\r
-       {\r
+                                                const string &Help, void *Value, bool *OptSet)\r
+{\r
        *(int *) Value = Default;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1248,13 +1255,13 @@ static void DefineIntOpt(const string &LongName, int Default, int Min, int Max,
        Opt.Help = Help;\r
        Opt.Type = OT_Int;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void DefineUnsOpt(const string &LongName, unsigned Default, unsigned Min,\r
-  unsigned Max, const string &Help, void *Value, bool *OptSet)\r
-       {\r
+                                                unsigned Max, const string &Help, void *Value, bool *OptSet)\r
+{\r
        *(unsigned *) Value = Default;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1265,13 +1272,13 @@ static void DefineUnsOpt(const string &LongName, unsigned Default, unsigned Min,
        Opt.Help = Help;\r
        Opt.Type = OT_Uns;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void DefineFloatOpt(const string &LongName, double Default, double Min,\r
-  double Max, const string &Help, void *Value, bool *OptSet)\r
-       {\r
+                                                  double Max, const string &Help, void *Value, bool *OptSet)\r
+{\r
        *(double *) Value = Default;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1282,13 +1289,13 @@ static void DefineFloatOpt(const string &LongName, double Default, double Min,
        Opt.Help = Help;\r
        Opt.Type = OT_Float;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void DefineStrOpt(const string &LongName, const char *Default,\r
-  const string &Help, void *Value, bool *OptSet)\r
-       {\r
+                                                const string &Help, void *Value, bool *OptSet)\r
+{\r
        *(string *) Value = (Default == 0 ? "" : string(Default));\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.OptSet = OptSet;\r
@@ -1297,34 +1304,34 @@ static void DefineStrOpt(const string &LongName, const char *Default,
        Opt.Help = Help;\r
        Opt.Type = OT_Str;\r
        AddOpt(Opt);\r
-       }\r
+}\r
 \r
 static void ParseEnumValues(const string &Values, map<string, unsigned> &EnumValues)\r
-       {\r
+{\r
        EnumValues.clear();\r
        \r
        string Name;\r
        string Value;\r
        bool Eq = false;\r
        for (string::const_iterator p = Values.begin(); ; ++p)\r
-               {\r
+       {\r
                char c = (p == Values.end() ? '|' : *p);\r
                if (isspace(c))\r
                        ;\r
                else if (c == '|')\r
-                       {\r
+               {\r
                        if (EnumValues.find(Name) != EnumValues.end())\r
                                Die("Invalid enum values, '%s' defined twice: '%s'",\r
-                                 Name.c_str(), Values.c_str());\r
+                                       Name.c_str(), Values.c_str());\r
                        if (Name.empty() || Value.empty())\r
                                Die("Invalid enum values, empty name or value: '%s'",\r
-                                 Values.c_str());\r
-\r
+                                       Values.c_str());\r
+                       \r
                        EnumValues[Name] = atoi(Value.c_str());\r
                        Name.clear();\r
                        Value.clear();\r
                        Eq = false;\r
-                       }\r
+               }\r
                else if (c == '=')\r
                        Eq = true;\r
                else if (Eq)\r
@@ -1333,14 +1340,14 @@ static void ParseEnumValues(const string &Values, map<string, unsigned> &EnumVal
                        Name.push_back(c);\r
                if (p == Values.end())\r
                        return;\r
-               }\r
        }\r
+}\r
 \r
 static void DefineEnumOpt(const string &LongName, const string &ShortName,\r
-  int Default, const string &Values, const string &Help, void *Value)\r
-       {\r
+                                                 int Default, const string &Values, const string &Help, void *Value)\r
+{\r
        *(int *) Value = Default;\r
-\r
+       \r
        OptInfo Opt;\r
        Opt.Value = Value;\r
        Opt.LongName = LongName;\r
@@ -1349,7 +1356,7 @@ static void DefineEnumOpt(const string &LongName, const string &ShortName,
        Opt.Type = OT_Enum;\r
        ParseEnumValues(Values, Opt.EnumValues);\r
        AddOpt(Opt);\r
-       }\r
+}\r
 #undef FLAG_OPT\r
 #undef TOG_OPT\r
 #undef INT_OPT\r
@@ -1367,110 +1374,110 @@ static void DefineEnumOpt(const string &LongName, const string &ShortName,
 #include "myopts.h"\r
 \r
 static int EnumStrToInt(const OptInfo &Opt, const string &Value)\r
-       {\r
+{\r
        const map<string, unsigned> &e = Opt.EnumValues;\r
        string s;\r
        for (map<string, unsigned>::const_iterator p = e.begin(); p != e.end(); ++p)\r
-               {\r
+       {\r
                if (Value == p->first)\r
                        return p->second;\r
                s += " " + p->first;\r
-               }\r
+       }\r
        CmdLineErr("--%s %s not recognized, valid are: %s",\r
-         Opt.LongName.c_str(), Value.c_str(), s.c_str());\r
+                          Opt.LongName.c_str(), Value.c_str(), s.c_str());\r
        ureturn(-1);\r
-       }\r
+}\r
 \r
 static void SetOpt(OptInfo &Opt, const string &Value)\r
-       {\r
+{\r
        *Opt.OptSet = true;\r
        switch (Opt.Type)\r
+       {\r
+               case OT_Int:\r
                {\r
-       case OT_Int:\r
-               {\r
-               *(int *) Opt.Value = atoi(Value.c_str());\r
-               break;\r
+                       *(int *) Opt.Value = atoi(Value.c_str());\r
+                       break;\r
                }\r
-       case OT_Uns:\r
+               case OT_Uns:\r
                {\r
-               unsigned uValue = 0;\r
-               int n = sscanf(Value.c_str(), "%u", &uValue);\r
-               if (n != 1)\r
-                       CmdLineErr("Invalid value '%s' for --%s",\r
-                         Value.c_str(), Opt.LongName.c_str());\r
-               *(unsigned *) Opt.Value = uValue;\r
-               break;\r
+                       unsigned uValue = 0;\r
+                       int n = sscanf(Value.c_str(), "%u", &uValue);\r
+                       if (n != 1)\r
+                               CmdLineErr("Invalid value '%s' for --%s",\r
+                                                  Value.c_str(), Opt.LongName.c_str());\r
+                       *(unsigned *) Opt.Value = uValue;\r
+                       break;\r
                }\r
-       case OT_Float:\r
+               case OT_Float:\r
                {\r
-               *(double *) Opt.Value = atof(Value.c_str());\r
-               break;\r
+                       *(double *) Opt.Value = atof(Value.c_str());\r
+                       break;\r
                }\r
-       case OT_Str:\r
+               case OT_Str:\r
                {\r
-               *(string *) Opt.Value = Value;\r
-               break;\r
+                       *(string *) Opt.Value = Value;\r
+                       break;\r
                }\r
-       case OT_Enum:\r
+               case OT_Enum:\r
                {\r
-               *(int *) Opt.Value = EnumStrToInt(Opt, Value);\r
-               break;\r
-               }\r
-       default:\r
-               asserta(false);\r
+                       *(int *) Opt.Value = EnumStrToInt(Opt, Value);\r
+                       break;\r
                }\r
+               default:\r
+                       asserta(false);\r
        }\r
+}\r
 \r
 void LogOpts()\r
-       {\r
+{\r
        for (set<OptInfo>::const_iterator p = g_Opts.begin(); p != g_Opts.end(); ++p)\r
-               {\r
+       {\r
                const OptInfo &Opt = *p;\r
                Log("%s = ", Opt.LongName.c_str());\r
                switch (Opt.Type)\r
+               {\r
+                       case OT_Flag:\r
+                               Log("%s", (*(bool *) Opt.Value) ? "yes" : "no");\r
+                               break;\r
+                       case OT_Tog:\r
+                               Log("%s", (*(bool *) Opt.Value) ? "on" : "off");\r
+                               break;\r
+                       case OT_Int:\r
+                               Log("%d", *(int *) Opt.Value);\r
+                               break;\r
+                       case OT_Uns:\r
+                               Log("%u", *(unsigned *) Opt.Value);\r
+                               break;\r
+                       case OT_Float:\r
                        {\r
-               case OT_Flag:\r
-                       Log("%s", (*(bool *) Opt.Value) ? "yes" : "no");\r
-                       break;\r
-               case OT_Tog:\r
-                       Log("%s", (*(bool *) Opt.Value) ? "on" : "off");\r
-                       break;\r
-               case OT_Int:\r
-                       Log("%d", *(int *) Opt.Value);\r
-                       break;\r
-               case OT_Uns:\r
-                       Log("%u", *(unsigned *) Opt.Value);\r
-                       break;\r
-               case OT_Float:\r
-                       {\r
-                       double Value = *(double *) Opt.Value;\r
-                       if (Value == FLT_MAX)\r
-                               Log("*");\r
-                       else\r
-                               Log("%g", Value);\r
-                       break;\r
-                       }\r
-               case OT_Str:\r
-                       Log("%s", (*(string *) Opt.Value).c_str());\r
-                       break;\r
-               case OT_Enum:\r
-                       Log("%d", *(int *) Opt.Value);\r
-                       break;\r
-               default:\r
-                       asserta(false);\r
+                               double Value = *(double *) Opt.Value;\r
+                               if (Value == FLT_MAX)\r
+                                       Log("*");\r
+                               else\r
+                                       Log("%g", Value);\r
+                               break;\r
                        }\r
-               Log("\n");\r
+                       case OT_Str:\r
+                               Log("%s", (*(string *) Opt.Value).c_str());\r
+                               break;\r
+                       case OT_Enum:\r
+                               Log("%d", *(int *) Opt.Value);\r
+                               break;\r
+                       default:\r
+                               asserta(false);\r
                }\r
+               Log("\n");\r
        }\r
+}\r
 \r
 static void CompilerInfo()\r
-       {\r
+{\r
 #ifdef _FILE_OFFSET_BITS\r
     printf("_FILE_OFFSET_BITS=%d\n", _FILE_OFFSET_BITS);\r
 #else\r
     printf("_FILE_OFFSET_BITS not defined\n");\r
 #endif\r
-\r
+       \r
 #define x(t)   printf("sizeof(" #t ") = %d\n", (int) sizeof(t));\r
        x(int)\r
        x(long)\r
@@ -1480,60 +1487,61 @@ static void CompilerInfo()
        x(off_t)\r
 #undef x\r
        exit(0);\r
-       }\r
+}\r
 \r
 void Split(const string &Str, vector<string> &Fields, char Sep)\r
-       {\r
+{\r
        Fields.clear();\r
        const unsigned Length = (unsigned) Str.size();\r
        string s;\r
        for (unsigned i = 0; i < Length; ++i)\r
-               {\r
+       {\r
                char c = Str[i];\r
                if ((Sep == 0 && isspace(c)) || c == Sep)\r
-                       {\r
+               {\r
                        if (!s.empty() || Sep != 0)\r
                                Fields.push_back(s);\r
                        s.clear();\r
-                       }\r
+               }\r
                else\r
                        s.push_back(c);\r
-               }\r
+       }\r
        if (!s.empty())\r
                Fields.push_back(s);\r
-       }\r
+}\r
 \r
 static void GetArgsFromFile(const string &FileName, vector<string> &Args)\r
-       {\r
+{\r
        Args.clear();\r
-\r
+       \r
        FILE *f = OpenStdioFile(FileName);\r
        string Line;\r
        while (ReadLineStdioFile(f, Line))\r
-               {\r
+       {\r
                size_t n = Line.find('#');\r
                if (n != string::npos)\r
                        Line = Line.substr(0, n);\r
                vector<string> Fields;\r
                Split(Line, Fields);\r
                Args.insert(Args.end(), Fields.begin(), Fields.end());\r
-               }\r
-       CloseStdioFile(f);\r
        }\r
+       CloseStdioFile(f);\r
+}\r
 \r
 void MyCmdLine(int argc, char **argv)\r
-       {\r
+{\r
+       g_Opts.clear(); g_Argv.clear();\r
        static unsigned RecurseDepth = 0;\r
        ++RecurseDepth;\r
-\r
+       \r
        DefineFlagOpt("compilerinfo", "Write info about compiler types and #defines to stdout.",\r
-         (void *) &opt_compilerinfo, &optset_compilerinfo);\r
+                                 (void *) &opt_compilerinfo, &optset_compilerinfo);\r
        DefineFlagOpt("quiet", "Turn off progress messages.", (void *) &opt_quiet, &optset_quiet);\r
        DefineFlagOpt("version", "Show version and exit.", (void *) &opt_version, &optset_version);\r
        DefineFlagOpt("logopts", "Log options.", (void *) &opt_logopts, &optset_logopts);\r
        DefineFlagOpt("help", "Display command-line options.", (void *) &opt_help, &optset_help);\r
        DefineStrOpt("log", "", "Log file name.", (void *) &opt_log, &optset_log);\r
-\r
+       \r
 #undef FLAG_OPT\r
 #undef TOG_OPT\r
 #undef INT_OPT\r
@@ -1549,93 +1557,93 @@ void MyCmdLine(int argc, char **argv)
 #define STR_OPT(LongName, Default)                             DefineStrOpt(#LongName, Default, "help", (void *) &opt_##LongName, &optset_##LongName);\r
 #define ENUM_OPT(LongName, Values, Default)            DefineEnumOpt(#LongName, Values, Default, "help", (void *) &opt_##LongName, &optset_##LongName);\r
 #include "myopts.h"\r
-\r
+       \r
        if (RecurseDepth == 0)\r
                g_Argv.clear();\r
-\r
-       for (int i = 0; i < argc; ++i) {\r
+       \r
+       for (int i = 0; i < argc; ++i) \r
                g_Argv.push_back(string(argv[i]));\r
-       }\r
-\r
+       \r
+       \r
        int i = 1;\r
        for (;;)\r
-               {\r
+       {\r
                if (i >= argc)\r
                        break;\r
                const string &Arg = g_Argv[i];\r
-                       \r
+               \r
                if (Arg.empty())\r
                        continue;\r
                else if (Arg == "file:" && i + 1 < argc)\r
-                       {\r
+               {\r
                        const string &FileName = g_Argv[i+1];\r
                        vector<string> Args;\r
                        GetArgsFromFile(FileName, Args);\r
                        for (vector<string>::const_iterator p = Args.begin();\r
-                         p != Args.end(); ++p)\r
-                               {\r
+                                p != Args.end(); ++p)\r
+                       {\r
                                g_Argv.push_back(*p);\r
                                ++argc;\r
-                               }\r
+                       }\r
                        i += 2;\r
                        continue;\r
-                       }\r
+               }\r
                else if (Arg.size() > 1 && Arg[0] == '-')\r
-                       {\r
+               {\r
                        string LongName = (Arg.size() > 2 && Arg[1] == '-' ? Arg.substr(2) : Arg.substr(1));\r
                        OptInfo Opt = *GetOptInfo(LongName, true);\r
                        *Opt.OptSet = true;\r
                        if (Opt.Type == OT_Flag)\r
-                               {\r
+                       {\r
                                g_Opts.erase(Opt);\r
                                *(bool *) Opt.Value = true;\r
                                g_Opts.insert(Opt);\r
                                ++i;\r
                                continue;\r
-                               }\r
+                       }\r
                        else if (Opt.Type == OT_Tog)\r
-                               {\r
+                       {\r
                                g_Opts.erase(Opt);\r
                                if (string("no") + Opt.LongName == LongName)\r
                                        *(bool *) Opt.Value = false;\r
                                else\r
-                                       {\r
+                               {\r
                                        asserta(Opt.LongName == LongName);\r
                                        *(bool *) Opt.Value = true;\r
-                                       }\r
+                               }\r
                                g_Opts.insert(Opt);\r
                                ++i;\r
                                continue;\r
-                               }\r
-\r
+                       }\r
+                       \r
                        ++i;\r
                        if (i >= argc)\r
                                CmdLineErr("Missing value for option --%s", LongName.c_str());\r
-\r
+                       \r
                        string Value = g_Argv[i];\r
                        SetOpt(Opt, Value);\r
-\r
+                       \r
                        ++i;\r
                        continue;\r
-                       }\r
+               }\r
                else\r
                        CmdLineErr("Expected -option_name or --option_name, got '%s'", Arg.c_str());\r
-               }\r
-\r
+       }\r
+       \r
        --RecurseDepth;\r
        if (RecurseDepth > 0)\r
                return;\r
-\r
+       \r
        if (opt_help)\r
                Help();\r
-\r
+       \r
        if (opt_compilerinfo)\r
                CompilerInfo();\r
-\r
+       \r
        SetLogFileName(opt_log);\r
-\r
+       \r
        if (opt_log != "")\r
-               {\r
+       {\r
                for (int i = 0; i < argc; ++i)\r
                        Log("%s%s", i == 0 ? "" : " ", g_Argv[i].c_str());\r
                Log("\n");\r
@@ -1645,57 +1653,57 @@ void MyCmdLine(int argc, char **argv)
                Log("Started %s", s); // there is a newline in s\r
                Log("Version " MY_VERSION ".%s\n", SVN_VERSION);\r
                Log("\n");\r
-               }\r
-\r
+       }\r
+       \r
        if (opt_logopts)\r
                LogOpts();\r
-       }\r
+}\r
 \r
 double Pct(double x, double y)\r
-       {\r
+{\r
        if (y == 0.0f)\r
                return 0.0f;\r
        return (x*100.0f)/y;\r
-       }\r
+}\r
 \r
 void GetCmdLine(string &s)\r
-       {\r
+{\r
        s.clear();\r
        for (unsigned i = 0; i < SIZE(g_Argv); ++i)\r
-               {\r
+       {\r
                if (i > 0)\r
                        s += " ";\r
                s += g_Argv[i];\r
-               }\r
        }\r
+}\r
 \r
 char *mystrsave(const char *s)\r
-       {\r
+{\r
        unsigned n = unsigned(strlen(s));\r
        char *t = myalloc(char, n+1);\r
        memcpy(t, s, n+1);\r
        return t;\r
-       }\r
+}\r
 \r
 void Logu(unsigned u, unsigned w, unsigned prefixspaces)\r
-       {\r
+{\r
        for (unsigned i = 0; i < prefixspaces; ++i)\r
                Log(" ");\r
        if (u == UINT_MAX)\r
                Log("%*.*s", w, w, "*");\r
        else\r
                Log("%*u", w, u);\r
-       }\r
+}\r
 \r
 void Logf(float x, unsigned w, unsigned prefixspaces)\r
-       {\r
+{\r
        for (unsigned i = 0; i < prefixspaces; ++i)\r
                Log(" ");\r
        if (x == FLT_MAX)\r
                Log("%*.*s", w, w, "*");\r
        else\r
                Log("%*.2f", w, x);\r
-       }\r
+}\r
 \r
 static uint32 g_SLCG_state = 1;\r
 \r
@@ -1707,65 +1715,65 @@ static uint32 g_SLCG_c = 2531011;
 // Simple Linear Congruential Generator\r
 // Bad properties; used just to initialize the better generator.\r
 static uint32 SLCG_rand()\r
-       {\r
+{\r
        g_SLCG_state = g_SLCG_state*g_SLCG_a + g_SLCG_c;\r
        return g_SLCG_state;\r
-       }\r
+}\r
 \r
 static void SLCG_srand(uint32 Seed)\r
-       {\r
+{\r
        g_SLCG_state = Seed;\r
        for (int i = 0; i < 10; ++i)\r
                SLCG_rand();\r
-       }\r
+}\r
 \r
 /***\r
-A multiply-with-carry random number generator, see:\r
-http://en.wikipedia.org/wiki/Multiply-with-carry\r
-\r
-The particular multipliers used here were found on\r
-the web where they are attributed to George Marsaglia.\r
-***/\r
+ A multiply-with-carry random number generator, see:\r
+ http://en.wikipedia.org/wiki/Multiply-with-carry\r
\r
+ The particular multipliers used here were found on\r
+ the web where they are attributed to George Marsaglia.\r
+ ***/\r
 \r
 static bool g_InitRandDone = false;\r
 static uint32 g_X[5];\r
 \r
 uint32 RandInt32()\r
-       {\r
+{\r
        InitRand();\r
-\r
+       \r
        uint64 Sum = 2111111111*(uint64) g_X[3] + 1492*(uint64) g_X[2] +\r
-         1776*(uint64) g_X[1] + 5115*(uint64) g_X[0] + g_X[4];\r
+       1776*(uint64) g_X[1] + 5115*(uint64) g_X[0] + g_X[4];\r
        g_X[3] = g_X[2];\r
        g_X[2] = g_X[1];\r
        g_X[1] = g_X[0];\r
        g_X[4] = (uint32) (Sum >> 32);\r
        g_X[0] = (uint32) Sum;\r
        return g_X[0];\r
-       }\r
+}\r
 \r
 unsigned randu32()\r
-       {\r
+{\r
        return (unsigned) RandInt32();\r
-       }\r
+}\r
 \r
 void InitRand()\r
-       {\r
+{\r
        if (g_InitRandDone)\r
                return;\r
-// Do this first to avoid recursion\r
+       // Do this first to avoid recursion\r
        g_InitRandDone = true;\r
-\r
+       \r
        unsigned Seed = (optset_randseed ? opt_randseed : (unsigned) (time(0)*getpid()));\r
        Log("RandSeed=%u\n", Seed);\r
        SLCG_srand(Seed);\r
-\r
+       \r
        for (unsigned i = 0; i < 5; i++)\r
                g_X[i] = SLCG_rand();\r
-\r
+       \r
        for (unsigned i = 0; i < 100; i++)\r
                RandInt32();\r
-       }\r
+}\r
 \r
 // MUST COME AT END BECAUSE OF #undef\r
 #if    RCE_MALLOC\r
@@ -1773,72 +1781,72 @@ void InitRand()
 #undef myfree\r
 #undef myfree2\r
 void *mymalloc(unsigned bytes, const char *FileName, int Line)\r
-       {\r
+{\r
        void *rce_malloc(unsigned bytes, const char *FileName, int Line);\r
        return rce_malloc(bytes, FileName, Line);\r
-       }\r
+}\r
 \r
 void myfree(void *p, const char *FileName, int Line)\r
-       {\r
+{\r
        void rce_free(void *p, const char *FileName, int Line);\r
        rce_free(p, FileName, Line);\r
-       }\r
+}\r
 \r
 void myfree2(void *p, unsigned bytes, const char *FileName, int Line)\r
-       {\r
+{\r
        void rce_free(void *p, const char *FileName, int Line);\r
        rce_free(p, FileName, Line);\r
-       }\r
+}\r
 \r
 #else // RCE_MALLOC\r
 void *mymalloc(unsigned bytes)\r
-       {\r
+{\r
        ++g_NewCalls;\r
        if (g_InitialMemUseBytes == 0)\r
                g_InitialMemUseBytes = GetMemUseBytes();\r
-\r
+       \r
        g_TotalAllocBytes += bytes;\r
        g_NetBytes += bytes;\r
        if (g_NetBytes > g_MaxNetBytes)\r
-               {\r
+       {\r
                if (g_NetBytes > g_MaxNetBytes + 10000000)\r
                        GetMemUseBytes();//to force update of peak\r
                g_MaxNetBytes = g_NetBytes;\r
-               }\r
+       }\r
        void *p = malloc(bytes);\r
        //void *p = _malloc_dbg(bytes, _NORMAL_BLOCK, __FILE__, __LINE__);\r
        if (0 == p)\r
-               {\r
+       {\r
                double b = GetMemUseBytes();\r
                fprintf(stderr, "\nOut of memory mymalloc(%u), curr %.3g bytes",\r
-                 (unsigned) bytes, b);\r
+                               (unsigned) bytes, b);\r
                void LogAllocs();\r
                LogAllocs();\r
 #if DEBUG && defined(_MSC_VER)\r
                asserta(_CrtCheckMemory());\r
 #endif\r
                Die("Out of memory, mymalloc(%u), curr %.3g bytes\n",\r
-                 (unsigned) bytes, b);\r
-               }\r
-       return p;\r
+                       (unsigned) bytes, b);\r
        }\r
+       return p;\r
+}\r
 \r
 void myfree(void *p)\r
-       {\r
+{\r
        if (p == 0)\r
                return;\r
        free(p);\r
        //_free_dbg(p, _NORMAL_BLOCK);\r
-       }\r
+}\r
 \r
 void myfree2(void *p, unsigned bytes)\r
-       {\r
+{\r
        ++g_FreeCalls;\r
        g_TotalFreeBytes += bytes;\r
        g_NetBytes -= bytes;\r
-\r
+       \r
        if (p == 0)\r
                return;\r
        free(p);\r
-       }\r
+}\r
 #endif\r
index 6ca36361dc55fe6c204017486c98ebeea77e7a9c..5438147ea3dd186989dafd144cf2d819c8845ef3 100644 (file)
@@ -618,9 +618,10 @@ bool PhyloTree::ErrorCheck(vector<string> templateFileNames){
                                okay = false;
                        }
                        
-                       templateFileNames.erase(templateFileNames.begin()+i);
-                       i--;
+                       //templateFileNames.erase(templateFileNames.begin()+i);
+                       //i--;
                }
+               templateFileNames.clear();
                
                if (taxonomyFileNames.size() > 0) { //there are names in tax file that are not in template
                        okay = false;
index 2868004825b8336ab1c4e4feb25dc415103b1881..6f106187232335fbc39078cc478f60846b4319c5 100644 (file)
@@ -82,7 +82,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct preClusterData {
+struct preClusterData {
        string fastafile; 
        string namefile; 
        string groupfile;
@@ -277,7 +277,7 @@ static DWORD WINAPI MyPreclusterThreadFunction(LPVOID lpParam){
 
        }
        catch(exception& e) {
-               pDataArray->m->errorOut(e, "AlignCommand", "MyPreclusterThreadFunction");
+               pDataArray->m->errorOut(e, "PreClusterCommand", "MyPreclusterThreadFunction");
                exit(1);
        }
 } 
index 4d9bcbb0f02af27f29bd01d4f23f88adefcd7a10..b3a0071079bdbcbdb6a1069cf6bc1d2f53f8fad9 100644 (file)
@@ -129,7 +129,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct flowDistParentForkData {
+struct flowDistParentForkData {
        string distFileName; 
        vector<int> mapUniqueToSeq;
        vector<int> mapSeqToUnique;
index b566e1b801a932374736991076457f0efd9dda4c..0a80aee10aec83e3521d7e35642489afc91392f8 100644 (file)
--- a/timing.h
+++ b/timing.h
@@ -9,10 +9,10 @@
 #define BG_TIMING      0
 #endif
 
-//#if  UCHIMES
+#if    UCHIMES
 #undef TIMING
 #define TIMING 0
-//#endif
+#endif
 
 #if TIMING
 
index e3a2814facba50904109c7f97a225e6a21b6589a..0dc1cd977c9b106b4986e2cb839939cae7541db2 100644 (file)
@@ -83,7 +83,7 @@ private:
 //custom data structure for threads to use.
 // This is passed by void pointer so it can be any data type
 // that can be passed using a single void pointer (LPVOID).
-typedef struct trimFlowData {
+struct trimFlowData {
        string flowFileName; 
        string trimFlowFileName; 
        string scrapFlowFileName;