Esempio n. 1
0
void binary_save(const blitz::Array<T,n> & M,std::string filename)
{
  T z;assert(M.isStorageContiguous());
  std::stringstream f;M.dumpStructureInformation(f);
  std::ofstream out(filename.c_str(),std::ios::binary);
  std::string s = f.str();int i=int(s.length())+1;char c='1';
  out.write( (char*) &i,sizeof(i));
  out.write( (s.c_str()) ,i*sizeof(c));  
  out.write( (char*)M.dataFirst(),M.numElements()*sizeof(z));
}
Esempio n. 2
0
void binary_load(blitz::Array<T,n> & M,std::string filename)
{
  assert(M.isStorageContiguous());T z;
  std::ifstream out(filename.c_str(),std::ios::binary);
  int i;char c='1';
  out.read( (char*) &i,sizeof(i));
  char *st = new char[i+1];
  out.read( st ,i*sizeof(c)); std::string s(st); 
  std::stringstream f;  M.dumpStructureInformation(f);
  if (f.str() != s) FATAL("Can not load binary : array do not conform. Structure (file vs array)"<<s<<"----"<<f.str());
  out.read( (char*)M.dataFirst(),M.numElements()*sizeof(z));
}