9 * -I isea standard orientation
10 * -D dymaxion orientation
15 * -t h t d hex tri diamond
18 * -O q2dd seqnum interleave plane q2dd projtri vertex2dd
24 * -b bin point values (average)
25 * -e bin point presence
26 * -G spacing resolution generate graticule
31 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");
35 fprintf(stderr, "%s\n", s);
39 static int verbose = 0;
40 static int precision = 10;
42 void options(int ac, char **av, struct isea_dgg *g) {
47 if (av[i][0] != '-') {
54 isea_orient_isea(g); break;
56 isea_orient_pole(g); break;
58 isea_orient_dymax(g); break;
60 g->radius = strtod(av[++i],NULL); break;
62 g->o_lon = strtod(av[++i],NULL); break;
64 g->o_lat = strtod(av[++i],NULL); break;
66 g->o_az = strtod(av[++i],NULL); break;
68 precision = atoi(av[++i]); break;
70 g->aperture = atoi(av[++i]); break;
72 g->resolution = atoi(av[++i]); break;
76 g->topology = ISEA_HEXAGON;
79 g->topology = ISEA_TRIANGLE;
82 g->topology = ISEA_DIAMOND;
86 die("Invalid topology");
96 if (!strcmp(optarg, "projtri")) {
97 g->output = ISEA_PROJTRI;
99 else if (!strcmp(optarg, "vertex2dd")) {
100 g->output = ISEA_VERTEX2DD;
102 else if (!strcmp(optarg, "q2dd")) {
103 g->output = ISEA_Q2DD;
105 else if (!strcmp(optarg, "q2di")) {
106 g->output = ISEA_Q2DI;
108 else if (!strcmp(optarg, "seqnum")) {
109 g->output = ISEA_SEQNUM;
111 else if (!strcmp(optarg, "plane")) {
112 g->output = ISEA_PLANE;
114 fprintf(stderr, "unknown output format: %s\n",optarg);
120 die("Unknown option");
127 #define PROJ_PARMS__ \
131 #include <projects.h>
133 PROJ_HEAD(isea, "Icosahedral Snyder Equal Area") "\n\tSph";
142 out = isea_forward(&P->dgg, &in);
149 FREEUP; if (P) pj_dalloc(P); }
155 isea_grid_init(&P->dgg);
157 P->dgg.output = ISEA_PLANE;
158 /* P->dgg.radius = P->a; /* otherwise defaults to 1 */
159 /* calling library will scale, I think */
161 opt = pj_param(P->params, "sorient").s;
163 if (!strcmp(opt, "isea")) {
164 isea_orient_isea(&P->dgg);
165 } else if (!strcmp(opt, "pole")) {
166 isea_orient_pole(&P->dgg);
172 if (pj_param(P->params, "tazi").i) {
173 P->dgg.o_az = pj_param(P->params, "razi").f;
176 if (pj_param(P->params, "tlon_0").i) {
177 P->dgg.o_lon = pj_param(P->params, "rlon_0").f;
180 if (pj_param(P->params, "tlat_0").i) {
181 P->dgg.o_lat = pj_param(P->params, "rlat_0").f;
184 if (pj_param(P->params, "taperture").i) {
185 P->dgg.aperture = pj_param(P->params, "iaperture").i;
188 if (pj_param(P->params, "tresolution").i) {
189 P->dgg.resolution = pj_param(P->params, "iresolution").i;
192 opt = pj_param(P->params, "smode").s;
194 if (!strcmp(opt, "plane")) {
195 P->dgg.output = ISEA_PLANE;
196 } else if (!strcmp(opt, "di")) {
197 P->dgg.output = ISEA_Q2DI;
199 else if (!strcmp(opt, "dd")) {
200 P->dgg.output = ISEA_Q2DD;
202 else if (!strcmp(opt, "hex")) {
203 P->dgg.output = ISEA_HEX;
210 if (pj_param(P->params, "trescale").i) {
211 P->dgg.radius = ISEA_SCALE;
214 if (pj_param(P->params, "tresolution").i) {
215 P->dgg.resolution = pj_param(P->params, "iresolution").i;
217 P->dgg.resolution = 4;
220 if (pj_param(P->params, "taperture").i) {
221 P->dgg.aperture = pj_param(P->params, "iaperture").i;
230 main(int ac, char *av[])
234 struct isea_pt out, coord;
242 isea_grid_init(&dgg);
243 dgg.output = ISEA_PLANE;
244 dgg.radius = ISEA_SCALE; /* 0.8301572857837594396028083; */
246 options(ac, av, &dgg);
249 printf("isea lat = %lf, lon = %lf, az = %lf\n",
250 dgg.o_lat * 180.0 / M_PI, dgg.o_lon * 180.0 / M_PI,
251 dgg.o_az * 180.0 / M_PI);
254 while (fgets(line, sizeof line, stdin)) {
255 line[sizeof line-1] = 0;
256 if (line[0] == '#') {
259 if (!strncmp(line, "ENDPOLY", 7)) {
263 in.lon = strtod(line, &rest);
264 in.lat = strtod(rest, &rest);
266 nl = strchr(rest, '\n');
269 in.lon *= M_PI / 180.0;
270 in.lat *= M_PI / 180.0;
272 out = isea_forward(&dgg, &in);
274 quad = ((tri - 1) % 5) + ((tri - 1) / 10) * 5 + 1;
277 if (dgg.output == ISEA_PLANE) {
278 calctri = isea_xy_triangle(&coord,
279 dgg.output == ISEA_PLANE ? dgg.radius : 1.0);
280 if (tri != calctri) {
282 "got %d (%f, %f), expected %d\n",
283 calctri, out.x, out.y, tri);
287 in.lon *= 180.0 / M_PI;
288 in.lat *= 180.0 / M_PI;
290 switch (dgg.output) {
292 printf("%d %.*f %.*f%s\n", tri, precision, out.x, precision, out.y, rest);
295 printf("%d %.*f %.*f%s\n", tri-1, precision, out.x,
296 precision, out.y, rest);
299 printf("%d %d %.*f %.*f%s\n", quad, tri-1, precision,
300 out.x, precision, out.y, rest);
303 /* Same as above, we just don't print as much */
304 printf("%d %.*f %.*f%s\n", quad, precision,
305 out.x, precision, out.y, rest);
308 printf("%d %.0lf %.0lf%s\n", dgg.quad, coord.x, coord.y, rest);
311 quad = isea_ptdi(&dgg, tri, &out, &coord);
312 printf("%d%s\n", isea_disn(&dgg, quad, &coord), rest);