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()
{
bool status=false;
if (this->valid) {
if (tools::Ctools::tolower(simtype)=="gadget") {
status=buildGadgetFile();
if (tools::Ctools::tolower(simtype)=="gadget" ||
tools::Ctools::tolower(simtype)=="gadget3") {
status=buildAllGadgetFile();
}
else {
if (tools::Ctools::tolower(simtype)=="nemo") {
......@@ -518,13 +519,8 @@ template <class T> bool CSnapshotSimIn<T>::isNewFrame()
if (tools::Ctools::tolower(simtype)=="ramses") {
status=buildRamsesFile();
}
else {
if (tools::Ctools::tolower(simtype)=="gadget3") { // hdf5
status=buildGadgetH5File();
}
else {
std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
}
else {
std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
}
}
}
......@@ -567,9 +563,10 @@ template <class T> bool CSnapshotSimIn<T>::buildNemoFile()
}
return status;
}
// ============================================================================
// buildGadgetFile
template <class T> bool CSnapshotSimIn<T>::buildGadgetH5File()
// buildAllGadgetFile (gadget 1,2 or 3 format)
template <class T> bool CSnapshotSimIn<T>::buildAllGadgetFile()
{
bool stop=false,status=false;
int cpt=1;
......@@ -580,61 +577,24 @@ template <class T> bool CSnapshotSimIn<T>::buildGadgetH5File()
std::ostringstream ss;
ss << std::setw(cpt) << std::setfill('0') << nframe;
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;
// try to open file with ".hdf5 extension"
snapshot = new CSnapshotGadgetH5In<T>(myfile+".hdf5", this->select_part, this->select_time, this->verbose);
if (snapshot) delete snapshot;
// try to open Gadget1/2 file
snapshot = new CSnapshotGadgetIn<T>(myfile, this->select_part, this->select_time, this->verbose);
if (!snapshot->isValidData()) {
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) {
nframe++; // next frame index
}
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";)
// try to open gadget3 file with ".hdf5 extension"
snapshot = new CSnapshotGadgetH5In<T>(myfile+".hdf5", this->select_part, this->select_time, this->verbose);
if (snapshot) delete snapshot;
// try to open file
snapshot = new CSnapshotGadgetIn<T>(myfile, this->select_part, this->select_time, this->verbose);
if (!snapshot->isValidData()) {
delete snapshot;
// 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
T t;
bool ok=snapshot->getData("time",&t);
......
......@@ -86,8 +86,7 @@ namespace uns {
std::string dirname; // sim's dirname
std::string basename;// sim's basename
int nframe; // #frames read
bool buildGadgetFile();
bool buildGadgetH5File();
bool buildAllGadgetFile();
bool buildNemoFile();
bool buildRamsesFile();
int addNemoComponent(int&,std::string,std::string );
......
......@@ -58,7 +58,7 @@
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; }
......
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