#include #include #include #include #include #include #include "loadZobov.hpp" using namespace std; bool loadZobov(const char *descName, const char *adjName, const char *volName, ZobovRep& z) { ifstream descFile(descName); ifstream adjFile(adjName); ifstream volFile(volName); int32_t numParticles, numZones, numPinZone; int32_t totalParticles; int32_t numVoids; adjFile.read((char *)&numParticles, sizeof(numParticles)); adjFile.read((char *)&numZones, sizeof(numZones)); if (!adjFile) return false; cout << "Number of particles = " << numParticles << endl; cout << "Number of zones = " << numZones << endl; totalParticles = 0; z.allZones.resize(numZones); for (int zone = 0; zone < numZones; zone++) { adjFile.read((char *)&numPinZone, sizeof(numPinZone)); if (!adjFile) { cout << "Problem on the zone " << zone << " / " << numZones << endl; return false; } z.allZones[zone].pId.resize(numPinZone); adjFile.read((char *)&z.allZones[zone].pId[0], sizeof(int)*numPinZone); totalParticles += numPinZone; } cout << "Zoned " << totalParticles << endl; if (totalParticles != numParticles) { cerr << "The numbers of particles are inconsistent ! (" << totalParticles << " vs " << numParticles << ")"<< endl; abort(); } volFile.read((char *)&numVoids, sizeof(numVoids)); if (!volFile) return false; cout << "Number of voids = " << numVoids << endl; z.allVoids.resize(numVoids); for (int v = 0; v < numVoids; v++) { int32_t numZinV; volFile.read((char *)&numZinV, sizeof(numZinV)); if (!volFile) return false; z.allVoids[v].zId.resize(numZinV); int *zId = new int[numZinV]; volFile.read((char *)zId, sizeof(int)*numZinV); for (int k = 0; k < numZinV; k++) z.allVoids[v].zId[k] = &z.allZones[zId[k]]; delete[] zId; } cout << "Loading description" << endl; string line; getline(descFile, line); getline(descFile, line); getline(descFile, line); while (!descFile.eof()) { istringstream lineStream(line.c_str()); int orderId, volId, coreParticle, numParticlesInZone, numZonesInVoid, numInVoid; float coreDensity, volumeZone, volumeVoid, densityContrast; float probability; lineStream >> orderId >> volId >> coreParticle >> coreDensity >> volumeZone >> numParticlesInZone >> numZonesInVoid >> volumeVoid >> numInVoid >> densityContrast >> probability; if (!lineStream) { cerr << "Error in text stream" << endl; abort(); } z.allVoids[volId].proba = probability; z.allVoids[volId].volume = volumeVoid; z.allVoids[volId].numParticles = numInVoid; z.allVoids[volId].coreParticle = coreParticle; // Sanity check int actualNumber = 0; for (int j = 0; j < z.allVoids[volId].zId.size(); j++) actualNumber += z.allVoids[volId].zId[j]->pId.size(); if (actualNumber != numInVoid) { cerr << "Sanity check failed." << " The number of particles in the description (" << numInVoid << ") is different from the one in the file (" << actualNumber << ")" << endl; } getline(descFile, line); } cout << "Done loading" << endl; return true; }