GRASS GIS 8 Programmer's Manual  8.5.0dev(2025)-299a28a7d0
raster/range.c
Go to the documentation of this file.
1 /*!
2  * \file lib/raster/range.c
3  *
4  * \brief Raster Library - Raster range file management
5  *
6  * (C) 2001-2009 GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author Original author CERL
12  */
13 
14 #include <unistd.h>
15 
16 #include <grass/raster.h>
17 #include <grass/glocale.h>
18 
19 #include "R.h"
20 
21 #define DEFAULT_CELL_MIN 1
22 #define DEFAULT_CELL_MAX 255
23 
24 static void init_rstats(struct R_stats *);
25 
26 /*!
27  \brief Remove floating-point range
28 
29  Note: For internal use only.
30 
31  \param name map name
32  */
33 void Rast__remove_fp_range(const char *name)
34 {
35  G_remove_misc("cell_misc", "f_range", name);
36 }
37 
38 /*!
39  * \brief Construct default range
40  *
41  * Sets the integer range to [1,255]
42  *
43  * \param[out] r pointer to Range structure which holds range info
44  */
46 {
49 }
50 
51 /*!
52  * \brief Read floating-point range
53  *
54  * Read the floating point range file <i>drange</i>. This file is
55  * written in binary using XDR format.
56  *
57  * An empty range file indicates that the min, max are undefined. This
58  * is a valid case, and the result should be an initialized range
59  * struct with no defined min/max. If the range file is missing and
60  * the map is a floating-point map, this function will create a
61  * default range by calling G_construct_default_range().
62  *
63  * \param name map name
64  * \param mapset mapset name
65  * \param drange pointer to FPRange structure which holds fp range
66  *
67  * \return 1 on success
68  * \return 2 range is empty
69  * \return -1 on error
70  */
71 int Rast_read_fp_range(const char *name, const char *mapset,
72  struct FPRange *drange)
73 {
74  struct Range range;
75  int fd;
76  char xdr_buf[2][XDR_DOUBLE_NBYTES];
77  DCELL dcell1, dcell2;
78 
79  Rast_init();
80  Rast_init_fp_range(drange);
81 
82  if (Rast_map_type(name, mapset) == CELL_TYPE) {
83  /* if map is integer
84  read integer range and convert it to double */
85 
86  if (Rast_read_range(name, mapset, &range) >= 0) {
87  /* if the integer range is empty */
88  if (range.first_time)
89  return 2;
90 
91  Rast_update_fp_range((DCELL)range.min, drange);
92  Rast_update_fp_range((DCELL)range.max, drange);
93  return 1;
94  }
95  return -1;
96  }
97 
98  fd = -1;
99  char *mname = G_fully_qualified_name(name, mapset);
100 
101  if (G_find_file2_misc("cell_misc", "f_range", name, mapset)) {
102  fd = G_open_old_misc("cell_misc", "f_range", name, mapset);
103  if (fd < 0) {
104  G_warning(_("Unable to read fp range file for <%s>"), mname);
105  G_free(mname);
106  return -1;
107  }
108 
109  if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
110  /* if the f_range file exists, but empty file, meaning Nulls */
111  close(fd);
112  G_debug(1, "Empty fp range file meaning Nulls for <%s>", mname);
113  G_free(mname);
114  return 2;
115  }
116 
117  G_xdr_get_double(&dcell1, xdr_buf[0]);
118  G_xdr_get_double(&dcell2, xdr_buf[1]);
119 
120  Rast_update_fp_range(dcell1, drange);
121  Rast_update_fp_range(dcell2, drange);
122  close(fd);
123  }
124  else {
125  /* "f_range" file does not exist */
126  G_warning(_("Missing fp range file for <%s> (run r.support -s)"),
127  mname);
128  G_free(mname);
129  return -1;
130  }
131  G_free(mname);
132 
133  return 1;
134 }
135 
136 /*!
137  * \brief Read raster range (CELL)
138  *
139  * This routine reads the range information for the raster map
140  * <i>name</i> in <i>mapset</i> into the <i>range</i> structure.
141  *
142  * A diagnostic message is printed and -1 is returned if there is an error
143  * reading the range file. Otherwise, 0 is returned.
144  *
145  * Old range file (those with 4 numbers) should treat zeros in this
146  * file as NULL-values. New range files (those with just 2 numbers)
147  * should treat these numbers as real data (zeros are real data in
148  * this case). An empty range file indicates that the min, max are
149  * undefined. This is a valid case, and the result should be an
150  * initialized range struct with no defined min/max. If the range file
151  * is missing and the map is a floating-point map, this function will
152  * create a default range by calling G_construct_default_range().
153  *
154  * \param name map name
155  * \param mapset mapset name
156  * \param[out] range pointer to Range structure which holds range info
157  *
158  * \return -1 on error
159  * \return 1 on success
160  * \return 2 if range is empty
161  * \return 3 if raster map is floating-point, get range from quant rules
162  */
163 int Rast_read_range(const char *name, const char *mapset, struct Range *range)
164 {
165  FILE *fd;
166  CELL x[4];
167  char buf[200];
168  int n, count;
169  struct Quant quant;
170  struct FPRange drange;
171 
172  Rast_init_range(range);
173  fd = NULL;
174  char *mname = G_fully_qualified_name(name, mapset);
175 
176  /* if map is not integer, read quant rules, and get limits */
177  if (Rast_map_type(name, mapset) != CELL_TYPE) {
178  DCELL dmin, dmax;
179 
180  if (Rast_read_quant(name, mapset, &quant) < 0) {
181  G_warning(_("Unable to read quant rules for raster map <%s>"),
182  mname);
183  G_free(mname);
184  return -1;
185  }
186  if (Rast_quant_is_truncate(&quant) || Rast_quant_is_round(&quant)) {
187  if (Rast_read_fp_range(name, mapset, &drange) >= 0) {
188  Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
189  if (Rast_quant_is_truncate(&quant)) {
190  x[0] = (CELL)dmin;
191  x[1] = (CELL)dmax;
192  }
193  else { /* round */
194 
195  if (dmin > 0)
196  x[0] = (CELL)(dmin + .5);
197  else
198  x[0] = (CELL)(dmin - .5);
199  if (dmax > 0)
200  x[1] = (CELL)(dmax + .5);
201  else
202  x[1] = (CELL)(dmax - .5);
203  }
204  }
205  else {
206  G_free(mname);
207  return -1;
208  }
209  }
210  else
211  Rast_quant_get_limits(&quant, &dmin, &dmax, &x[0], &x[1]);
212 
213  Rast_update_range(x[0], range);
214  Rast_update_range(x[1], range);
215  G_free(mname);
216  return 3;
217  }
218 
219  if (G_find_file2_misc("cell_misc", "range", name, mapset)) {
220  fd = G_fopen_old_misc("cell_misc", "range", name, mapset);
221  if (!fd) {
222  G_warning(_("Unable to read range file for <%s>"), mname);
223  G_free(mname);
224  return -1;
225  }
226 
227  /* if range file exists but empty */
228  if (!fgets(buf, sizeof buf, fd)) {
229  if (fd)
230  fclose(fd);
231  G_free(mname);
232  return 2;
233  }
234 
235  x[0] = x[1] = x[2] = x[3] = 0;
236  count = sscanf(buf, "%d%d%d%d", &x[0], &x[1], &x[2], &x[3]);
237 
238  /* if wrong format */
239  if (count <= 0) {
240  if (fd)
241  fclose(fd);
242 
243  G_warning(_("Unable to read range file for <%s>"),
244  G_fully_qualified_name(name, mapset));
245  G_free(mname);
246  return -1;
247  }
248 
249  for (n = 0; n < count; n++) {
250  /* if count==4, the range file is old (4.1) and 0's in it
251  have to be ignored */
252  if (count < 4 || x[n])
253  Rast_update_range((CELL)x[n], range);
254  }
255  fclose(fd);
256  }
257  else {
258  /* "range" file does not exist */
259  G_warning(_("Missing range file for <%s> (run r.support -s)"), mname);
260  G_free(mname);
261  return -1;
262  }
263  G_free(mname);
264 
265  return 1;
266 }
267 
268 /*!
269  * \brief Read raster stats
270  *
271  * Read the stats file <i>stats</i>. This file is
272  * written in binary using XDR format.
273  *
274  * An empty stats file indicates that all cells are NULL. This
275  * is a valid case, and the result should be an initialized rstats
276  * struct with no defined stats. If the stats file is missing
277  * this function will create a default stats with count = 0.
278  *
279  * \param name map name
280  * \param mapset mapset name
281  * \param rstats pointer to R_stats structure which holds raster stats
282  *
283  * \return 1 on success
284  * \return 2 stats is empty
285  * \return -1 on error or stats file does not exist
286  */
287 int Rast_read_rstats(const char *name, const char *mapset,
288  struct R_stats *rstats)
289 {
290  int fd;
291  char xdr_buf[2][XDR_DOUBLE_NBYTES];
292  DCELL dcell1, dcell2;
293  unsigned char cc[8];
294  char nbytes;
295  int i;
297 
298  Rast_init();
299  init_rstats(rstats);
300 
301  fd = -1;
302 
303  if (!G_find_file2_misc("cell_misc", "stats", name, mapset)) {
304  G_debug(1, "Stats file does not exist");
305  return -1;
306  }
307 
308  char *mname = G_fully_qualified_name(name, mapset);
309 
310  fd = G_open_old_misc("cell_misc", "stats", name, mapset);
311  if (fd < 0) {
312  G_warning(_("Unable to read stats file for <%s>"), mname);
313  G_free(mname);
314  return -1;
315  }
316 
317  if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
318  /* if the stats file exists, but empty file, meaning Nulls */
319  close(fd);
320  G_debug(1, "Empty stats file meaning Nulls for <%s>", mname);
321  G_free(mname);
322  return 2;
323  }
324 
325  G_xdr_get_double(&dcell1, xdr_buf[0]);
326  G_xdr_get_double(&dcell2, xdr_buf[1]);
327 
328  rstats->sum = dcell1;
329  rstats->sumsq = dcell2;
330 
331  /* count; see cell_values_int() in get_row.c */
332  nbytes = 1;
333  if (read(fd, &nbytes, 1) != 1) {
334  /* if the stats file exists, but empty file, meaning Nulls */
335  close(fd);
336  G_debug(1, "Unable to read byte count in stats file for <%s>", mname);
337  G_free(mname);
338  return -1;
339  }
340 
341  count = 0;
342  if (nbytes == 0) {
343  close(fd);
344  G_free(mname);
345  return 1;
346  }
347 
348  if (nbytes < 1 || (unsigned char)nbytes > sizeof(grass_int64)) {
349  close(fd);
350  G_debug(1, "Invalid byte count in stats file for <%s>", mname);
351  G_free(mname);
352  return -1;
353  }
354  if (read(fd, cc, nbytes) != nbytes) {
355  /* incorrect number of bytes for count */
356  close(fd);
357  G_debug(1, "Unable to read count in stats file for <%s>", mname);
358  G_free(mname);
359  return -1;
360  }
361 
362  /* copy byte by byte */
363  for (i = nbytes - 1; i >= 0; i--) {
364  count = (count << 8);
365  count = count + cc[i];
366  }
367  rstats->count = count;
368 
369  close(fd);
370  G_free(mname);
371 
372  return 1;
373 }
374 
375 /*!
376  * \brief Write raster range file
377  *
378  * This routine writes the range information for the raster map
379  * <i>name</i> in the current mapset from the <i>range</i> structure.
380  * A diagnostic message is printed and -1 is returned if there is an
381  * error writing the range file. Otherwise, 0 is returned.
382  *
383  * This routine only writes 2 numbers (min,max) to the range
384  * file, instead of the 4 (pmin,pmax,nmin,nmax) previously written.
385  * If there is no defined min,max, an empty file is written.
386  *
387  * \param name map name
388  * \param range pointer to Range structure which holds range info
389  */
390 void Rast_write_range(const char *name, const struct Range *range)
391 {
392  FILE *fp;
393 
394  Rast_write_rstats(name, &(range->rstats));
395 
396  if (Rast_map_type(name, G_mapset()) != CELL_TYPE) {
397  G_remove_misc("cell_misc", "range",
398  name); /* remove the old file with this name */
399  G_fatal_error(_("Unable to write range file for <%s>"), name);
400  }
401 
402  fp = G_fopen_new_misc("cell_misc", "range", name);
403  if (!fp) {
404  G_remove_misc("cell_misc", "range",
405  name); /* remove the old file with this name */
406  G_fatal_error(_("Unable to write range file for <%s>"), name);
407  }
408 
409  /* if range has been updated */
410  if (!range->first_time)
411  fprintf(fp, "%ld %ld\n", (long)range->min, (long)range->max);
412 
413  fclose(fp);
414 }
415 
416 /*!
417  * \brief Write raster range file (floating-point)
418  *
419  * Write the floating point range file <tt>f_range</tt>. This file is
420  * written in binary using XDR format. If there is no defined min/max
421  * in <em>range</em>, an empty <tt>f_range</tt> file is created.
422  *
423  * \param name map name
424  * \param range pointer to FPRange which holds fp range info
425  */
426 void Rast_write_fp_range(const char *name, const struct FPRange *range)
427 {
428  int fd;
429  char xdr_buf[2][XDR_DOUBLE_NBYTES];
430 
431  Rast_init();
432 
433  Rast_write_rstats(name, &(range->rstats));
434 
435  fd = G_open_new_misc("cell_misc", "f_range", name);
436  if (fd < 0) {
437  G_remove_misc("cell_misc", "f_range", name);
438  G_fatal_error(_("Unable to write range file for <%s>"), name);
439  }
440 
441  /* if range hasn't been updated, write empty file meaning Nulls */
442  if (range->first_time) {
443  close(fd);
444  return;
445  }
446 
447  G_xdr_put_double(xdr_buf[0], &range->min);
448  G_xdr_put_double(xdr_buf[1], &range->max);
449 
450  if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
451  G_remove_misc("cell_misc", "f_range", name);
452  G_fatal_error(_("Unable to write range file for <%s>"), name);
453  }
454 
455  close(fd);
456 }
457 
458 /*!
459  * \brief Write raster stats file
460  *
461  * Write the stats file <tt>stats</tt>. This file is
462  * written in binary using XDR format. If the count is < 1
463  * in <em>rstats</em>, an empty <tt>stats</tt> file is created.
464  *
465  * \param name map name
466  * \param rstats pointer to R_stats which holds stats info
467  */
468 void Rast_write_rstats(const char *name, const struct R_stats *rstats)
469 {
470  int fd;
471  char xdr_buf[2][XDR_DOUBLE_NBYTES];
472  unsigned char cc[8];
473  char nbytes;
474  unsigned int i;
476 
477  Rast_init();
478 
479  fd = G_open_new_misc("cell_misc", "stats", name);
480  if (fd < 0) {
481  G_remove_misc("cell_misc", "stats", name);
482  G_fatal_error(_("Unable to write stats file for <%s>"), name);
483  }
484 
485  /* if count is zero, write empty file meaning Nulls */
486  if (rstats->count < 1) {
487  close(fd);
488  return;
489  }
490 
491  G_xdr_put_double(xdr_buf[0], &rstats->sum);
492  G_xdr_put_double(xdr_buf[1], &rstats->sumsq);
493 
494  if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
495  G_remove_misc("cell_misc", "stats", name);
496  G_fatal_error(_("Unable to write stats file for <%s>"), name);
497  }
498 
499  /* count; see convert_int() in put_row.c */
500  count = rstats->count;
501  nbytes = 0;
502  /* copy byte by byte */
503  for (i = 0; i < sizeof(grass_int64); i++) {
504  cc[i] = count & 0xff;
505  count >>= 8;
506  if (cc[i])
507  nbytes = i;
508  }
509  nbytes++;
510 
511  /* number of bytes needed for count */
512  if (write(fd, &nbytes, 1) != 1) {
513  G_remove_misc("cell_misc", "stats", name);
514  G_fatal_error(_("Unable to write stats file for <%s>"), name);
515  }
516 
517  if (nbytes > 0 && write(fd, cc, nbytes) != nbytes) {
518  G_remove_misc("cell_misc", "stats", name);
519  G_fatal_error(_("Unable to write stats file for <%s>"), name);
520  }
521 
522  close(fd);
523 }
524 
525 /*!
526  * \brief Update range structure (CELL)
527  *
528  * Compares the <i>cat</i> value with the minimum and maximum values
529  * in the <i>range</i> structure, modifying the range if <i>cat</i>
530  * extends the range.
531  *
532  * NULL-values must be detected and ignored.
533  *
534  * \param cat raster value
535  * \param range pointer to Range structure which holds range info
536  */
537 void Rast_update_range(CELL cat, struct Range *range)
538 {
539  if (!Rast_is_c_null_value(&cat)) {
540  if (range->first_time) {
541  range->first_time = 0;
542  range->min = cat;
543  range->max = cat;
544  return;
545  }
546  if (cat < range->min)
547  range->min = cat;
548  if (cat > range->max)
549  range->max = cat;
550  }
551 }
552 
553 /*!
554  * \brief Update range structure (floating-point)
555  *
556  * Compares the <i>cat</i> value with the minimum and maximum values
557  * in the <i>range</i> structure, modifying the range if <i>cat</i>
558  * extends the range.
559  *
560  * NULL-values must be detected and ignored.
561  *
562  * \param val raster value
563  * \param range pointer to Range structure which holds range info
564  */
565 void Rast_update_fp_range(DCELL val, struct FPRange *range)
566 {
567  if (!Rast_is_d_null_value(&val)) {
568  if (range->first_time) {
569  range->first_time = 0;
570  range->min = val;
571  range->max = val;
572  return;
573  }
574  if (val < range->min)
575  range->min = val;
576  if (val > range->max)
577  range->max = val;
578  }
579 }
580 
581 /*!
582  * \brief Update range structure based on raster row (CELL)
583  *
584  * This routine updates the <i>range</i> data just like
585  * Rast_update_range(), but for <i>n</i> values from the <i>cell</i>
586  * array.
587  *
588  * \param cell raster values
589  * \param n number of values
590  * \param range pointer to Range structure which holds range info
591  */
592 void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
593 {
594  Rast__row_update_range(cell, n, range, 0);
595 }
596 
597 /*!
598  * \brief Update range structure based on raster row
599  *
600  * Note: for internal use only.
601  *
602  * \param cell raster values
603  * \param n number of values
604  * \param range pointer to Range structure which holds range info
605  * \param ignore_zeros ignore zeros
606  */
607 void Rast__row_update_range(const CELL *cell, int n, struct Range *range,
608  int ignore_zeros)
609 {
610  CELL cat;
611 
612  while (n-- > 0) {
613  cat = *cell++;
614  if (Rast_is_c_null_value(&cat) || (ignore_zeros && !cat))
615  continue;
616  if (range->first_time) {
617  range->first_time = 0;
618  range->min = cat;
619  range->max = cat;
620 
621  range->rstats.sum = cat;
622  range->rstats.sumsq = (DCELL)cat * cat;
623 
624  range->rstats.count = 1;
625 
626  continue;
627  }
628  if (cat < range->min)
629  range->min = cat;
630  if (cat > range->max)
631  range->max = cat;
632 
633  range->rstats.sum += cat;
634  range->rstats.sumsq += (DCELL)cat * cat;
635 
636  range->rstats.count += 1;
637  }
638 }
639 
640 /*!
641  * \brief Update range structure based on raster row (floating-point)
642  *
643  * This routine updates the <i>range</i> data just like
644  * Rast_update_range(), but for <i>n</i> values from the <i>cell</i>
645  * array.
646  *
647  * \param cell raster values
648  * \param n number of values
649  * \param range pointer to Range structure which holds range info
650  * \param data_type raster type (CELL, FCELL, DCELL)
651  */
652 void Rast_row_update_fp_range(const void *rast, int n, struct FPRange *range,
653  RASTER_MAP_TYPE data_type)
654 {
655  size_t size = Rast_cell_size(data_type);
656  DCELL val = 0.0;
657 
658  while (n-- > 0) {
659  switch (data_type) {
660  case CELL_TYPE:
661  val = (DCELL) * ((CELL *)rast);
662  break;
663  case FCELL_TYPE:
664  val = (DCELL) * ((FCELL *)rast);
665  break;
666  case DCELL_TYPE:
667  val = *((DCELL *)rast);
668  break;
669  }
670 
671  if (Rast_is_null_value(rast, data_type)) {
672  rast = G_incr_void_ptr(rast, size);
673  continue;
674  }
675  if (range->first_time) {
676  range->first_time = 0;
677  range->min = val;
678  range->max = val;
679 
680  range->rstats.sum = val;
681  range->rstats.sumsq = val * val;
682  range->rstats.count = 1;
683  }
684  else {
685  if (val < range->min)
686  range->min = val;
687  if (val > range->max)
688  range->max = val;
689 
690  range->rstats.sum += val;
691  range->rstats.sumsq += val * val;
692  range->rstats.count += 1;
693  }
694 
695  rast = G_incr_void_ptr(rast, size);
696  }
697 }
698 
699 /*!
700  * \brief Initialize range structure
701  *
702  * Initializes the <i>range</i> structure for updates by
703  * Rast_update_range() and Rast_row_update_range().
704  *
705  * Must set a flag in the range structure that indicates that no
706  * min/max have been defined - probably a <tt>"first"</tt> boolean
707  * flag.
708  *
709  * \param range pointer to Range structure which holds range info
710  */
711 void Rast_init_range(struct Range *range)
712 {
713  Rast_set_c_null_value(&(range->min), 1);
714  Rast_set_c_null_value(&(range->max), 1);
715 
716  init_rstats(&range->rstats);
717 
718  range->first_time = 1;
719 }
720 
721 /*!
722  * \brief Get range min and max
723  *
724  * The minimum and maximum CELL values are extracted from the
725  * <i>range</i> structure.
726  *
727  * If the range structure has no defined min/max (first!=0) there will
728  * not be a valid range. In this case the min and max returned must be
729  * the NULL-value.
730  *
731  * \param range pointer to Range structure which holds range info
732  * \param[out] min minimum value
733  * \param[out] max maximum value
734  */
735 void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
736 {
737  if (range->first_time) {
740  }
741  else {
742  if (Rast_is_c_null_value(&(range->min)))
744  else
745  *min = range->min;
746 
747  if (Rast_is_c_null_value(&(range->max)))
749  else
750  *max = range->max;
751  }
752 }
753 
754 /*!
755  * \brief Initialize fp range
756  *
757  * Must set a flag in the range structure that indicates that no
758  * min/max have been defined - probably a <tt>"first"</tt> boolean
759  * flag.
760  *
761  * \param range pointer to FPRange which holds fp range info
762  */
763 void Rast_init_fp_range(struct FPRange *range)
764 {
765  Rast_set_d_null_value(&(range->min), 1);
766  Rast_set_d_null_value(&(range->max), 1);
767 
768  init_rstats(&range->rstats);
769 
770  range->first_time = 1;
771 }
772 
773 /*!
774  * \brief Get minimum and maximum value from fp range
775  *
776  * Extract the min/max from the range structure <i>range</i>. If the
777  * range structure has no defined min/max (first!=0) there will not be
778  * a valid range. In this case the min and max returned must be the
779  * NULL-value.
780  *
781  * \param range pointer to FPRange which holds fp range info
782  * \param[out] min minimum value
783  * \param[out] max maximum value
784  */
785 void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min,
786  DCELL *max)
787 {
788  if (range->first_time) {
791  }
792  else {
793  if (Rast_is_d_null_value(&(range->min)))
795  else
796  *min = range->min;
797 
798  if (Rast_is_d_null_value(&(range->max)))
800  else
801  *max = range->max;
802  }
803 }
804 
805 static void init_rstats(struct R_stats *rstats)
806 {
809  rstats->count = 0;
810 }
#define XDR_DOUBLE_NBYTES
Definition: R.h:8
#define NULL
Definition: ccmath.h:32
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:150
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition: open_misc.c:205
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_open_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition: open_misc.c:132
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition: open_misc.c:178
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a misc file from the mapset search list or in a specified mapset. (look but don't touch)
Definition: find_file.c:257
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
Definition: remove.c:65
void G_xdr_put_double(void *, const double *)
Definition: gis/xdr.c:94
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
Definition: nme_in_mps.c:101
void G_xdr_get_double(double *, const void *)
Definition: gis/xdr.c:89
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:81
int G_open_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition: open_misc.c:111
int G_debug(int, const char *,...) __attribute__((format(printf
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
Definition: null_val.c:176
void Rast_init(void)
Initialize GRASS GIS engine.
Definition: raster/init.c:43
int Rast_quant_get_limits(const struct Quant *, DCELL *, DCELL *, CELL *, CELL *)
Returns the minimum and maximum cell and dcell values of all the ranges defined.
Definition: quant.c:281
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:153
int Rast_read_quant(const char *, const char *, struct Quant *)
Reads quantization rules for name in mapset and stores them in the quantization structure....
Definition: quant_rw.c:187
int Rast_quant_is_round(const struct Quant *)
Returns whether or not quant rules are set to round map.
Definition: quant.c:204
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
Definition: null_val.c:124
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.
Definition: raster/open.c:894
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
Definition: alloc_cell.c:38
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:414
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:410
int Rast_quant_is_truncate(const struct Quant *)
Returns whether or not quant rules are set to truncate map.
Definition: quant.c:192
#define min(x, y)
Definition: draw2.c:29
#define max(x, y)
Definition: draw2.c:30
float FCELL
Definition: gis.h:630
int64_t grass_int64
Definition: gis.h:635
double DCELL
Definition: gis.h:629
int CELL
Definition: gis.h:628
#define _(str)
Definition: glocale.h:10
GRASS_INTERPFL_EXPORT int count
const char * name
Definition: named_colr.c:6
void Rast_write_fp_range(const char *name, const struct FPRange *range)
Write raster range file (floating-point)
Definition: raster/range.c:426
void Rast__row_update_range(const CELL *cell, int n, struct Range *range, int ignore_zeros)
Update range structure based on raster row.
Definition: raster/range.c:607
int Rast_read_range(const char *name, const char *mapset, struct Range *range)
Read raster range (CELL)
Definition: raster/range.c:163
void Rast__remove_fp_range(const char *name)
Remove floating-point range.
Definition: raster/range.c:33
void Rast_construct_default_range(struct Range *range)
Construct default range.
Definition: raster/range.c:45
void Rast_update_fp_range(DCELL val, struct FPRange *range)
Update range structure (floating-point)
Definition: raster/range.c:565
void Rast_write_rstats(const char *name, const struct R_stats *rstats)
Write raster stats file.
Definition: raster/range.c:468
int Rast_read_rstats(const char *name, const char *mapset, struct R_stats *rstats)
Read raster stats.
Definition: raster/range.c:287
void Rast_row_update_fp_range(const void *rast, int n, struct FPRange *range, RASTER_MAP_TYPE data_type)
Update range structure based on raster row (floating-point)
Definition: raster/range.c:652
void Rast_write_range(const char *name, const struct Range *range)
Write raster range file.
Definition: raster/range.c:390
void Rast_init_range(struct Range *range)
Initialize range structure.
Definition: raster/range.c:711
int Rast_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read floating-point range.
Definition: raster/range.c:71
void Rast_update_range(CELL cat, struct Range *range)
Update range structure (CELL)
Definition: raster/range.c:537
#define DEFAULT_CELL_MAX
Definition: raster/range.c:22
void Rast_init_fp_range(struct FPRange *range)
Initialize fp range.
Definition: raster/range.c:763
#define DEFAULT_CELL_MIN
Definition: raster/range.c:21
void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
Get range min and max.
Definition: raster/range.c:735
void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
Update range structure based on raster row (CELL)
Definition: raster/range.c:592
void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Get minimum and maximum value from fp range.
Definition: raster/range.c:785
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
#define CELL_TYPE
Definition: raster.h:11
int RASTER_MAP_TYPE
Definition: raster.h:25
struct R_stats rstats
Definition: raster.h:231
DCELL min
Definition: raster.h:228
int first_time
Definition: raster.h:230
DCELL max
Definition: raster.h:229
Definition: raster.h:80
DCELL sumsq
Definition: raster.h:216
grass_int64 count
Definition: raster.h:217
DCELL sum
Definition: raster.h:215
Definition: raster.h:220
CELL min
Definition: raster.h:221
int first_time
Definition: raster.h:223
CELL max
Definition: raster.h:222
struct R_stats rstats
Definition: raster.h:224
#define read
Definition: unistd.h:5
#define close
Definition: unistd.h:8
#define write
Definition: unistd.h:6
#define x