]> git.donarmstrong.com Git - mothur.git/blobdiff - ccode.cpp
working on removing pointers from chimera.slayer to eliminate pesky memory leaks
[mothur.git] / ccode.cpp
index 56856a9e4ac545627068eec2786dfdb4c476d1fb..ee88ba1c84838b2b9d6e4edaef2899ca81d31dee 100644 (file)
--- a/ccode.cpp
+++ b/ccode.cpp
@@ -25,17 +25,22 @@ Ccode::Ccode(string filename, string temp, bool f, string mask, int win, int num
        distCalc = new eachGapDist();
        decalc = new DeCalculator();
        
-       mapInfo = outputDir + getRootName(getSimpleName(fastafile)) + "mapinfo";
+       mapInfo = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "mapinfo";
        
        #ifdef USE_MPI
                
-               char inFileName[mapInfo.length()];
+               //char* inFileName = new char[mapInfo.length()];
+               //memcpy(inFileName, mapInfo.c_str(), mapInfo.length());
+               
+               char inFileName[1024];
                strcpy(inFileName, mapInfo.c_str());
                
                int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
 
                MPI_File_open(MPI_COMM_WORLD, inFileName, outMode, MPI_INFO_NULL, &outMap);  //comm, filename, mode, info, filepointer
                
+               //delete inFileName;
+
                int pid;
                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
                
@@ -44,15 +49,16 @@ Ccode::Ccode(string filename, string temp, bool f, string mask, int win, int num
                        
                        MPI_Status status;
                        int length = outString.length();
-                       char buf2[length];
-                       strcpy(buf2, outString.c_str()); 
+                       char* buf2 = new char[length];
+                       memcpy(buf2, outString.c_str(), length);
                                
                        MPI_File_write_shared(outMap, buf2, length, MPI_CHAR, &status);
+                       delete buf2;
                }
        #else
 
                ofstream out2;
-               openOutputFile(mapInfo, out2);
+               m->openOutputFile(mapInfo, out2);
                
                out2 << "Place in masked, filtered and trimmed sequence\tPlace in original alignment" << endl;
                out2.close();
@@ -68,11 +74,11 @@ Ccode::~Ccode() {
        #endif
 }      
 //***************************************************************************************************************
-int Ccode::print(ostream& out, ostream& outAcc) {
+Sequence Ccode::print(ostream& out, ostream& outAcc) {
        try {
                
                ofstream out2;
-               openOutputFileAppend(mapInfo, out2);
+               m->openOutputFileAppend(mapInfo, out2);
                
                out2 << querySeq->getName() << endl;
                for (it = spotMap.begin(); it!= spotMap.end(); it++) {
@@ -149,7 +155,7 @@ int Ccode::print(ostream& out, ostream& outAcc) {
                //free memory
                for (int i = 0; i < closest.size(); i++) {  delete closest[i].seq;  }
 
-               return results;
+               return *querySeq;
        }
        catch(exception& e) {
                m->errorOut(e, "Ccode", "print");
@@ -158,7 +164,7 @@ int Ccode::print(ostream& out, ostream& outAcc) {
 }
 #ifdef USE_MPI
 //***************************************************************************************************************
-int Ccode::print(MPI_File& out, MPI_File& outAcc) {
+Sequence Ccode::print(MPI_File& out, MPI_File& outAcc) {
        try {
                
                string outMapString = "";
@@ -235,27 +241,29 @@ int Ccode::print(MPI_File& out, MPI_File& outAcc) {
                
                MPI_Status status;
                int length = outString.length();
-               char buf2[length];
-               strcpy(buf2, outString.c_str()); 
+               char* buf2 = new char[length];
+               memcpy(buf2, outString.c_str(), length);
                                
                MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status);
-                       
+               delete buf2;
+
                if (results) {
                        m->mothurOut(querySeq->getName() + " was found have at least one chimeric window."); m->mothurOutEndLine();
                        outAccString += querySeq->getName() + "\n";
                        
                        MPI_Status statusAcc;
                        length = outAccString.length();
-                       char buf[length];
-                       strcpy(buf, outAccString.c_str()); 
+                       char* buf = new char[length];
+                       memcpy(buf, outAccString.c_str(), length);
                                
                        MPI_File_write_shared(outAcc, buf, length, MPI_CHAR, &statusAcc);
+                       delete buf;
                }
 
                //free memory
                for (int i = 0; i < closest.size(); i++) {  delete closest[i].seq;  }
 
-               return results;
+               return *querySeq;
        }
        catch(exception& e) {
                m->errorOut(e, "Ccode", "print");
@@ -267,10 +275,13 @@ int Ccode::printMapping(string& output) {
        try {
                        MPI_Status status;
                        int length = output.length();
-                       char buf[length];
-                       strcpy(buf, output.c_str()); 
+                       char* buf = new char[length];
+                       memcpy(buf, output.c_str(), length);
                                
                        MPI_File_write_shared(outMap, buf, length, MPI_CHAR, &status);
+                       delete buf;
+                       
+                       return 0;
 
        }
        catch(exception& e) {