IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 20, 2014, 5:38:01 PM (12 years ago)
Author:
watersc1
Message:

Addition of a -show mode to detselect, which displays a catalog of detrends for a specified camera/telescope. The return catalog lists the constraints on the use of this detrend. It does not filter out superceded detrends, although they are sorted in descending order, so the first in the list that matches the image constraints is the one detselect -search would yield.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/detselect.c

    r31058 r36543  
    2929static bool searchMode(pxConfig *config);
    3030static bool selectMode(pxConfig *config);
     31static bool showMode(pxConfig *config);
     32
    3133
    3234# define MODECASE(caseName, func) \
     
    5052        MODECASE(DETSELECT_MODE_SEARCH,        searchMode);
    5153        MODECASE(DETSELECT_MODE_SELECT,        selectMode);
     54        MODECASE(DETSELECT_MODE_SHOW,          showMode);
    5255        default:
    5356            psAbort("invalid option (this should not happen)");
     
    241244    return true;
    242245}
     246
     247static bool showMode(pxConfig *config)
     248{
     249    PS_ASSERT_PTR_NON_NULL(config, false);
     250
     251    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     252
     253    psMetadata *where = psMetadataAlloc();
     254
     255    PXOPT_COPY_STR(config->args, where, "-inst",      "camera", "==");
     256    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
     257    PXOPT_COPY_STR(config->args, where, "-det_type",  "det_type", "==");
     258    PXOPT_COPY_STR(config->args, where, "-type",      "det_type", "==");
     259
     260    psString query = pxDataGet("detselect_show.sql");
     261    if (!query) {
     262        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     263        return false;
     264    }
     265
     266    // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE
     267    if (where && psListLength(where->list)) {
     268        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     269        psStringAppend(&query, " AND %s", whereClause);
     270        psFree(whereClause);
     271    }
     272    psFree(where);
     273
     274    // we choose the single detrend image which matches all criteria and has
     275    // the latest insertion date
     276
     277    psStringAppend(&query, " ORDER BY registered DESC, iteration DESC, time_begin, time_end");
     278
     279    if (!p_psDBRunQuery(config->dbh, query)) {
     280        psError(PS_ERR_UNKNOWN, false, "database error");
     281        psFree(query);
     282        return false;
     283    }
     284    psFree(query);
     285
     286    psArray *output = p_psDBFetchResult(config->dbh);
     287    if (!output) {
     288        psError(PS_ERR_UNKNOWN, false, "database error");
     289        return false;
     290    }
     291    if (!psArrayLength(output)) {
     292        // XXX check psError here
     293        psError(PS_ERR_UNKNOWN, false, "no detRun rows found");
     294        psFree(output);
     295        return true;
     296    }
     297
     298    // negative simple so the default is true
     299    if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) {
     300        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     301        psFree(output);
     302        return false;
     303    }
     304
     305    psFree(output);
     306    return(true);
     307}
Note: See TracChangeset for help on using the changeset viewer.