From c26551fc874056124ffa7aa0fea893e59b2fcb35 Mon Sep 17 00:00:00 2001 From: Dustin Lang Date: Sat, 8 Jan 2022 15:27:25 -0500 Subject: [PATCH] avoid HUGE_VAL, define LARGE_VAL --- __init__.py | 2 +- catalogs/usnob-scamp-catalog.c | 4 ++-- include/astrometry/kdtree.h | 5 +++-- include/astrometry/mathutil.h | 3 +++ include/astrometry/os-features.h | 3 --- include/astrometry/solver.h | 2 +- libkd/dualtree_nearestneighbour.c | 2 +- libkd/kdint_dtype_d.h | 4 ++-- libkd/kdint_dtype_f.h | 4 ++-- libkd/kdint_etype_d.h | 4 ++-- libkd/kdint_etype_f.h | 4 ++-- libkd/kdint_ttype_d.h | 6 +++--- libkd/kdint_ttype_f.h | 6 +++--- libkd/kdtree.c | 11 ++++++----- libkd/kdtree_internal.c | 13 +++++++------ libkd/pyspherematch.c | 3 ++- libkd/test_libkd.c | 2 +- plot/plotimage.c | 8 ++++---- qfits-an/qfits_table.c | 10 ++++++---- solver/agreeable.c | 2 +- solver/augment-xylist.c | 15 ++++++++------- solver/build-index.c | 3 ++- solver/dstnthing.c | 5 +++-- solver/engine.c | 22 ++++++++++++---------- solver/fits-guess-scale.c | 3 ++- solver/index-info.c | 12 ------------ solver/index-stats.c | 4 ++-- solver/keirthing.c | 7 ++++--- solver/onefield.c | 2 +- solver/solver.c | 14 +++++++------- solver/tweak2.c | 6 +++--- solver/uniformize-catalog-main.c | 3 ++- solver/uniformize-catalog.c | 2 +- solver/verify-paths.c | 4 ++-- solver/verify.c | 23 +++++++++++------------ solver/whynot.c | 2 +- util/an-fitstopnm.c | 5 +++-- util/dobjects.c | 3 ++- util/fitsioutils.c | 3 ++- util/get-healpix.c | 4 ++-- util/healpix.c | 4 ++-- util/search-index.c | 5 +++-- util/sip_qfits.c | 4 ++-- util/sparsematrix.c | 5 +++-- util/starutil.c | 10 +++++----- util/starxy.c | 5 +++-- util/wcs-rd2xy-main.c | 5 +++-- util/wcs-resample.c | 13 +++++++------ util/wcs-to-tan.c | 12 ++++++------ util/wcs-xy2rd-main.c | 5 +++-- 50 files changed, 159 insertions(+), 149 deletions(-) diff --git a/__init__.py b/__init__.py index 1f1f68050..641d414f5 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -__version__ = '0.87-1-gccf53467' +__version__ = '0.87-10-gd7855b91' diff --git a/catalogs/usnob-scamp-catalog.c b/catalogs/usnob-scamp-catalog.c index 701cdc68f..e73d856e4 100644 --- a/catalogs/usnob-scamp-catalog.c +++ b/catalogs/usnob-scamp-catalog.c @@ -10,11 +10,11 @@ #include "os-features.h" #include "scamp-catalog.h" #include "usnob-fits.h" -//#include "healpix-utils.h" #include "healpix.h" #include "starutil.h" #include "errors.h" #include "log.h" +#include "mathutil.h" const char* OPTIONS = "hu:o:A:D:r:n:RBNv"; @@ -92,7 +92,7 @@ int main(int argc, char** args) { } log_init(loglvl); - if (ra == HUGE_VAL || dec == HUGE_VAL || !usnobpath || !scampref || radius == 0.0 || !nside) { + if (ra == LARGE_VAL || dec == LARGE_VAL || !usnobpath || !scampref || radius == 0.0 || !nside) { print_help(args[0]); printf("\n\nNeed RA, Dec, USNOB path, Nside, Scamp output file, and radius.\n"); exit(-1); diff --git a/include/astrometry/kdtree.h b/include/astrometry/kdtree.h index f0e92e4cc..540fe5ea5 100644 --- a/include/astrometry/kdtree.h +++ b/include/astrometry/kdtree.h @@ -11,8 +11,9 @@ #define KDTREE_MAX_LEVELS 1000 -#define KDT_INFTY_DOUBLE HUGE_VAL -#define KDT_INFTY_FLOAT HUGE_VALF +// negatives of these values should be valid also +#define KDT_LARGEVAL 1e308 +#define KDT_LARGEVALF 1e38 enum kd_rangesearch_options { KD_OPTIONS_COMPUTE_DISTS = 0x1, diff --git a/include/astrometry/mathutil.h b/include/astrometry/mathutil.h index 6ecd93c9a..91f5846e8 100644 --- a/include/astrometry/mathutil.h +++ b/include/astrometry/mathutil.h @@ -9,6 +9,9 @@ #include "astrometry/keywords.h" #include "bl.h" +#define LARGE_VAL 1e30 +#define LARGE_VALF 1e30f + int point_in_polygon(double x, double y, const dl* polygon); /* diff --git a/include/astrometry/os-features.h b/include/astrometry/os-features.h index 6b73a7d83..780c4b916 100644 --- a/include/astrometry/os-features.h +++ b/include/astrometry/os-features.h @@ -48,9 +48,6 @@ ? __x_n >= __LDBL_MIN__ \ : __x_n >= __DBL_MIN__), 1); }) -#undef HUGE_VALF -#define HUGE_VALF (1e50f) - #endif diff --git a/include/astrometry/solver.h b/include/astrometry/solver.h index d3def5cd3..53545e82c 100644 --- a/include/astrometry/solver.h +++ b/include/astrometry/solver.h @@ -119,7 +119,7 @@ struct solver_t { double logratio_bail_threshold; // During verification, if the log-odds ratio rises above this level, we accept the - // match and bail out. Default: HUGE_VAL (ie, don't bail out: keep going to find the + // match and bail out. Default: LARGE_VAL (ie, don't bail out: keep going to find the // maximum Bayes factor value). double logratio_stoplooking; diff --git a/libkd/dualtree_nearestneighbour.c b/libkd/dualtree_nearestneighbour.c index 71122197d..6ec71e28d 100644 --- a/libkd/dualtree_nearestneighbour.c +++ b/libkd/dualtree_nearestneighbour.c @@ -78,7 +78,7 @@ void dualtree_nearestneighbour(kdtree_t* xtree, kdtree_t* ytree, double maxdist2 params.nearest_d2 = malloc(NY * sizeof(double)); if (maxdist2 == 0.0) - maxdist2 = HUGE_VAL; + maxdist2 = LARGE_VAL; for (i=0; itreetype, res=, (kd1, node1, kd2, node2)); return res; } @@ -599,7 +600,7 @@ KD_DECLARE(kdtree_node_node_maxdist2, double, (const kdtree_t* kd1, int node1, c double kdtree_node_node_maxdist2(const kdtree_t* kd1, int node1, const kdtree_t* kd2, int node2) { - double res = HUGE_VAL; + double res = LARGE_VAL; KD_DISPATCH(kdtree_node_node_maxdist2, kd1->treetype, res=, (kd1, node1, kd2, node2)); return res; } @@ -627,7 +628,7 @@ int kdtree_node_node_maxdist2_exceeds(const kdtree_t* kd1, int node1, KD_DECLARE(kdtree_node_point_mindist2, double, (const kdtree_t* kd, int node, const void* query)); double kdtree_node_point_mindist2(const kdtree_t* kd, int node, const void* pt) { - double res = HUGE_VAL; + double res = LARGE_VAL; KD_DISPATCH(kdtree_node_point_mindist2, kd->treetype, res=, (kd, node, pt)); return res; } @@ -635,7 +636,7 @@ double kdtree_node_point_mindist2(const kdtree_t* kd, int node, const void* pt) KD_DECLARE(kdtree_node_point_maxdist2, double, (const kdtree_t* kd, int node, const void* query)); double kdtree_node_point_maxdist2(const kdtree_t* kd, int node, const void* pt) { - double res = HUGE_VAL; + double res = LARGE_VAL; KD_DISPATCH(kdtree_node_point_maxdist2, kd->treetype, res=, (kd, node, pt)); return res; } diff --git a/libkd/kdtree_internal.c b/libkd/kdtree_internal.c index 36b98b5d7..c54670e68 100644 --- a/libkd/kdtree_internal.c +++ b/libkd/kdtree_internal.c @@ -14,6 +14,7 @@ #include "kdtree_mem.h" #include "keywords.h" #include "errors.h" +#include "mathutil.h" #define KDTREE_MAX_RESULTS 1000 #define KDTREE_MAX_DIM 100 @@ -659,7 +660,7 @@ static void kdtree_nn_bb(const kdtree_t* kd, const etype* query, continue; } - childd2[0] = childd2[1] = HUGE_VAL; + childd2[0] = childd2[1] = LARGE_VAL; for (child=0; child<2; child++) { anbool bailed; double dist2; @@ -728,11 +729,11 @@ static void kdtree_nn_bb(const kdtree_t* kd, const etype* query, secondid = KD_CHILD_LEFT(nodeid); } - if (firstd2 == HUGE_VAL) + if (firstd2 == LARGE_VAL) continue; // it's a stack, so put the "second" one on first. - if (secondd2 != HUGE_VAL) { + if (secondd2 != LARGE_VAL) { stackpos++; nodestack[stackpos] = secondid; dist2stack[stackpos] = secondd2; @@ -1215,7 +1216,7 @@ kdtree_qres_t* MANGLE(kdtree_rangesearch_options) // HACK - should do "use_dtype", just like "use_ttype". if (dist2_exceeds(kd, query, data, D, maxd2)) continue; - if (!add_result(kd, res, HUGE_VAL, KD_PERM(kd, i), data, + if (!add_result(kd, res, LARGE_VAL, KD_PERM(kd, i), data, D, do_dists, do_points)) return NULL; } @@ -1309,7 +1310,7 @@ kdtree_qres_t* MANGLE(kdtree_rangesearch_options) } } else { for (i=L; i<=R; i++) - if (!add_result(kd, res, HUGE_VAL, KD_PERM(kd, i), + if (!add_result(kd, res, LARGE_VAL, KD_PERM(kd, i), KD_DATA(kd, D, i), D, do_dists, do_points)) return NULL; @@ -2531,7 +2532,7 @@ double MANGLE(kdtree_node_point_mindist2) double d2 = 0.0; if (!bboxes(kd, node, &tlo, &thi, D)) { ERROR("Error: kdtree does not have bounding boxes!"); - return HUGE_VAL; + return LARGE_VAL; } for (d=0; dW * pargs->H); i++) { plo = MIN(plo, rimg[i]); @@ -367,8 +367,8 @@ unsigned char* plot_image_scale_float(plotimage_t* args, const float* fimg) { if (args->auto_scale) { // min/max, or percentiles? /* - double mn = HUGE_VAL; - double mx = -HUGE_VAL; + double mn = LARGE_VAL; + double mx = -LARGE_VAL; for (i=0; i<(args->W*args->H); i++) { mn = MIN(mn, fimg[i]); mx = MAX(mx, fimg[i]); diff --git a/qfits-an/qfits_table.c b/qfits-an/qfits_table.c index 12472eb3a..0f0e7a7e6 100644 --- a/qfits-an/qfits_table.c +++ b/qfits-an/qfits_table.c @@ -59,6 +59,8 @@ #define ELEMENT_MAX_DISPLAY_SIZE 50 +#define LARGE_VALF 1e30f + /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ @@ -565,8 +567,8 @@ qfits_table * qfits_table_open2(const qfits_header* hdr, off_t offset_beg, size_ /* zero <-> TZERO */ sprintf(keyword, "TZERO%d", i+1); zero_present = 1; - zero = qfits_header_getdouble(hdr, keyword, HUGE_VAL); - if (zero == HUGE_VAL) { + zero = qfits_header_getdouble(hdr, keyword, LARGE_VALF); + if (zero == LARGE_VALF) { zero = 0.0; zero_present = 0; } @@ -574,8 +576,8 @@ qfits_table * qfits_table_open2(const qfits_header* hdr, off_t offset_beg, size_ /* scale <-> TSCAL */ sprintf(keyword, "TSCAL%d", i+1); scale_present = 1; - scale = qfits_header_getdouble(hdr, keyword, HUGE_VAL); - if (scale == HUGE_VAL) { + scale = qfits_header_getdouble(hdr, keyword, LARGE_VALF); + if (scale == LARGE_VALF) { scale = 1.0; scale_present = 0; } diff --git a/solver/agreeable.c b/solver/agreeable.c index 55aec51a2..2695bc3c4 100644 --- a/solver/agreeable.c +++ b/solver/agreeable.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) { int fieldfile; int totalsolved, totalunsolved; int mode = MODE_BEST; - double logodds_tosolve = -HUGE_VAL; + double logodds_tosolve = -LARGE_VAL; anbool agree = FALSE; MatchObj* bestmo; diff --git a/solver/augment-xylist.c b/solver/augment-xylist.c index d742a4a73..b5dbe913d 100644 --- a/solver/augment-xylist.c +++ b/solver/augment-xylist.c @@ -41,6 +41,7 @@ #include "augment-xylist.h" #include "log.h" #include "anqfits.h" +#include "mathutil.h" static void delete_existing_an_headers(qfits_header* hdr); @@ -56,8 +57,8 @@ void augment_xylist_init(augment_xylist_t* axy) { axy->tagalong = sl_new(4); axy->try_verify = TRUE; axy->resort = TRUE; - axy->ra_center = HUGE_VAL; - axy->dec_center = HUGE_VAL; + axy->ra_center = LARGE_VAL; + axy->dec_center = LARGE_VAL; axy->parity = PARITY_BOTH; axy->uniformize = 10; axy->verify_uniformize = TRUE; @@ -137,7 +138,7 @@ static an_option_t options[] = { {'#', "odds-to-reject", required_argument, "odds", "odds ratio at which to reject a hypothesis (default: 1e-100)"}, {'%', "odds-to-stop-looking", required_argument, "odds", - "odds ratio at which to stop adding stars when evaluating a hypothesis (default: HUGE_VAL)"}, + "odds ratio at which to stop adding stars when evaluating a hypothesis (default: LARGE_VAL)"}, {'^', "use-source-extractor", no_argument, NULL, "use SourceExtractor rather than built-in image2xy to find sources"}, {'&', "source-extractor-config", required_argument, "filename", @@ -343,14 +344,14 @@ int augment_xylist_parse_option(char argchar, char* optarg, break; case '3': axy->ra_center = atora(optarg); - if (axy->ra_center == HUGE_VAL) { + if (axy->ra_center == LARGE_VAL) { ERROR("Couldn't understand your RA center argument \"%s\"", optarg); return -1; } break; case '4': axy->dec_center = atodec(optarg); - if (axy->dec_center == HUGE_VAL) { + if (axy->dec_center == LARGE_VAL) { ERROR("Couldn't understand your Dec center argument \"%s\"", optarg); return -1; } @@ -1313,8 +1314,8 @@ int augment_xylist(augment_xylist_t* axy, qfits_header_add(hdr, "ANPARITY", "NEG", "det(CD) < 0", NULL); } - if ((axy->ra_center != HUGE_VAL) && - (axy->dec_center != HUGE_VAL) && + if ((axy->ra_center != LARGE_VAL) && + (axy->dec_center != LARGE_VAL) && (axy->search_radius >= 0.0)) { fits_header_add_double(hdr, "ANERA", axy->ra_center, "RA center estimate (deg)"); fits_header_add_double(hdr, "ANEDEC", axy->dec_center, "Dec center estimate (deg)"); diff --git a/solver/build-index.c b/solver/build-index.c index 9ff465c5b..ee91c4086 100644 --- a/solver/build-index.c +++ b/solver/build-index.c @@ -37,6 +37,7 @@ #include "merge-index.h" #include "fitsioutils.h" #include "permutedsort.h" +#include "mathutil.h" static void add_boilerplate(index_params_t* p, qfits_header* hdr) { } @@ -727,7 +728,7 @@ void build_index_defaults(index_params_t* p) { p->Nloosen = 20; p->dimquads = 4; p->sortasc = TRUE; - p->brightcut = -HUGE_VAL; + p->brightcut = -LARGE_VAL; // default to all-sky p->bighp = -1; //p->inmemory = TRUE; diff --git a/solver/dstnthing.c b/solver/dstnthing.c index 4b8fd16d2..d8778b736 100644 --- a/solver/dstnthing.c +++ b/solver/dstnthing.c @@ -25,6 +25,7 @@ #include "cairoutils.h" #include "fitsioutils.h" #include "tweak2.h" +#include "mathutil.h" static const char* OPTIONS = "hx:m:r:vj:p:i:J:o:W:w:s:X:Y:"; @@ -223,7 +224,7 @@ int main(int argc, char** args) { int order = 2; int loglvl = LOG_MSG; - double crpix[] = { HUGE_VAL, HUGE_VAL }; + double crpix[] = { LARGE_VAL, LARGE_VAL }; anbool do_crpix = FALSE; //FILE* logstream = stderr; @@ -288,7 +289,7 @@ int main(int argc, char** args) { exit(-1); } - do_crpix = (crpix[0] != HUGE_VAL) && (crpix[1] != HUGE_VAL); + do_crpix = (crpix[0] != LARGE_VAL) && (crpix[1] != LARGE_VAL); log_init(loglvl); diff --git a/solver/engine.c b/solver/engine.c index 57b0c8435..a90b3b4eb 100644 --- a/solver/engine.c +++ b/solver/engine.c @@ -21,12 +21,14 @@ #include #include +#include "math.h" + +#include "mathutil.h" #include "ioutils.h" #include "fileutils.h" #include "bl.h" #include "an-bool.h" #include "solver.h" -#include "math.h" #include "fitsioutils.h" #include "solverutils.h" #include "os-features.h" @@ -659,7 +661,7 @@ static anbool parse_job_from_qfits_header(const qfits_header* hdr, job_t* job) { onefield_t* bp = &(job->bp); solver_t* sp = &(bp->solver); - double dnil = -HUGE_VAL; + double dnil = -LARGE_VAL; char *pstr; int n; anbool run; @@ -782,12 +784,12 @@ static anbool parse_job_from_qfits_header(const qfits_header* hdr, job_t* job) { if (val > 0.0) bp->quad_size_fraction_hi = val; - job->ra_center = qfits_header_getdouble(hdr, "ANERA", HUGE_VAL); - job->dec_center = qfits_header_getdouble(hdr, "ANEDEC", HUGE_VAL); - job->search_radius = qfits_header_getdouble(hdr, "ANERAD", HUGE_VAL); - job->use_radec_center = ((job->ra_center != HUGE_VAL) && - (job->dec_center != HUGE_VAL) && - (job->search_radius != HUGE_VAL)); + job->ra_center = qfits_header_getdouble(hdr, "ANERA", dnil); + job->dec_center = qfits_header_getdouble(hdr, "ANEDEC", dnil); + job->search_radius = qfits_header_getdouble(hdr, "ANERAD", dnil); + job->use_radec_center = ((job->ra_center != dnil) && + (job->dec_center != dnil) && + (job->search_radius != dnil)); // tag-along columns bp->rdls_tagalong_all = qfits_header_getboolean(hdr, "ANTAGALL", FALSE); @@ -977,8 +979,8 @@ engine_t* engine_new() { engine->ismallest = il_new(4); engine->ibiggest = il_new(4); engine->default_depths = il_new(4); - engine->sizesmallest = HUGE_VAL; - engine->sizebiggest = -HUGE_VAL; + engine->sizesmallest = LARGE_VAL; + engine->sizebiggest = -LARGE_VAL; // Default scale estimate: field width, in degrees: engine->minwidth = 0.1; diff --git a/solver/fits-guess-scale.c b/solver/fits-guess-scale.c index 9dac5dccf..472460c56 100644 --- a/solver/fits-guess-scale.c +++ b/solver/fits-guess-scale.c @@ -17,6 +17,7 @@ #include "starutil.h" #include "errors.h" #include "log.h" +#include "mathutil.h" int fits_guess_scale(const char* infn, sl** p_methods, dl** p_scales) { @@ -79,7 +80,7 @@ void fits_guess_scale_hdr(const qfits_header* hdr, if (!gotsip) { // it might have a correct CD matrix but be missing other parts (eg CRVAL) double cd11, cd12, cd21, cd22; - double errval = -HUGE_VAL; + double errval = -LARGE_VAL; cd11 = qfits_header_getdouble(hdr, "CD1_1", errval); cd12 = qfits_header_getdouble(hdr, "CD1_2", errval); cd21 = qfits_header_getdouble(hdr, "CD2_1", errval); diff --git a/solver/index-info.c b/solver/index-info.c index ce9c8d98b..4f32d5806 100644 --- a/solver/index-info.c +++ b/solver/index-info.c @@ -30,7 +30,6 @@ void printHelp(char* progname) { int main(int argc, char **argv) { int argchar; - //double ra=HUGE_VAL, dec=HUGE_VAL, radius=HUGE_VAL; int loglvl = LOG_MSG; char** myargs; int nmyargs; @@ -38,17 +37,6 @@ int main(int argc, char **argv) { while ((argchar = getopt (argc, argv, OPTIONS)) != -1) switch (argchar) { - /* - case 'r': - ra = atof(optarg); - break; - case 'd': - dec = atof(optarg); - break; - case 'R': - radius = atof(optarg); - break; - */ case 'v': loglvl++; break; diff --git a/solver/index-stats.c b/solver/index-stats.c index 574f81607..d1a507f26 100644 --- a/solver/index-stats.c +++ b/solver/index-stats.c @@ -104,8 +104,8 @@ int main(int argc, char** args) { for (k=0; klogratio_tosolve; - bp->logratio_tosolve = HUGE_VAL; + bp->logratio_tosolve = LARGE_VAL; for (w = 0; w < bl_size(bp->verify_wcs_list); w++) { double pixscale; diff --git a/solver/solver.c b/solver/solver.c index 19d59af75..4e81adaa2 100644 --- a/solver/solver.c +++ b/solver/solver.c @@ -630,8 +630,8 @@ static void find_field_boundaries(solver_t* solver) { if ((solver->field_minx == solver->field_maxx) || (solver->field_miny == solver->field_maxy)) { int i; - solver->field_minx = solver->field_miny = HUGE_VAL; - solver->field_maxx = solver->field_maxy = -HUGE_VAL; + solver->field_minx = solver->field_miny = LARGE_VAL; + solver->field_maxx = solver->field_maxy = -LARGE_VAL; for (i = 0; i < starxy_n(solver->fieldxy); i++) { solver->field_minx = MIN(solver->field_minx, field_getx(solver, i)); solver->field_maxx = MAX(solver->field_maxx, field_getx(solver, i)); @@ -797,8 +797,8 @@ void solver_run(solver_t* solver) { { double minAB2s[num_indexes]; double maxAB2s[num_indexes]; - solver->minminAB2 = HUGE_VAL; - solver->maxmaxAB2 = -HUGE_VAL; + solver->minminAB2 = LARGE_VAL; + solver->maxmaxAB2 = -LARGE_VAL; for (i = 0; i < num_indexes; i++) { double minAB=0, maxAB=0; index_t* index = pl_get(solver->indexes, i); @@ -1640,10 +1640,10 @@ solver_t* solver_new() { void solver_set_default_values(solver_t* solver) { memset(solver, 0, sizeof(solver_t)); solver->indexes = pl_new(16); - solver->funits_upper = HUGE_VAL; + solver->funits_upper = LARGE_VAL; solver->logratio_bail_threshold = log(1e-100); - solver->logratio_stoplooking = HUGE_VAL; - solver->logratio_totune = HUGE_VAL; + solver->logratio_stoplooking = LARGE_VAL; + solver->logratio_totune = LARGE_VAL; solver->parity = DEFAULT_PARITY; solver->codetol = DEFAULT_CODE_TOL; solver->distractor_ratio = DEFAULT_DISTRACTOR_RATIO; diff --git a/solver/tweak2.c b/solver/tweak2.c index 43037e3c5..ee3150c46 100644 --- a/solver/tweak2.c +++ b/solver/tweak2.c @@ -350,7 +350,7 @@ sip_t* tweak2(const double* fieldxy, int Nfield, logodds = verify_star_lists(indexpix, Nin, fieldxy, fieldsigma2s, Nfield, W*H, distractors, - logodds_bail, HUGE_VAL, + logodds_bail, LARGE_VAL, &besti, &odds, &theta, NULL, &testperm); */ @@ -360,7 +360,7 @@ sip_t* tweak2(const double* fieldxy, int Nfield, fieldxy, fieldsigma2s, Nfield, pix2, gamma, qc, quadR2, W, H, distractors, - logodds_bail, HUGE_VAL, + logodds_bail, LARGE_VAL, &besti, &odds, &theta, NULL, &testperm, &refperm); @@ -524,7 +524,7 @@ sip_t* tweak2(const double* fieldxy, int Nfield, fieldxy, fieldsigma2s, Nfield, pix2, gamma, qc, quadR2, W, H, distractors, - logodds_bail, HUGE_VAL, + logodds_bail, LARGE_VAL, &besti, &odds, &theta, NULL, &testperm, &refperm); logverb("Logodds: %g\n", logodds); diff --git a/solver/uniformize-catalog-main.c b/solver/uniformize-catalog-main.c index ff497d1ee..1c571110b 100644 --- a/solver/uniformize-catalog-main.c +++ b/solver/uniformize-catalog-main.c @@ -16,6 +16,7 @@ #include "errors.h" #include "log.h" #include "fitsioutils.h" +#include "mathutil.h" const char* OPTIONS = "hvH:s:n:N:d:R:D:S:fm:"; @@ -53,7 +54,7 @@ int main(int argc, char *argv[]) { int Nside = 100; double dedup = 0.0; int margin = 0; - double mincut = -HUGE_VAL; + double mincut = -LARGE_VAL; fitstable_t* intable; fitstable_t* outtable; diff --git a/solver/uniformize-catalog.c b/solver/uniformize-catalog.c index f030ac791..4ba4bf223 100644 --- a/solver/uniformize-catalog.c +++ b/solver/uniformize-catalog.c @@ -153,7 +153,7 @@ int uniformize_catalog(fitstable_t* intable, fitstable_t* outtable, inorder = permuted_sort(sortval, sizeof(double), sort_ascending ? compare_doubles_asc : compare_doubles_desc, NULL, N); - if (sort_min_cut > -HUGE_VAL) { + if (sort_min_cut > -LARGE_VAL) { logverb("Cutting to %s > %g...\n", sortcol, sort_min_cut); // Cut objects with sortval < sort_min_cut. if (sort_ascending) { diff --git a/solver/verify-paths.c b/solver/verify-paths.c index 34c70ec88..372517858 100644 --- a/solver/verify-paths.c +++ b/solver/verify-paths.c @@ -196,7 +196,7 @@ int main(int argc, char** args) { double fieldW=0, fieldH=0; double logbail = log(1e-100); double logkeep = log(1e12); - double logaccept = HUGE_VAL; + double logaccept = LARGE_VAL; anbool growvariance = TRUE; anbool fake = FALSE; double logodds; @@ -343,7 +343,7 @@ int main(int argc, char** args) { for (i=0; idimquads; i++) { double qxy[2]; int besti = -1; - double bestd2 = HUGE_VAL; + double bestd2 = LARGE_VAL; if (!tan_xyzarr2pixelxy(&(mo->wcstan), mo->quadxyz + 3*i, qxy, qxy+1)) { ERROR("quad star projects to wrong side of sphere!"); exit(-1); diff --git a/solver/verify.c b/solver/verify.c index a5221f1ee..ebced604b 100644 --- a/solver/verify.c +++ b/solver/verify.c @@ -32,7 +32,6 @@ #define DLOG_ODDS 10 #define DLOG_ODDS_MIN log(1e6) -//#define DLOG_ODDS_MIN -HUGE_VAL #define dlog(lev, fmt, ...) data_log(DATALOG_MASK_VERIFY, lev, fmt, ##__VA_ARGS__) @@ -476,7 +475,7 @@ static double real_verify_star_lists(verify_t* v, if (!v->NR || !v->NT) { logerr("real_verify_star_lists: NR=%i, NT=%i\n", v->NR, v->NT); - return -HUGE_VAL; + return -LARGE_VAL; } // Build a tree out of the index stars in pixel space... @@ -501,7 +500,7 @@ static double real_verify_star_lists(verify_t* v, rprobs = malloc(v->NR * sizeof(double)); for (i=0; iNR; i++) - rprobs[i] = -HUGE_VAL; + rprobs[i] = -LARGE_VAL; if (p_logodds || data_log_passes(DATALOG_MASK_VERIFY, DLOG_ODDS)) all_logodds = calloc(v->NT, sizeof(double)); @@ -518,8 +517,8 @@ static double real_verify_star_lists(verify_t* v, logbg = log(1.0 / effective_area); worstlogodds = 0; - bestlogodds = -HUGE_VAL; - bestworstlogodds = -HUGE_VAL; + bestlogodds = -LARGE_VAL; + bestworstlogodds = -LARGE_VAL; besti = -1; logodds = 0.0; mu = 0; @@ -548,7 +547,7 @@ static double real_verify_star_lists(verify_t* v, // no nearest neighbour within range. debug2(" No nearest neighbour.\n"); refi = -1; - logfg = -HUGE_VAL; + logfg = -LARGE_VAL; } else { double loggmax; // Note that "refi" is w.r.t. the "refcopy" array (not the original data). @@ -1047,7 +1046,7 @@ static void set_null_mo(MatchObj* mo) { mo->nfield = 0; mo->nmatch = 0; matchobj_compute_derived(mo); - mo->logodds = -HUGE_VAL; + mo->logodds = -LARGE_VAL; } static void check_permutation(const int* perm, int N) { @@ -1158,7 +1157,7 @@ static void fixup_theta(int* theta, double* allodds, int ibailed, int istopped, if (theta[i] < 0) { etheta[ti] = theta[i]; // No match -> no weight. - eodds[ti] = -HUGE_VAL; + eodds[ti] = -LARGE_VAL; } else { if (DEBUGVERIFY) assert(invrperm[theta[i]] != BAD_PERM); @@ -1172,7 +1171,7 @@ static void fixup_theta(int* theta, double* allodds, int ibailed, int istopped, for (i=v->NT; iNTall; i++) { ti = v->testperm[i]; etheta[ti] = THETA_FILTERED; - eodds[ti] = -HUGE_VAL; + eodds[ti] = -LARGE_VAL; } if (DEBUGVERIFY) { @@ -1393,7 +1392,7 @@ void verify_hit(const startree_t* skdt, int index_cutnside, MatchObj* mo, goto bailout; } - worst = -HUGE_VAL; + worst = -LARGE_VAL; K = real_verify_star_lists(v, effA, distractors, logbail, logstoplooking, &besti, &allodds, &theta, &worst, &ibailed, &istopped); @@ -1436,7 +1435,7 @@ void verify_hit(const startree_t* skdt, int index_cutnside, MatchObj* mo, ti = mo->field[j]; assert(etheta[ti] == THETA_FILTERED); etheta[ti] = ri; - eodds[ti] = HUGE_VAL; + eodds[ti] = LARGE_VAL; debug2("Matched ref index %i (star %i) to test index %i; ref pos=(%.1f, %.1f), test pos=(%.1f, %.1f)\n", ri, v->refstarid[ri], ti, v->refxy[ri*2+0], v->refxy[ri*2+1], v->testxy[ti*2+0], v->testxy[ti*2+1]); break; @@ -1745,7 +1744,7 @@ double verify_star_lists_ror(double* refxys, int NR, *p_besti = besti; } else { - X = -HUGE_VAL; + X = -LARGE_VAL; } diff --git a/solver/whynot.c b/solver/whynot.c index 5b3215df4..2b6323bbb 100644 --- a/solver/whynot.c +++ b/solver/whynot.c @@ -960,7 +960,7 @@ int main(int argc, char** args) { verify_hit(indx->starkd, indx->cutnside, &mo, NULL, vf, verpix2, DEFAULT_DISTRACTOR_RATIO, W, H, - log(1e-100), log(1e9), HUGE_VAL, TRUE, FALSE); + log(1e-100), log(1e9), LARGE_VAL, TRUE, FALSE); verify_field_free(vf); } diff --git a/util/an-fitstopnm.c b/util/an-fitstopnm.c index cd4318238..155b54ac7 100644 --- a/util/an-fitstopnm.c +++ b/util/an-fitstopnm.c @@ -19,6 +19,7 @@ #include "log.h" #include "errors.h" #include "fitsioutils.h" +#include "mathutil.h" static const char* OPTIONS = "hi:o:Oe:p:m:IX:N:xnrsvML:H:"; @@ -271,7 +272,7 @@ int main(int argc, char *argv[]) { float scale; if (find_min) { - minval = HUGE_VALF; + minval = LARGE_VALF; for (i=0; i<(nx*ny); i++) { if (isfinite(img[i])) { minval = MIN(minval, img[i]); @@ -281,7 +282,7 @@ int main(int argc, char *argv[]) { logverb("Minimum pixel value: %g\n", minval); } if (find_max) { - maxval = -HUGE_VALF; + maxval = -LARGE_VALF; for (i=0; i<(nx*ny); i++) { if (isfinite(img[i])) { maxval = MAX(maxval, img[i]); diff --git a/util/dobjects.c b/util/dobjects.c index 5941e8cd7..0bd354b20 100644 --- a/util/dobjects.c +++ b/util/dobjects.c @@ -12,6 +12,7 @@ #include "dimage.h" #include "simplexy-common.h" #include "log.h" +#include "mathutil.h" /* * dobjects.c @@ -55,7 +56,7 @@ int dmask(float *image, int nx, int ny, float limit, if (!flagged_one) { /* no pixels were masked - what parameter settings would cause at least one pixel to be masked? */ - float maxval = -HUGE_VAL; + float maxval = -LARGE_VALF; for (i=0; i<(nx*ny); i++) maxval = MAX(maxval, image[i]); logmsg("No pixels were marked as significant.\n" diff --git a/util/fitsioutils.c b/util/fitsioutils.c index a4567e12c..a58ab5f6a 100644 --- a/util/fitsioutils.c +++ b/util/fitsioutils.c @@ -24,6 +24,7 @@ #include "errors.h" #include "log.h" #include "errors.h" +#include "mathutil.h" Malloc char* fits_to_string(const qfits_header* hdr, int* size) { @@ -307,7 +308,7 @@ double fits_get_double_val(const qfits_table* table, int column, } else { fprintf(stderr, "Invalid column type %i.\n", table->col[column].atom_type); } - return HUGE_VAL; + return LARGE_VAL; } int fits_is_table_header(const char* key) { diff --git a/util/get-healpix.c b/util/get-healpix.c index 9e7f4ce2c..4983f4b15 100644 --- a/util/get-healpix.c +++ b/util/get-healpix.c @@ -36,7 +36,7 @@ int main(int argc, char** args) { int healpix = -1; int i; anbool degrees = TRUE; - double radius = HUGE_VAL; + double radius = LARGE_VAL; int nargs; int c; int Nside = 1; @@ -152,7 +152,7 @@ int main(int argc, char** args) { printf("]\n"); } - if (radius != HUGE_VAL) { + if (radius != LARGE_VAL) { il* hps; printf("Healpixes within radius %g degrees: [", radius); hps = healpix_rangesearch_xyz(xyz, radius, Nside, NULL); diff --git a/util/healpix.c b/util/healpix.c index 4b50bde92..23a31dddd 100644 --- a/util/healpix.c +++ b/util/healpix.c @@ -1435,8 +1435,8 @@ void healpix_radec_bounds(int hp, int nside, double ralo,rahi,declo,dechi; double ra,dec; double dx, dy; - ralo = declo = HUGE_VAL; - rahi = dechi = -HUGE_VAL; + ralo = declo = LARGE_VAL; + rahi = dechi = -LARGE_VAL; for (dy=0; dy<2; dy+=1.0) { for (dx=0; dx<2; dx+=1.0) { healpix_to_radecdeg(hp, nside, dx, dy, &ra, &dec); diff --git a/util/search-index.c b/util/search-index.c index 005a6956a..125d13f0d 100644 --- a/util/search-index.c +++ b/util/search-index.c @@ -16,6 +16,7 @@ #include "boilerplate.h" #include "tic.h" #include "fitstable.h" +#include "mathutil.h" static const char* OPTIONS = "hvr:d:R:o:"; @@ -33,7 +34,7 @@ void printHelp(char* progname) { int main(int argc, char **argv) { int argchar; - double ra=HUGE_VAL, dec=HUGE_VAL, radius=HUGE_VAL; + double ra=LARGE_VAL, dec=LARGE_VAL, radius=LARGE_VAL; int loglvl = LOG_MSG; char** myargs; int nmyargs; @@ -73,7 +74,7 @@ int main(int argc, char **argv) { printHelp(argv[0]); exit(-1); } - if (ra == HUGE_VAL || dec == HUGE_VAL || radius == HUGE_VAL) { + if (ra == LARGE_VAL || dec == LARGE_VAL || radius == LARGE_VAL) { printHelp(argv[0]); exit(-1); } diff --git a/util/sip_qfits.c b/util/sip_qfits.c index 9275e1f76..1cb3bbfac 100644 --- a/util/sip_qfits.c +++ b/util/sip_qfits.c @@ -16,8 +16,8 @@ #include "errors.h" #include "log.h" #include "ioutils.h" - #include "anqfits.h" +#include "mathutil.h" sip_t* sip_from_string(const char* str, int slen, sip_t* dest) { qfits_header* hdr; @@ -308,7 +308,7 @@ static anbool read_polynomial(const qfits_header* hdr, const char* format, anbool skip_linear, anbool skip_zero) { int i, j; char key[64]; - double nil = -HUGE_VAL; + double nil = -LARGE_VAL; double val; for (i=0; i<=order; i++) for (j=0; (i+j)<=order; j++) { diff --git a/util/sparsematrix.c b/util/sparsematrix.c index a9a242b60..7bdb1235a 100644 --- a/util/sparsematrix.c +++ b/util/sparsematrix.c @@ -8,6 +8,7 @@ #include "os-features.h" #include "sparsematrix.h" +#include "mathutil.h" struct entry { int c; @@ -178,7 +179,7 @@ void sparsematrix_subset_rows(sparsematrix_t* sp, const int* rows, int NR) { } double sparsematrix_max(const sparsematrix_t* sp) { - double mx = -HUGE_VAL; + double mx = -LARGE_VAL; FOR_EACH(sp, mx = MAX(mx, e->val)); /* FOR_EACH_DECL(); @@ -190,7 +191,7 @@ double sparsematrix_max(const sparsematrix_t* sp) { } double sparsematrix_argmax(const sparsematrix_t* sp, int* pr, int* pc) { - double mx = -HUGE_VAL; + double mx = -LARGE_VAL; FOR_EACH(sp, if (e->val > mx) { mx = e->val; *pr = r; *pc = e->c; }); return mx; } diff --git a/util/starutil.c b/util/starutil.c index 51aee4615..c13dcb117 100644 --- a/util/starutil.c +++ b/util/starutil.c @@ -135,12 +135,12 @@ double atora(const char* str) { if (!str) { //ERROR("Null string to atora()"); - return HUGE_VAL; + return LARGE_VAL; } rtn = parse_hms_string(str, &sgn, &hr, &min, &sec); if (rtn == -1) { ERROR("Failed to run regex"); - return HUGE_VAL; + return LARGE_VAL; } if (rtn == 0) return sgn * hms2ra(hr, min, sec); @@ -148,7 +148,7 @@ double atora(const char* str) { ra = strtod(str, &eptr); if (eptr == str) // no conversion - return HUGE_VAL; + return LARGE_VAL; return ra; } @@ -162,7 +162,7 @@ double atodec(const char* str) { rtn = parse_hms_string(str, &sgn, °, &min, &sec); if (rtn == -1) { ERROR("Failed to run regex"); - return HUGE_VAL; + return LARGE_VAL; } if (rtn == 0) return dms2dec(sgn, deg, min, sec); @@ -170,7 +170,7 @@ double atodec(const char* str) { dec = strtod(str, &eptr); if (eptr == str) // no conversion - return HUGE_VAL; + return LARGE_VAL; return dec; } diff --git a/util/starxy.c b/util/starxy.c index 15db94e57..e3564bd05 100644 --- a/util/starxy.c +++ b/util/starxy.c @@ -10,6 +10,7 @@ #include "os-features.h" #include "starxy.h" #include "permutedsort.h" +#include "mathutil.h" void starxy_set_xy_array(starxy_t* s, const double* xy) { int i,N; @@ -39,8 +40,8 @@ starxy_t* starxy_copy(starxy_t* s) { void starxy_compute_range(starxy_t* xy) { int i, N; - xy->xlo = xy->ylo = HUGE_VAL; - xy->xhi = xy->yhi = -HUGE_VAL; + xy->xlo = xy->ylo = LARGE_VAL; + xy->xhi = xy->yhi = -LARGE_VAL; N = starxy_n(xy); for (i=0; ixlo = MIN(xy->xlo, starxy_getx(xy, i)); diff --git a/util/wcs-rd2xy-main.c b/util/wcs-rd2xy-main.c index b4856d8bf..2094d7cdd 100644 --- a/util/wcs-rd2xy-main.c +++ b/util/wcs-rd2xy-main.c @@ -16,6 +16,7 @@ #include "anwcs.h" #include "errors.h" #include "log.h" +#include "mathutil.h" const char* OPTIONS = "hi:o:w:f:R:D:te:r:d:Lv"; @@ -48,7 +49,7 @@ int main(int argc, char** args) { anbool forcetan = FALSE; il* fields; int ext = 0; - double ra=HUGE_VAL, dec=HUGE_VAL; + double ra=LARGE_VAL, dec=LARGE_VAL; anbool wcslib = FALSE; int loglvl = LOG_MSG; @@ -105,7 +106,7 @@ int main(int argc, char** args) { exit(-1); } - if (!(wcsfn && ((rdlsfn && xylsfn) || ((ra != HUGE_VAL) && (dec != HUGE_VAL))))) { + if (!(wcsfn && ((rdlsfn && xylsfn) || ((ra != LARGE_VAL) && (dec != LARGE_VAL))))) { print_help(args[0]); exit(-1); } diff --git a/util/wcs-resample.c b/util/wcs-resample.c index 44a8fed6b..3900d5a39 100644 --- a/util/wcs-resample.c +++ b/util/wcs-resample.c @@ -22,6 +22,7 @@ #include "fitsioutils.h" #include "anwcs.h" #include "resample.h" +#include "mathutil.h" int resample_wcs_files(const char* infitsfn, int infitsext, const char* inwcsfn, int inwcsext, @@ -104,16 +105,16 @@ int resample_wcs_files(const char* infitsfn, int infitsext, double pmin, pmax; int i; /* - pmin = HUGE_VAL; - pmax = -HUGE_VAL; + pmin = LARGE_VAL; + pmax = -LARGE_VAL; for (i=0; i<(inW*inH); i++) { pmin = MIN(pmin, inimg[i]); pmax = MAX(pmax, inimg[i]); } logmsg("Input image bounds: %g to %g\n", pmin, pmax); */ - pmin = HUGE_VAL; - pmax = -HUGE_VAL; + pmin = LARGE_VAL; + pmax = -LARGE_VAL; for (i=0; i<(outW*outH); i++) { pmin = MIN(pmin, outimg[i]); pmax = MAX(pmax, outimg[i]); @@ -236,8 +237,8 @@ int resample_wcs(const anwcs_t* inwcs, const float* inimg, int inW, int inH, double xmin, xmax, ymin, ymax; int x, y, W, H; double xx,yy; - xmin = ymin = HUGE_VAL; - xmax = ymax = -HUGE_VAL; + xmin = ymin = LARGE_VAL; + xmax = ymax = -LARGE_VAL; // HACK -- just look at the corners. Could anwcs_walk_boundary. W = anwcs_imagew(inwcs); H = anwcs_imageh(inwcs); diff --git a/util/wcs-to-tan.c b/util/wcs-to-tan.c index 4bae910e1..25d696baa 100644 --- a/util/wcs-to-tan.c +++ b/util/wcs-to-tan.c @@ -45,8 +45,8 @@ int main(int argc, char** args) { anbool forcewcslib = FALSE; double xlo = 1; double ylo = 1; - double xhi = HUGE_VAL; - double yhi = HUGE_VAL; + double xhi = LARGE_VAL; + double yhi = LARGE_VAL; int N = 20; double* xyz = NULL; @@ -128,20 +128,20 @@ int main(int argc, char** args) { anwcs_print(inwcs, log_get_fid()); } - if (xhi == HUGE_VAL) { + if (xhi == LARGE_VAL) { xhi = anwcs_imagew(inwcs); logverb("Setting image width to %g\n", xhi); } - if (yhi == HUGE_VAL) { + if (yhi == LARGE_VAL) { yhi = anwcs_imageh(inwcs); logverb("Setting image height to %g\n", yhi); } // FIXME -- what if the user wants xhi or yhi == 0? - if (xhi == HUGE_VAL || xhi == 0) { + if (xhi == LARGE_VAL || xhi == 0) { ERROR("Couldn't find the image size; please supply -W\n"); exit(-1); } - if (yhi == HUGE_VAL || yhi == 0) { + if (yhi == LARGE_VAL || yhi == 0) { ERROR("Couldn't find the image size; please supply -H\n"); exit(-1); } diff --git a/util/wcs-xy2rd-main.c b/util/wcs-xy2rd-main.c index 4cd46f092..c83792e6f 100644 --- a/util/wcs-xy2rd-main.c +++ b/util/wcs-xy2rd-main.c @@ -18,6 +18,7 @@ #include "errors.h" #include "wcs-xy2rd.h" #include "log.h" +#include "mathutil.h" const char* OPTIONS = "hi:o:w:f:R:D:te:x:y:X:Y:LTvs"; @@ -59,7 +60,7 @@ int main(int argc, char** args) { double x, y; int loglvl = LOG_MSG; - x = y = HUGE_VAL; + x = y = LARGE_VAL; fields = il_new(16); while ((c = getopt(argc, args, OPTIONS)) != -1) { @@ -119,7 +120,7 @@ int main(int argc, char** args) { exit(-1); } - if (!(wcsfn && ((rdlsfn && xylsfn) || ((x != HUGE_VAL) && (y != HUGE_VAL))))) { + if (!(wcsfn && ((rdlsfn && xylsfn) || ((x != LARGE_VAL) && (y != LARGE_VAL))))) { print_help(args[0]); exit(-1); }