Elaboradar  0.1
 Tutto Classi Namespace File Funzioni Variabili Tipi enumerati (enum) Gruppi
void elaboradar::Assets::write_image ( const radarelab::Matrix2D< unsigned char > &  image,
const char *  dir_env_var,
const char *  ext,
const char *  desc 
)

Write an image in a raw file in ${dir_env_var}, with the acquisition date as file name and the given extension.

Image matrix is tranformed in out_image(x,image.cols()-1-y) = image(y, x);

Parametri
[in]image- Matrix2D to be written
[in]dir_env_var- file path
[in]ext- file extension
[out]desc- used to get better error messages.

Definizione alla linea 543 del file assets.cpp.

Referenzia fname_from_acq_time(), e radarelab::fopen_checked().

544 {
545  const char* dir = getenv(dir_env_var);
546  if (!dir)
547  {
548  LOG_INFO("$%s not set", dir_env_var);
549  throw runtime_error("required env var is not set");
550  }
551 
552  string fname = string(dir) + "/" + fname_from_acq_time() + ext;
553  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
554 
555  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
556 
557  // Convert to south-north columns scanned west to east
558  Matrix2D<unsigned char> transformed(image.cols(), image.rows());
559  for (unsigned y = 0; y < image.cols(); ++y)
560  for (unsigned x = 0; x < image.rows(); ++x)
561  transformed(x, image.cols()-1-y) = image(y, x);
562  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
563  {
564  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
565  fclose(out);
566  throw std::runtime_error("cannot write to image file");
567  }
568 
569  fclose(out);
570 }
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
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition: assets.cpp:529