get_window.c

Go to the documentation of this file.
00001 /*
00002  *************************************************************************
00003  * G_get_window (window)
00004  *     struct Cell_head *window
00005  *
00006  *      read the current mapset window
00007  *      dies if error
00008  *
00009  *************************************************************************
00010  * G_get_default_window (window)
00011  *     struct Cell_head *window
00012  *
00013  *      read the default window for the location
00014  *      dies if error
00015  *
00016  *************************************************************************
00017  * char *
00018  * G__get_window (window, element, name, mapset)
00019  *      read the window 'name' in 'element' in 'mapset'
00020  *      returns NULL if ok, error message if not
00021  ************************************************************************/
00022 
00023 #include <stdlib.h>
00024 #include "G.h"
00025 #include "gis.h"
00026 #include "glocale.h"
00027 
00028 
00047 int G_get_window (struct Cell_head *window )
00048 {
00049     static int first = 1;
00050     static struct Cell_head dbwindow ;
00051 
00052     if (first)
00053     {
00054         char *err;
00055 
00056         if(err = G__get_window (&dbwindow,"","WIND",G_mapset()))
00057         {
00058             G_fatal_error (_("region for current mapset %s\nrun \"g.region\""), err);
00059             G_free (err);
00060         }
00061     }
00062 
00063     first = 0;
00064     G_copy ((char *) window, (char *) &dbwindow, sizeof(dbwindow) ) ;
00065 
00066     if (!G__.window_set)
00067     {
00068         G__.window_set = 1;
00069         G_copy((char *) &G__.window, (char *) &dbwindow, sizeof(dbwindow) ) ;
00070     }
00071 
00072     return 1;
00073 }
00074 
00075 
00088 int G_get_default_window ( struct Cell_head *window )
00089 {
00090     char *err;
00091 
00092     if ((err = G__get_window (window,"","DEFAULT_WIND","PERMANENT")))
00093     {
00094         G_fatal_error (_("default region %s"), err);
00095         G_free (err);
00096     }
00097     return 1;
00098 }
00099 
00100 char *G__get_window ( struct Cell_head *window,
00101        char *element, char *name, char *mapset)
00102 {
00103     FILE *fd ;
00104     char *err;
00105     char *G__read_Cell_head();
00106 
00107     G_zero ((char *) window, sizeof (struct Cell_head));
00108     if (!(fd = G_fopen_old (element, name, mapset) ))
00109     {
00110 /*
00111 char path[1024];
00112 G__file_name (path,element,name,mapset);
00113 fprintf (stderr, "G__get_window(%s)\n",path);
00114 */
00115         return G_store (_("is not set"));
00116     }
00117 
00118     err = G__read_Cell_head(fd, window, 0);
00119     fclose (fd);
00120 
00121     if (err)
00122     {
00123         char msg[1024];
00124 
00125         sprintf (msg, _("is invalid\n%s"), err);
00126         G_free (err);
00127         return G_store (msg);
00128     }
00129 
00130     return NULL;
00131 }

Generated on Sat Jul 22 22:06:14 2006 for GRASS by  doxygen 1.4.7