get_cellhd.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. \file raster/get_cellhd.c
  3. \brief Raster library - Read raster map header
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <grass/gis.h>
  12. #include <grass/raster.h>
  13. #include <grass/glocale.h>
  14. /*!
  15. \brief Read the raster header
  16. The raster header for the raster map <i>name</i> in the specified
  17. <i>mapset</i> is read into the <i>cellhd</i> structure. If there is
  18. an error reading the raster header file, a diagnostic message is
  19. printed and -1 is returned. Otherwise, 0 is returned.
  20. <b>Note</b>:a warning message for errors encountered.
  21. Cell header files may contain either grid cell header information or
  22. reclass information. If it is a reclass file, it will specify the
  23. map and mapset names of the actual grid cell file being
  24. reclassed. Rast_get_cellhd(), upon reading reclass information will go
  25. read the cell header information for the referenced file. Only one
  26. reference is allowed.
  27. \param name name of map
  28. \param mapset mapset that map belongs to
  29. \param[out] cellhd structure to hold cell header info
  30. \return void
  31. */
  32. void Rast_get_cellhd(const char *name, const char *mapset,
  33. struct Cell_head *cellhd)
  34. {
  35. FILE *fp;
  36. int is_reclass;
  37. char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX];
  38. /*
  39. is_reclass = Rast_is_reclass (name, mapset, real_name, real_mapset);
  40. if (is_reclass < 0)
  41. {
  42. sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
  43. tail = buf + strlen(buf);
  44. strcpy (tail, "It is a reclass file, but with an invalid format");
  45. G_warning(buf);
  46. return -1;
  47. }
  48. */
  49. is_reclass = (Rast_is_reclass(name, mapset, real_name, real_mapset) > 0);
  50. if (is_reclass) {
  51. fp = G_fopen_old("cellhd", real_name, real_mapset);
  52. if (!fp)
  53. G_fatal_error(_("Unable to read header file for raster map <%s@%s>."
  54. "It is a reclass of raster map <%s@%s> %s"),
  55. name, mapset, real_name, real_mapset,
  56. !G_find_raster(real_name, real_mapset)
  57. ? _("which is missing.")
  58. : _("whose header file can't be opened."));
  59. }
  60. else {
  61. fp = G_fopen_old("cellhd", name, mapset);
  62. if (!fp)
  63. G_fatal_error(_("Unable to open header file for raster map <%s@%s>"),
  64. name, mapset);
  65. }
  66. G__read_Cell_head(fp, cellhd, 1);
  67. fclose(fp);
  68. }