read_map.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /****************************************************************************
  2. *
  3. * MODULE: r.basins.fill
  4. *
  5. * AUTHOR(S): Dale White - Dept. of Geography, Pennsylvania State U.
  6. * Larry Band - Dept. of Geography, University of Toronto
  7. *
  8. * PURPOSE: Generates a raster map layer showing watershed subbasins.
  9. *
  10. * COPYRIGHT: (C) 2005 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. ****************************************************************************/
  17. #include <grass/gis.h>
  18. #include <grass/raster.h>
  19. #include <grass/glocale.h>
  20. #include "local_proto.h"
  21. CELL *read_map(const char *name, int nomask, int nrows, int ncols)
  22. {
  23. int fd;
  24. CELL *map;
  25. int row;
  26. void (*get_row)(int, CELL *, int);
  27. /* allocate entire map */
  28. map = (CELL *) G_malloc(nrows * ncols * sizeof(CELL));
  29. /* open the map */
  30. fd = Rast_open_old(name, "");
  31. /* read the map */
  32. G_message(_("Reading <%s> ... "), name);
  33. if (nomask)
  34. get_row = Rast_get_c_row_nomask;
  35. else
  36. get_row = Rast_get_c_row;
  37. for (row = 0; row < nrows; row++) {
  38. G_percent(row, nrows, 10);
  39. (*get_row)(fd, map + row * ncols, row);
  40. }
  41. G_percent(nrows, nrows, 10);
  42. Rast_close(fd);
  43. return map;
  44. }