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,12 +15,13 @@
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;
if (!quiet)
cout << "Detecting number of files and particles..." << endl; cout << "Detecting number of files and particles..." << endl;
while (1) while (1)
{ {
@ -28,6 +29,7 @@ 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();
if (!quiet)
cout << " ... " << fname << endl; 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,6 +50,7 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
nPar = infile.readInt32(); nPar = infile.readInt32();
infile.endCheckpoint(); infile.endCheckpoint();
if (!quiet)
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl;
totPart += nPar; totPart += nPar;
@ -61,6 +64,7 @@ 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;
if (!quiet)
cout << " Needing " << memSize / 1024 << " kBytes" << endl; cout << " Needing " << memSize / 1024 << " kBytes" << endl;
gd->particles = (ParticleState *)malloc(memSize); gd->particles = (ParticleState *)malloc(memSize);
assert(gd->particles != 0); assert(gd->particles != 0);
@ -78,6 +82,7 @@ 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; // ????
if (!quiet)
cout << " Total number part=" << totPart << endl cout << " Total number part=" << totPart << endl
<< "Loading particles ..." << endl; << "Loading particles ..." << endl;
@ -89,6 +94,7 @@ 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();
if (!quiet)
cout << " ... " << id; cout << " ... " << id;
cout.flush(); cout.flush();
@ -177,6 +183,7 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name)
id++; id++;
} }
if (!quiet)
cout << endl; 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,8 +266,10 @@ 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;
if (!quiet)
cout << "L0=" << L0 << " Mpc" << endl; cout << "L0=" << L0 << " Mpc" << endl;
if (!quiet)
cout << "Detecting number of files and particles..." << endl; cout << "Detecting number of files and particles..." << endl;
while (1) while (1)
{ {
@ -268,6 +277,7 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
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();
if (!quiet)
cout << " ... " << fname << endl; cout << " ... " << fname << endl;
@ -275,10 +285,10 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
{ {
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,6 +299,7 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
nPar = infile.readInt32(); nPar = infile.readInt32();
infile.endCheckpoint(); infile.endCheckpoint();
if (!quiet)
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl;
totPart += nPar; totPart += nPar;
@ -303,12 +314,14 @@ 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);
if (!quiet)
cout << " Needing " << memSize / 1024 << " kBytes" << endl; 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;
if (!quiet)
cout << " Total number part=" << totPart << endl cout << " Total number part=" << totPart << endl
<< "Loading particles ..." << endl; << "Loading particles ..." << endl;
@ -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,6 +410,7 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
id++; id++;
} }
if (!quiet)
cout << endl; 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);
}; };