00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string.h>
00026 #include <stdlib.h>
00027 #include <grass/gis.h>
00028 #include <grass/glocale.h>
00029
00030
00046 int G_get_cellhd (char *name, char *mapset, struct Cell_head *cellhd)
00047
00048 {
00049 FILE *fd;
00050 int is_reclass;
00051 char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX];
00052 char buf[1024];
00053 char *tail;
00054 char *err, *G__read_Cell_head();
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 is_reclass = (G_is_reclass (name, mapset, real_name, real_mapset) > 0);
00068 if (is_reclass)
00069 {
00070 fd = G_fopen_old ("cellhd", real_name, real_mapset);
00071 if (fd == NULL)
00072 {
00073 sprintf (buf,_("Can't read header file for [%s in %s]\n"), name, mapset);
00074 tail = buf + strlen(buf);
00075 sprintf (tail, _("It is a reclass of [%s in %s] "), 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 {
00087 fd = G_fopen_old ("cellhd", name, mapset);
00088 if (fd == NULL)
00089 {
00090 sprintf (buf, _("Can't open header file for [%s in %s]"), name, mapset);
00091 G_warning (buf);
00092 return -1;
00093 }
00094 }
00095
00096 err = G__read_Cell_head (fd, cellhd, 1);
00097 fclose (fd);
00098
00099 if (err == NULL)
00100 return 0;
00101
00102 sprintf (buf, _("Can't read header file for [%s in %s]\n"), name, mapset);
00103 tail = buf + strlen(buf);
00104 if (is_reclass)
00105 {
00106 sprintf (tail, _("It is a reclass of [%s in %s] whose header file is invalid\n"),
00107 real_name, real_mapset);
00108 }
00109 else
00110 sprintf (tail, _("Invalid format\n"));
00111 tail = buf + strlen(buf);
00112 strcpy (tail, err);
00113 G_free (err);
00114 G_warning (buf);
00115 return -1;
00116 }