IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 5, 2008, 2:07:07 PM (18 years ago)
Author:
eugene
Message:

updates from HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/ippTools/src/stacktool.c

    r18659 r18923  
    107107    psMetadata *whereRE = psMetadataAlloc(); // rawExp where
    108108    psMetadata *whereWSF = psMetadataAlloc(); // warpSkyfile where
    109     psMetadata *having = psMetadataAlloc(); // having
     109    psMetadata *having = psMetadataAlloc(); // HAVING clause
    110110    // map -inst -> camera, etc
    111111    PXOPT_COPY_STR(config->args, whereRE, "-select_inst", "camera", "==");
     
    128128
    129129    PXOPT_COPY_STR(config->args, having, "-select_skycell_id", "skycell_id", "==");
     130    PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">=");
    130131
    131132    PXOPT_LOOKUP_S32(randomLimit, config->args, "-random", false, false);
    132133
    133     PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">=");
    134     PXOPT_COPY_S32(config->args, having, "-min_new", "(num_warp - num_stack)", ">=");
    135 
     134    PXOPT_LOOKUP_S32(min_new, config->args, "-min_new", false, false);
    136135    PXOPT_LOOKUP_F32(min_frac, config->args, "-min_frac", false, false);
    137136
     
    178177    psFree(groupby);
    179178
    180     if (psListLength(having->list)) {
    181         psString havingClause = psDBGenerateWhereConditionSQL(having, NULL);
    182         psStringAppend(&select, " HAVING %s", havingClause);
    183         psFree(havingClause);
    184     }
    185 
    186     // Gotta handle this one explicitly --- want to avoid divisions
    187     if (isfinite(min_frac)) {
     179    // Restriction on aggregated quantities using HAVING
     180    {
     181        psString havingClause = NULL;   // HAVING string
    188182        if (psListLength(having->list)) {
    189             psStringAppend(&select, " AND");
    190         } else {
    191             psStringAppend(&select, " HAVING");
    192         }
    193         psStringAppend(&select, " num_warp >= %f * num_stack", (double)min_frac);
    194     }
    195 
     183            havingClause = psDBGenerateWhereConditionSQL(having, NULL);
     184        }
     185
     186        if (min_new > 0) {
     187            if (havingClause) {
     188                psStringAppend(&havingClause, " AND");
     189            }
     190            psStringAppend(&havingClause,
     191                           " (num_warp - num_stack >= %d OR (num_warp >= %d AND num_stack IS NULL))",
     192                           min_new, min_new);
     193        }
     194        if (isfinite(min_frac)) {
     195            if (havingClause) {
     196                psStringAppend(&havingClause, " AND");
     197            }
     198            // Avoiding division by zero
     199            psStringAppend(&havingClause, " (num_warp >= %f * num_stack OR num_stack IS NULL)",
     200                           (double)min_frac);
     201        }
     202        if (havingClause) {
     203            psStringAppend(&select, " HAVING %s", havingClause);
     204            psFree(havingClause);
     205        }
     206    }
    196207    psFree(having);
     208
    197209
    198210    if (!p_psDBRunQuery(config->dbh, select)) {
     
    239251    }
    240252
     253    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
    241254    for (long i = 0; i < output->n; i++) {
    242255        psMetadata *row = output->data[i]; // Row from select
     
    249262            psFree(output);
    250263            psFree(insert);
     264            psFree(list);
    251265            if (!psDBRollback(config->dbh)) {
    252266                psError(PS_ERR_UNKNOWN, false, "database error");
     
    260274            psFree(output);
    261275            psFree(insert);
     276            psFree(list);
    262277            if (!psDBRollback(config->dbh)) {
    263278                psError(PS_ERR_UNKNOWN, false, "database error");
     
    271286            psFree(output);
    272287            psFree(insert);
     288            psFree(list);
    273289            if (!psDBRollback(config->dbh)) {
    274290                psError(PS_ERR_UNKNOWN, false, "database error");
     
    296312            psFree(run);
    297313            psFree(insert);
     314            psFree(list);
    298315            if (!psDBRollback(config->dbh)) {
    299316                psError(PS_ERR_UNKNOWN, false, "database error");
     
    306323        run->stack_id = stack_id;
    307324
    308         if (!stackRunPrintObject(stdout, run, !simple)) {
    309             psError(PS_ERR_UNKNOWN, false, "failed to print object");
    310             psFree(run);
    311             psFree(insert);
    312             if (!psDBRollback(config->dbh)) {
    313                 psError(PS_ERR_UNKNOWN, false, "database error");
    314             }
    315             return false;
    316         }
     325        psArrayAdd(list, list->n, run);
    317326        psFree(run);
    318327
     
    331340            psFree(insert);
    332341            psFree(output);
     342            psFree(list);
    333343            if (!psDBRollback(config->dbh)) {
    334344                psError(PS_ERR_UNKNOWN, false, "database error");
     
    338348        psFree(thisInsert);
    339349    }
     350    psFree(output);
    340351
    341352    if (!psDBCommit(config->dbh)) {
    342353        psError(PS_ERR_UNKNOWN, false, "database error");
    343         return false;
    344     }
    345 
    346     psFree(output);
     354        psFree(list);
     355        return false;
     356    }
     357
     358    if (!stackRunPrintObjects(stdout, list, !simple)) {
     359        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     360        return false;
     361    }
     362
     363    psFree(list);
    347364
    348365    return true;
Note: See TracChangeset for help on using the changeset viewer.