get_ell_name.c

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

Generated on Wed Aug 23 17:49:22 2006 for GRASS by  doxygen 1.4.7