1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <grass/raster.h>
- #include <grass/glocale.h>
- #include "global.h"
- int write_matrix(int row, int col)
- {
- int n;
- off_t offset;
- select_target_env();
- if (!temp_fd) {
- temp_name = G_tempfile();
- temp_fd = creat(temp_name, 0660);
- }
- for (n = 0; n < matrix_rows; n++) {
- offset =
- ((off_t) row++ * target_window.cols +
- col) * Rast_cell_size(map_type);
- lseek(temp_fd, offset, SEEK_SET);
- if (write(temp_fd, cell_buf[n], Rast_cell_size(map_type) * matrix_cols)
- != Rast_cell_size(map_type) * matrix_cols) {
- unlink(temp_name);
- G_fatal_error(_("Error while writing to temp file"));
- }
- /*Rast_put_c_row_random (outfd, cell_buf[n], row++, col, matrix_cols); */
- }
- select_current_env();
- return 0;
- }
- int write_map(char *name)
- {
- int fd, row;
- void *rast;
- Rast_set_output_window(&target_window);
- /* working with split windows, can not use Rast_allocate_buf(map_type); */
- rast = G_malloc(target_window.cols * Rast_cell_size(map_type));
- close(temp_fd);
- temp_fd = open(temp_name, 0);
- fd = Rast_open_new(name, map_type);
- for (row = 0; row < target_window.rows; row++) {
- if (read(temp_fd, rast, target_window.cols * Rast_cell_size(map_type))
- != target_window.cols * Rast_cell_size(map_type))
- G_fatal_error(_("Error writing row %d"), row);
- Rast_put_row(fd, rast, map_type);
- }
- close(temp_fd);
- unlink(temp_name);
- Rast_close(fd);
- G_free(rast);
- return 0;
- }
|