- string fileName = distFile + "." + toString(groupIDB) + ".temp";
- ifstream fileB(fileName.c_str());
- while(fileB){
- fileB >> row >> column >> distance;
- outFile << row << '\t' << column << '\t' << distance << endl;
- gobble(fileB);
+
+ numOutputs[groupID] += numOutputs[groupIDB];
+ outputs[groupID] += outputs[groupIDB];
+
+ if (wroteOutPut[groupIDB]) {
+ string fileName = distFile + "." + toString(groupIDB) + ".temp";
+ ifstream fileB(fileName.c_str(), ios::ate);
+
+ long size;
+ char* memblock;
+
+ size = fileB.tellg();
+
+ fileB.seekg (0, ios::beg);
+
+ int numRead = size / 1024;
+ int lastRead = size % 1024;
+
+ for (int i = 0; i < numRead; i++) {
+
+ memblock = new char [1024];
+
+ fileB.read (memblock, 1024);
+
+ string temp = memblock;
+ outFile << temp.substr(0, 1024);
+
+ delete memblock;
+ }
+
+ memblock = new char [lastRead];
+
+ fileB.read (memblock, lastRead);
+
+ //not sure why but it will read more than lastRead char...??
+ string temp = memblock;
+ outFile << temp.substr(0, lastRead);
+ delete memblock;
+
+ fileB.close();
+ remove(fileName.c_str());
+
+ wroteOutPut[groupID] = true;
+ wroteOutPut[groupIDB] = false;
+ }
+
+ if (numOutputs[groupID] != 0) {
+ outFile << outputs[groupID];
+ wroteOutPut[groupID] = true;
+ outputs[groupID] = "";
+ numOutputs[groupID] = 0;
+
+ outputs[groupIDB] = "";
+ numOutputs[groupIDB] = 0;