00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <string.h>
00017 #include <unistd.h>
00018 #include <stdlib.h>
00019 #include <grass/gis.h>
00020 #include <grass/glocale.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00043 int G_ask_datum_name(char *datumname, char *ellpsname)
00044 {
00045 char buff[1024],answer[100], ellipse[100];
00046 char *dat, *Tmp_file;
00047 FILE *Tmp_fd = NULL;
00048 int i;
00049
00050
00051 for(;;) {
00052 do {
00053 fprintf(stderr,_("\nPlease specify datum name\n"));
00054 fprintf(stderr,_("Enter 'list' for the list of available datums\n"));
00055 fprintf(stderr,("or 'custom' if you wish to enter custom parameters\n"));
00056 fprintf (stderr, _("Hit RETURN to cancel request\n"));
00057 fprintf(stderr,">");
00058 } while(!G_gets(answer));
00059 G_strip(answer);
00060
00061 if(strlen(answer)==0)
00062 return -1;
00063
00064 if (strcmp(answer,"list") == 0) {
00065 Tmp_file = G_tempfile ();
00066 if (NULL == (Tmp_fd = fopen (Tmp_file, "w")))
00067 G_warning(_("Cannot open temp file") );
00068 else
00069 {
00070 fprintf(Tmp_fd,"Short Name\tLong Name / Description\n---\n");
00071 for (i=0; (dat = G_datum_name(i)); i++) {
00072 fprintf(Tmp_fd,"%s\t%s\n\t\t\t(%s ellipsoid)\n---\n",
00073 dat, G_datum_description(i), G_datum_ellipsoid(i));
00074 }
00075 fclose(Tmp_fd);
00076 if (isatty(1)) {
00077 sprintf(buff,"$GRASS_PAGER %s",Tmp_file);
00078 }
00079 else
00080 sprintf(buff,"cat %s",Tmp_file);
00081 G_system(buff);
00082
00083 remove ( Tmp_file );
00084 }
00085 G_free ( Tmp_file );
00086 }
00087 else {
00088 if (G_strcasecmp(answer,"custom") == 0) break;
00089
00090 if (G_get_datum_by_name(answer) < 0) {
00091 fprintf(stderr,_("\ninvalid datum\n"));
00092 }
00093 else break;
00094 }
00095 }
00096
00097
00098 if (G_strcasecmp(answer,"custom") == 0)
00099 {
00100
00101 if(G_ask_ellipse_name(ellipse) < 0)
00102 return -1;
00103 sprintf(ellpsname, ellipse);
00104 sprintf(datumname, "custom");
00105 }
00106 else
00107 {
00108
00109 if((i = G_get_datum_by_name(answer)) < 0)
00110 return -1;
00111 sprintf(ellpsname, G_datum_ellipsoid(i));
00112 sprintf(datumname, G_datum_name(i));
00113 }
00114
00115 return 1;
00116
00117 }
00118