get_cellhd.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *  G_get_cellhd (name, mapset, cellhd)
00004  *      char *name                   name of map
00005  *      char *mapset                 mapset that map belongs to
00006  *      struct Cell_head *cellhd    structure to hold cell header info
00007  *
00008  *  Reads the cell file header information associated with map layer "map"
00009  *  in mapset "mapset" into the structure "cellhd".
00010  *
00011  *  returns:     0  if successful
00012  *              -1  on fail
00013  *
00014  *  note:   a warning message for errors encountered.
00015  *
00016  *       Cell header files may contain either grid cell header 
00017  *       information or reclass information.   If it is a reclass
00018  *       file, it will specify the map and mapset names of the actual
00019  *       grid cell file being reclassed.  G_get_cellhd(), upon 
00020  *       reading reclass information will go read the cell header
00021  *       information for the referenced file.  Only one reference is 
00022  *       allowed.
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     is_reclass = G_is_reclass (name, mapset, real_name, real_mapset);
00058     if (is_reclass < 0)
00059     {
00060         sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
00061         tail = buf + strlen(buf);
00062         strcpy (tail, "It is a reclass file, but with an invalid format");
00063         G_warning(buf);
00064         return -1;
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 }

Generated on Fri Nov 21 11:02:18 2008 for GRASS by  doxygen 1.5.1