r_cell.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Function: cellfile
  2. **
  3. ** This function is a slightly modified version of the p.map function.
  4. ** Modified: Paul W. Carlson April 1992
  5. */
  6. #include <string.h>
  7. #include <grass/raster.h>
  8. #include "local_proto.h"
  9. int read_cell(char *name, char *mapset)
  10. {
  11. /* full name can be "name@mapset in mapset" */
  12. char fullname[GNAME_MAX + 2 * GMAPSET_MAX + 4];
  13. PS.do_colortable = 0;
  14. if (PS.cell_fd >= 0) {
  15. Rast_close(PS.cell_fd);
  16. G_free(PS.cell_name);
  17. Rast_free_colors(&PS.colors);
  18. PS.cell_fd = -1;
  19. }
  20. sprintf(fullname, "%s in %s", name, mapset);
  21. if (Rast_read_colors(name, mapset, &PS.colors) == -1) {
  22. error(fullname, "", "can't read color table");
  23. return 0;
  24. }
  25. Rast_get_c_color_range(&PS.min_color, &PS.max_color, &PS.colors);
  26. /* open raster map for reading */
  27. PS.cell_fd = Rast_open_old(name, mapset);
  28. strcpy(PS.celltitle, Rast_get_cell_title(name, mapset));
  29. G_strip(PS.celltitle);
  30. if (PS.celltitle[0] == 0)
  31. sprintf(PS.celltitle, "(%s)", name);
  32. PS.cell_name = G_store(name);
  33. PS.cell_mapset = G_store(mapset);
  34. PS.do_raster = 1;
  35. return 1;
  36. }