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

View File

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