U
This commit is contained in:
parent
a9f9338849
commit
779aa58900
@ -69,18 +69,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
|||||||
GadgetHeader h;
|
GadgetHeader h;
|
||||||
|
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
int numDigits = 1;
|
int k = snprintf(0, 0, "%s.%d", fname, id)+1;
|
||||||
int mul = 1;
|
char *out_fname = new char[k];
|
||||||
while (mul < id)
|
snprintf(out_fname, k, "%s.%d", fname, 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);
|
f = new UnformattedRead(out_fname);
|
||||||
if (f == 0)
|
if (f == 0)
|
||||||
@ -107,7 +98,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
|||||||
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();
|
data->time = 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();
|
||||||
@ -125,7 +116,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
|||||||
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];
|
NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k];
|
||||||
}
|
}
|
||||||
data->NumPart = NumPart;
|
data->NumPart = NumPart;
|
||||||
data->TotalNumPart = NumPartTotal;
|
data->TotalNumPart = NumPartTotal;
|
||||||
@ -143,9 +134,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
|||||||
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[0][p] = f->readReal32();
|
||||||
data->Pos[p][1] = f->readReal32();
|
data->Pos[1][p] = f->readReal32();
|
||||||
data->Pos[p][2] = f->readReal32();
|
data->Pos[2][p] = f->readReal32();
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,9 +161,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags)
|
|||||||
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[0][p] = f->readReal32();
|
||||||
data->Vel[p][1] = f->readReal32();
|
data->Vel[1][p] = f->readReal32();
|
||||||
data->Vel[p][2] = f->readReal32();
|
data->Vel[2][p] = f->readReal32();
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user