Support for quiet mode

This commit is contained in:
Guilhem Lavaux 2009-08-26 11:54:35 -05:00
parent 639635edcd
commit b601bd294f
2 changed files with 42 additions and 28 deletions

View File

@ -15,20 +15,22 @@
using namespace std; using namespace std;
CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name, bool quiet)
{ {
GadgetData *gd = (GadgetData *)malloc(sizeof(GadgetData)); GadgetData *gd = (GadgetData *)malloc(sizeof(GadgetData));
int id = 1; int id = 1;
uint32_t totPart = 0; uint32_t totPart = 0;
cout << "Detecting number of files and particles..." << endl; if (!quiet)
cout << "Detecting number of files and particles..." << endl;
while (1) while (1)
{ {
ostringstream ss_fname; ostringstream ss_fname;
ss_fname << name << setfill('0') << setw(5) << id; ss_fname << name << setfill('0') << setw(5) << id;
string fname = ss_fname.str(); string fname = ss_fname.str();
cout << " ... " << fname << endl; if (!quiet)
cout << " ... " << fname << endl;
try try
{ {
@ -37,7 +39,7 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
int nCpu, ndim, nPar; int nCpu, ndim, nPar;
infile.beginCheckpoint(); infile.beginCheckpoint();
nCpu = infile.readInt32(); nCpu = max(1,infile.readInt32());
infile.endCheckpoint(); infile.endCheckpoint();
infile.beginCheckpoint(); infile.beginCheckpoint();
@ -48,7 +50,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
nPar = infile.readInt32(); nPar = infile.readInt32();
infile.endCheckpoint(); infile.endCheckpoint();
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; if (!quiet)
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl;
totPart += nPar; totPart += nPar;
id++; id++;
@ -61,7 +64,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
assert (totPart <= ((~(size_t)0)/sizeof(ParticleState))); assert (totPart <= ((~(size_t)0)/sizeof(ParticleState)));
size_t memSize = sizeof(ParticleState)*(size_t)totPart; size_t memSize = sizeof(ParticleState)*(size_t)totPart;
cout << " Needing " << memSize / 1024 << " kBytes" << endl; if (!quiet)
cout << " Needing " << memSize / 1024 << " kBytes" << endl;
gd->particles = (ParticleState *)malloc(memSize); gd->particles = (ParticleState *)malloc(memSize);
assert(gd->particles != 0); assert(gd->particles != 0);
gd->NumPart = totPart; gd->NumPart = totPart;
@ -78,8 +82,9 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
gd->header.OmegaLambda = 0.70; // ???? gd->header.OmegaLambda = 0.70; // ????
gd->header.HubbleParam = 0.70; // ???? gd->header.HubbleParam = 0.70; // ????
cout << " Total number part=" << totPart << endl if (!quiet)
<< "Loading particles ..." << endl; cout << " Total number part=" << totPart << endl
<< "Loading particles ..." << endl;
uint32_t curPos = 0; uint32_t curPos = 0;
id = 1; id = 1;
@ -89,7 +94,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
ss_fname << name << setfill('0') << setw(5) << id; ss_fname << name << setfill('0') << setw(5) << id;
string fname = ss_fname.str(); string fname = ss_fname.str();
cout << " ... " << id; if (!quiet)
cout << " ... " << id;
cout.flush(); cout.flush();
try { try {
@ -177,7 +183,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
id++; id++;
} }
cout << endl; if (!quiet)
cout << endl;
return gd; return gd;
} }
@ -245,7 +252,7 @@ int readInfoFile(const char *basename, int outputId, InfoData& info)
return 1; return 1;
} }
CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, int outputId) CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, int outputId, bool quiet)
{ {
PurePositionData *gd = (PurePositionData *)malloc(sizeof(PurePositionData)); PurePositionData *gd = (PurePositionData *)malloc(sizeof(PurePositionData));
int id = 1; int id = 1;
@ -259,26 +266,29 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
return 0; return 0;
double L0 = info.boxSize*info.unitLength/CM_IN_MPC/info.aexp; double L0 = info.boxSize*info.unitLength/CM_IN_MPC/info.aexp;
cout << "L0=" << L0 << " Mpc" << endl; if (!quiet)
cout << "L0=" << L0 << " Mpc" << endl;
cout << "Detecting number of files and particles..." << endl; if (!quiet)
cout << "Detecting number of files and particles..." << endl;
while (1) while (1)
{ {
ostringstream ss_fname; ostringstream ss_fname;
ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id; ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id;
string fname = ss_fname.str(); string fname = ss_fname.str();
cout << " ... " << fname << endl; if (!quiet)
cout << " ... " << fname << endl;
try try
{ {
UnformattedRead infile(fname); UnformattedRead infile(fname);
int nCpu, ndim, nPar; int ndim, nPar;
infile.beginCheckpoint(); infile.beginCheckpoint();
nCpu = infile.readInt32(); nCpu = max(1,infile.readInt32());
infile.endCheckpoint(); infile.endCheckpoint();
infile.beginCheckpoint(); infile.beginCheckpoint();
@ -289,7 +299,8 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
nPar = infile.readInt32(); nPar = infile.readInt32();
infile.endCheckpoint(); infile.endCheckpoint();
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; if (!quiet)
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl;
totPart += nPar; totPart += nPar;
id++; id++;
@ -303,14 +314,16 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
assert (totPart <= ((~(size_t)0)/sizeof(FCoordinates))); assert (totPart <= ((~(size_t)0)/sizeof(FCoordinates)));
size_t memSize = sizeof(FCoordinates)*(size_t)(totPart+totPart/nCpu); size_t memSize = sizeof(FCoordinates)*(size_t)(totPart+totPart/nCpu);
cout << " Needing " << memSize / 1024 << " kBytes" << endl; if (!quiet)
cout << " Needing " << memSize / 1024 << " kBytes" << endl;
gd->pos = (FCoordinates *)malloc(sizeof(FCoordinates)*totPart); gd->pos = (FCoordinates *)malloc(sizeof(FCoordinates)*totPart);
assert(gd->pos != 0); assert(gd->pos != 0);
gd->NumPart = totPart; gd->NumPart = totPart;
gd->BoxSize = L0*1000; gd->BoxSize = L0*1000;
cout << " Total number part=" << totPart << endl if (!quiet)
<< "Loading particles ..." << endl; cout << " Total number part=" << totPart << endl
<< "Loading particles ..." << endl;
uint32_t curPos = 0; uint32_t curPos = 0;
id = 1; id = 1;
@ -322,8 +335,8 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
string fname = ss_fname.str(); string fname = ss_fname.str();
int *idP; int *idP;
cout << " ... " << id; if (!quiet)
cout.flush(); (cout << " ... " << id).flush();
try try
{ {
@ -397,7 +410,8 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
id++; id++;
} }
cout << endl; if (!quiet)
cout << endl;
return gd; return gd;
} }

View File

@ -5,8 +5,8 @@
namespace CosmoTool { namespace CosmoTool {
GadgetData *loadRamses(const char *name); GadgetData *loadRamses(const char *name, bool quiet = false);
PurePositionData *loadRamsesPosition(const char *fname, int id); PurePositionData *loadRamsesPosition(const char *fname, int id, bool quiet = false);
}; };