24 #include <grass/gis.h>
25 #include <grass/glocale.h>
38 static CELL cellNullPattern;
39 static FCELL fcellNullPattern;
40 static DCELL dcellNullPattern;
43 static int initialized =
FALSE;
47 static int EmbedGivenNulls(
void *,
char *, RASTER_MAP_TYPE,
int);
48 static void InitError(
void);
63 static int EmbedGivenNulls(
void *cell,
char *nulls, RASTER_MAP_TYPE map_type,
75 for (i = 0; i < ncols; i++) {
91 G_warning(_(
"EmbedGivenNulls: wrong data type!"));
108 static void InitError(
void)
112 strcpy(errMsg, _(
"Null values have not been initialized. "));
113 strcat(errMsg, _(
"G_gisinit() must be called first. "));
114 strcat(errMsg, _(
"Please advise GRASS developers of this error.\n"));
133 unsigned char *bytePtr;
142 numBits =
sizeof(CELL) * 8;
144 cellNullPattern = 1 << (numBits - 1);
149 bytePtr = (
unsigned char *)&fcellNullPattern;
151 for (i = 0; i <
sizeof(FCELL); i++) {
152 *bytePtr = (
unsigned char)255;
159 bytePtr = (
unsigned char *)&dcellNullPattern;
161 for (i = 0; i <
sizeof(DCELL); i++) {
162 *bytePtr = (
unsigned char)255;
186 RASTER_MAP_TYPE data_type)
223 G_warning(_(
"G_set_null_value: wrong data type!"));
250 for (i = 0; i < numVals; i++) {
251 *cellPtr = cellNullPattern;
277 fcellPtr = fcellVals;
279 for (i = 0; i < numVals; i++) {
280 *fcellPtr = fcellNullPattern;
306 dcellPtr = dcellVals;
308 for (i = 0; i < numVals; i++) {
309 *dcellPtr = dcellNullPattern;
350 G_warning(
"G_is_null_value: wrong data type!");
384 for (i = 0; i <
sizeof(CELL); i++) {
385 if (((
unsigned char *)cellVal)[i] !=
386 ((
unsigned char *)&cellNullPattern)[i]) {
427 return *fcellVal != *fcellVal;
452 return *dcellVal != *dcellVal;
486 RASTER_MAP_TYPE data_type)
488 return (EmbedGivenNulls(rast, null_row, data_type, ncols));
516 return (EmbedGivenNulls((
void *)cellVal, null_row, CELL_TYPE, ncols));
544 return (EmbedGivenNulls((
void *)fcellVal, null_row, FCELL_TYPE, ncols));
572 return (EmbedGivenNulls((
void *)dcellVal, null_row, DCELL_TYPE, ncols));
595 G_warning(
"G__check_null_bit: can't access index %d. "
596 "Size of flags is %d (bit # is %d",
601 offset = (ind + 1) * 8 - bit_num - 1;
603 return ((flags[ind] & ((
unsigned char)1 << offset)) != 0);
621 int col,
int n,
int ncols)
628 if (col == 0 && n == ncols) {
636 for (i = 0; i <
size; i++) {
641 if (count >= col && count < (col + n)) {
642 v = v | ((
unsigned char)zero_ones[count - col] << k);
644 else if (count < ncols) {
680 for (i = 0; i <
size; i++) {
686 *v = *v | ((
unsigned char)zero_ones[count] << k);
709 const unsigned char *v;
718 for (i = 0; i <
size; i++) {
723 zero_ones[
count] = ((*v & ((
unsigned char)1 << k)) != 0);
752 for (i = 0; i <
size; i++) {
753 if ((i + 1) * 8 <= cols) {
754 *v = (
unsigned char)255;
757 *v = (
unsigned char)255 << ((i + 1) * 8 -
cols);
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
void G__set_null_value(void *rast, int numVals, int null_is_zero, RASTER_MAP_TYPE data_type)
void G_set_d_null_value(DCELL *dcellVals, int numVals)
int G__set_flags_from_01_random(const char *zero_ones, unsigned char *flags, int col, int n, int ncols)
int G_warning(const char *msg,...)
Print a warning message to stderr.
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
void G__init_null_patterns(void)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
int G_is_f_null_value(const FCELL *fcellVal)
Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn't good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be.
int G_insert_null_values(void *rast, char *null_row, int ncols, RASTER_MAP_TYPE data_type)
Insert NULL value.
size_t G_raster_size(RASTER_MAP_TYPE data_type)
Returns size of a raster CELL in bytes.
int G__convert_01_flags(const char *zero_ones, unsigned char *flags, int n)
int G__init_null_bits(unsigned char *flags, int cols)
int G_insert_d_null_values(DCELL *dcellVal, char *null_row, int ncols)
Insert DCELL NULL value.
int G__convert_flags_01(char *zero_ones, const unsigned char *flags, int n)
int G_insert_f_null_values(FCELL *fcellVal, char *null_row, int ncols)
Insert FCELL NULL value.
void G_set_f_null_value(FCELL *fcellVals, int numVals)
int G__null_bitstream_size(int cols)
Determines null bitstream size.
void G_set_null_value(void *buf, int numVals, RASTER_MAP_TYPE data_type)
void G_set_c_null_value(CELL *cellVals, int numVals)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G__check_null_bit(const unsigned char *flags, int bit_num, int n)
int G_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
If the data_type is CELL_TYPE, calls G_is_c_null_value ((CELL *) rast); If the data_type is FCELL_TYP...
int G_insert_c_null_values(CELL *cellVal, char *null_row, int ncols)
Insert CELL NULL value.