GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mke_loc.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <grass/gis.h>
7 #include "local_proto.h"
8 
9 int make_location(const char *gisdbase, const char *location_name)
10 {
11  struct Cell_head window;
12  char buf[GPATH_MAX];
13  int i;
14  char myname[75];
15  char *mapset;
16  char *name, c;
17  FILE *fp;
18 
20  fprintf(stderr,
21  "To create a new LOCATION, you will need the following information:\n");
22  fprintf(stderr, "\n");
23  fprintf(stderr, "1. The coordinate system for the database\n");
24  /*for (i = 1; name = G__projection_name(i); i++) */
25  fprintf(stderr, " %s (for imagery and other unreferenced data)\n",
26  G__projection_name(PROJECTION_XY));
27  fprintf(stderr, " %s\n", G__projection_name(PROJECTION_LL));
28  fprintf(stderr, " %s\n", G__projection_name(PROJECTION_UTM));
29  fprintf(stderr, " %s\n", G__projection_name(PROJECTION_OTHER));
30  fprintf(stderr, "2. The zone for the %s database\n",
31  G__projection_name(PROJECTION_UTM));
32  fprintf(stderr,
33  " and all the necessary parameters for projections other than\n");
34  fprintf(stderr, " %s, %s, and %s\n", G__projection_name(PROJECTION_LL),
35  G__projection_name(PROJECTION_XY),
36  G__projection_name(PROJECTION_UTM));
37  fprintf(stderr,
38  "3. The coordinates of the area to become the default region\n");
39  fprintf(stderr, " and the grid resolution of this region\n");
40  fprintf(stderr,
41  "4. A short, one-line description or title for the location\n");
42  fprintf(stderr, "\n");
43 
44  if (!G_yes("Do you have all this information? ", 1))
45  return 0;
46 
47  G_zero(&window, sizeof(window));
48  while (1) {
50  fprintf(stderr,
51  "Please specify the coordinate system for location <%s>\n\n",
52  location_name);
53  fprintf(stderr, "A %s\n", G__projection_name(PROJECTION_XY));
54  fprintf(stderr, "B %s\n", G__projection_name(PROJECTION_LL));
55  fprintf(stderr, "C %s\n", G__projection_name(PROJECTION_UTM));
56  fprintf(stderr, "D %s\n", G__projection_name(PROJECTION_OTHER));
57  fprintf(stderr, "RETURN to cancel\n");
58  fprintf(stderr, "\n");
59  fprintf(stderr, "> ");
60  if (!G_gets(buf))
61  continue;
62  G_strip(buf);
63  if (*buf == 0)
64  return 0;
65  if (sscanf(buf, "%c", &c) != 1)
66  continue;
67  switch (c) {
68  case 'A':
69  i = PROJECTION_XY;
70  break;
71  case 'a':
72  i = PROJECTION_XY;
73  break;
74  case 'B':
75  i = PROJECTION_LL;
76  break;
77  case 'b':
78  i = PROJECTION_LL;
79  break;
80  case 'C':
81  i = PROJECTION_UTM;
82  break;
83  case 'c':
84  i = PROJECTION_UTM;
85  break;
86  case 'D':
87  i = PROJECTION_OTHER;
88  break;
89  case 'd':
90  i = PROJECTION_OTHER;
91  break;
92  default:
93  continue;
94  }
95  name = G__projection_name(i);
96  if (name == NULL)
97  continue;
98  fprintf(stderr, "\n");
99  sprintf(buf, "\n%s coordinate system? ", name);
100  if (G_yes(buf, 1))
101  break;
102  }
103  window.proj = i;
104  /*
105  while (window.proj == PROJECTION_UTM)
106  {
107  fprintf (stderr, " ("Please specify the %s zone for location <%s>\n",
108  G__projection_name(window.proj), location_name);
109  fprintf (stderr, " ("or RETURN to cancel\n");
110  fprintf (stderr, " ("\n");
111  fprintf (stderr, " ("> ");
112  if (!G_gets(buf))
113  continue;
114  G_strip (buf);
115  if (*buf == 0) return 0;
116  if (sscanf (buf, "%d", &i) != 1)
117  continue;
118  if (i > 0 && i <= 60)
119  {
120  fprintf(stderr, "zone %d is illegal"\n);
121  fprintf (stderr, " ("\n");
122  sprintf (buf, "zone %d? ", i);
123  if (G_yes (buf, 1))
124  {
125  window.zone = i;
126  break;
127  }
128  }
129  */
130 
131  while (1) {
132  G_clear_screen();
133  fprintf(stderr,
134  "Please enter a one line description for location <%s>\n\n",
135  location_name);
136  fprintf(stderr, "> ");
137  if (!G_gets(buf))
138  continue;
139  G_squeeze(buf);
140  buf[sizeof(myname)] = 0;
141  G_squeeze(buf);
142  fprintf(stderr,
143  "=====================================================\n");
144  fprintf(stderr, "%s\n", buf);
145  fprintf(stderr,
146  "=====================================================\n");
147  if (G_yes("ok? ", *buf != 0))
148  break;
149  }
150  strcpy(myname, buf);
151  /*
152  if(G_edit_cellhd(&window, -1) < 0)
153  return 0;
154  */
155 
156  mapset = "PERMANENT";
157  G__setenv("MAPSET", mapset);
158  G__setenv("LOCATION_NAME", location_name);
159 
160  sprintf(buf, "%s/%s", gisdbase, location_name);
161  if (G_mkdir(buf) < 0)
162  return 0;
163  sprintf(buf, "%s/%s/%s", gisdbase, location_name, mapset);
164  if (G_mkdir(buf) < 0)
165  return 0;
166  /* set the dummy window */
167  window.north = 1.;
168  window.south = 0.;
169  window.top = 1.;
170  window.bottom = 0.;
171  window.rows = 1;
172  window.rows3 = 1;
173  window.cols = 1;
174  window.cols3 = 1;
175  window.depths = 1;
176  window.ew_res = 1.;
177  window.ew_res3 = 1.;
178  window.ns_res = 1.;
179  window.ns_res3 = 1.;
180  window.tb_res = 1.;
181  window.east = 1.;
182  window.west = 0.;
183  window.zone = 0.;
184  /* make a dummy default window for location */
185  /* later after calling g.setrpj we will let user create a real default window */
186  G__put_window(&window, "", "DEFAULT_WIND");
187  G__put_window(&window, "", "WIND");
188 
189  sprintf(buf, "%s/%s/%s/MYNAME", gisdbase, location_name, mapset);
190  fp = fopen(buf, "w");
191  fputs(myname, fp);
192  fclose(fp);
193 
194  return 1;
195 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_mkdir(const char *path)
Creates a new directory.
Definition: paths.c:17
int G_gets(char *buf)
Definition: gets.c:39
string name
Definition: render.py:1314
int G_yes(const char *question, int dflt)
Ask a yes/no question.
Definition: yes.c:39
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:29
int G_clear_screen(void)
Definition: clear_scrn.c:12
int G_strip(char *buf)
Removes all leading and trailing white space from string.
Definition: strings.c:389
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
int G__setenv(const char *name, const char *value)
Set environment name to value.
Definition: env.c:388
fclose(fd)
int G__put_window(const struct Cell_head *window, char *dir, char *name)
Definition: put_window.c:40
char * G__projection_name(int n)
Definition: proj2.c:36
char * G_squeeze(char *line)
Remove superfluous white space.
Definition: squeeze.c:45
int make_location(const char *, const char *)
Definition: mke_loc.c:9