int main()

in src/apps/filters/localIjToH3.c [50:118]


int main(int argc, char *argv[]) {
    H3Index origin = 0;
    CoordIJ ij = {0};

    Arg helpArg = ARG_HELP;
    Arg originArg = {
        .names = {"-o", "--origin"},
        .scanFormat = "%" PRIx64,
        .valueName = "origin",
        .value = &origin,
        .required = true,
        .helpText =
            "Origin (anchoring index) for the local coordinate system."};
    Arg iArg = {.names = {"-i", NULL},
                .scanFormat = "%d",
                .valueName = "i",
                .value = &ij.i,
                .helpText =
                    "I coordinate. If not specified \"i j\" pairs will be read "
                    "from standard input."};
    Arg jArg = {.names = {"-j", NULL},
                .scanFormat = "%d",
                .valueName = "j",
                .value = &ij.j,
                .helpText = "J coordinate."};

    Arg *args[] = {&helpArg, &originArg, &iArg, &jArg};
    const int numArgs = 4;
    const char *helpText = "Converts local IJ coordinates to H3 indexes";

    if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
        return helpArg.found ? 0 : 1;
    }

    if (!H3_EXPORT(h3IsValid)(origin)) {
        printHelp(stderr, argv[0], helpText, numArgs, args,
                  "Origin is invalid.", NULL);
        return 1;
    }

    if (iArg.found != jArg.found) {
        // One is found but the other is not.
        printHelp(stderr, argv[0], helpText, numArgs, args,
                  "I and J must both be specified.", NULL);
        return 1;
    }

    if (iArg.found) {
        doCell(&ij, origin);
    } else {
        // process the coordinates on stdin
        char buff[BUFF_SIZE];
        while (1) {
            // get coordinates from stdin
            if (!fgets(buff, BUFF_SIZE, stdin)) {
                if (feof(stdin))
                    break;
                else
                    error("reading IJ coordinates from stdin");
            }

            if (!sscanf(buff, "%d %d", &ij.i, &ij.j))
                error(
                    "Parsing IJ coordinates. Expected `<integer> <integer>`.");

            doCell(&ij, origin);
        }
    }
}