From b601bd294f45002ba1e9e588e5684ed2cbf0abca Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 26 Aug 2009 11:54:35 -0500 Subject: [PATCH] Support for quiet mode --- src/loadRamses.cpp | 66 ++++++++++++++++++++++++++++------------------ src/loadRamses.hpp | 4 +-- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/loadRamses.cpp b/src/loadRamses.cpp index 57d2ae8..a7e8870 100644 --- a/src/loadRamses.cpp +++ b/src/loadRamses.cpp @@ -15,20 +15,22 @@ 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; - - cout << "Detecting number of files and particles..." << endl; + + if (!quiet) + cout << "Detecting number of files and particles..." << endl; while (1) { ostringstream ss_fname; ss_fname << name << setfill('0') << setw(5) << id; string fname = ss_fname.str(); - cout << " ... " << fname << endl; + 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,7 +50,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) nPar = infile.readInt32(); infile.endCheckpoint(); - cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; + if (!quiet) + cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; totPart += nPar; id++; @@ -61,7 +64,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) assert (totPart <= ((~(size_t)0)/sizeof(ParticleState))); 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); assert(gd->particles != 0); gd->NumPart = totPart; @@ -78,8 +82,9 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) gd->header.OmegaLambda = 0.70; // ???? gd->header.HubbleParam = 0.70; // ???? - cout << " Total number part=" << totPart << endl - << "Loading particles ..." << endl; + if (!quiet) + cout << " Total number part=" << totPart << endl + << "Loading particles ..." << endl; uint32_t curPos = 0; id = 1; @@ -89,7 +94,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) ss_fname << name << setfill('0') << setw(5) << id; string fname = ss_fname.str(); - cout << " ... " << id; + if (!quiet) + cout << " ... " << id; cout.flush(); try { @@ -177,7 +183,8 @@ CosmoTool::GadgetData *CosmoTool::loadRamses(const char *name) id++; } - cout << endl; + 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,26 +266,29 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, return 0; 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) { ostringstream ss_fname; ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id; string fname = ss_fname.str(); - - cout << " ... " << fname << endl; + + if (!quiet) + cout << " ... " << fname << endl; try { 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,7 +299,8 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, nPar = infile.readInt32(); infile.endCheckpoint(); - cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; + if (!quiet) + cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl; totPart += nPar; id++; @@ -303,15 +314,17 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, assert (totPart <= ((~(size_t)0)/sizeof(FCoordinates))); 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); assert(gd->pos != 0); gd->NumPart = totPart; gd->BoxSize = L0*1000; - cout << " Total number part=" << totPart << endl - << "Loading particles ..." << endl; - + if (!quiet) + cout << " Total number part=" << totPart << endl + << "Loading particles ..." << endl; + uint32_t curPos = 0; id = 1; while (1) @@ -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,7 +410,8 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename, id++; } - cout << endl; + if (!quiet) + cout << endl; return gd; } diff --git a/src/loadRamses.hpp b/src/loadRamses.hpp index c23d178..7ad966c 100644 --- a/src/loadRamses.hpp +++ b/src/loadRamses.hpp @@ -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); };