Commit 112130cf authored by jclamber's avatar jclamber

data STREAM stored in a map string/vector automatically deleted

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@222 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent c21879c6
......@@ -87,6 +87,7 @@ namespace uns {
interface_index=1;
file_structure = "component";
}
}
// ----------------------------------------------------------------------------
// destructor
......@@ -110,6 +111,13 @@ CSnapshotGadgetIn::~CSnapshotGadgetIn()
if (im) delete [] im;
if (ssl) delete [] ssl;
if (cm) delete [] cm;
std::map<std::string,std::vector <float> >::const_iterator it;
for (it = data_vector.begin(); it != data_vector.end(); it++) {
std::cerr << "~CSnapshotGadgetIn(): Delete key = " << it->first
<< " size=" << it->second.size() << "\n";
data_vector[it->first].clear();
}
}
crv.clear();
}
......@@ -277,7 +285,7 @@ template <class T> int CSnapshotGadgetIn::readOneArray(T ** data, const int comp
return 1;
}
// ============================================================================
template <class T> int CSnapshotGadgetIn::readStreamBlock(const std::string req_blockname, int * nbody,T ** data)
template <class T> int CSnapshotGadgetIn::readStreamBlock(const std::string req_blockname, std::vector<T> & data)
{
if (is_read) { // file has already been read
close();
......@@ -311,21 +319,18 @@ template <class T> int CSnapshotGadgetIn::readStreamBlock(const std::string req_
bytes_counter=0;
int len1 = readFRecord();
if (*data==NULL) { // first time
*data = new T[len1/sizeof(T)]; // !! TO CHECK
if (data.size()==0) { // first time
data.resize(len1/sizeof(T)); // !! TO CHECK
}
else {
if (i>0) { // more than one file
T * tmp = new T[(last_len+len1)/sizeof(T)]; // upgrade array
mempcpy((T*) tmp,(T*) *data,last_len/sizeof(T)); // copy old data
delete [] (*data); // delete previous array
*data = tmp; // assign new array
data.resize((last_len+len1)/sizeof(T));
} else {
std::cerr << "WARNING, pointer not allocated...\n";
}
}
T * ptr = *data;
T * ptr = &data[0];
readData((char *) &ptr[last_len], sizeof(T), len1/sizeof(T) );
int len2 = readFRecord();
if (len2==len1) ; // remove warning....
......@@ -347,9 +352,9 @@ template <class T> int CSnapshotGadgetIn::readStreamBlock(const std::string req_
}
}
if (last_len>0) { // found something
*nbody=last_len/sizeof(T);
}
// if (last_len>0) { // found something
// *nbody=last_len/sizeof(T);
// }
return 1;
}
......@@ -1089,10 +1094,20 @@ bool CSnapshotGadgetIn::getData(const std::string comp, std::string name, int *n
break;
default: // unkown name
if (comp=="STREAM") { // data stream reading
int status=readStreamBlock(name,n,data);
if (status>0) {
ok=true;
if (data_vector[name].size()==0) { // map key does not exist
std::vector<float> * p = &(data_vector[name]);
int status=readStreamBlock(name,*p);
if (status>0) {
ok=true;
}
} else {
ok = true;
}
if (ok) {
*n = data_vector[name].size();
*data = &data_vector[name][0];
}
} else {
ok=false;
}
......
......@@ -129,6 +129,10 @@ typedef struct particle_data_lite
int close();
private:
std::map<std::string, std::vector<float> > data_vector; // map container to track vector storage
bool first_loc;
int open(const std::string);
......@@ -217,7 +221,7 @@ typedef struct particle_data_lite
template <class T> int readGasStarsUnknownArray(T ** data, int * n,const int * compOffset);
template <class T> int readOneArray(T ** data, const int compid,const int * compOffset);
template <class T> int readStreamBlock(const std::string blockname, int * nbody,T ** data);
template <class T> int readStreamBlock(const std::string blockname, std::vector<T> &data);
bool readBlockName();
std::string block_name;
int readHeader(const int);
......
......@@ -95,6 +95,7 @@ enum StringData {
// Map to associate component with a type
static std::map<std::string, int> s_mapCompInt;
//
// py wrapper
//
......
......@@ -79,8 +79,8 @@ int main(int argc, char ** argv )
// get MASS from input snapshot
ok=uns->snapshot->getData("mass",&cnbody,&mass);
float * U;
ok=uns->snapshot->getData("STREAM","U",&cnbody,&U);
float * AGE;
ok=uns->snapshot->getData("STREAM","AGE",&cnbody,&AGE);
ok=uns->snapshot->getData("mass",&cnbody,&mass);
......
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