#include #include #include #include #include "isea.h" #include "hex.h" /* * options * * orientation * -l longitude * -z azimuth * -p latitude * * -I isea standard orientation * -D dymaxion orientation * -P vertex at pole * * -a aperture * -r resolution * -t h t d hex tri diamond * * addressing * -O q2dd seqnum interleave plane q2dd projtri vertex2dd * -I * * operation * -g generate grid * -x transform * -b bin point values (average) * -e bin point presence * -G spacing resolution generate graticule */ void usage(void) { fprintf(stderr, "%s", "isea [-l ] [-z ] [-p ] [-I] [-D] [-P] [-a ] [-r ] [-t ] [-A ] [-g] [-b] [-e] [-x]\n"); } void die(char *s) { fprintf(stderr, "%s\n", s); exit(EXIT_FAILURE); } static int verbose = 0; static int precision = 10; void options(int ac, char **av, struct isea_dgg *g) { int i = 1; char *optarg; for (i=1;iradius = strtod(av[++i],NULL); break; case 'l': g->o_lon = strtod(av[++i],NULL) * M_PI / 180.0; break; case 'p': g->o_lat = strtod(av[++i],NULL) * M_PI / 180.0; break; case 'z': g->o_az = strtod(av[++i],NULL) * M_PI / 180.0; break; case 'd': precision = atoi(av[++i]); break; case 'a': g->aperture = atoi(av[++i]); break; case 'r': g->resolution = atoi(av[++i]); break; case 't': switch (av[++i][0]) { case 'h': g->topology = ISEA_HEXAGON; break; case 't': g->topology = ISEA_TRIANGLE; break; case 'd': g->topology = ISEA_DIAMOND; break; default: usage(); die("Invalid topology"); break; }; break; case 'O': if (av[i][2]) { optarg = &av[i][2]; } else { optarg = av[++i]; } if (!strcmp(optarg, "projtri")) { g->output = ISEA_PROJTRI; } else if (!strcmp(optarg, "vertex2dd")) { g->output = ISEA_VERTEX2DD; } else if (!strcmp(optarg, "q2dd")) { g->output = ISEA_Q2DD; } else if (!strcmp(optarg, "q2di")) { g->output = ISEA_Q2DI; } else if (!strcmp(optarg, "seqnum")) { g->output = ISEA_SEQNUM; } else if (!strcmp(optarg, "plane")) { g->output = ISEA_PLANE; } else { fprintf(stderr, "unknown output format: %s\n",optarg); die("exiting"); } break; default: usage(); die("Unknown option"); } } } int main(int ac, char *av[]) { struct isea_dgg dgg; struct isea_geo in; struct isea_pt out, coord; int tri,calctri; int graticule = 0; int quad = 0; char line[1024]; char *rest, *nl; isea_grid_init(&dgg); dgg.output = ISEA_PLANE; dgg.radius = ISEA_SCALE; /* 0.8301572857837594396028083; */ options(ac, av, &dgg); if (verbose) { fprintf(stderr, "isea lat = %lf, lon = %lf, az = %lf, output = %s\n", dgg.o_lat * 180.0 / M_PI, dgg.o_lon * 180.0 / M_PI, dgg.o_az * 180.0 / M_PI, dgg.output == ISEA_PLANE ? "plane" : "not plane"); } while (fgets(line, sizeof line, stdin)) { line[sizeof line-1] = 0; if (line[0] == '#') { continue; } if (!strncmp(line, "ENDPOLY", 7)) { printf("%s", line); continue; } in.lon = strtod(line, &rest); in.lat = strtod(rest, &rest); nl = strchr(rest, '\n'); if (nl) *nl = 0; in.lon *= M_PI / 180.0; in.lat *= M_PI / 180.0; out = isea_forward(&dgg, &in); tri = dgg.triangle; quad = ((tri - 1) % 5) + ((tri - 1) / 10) * 5 + 1; coord = out; if (dgg.output == ISEA_PLANE) { calctri = isea_xy_triangle(&coord, dgg.output == ISEA_PLANE ? dgg.radius : 1.0); #if 0 if (tri != calctri) { fprintf(stderr, "got %d (%f, %f), expected %d\n", calctri, out.x, out.y, tri); } #endif } in.lon *= 180.0 / M_PI; in.lat *= 180.0 / M_PI; switch (dgg.output) { case ISEA_PLANE: printf("%.*f %.*f%s\n", precision, out.x, precision, out.y, rest); break; case ISEA_PROJTRI: printf("%d %.*f %.*f%s\n", tri-1, precision, out.x, precision, out.y, rest); break; case ISEA_VERTEX2DD: printf("%d %d %.*f %.*f%s\n", quad, tri-1, precision, out.x, precision, out.y, rest); break; case ISEA_Q2DD: /* Same as above, we just don't print as much */ printf("%d %.*f %.*f%s\n", quad, precision, out.x, precision, out.y, rest); break; case ISEA_Q2DI: printf("%d %.0lf %.0lf%s\n", dgg.quad, coord.x, coord.y, rest); break; case ISEA_SEQNUM: quad = isea_ptdi(&dgg, tri, &out, &coord); printf("%d%s\n", isea_disn(&dgg, quad, &coord), rest); break; } fflush(stdout); } if (graticule) { } exit(EXIT_SUCCESS); }