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