int output_raster(int fd) { int i; for (i = 0; i < page.rows; i++, at_row++) { G_percent(i, page.rows, 2); switch (format) { case USE_CELL: cell = raster.cell[i]; /* insert the NULL values */ G_insert_c_null_values(cell, null_flags[i], page.cols); if (G_put_c_raster_row(fd, cell) < 0) return -1; break; case USE_DCELL: dcell = raster.dcell[i]; /* insert the NULL values */ G_insert_d_null_values(dcell, null_flags[i], page.cols); if (G_put_d_raster_row(fd, dcell) < 0) return -1; break; } } G_percent(1, 1, 1); return configure_plot(); }
/* NULL cell handling added by Benjamin Ducke, May 2004 */ void Close_segmented_outfile (char* map_name, int map_fd, char* seg_name, int seg_fd, SEGMENT* seg, CELL* cell_buf, int terse, SEGMENT* elevation_seg, RASTER_MAP_TYPE data_type, int make_nulls) { unsigned long row, nrows, col, ncols; void *value = NULL; char *null_flags; /* the following are used to store different raster map types */ CELL c_value; FCELL f_value; DCELL d_value; /* Find number of rows and columns in elevation map */ nrows = G_window_rows(); ncols = G_window_cols(); /* allocate memory for a NULL data row */ null_flags = G_calloc ((unsigned) ncols, sizeof (char)); /* Write pending updates by segment_put() to output map */ segment_flush(seg); if (!terse) { fprintf (stdout, "\nWriting raster map '%s': \n", map_name); } /* Convert output submatrices to full cell overlay */ for(row=0; row< nrows; row++) { segment_get_row(seg, cell_buf, (signed) row); /* check for NULL values in the corresponding row of the */ /* elevation input file. If there are any, set the CELLs */ /* in the output file to NULL, as well */ /* initialize null data row */ for (col=0; col<ncols; col++) { null_flags[col] = 0; } /* convert all -1 cells to NULL, if user wants it so */ if ( make_nulls == 1 ) { for (col=0; col<ncols; col++) { if ( cell_buf[col] == -1 ) { null_flags[col] = 1; } } } /* update NULL flags in row */ for (col=0; col<ncols; col++) { if ( data_type == CELL_TYPE ) { value = (CELL*) &c_value; } if ( data_type == FCELL_TYPE ) { value = (FCELL*) &f_value; } if ( data_type == DCELL_TYPE ) { value = (DCELL*) &d_value; } segment_get (elevation_seg, value, (signed) row, (signed) col); /* check for NULL value and record in null_flags row */ if ( data_type == CELL_TYPE ) { if (G_is_c_null_value (&c_value) ) { null_flags[col] = 1; /* signal NULL value in null_flags row */ } } if ( data_type == FCELL_TYPE ) { if (G_is_f_null_value (&f_value) ) { null_flags[col] = 1; /* signal NULL value in null_flags row */ } } if ( data_type == DCELL_TYPE ) { if (G_is_d_null_value (&d_value) ) { null_flags[col] = 1; /* signal NULL value in null_flags row */ } } } /* set all NULL cells according to null_flags row */ G_insert_c_null_values (cell_buf, null_flags, (signed) ncols); /* now, write this row to disk */ if(G_put_raster_row (map_fd, cell_buf, CELL_TYPE) < 0) { G_fatal_error ("Failed to convert output submatrices "); } /* progress display */ if (! terse) { G_percent ((signed) row, (signed) nrows-1,2); } } G_free (null_flags); /* Close files */ segment_release (seg); close (seg_fd); unlink (seg_name); G_close_cell (map_fd); }