GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
raster/put_row.c
Go to the documentation of this file.
1 /*!
2  \file lib/raster/put_row.c
3 
4  \brief Raster library - Put raster row
5 
6  (C) 2003-2009 by the 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 /**********************************************************************
15 
16  **********************************************************************/
17 
18 #include <string.h>
19 
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <errno.h>
25 
26 #include <grass/config.h>
27 #include <grass/raster.h>
28 #include <grass/glocale.h>
29 
30 #include "R.h"
31 
32 static void put_raster_row(int, const void *, RASTER_MAP_TYPE, int);
33 
34 /*!
35  \brief Writes the next row for cell/fcell/dcell file
36 
37  Writes the next row for the cell file opened on 'fd' from 'buf' All
38  writes go into NEW files that exactly match the current window. The
39  file must have been opened with Rast_open_new() and be written
40  sequentially, ie no skipping rows.
41 
42  When the null values are embedded into the data, corresponding cells
43  are changed to 0's and the corresponding null value row is written
44  into null file.
45 
46  A map cannot be copied using Rast_get_row() and
47  Rast_put_row(). The former resamples the data of the original
48  map into a row buffer that matches the current window. The later
49  writes out rows associated with the window.
50 
51  Keeps track of the minimum and maximum cell value for use in
52  updating the range file upon close of the cell file. HOWEVER when
53  nulls are not embedded, the cells are considered 0's as far as
54  updating range is concerned, even if the corresponding cell is null
55  in the resulting null file, so programmer should be carefult to set
56  all the null values using Rast_set_null_value() or
57  G_insert_d_null_values() or G_insert_f_null_values().
58 
59  \param fd file descriptor where data is to be written
60  \param buf buffer holding data
61  \param data_type raster map type (CELL_TYPE, FCELL_TYPE, DCELL_TYPE)
62 
63  \return void
64  */
65 void Rast_put_row(int fd, const void *buf, RASTER_MAP_TYPE data_type)
66 {
67  put_raster_row(fd, buf, data_type, 0);
68 }
69 
70 /*!
71  \brief Writes the next row for cell file (CELL version)
72 
73  See Rast_put_row() for details.
74 
75  \param fd file descriptor where data is to be written
76  \param buf buffer holding data
77 
78  \return void
79  */
80 void Rast_put_c_row(int fd, const CELL * buf)
81 {
82  Rast_put_row(fd, buf, CELL_TYPE);
83 }
84 
85 /*!
86  \brief Writes the next row for fcell file (FCELL version)
87 
88  See Rast_put_row() for details.
89 
90  \param fd file descriptor where data is to be written
91  \param buf buffer holding data
92 
93  \return void
94  */
95 void Rast_put_f_row(int fd, const FCELL * buf)
96 {
97  Rast_put_row(fd, buf, FCELL_TYPE);
98 }
99 
100 /*!
101  \brief Writes the next row for dcell file (DCELL version)
102 
103  See Rast_put_row() for details.
104 
105  \param fd file descriptor where data is to be written
106  \param buf buffer holding data
107 
108  \return void
109  */
110 void Rast_put_d_row(int fd, const DCELL * buf)
111 {
112  Rast_put_row(fd, buf, DCELL_TYPE);
113 }
114 
115 static void write_data(int fd, int row, unsigned char *buf, int n)
116 {
117  struct fileinfo *fcb = &R__.fileinfo[fd];
118  ssize_t nwrite = fcb->nbytes * n;
119 
120  if (write(fcb->data_fd, buf, nwrite) != nwrite)
121  G_fatal_error(_("Error writing uncompressed FP data for row %d of <%s>: %s"),
122  row, fcb->name, strerror(errno));
123 }
124 
125 static void write_data_compressed(int fd, int row, unsigned char *buf, int n, int compressor)
126 {
127  struct fileinfo *fcb = &R__.fileinfo[fd];
128  int nwrite = fcb->nbytes * n;
129 
130  if (G_write_compressed(fcb->data_fd, buf, nwrite, compressor) < 0)
131  G_fatal_error(_("Error writing compressed FP data for row %d of <%s>: %s"),
132  row, fcb->name, strerror(errno));
133 }
134 
135 static void set_file_pointer(int fd, int row)
136 {
137  struct fileinfo *fcb = &R__.fileinfo[fd];
138 
139  fcb->row_ptr[row] = lseek(fcb->data_fd, 0L, SEEK_CUR);
140 }
141 
142 static void convert_float(float *work_buf, int size, char *null_buf,
143  const FCELL *rast, int row, int n)
144 {
145  int i;
146 
147  for (i = 0; i < n; i++) {
148  FCELL f;
149 
150  /* substitute embedded null vals by 0's */
151  if (Rast_is_f_null_value(&rast[i])) {
152  f = 0.;
153  null_buf[i] = 1;
154  }
155  else
156  f = rast[i];
157 
158  G_xdr_put_float(&work_buf[i], &f);
159  }
160 }
161 
162 static void convert_double(double *work_buf, int size, char *null_buf,
163  const DCELL *rast, int row, int n)
164 {
165  int i;
166 
167  for (i = 0; i < n; i++) {
168  DCELL d;
169 
170  /* substitute embedded null vals by 0's */
171  if (Rast_is_d_null_value(&rast[i])) {
172  d = 0.;
173  null_buf[i] = 1;
174  }
175  else
176  d = rast[i];
177 
178  G_xdr_put_double(&work_buf[i], &d);
179  }
180 }
181 
182 /* writes data to fcell file for either full or partial rows */
183 static void put_fp_data(int fd, char *null_buf, const void *rast,
184  int row, int n, RASTER_MAP_TYPE data_type)
185 {
186  struct fileinfo *fcb = &R__.fileinfo[fd];
187  int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
188  int size = fcb->nbytes * fcb->cellhd.cols;
189  void *work_buf;
190 
191  if (row < 0 || row >= fcb->cellhd.rows)
192  return;
193 
194  if (n <= 0)
195  return;
196 
197  work_buf = G_malloc(size + 1);
198 
199  if (compressed)
200  set_file_pointer(fd, row);
201 
202  if (data_type == FCELL_TYPE)
203  convert_float(work_buf, size, null_buf, rast, row, n);
204  else
205  convert_double(work_buf, size, null_buf, rast, row, n);
206 
207  if (compressed)
208  write_data_compressed(fd, row, work_buf, n, fcb->cellhd.compressed);
209  else
210  write_data(fd, row, work_buf, n);
211 
212  G_free(work_buf);
213 }
214 
215 static void convert_int(unsigned char *wk, char *null_buf, const CELL * rast,
216  int n, int len, int zeros_r_nulls)
217 {
218  int i;
219 
220  /* transform CELL data into non-machine dependent multi-byte format */
221 
222  for (i = 0; i < n; i++) {
223  CELL v = rast[i];
224  int neg;
225  int k;
226 
227  /* substitute embedded null vals by 0's */
228  if (Rast_is_c_null_value(&v)) {
229  v = 0;
230  null_buf[i] = 1;
231  }
232  else if (zeros_r_nulls && !v)
233  null_buf[i] = 1;
234 
235  /* negatives */
236  if (v < 0) {
237  neg = 1;
238  v = -v;
239  }
240  else
241  neg = 0;
242 
243  /* copy byte by byte */
244  for (k = len - 1; k >= 0; k--) {
245  wk[k] = v & 0xff;
246  v >>= 8;
247  }
248 
249  /* set negative bit in first byte */
250  if (neg)
251  wk[0] |= 0x80;
252 
253  wk += len;
254  }
255 }
256 
257 static int count_bytes(const unsigned char *wk, int n, int len)
258 {
259  int i, j;
260 
261  for (i = 0; i < len - 1; i++)
262  for (j = 0; j < n; j++)
263  if (wk[j * len + i] != 0)
264  return len - i;
265 
266  return 1;
267 }
268 
269 static void trim_bytes(unsigned char *wk, int n, int slen, int trim)
270 {
271  unsigned char *wk2 = wk;
272  int i, j;
273 
274  for (i = 0; i < n; i++) {
275  for (j = 0; j < trim; j++)
276  wk++;
277  for (; j < slen; j++)
278  *wk2++ = *wk++;
279  }
280 }
281 
282 static int same(const unsigned char *x, const unsigned char *y, int n)
283 {
284  return (memcmp(x, y, n) == 0);
285 }
286 
287 static int count_run(const unsigned char *src, int n, int nbytes)
288 {
289  const unsigned char *cur = src + nbytes;
290  int i;
291 
292  for (i = 1; i < n; i++) {
293  if (i == 255 || !same(cur, src, nbytes))
294  return i;
295 
296  cur += nbytes;
297  }
298 
299  return n;
300 }
301 
302 static int rle_compress(unsigned char *dst, unsigned char *src, int n,
303  int nbytes)
304 {
305  int nwrite = 0;
306  int total = nbytes * n;
307 
308  while (n > 0) {
309  int count;
310 
311  nwrite += nbytes + 1;
312  if (nwrite >= total)
313  return 0;
314 
315  count = count_run(src, n, nbytes);
316 
317  *dst++ = count;
318  memcpy(dst, src, nbytes);
319  dst += nbytes;
320 
321  src += count * nbytes;
322  n -= count;
323  }
324 
325  return (nwrite >= total) ? 0 : nwrite;
326 }
327 
328 static void put_data(int fd, char *null_buf, const CELL * cell,
329  int row, int n, int zeros_r_nulls)
330 {
331  struct fileinfo *fcb = &R__.fileinfo[fd];
332  int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
333  int len = compressed ? sizeof(CELL) : fcb->nbytes;
334  unsigned char *work_buf, *wk;
335  ssize_t nwrite;
336 
337  if (row < 0 || row >= fcb->cellhd.rows)
338  return;
339 
340  if (n <= 0)
341  return;
342 
343  work_buf = G_malloc(fcb->cellhd.cols * sizeof(CELL) + 1);
344  wk = work_buf;
345 
346  if (compressed)
347  set_file_pointer(fd, row);
348 
349  if (compressed)
350  wk++;
351 
352  convert_int(wk, null_buf, cell, n, len, zeros_r_nulls);
353 
354  if (compressed) {
355  int nbytes = count_bytes(wk, n, len);
356  unsigned char *compressed_buf;
357  int total, cmax;
358 
359  if (fcb->nbytes < nbytes)
360  fcb->nbytes = nbytes;
361 
362  /* first trim away zero high bytes */
363  if (nbytes < len)
364  trim_bytes(wk, n, len, len - nbytes);
365 
366  total = nbytes * n;
367  /* get upper bound of compressed size */
368  if (fcb->cellhd.compressed == 1)
369  cmax = total;
370  else
371  cmax = G_compress_bound(total, fcb->cellhd.compressed);
372  compressed_buf = G_malloc(cmax + 1);
373 
374  compressed_buf[0] = work_buf[0] = nbytes;
375 
376  /* then compress the data */
377  if (fcb->cellhd.compressed == 1)
378  nwrite = rle_compress(compressed_buf + 1, work_buf + 1, n, nbytes);
379  else {
380  nwrite = G_compress(work_buf + 1, total, compressed_buf + 1, cmax,
381  fcb->cellhd.compressed);
382  }
383 
384  if (nwrite >= total)
385  nwrite = 0;
386 
387  if (nwrite > 0) {
388  nwrite++;
389 
390  if (write(fcb->data_fd, compressed_buf, nwrite) != nwrite)
391  G_fatal_error(_("Error writing compressed data for row %d of <%s>: %s"),
392  row, fcb->name, strerror(errno));
393  }
394  else {
395  nwrite = nbytes * n + 1;
396  if (write(fcb->data_fd, work_buf, nwrite) != nwrite)
397  G_fatal_error(_("Error writing compressed data for row %d of <%s>: %s"),
398  row, fcb->name, strerror(errno));
399  }
400 
401  G_free(compressed_buf);
402  }
403  else {
404  nwrite = fcb->nbytes * n;
405 
406  if (write(fcb->data_fd, work_buf, nwrite) != nwrite)
407  G_fatal_error(_("Error writing uncompressed data for row %d of <%s>: %s"),
408  row, fcb->name, strerror(errno));
409  }
410 
411  G_free(work_buf);
412 }
413 
414 static void put_data_gdal(int fd, const void *rast, int row, int n,
415  int zeros_r_nulls, RASTER_MAP_TYPE map_type)
416 {
417 #ifdef HAVE_GDAL
418  struct fileinfo *fcb = &R__.fileinfo[fd];
419  int size = Rast_cell_size(map_type);
420  DCELL null_val = fcb->gdal->null_val;
421  const void *src;
422  void *work_buf, *dst;
423  GDALDataType datatype;
424  CPLErr err;
425  int i;
426 
427  if (row < 0 || row >= fcb->cellhd.rows)
428  return;
429 
430  if (n <= 0)
431  return;
432 
433  work_buf = G_malloc(n * size);
434 
435  datatype = GDT_Unknown;
436  switch (map_type) {
437  case CELL_TYPE:
438  datatype = GDT_Int32;
439  break;
440  case FCELL_TYPE:
441  datatype = GDT_Float32;
442  break;
443  case DCELL_TYPE:
444  datatype = GDT_Float64;
445  break;
446  }
447 
448  src = rast;
449  dst = work_buf;
450 
451  for (i = 0; i < n; i++) {
452  if (Rast_is_null_value(src, map_type) ||
453  (zeros_r_nulls && !*(CELL *) src))
454  Rast_set_d_value(dst, null_val, map_type);
455  else
456  memcpy(dst, src, size);
457  src = G_incr_void_ptr(src, size);
458  dst = G_incr_void_ptr(dst, size);
459  }
460 
461  err = Rast_gdal_raster_IO(fcb->gdal->band, GF_Write, 0, row, n, 1,
462  work_buf, n, 1, datatype, 0, 0);
463 
464  G_free(work_buf);
465 
466  if (err != CE_None)
467  G_fatal_error(_("Error writing data via GDAL for row %d of <%s>"),
468  row, fcb->name);
469 #endif
470 }
471 
472 static void put_raster_data(int fd, char *null_buf, const void *rast,
473  int row, int n,
474  int zeros_r_nulls, RASTER_MAP_TYPE map_type)
475 {
476  struct fileinfo *fcb = &R__.fileinfo[fd];
477 
478  if (fcb->gdal)
479  put_data_gdal(fd, rast, row, n, zeros_r_nulls, map_type);
480  else if (map_type == CELL_TYPE)
481  put_data(fd, null_buf, rast, row, n, zeros_r_nulls);
482  else
483  put_fp_data(fd, null_buf, rast, row, n, map_type);
484 }
485 
486 static void put_null_value_row(int fd, const char *flags)
487 {
488  struct fileinfo *fcb = &R__.fileinfo[fd];
489 
490  if (fcb->gdal)
491  G_fatal_error(_("GDAL output doesn't support writing null rows separately"));
492 
493  if (fcb->null_fd < 0)
494  G_fatal_error(_("No null file for <%s>"), fcb->name);
495 
496  Rast__convert_01_flags(flags, fcb->null_bits,
497  fcb->cellhd.cols);
498 
500 }
501 
502 static void write_null_bits_compressed(const unsigned char *flags,
503  int row, size_t size, int fd)
504 {
505  struct fileinfo *fcb = &R__.fileinfo[fd];
506  unsigned char *compressed_buf;
507  ssize_t nwrite;
508  size_t cmax;
509 
510  fcb->null_row_ptr[row] = lseek(fcb->null_fd, 0L, SEEK_CUR);
511 
512  /* get upper bound of compressed size */
513  cmax = G_compress_bound(size, 3);
514  compressed_buf = G_malloc(cmax);
515 
516  /* compress null bits file with LZ4, see lib/gis/compress.h */
517  nwrite = G_compress((unsigned char *)flags, size, compressed_buf, cmax, 3);
518 
519  if (nwrite > 0 && nwrite < size) {
520  if (write(fcb->null_fd, compressed_buf, nwrite) != nwrite)
521  G_fatal_error(_("Error writing compressed null data for row %d of <%s>: %s"),
522  row, fcb->name, strerror(errno));
523  }
524  else {
525  if (write(fcb->null_fd, flags, size) != size)
526  G_fatal_error(_("Error writing compressed null data for row %d of <%s>: %s"),
527  row, fcb->name, strerror(errno));
528  }
529 
530  G_free(compressed_buf);
531 }
532 
533 /*!
534  \brief Write null data
535 
536  \param flags ?
537  \param row row number
538  \param col col number
539  \param fd file descriptor of cell data file
540 
541  \return void
542  */
543 void Rast__write_null_bits(int fd, const unsigned char *flags)
544 {
545  struct fileinfo *fcb = &R__.fileinfo[fd];
546  int row = fcb->null_cur_row++;
547  off_t offset;
548  size_t size;
549 
551 
552  if (fcb->null_row_ptr) {
553  write_null_bits_compressed(flags, row, size, fd);
554  return;
555  }
556 
557  offset = (off_t) size * row;
558 
559  if (lseek(fcb->null_fd, offset, SEEK_SET) < 0)
560  G_fatal_error(_("Error writing null row %d of <%s>"),
561  row, fcb->name);
562 
563  if (write(fcb->null_fd, flags, size) != size)
564  G_fatal_error(_("Error writing null row %d of <%s>: %s"),
565  row, fcb->name, strerror(errno));
566 }
567 
568 static void convert_and_write_if(int fd, const void *vbuf)
569 {
570  const CELL *buf = vbuf;
571  struct fileinfo *fcb = &R__.fileinfo[fd];
572  FCELL *p = (FCELL *) fcb->data;
573  int i;
574 
575  for (i = 0; i < fcb->cellhd.cols; i++)
576  if (Rast_is_c_null_value(&buf[i]))
577  Rast_set_f_null_value(&p[i], 1);
578  else
579  p[i] = (FCELL) buf[i];
580 
581  Rast_put_f_row(fd, p);
582 }
583 
584 static void convert_and_write_df(int fd, const void *vbuf)
585 {
586  const DCELL *buf = vbuf;
587  struct fileinfo *fcb = &R__.fileinfo[fd];
588  FCELL *p = (FCELL *) fcb->data;
589  int i;
590 
591  for (i = 0; i < fcb->cellhd.cols; i++)
592  if (Rast_is_d_null_value(&buf[i]))
593  Rast_set_f_null_value(&p[i], 1);
594  else
595  p[i] = (FCELL) buf[i];
596 
597  Rast_put_f_row(fd, p);
598 }
599 
600 static void convert_and_write_id(int fd, const void *vbuf)
601 {
602  const CELL *buf = vbuf;
603  struct fileinfo *fcb = &R__.fileinfo[fd];
604  DCELL *p = (DCELL *) fcb->data;
605  int i;
606 
607  for (i = 0; i < fcb->cellhd.cols; i++)
608  if (Rast_is_c_null_value(&buf[i]))
609  Rast_set_d_null_value(&p[i], 1);
610  else
611  p[i] = (DCELL) buf[i];
612 
613  Rast_put_d_row(fd, p);
614 }
615 
616 static void convert_and_write_fd(int fd, const void *vbuf)
617 {
618  const FCELL *buf = vbuf;
619  struct fileinfo *fcb = &R__.fileinfo[fd];
620  DCELL *p = (DCELL *) fcb->data;
621  int i;
622 
623  for (i = 0; i < fcb->cellhd.cols; i++)
624  if (Rast_is_f_null_value(&buf[i]))
625  Rast_set_d_null_value(&p[i], 1);
626  else
627  p[i] = (DCELL) buf[i];
628 
629  Rast_put_d_row(fd, p);
630 }
631 
632 static void convert_and_write_fi(int fd, const void *vbuf)
633 {
634  const FCELL *buf = vbuf;
635  struct fileinfo *fcb = &R__.fileinfo[fd];
636  CELL *p = (CELL *) fcb->data;
637  int i;
638 
639  for (i = 0; i < fcb->cellhd.cols; i++)
640  if (Rast_is_f_null_value(&buf[i]))
641  Rast_set_c_null_value(&p[i], 1);
642  else
643  p[i] = (CELL) buf[i];
644 
645  Rast_put_c_row(fd, p);
646 }
647 
648 static void convert_and_write_di(int fd, const void *vbuf)
649 {
650  const DCELL *buf = vbuf;
651  struct fileinfo *fcb = &R__.fileinfo[fd];
652  CELL *p = (CELL *) fcb->data;
653  int i;
654 
655  for (i = 0; i < fcb->cellhd.cols; i++)
656  if (Rast_is_d_null_value(&buf[i]))
657  Rast_set_c_null_value(&p[i], 1);
658  else
659  p[i] = (CELL) buf[i];
660 
661  Rast_put_c_row(fd, p);
662 }
663 
664 /*!
665  \brief converts a buffer of zero's and ones to bitstream.
666 
667  Stores this bitstream in memory. (the null rows from memory are
668  written into null file after the limit is reached, and the place for
669  new null rows to be kept in memory is freed. Should not be used by
670  application programs.
671 
672  \param fd file descriptor where data is to be written
673  \param buf buffer holding null data
674 
675  \return void
676  */
677 static void put_raster_row(int fd, const void *buf, RASTER_MAP_TYPE data_type,
678  int zeros_r_nulls)
679 {
680  static void (*convert_and_write_FtypeOtype[3][3])(int, const void *) = {
681  {NULL, convert_and_write_if, convert_and_write_id},
682  {convert_and_write_fi, NULL, convert_and_write_fd},
683  {convert_and_write_di, convert_and_write_df, NULL}
684  };
685  struct fileinfo *fcb = &R__.fileinfo[fd];
686  char *null_buf;
687 
688  switch (fcb->open_mode) {
689  case OPEN_OLD:
690  G_fatal_error(_("put_raster_row: raster map <%s> not open for write - request ignored"),
691  fcb->name);
692  break;
693  case OPEN_NEW_COMPRESSED:
695  break;
696  default:
697  G_fatal_error(_("put_raster_row: unopened file descriptor - request ignored"));
698  break;
699  }
700 
701  if (fcb->map_type != data_type) {
702  convert_and_write_FtypeOtype[data_type][fcb->map_type](fd, buf);
703  return;
704  }
705 
706  null_buf = G_malloc(fcb->cellhd.cols);
707  G_zero(null_buf, fcb->cellhd.cols);
708 
709  put_raster_data(fd, null_buf, buf, fcb->cur_row, fcb->cellhd.cols,
710  zeros_r_nulls, data_type);
711 
712  /* only for integer maps */
713  if (data_type == CELL_TYPE) {
714  if (fcb->want_histogram)
715  Rast_update_cell_stats(buf, fcb->cellhd.cols, &fcb->statf);
716  Rast__row_update_range(buf, fcb->cellhd.cols, &fcb->range,
717  zeros_r_nulls);
718  }
719  else
720  Rast_row_update_fp_range(buf, fcb->cellhd.cols, &fcb->fp_range,
721  data_type);
722 
723  fcb->cur_row++;
724 
725  /* write the null row for the data row */
726  if (!fcb->gdal)
727  put_null_value_row(fd, null_buf);
728 
729  G_free(null_buf);
730 }
#define CELL_TYPE
Definition: raster.h:11
#define OPEN_NEW_COMPRESSED
Definition: R.h:109
#define G_malloc(n)
Definition: defs/gis.h:112
void Rast__write_null_bits(int fd, const unsigned char *flags)
Write null data.
int nbytes
Definition: R.h:73
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
if(!(yy_init))
Definition: sqlp.yy.c:775
struct compressor_list compressor[]
Definition: compress.h:54
int want_histogram
Definition: R.h:62
int G_write_compressed(int, unsigned char *, int, int)
Definition: compress.c:326
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 map_type
Definition: R.h:74
Definition: R.h:88
void Rast_put_c_row(int fd, const CELL *buf)
Writes the next row for cell file (CELL version)
CPLErr Rast_gdal_raster_IO(GDALRasterBandH, GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int)
char * name
Definition: R.h:78
int data_fd
Definition: R.h:83
#define Rast_is_d_null_value(dcellVal)
Definition: defs/raster.h:414
off_t * row_ptr
Definition: R.h:64
int G_compress_bound(int, int)
Definition: compress.c:205
double DCELL
Definition: gis.h:614
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
int count
void Rast__row_update_range(const CELL *, int, struct Range *, int)
Update range structure based on raster row.
Definition: range.c:587
unsigned char * data
Definition: R.h:70
char * dst
Definition: lz4.h:599
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:100
#define Rast_is_f_null_value(fcellVal)
Definition: defs/raster.h:412
#define NULL
Definition: ccmath.h:32
unsigned char * null_bits
Definition: R.h:72
struct GDAL_link * gdal
Definition: R.h:82
#define x
struct Range range
Definition: R.h:60
#define OPEN_NEW_UNCOMPRESSED
Definition: R.h:110
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
Definition: symbol/read.c:220
int compressed
Compression mode (raster header only)
Definition: gis.h:436
#define DCELL_TYPE
Definition: raster.h:13
struct Cell_stats statf
Definition: R.h:59
int Rast__null_bitstream_size(int)
Determines null bitstream size.
Definition: alloc_cell.c:148
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
Definition: alloc_cell.c:39
int null_fd
Definition: R.h:71
int G_compress(unsigned char *, int, unsigned char *, int, int)
Definition: compress.c:221
int open_mode
Definition: R.h:56
void G_xdr_put_double(void *, const double *)
Definition: gis/xdr.c:88
int cur_row
Definition: R.h:67
void G_xdr_put_float(void *, const float *)
Definition: gis/xdr.c:78
void Rast_set_f_null_value(FCELL *, int)
To set a number of FCELL raster values to NULL.
Definition: null_val.c:138
void Rast_put_f_row(int fd, const FCELL *buf)
Writes the next row for fcell file (FCELL version)
struct fileinfo * fileinfo
Definition: R.h:103
#define OPEN_OLD
Definition: R.h:108
int Rast_update_cell_stats(const CELL *, int, struct Cell_stats *)
Add data to cell stats.
Definition: cell_stats.c:62
float FCELL
Definition: gis.h:615
void Rast_put_d_row(int fd, const DCELL *buf)
Writes the next row for dcell file (DCELL version)
void Rast_set_d_value(void *, DCELL, RASTER_MAP_TYPE)
Places a DCELL raster value.
void Rast_row_update_fp_range(const void *, int, struct FPRange *, RASTER_MAP_TYPE)
Update range structure based on raster row (floating-point)
Definition: range.c:630
int cols
Number of columns for 2D data.
Definition: gis.h:442
off_t * null_row_ptr
Definition: R.h:84
struct Cell_head cellhd
Definition: R.h:57
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:23
int CELL
Definition: gis.h:613
Definition: R.h:54
#define _(str)
Definition: glocale.h:10
int RASTER_MAP_TYPE
Definition: raster.h:25
void Rast__convert_01_flags(const char *, unsigned char *, int)
?
Definition: null_val.c:423
int null_cur_row
Definition: R.h:68
#define FCELL_TYPE
Definition: raster.h:12
void Rast_put_row(int fd, const void *buf, RASTER_MAP_TYPE data_type)
Writes the next row for cell/fcell/dcell file.
int rows
Number of rows for 2D data.
Definition: gis.h:438
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:410
struct FPRange fp_range
Definition: R.h:61
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:155
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
Definition: null_val.c:179