mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-05 15:51:12 +00:00
Initial import
This commit is contained in:
commit
e57d9a731a
17 changed files with 3271 additions and 0 deletions
136
mytools/loadZobov.cpp
Normal file
136
mytools/loadZobov.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue