Elaboradar  0.1
 Tutto Classi Namespace File Funzioni Variabili Tipi enumerati (enum) Gruppi
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  fname = conf_site->get_first_level_file_name(conf_month);
125  load_raw(fname, "mappa statica", matrix);
126 }
127 
129 {
130  load_raw(fname_out_pp_bloc("mat_el.bin"), "elev BB", matrix);
131 }
132 
134 {
135  load_raw(fname_out_pp_bloc("mat_bloc.bin"), "elev BB", matrix);
136 }
137 
138 namespace {
139 
140 double parse_hray(File& fd, std::function<void (unsigned el, unsigned bin, double value)> on_sample)
141 {
142  size_t line_no = 0;
143  double dtrs;
144  fd.read_lines([&](char* line, size_t len) {
145  if (line_no == 0)
146  {
147  // Read dtrs in the first line
148  dtrs = strtod(line, NULL);
149  } else {
150  char* s = line;
151  int el = 0;
152  while (true)
153  {
154  char* next;
155  double val = strtod(s, &next);
156  if (next == s) break;
157  on_sample(el, line_no - 1, val);
158  s = next;
159  ++el;
160  }
161  }
162  ++line_no;
163  });
164  if (line_no == 0)
165  throw std::runtime_error("hray/hray_inf file is empty");
166  return dtrs;
167 }
168 
169 }
170 
171 double Assets::read_file_hray(std::function<void (unsigned el, unsigned bin, double value)> on_sample)
172 {
173  File fd(logging_category);
174  if (!fd.open(fname_out_pp_bloc("h_ray.txt"), "rb", "hray"))
175  throw std::runtime_error("cannot open hray file");
176  return parse_hray(fd, on_sample);
177 }
178 
179 double Assets::read_file_hray_inf(std::function<void (unsigned el, unsigned bin, double value)> on_sample)
180 {
181  File fd(logging_category);
182  if (!fd.open(fname_out_pp_bloc("h_rayinf.txt"), "rb", "hray inf"))
183  throw std::runtime_error("cannot open hray inf file");
184  return parse_hray(fd, on_sample);
185 }
186 
187 std::string Assets::fname_out_pp_bloc(const char* suffix) const
188 {
189  const char* dir = getenv("DIR_OUT_PP_BLOC");
190  if (!dir) throw runtime_error("DIR_OUT_PP_BLOC is not set");
191 
192  char fname[1024];
193  sprintf(fname, "%s/%04d%02d%02d%02d%02d%s", dir,
194  conf_year, conf_month, conf_day, conf_hour, conf_minute, suffix);
195 
196  return fname;
197 }
198 
200 {
201  LOG_CATEGORY("radar.vpr");
202  File in(logging_category);
203  if (!in.open_from_env("FILE_T", "rt"))
204  return NODATAVPR;
205 
206  float media_t = 0;
207  int icount = 0;
208  float lon, lat, t;
209 
210  while (1) {
211  if(fscanf(in, "%f %f %f \n",&lon,&lat,&t) == EOF) break;
212  if (fabs(conf_site->radarSite.lat_r-lat)<=maxdlat && fabs(conf_site->radarSite.lon_r-lon)<=maxdlon) {
213  ++icount;
214  media_t += t - 273.15;
215  }
216  }
217 
218  if (icount == 0)
219  {
220  LOG_ERROR("Temperature data not found in $FILE_T=%s", in.name());
221  return NODATAVPR;
222  }
223 
224  media_t /= (float)icount;
225  LOG_INFO("ho %i stazioni dati affidabili e la t media è %f\n", icount, media_t);
226  return media_t;
227 }
228 
229 long int Assets::read_profile_gap() const
230 {
231  LOG_CATEGORY("radar.vpr");
232  File in(logging_category);
233  if (!in.open_from_env("LAST_VPR", "rb"))
234  return 100;
235 
236  // FIXME: time_t può essere 64 bit, qui viene sempre troncato.
237  // FIXME: l'ideale sarebbe, in questo caso, usare fprintf/fscanf invece di
238  // FIXME: fread/fwrite
239  uint32_t last_time;
240  fread(&last_time, 4, 1, in);
241 
242  long int gap1 = abs(conf_acq_time - last_time)/900;
243  LOG_INFO("old_data_header.norm.maq.acq_date last_time gap %ld %u %ld", conf_acq_time, last_time, gap1);
244 
245  return gap1;
246 }
247 
249 {
250  LOG_CATEGORY("radar.vpr");
251  File in(logging_category);
252  if (!in.open_from_env("VPR_HEATING", "rt"))
253  return 0;
254 
255  int heating;
256  if (fscanf(in, "%i ", &heating) != 1)
257  {
258  LOG_ERROR("Cannot read $VPR_HEATING=%s: %s", in.name(), strerror(errno));
259  return 0;
260  }
261 
262  return heating;
263 }
264 
265 void Assets::write_vpr_heating(int value) const
266 {
267  LOG_CATEGORY("radar.vpr");
268  File out(logging_category);
269  if (!out.open_from_env("VPR_HEATING", "wt"))
270  return;
271 
272  if (fprintf(out, " %i \n", value) < 0)
273  LOG_ERROR("Cannot write $VPR_HEATING=%s: %s", out.name(), strerror(errno));
274 }
275 
276 bool Assets::read_0term(float& zeroterm)
277 {
278  LOG_CATEGORY("radar.class");
279  File in(logging_category);
280  if (!in.open_from_env("FILE_ZERO_TERMICO", "rt"))
281  return false;
282 
283  if (fscanf(in, "%f", &zeroterm) != 1)
284  {
285  LOG_ERROR("$FILE_ZERO_TERMICO=%s cannot be read: %s", in.name(), strerror(errno));
286  return false;
287  }
288 
289  return true;
290 }
291 
293 {
294  //LOG_CATEGORY("radar.vpr");
295  const char* fname = getenv("LAST_VPR");
296  if (!fname) throw runtime_error("$LAST_VPR is not set");
297  FILE* out = fopen_checked(fname, "wb", "ultimo VPR");
298  uint32_t val = conf_acq_time;
299  fwrite(&val, 4, 1, out);
300  fclose(out);
301 }
302 
304 {
305  File in(logging_category);
306  if (!in.open_from_env("VPR_HMAX", "rt"))
307  return -9999;
308 
309  int value;
310  if (fscanf(in, "%i", &value) != 1)
311  {
312  LOG_ERROR("$VPR_HMAX=%s cannot be read: %s", in.name(), strerror(errno));
313  return -9999;
314  }
315 
316  LOG_INFO("fatta lettura hmax vpr = %i", value);
317  return value;
318 }
319 
320 void Assets::write_vpr_hmax(int hvprmax)
321 {
322  const char* fname = getenv("VPR_HMAX");
323  if (!fname) throw runtime_error("$VPR_HMAX is not set");
324  FILE* out = fopen_checked(fname, "wt", "hmax VPR");
325  fprintf(out, "%d", hvprmax);
326  fclose(out);
327 }
328 
329 bool Assets::read_vpr0(algo::VPR& vpr0)
330 {
331  File in(logging_category);
332  if (!in.open_from_env("VPR0_FILE", "rt")) return false;
333 
334  for (unsigned i = 0; i < vpr0.size(); ++i)
335  //-----leggo vpr e area per ogni strato----
336  if (fscanf(in, "%f %li\n", &vpr0.val[i], &vpr0.area[i]) != 2)
337  {
338  LOG_ERROR("$VPR0_FILE=%s cannot be read: %s", in.name(), strerror(errno));
339  throw std::runtime_error("cannot read $VPR0_FILE");
340  }
341 
342  return true;
343 }
344 
345 bool Assets::read_archived_vpr(const algo::DBZ& dbz, time_t time, radarelab::algo::VPR& vpr)
346 {
347  const char* dir = getenv("DIR_STORE_VPR"); //--questa non sarebbe una dir_arch più che store?... contesto il nome...
348  if (!dir) return false;
349 
350  struct tm t;
351  gmtime_r(&time, &t);
352 
353  char fname[64];
354  snprintf(fname, 64, "%04d%02d%02d%02d%02d_vpr_%s",
355  t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
356  t.tm_hour, t.tm_min, conf_site->name.c_str());
357 
358  string pathname = dir;
359  pathname += "/";
360  pathname += fname;
361 
362  File in(logging_category);
363  if (!in.open(pathname, "r", "archived VPR file"))
364  return false;
365 
366  // TODO: check the actual format of the file and make the parsing safe:
367  // currently if one of these strings is longer than 99, we crash or worse.
368  char stringa[100];
369  fscanf(in, " %s %s %s %s" ,stringa ,stringa,stringa,stringa);
370  for (unsigned ilay=0; ilay < vpr.size(); ++ilay){
371  float vpr_dbz;
372  long int ar;
373  int il;
374  fscanf(in, " %i %f %li", &il, &vpr_dbz, &ar); //---NB il file in archivio è in dBZ e contiene anche la quota----
375 
376  //---- converto in R il profilo vecchio--
377  if (vpr_dbz > 0)
378  {
379  vpr.val[ilay] = dbz.DBZtoR(vpr_dbz);
380  vpr.area[ilay] = ar;
381  }
382  else
383  vpr.val[ilay] = NODATAVPR;
384  }
385 
386  return true;
387 }
388 
389 bool Assets::find_vpr0(const radarelab::algo::DBZ& dbz, radarelab::algo::VPR& vpr0, long int& gap)
390 {
391  /*------calcolo la distanza temporale che separa l'ultimo profilo calcolato dall'istante attuale--*/
392  /* (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)*/
393  gap = read_profile_gap();
394 
395  /*------leggo il profilo vecchio più recente di MEMORY ----*/
396  /*------nota bene: è in R ovvero pioggia!! ----*/
397 
398  if (!read_vpr0(vpr0))
399  {
400  LOG_WARN("non esiste file vpr vecchio: %s",getenv("VPR0_FILE"));
401 
402  //----se file non esiste assegno gap=100----
403  gap = 100;
404  }
405 
406  //------------se gap < MEMORY leggo vpr e area per ogni strato-----------
407 
408  if (gap <= MEMORY)
409  return true;
410 
411  //-----Se gap > MEMORY
412 
413  //a)----- tento .. sono in POST-ELABORAZIONE:----
414 
415  //-----devo andare a ricercare tra i profili 'buoni' in archivio quello con cui combinare il dato----
416  //---- 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
417  //---- pari a memory finchè non trovo un profilo. se non lo trovo gap resta=100
418 
419  /* questo per fare ciclo sul vpr vecchio*/
420  time_t Time = conf_acq_time;
421 
422  // TODO: cerca in archivio se esiste un VPR piú recente del
423  // last_vpr: togliere dal calcolo VPR generico e spostarlo nel
424  // punto dove viene caricato il VPR precedente
425  for (unsigned i=0;i<MEMORY;i++)
426  if (read_archived_vpr(dbz, Time + i * 900, vpr0))
427  {
428  gap = 0;
429  return true;
430  }
431 
432  return false;
433 }
434 
435 void Assets::write_vpr0(const algo::VPR& vpr)
436 {
437  const char* fname = getenv("VPR0_FILE");
438  if (!fname) throw runtime_error("$VPR0_FILE (ultimo vpr) is not set");
439  FILE* out = fopen_checked(fname, "wt", "ultimo vpr");
440  for (unsigned i = 0; i < vpr.size(); ++i)
441  if (fprintf(out, " %10.3f %li\n", vpr.val[i], vpr.area[i]) < 0)
442  {
443  LOG_ERROR("$VPR0_FILE=%s cannot be written: %s", fname, strerror(errno));
444  fclose(out);
445  throw std::runtime_error("cannot write to $VPR0_FILE");
446  }
447  fclose(out);
448 }
449 
451 {
452  const char* dirname = getenv("OUTPUT_Z_LOWRIS_DIR");
453  if (!dirname) throw runtime_error("OUTPUT_Z_LOWRIS_DIR is not set");
454  string fname(dirname);
455  fname += "/MP_coeff";
456  File out(logging_category);
457  out.open(fname, "wb", "MP coefficients");
458 
459  unsigned char MP_coeff[2]; /* a/10 e b*10 per scrivere come 2 byte */
460  MP_coeff[0]=(unsigned char)(dbz.aMP/10);
461  MP_coeff[1]=(unsigned char)(dbz.bMP*10);
462 
463  fwrite(MP_coeff, sizeof(MP_coeff), 1, out);
464 }
465 
467 {
468  if (!outfile_devel_data)
469  {
470  const char* qdir = getenv("DIR_QUALITY");
471  if (!qdir) throw runtime_error("$DIR_QUALITY is not set");
472  string fname(qdir);
473  fname += "/devel-data.h5";
474  outfile_devel_data = new H5::H5File(fname, H5F_ACC_TRUNC);
475  }
476  return *outfile_devel_data;
477 }
478 
479 template<class T>
480 void Assets::load_raw(const std::string& fname, const char* desc, Matrix2D<T>& matrix)
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 }
512 
513 void Assets::load_ascii(const std::string& fname, const char* desc, Matrix2D<float>& matrix)
514 {
515  LOG_INFO("Opening %s %s", desc, fname.c_str());
516  FILE* in = fopen_checked(fname.c_str(), "rt", desc);
517 
518  for (unsigned x = 0; x < matrix.cols(); ++x)
519  for (unsigned y = 0; y < matrix.rows(); ++y)
520  {
521  float val;
522  fscanf(in, "%f ", &val);
523  matrix(y, x) = val;
524  }
525 
526  fclose(in);
527 }
528 
529 std::string Assets::fname_from_acq_time() const
530 {
531  const unsigned buf_size = 16;
532  char buf[buf_size];
533 
534  struct tm *tempo = gmtime(&conf_acq_time);
535 
536  snprintf(buf, buf_size, "%04d%02d%02d%02d%02d",
537  tempo->tm_year+1900, tempo->tm_mon+1, tempo->tm_mday,
538  tempo->tm_hour, tempo->tm_min);
539 
540  return buf;
541 }
542 
543 void Assets::write_image(const Matrix2D<unsigned char>& image, const char* dir_env_var, const char* ext, const char* desc)
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 }
571 
572 void Assets::write_subimage(const Matrix2D<unsigned char>& image,unsigned image_side, const char* dir_env_var, const char* ext, const char* desc)
573 {
574  const char* dir = getenv(dir_env_var);
575  if (!dir)
576  {
577  LOG_INFO("$%s not set", dir_env_var);
578  throw runtime_error("required env var is not set");
579  }
580 
581  string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + ext;
582  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
583 
584  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
585 
586  // Convert to south-north columns scanned west to east
587  unsigned xofs = (image.cols() - image_side) / 2;
588  unsigned yofs = (image.rows() - image_side) / 2;
589  //LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, image.cols(), image.rows(), xofs, yofs);
590  Matrix2D<unsigned char> transformed(image_side, image_side);
591  for (unsigned y = 0; y < image_side; ++y)
592  for (unsigned x = 0; x < image_side; ++x)
593  transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
594 
595  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
596  {
597  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
598  fclose(out);
599  throw std::runtime_error("cannot write to image file");
600  }
601 
602  fclose(out);
603 }
604 
605 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)
606 {
607  const char* dir = getenv(dir_env_var);
608  if (!dir)
609  {
610  LOG_INFO("$%s not set", dir_env_var);
611  throw runtime_error("required env var is not set");
612  }
613  string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + "_"+algos+ext;
614  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
615 
616  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
617 
618  // Convert to south-north columns scanned west to east
619  unsigned xofs = (image.cols() - image_side) / 2;
620  unsigned yofs = (image.rows() - image_side) / 2;
621  LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, image.cols(), image.rows(), xofs, yofs);
622  Matrix2D<unsigned char> transformed(image_side, image_side);
623  for (unsigned y = 0; y < image_side; ++y)
624  for (unsigned x = 0; x < image_side; ++x)
625  transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
626 
627  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
628  {
629  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
630  fclose(out);
631  throw std::runtime_error("cannot write to image file");
632  }
633 
634  fclose(out);
635 }
636 
637 template<typename T>
638 void Assets::write_gdal_image(const Matrix2D<T>& image, const char* dir_env_var, const char* name, const char* format)
639 {
640 #ifdef HAVE_GDAL
641  const char* dir = getenv(dir_env_var);
642  if (!dir)
643  {
644  LOG_INFO("$%s not set", dir_env_var);
645  throw runtime_error("required env var is not set");
646  }
647 
648  string fname = string(dir) + "/" + fname_from_acq_time() + "-" + name + "." + gdal_extension_for_format(format);
649 
650  radarelab::write_image(image, fname, format);
651 #else
652  throw std::runtime_error("GDAL support was not enabled at compile time");
653 #endif
654 }
655 
656 template void Assets::write_gdal_image(const Matrix2D<unsigned char>&, const char*, const char*, const char*);
657 template void Assets::write_gdal_image(const Matrix2D<unsigned short>&, const char*, const char*, const char*);
658 template void Assets::write_gdal_image(const Matrix2D<int>&, const char*, const char*, const char*);
659 template void Assets::write_gdal_image(const Matrix2D<unsigned>&, const char*, const char*, const char*);
660 template void Assets::write_gdal_image(const Matrix2D<short>&, const char*, const char*, const char*);
661 template void Assets::write_gdal_image(const Matrix2D<double>&, const char*, const char*, const char*);
662 
663  time_t Assets::getAcqTime() { return conf_acq_time;} ;
664  RadarSite Assets::getRadarSite() { return conf_site->radarSite; };
665 
666 }
virtual const char * get_dem_file_name() const =0
Return dem file name.
Radar site information.
Definition: site.h:23
definisce struttura Site Contiene le informazioni di base che caratterizzano il sito radar ...
void configure(const Site &site, time_t acq_time)
Configure asset lookup with the given details.
Definition: assets.cpp:41
void write_vpr_hmax(int hvprmax)
write in $VPR_HMAX the vpr peak&#39;s height.
Definition: assets.cpp:320
float read_t_ground() const
fornisce temperatura al suolo, da lettura file esterno
Definition: assets.cpp:199
void write_vpr0(const radarelab::algo::VPR &vpr)
Write in $VPR0_FILE the vpr calculated.
Definition: assets.cpp:435
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:389
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
Class to manage reflectivity functions (simply attenuation correction, conversion between Z...
Definition: dbz.h:22
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:572
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
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 write_vpr_heating(int value) const
Write a new value to $VPR_HEATING (counter of consecutive vpr calculated, see scientific documentatio...
Definition: assets.cpp:265
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:466
RadarSite radarSite
Description of radar site.
Definition: site.h:35
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:187
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition: assets.cpp:529
bool read_vpr0(radarelab::algo::VPR &vpr0)
Read in $VPR0_FILE the last vpr available.
Definition: assets.cpp:329
static const Site & get(const char *name)
Get a Site object according to a site name.
Definition: site.cpp:154
void load_first_level(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level file.
Definition: assets.cpp:120
void load_dem(radarelab::Matrix2D< float > &matrix)
Open the dem file.
Definition: assets.cpp:115
void load_first_level_bb_bloc(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level elevation BB bloc file.
Definition: assets.cpp:133
bool read_0term(float &zeroterm)
Read $FILE_ZERO_TERMICO.
Definition: assets.cpp:276
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:480
int read_vpr_heating() const
Read the value of $VPR_HEATING (counter of consecutive vpr calculated, see scientific documentation) ...
Definition: assets.cpp:248
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
void write_last_vpr()
Write the acquisition time in $LAST_VPR file.
Definition: assets.cpp:292
virtual const char * get_first_level_file_name(unsigned month) const =0
Return first_elev file name.
int read_vpr_hmax()
Read in $VPR_HMAX the vpr peak&#39;s height.
Definition: assets.cpp:303
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:543
void load_first_level_bb_el(radarelab::Matrix2D< unsigned char > &matrix)
Open the first level elevation BB el file.
Definition: assets.cpp:128
void gdal_init_once()
Initialize the GDAL library when called for the first time; does nothing all other times...
Definition: image.cpp:12
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:179
Open a file taking its name from a given env variable.
Definition: utils.h:21
std::string name
Nome sito radar.
Definition: site.h:29
Gestisce risorse usate dal programma.
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:638
long int read_profile_gap() const
Read the gap between the time in $LAST_VPR and the current acquisition time.
Definition: assets.cpp:229
bool open(const std::string &fname, const char *mode, const char *desc=nullptr)
Opens a file by its pathname.
Definition: utils.cpp:49
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:345
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:171
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:513
void write_dbz_coefficients(const radarelab::algo::DBZ &dbz)
Write in $OUTPUT_Z_LOWRIS_DIR/MP_coeff the MP coefficients.
Definition: assets.cpp:450