int unpermute_quads_files(const char* quadinfn, const char* ckdtinfn, const char* quadoutfn, const char* ckdtoutfn, char** args, int argc) { quadfile* quadin; quadfile* quadout; codetree* treein; codetree* treeout; logmsg("Reading code tree from %s ...\n", ckdtinfn); treein = codetree_open(ckdtinfn); if (!treein) { ERROR("Failed to read code kdtree from %s", ckdtinfn); return -1; } logmsg("Reading quads from %s ...\n", quadinfn); quadin = quadfile_open(quadinfn); if (!quadin) { ERROR("Failed to read quads from %s", quadinfn); return -1; } logmsg("Writing quads to %s ...\n", quadoutfn); quadout = quadfile_open_for_writing(quadoutfn); if (!quadout) { ERROR("Failed to write quads to %s", quadoutfn); return -1; } if (unpermute_quads(quadin, treein, quadout, &treeout, args, argc)) { return -1; } if (quadfile_close(quadout)) { ERROR("Failed to close output quadfile"); return -1; } quadfile_close(quadin); logmsg("Writing code kdtree to %s ...\n", ckdtoutfn); if (codetree_write_to_file(treeout, ckdtoutfn) || codetree_close(treeout)) { ERROR("Failed to write code kdtree"); return -1; } free(treein->tree); treein->tree = NULL; codetree_close(treein); return 0; }
int hpquads_files(const char* skdtfn, const char* codefn, const char* quadfn, int Nside, double scale_min_arcmin, double scale_max_arcmin, int dimquads, int passes, int Nreuses, int Nloosen, int id, anbool scanoccupied, void* sort_data, int (*sort_func)(const void*, const void*), int sort_size, char** args, int argc) { quadfile_t* quads; codefile_t* codes; startree_t* starkd; int rtn; logmsg("Reading star kdtree %s ...\n", skdtfn); starkd = startree_open(skdtfn); if (!starkd) { ERROR("Failed to open star kdtree %s\n", skdtfn); return -1; } logmsg("Will write to quad file %s and code file %s\n", quadfn, codefn); quads = quadfile_open_for_writing(quadfn); if (!quads) { ERROR("Couldn't open file %s to write quads.\n", quadfn); return -1; } codes = codefile_open_for_writing(codefn); if (!codes) { ERROR("Couldn't open file %s to write codes.\n", codefn); return -1; } rtn = hpquads(starkd, codes, quads, Nside, scale_min_arcmin, scale_max_arcmin, dimquads, passes, Nreuses, Nloosen, id, scanoccupied, sort_data, sort_func, sort_size, args, argc); if (rtn) return rtn; if (quadfile_close(quads)) { ERROR("Couldn't write quad output file"); return -1; } if (codefile_close(codes)) { ERROR("Couldn't write code output file"); return -1; } startree_close(starkd); return rtn; }
int unpermute_stars_files(const char* skdtinfn, const char* quadinfn, const char* skdtoutfn, const char* quadoutfn, anbool dosweeps, anbool check, char** args, int argc) { quadfile_t* qfin; quadfile_t* qfout; startree_t* treein; startree_t* treeout; fitstable_t* tagout = NULL; fitstable_t* tagin; int rtn; logmsg("Reading star tree from %s ...\n", skdtinfn); treein = startree_open(skdtinfn); if (!treein) { ERROR("Failed to read star kdtree from %s.\n", skdtinfn); return -1; } logmsg("Reading quadfile from %s ...\n", quadinfn); qfin = quadfile_open(quadinfn); if (!qfin) { ERROR("Failed to read quadfile from %s.\n", quadinfn); return -1; } logmsg("Writing quadfile to %s ...\n", quadoutfn); qfout = quadfile_open_for_writing(quadoutfn); if (!qfout) { ERROR("Failed to write quadfile to %s.\n", quadoutfn); return -1; } rtn = unpermute_stars(treein, qfin, &treeout, qfout, dosweeps, check, args, argc); if (rtn) return rtn; if (quadfile_close(qfout)) { ERROR("Failed to close output quadfile.\n"); return -1; } logmsg("Writing star kdtree to %s ...\n", skdtoutfn); if (startree_write_to_file(treeout, skdtoutfn)) { ERROR("Failed to write star kdtree.\n"); return -1; } if (startree_has_tagalong(treein)) { logmsg("Permuting tag-along table...\n"); tagin = startree_get_tagalong(treein); if (tagin) { tagout = fitstable_open_for_appending(skdtoutfn); tagout->table = fits_copy_table(tagin->table); tagout->table->nr = 0; if (unpermute_stars_tagalong(treein, tagout)) { ERROR("Failed to permute tag-along table"); return -1; } if (fitstable_close(tagout)) { ERROR("Failed to close tag-along data"); return -1; } } } quadfile_close(qfin); startree_close(treein); free(treeout->sweep); free(treeout->tree); treeout->tree = NULL; startree_close(treeout); return 0; }
int allquads_open_outputs(allquads_t* aq) { int hp, hpnside; qfits_header* hdr; printf("Reading star kdtree %s ...\n", aq->skdtfn); aq->starkd = startree_open(aq->skdtfn); if (!aq->starkd) { ERROR("Failed to open star kdtree %s\n", aq->skdtfn); return -1; } printf("Star tree contains %i objects.\n", startree_N(aq->starkd)); printf("Will write to quad file %s and code file %s\n", aq->quadfn, aq->codefn); aq->quads = quadfile_open_for_writing(aq->quadfn); if (!aq->quads) { ERROR("Couldn't open file %s to write quads.\n", aq->quadfn); return -1; } aq->codes = codefile_open_for_writing(aq->codefn); if (!aq->codes) { ERROR("Couldn't open file %s to write codes.\n", aq->quadfn); return -1; } aq->quads->dimquads = aq->dimquads; aq->codes->dimcodes = aq->dimcodes; if (aq->id) { aq->quads->indexid = aq->id; aq->codes->indexid = aq->id; } // get the "HEALPIX" header from the skdt and put it in the code and quad headers. hp = qfits_header_getint(startree_header(aq->starkd), "HEALPIX", -1); if (hp == -1) { logmsg("Warning: skdt does not contain \"HEALPIX\" header. Code and quad files will not contain this header either.\n"); } aq->quads->healpix = hp; aq->codes->healpix = hp; // likewise "HPNSIDE" hpnside = qfits_header_getint(startree_header(aq->starkd), "HPNSIDE", 1); aq->quads->hpnside = hpnside; aq->codes->hpnside = hpnside; hdr = quadfile_get_header(aq->quads); qfits_header_add(hdr, "CXDX", "T", "All codes have the property cx<=dx.", NULL); qfits_header_add(hdr, "CXDXLT1", "T", "All codes have the property cx+dx<=1.", NULL); qfits_header_add(hdr, "MIDHALF", "T", "All codes have the property cx+dx<=1.", NULL); qfits_header_add(hdr, "CIRCLE", "T", "Codes live in the circle, not the box.", NULL); hdr = codefile_get_header(aq->codes); qfits_header_add(hdr, "CXDX", "T", "All codes have the property cx<=dx.", NULL); qfits_header_add(hdr, "CXDXLT1", "T", "All codes have the property cx+dx<=1.", NULL); qfits_header_add(hdr, "MIDHALF", "T", "All codes have the property cx+dx<=1.", NULL); qfits_header_add(hdr, "CIRCLE", "T", "Codes live in the circle, not the box.", NULL); if (quadfile_write_header(aq->quads)) { ERROR("Couldn't write headers to quads file %s\n", aq->quadfn); return -1; } if (codefile_write_header(aq->codes)) { ERROR("Couldn't write headers to code file %s\n", aq->codefn); return -1; } if (!aq->use_d2_lower) aq->quad_d2_lower = 0.0; if (!aq->use_d2_upper) aq->quad_d2_upper = 10.0; aq->codes->numstars = startree_N(aq->starkd); aq->codes->index_scale_upper = distsq2rad(aq->quad_d2_upper); aq->codes->index_scale_lower = distsq2rad(aq->quad_d2_lower); aq->quads->numstars = aq->codes->numstars; aq->quads->index_scale_upper = aq->codes->index_scale_upper; aq->quads->index_scale_lower = aq->codes->index_scale_lower; return 0; }