Skip to content

Commit

Permalink
startree: add '-T' flag to write tag-along table as the first HDU, fo…
Browse files Browse the repository at this point in the history
…llowed by the kd-tree structure
  • Loading branch information
dstndstn committed Mar 21, 2018
1 parent 78168a4 commit 82c5173
Showing 1 changed file with 61 additions and 18 deletions.
79 changes: 61 additions & 18 deletions blind/startree-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "log.h"
#include "fitsioutils.h"

const char* OPTIONS = "hvL:d:t:bsSci:o:R:D:Pkn:";
const char* OPTIONS = "hvL:d:t:bsSci:o:R:D:PTkn:";

void printHelp(char* progname) {
BOILERPLATE_HELP_HEADER(stdout);
Expand All @@ -32,6 +32,7 @@ void printHelp(char* progname) {
" [-S]: include separate splitdim array\n"
" [-c]: run kdtree_check on the resulting tree\n"
" [-P]: unpermute tree + tag-along data\n"
" [-T]: write tag-along table as first extension HDU\n"
" [-k]: keep RA,Dec columns in tag-along table\n"
" [-n <name>]: kd-tree name (default \"stars\")\n"
" [-v]: +verbose\n"
Expand Down Expand Up @@ -60,6 +61,7 @@ int main(int argc, char *argv[]) {
anbool unpermute = FALSE;
anbool remove_radec = TRUE;
u32* perm = NULL;
anbool tagalong_first = FALSE;

if (argc <= 2) {
printHelp(progname);
Expand All @@ -68,6 +70,9 @@ int main(int argc, char *argv[]) {

while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
switch (argchar) {
case 'T':
tagalong_first = TRUE;
break;
case 'n':
treename = optarg;
break;
Expand Down Expand Up @@ -171,27 +176,65 @@ int main(int argc, char *argv[]) {
starkd->tree->perm = NULL;
}

if (startree_write_to_file(starkd, skdtfn)) {
ERROR("Failed to write star kdtree");
exit(-1);
}
startree_close(starkd);
if (tagalong_first) {
logmsg("Writing tag-along data...\n");
tag = fitstable_open_for_writing(skdtfn);
if (fitstable_write_primary_header(tag)) {
ERROR("Failed to write primary header");
exit(-1);
}
if (startree_write_tagalong_table(cat, tag, racol, deccol,
(int*)perm, remove_radec)) {
ERROR("Failed to write tag-along table");
exit(-1);
}
// Append kd-tree
logverb("Appending kd-tree structure...\n");
FILE* fid = fopen(skdtfn, "r+b");
if (!fid) {
SYSERROR("Failed to open startree output file to append kd-tree: %s", skdtfn);
exit(-1);
}
if (fseeko(fid, 0, SEEK_END)) {
SYSERROR("Failed to seek to the end of the startree file to append kd-tree: %s", skdtfn);
exit(-1);
}
if (startree_append_to(starkd, fid)) {
ERROR("Failed to append star kdtree");
exit(-1);
}
startree_close(starkd);
if (fclose(fid)) {
SYSERROR("Failed to close star kdtree file after appending tree\n");
exit(-1);
}
if (fitstable_close(tag)) {
ERROR("Failed to close tag-along data");
exit(-1);
}

} else {
if (startree_write_to_file(starkd, skdtfn)) {
ERROR("Failed to write star kdtree");
exit(-1);
}
startree_close(starkd);

// Append tag-along table.
logmsg("Writing tag-along data...\n");
tag = fitstable_open_for_appending(skdtfn);
// Append tag-along table.
logmsg("Writing tag-along data...\n");
tag = fitstable_open_for_appending(skdtfn);

if (startree_write_tagalong_table(cat, tag, racol, deccol,
(int*)perm, remove_radec)) {
ERROR("Failed to write tag-along table");
exit(-1);
}
if (startree_write_tagalong_table(cat, tag, racol, deccol,
(int*)perm, remove_radec)) {
ERROR("Failed to write tag-along table");
exit(-1);
}

if (fitstable_close(tag)) {
ERROR("Failed to close tag-along data");
exit(-1);
if (fitstable_close(tag)) {
ERROR("Failed to close tag-along data");
exit(-1);
}
}

fitstable_close(cat);
return 0;
}
Expand Down

0 comments on commit 82c5173

Please sign in to comment.