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 "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     is_reclass = G_is_reclass (name, mapset, real_name, real_mapset);
00060     if (is_reclass < 0)
00061     {
00062         sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
00063         tail = buf + strlen(buf);
00064         strcpy (tail, "It is a reclass file, but with an invalid format");
00065         G_warning(buf);
00066         return -1;
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 }

Generated on Mon Jan 1 19:49:25 2007 for GRASS by  doxygen 1.5.1