Commit c32129b9 authored by jclamber's avatar jclamber

add acc output for gadget2 files

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@123 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 8e21a9ad
......@@ -1276,12 +1276,14 @@ CSnapshotGadgetOut::CSnapshotGadgetOut(const std::string _n, const std::string _
pos [i] = NULL;
vel [i] = NULL;
pot [i] = NULL;
acc [i] = NULL;
id [i] = NULL;
ptrIsAlloc[i]["mass" ]=false;
ptrIsAlloc[i]["pos" ]=false;
ptrIsAlloc[i]["vel" ]=false;
ptrIsAlloc[i]["id" ]=false;
ptrIsAlloc[i]["pot" ]=false;
ptrIsAlloc[i]["acc" ]=false;
}
//id = NULL;
age = NULL;
......@@ -1315,6 +1317,7 @@ CSnapshotGadgetOut::~CSnapshotGadgetOut()
if (vel [i]&& ptrIsAlloc[i]["vel" ]) delete [] vel[i];
if (id [i]&& ptrIsAlloc[i]["id" ]) delete [] id[i];
if (pot [i]&& ptrIsAlloc[i]["pot" ]) delete [] pot[i];
if (acc [i]&& ptrIsAlloc[i]["acc" ]) delete [] acc[i];
}
// gas only
if (rho && ptrIsAlloc[0]["rho" ]) delete [] rho;
......@@ -1459,6 +1462,9 @@ int CSnapshotGadgetOut::setData(std::string name,std::string array, const int n
case uns::Pot :
status = setPot(name, n, data, _addr);
break;
case uns::Acc :
status = setAcc(name, n, data, _addr);
break;
case uns::Hsml :
status = setHsml(n, data, _addr);
break;
......@@ -1729,7 +1735,34 @@ int CSnapshotGadgetOut::setPos(std::string name, const int _n, float * _pos, con
bits |= POT_BIT;
return 1;
}
// ============================================================================
// setAcc:
int CSnapshotGadgetOut::setAcc(std::string name, const int _n, float * _acc, const bool addr)
{
int index=-1;
switch(CunsOut::s_mapStringValues[name]) {
case uns::Gas : index=0; break;
case uns::Halo : index=1; break;
case uns::Disk : index=2; break;
case uns::Bulge : index=3; break;
case uns::Stars : index=4; break;
case uns::Bndry : index=5; break;
default:
break;
}
if (addr) { // map address
acc[index] = _acc;
}
else {
ptrIsAlloc[index]["acc"]=true;
if (acc[index]) delete [] acc[index];
acc[index] = new float[_n*3];
memcpy(acc[index],_acc,sizeof(float)*_n*3);
}
header.npart[index] = _n;
bits |= ACC_BIT;
return 1;
}
// ============================================================================
// setRho:
int CSnapshotGadgetOut::setRho(const int _n, float * _rho, const bool addr)
......@@ -2071,19 +2104,7 @@ int CSnapshotGadgetOut::write()
if (header.npart[k] && header.mass[k]==0) // mass exist for the component
writeData((char *) mass[k], sizeof(float), header.npart[k]);
writeFRecord(blk);
}
if (bits & POT_BIT) {
blk=sizeof(float)*npartTotal;
writeBlockName("POT ",blk);
writeFRecord(blk);
for(int k=0;k<6;k++) {
if (header.npart[k]) { // pos exist for the component
assert(pot[k]!=NULL);
writeData((char *) pot[k], sizeof(float), header.npart[k]);
}
}
writeFRecord(blk);
}
}
// U
if (bits & U_BIT) {
assert(header.npart[0]>0);
......@@ -2092,16 +2113,7 @@ int CSnapshotGadgetOut::write()
writeFRecord(blk);
writeData((char *) intenerg, sizeof(float), header.npart[0]);
writeFRecord(blk);
}
// Temp
if (bits & TEMP_BIT) {
assert(header.npart[0]>0);
blk=sizeof(float)*header.npart[0];
writeBlockName("NE ",blk);
writeFRecord(blk);
writeData((char *) temp, sizeof(float), header.npart[0]);
writeFRecord(blk);
}
}
// RHO
if (bits & RHO_BIT) {
assert(header.npart[0]>0);
......@@ -2120,6 +2132,38 @@ int CSnapshotGadgetOut::write()
writeData((char *) hsml, sizeof(float), header.npart[0]);
writeFRecord(blk);
}
// Pot
if (bits & POT_BIT) {
blk=sizeof(float)*npartTotal;
writeBlockName("POT ",blk);
writeFRecord(blk);
for(int k=0;k<6;k++) {
if (header.npart[k]) { // pos exist for the component
assert(pot[k]!=NULL);
writeData((char *) pot[k], sizeof(float), header.npart[k]);
}
}
writeFRecord(blk);
}
// ACC
if (bits & ACC_BIT) {
blk=sizeof(float)*3*npartTotal;
writeBlockName("ACC ",blk);
writeFRecord(blk);
for(int k=0;k<6;k++)
if (header.npart[k]) // acc exist for the component
writeData((char *) acc[k], sizeof(float)*3, header.npart[k]);
writeFRecord(blk);
}
// Temp
if (bits & TEMP_BIT) {
assert(header.npart[0]>0);
blk=sizeof(float)*header.npart[0];
writeBlockName("NE ",blk);
writeFRecord(blk);
writeData((char *) temp, sizeof(float), header.npart[0]);
writeFRecord(blk);
}
// Metal
if (bits & METAL_BIT) {
int nb=(header.npart[0]+header.npart[4]);
......
......@@ -286,7 +286,7 @@ typedef struct particle_data_lite
private:
//data
float * mass[6], * pos[6], * vel[6], * pot[6], * rho, * hsml, * age, * metal, * intenerg, * temp;
float * mass[6], * pos[6], *acc[6], * vel[6], * pot[6], * rho, * hsml, * age, * metal, * intenerg, * temp;
int * id[6];
int ntot_withmasses;
std::ofstream out;
......@@ -313,6 +313,7 @@ typedef struct particle_data_lite
int setVel (std::string, const int _n, float * _vel , const bool addr);
int setId (std::string, const int _n, int * _id , const bool addr);
int setPot (std::string, const int _n, float * _pot , const bool addr);
int setAcc (std::string, const int _n, float * _acc , const bool addr);
int setRho (const int _n, float * _rho , const bool addr);
int setHsml(const int _n, float * _hsml, const bool addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment