GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
get_ell_name.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: GRASS 5 gis library, get_ell_name.c
5  * AUTHOR(S): unknown, updated by Andreas Lange, andreas.lange@rhein-main.de
6  * PURPOSE: Get ellipse name from user
7  * COPYRIGHT: (C) 2000 by the GRASS Development Team
8  *
9  * This program is free software under the GNU General Public
10  * License (>=v2). Read the file COPYING that comes with GRASS
11  * for details.
12  *
13  *****************************************************************************/
14 
15 #include <string.h>
16 #include <unistd.h>
17 #include <stdlib.h>
18 #include <grass/gis.h>
19 #include <grass/glocale.h>
20 
21 int G_ask_ellipse_name(char *spheroid)
22 {
23  char buff[1024], answer[50];
24  double aa, e2;
25  char *sph, *Tmp_file;
26  FILE *Tmp_fd = NULL;
27  int i;
28 
29  Tmp_file = G_tempfile();
30  if (NULL == (Tmp_fd = fopen(Tmp_file, "w"))) {
31  G_fatal_error(_("Cannot open temp file"));
32  }
33  fprintf(Tmp_fd, "sphere\n");
34  for (i = 0; (sph = G_ellipsoid_name(i)); i++) {
35  fprintf(Tmp_fd, "%s\n", sph);
36  }
37 
38  fclose(Tmp_fd);
39 
40  for (;;) {
41  do {
42  fprintf(stderr, _("\nPlease specify ellipsoid name\n"));
43  fprintf(stderr,
44  _("Enter 'list' for the list of available ellipsoids\n"));
45  fprintf(stderr, _("Hit RETURN to cancel request\n"));
46  fprintf(stderr, ">");
47  } while (!G_gets(answer));
48  G_strip(answer);
49  if (strlen(answer) == 0)
50  return -1;
51  if (strcmp(answer, "list") == 0) {
52  char *pager;
53 
54  pager = getenv("GRASS_PAGER");
55  if (!pager || strlen(pager) == 0)
56  pager = "cat";
57 
58  /* Always print interactive output to stderr */
59  sprintf(buff, "%s \"%s\" 1>&2", pager,
60  G_convert_dirseps_to_host(Tmp_file));
61  G_system(buff);
62  }
63  else {
64  if (strcmp(answer, "sphere") == 0)
65  break;
66  if (G_get_ellipsoid_by_name(answer, &aa, &e2) == 0) {
67  fprintf(stderr, _("\ninvalid ellipsoid\n"));
68  }
69  else
70  break;
71  }
72  }
73  sprintf(spheroid, "%s", answer);
74  remove(Tmp_file);
75  if (strcmp(spheroid, "sphere") == 0) {
76  return 2;
77  }
78  return 1;
79 }