diff --git a/src/loadGadget.cpp b/src/loadGadget.cpp index 64b4970..03f0b78 100644 --- a/src/loadGadget.cpp +++ b/src/loadGadget.cpp @@ -69,18 +69,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) 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(); + int k = snprintf(0, 0, "%s.%d", fname, id)+1; + char *out_fname = new char[k]; + snprintf(out_fname, k, "%s.%d", fname, id); f = new UnformattedRead(out_fname); if (f == 0) @@ -107,7 +98,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) h.npart[i] = f->readInt32(); for (int i = 0; i < 6; i++) h.mass[i] = f->readReal64(); - h.time = f->readReal64(); + data->time = h.time = f->readReal64(); h.redshift = f->readReal64(); h.flag_sfr = 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++) { NumPart += h.npart[k]; - NumPartTotal += h.npartTotal[k]; + NumPartTotal += (id < 0) ? h.npart[k] : h.npartTotal[k]; } data->NumPart = NumPart; data->TotalNumPart = NumPartTotal; @@ -143,9 +134,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) f->beginCheckpoint(); for(int k = 0, p = 0; k < 5; k++) { for(int n = 0; n < h.npart[k]; n++) { - data->Pos[p][0] = f->readReal32(); - data->Pos[p][1] = f->readReal32(); - data->Pos[p][2] = f->readReal32(); + data->Pos[0][p] = f->readReal32(); + data->Pos[1][p] = f->readReal32(); + data->Pos[2][p] = f->readReal32(); p++; } } @@ -170,9 +161,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags) f->beginCheckpoint(); for(int k = 0, p = 0; k < 5; k++) { for(int n = 0; n < h.npart[k]; n++) { - data->Vel[p][0] = f->readReal32(); - data->Vel[p][1] = f->readReal32(); - data->Vel[p][2] = f->readReal32(); + data->Vel[0][p] = f->readReal32(); + data->Vel[1][p] = f->readReal32(); + data->Vel[2][p] = f->readReal32(); p++; } }