Elaboradar  0.1
assets.cpp
1 #include "assets.h"
2 #include "config.h"
3 #include <radarelab/utils.h>
4 #include <radarelab/matrix.h>
5 #include <radarelab/image.h>
6 #include <radarelab/algo/dbz.h>
7 #include <radarelab/algo/vpr.h>
8 #include <radarelab/vpr_par.h>
9 #include "site.h"
10 #include <cstring>
11 #include <cstdlib>
12 #include <cmath>
13 #include <cerrno>
14 #include <stdint.h>
15 #include <stdexcept>
16 
17 using namespace std;
18 using namespace radarelab;
19 
20 namespace elaboradar {
21 
22 Assets::Assets(const Config& cfg)
23  : logging_category(log4c_category_get("radar.assets")), cfg(cfg), outfile_devel_data(0)
24 {
25 #ifdef HAVE_GDAL
27 #endif
28 }
29 
30 Assets::~Assets()
31 {
32  if (outfile_devel_data)
33  delete outfile_devel_data;
34 }
35 
36 void Assets::configure(const char* site, time_t acq_time)
37 {
38  configure(Site::get(site), acq_time);
39 }
40 
41 void Assets::configure(const Site& site, time_t acq_time)
42 {
43  conf_site = &site;
44  conf_acq_time = acq_time;
45  struct tm* tempo = gmtime(&acq_time);
46  conf_year = tempo->tm_year + 1900;
47  conf_month = tempo->tm_mon + 1;
48  conf_day = tempo->tm_mday;
49  conf_hour = tempo->tm_hour;
50  conf_minute = tempo->tm_min;
51 }
52 
53 bool Assets::save_acq_time(time_t acq_time)
54 {
55  if (acq_time == 0) acq_time = conf_acq_time;
56 
57  // If LAST_FILE is not set, return true
58  const char* last_file = getenv("LAST_FILE");
59  if (last_file == NULL)
60  {
61  LOG_INFO("$LAST_FILE not set");
62  return true;
63  }
64 
65  bool res = true;
66  uint32_t last_time;
67 
68  FILE* fp = fopen(last_file, "r");
69 
70  // If the file does not exist, return true
71  if (fp == NULL)
72  {
73  LOG_INFO("$LAST_FILE=%s does not exist", last_file);
74  last_time = 0;
75  goto check;
76  }
77 
78  // If the file is empty, return true
79  if (fread(&last_time, 4, 1, fp) != 1)
80  {
81  LOG_INFO("$LAST_FILE=%s cannot be read", last_file);
82  last_time = 0;
83  goto check;
84  }
85 
86 check:
87  {
88  int diff = acq_time - last_time;
89  LOG_INFO("%s: new acq_time is old %c %d", last_file, diff < 0 ? '-' : '+', abs(diff));
90  }
91 
92  if (acq_time <= last_time)
93  res = false;
94 
95  if (fp) fclose(fp);
96 
97  if ((fp = fopen(last_file, "w")) == NULL)
98  {
99  LOG_WARN("cannot write to %s: %s", last_file, strerror(errno));
100  throw std::runtime_error("cannot (re)create $LAST_FILE");
101  }
102 
103  // Fit acq_time in 4 bytes (FIXME: so far so good, until 2036)
104  last_time = acq_time;
105  if (fwrite(&last_time, 4, 1, fp) != 1)
106  {
107  LOG_WARN("cannot write to %s: %s", last_file, strerror(errno));
108  throw std::runtime_error("cannot write to $LAST_FILE");
109  }
110  fclose(fp);
111 
112  return res;
113 }
114 
116 {
117  load_ascii(conf_site->get_dem_file_name(), "file dem", matrix);
118 }
119 
121 {
122  const char* fname = getenv("FIRST_LEVEL_FILE");
123  if (!fname){
124  LOG_WARN("leggo datipath da conf_site..");
125  fname = conf_site->get_first_level_file_name(conf_month);
126  }
127  load_raw(fname, "mappa statica", matrix);
128 }
129 
131 {
132  load_raw(fname_out_pp_bloc("mat_el.bin"), "elev BB", matrix);
133 }
134 
136 {
137  load_raw(fname_out_pp_bloc("mat_bloc.bin"), "elev BB", matrix);
138 }
139 
140 namespace {
141 
142 double parse_hray(File& fd, std::function<void (unsigned el, unsigned bin, double value)> on_sample)
143 {
144  size_t line_no = 0;
145  double dtrs;
146  fd.read_lines([&](char* line, size_t len) {
147  if (line_no == 0)
148  {
149  // Read dtrs in the first line
150  dtrs = strtod(line, NULL);
151  } else {
152  char* s = line;
153  int el = 0;
154  while (true)
155  {
156  char* next;
157  double val = strtod(s, &next);
158  if (next == s) break;
159  on_sample(el, line_no - 1, val);
160  s = next;
161  ++el;
162  }
163  }
164  ++line_no;
165  });
166  if (line_no == 0)
167  throw std::runtime_error("hray/hray_inf file is empty");
168  return dtrs;
169 }
170 
171 }
172 
173 double Assets::read_file_hray(std::function<void (unsigned el, unsigned bin, double value)> on_sample)
174 {
175  File fd(logging_category);
176  if (!fd.open(fname_out_pp_bloc("h_ray.txt"), "rb", "hray"))
177  throw std::runtime_error("cannot open hray file");
178  return parse_hray(fd, on_sample);
179 }
180 
181 double Assets::read_file_hray_inf(std::function<void (unsigned el, unsigned bin, double value)> on_sample)
182 {
183  File fd(logging_category);
184  if (!fd.open(fname_out_pp_bloc("h_rayinf.txt"), "rb", "hray inf"))
185  throw std::runtime_error("cannot open hray inf file");
186  return parse_hray(fd, on_sample);
187 }
188 
189 std::string Assets::fname_out_pp_bloc(const char* suffix) const
190 {
191  const char* dir = getenv("DIR_OUT_PP_BLOC");
192  if (!dir) throw runtime_error("DIR_OUT_PP_BLOC is not set");
193 
194  char fname[1024];
195  sprintf(fname, "%s/%04d%02d%02d%02d%02d%s", dir,
196  conf_year, conf_month, conf_day, conf_hour, conf_minute, suffix);
197 
198  return fname;
199 }
200 
202 {
203  LOG_CATEGORY("radar.vpr");
204  File in(logging_category);
205  if (!in.open_from_env("FILE_T", "rt"))
206  return NODATAVPR;
207 
208  float media_t = 0;
209  int icount = 0;
210  float lon, lat, t;
211 
212  while (1) {
213  if(fscanf(in, "%f %f %f \n",&lon,&lat,&t) == EOF) break;
214  if (fabs(conf_site->radarSite.lat_r-lat)<=maxdlat && fabs(conf_site->radarSite.lon_r-lon)<=maxdlon) {
215  ++icount;
216  media_t += t - 273.15;
217  }
218  }
219 
220  if (icount == 0)
221  {
222  LOG_ERROR("Temperature data not found in $FILE_T=%s", in.name());
223  return NODATAVPR;
224  }
225 
226  media_t /= (float)icount;
227  LOG_INFO("ho %i stazioni dati affidabili e la t media è %f\n", icount, media_t);
228  return media_t;
229 }
230 
231 long int Assets::read_profile_gap() const
232 {
233  LOG_CATEGORY("radar.vpr");
234  File in(logging_category);
235  if (!in.open_from_env("LAST_VPR", "rb"))
236  return 100;
237 
238  // FIXME: time_t può essere 64 bit, qui viene sempre troncato.
239  // FIXME: l'ideale sarebbe, in questo caso, usare fprintf/fscanf invece di
240  // FIXME: fread/fwrite
241  uint32_t last_time;
242  fread(&last_time, 4, 1, in);
243 
244  long int gap1 = abs(conf_acq_time - last_time)/900;
245  LOG_INFO("old_data_header.norm.maq.acq_date last_time gap %ld %u %ld", conf_acq_time, last_time, gap1);
246 
247  return gap1;
248 }
249 
251 {
252  LOG_CATEGORY("radar.vpr");
253  File in(logging_category);
254  if (!in.open_from_env("VPR_HEATING", "rt"))
255  return 0;
256 
257  int heating;
258  if (fscanf(in, "%i ", &heating) != 1)
259  {
260  LOG_ERROR("Cannot read $VPR_HEATING=%s: %s", in.name(), strerror(errno));
261  return 0;
262  }
263 
264  return heating;
265 }
266 
267 void Assets::write_vpr_heating(int value) const
268 {
269  LOG_CATEGORY("radar.vpr");
270  File out(logging_category);
271  if (!out.open_from_env("VPR_HEATING", "wt"))
272  return;
273 
274  if (fprintf(out, " %i \n", value) < 0)
275  LOG_ERROR("Cannot write $VPR_HEATING=%s: %s", out.name(), strerror(errno));
276 }
277 
278 bool Assets::read_0term(float& zeroterm)
279 {
280  LOG_CATEGORY("radar.class");
281  File in(logging_category);
282  if (!in.open_from_env("FILE_ZERO_TERMICO", "rt"))
283  return false;
284 
285  if (fscanf(in, "%f", &zeroterm) != 1)
286  {
287  LOG_ERROR("$FILE_ZERO_TERMICO=%s cannot be read: %s", in.name(), strerror(errno));
288  return false;
289  }
290 
291  return true;
292 }
293 
295 {
296  //LOG_CATEGORY("radar.vpr");
297  const char* fname = getenv("LAST_VPR");
298  if (!fname) throw runtime_error("$LAST_VPR is not set");
299  FILE* out = fopen_checked(fname, "wb", "ultimo VPR");
300  uint32_t val = conf_acq_time;
301  fwrite(&val, 4, 1, out);
302  fclose(out);
303 }
304 
306 {
307  File in(logging_category);
308  if (!in.open_from_env("VPR_HMAX", "rt"))
309  return -9999;
310 
311  int value;
312  if (fscanf(in, "%i", &value) != 1)
313  {
314  LOG_ERROR("$VPR_HMAX=%s cannot be read: %s", in.name(), strerror(errno));
315  return -9999;
316  }
317 
318  LOG_INFO("fatta lettura hmax vpr = %i", value);
319  return value;
320 }
321 
322 void Assets::write_vpr_hmax(int hvprmax)
323 {
324  const char* fname = getenv("VPR_HMAX");
325  if (!fname) throw runtime_error("$VPR_HMAX is not set");
326  FILE* out = fopen_checked(fname, "wt", "hmax VPR");
327  fprintf(out, "%d", hvprmax);
328  fclose(out);
329 }
330 
331 bool Assets::read_vpr0(algo::VPR& vpr0)
332 {
333  File in(logging_category);
334  if (!in.open_from_env("VPR0_FILE", "rt")) return false;
335 
336  for (unsigned i = 0; i < vpr0.size(); ++i)
337  //-----leggo vpr e area per ogni strato----
338  if (fscanf(in, "%f %li\n", &vpr0.val[i], &vpr0.area[i]) != 2)
339  {
340  LOG_ERROR("$VPR0_FILE=%s cannot be read: %s", in.name(), strerror(errno));
341  throw std::runtime_error("cannot read $VPR0_FILE");
342  }
343 
344  return true;
345 }
346 
347 bool Assets::read_archived_vpr(const algo::DBZ& dbz, time_t time, radarelab::algo::VPR& vpr)
348 {
349  const char* dir = getenv("DIR_STORE_VPR"); //--questa non sarebbe una dir_arch più che store?... contesto il nome...
350  if (!dir) return false;
351 
352  struct tm t;
353  gmtime_r(&time, &t);
354 
355  char fname[64];
356  snprintf(fname, 64, "%04d%02d%02d%02d%02d_vpr_%s",
357  t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
358  t.tm_hour, t.tm_min, conf_site->name.c_str());
359 
360  string pathname = dir;
361  pathname += "/";
362  pathname += fname;
363 
364  File in(logging_category);
365  if (!in.open(pathname, "r", "archived VPR file"))
366  return false;
367 
368  // TODO: check the actual format of the file and make the parsing safe:
369  // currently if one of these strings is longer than 99, we crash or worse.
370  char stringa[100];
371  fscanf(in, " %s %s %s %s" ,stringa ,stringa,stringa,stringa);
372  for (unsigned ilay=0; ilay < vpr.size(); ++ilay){
373  float vpr_dbz;
374  long int ar;
375  int il;
376  fscanf(in, " %i %f %li", &il, &vpr_dbz, &ar); //---NB il file in archivio è in dBZ e contiene anche la quota----
377 
378  //---- converto in R il profilo vecchio--
379  if (vpr_dbz > 0)
380  {
381  vpr.val[ilay] = dbz.DBZtoR(vpr_dbz);
382  vpr.area[ilay] = ar;
383  }
384  else
385  vpr.val[ilay] = NODATAVPR;
386  }
387 
388  return true;
389 }
390 
391 bool Assets::find_vpr0(const radarelab::algo::DBZ& dbz, radarelab::algo::VPR& vpr0, long int& gap)
392 {
393  /*------calcolo la distanza temporale che separa l'ultimo profilo calcolato dall'istante attuale--*/
394  /* (dentro il file LAST_VPR c'è una data che contiene la data cui si riferisce il vpr in n0 di secondi dall'istante di riferimento)*/
395  gap = read_profile_gap();
396 
397  /*------leggo il profilo vecchio più recente di MEMORY ----*/
398  /*------nota bene: è in R ovvero pioggia!! ----*/
399 
400  if (!read_vpr0(vpr0))
401  {
402  LOG_WARN("non esiste file vpr vecchio: %s",getenv("VPR0_FILE"));
403 
404  //----se file non esiste assegno gap=100----
405  gap = 100;
406  }
407 
408  //------------se gap < MEMORY leggo vpr e area per ogni strato-----------
409 
410  if (gap <= MEMORY)
411  return true;
412 
413  //-----Se gap > MEMORY
414 
415  //a)----- tento .. sono in POST-ELABORAZIONE:----
416 
417  //-----devo andare a ricercare tra i profili 'buoni' in archivio quello con cui combinare il dato----
418  //---- trattandosi di profili con data nel nome del file, costruisco il nome a partire dall'istante corrente ciclando su un numero di quarti d'ora
419  //---- pari a memory finchè non trovo un profilo. se non lo trovo gap resta=100
420 
421  /* questo per fare ciclo sul vpr vecchio*/
422  time_t Time = conf_acq_time;
423 
424  // TODO: cerca in archivio se esiste un VPR piú recente del
425  // last_vpr: togliere dal calcolo VPR generico e spostarlo nel
426  // punto dove viene caricato il VPR precedente
427  for (unsigned i=0;i<MEMORY;i++)
428  if (read_archived_vpr(dbz, Time + i * 900, vpr0))
429  {
430  gap = 0;
431  return true;
432  }
433 
434  return false;
435 }
436 
437 void Assets::write_vpr0(const algo::VPR& vpr)
438 {
439  const char* fname = getenv("VPR0_FILE");
440  if (!fname) throw runtime_error("$VPR0_FILE (ultimo vpr) is not set");
441  FILE* out = fopen_checked(fname, "wt", "ultimo vpr");
442  for (unsigned i = 0; i < vpr.size(); ++i)
443  if (fprintf(out, " %10.3f %li\n", vpr.val[i], vpr.area[i]) < 0)
444  {
445  LOG_ERROR("$VPR0_FILE=%s cannot be written: %s", fname, strerror(errno));
446  fclose(out);
447  throw std::runtime_error("cannot write to $VPR0_FILE");
448  }
449  fclose(out);
450 }
451 
453 {
454  const char* dirname = getenv("OUTPUT_Z_LOWRIS_DIR");
455  if (!dirname) throw runtime_error("OUTPUT_Z_LOWRIS_DIR is not set");
456  string fname(dirname);
457  fname += "/MP_coeff";
458  File out(logging_category);
459  out.open(fname, "wb", "MP coefficients");
460 
461  unsigned char MP_coeff[2]; /* a/10 e b*10 per scrivere come 2 byte */
462  MP_coeff[0]=(unsigned char)(dbz.aMP/10);
463  MP_coeff[1]=(unsigned char)(dbz.bMP*10);
464 
465  fwrite(MP_coeff, sizeof(MP_coeff), 1, out);
466 }
467 
469 {
470  if (!outfile_devel_data)
471  {
472  const char* qdir = getenv("DIR_QUALITY");
473  if (!qdir) throw runtime_error("$DIR_QUALITY is not set");
474  string fname(qdir);
475  fname += "/devel-data.h5";
476  outfile_devel_data = new H5::H5File(fname, H5F_ACC_TRUNC);
477  }
478  return *outfile_devel_data;
479 }
480 
481 template<class T>
482 void Assets::load_raw(const std::string& fname, const char* desc, Matrix2D<T>& matrix)
483 {
484  LOG_INFO("Opening %s %s", desc, fname.c_str());
485  FILE* in = fopen_checked(fname.c_str(), "rb", desc);
486 
487  // Read the file size
488  fseek(in, 0,SEEK_END);
489  long fsize = ftell(in);
490  rewind(in);
491 
492  // Check that the file size is consistent with what we want
493  if ((unsigned)fsize != matrix.size() * sizeof(T))
494  {
495  LOG_ERROR("Il file %s è %ld byte ma dovrebbe invece essere %ld byte\n",
496  fname.c_str(), fsize, matrix.size() * sizeof(T));
497  throw std::runtime_error("La dimensione della mappa statica non è quello che mi aspetto");
498  }
499  LOG_INFO ("DIMENSIONE MAPPA STATICA %ld %ld", matrix.rows(), matrix.cols());
500 
501  for (unsigned i = 0; i < matrix.rows(); ++i)
502  if (fread(matrix.data() + i * matrix.cols(), matrix.cols(), 1, in) != 1)
503  {
504  std::string errmsg("Error reading ");
505  errmsg += fname;
506  errmsg += ": ";
507  errmsg += strerror(errno);
508  fclose(in);
509  throw std::runtime_error(errmsg);
510  }
511 
512  fclose(in);
513 }
514 
515 void Assets::load_ascii(const std::string& fname, const char* desc, Matrix2D<float>& matrix)
516 {
517  LOG_INFO("Opening %s %s", desc, fname.c_str());
518  FILE* in = fopen_checked(fname.c_str(), "rt", desc);
519 
520  for (unsigned x = 0; x < matrix.cols(); ++x)
521  for (unsigned y = 0; y < matrix.rows(); ++y)
522  {
523  float val;
524  fscanf(in, "%f ", &val);
525  matrix(y, x) = val;
526  }
527 
528  fclose(in);
529 }
530 
531 std::string Assets::fname_from_acq_time() const
532 {
533  const unsigned buf_size = 16;
534  char buf[buf_size];
535  struct tm *tempo = gmtime(&conf_acq_time);
536  strftime(buf, buf_size, "%Y%m%d%H%M", tempo);
537  return buf;
538 }
539 
540 void Assets::write_image(const Matrix2D<unsigned char>& image, const char* dir_env_var, const char* ext, const char* desc)
541 {
542  const char* dir = getenv(dir_env_var);
543  if (!dir)
544  {
545  LOG_INFO("$%s not set", dir_env_var);
546  throw runtime_error("required env var is not set");
547  }
548 
549  string fname = string(dir) + "/" + fname_from_acq_time() + ext;
550  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
551 
552  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
553 
554  // Convert to south-north columns scanned west to east
555  Matrix2D<unsigned char> transformed(image.cols(), image.rows());
556  for (unsigned y = 0; y < image.cols(); ++y)
557  for (unsigned x = 0; x < image.rows(); ++x)
558  transformed(x, image.cols()-1-y) = image(y, x);
559  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
560  {
561  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
562  fclose(out);
563  throw std::runtime_error("cannot write to image file");
564  }
565 
566  fclose(out);
567 }
568 
569 void Assets::write_subimage(const Matrix2D<unsigned char>& image,unsigned image_side, const char* dir_env_var, const char* ext, const char* desc)
570 {
571  const char* dir = getenv(dir_env_var);
572  if (!dir)
573  {
574  LOG_INFO("$%s not set", dir_env_var);
575  throw runtime_error("required env var is not set");
576  }
577 
578  string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + ext;
579  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
580 
581  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
582 
583  // Convert to south-north columns scanned west to east
584  unsigned xofs = (image.cols() - image_side) / 2;
585  unsigned yofs = (image.rows() - image_side) / 2;
586  //LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, image.cols(), image.rows(), xofs, yofs);
587  Matrix2D<unsigned char> transformed(image_side, image_side);
588  for (unsigned y = 0; y < image_side; ++y)
589  for (unsigned x = 0; x < image_side; ++x)
590  transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
591 
592  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
593  {
594  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
595  fclose(out);
596  throw std::runtime_error("cannot write to image file");
597  }
598 
599  fclose(out);
600 }
601 
602 void Assets::write_subimage(const Matrix2D<unsigned char>& image, unsigned image_side, string algos,const char* dir_env_var, const char* ext, const char* desc)
603 {
604  const char* dir = getenv(dir_env_var);
605  if (!dir)
606  {
607  LOG_INFO("$%s not set", dir_env_var);
608  throw runtime_error("required env var is not set");
609  }
610  string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + "_"+algos+ext;
611  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
612 
613  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
614 
615  // Convert to south-north columns scanned west to east
616  unsigned xofs = (image.cols() - image_side) / 2;
617  unsigned yofs = (image.rows() - image_side) / 2;
618  LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, (int)image.cols(), (int)image.rows(), xofs, yofs);
619  Matrix2D<unsigned char> transformed(image_side, image_side);
620  for (unsigned y = 0; y < image_side; ++y)
621  for (unsigned x = 0; x < image_side; ++x)
622  transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
623 
624  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
625  {
626  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
627  fclose(out);
628  throw std::runtime_error("cannot write to image file");
629  }
630 
631  fclose(out);
632 }
633 
634 template<typename T>
635 void Assets::write_gdal_image(const Matrix2D<T>& image, const char* dir_env_var, const char* name, const char* format)
636 {
637 #ifdef HAVE_GDAL
638  const char* dir = getenv(dir_env_var);
639  if (!dir)
640  {
641  LOG_INFO("$%s not set", dir_env_var);
642  throw runtime_error("required env var is not set");
643  }
644 
645  string fname = string(dir) + "/" + fname_from_acq_time() + "-" + name + "." + gdal_extension_for_format(format);
646 
647  radarelab::write_image(image, fname, format);
648 #else
649  throw std::runtime_error("GDAL support was not enabled at compile time");
650 #endif
651 }
652 
653 template void Assets::write_gdal_image(const Matrix2D<unsigned char>&, const char*, const char*, const char*);
654 template void Assets::write_gdal_image(const Matrix2D<unsigned short>&, const char*, const char*, const char*);
655 template void Assets::write_gdal_image(const Matrix2D<int>&, const char*, const char*, const char*);
656 template void Assets::write_gdal_image(const Matrix2D<unsigned>&, const char*, const char*, const char*);
657 template void Assets::write_gdal_image(const Matrix2D<short>&, const char*, const char*, const char*);
658 template void Assets::write_gdal_image(const Matrix2D<double>&, const char*, const char*, const char*);
659 
660  time_t Assets::getAcqTime() { return conf_acq_time;} ;
661  RadarSite Assets::getRadarSite() { return conf_site->radarSite; };
662 
663 }
Gestisce risorse usate dal programma.
double read_file_hray_inf(std::function< void(unsigned el, unsigned bin, double value)> on_sample)
Read the hray file, calling a callback on each parsed value.
Definition: assets.cpp:181
void load_first_level_bb_bloc(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level elevation BB bloc file.
Definition: assets.cpp:135
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition: assets.cpp:531
void write_vpr0(const radarelab::algo::VPR &vpr)
Write in $VPR0_FILE the vpr calculated.
Definition: assets.cpp:437
bool read_0term(float &zeroterm)
Read $FILE_ZERO_TERMICO.
Definition: assets.cpp:278
void write_subimage(const radarelab::Matrix2D< unsigned char > &image, unsigned image_side, 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 ...
Definition: assets.cpp:569
bool save_acq_time(time_t acq_time=0)
Save acq_time in $LAST_FILE, comparing it with the previous value.
Definition: assets.cpp:53
double read_file_hray(std::function< void(unsigned el, unsigned bin, double value)> on_sample)
Read the hray file, calling a callback on each parsed value.
Definition: assets.cpp:173
void write_vpr_hmax(int hvprmax)
write in $VPR_HMAX the vpr peak's height.
Definition: assets.cpp:322
void load_dem(radarelab::Matrix2D< float > &matrix)
Open the dem file.
Definition: assets.cpp:115
H5::H5File get_devel_data_output() const
Return an open HDF5 File ( $DIR_QUALITY/devel-data.h5) to which we can write datasets used to debug r...
Definition: assets.cpp:468
void load_raw(const std::string &fname, const char *desc, radarelab::Matrix2D< T > &matrix)
Load a Matrix2D, from packed row-major binary data.
Definition: assets.cpp:482
void load_ascii(const std::string &fname, const char *desc, radarelab::Matrix2D< float > &matrix)
Load a Matrix2D, from space-separated column-major ascii floats.
Definition: assets.cpp:515
bool read_archived_vpr(const radarelab::algo::DBZ &dbz, time_t time, radarelab::algo::VPR &vpr)
Try to read the archived VPR at time time.
Definition: assets.cpp:347
bool read_vpr0(radarelab::algo::VPR &vpr0)
Read in $VPR0_FILE the last vpr available.
Definition: assets.cpp:331
void 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 ...
Definition: assets.cpp:540
void configure(const Site &site, time_t acq_time)
Configure asset lookup with the given details.
Definition: assets.cpp:41
float read_t_ground() const
fornisce temperatura al suolo, da lettura file esterno
Definition: assets.cpp:201
void write_vpr_heating(int value) const
Write a new value to $VPR_HEATING (counter of consecutive vpr calculated, see scientific documentatio...
Definition: assets.cpp:267
void write_gdal_image(const radarelab::Matrix2D< T > &image, const char *dir_env_var, const char *name, const char *format)
Write a graphic image with gdal.
Definition: assets.cpp:635
long int read_profile_gap() const
Read the gap between the time in $LAST_VPR and the current acquisition time.
Definition: assets.cpp:231
void write_dbz_coefficients(const radarelab::algo::DBZ &dbz)
Write in $OUTPUT_Z_LOWRIS_DIR/MP_coeff the MP coefficients.
Definition: assets.cpp:452
bool find_vpr0(const radarelab::algo::DBZ &dbz, radarelab::algo::VPR &vpr0, long int &gap)
Read the gap and the vpr0, and if vpr0 is not found, look it up among the archived VPRs.
Definition: assets.cpp:391
void load_first_level(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level file.
Definition: assets.cpp:120
void load_first_level_bb_el(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level elevation BB el file.
Definition: assets.cpp:130
int read_vpr_heating() const
Read the value of $VPR_HEATING (counter of consecutive vpr calculated, see scientific documentation)
Definition: assets.cpp:250
std::string fname_out_pp_bloc(const char *suffix) const
Compute the file name of a date/time based file in $DIR_OUT_PP_BLOC.
Definition: assets.cpp:189
int read_vpr_hmax()
Read in $VPR_HMAX the vpr peak's height.
Definition: assets.cpp:305
void write_last_vpr()
Write the acquisition time in $LAST_VPR file.
Definition: assets.cpp:294
bool open_from_env(const char *varname, const char *mode, const char *desc=nullptr)
Opens a file taking its name from the environment variable envname.
Definition: utils.cpp:37
void read_lines(std::function< void(char *, size_t)> line_cb)
Read the file line by line, calling line_cb on each line read.
Definition: utils.cpp:75
bool open(const std::string &fname, const char *mode, const char *desc=nullptr)
Opens a file by its pathname.
Definition: utils.cpp:49
Open a file taking its name from a given env variable.
Definition: utils.h:22
Class to manage reflectivity functions (simply attenuation correction, conversion between Z,...
Definition: dbz.h:23
name space generale del programma
Definition: assets.h:28
void gdal_init_once()
Initialize the GDAL library when called for the first time; does nothing all other times.
Definition: image.cpp:12
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
String functions.
Definition: cart.cpp:4
definisce struttura Site Contiene le informazioni di base che caratterizzano il sito radar
std::string name
Nome sito radar.
Definition: site.h:29
static const Site & get(const char *name)
Get a Site object according to a site name.
Definition: site.cpp:159
RadarSite radarSite
Description of radar site.
Definition: site.h:41
virtual const char * get_dem_file_name() const =0
Return dem file name.
virtual const char * get_first_level_file_name(unsigned month) const =0
Return first_elev file name.
Radar site information.
Definition: site.h:24
Base for all matrices we use, since we rely on row-major data.
Definition: matrix.h:37