read_cell.c 615 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "contour.h"
  2. #include <grass/raster.h>
  3. #include <grass/glocale.h>
  4. DCELL **read_cell(const char *name)
  5. {
  6. int nrows = Rast_window_rows();
  7. int ncols = Rast_window_cols();
  8. DCELL *buf, **idx;
  9. int fd;
  10. int row;
  11. fd = Rast_open_old(name, "");
  12. buf = G_malloc((size_t) nrows * ncols * sizeof(DCELL));
  13. idx = G_malloc(nrows * sizeof(DCELL *));
  14. for (row = 0; row < nrows; row++) {
  15. idx[row] = &buf[row * ncols];
  16. Rast_get_d_row(fd, idx[row], row);
  17. }
  18. Rast_close(fd);
  19. return idx;
  20. }
  21. void free_cell(DCELL **idx)
  22. {
  23. G_free(idx[0]);
  24. G_free(idx);
  25. }