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,
00055 _("Enter 'list' for the list of available datums\n"));
00056 fprintf(stderr,
00057 _("or 'custom' if you wish to enter custom parameters\n"));
00058 fprintf(stderr, _("Hit RETURN to cancel request\n"));
00059 fprintf(stderr, ">");
00060 } while (!G_gets(answer));
00061 G_strip(answer);
00062
00063 if (strlen(answer) == 0)
00064 return -1;
00065
00066 if (strcmp(answer, "list") == 0) {
00067 Tmp_file = G_tempfile();
00068 if (NULL == (Tmp_fd = fopen(Tmp_file, "w")))
00069 G_warning(_("Cannot open temp file"));
00070 else {
00071 char *pager;
00072
00073 fprintf(Tmp_fd, "Short Name\tLong Name / Description\n---\n");
00074 for (i = 0; (dat = G_datum_name(i)); i++) {
00075 fprintf(Tmp_fd, "%s\t%s\n\t\t\t(%s ellipsoid)\n---\n",
00076 dat, G_datum_description(i),
00077 G_datum_ellipsoid(i));
00078 }
00079 fclose(Tmp_fd);
00080
00081 pager = getenv("GRASS_PAGER");
00082 if (!pager || strlen(pager) == 0)
00083 pager = "cat";
00084 sprintf(buff, "%s \"%s\" 1>&2", pager,
00085 G_convert_dirseps_to_host(Tmp_file));
00086 G_system(buff);
00087
00088 remove(Tmp_file);
00089 }
00090 G_free(Tmp_file);
00091 }
00092 else {
00093 if (G_strcasecmp(answer, "custom") == 0)
00094 break;
00095
00096 if (G_get_datum_by_name(answer) < 0) {
00097 fprintf(stderr, _("\ninvalid datum\n"));
00098 }
00099 else
00100 break;
00101 }
00102 }
00103
00104
00105 if (G_strcasecmp(answer, "custom") == 0) {
00106
00107 if (G_ask_ellipse_name(ellipse) < 0)
00108 return -1;
00109 sprintf(ellpsname, ellipse);
00110 sprintf(datumname, "custom");
00111 }
00112 else {
00113
00114 if ((i = G_get_datum_by_name(answer)) < 0)
00115 return -1;
00116 sprintf(ellpsname, G_datum_ellipsoid(i));
00117 sprintf(datumname, G_datum_name(i));
00118 }
00119
00120 return 1;
00121
00122 }