Commit 3c5bca3a authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles

unify gadget1-2-3 reading from sqlite3 db

parent 0cfa71b5
File mode changed from 100644 to 100755
...@@ -507,8 +507,9 @@ template <class T> bool CSnapshotSimIn<T>::isNewFrame() ...@@ -507,8 +507,9 @@ template <class T> bool CSnapshotSimIn<T>::isNewFrame()
{ {
bool status=false; bool status=false;
if (this->valid) { if (this->valid) {
if (tools::Ctools::tolower(simtype)=="gadget") { if (tools::Ctools::tolower(simtype)=="gadget" ||
status=buildGadgetFile(); tools::Ctools::tolower(simtype)=="gadget3") {
status=buildAllGadgetFile();
} }
else { else {
if (tools::Ctools::tolower(simtype)=="nemo") { if (tools::Ctools::tolower(simtype)=="nemo") {
...@@ -518,13 +519,8 @@ template <class T> bool CSnapshotSimIn<T>::isNewFrame() ...@@ -518,13 +519,8 @@ template <class T> bool CSnapshotSimIn<T>::isNewFrame()
if (tools::Ctools::tolower(simtype)=="ramses") { if (tools::Ctools::tolower(simtype)=="ramses") {
status=buildRamsesFile(); status=buildRamsesFile();
} }
else { else {
if (tools::Ctools::tolower(simtype)=="gadget3") { // hdf5 std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
status=buildGadgetH5File();
}
else {
std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
}
} }
} }
} }
...@@ -567,9 +563,10 @@ template <class T> bool CSnapshotSimIn<T>::buildNemoFile() ...@@ -567,9 +563,10 @@ template <class T> bool CSnapshotSimIn<T>::buildNemoFile()
} }
return status; return status;
} }
// ============================================================================ // ============================================================================
// buildGadgetFile // buildAllGadgetFile (gadget 1,2 or 3 format)
template <class T> bool CSnapshotSimIn<T>::buildGadgetH5File() template <class T> bool CSnapshotSimIn<T>::buildAllGadgetFile()
{ {
bool stop=false,status=false; bool stop=false,status=false;
int cpt=1; int cpt=1;
...@@ -580,61 +577,24 @@ template <class T> bool CSnapshotSimIn<T>::buildGadgetH5File() ...@@ -580,61 +577,24 @@ template <class T> bool CSnapshotSimIn<T>::buildGadgetH5File()
std::ostringstream ss; std::ostringstream ss;
ss << std::setw(cpt) << std::setfill('0') << nframe; ss << std::setw(cpt) << std::setfill('0') << nframe;
std::string myfile = dirname+'/'+basename+'_'+ss.str(); std::string myfile = dirname+'/'+basename+'_'+ss.str();
PRINT("CSnapshotSimIn<T>::buildGadgetH5File() myfile=["<<myfile<<"]\n";) PRINT("CSnapshotSimIn<T>::buildGadgetFile() myfile=["<<myfile<<"]\n";)
if (snapshot) delete snapshot; if (snapshot) delete snapshot;
// try to open file with ".hdf5 extension" // try to open Gadget1/2 file
snapshot = new CSnapshotGadgetH5In<T>(myfile+".hdf5", this->select_part, this->select_time, this->verbose); snapshot = new CSnapshotGadgetIn<T>(myfile, this->select_part, this->select_time, this->verbose);
if (!snapshot->isValidData()) { if (!snapshot->isValidData()) {
delete snapshot; delete snapshot;
// try to open file without ".hdf5 extension"
snapshot = new CSnapshotGadgetH5In<T>(myfile, this->select_part, this->select_time, this->verbose);
}
if (snapshot->isValidData()) { // file exist
T t;
bool ok=snapshot->getData("time",&t);
if (ok && this->checkRangeTime(t)) { // time in range
status=true; // valid snap
stop=true; // get out loop
} else { // time out of range
delete snapshot; // del object
snapshot = NULL; // NULL for the next
nframe++; // try next frame
}
}
else { // file does not exist
delete snapshot;
snapshot = NULL;
cpt++;
}
}
if (status) { // try to open gadget3 file with ".hdf5 extension"
nframe++; // next frame index snapshot = new CSnapshotGadgetH5In<T>(myfile+".hdf5", this->select_part, this->select_time, this->verbose);
}
if (sel_from_index) { // occurs only one time
force_stop = true;
}
return status;
}
// ============================================================================
// buildGadgetFile
template <class T> bool CSnapshotSimIn<T>::buildGadgetFile()
{
bool stop=false,status=false;
int cpt=1;
// loop on all the possibility of file
// dirname+basename+nframe
// ex : gas001_0 gas001_00 gas001_000
while (!force_stop && !stop && cpt<=5) {
std::ostringstream ss;
ss << std::setw(cpt) << std::setfill('0') << nframe;
std::string myfile = dirname+'/'+basename+'_'+ss.str();
PRINT("CSnapshotSimIn<T>::buildGadgetFile() myfile=["<<myfile<<"]\n";)
if (snapshot) delete snapshot; if (!snapshot->isValidData()) {
// try to open file delete snapshot;
snapshot = new CSnapshotGadgetIn<T>(myfile, this->select_part, this->select_time, this->verbose); // try to open gadget3 file without ".hdf5 extension"
snapshot = new CSnapshotGadgetH5In<T>(myfile, this->select_part, this->select_time, this->verbose);
}
}
if (snapshot->isValidData()) { // file exist if (snapshot->isValidData()) { // file exist
T t; T t;
bool ok=snapshot->getData("time",&t); bool ok=snapshot->getData("time",&t);
......
...@@ -86,8 +86,7 @@ namespace uns { ...@@ -86,8 +86,7 @@ namespace uns {
std::string dirname; // sim's dirname std::string dirname; // sim's dirname
std::string basename;// sim's basename std::string basename;// sim's basename
int nframe; // #frames read int nframe; // #frames read
bool buildGadgetFile(); bool buildAllGadgetFile();
bool buildGadgetH5File();
bool buildNemoFile(); bool buildNemoFile();
bool buildRamsesFile(); bool buildRamsesFile();
int addNemoComponent(int&,std::string,std::string ); int addNemoComponent(int&,std::string,std::string );
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
namespace uns { namespace uns {
const std::string VERSION="1.2.0.pre-November-24th-2016"; // UNSIO version const std::string VERSION="1.2.0.pre-January-04th-2018"; // UNSIO version
inline std::string getVersion() { return uns::VERSION; } inline std::string getVersion() { return uns::VERSION; }
......
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