Elaboradar  0.1
 Tutto Classi Namespace File Funzioni Variabili Tipi enumerati (enum) Gruppi
template<class T >
void elaboradar::Assets::load_raw ( const std::string &  fname,
const char *  desc,
radarelab::Matrix2D< T > &  matrix 
)
protected

Load a Matrix2D, from packed row-major binary data.

Definizione alla linea 480 del file assets.cpp.

Referenzia radarelab::fopen_checked().

Referenziato da load_first_level(), load_first_level_bb_bloc(), e load_first_level_bb_el().

481 {
482  LOG_INFO("Opening %s %s", desc, fname.c_str());
483  FILE* in = fopen_checked(fname.c_str(), "rb", desc);
484 
485  // Read the file size
486  fseek(in, 0,SEEK_END);
487  long fsize = ftell(in);
488  rewind(in);
489 
490  // Check that the file size is consistent with what we want
491  if ((unsigned)fsize != matrix.size() * sizeof(T))
492  {
493  LOG_ERROR("Il file %s è %ld byte ma dovrebbe invece essere %ld byte\n",
494  fname.c_str(), fsize, matrix.size() * sizeof(T));
495  throw std::runtime_error("La dimensione della mappa statica non è quello che mi aspetto");
496  }
497  LOG_INFO ("DIMENSIONE MAPPA STATICA %ld %ld", matrix.rows(), matrix.cols());
498 
499  for (unsigned i = 0; i < matrix.rows(); ++i)
500  if (fread(matrix.data() + i * matrix.cols(), matrix.cols(), 1, in) != 1)
501  {
502  std::string errmsg("Error reading ");
503  errmsg += fname;
504  errmsg += ": ";
505  errmsg += strerror(errno);
506  fclose(in);
507  throw std::runtime_error(errmsg);
508  }
509 
510  fclose(in);
511 }
FILE * fopen_checked(const char *fname, const char *mode, const char *description)
A wrapper of fopen that throws an exception if it cannot open the file.
Definition: utils.cpp:144