GRASS Programmer's Manual
6.4.2(2012)
|
00001 /* 00002 **************************************************************************** 00003 * 00004 * MODULE: GRASS 5 gis library, get_ell_name.c 00005 * AUTHOR(S): unknown, updated by Andreas Lange, andreas.lange@rhein-main.de 00006 * PURPOSE: Get ellipse name from user 00007 * COPYRIGHT: (C) 2000 by the GRASS Development Team 00008 * 00009 * This program is free software under the GNU General Public 00010 * License (>=v2). Read the file COPYING that comes with GRASS 00011 * for details. 00012 * 00013 *****************************************************************************/ 00014 00015 #include <string.h> 00016 #include <unistd.h> 00017 #include <stdlib.h> 00018 #include <grass/gis.h> 00019 #include <grass/glocale.h> 00020 00021 int G_ask_ellipse_name(char *spheroid) 00022 { 00023 char buff[1024], answer[50]; 00024 double aa, e2; 00025 char *sph, *Tmp_file; 00026 FILE *Tmp_fd = NULL; 00027 int i; 00028 00029 Tmp_file = G_tempfile(); 00030 if (NULL == (Tmp_fd = fopen(Tmp_file, "w"))) { 00031 G_fatal_error(_("Cannot open temp file")); 00032 } 00033 fprintf(Tmp_fd, "sphere\n"); 00034 for (i = 0; (sph = G_ellipsoid_name(i)); i++) { 00035 fprintf(Tmp_fd, "%s\n", sph); 00036 } 00037 00038 fclose(Tmp_fd); 00039 00040 for (;;) { 00041 do { 00042 fprintf(stderr, _("\nPlease specify ellipsoid name\n")); 00043 fprintf(stderr, 00044 _("Enter 'list' for the list of available ellipsoids\n")); 00045 fprintf(stderr, _("Hit RETURN to cancel request\n")); 00046 fprintf(stderr, ">"); 00047 } while (!G_gets(answer)); 00048 G_strip(answer); 00049 if (strlen(answer) == 0) 00050 return -1; 00051 if (strcmp(answer, "list") == 0) { 00052 char *pager; 00053 00054 pager = getenv("GRASS_PAGER"); 00055 if (!pager || strlen(pager) == 0) 00056 pager = "cat"; 00057 00058 /* Always print interactive output to stderr */ 00059 sprintf(buff, "%s \"%s\" 1>&2", pager, 00060 G_convert_dirseps_to_host(Tmp_file)); 00061 G_system(buff); 00062 } 00063 else { 00064 if (strcmp(answer, "sphere") == 0) 00065 break; 00066 if (G_get_ellipsoid_by_name(answer, &aa, &e2) == 0) { 00067 fprintf(stderr, _("\ninvalid ellipsoid\n")); 00068 } 00069 else 00070 break; 00071 } 00072 } 00073 sprintf(spheroid, "%s", answer); 00074 remove(Tmp_file); 00075 if (strcmp(spheroid, "sphere") == 0) { 00076 return 2; 00077 } 00078 return 1; 00079 }