GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_gets(char *buf)
Definition: gets.c:39
char * G_convert_dirseps_to_host(char *path)
Converts directory separator characters in a string to the native host separator character (/ on Unix...
Definition: paths.c:73
char * G_tempfile(void)
Returns a temporary file name.
Definition: tempfile.c:47
char * getenv()
char buff[1024]
Definition: g3dcats.c:89
int G_strip(char *buf)
Removes all leading and trailing white space from string.
Definition: strings.c:389
int G_ask_ellipse_name(char *spheroid)
Definition: get_ell_name.c:21
char * G_ellipsoid_name(int n)
get ellipsoid name
Definition: get_ellipse.c:138
int G_get_ellipsoid_by_name(const char *name, double *a, double *e2)
get ellipsoid parameters by name
Definition: get_ellipse.c:110
return NULL
Definition: dbfopen.c:1394
fclose(fd)
int G_system(const char *command)
Run a shell level command.
Definition: system.c:51
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.