Added support for writing gadget files
This commit is contained in:
parent
dc8ef0be34
commit
d17fbbb66d
@ -273,3 +273,73 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, int loadflags, i
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CosmoTool::writeGadget(const char *fname, SimuData *data, int GadgetFormat)
|
||||
{
|
||||
UnformattedWrite *f;
|
||||
int npart[6];
|
||||
float mass[6];
|
||||
|
||||
if (data->Pos[0] == 0 || data->Vel[0] == 0 || data->Id == 0)
|
||||
return;
|
||||
|
||||
f = new UnformattedWrite(fname);
|
||||
if (f == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
npart[i] = 0;
|
||||
mass[i] = 0;
|
||||
}
|
||||
|
||||
npart[1] = data->NumPart;
|
||||
|
||||
f->beginCheckpoint();
|
||||
for (int i = 0; i < 6; i++)
|
||||
f->writeInt32(npart[i]);
|
||||
for (int i = 0; i < 6; i++)
|
||||
f->writeReal64(mass[i]);
|
||||
|
||||
f->writeReal64(data->time);
|
||||
f->writeReal64(1/data->time-1);
|
||||
f->writeInt32(0);
|
||||
f->writeInt32(0);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
f->writeInt32(npart[i]);
|
||||
f->writeInt32(0);
|
||||
f->writeInt32(1);
|
||||
f->writeReal64(data->BoxSize);
|
||||
f->writeReal64(data->Omega_M);
|
||||
f->writeReal64(data->Omega_Lambda);
|
||||
f->writeReal64(data->Hubble);
|
||||
f->endCheckpoint();
|
||||
|
||||
f->beginCheckpoint();
|
||||
for(int n = 0; n < data->NumPart; n++) {
|
||||
for (int k = 0; k < 3; k++)
|
||||
f->writeReal32(data->Pos[k][n]);
|
||||
}
|
||||
f->endCheckpoint();
|
||||
|
||||
float velmul = 1.0;
|
||||
if (GadgetFormat == 1)
|
||||
velmul = sqrt(data->time);
|
||||
|
||||
f->beginCheckpoint();
|
||||
for(int n = 0; n < data->NumPart; n++) {
|
||||
for (int k = 0; k < 3; k++)
|
||||
f->writeReal32(data->Vel[k][n]/velmul);
|
||||
}
|
||||
f->endCheckpoint();
|
||||
|
||||
f->beginCheckpoint();
|
||||
for(int n = 0; n < data->NumPart; n++)
|
||||
{
|
||||
f->writeReal32(data->Id[n]);
|
||||
}
|
||||
f->endCheckpoint();
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,9 @@ namespace CosmoTool {
|
||||
|
||||
SimuData *loadGadgetMulti(const char *fname, int id, int flags, int GadgetFormat = 1);
|
||||
|
||||
// Only single snapshot supported
|
||||
void writeGadget(const char *fname, SimuData *data, int GadgetFormat = 1);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user