17 * -I isea standard orientation
18 * -D dymaxion orientation
23 * -t h t d hex tri diamond
26 * -O q2dd seqnum interleave plane q2dd projtri vertex2dd
32 * -b bin point values (average)
33 * -e bin point presence
34 * -G spacing resolution generate graticule
38 fprintf(stderr, "%s", "isea [-l <lon>] [-z <azimuth>] [-p <latitude>] [-I] [-D] [-P] [-a <aperture>] [-r <resolution>] [-t <topology>] [-A <addressing>] [-g] [-b] [-e] [-x]\n");
42 fprintf(stderr, "%s\n", s);
46 static int verbose = 0;
47 static int precision = 10;
49 void options(int ac, char **av, struct isea_dgg *g) {
54 if (av[i][0] != '-') {
61 isea_orient_isea(g); break;
63 isea_orient_pole(g); break;
65 isea_orient_dymax(g); break;
67 g->radius = strtod(av[++i],NULL); break;
69 g->o_lon = strtod(av[++i],NULL) * M_PI / 180.0; break;
71 g->o_lat = strtod(av[++i],NULL) * M_PI / 180.0; break;
73 g->o_az = strtod(av[++i],NULL) * M_PI / 180.0; break;
75 precision = atoi(av[++i]); break;
77 g->aperture = atoi(av[++i]); break;
79 g->resolution = atoi(av[++i]); break;
83 g->topology = ISEA_HEXAGON;
86 g->topology = ISEA_TRIANGLE;
89 g->topology = ISEA_DIAMOND;
93 die("Invalid topology");
103 if (!strcmp(optarg, "projtri")) {
104 g->output = ISEA_PROJTRI;
106 else if (!strcmp(optarg, "vertex2dd")) {
107 g->output = ISEA_VERTEX2DD;
109 else if (!strcmp(optarg, "q2dd")) {
110 g->output = ISEA_Q2DD;
112 else if (!strcmp(optarg, "q2di")) {
113 g->output = ISEA_Q2DI;
115 else if (!strcmp(optarg, "seqnum")) {
116 g->output = ISEA_SEQNUM;
118 else if (!strcmp(optarg, "plane")) {
119 g->output = ISEA_PLANE;
121 fprintf(stderr, "unknown output format: %s\n",optarg);
127 die("Unknown option");
133 main(int ac, char *av[])
137 struct isea_pt out, coord;
145 isea_grid_init(&dgg);
146 dgg.output = ISEA_PLANE;
147 dgg.radius = ISEA_SCALE; /* 0.8301572857837594396028083; */
149 options(ac, av, &dgg);
152 fprintf(stderr, "isea lat = %lf, lon = %lf, az = %lf, output = %s\n",
153 dgg.o_lat * 180.0 / M_PI, dgg.o_lon * 180.0 / M_PI,
154 dgg.o_az * 180.0 / M_PI, dgg.output == ISEA_PLANE ? "plane" : "not plane");
157 while (fgets(line, sizeof line, stdin)) {
158 line[sizeof line-1] = 0;
159 if (line[0] == '#') {
162 if (!strncmp(line, "ENDPOLY", 7)) {
166 in.lon = strtod(line, &rest);
167 in.lat = strtod(rest, &rest);
169 nl = strchr(rest, '\n');
172 in.lon *= M_PI / 180.0;
173 in.lat *= M_PI / 180.0;
175 out = isea_forward(&dgg, &in);
177 quad = ((tri - 1) % 5) + ((tri - 1) / 10) * 5 + 1;
180 if (dgg.output == ISEA_PLANE) {
181 calctri = isea_xy_triangle(&coord,
182 dgg.output == ISEA_PLANE ? dgg.radius : 1.0);
184 if (tri != calctri) {
186 "got %d (%f, %f), expected %d\n",
187 calctri, out.x, out.y, tri);
192 in.lon *= 180.0 / M_PI;
193 in.lat *= 180.0 / M_PI;
195 switch (dgg.output) {
197 printf("%.*f %.*f%s\n", precision, out.x, precision, out.y, rest);
200 printf("%d %.*f %.*f%s\n", tri-1, precision, out.x,
201 precision, out.y, rest);
204 printf("%d %d %.*f %.*f%s\n", quad, tri-1, precision,
205 out.x, precision, out.y, rest);
208 /* Same as above, we just don't print as much */
209 printf("%d %.*f %.*f%s\n", quad, precision,
210 out.x, precision, out.y, rest);
213 printf("%d %.0lf %.0lf%s\n", dgg.quad, coord.x, coord.y, rest);
216 quad = isea_ptdi(&dgg, tri, &out, &coord);
217 printf("%d%s\n", isea_disn(&dgg, quad, &coord), rest);