IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 11, 2012, 2:04:31 PM (13 years ago)
Author:
watersc1
Message:

Merge from my branch including background restoration and stack stage projection cell binned images.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/ippTools/src

  • trunk/ippTools/src/stacktool.c

    r34731 r34800  
    3737static bool inputskyfileMode(pxConfig *config);
    3838static bool tosumMode(pxConfig *config);
     39static bool tobkgMode(pxConfig *config);
    3940static bool addsumskyfileMode(pxConfig *config);
    4041static bool sumskyfileMode(pxConfig *config);
     
    7677        MODECASE(STACKTOOL_MODE_INPUTSKYFILE,          inputskyfileMode);
    7778        MODECASE(STACKTOOL_MODE_TOSUM,                 tosumMode);
     79        MODECASE(STACKTOOL_MODE_TOBKG,                 tobkgMode);
    7880        MODECASE(STACKTOOL_MODE_ADDSUMSKYFILE,         addsumskyfileMode);
    7981        MODECASE(STACKTOOL_MODE_SUMSKYFILE,            sumskyfileMode);
     
    952954        // negative simple so the default is true
    953955        if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) {
     956            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     957            psFree(output);
     958            return false;
     959        }
     960    }
     961
     962    psFree(output);
     963
     964    return true;
     965}
     966
     967static bool tobkgMode(pxConfig *config)
     968{
     969    PS_ASSERT_PTR_NON_NULL(config, false);
     970
     971    psMetadata *where = psMetadataAlloc();
     972    PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
     973    pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
     974
     975    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     976    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     977
     978    psString query = pxDataGet("stacktool_tobkg.sql");
     979    if (!query) {
     980        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     981        return false;
     982    }
     983
     984    psString whereClause = psStringCopy(""); // WHERE conditions to add
     985    if (psListLength(where->list)) {
     986        psString new = psDBGenerateWhereConditionSQL(where, NULL);
     987        psStringAppend(&whereClause, "\nAND %s", new);
     988        psFree(new);
     989    }
     990    psFree(where);
     991
     992    psStringAppend(&query, "\nORDER by priority DESC, stack_id");
     993
     994    // treat limit == 0 as "no limit"
     995    if (limit) {
     996        psString limitString = psDBGenerateLimitSQL(limit);
     997        psStringAppend(&query, " %s", limitString);
     998        psFree(limitString);
     999    }
     1000
     1001    if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
     1002        psError(PS_ERR_UNKNOWN, false, "database error");
     1003        psFree(query);
     1004        return false;
     1005    }
     1006    psFree(query);
     1007
     1008    psArray *output = p_psDBFetchResult(config->dbh);
     1009    if (!output) {
     1010        psErrorCode err = psErrorCodeLast();
     1011        switch (err) {
     1012            case PS_ERR_DB_CLIENT:
     1013                psError(PXTOOLS_ERR_SYS, false, "database error");
     1014            case PS_ERR_DB_SERVER:
     1015                psError(PXTOOLS_ERR_PROG, false, "database error");
     1016            default:
     1017                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1018        }
     1019
     1020        return false;
     1021    }
     1022    if (!psArrayLength(output)) {
     1023        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1024        psFree(output);
     1025        return true;
     1026    }
     1027
     1028    if (psArrayLength(output)) {
     1029        // negative simple so the default is true
     1030        if (!ippdbPrintMetadatas(stdout, output, "stackBkgSkyfile", !simple)) {
    9541031            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    9551032            psFree(output);
     
    16811758    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    16821759    PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false);
     1760    PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false);
    16831761
    16841762    psMetadata *where = psMetadataAlloc();
    16851763    PXOPT_COPY_S64(config->args, where, "-stack_id",   "stack_id",   "==");
    16861764
    1687     if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
     1765    if (background_model) {
     1766      psMetadata *values = psMetadataAlloc();
     1767      PXOPT_COPY_S16(config->args, values, "-set_background_model", "background_model", "==");
     1768      long rows = psDBUpdateRows(config->dbh,"stackSumSkyfile", where, values);
     1769      psFree(values);
     1770      if (!rows) {
     1771        // This maybe should rollback and error if rows != 1
     1772        psError(PS_ERR_UNKNOWN, true, "no rows changed");
     1773        return false;
     1774      }
     1775    }
     1776    else {   
     1777      if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
    16881778        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    16891779        psFree (where);
    16901780        return false;
     1781      }
    16911782    }
    16921783    psFree (where);
Note: See TracChangeset for help on using the changeset viewer.