IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2006, 3:59:22 PM (20 years ago)
Author:
jhoblitt
Message:

impliment -runs

File:
1 edited

Legend:

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

    r7243 r7247  
    44
    55#include <stdlib.h>
     6#include <metadatadb.h>
    67
    78#include "pxtools.h"
     
    910
    1011static bool defineMode(pxConfig *config);
     12static bool runsMode(pxConfig *config);
    1113static bool rawMode(pxConfig *config);
    1214static bool addprocMode(pxConfig *config);
     
    3133        case DETTOOL_MODE_DEFINE:
    3234            if (!defineMode(config)) {
     35                goto FAIL;
     36            }
     37            break;
     38        case DETTOOL_MODE_RUNS:
     39            if (!runsMode(config)) {
    3340                goto FAIL;
    3441            }
     
    163170    // print the new det_id
    164171    printf("%ld\n", det_id);
     172
     173    return true;
     174}
     175
     176static bool runsMode(pxConfig *config)
     177{
     178    PS_ASSERT_PTR_NON_NULL(config, false);
     179
     180//    psArray *runs = detRunSelectRowObjects(config->dbh, config->where, 0);
     181    // XXX fix the hard coding of the table name
     182    psArray *runs = psDBSelectRows(config->dbh, "detRun", config->where, 0);
     183    if (!runs) {
     184        psError(PS_ERR_UNKNOWN, false, "no detRun rows found");
     185        return false;
     186    }
     187
     188    // print imfile list
     189    psMetadata *output = psMetadataAlloc();
     190    for (long i = 0; i < psArrayLength(runs); i++) {
     191        psMetadata *run = runs->data[i];
     192        psMetadata *md = psMetadataAlloc();
     193        bool status = false;
     194        // we need to change "position" to "det_id"
     195        // lookup values
     196        psS32 det_id = psMetadataLookupS32(&status, run, "position");
     197        if (!status) {
     198            psError(PS_ERR_UNKNOWN, false,
     199                    "failed to lookup value for position");
     200            psFree(output);
     201            psFree(md);
     202            psFree(runs);
     203            return false;
     204        }
     205        psString det_type = psMetadataLookupStr(&status, run, "det_type");
     206        if (!status) {
     207            psError(PS_ERR_UNKNOWN, false,
     208                    "failed to lookup value for det_type");
     209            psFree(output);
     210            psFree(md);
     211            psFree(runs);
     212            return false;
     213        }
     214        // add values
     215        if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", PS_META_DUPLICATE_OK,
     216                NULL, det_id)) {
     217            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
     218            psFree(output);
     219            psFree(md);
     220            psFree(runs);
     221            return false;
     222        }
     223        if (!psMetadataAddStr(md, PS_LIST_TAIL, "det_type",
     224                    PS_META_DUPLICATE_OK, NULL, det_type)) {
     225            psError(PS_ERR_UNKNOWN, false, "failed to add item det_type");
     226            psFree(output);
     227            psFree(md);
     228            psFree(runs);
     229            return false;
     230        }
     231        psMetadataAddMetadata(
     232            output, PS_LIST_TAIL, "detRun", PS_META_DUPLICATE_OK, NULL, md
     233        );
     234    }
     235
     236    psString str = psMetadataConfigFormat(output);
     237    psFree(output);
     238    fprintf(stdout, "%s\n", str);
     239    psFree(str);
     240
     241    psFree(runs);
    165242
    166243    return true;
Note: See TracChangeset for help on using the changeset viewer.