IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9967


Ignore:
Timestamp:
Nov 13, 2006, 4:00:40 PM (20 years ago)
Author:
jhoblitt
Message:

modernize pztool -seen

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

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

    r9735 r9967  
    3232static bool pendingMode(pxConfig *config);
    3333static bool copydoneMode(pxConfig *config);
    34 static bool summitExpPrint(FILE *stream, summitExpRow *summitExp);
     34
    3535static psArray *pztoolPendingExp(pxConfig *config);
    3636static psArray *pztoolPendingImfiles(pxConfig *config);
     
    7878    PS_ASSERT_PTR_NON_NULL(config, false);
    7979
    80     psArray *summit = summitExpSelectRowObjects(config->dbh,
    81         config->where, MAX_ROWS);
    82     if (!summit) {
    83         psError(PS_ERR_UNKNOWN, false, "no summitExp rows found"); \
    84         return false;
    85     }
    86 
    87     psArray *new = newExpSelectRowObjects(config->dbh,
    88         config->where, MAX_ROWS);
    89     if (!new) {
    90         psError(PS_ERR_UNKNOWN, false, "no newExp rows found"); \
    91     }
    92 
    93     if (new) {
    94         for (long i = 0; i < summit->n; i++) {
    95             summitExpRow *summitExp = summit->data[i];
    96             for (long j = 0; j < summit->n; j++) {
    97                 newExpRow *newExp = new->data[j];
    98                 if (strcmp(summitExp->exp_id, newExp->exp_id) == 0) {
    99                     psArrayRemoveData(summit, summitExp);
    100                     // dec the counter as the array just got shorter
    101                     //and we don't want to skip elemnts
    102                     i--;
    103                     break;
    104                 }
    105             }
    106         }
    107         psFree(new);
    108     }
    109 
    110     for (long i = 0; i < summit->n; i++) {
    111         if (!summitExpPrint(stdout, summit->data[i])) {
    112             psError(PS_ERR_UNKNOWN, false,"summitExpPrint() failed");
     80    psString query = psStringCopy(
     81        "SELECT"
     82        "    summitExp.*"
     83        " FROM summitExp"
     84        " LEFT JOIN newExp"
     85        "   USING(exp_id, camera, telescope)"
     86        " WHERE"
     87        "   newExp.exp_id is NULL"
     88        "   AND newExp.camera IS NULL"
     89        "   AND newExp.telescope IS NULL"
     90    );
     91
     92    if (config->where) {
     93        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "newExp");
     94        psStringAppend(&query, " AND %s", whereClause);
     95        psFree(whereClause);
     96    }
     97
     98    if (!p_psDBRunQuery(config->dbh, query)) {
     99        psError(PS_ERR_UNKNOWN, false, "database error");
     100        psFree(query);
     101        return false;
     102    }
     103    psFree(query);
     104
     105    psArray *output = p_psDBFetchResult(config->dbh);
     106    if (!output) {
     107        psError(PS_ERR_UNKNOWN, false, "database error");
     108        return false;
     109    }
     110    if (!psArrayLength(output)) {
     111        psError(PS_ERR_UNKNOWN, false, "no newExp rows found");
     112        psFree(output);
     113        return true;
     114    }
     115
     116    bool simple = false;
     117    {
     118        bool status = false;
     119        simple = psMetadataLookupBool(&status, config->args, "-simple");
     120        if (!status) {
     121            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    113122            return false;
    114123        }
    115124    }
     125
     126    // negative simple so the default is true
     127    if (!ippdbPrintMetadatas(stdout, output, "newExp", !simple)) {
     128        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     129        psFree(output);
     130        return false;
     131    }
     132
     133    psFree(output);
    116134
    117135    return true;
     
    201219
    202220    return false;
    203 }
    204 
    205 static bool summitExpPrint(FILE *stream, summitExpRow *summitExp)
    206 {
    207     PS_ASSERT_PTR_NON_NULL(stream, false);
    208     PS_ASSERT_PTR_NON_NULL(summitExp, false);
    209 
    210     fprintf(stream, "%s %s %s %s %s\n",
    211         summitExp->exp_id,
    212         summitExp->camera,
    213         summitExp->telescope,
    214         summitExp->exp_type,
    215         summitExp->uri
    216     );
    217 
    218     return true;
    219221}
    220222
  • trunk/ippTools/src/pztoolConfig.c

    r9392 r9967  
    4242    // -seen
    4343    psMetadata *seenArgs = psMetadataAlloc();
    44     psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_tag",  0,
    45         "define exposure ID", NULL);
    46     psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst",  0,
    47         "define camera ID", NULL);
    48     psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-telescope",  0,
    49         "define telescope ID", NULL);
    50     psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_type",  0,
    51         "define exposure type", NULL);
     44    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_tag", 0,
     45            "define exposure ID", NULL);
     46    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst", 0,
     47            "define camera ID", NULL);
     48    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-telescope", 0,
     49            "define telescope ID", NULL);
     50    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_type", 0,
     51            "define exposure type", NULL);
     52    psMetadataAddBool(seenArgs, PS_LIST_TAIL, "-simple", 0,
     53            "use the simple output format", false);
    5254   
    5355    // -pending
    5456    psMetadata *pendingArgs = psMetadataAlloc();
    55     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_tag",  0,
    56         "define exposure ID", NULL);
    57     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-inst",  0,
    58         "define camera ID", NULL);
    59     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-telescope",  0,
    60         "define telescope ID", NULL);
    61     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_type",  0,
    62         "define exposure type", NULL);
     57    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_tag", 0,
     58            "define exposure ID", NULL);
     59    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-inst", 0,
     60            "define camera ID", NULL);
     61    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-telescope", 0,
     62            "define telescope ID", NULL);
     63    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_type", 0,
     64            "define exposure type", NULL);
    6365
    6466    // -copydone
    6567    psMetadata *copydoneArgs = psMetadataAlloc();
    66     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_tag",  0,
    67         "define exposure ID", NULL);
    68     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class",  0,
    69         "define class", NULL);
    70     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class_id",  0,
    71         "define class_id", NULL);
    72     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-suri",  0,
    73         "define storage uri", NULL);
     68    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_tag", 0,
     69            "define exposure ID", NULL);
     70    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class", 0,
     71            "define class", NULL);
     72    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class_id", 0,
     73            "define class_id", NULL);
     74    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-suri", 0,
     75            "define storage uri", NULL);
    7476
    7577#define PXTOOL_MODE(option, modeval, argset) \
     
    8082        if (config->mode) { \
    8183            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); \
     84            goto FAIL; \
    8285        } \
    8386        config->mode = modeval; \
    8487        config->args = psMemIncrRefCounter(argset); \
    8588    } \
     89    if (!psMetadataAddMetadata(argSets, PS_LIST_TAIL, option, 0, NULL, argset)) {;\
     90        psError(PS_ERR_UNKNOWN, false, "failed to add argset for %s", option); \
     91    } \
     92    psFree(argset); \
    8693}
    8794
     95    psMetadata *argSets = psMetadataAlloc();
     96    // find which mode we're running under
    8897    PXTOOL_MODE("-seen",            PZTOOL_MODE_SEEN,         seenArgs);
    8998    PXTOOL_MODE("-pending",         PZTOOL_MODE_PENDING,      pendingArgs);
     
    100109
    101110    if (argErr) {
    102         printf("\nPan-STARRS Phase Z Search Tool\n");
     111        printf("\nPan-STARRS Detrend Tool\n");
    103112        printf("Usage: %s <mode> [<options>]\n\n", argv[0]);
    104         printf(" <mode> : -seen | -pending | -copydone\n\n");
     113        printf(" <mode> :\n\n");
    105114
    106         fprintf (stdout, "-seen ");
    107         psArgumentHelp(seenArgs);
    108         psFree(seenArgs);
     115        psMetadataIterator *iter = psMetadataIteratorAlloc(argSets, 0, NULL);
     116        psMetadataItem *item = NULL;
     117        while ((item = psMetadataGetAndIncrement(iter))) {
     118            if (!item->type == PS_DATA_METADATA) {
     119                psAbort(argv[0], "all options must be specified as a metadata");
     120            }
    109121
    110         fprintf (stdout, "-pending ");
    111         psArgumentHelp(pendingArgs);
    112         psFree(pendingArgs);
     122            fprintf(stdout, "%s ", item->name);
     123            psArgumentHelp(item->data.md);
     124        }
     125        psFree(iter);
    113126
    114         fprintf (stdout, "-copydone ");
    115         psArgumentHelp(copydoneArgs);
    116         psFree(copydoneArgs);
    117 
     127        psFree(argSets);
    118128        goto FAIL;
    119129    }
    120130
    121     psFree(seenArgs);
    122     psArgumentHelp(pendingArgs);
    123     psFree(copydoneArgs);
     131    psFree(argSets);
    124132
    125133    // setup search criterion
Note: See TracChangeset for help on using the changeset viewer.