IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2014, 11:03:38 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20140206
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140206

  • branches/eam_branches/ipp-20140206/ippTools/src

    • Property svn:ignore
      •  

        old new  
        4848releasetool
        4949fftool
         50remotetool
         51
  • branches/eam_branches/ipp-20140206/ippTools/src/detselect.c

    r31058 r36627  
    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");
     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.