Merge branch 'master' of file:///home/lavaux/Dropbox/gitRoot/CosmoToolbox

This commit is contained in:
Guilhem Lavaux 2010-04-27 07:16:34 -05:00
commit a9f9338849
2 changed files with 97 additions and 39 deletions

View File

@ -65,95 +65,152 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
{ {
SimuData *data; SimuData *data;
int p, n; int p, n;
UnformattedRead f(fname); UnformattedRead *f;
GadgetHeader h; GadgetHeader h;
if (id >= 0) {
int numDigits = 1;
int mul = 1;
while (mul < id)
{
mul *= 10;
numDigits++;
}
size_t len = numDigits+2+strlen(fname);
char *out_fname = new char[numDigits+2+strlen(fname)];
if (snprintf(out_fname, len, "%s.%d", fname, id) != len)
abort();
f = new UnformattedRead(out_fname);
if (f == 0)
return 0;
delete out_fname;
} else {
f = new UnformattedRead(fname);
if (f == 0)
return 0;
}
data = new SimuData; data = new SimuData;
if (data == 0) {
delete f;
return 0;
}
f.beginCheckpoint(); f->beginCheckpoint();
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
h.npart[i] = f.readInt32(); h.npart[i] = f->readInt32();
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
h.mass[i] = f.readReal64(); h.mass[i] = f->readReal64();
h.time = f.readReal64(); h.time = f->readReal64();
h.redshift = f.readReal64(); h.redshift = f->readReal64();
h.flag_sfr = f.readInt32(); h.flag_sfr = f->readInt32();
h.flag_feedback = f.readInt32(); h.flag_feedback = f->readInt32();
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
h.npartTotal[i] = f.readInt32(); h.npartTotal[i] = f->readInt32();
h.flag_cooling = f.readInt32(); h.flag_cooling = f->readInt32();
h.num_files = f.readInt32(); h.num_files = f->readInt32();
h.BoxSize = f.readReal64(); data->BoxSize = h.BoxSize = f->readReal64();
h.Omega0 = f.readReal64(); h.Omega0 = f->readReal64();
h.OmegaLambda = f.readReal64(); h.OmegaLambda = f->readReal64();
h.HubbleParam = f.readReal64(); h.HubbleParam = f->readReal64();
f.endCheckpoint(true); f->endCheckpoint(true);
long NumPart = 0; long NumPart = 0, NumPartTotal = 0;
for(int k=0; k<5; k++) for(int k=0; k<5; k++)
NumPart += h.npart[k]; {
NumPart += h.npart[k];
NumPartTotal += h.npartTotal[k];
}
data->NumPart = NumPart; data->NumPart = NumPart;
data->TotalNumPart = NumPartTotal;
if (loadflags & NEED_POSITION) { if (loadflags & NEED_POSITION) {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++) {
data->Pos[i] = new float[data->NumPart]; data->Pos[i] = new float[data->NumPart];
if (data->Pos[i] == 0) {
delete data;
return 0;
}
}
f.beginCheckpoint(); f->beginCheckpoint();
for(int k = 0, p = 0; k < 5; k++) { for(int k = 0, p = 0; k < 5; k++) {
for(int n = 0; n < h.npart[k]; n++) { for(int n = 0; n < h.npart[k]; n++) {
data->Pos[p][0] = f.readReal32(); data->Pos[p][0] = f->readReal32();
data->Pos[p][1] = f.readReal32(); data->Pos[p][1] = f->readReal32();
data->Pos[p][2] = f.readReal32(); data->Pos[p][2] = f->readReal32();
p++; p++;
} }
} }
f.endCheckpoint(); f->endCheckpoint();
} else { } else {
// Skip positions // Skip positions
f.skip(NumPart * 3 + 2*4); f->skip(NumPart * 3 * sizeof(float) + 2*4);
} }
if (loadflags & NEED_VELOCITY) { if (loadflags & NEED_VELOCITY) {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
data->Vel[i] = new float[data->NumPart]; {
data->Vel[i] = new float[data->NumPart];
if (data->Vel[i] == 0)
{
delete data;
return 0;
}
}
f.beginCheckpoint(); f->beginCheckpoint();
for(int k = 0, p = 0; k < 5; k++) { for(int k = 0, p = 0; k < 5; k++) {
for(int n = 0; n < h.npart[k]; n++) { for(int n = 0; n < h.npart[k]; n++) {
data->Vel[p][0] = f.readReal32(); data->Vel[p][0] = f->readReal32();
data->Vel[p][1] = f.readReal32(); data->Vel[p][1] = f->readReal32();
data->Vel[p][2] = f.readReal32(); data->Vel[p][2] = f->readReal32();
p++; p++;
} }
} }
f.endCheckpoint(); f->endCheckpoint();
// TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!! // TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!!
} else { } else {
// Skip velocities // Skip velocities
f.skip(NumPart*3+2*4); f->skip(NumPart*3*sizeof(float)+2*4);
} }
// Skip ids // Skip ids
if (loadflags & NEED_GADGET_ID) { if (loadflags & NEED_GADGET_ID) {
f.beginCheckpoint(); f->beginCheckpoint();
data->Id = new int[data->NumPart];
if (data->Id == 0)
{
delete data;
return 0;
}
for(int k = 0, p = 0; k < 6; k++) for(int k = 0, p = 0; k < 6; k++)
{ {
for(int n = 0; n < h.npart[k]; n++) for(int n = 0; n < h.npart[k]; n++)
{ {
data->Id[p] = f.readInt32(); data->Id[p] = f->readInt32();
p++; p++;
} }
} }
f.endCheckpoint(); f->endCheckpoint();
} else { } else {
f.skip(2*4); f->skip(2*4);
for (int k = 0; k < 6; k++) for (int k = 0; k < 6; k++)
f.skip(h.npart[k]); f->skip(h.npart[k]*4);
} }
delete f;
return data; return data;
} }

View File

@ -16,6 +16,7 @@ namespace CosmoTool
float time; float time;
long NumPart; long NumPart;
long TotalNumPart;
int *Id; int *Id;
float *Pos[3]; float *Pos[3];
float *Vel[3]; float *Vel[3];