GRASS Programmer's Manual 6.4.1(2011)
|
00001 00014 #include <string.h> 00015 #include <stdlib.h> 00016 #include <grass/gis.h> 00017 #include <grass/glocale.h> 00018 00045 int G_get_cellhd(const char *name, const char *mapset, 00046 struct Cell_head *cellhd) 00047 { 00048 FILE *fd; 00049 int is_reclass; 00050 char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX]; 00051 char buf[1024]; 00052 char *tail; 00053 char *err; 00054 00055 /* 00056 is_reclass = G_is_reclass (name, mapset, real_name, real_mapset); 00057 if (is_reclass < 0) 00058 { 00059 sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset); 00060 tail = buf + strlen(buf); 00061 strcpy (tail, "It is a reclass file, but with an invalid format"); 00062 G_warning(buf); 00063 return -1; 00064 } 00065 */ 00066 is_reclass = (G_is_reclass(name, mapset, real_name, real_mapset) > 0); 00067 if (is_reclass) { 00068 fd = G_fopen_old("cellhd", real_name, real_mapset); 00069 if (fd == NULL) { 00070 sprintf(buf, 00071 _("Unable to read header file for raster map <%s@%s>."), 00072 name, mapset); 00073 tail = buf + strlen(buf); 00074 sprintf(tail, _(" It is a reclass of raster map <%s@%s> "), 00075 real_name, real_mapset); 00076 tail = buf + strlen(buf); 00077 if (!G_find_cell(real_name, real_mapset)) 00078 sprintf(tail, _("which is missing.")); 00079 else 00080 sprintf(tail, _("whose header file can't be opened.")); 00081 G_warning(buf); 00082 return -1; 00083 } 00084 } 00085 else { 00086 fd = G_fopen_old("cellhd", name, mapset); 00087 if (fd == NULL) { 00088 G_warning(_("Unable to open header file for raster map <%s@%s>"), 00089 name, mapset); 00090 return -1; 00091 } 00092 } 00093 00094 err = G__read_Cell_head(fd, cellhd, 1); 00095 fclose(fd); 00096 00097 if (err == NULL) 00098 return 0; 00099 00100 sprintf(buf, _("Unable to read header file for raster map <%s@%s>."), 00101 name, mapset); 00102 tail = buf + strlen(buf); 00103 if (is_reclass) { 00104 sprintf(tail, 00105 _(" It is a reclass of raster map <%s@%s> whose header file is invalid."), 00106 real_name, real_mapset); 00107 } 00108 else 00109 sprintf(tail, _(" Invalid format.")); 00110 tail = buf + strlen(buf); 00111 strcpy(tail, err); 00112 00113 G_free(err); 00114 00115 G_warning(buf); 00116 return -1; 00117 }