Added support for types and masses

This commit is contained in:
Guilhem Lavaux 2014-07-05 22:05:04 +02:00
parent 33806a690f
commit fc44597829
3 changed files with 87 additions and 3 deletions

View file

@ -261,6 +261,42 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
f->skip(h.npart[k]*4);
}
if (loadflags & NEED_MASS) {
try
{
long l = 0;
f->beginCheckpoint();
data->Mass = new float[NumPart];
for (int k = 0; k < 6; k++)
{
if (h.mass[k] == 0) {
for(int n = 0; n < h.npart[k]; n++)
{
data->Mass[l++] = f->readReal32();
}
} else {
for(int n = 0; n < h.npart[k]; n++)
{
data->Mass[l++] = h.mass[k];
}
}
}
f->endCheckpoint();
}
catch (const InvalidUnformattedAccess& e)
{
cerr << "Invalid unformatted access while reading ID" << endl;
delete f;
delete data;
return 0;
}
} else {
f->skip(2*4);
for (int k = 0; k < 6; k++)
if (h.mass[k] == 0)
f->skip(h.npart[k]*4);
}
delete f;
return data;

View file

@ -45,6 +45,7 @@ namespace CosmoTool
static const int NEED_POSITION = 2;
static const int NEED_VELOCITY = 4;
static const int NEED_TYPE = 8;
static const int NEED_MASS = 16;
struct SimuParticle
{
@ -78,12 +79,13 @@ namespace CosmoTool
long *Id;
float *Pos[3];
float *Vel[3];
float *Mass;
int *type;
AttributeMap attributes;
public:
SimuData() : Id(0),NumPart(0),type(0),noAuto(false) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; }
SimuData() : Mass(0), Id(0),NumPart(0),type(0),noAuto(false) { Pos[0]=Pos[1]=Pos[2]=0; Vel[0]=Vel[1]=Vel[2]=0; }
~SimuData()
{
if (!noAuto) {
@ -98,6 +100,8 @@ namespace CosmoTool
delete[] type;
if (Id)
delete[] Id;
if (Mass)
delete[] Mass;
}
for (AttributeMap::iterator i = attributes.begin();
i != attributes.end();