IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 1, 2007, 3:09:33 PM (19 years ago)
Author:
jhoblitt
Message:

add p2tool -queuerawexp

File:
1 edited

Legend:

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

    r11138 r11562  
    2929#include "p2tool.h"
    3030
     31static bool queuerawexpMode(pxConfig *config);
    3132static bool pendingimfileMode(pxConfig *config);
    3233static bool addprocessedimfileMode(pxConfig *config);
     
    5556
    5657    switch (config->mode) {
     58        MODECASE(P2TOOL_MODE_QUEUERAWEXP,           queuerawexpMode);
    5759        MODECASE(P2TOOL_MODE_PENDINGIMFILE,         pendingimfileMode);
    5860        MODECASE(P2TOOL_MODE_ADDPROCESSEDIMFILE,    addprocessedimfileMode);
     
    8284}
    8385
     86#define ADDPARAMSTR(from, to, name) \
     87{ \
     88    bool status = false; \
     89    psString str = psMetadataLookupStr(&status, from, "-" name); \
     90    if (!status) { \
     91        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \
     92        return false; \
     93    } \
     94    if (str) { \
     95        if (!psMetadataAddStr(to, PS_LIST_TAIL, name, 0, "==", str)) { \
     96            psError(PS_ERR_UNKNOWN, false, "failed to add item " name); \
     97            psFree(to); \
     98            return false; \
     99        } \
     100    } \
     101}
     102
     103
     104#define ADDPARAMF(from, to, type, name) \
     105{ \
     106    bool status = false; \
     107    ps##type var = psMetadataLookup##type(&status, from, "-" #name); \
     108    if (!status) { \
     109        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \
     110        return false; \
     111    } \
     112    if (!isnan(var)) { \
     113        if (!psMetadataAdd##type(to, PS_LIST_TAIL, #name, 0, "==", var)) { \
     114            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
     115            psFree(to); \
     116            return false; \
     117        } \
     118    } \
     119}
     120
     121
     122static bool queuerawexpMode(pxConfig *config)
     123{
     124    PS_ASSERT_PTR_NON_NULL(config, NULL);
     125
     126    psMetadata *where = psMetadataAlloc();
     127    ADDPARAMSTR(config->args, where, "exp_tag");
     128    ADDPARAMSTR(config->args, where, "exp_id");
     129    ADDPARAMSTR(config->args, where, "inst");
     130    ADDPARAMSTR(config->args, where, "telescope");
     131    ADDPARAMSTR(config->args, where, "dateobs");
     132    ADDPARAMSTR(config->args, where, "exp_type");
     133    ADDPARAMSTR(config->args, where, "imfiles");
     134    ADDPARAMSTR(config->args, where, "workdir");
     135    ADDPARAMSTR(config->args, where, "filter");
     136    ADDPARAMF(config->args, where, F32, "airmass");
     137    ADDPARAMF(config->args, where, F32, "ra");
     138    ADDPARAMF(config->args, where, F32, "decl");
     139    ADDPARAMF(config->args, where, F32, "exp_time");
     140    ADDPARAMF(config->args, where, F64, "bg");
     141    ADDPARAMF(config->args, where, F64, "bg_stdev");
     142    ADDPARAMF(config->args, where, F64, "bg_mean_stdev");
     143    ADDPARAMF(config->args, where, F64, "alt");
     144    ADDPARAMF(config->args, where, F64, "az");
     145    ADDPARAMF(config->args, where, F32, "ccd_temp");
     146    ADDPARAMF(config->args, where, F64, "posang");
     147    ADDPARAMSTR(config->args, where, "object");
     148
     149    if (config->where->list->n < 1) {
     150        psFree(config->where);
     151        config->where = NULL;
     152    }
     153
     154    bool status = false;
     155    psString label = psMetadataLookupStr(&status, config->args, "-set_label");
     156    if (!status) {
     157        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_label");
     158        return false;
     159    }
     160
     161    // XXX this does not work!!!
     162    psString query = psStringCopy(
     163            "INSERT INTO p2PendingExp\n"
     164            "   SElECT\n"
     165            "       exp_tag,\n"
     166            "       'my recipe',\n"  // recipe
     167            "       255\n"         // p1_version
     168            "       255\n"         // p2_version
     169            "       %s\n"
     170            "   FROM rawExp"
     171            "   LEFT JOIN p2ProcessedExp"
     172            "       USING(exp_tag)"
     173            "   WHERE"
     174            "       rawExp.fault = 0"
     175        );
     176
     177    if (config->where) {
     178        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawExp");
     179        psStringAppend(&query, " AND %s", whereClause);
     180        psFree(whereClause);
     181    }
     182
     183    if (!p_psDBRunQuery(config->dbh, query, label ? label : "NULL")) {
     184        psError(PS_ERR_UNKNOWN, false, "database error");
     185        psFree(query);
     186        return false;
     187    }
     188    psFree(query);
     189
     190    psArray *output = p_psDBFetchResult(config->dbh);
     191    if (!output) {
     192        psError(PS_ERR_UNKNOWN, false, "database error");
     193        return false;
     194    }
     195    if (!psArrayLength(output)) {
     196        // XXX check psError here
     197        psError(PS_ERR_UNKNOWN, false, "no p2PendingImfile rows found");
     198        psFree(output);
     199        return false;
     200    }
     201
     202    return true;
     203}
    84204
    85205static bool pendingimfileMode(pxConfig *config)
Note: See TracChangeset for help on using the changeset viewer.