IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 25, 2006, 5:11:15 PM (20 years ago)
Author:
jhoblitt
Message:

add -pending support (without search)

File:
1 edited

Legend:

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

    r6981 r6991  
    99
    1010static bool pendingMode(pxConfig *config);
    11 static bool updateMode(pxConfig *config);
    12 static psArray *newFrameSearchPending(pxConfig *config);
    13 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp);
    14 static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp);
     11static bool defineMode(pxConfig *config);
     12static p1PendingExpRow *rawScienceTop1PendingExp(rawScienceExpRow *raw);
    1513
    1614int main(int argc, char **argv)
     
    2422            }
    2523            break;
    26         case PX_MODE_UPDATE:
    27             if (!updateMode(config)) {
     24        case PX_MODE_DEFINE:
     25            if (!defineMode(config)) {
    2826                goto FAIL;
    2927            }
     
    4442    PS_ASSERT_PTR_NON_NULL(config, false);
    4543
    46     psArray *new = newFrameSearchPending(config);
    47     if (!new) {
    48         psError(PS_ERR_UNKNOWN, false, "no newFrames found");
     44    psArray *p1PendingExp = p1PendingExpSelectRowObjects(config->dbh, NULL, 0);
     45    if (!p1PendingExp) {
     46        psError(PS_ERR_UNKNOWN, false, "no p1PendingExp found");
    4947        return false;
    5048    }
    5149
    52     bool status = newFramePrint(stdout, config, new);
    53     if (!status) {
    54         psError(PS_ERR_UNKNOWN, false,"newFramePrint() failed");
    55         return false;
     50    psMetadata *output = psMetadataAlloc();
     51
     52    for (long i = 0; i < psArrayLength(p1PendingExp); i++) {
     53        psMetadata *md = p1PendingExpMetadataFromObject(p1PendingExp->data[i]);
     54        psMetadataAddMetadata(output, PS_LIST_TAIL, "p1PendingExp",
     55            PS_META_DUPLICATE_OK, NULL, md);
     56        psFree(md);
    5657    }
     58
     59    psString str = psMetadataConfigFormat(output);
     60    psFree(output);
     61
     62    fprintf(stdout, "%s\n", str);
     63    psFree(str);
    5764
    5865    return true;
    5966}
    6067
    61 static bool updateMode(pxConfig *config)
     68static bool defineMode(pxConfig *config)
    6269{
    6370    PS_ASSERT_PTR_NON_NULL(config, false);
    64 
    65     psArray *new = newFrameSearchPending(config);
    66     if (!new) {
    67         psError(PS_ERR_UNKNOWN, false, "no newFrames found");
    68         return true;
    69     }
    70 
    71     // insert 'new' rawScience & detrendframes
    72     if (new->n > 0) {
    73         for (long i = 0; i < new->n; i++) {
    74             newFrame *newFrame = new->data[i];
    75             if (strcmp(newFrame->exposure->exp_type, "object") == 0) {
    76                 // it's a science frame
    77                 rawScienceFrame *rawScienceFrame = newToRawScienceFrame(newFrame);
    78                 if (!rawScienceFrameInsert(config, rawScienceFrame)) {
    79                     // error
    80                 }
    81             } else {
    82                 // it's a detrend frame
    83                 rawDetrendFrame *rawDetrendFrame = newToRawDetrendFrame(newFrame);
    84                 if (!rawDetrendFrameInsert(config, rawDetrendFrame)) {
    85                     // error
    86                 }
    87             }
    88            
    89             /*
    90             // lookup camera name in p0CameraConfig
    91             psMetadata *where = psMetadataAlloc();
    92             //bool status = false;
    93             psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, NULL,
    94                 newFrame->exposure->camera);
    95             psArray *configs = p0CameraConfigSelectRowObjects(config->dbh, where, MAX_ROWS);
    96             psFree(where);
    97             // if there is no match then we default to sending into into p2
    98             if (!configs) {
    99                 // convert newFrame->exposure to p2PendingExp
    100                 p2PendingExpRow *p2PendingExp = newToP2PendingExp(
    101                     newFrame->exposure
    102                 );
    103                 p2PendingExpInsertObject(config->dbh, p2PendingExp);
    104                 psFree(p2PendingExp);
    105                 continue;
    106             }
    107 
    108             // only use the first match
    109             int pX = ((p0CameraConfigRow *)configs->data[0])->phase;
    110             switch (pX) {
    111                 case 1:
    112                     // convert newFrame->exposure to p1PendingExp
    113                 {
    114                     p1PendingExpRow *p1PendingExp = newToP1PendingExp(
    115                         newFrame->exposure
    116                     );
    117                     p1PendingExpInsertObject(config->dbh, p1PendingExp);
    118                     psFree(p1PendingExp);
    119                 }
    120                     break;
    121                 case 2:
    122                     // convert newFrame->exposure to p2PendingExp
    123                 {
    124                     p2PendingExpRow *p2PendingExp = newToP2PendingExp(
    125                         newFrame->exposure
    126                     );
    127                     p2PendingExpInsertObject(config->dbh, p2PendingExp);
    128                     psFree(p2PendingExp);
    129                 }
    130                     break;
    131                 default:
    132                     // XXX add argv[0] to pxConfig
    133                     psAbort("foo", "invalid phase (this should not happen)");
    134             }
    135 
    136             psFree(configs);
    137             */
    138         }
    139         psFree(new);
    140     }
    14171
    14272    return true;
    14373}
    14474
    145 static psArray *newFrameSearchPending(pxConfig *config)
    146 {
    147     PS_ASSERT_PTR_NON_NULL(config, NULL);
    148 
    149     psArray *new = newFrameSearch(config);
    150     if (!new) {
    151         psError(PS_ERR_UNKNOWN, false, "no newFrames found");
    152         return false;
    153     }
    154 
    155     psArray *raw = rawScienceFrameSearch(config);
    156     if (!raw) {
    157         psError(PS_ERR_UNKNOWN, false, "no rawScienceFrames found");
    158     //    return false;
    159     }
    160 
    161     psArray *rawDetrend = rawDetrendFrameSearch(config);
    162     if (!rawDetrend) {
    163         psError(PS_ERR_UNKNOWN, false, "no rawDetrendFrames found");
    164     //    return false;
    165     }
    166 
    167     // ignore duplicate raw frames
    168     if (raw) {
    169         for (long i = 0; i < new->n; i++) {
    170             newFrame *newFrame = new->data[i];
    171             for (long j = 0; j < raw->n; j++) {
    172                 rawScienceFrame *rawScienceFrame = raw->data[j];
    173                 if (strcmp(newFrame->exposure->exp_id,
    174                            rawScienceFrame->exposure->exp_id) == 0) {
    175                     psArrayRemove(new, newFrame);
    176                     // dec the counter as the array just got shorter
    177                     //and we don't want to skip elemnts
    178                     i--;
    179                     break;
    180                 }
    181             }
    182         }
    183         psFree(raw);
    184     }
    185 
    186     // ignore duplicate rawDetrend frames
    187     if (rawDetrend) {
    188         for (long i = 0; i < new->n; i++) {
    189             newFrame *newFrame = new->data[i];
    190             for (long j = 0; j < rawDetrend->n; j++) {
    191                 rawDetrendFrame *rawDetrendFrame = rawDetrend->data[j];
    192                 if (strcmp(newFrame->exposure->exp_id,
    193                            rawDetrendFrame->exposure->exp_id) == 0) {
    194                     psArrayRemove(new, newFrame);
    195                     // dec the counter as the array just got shorter
    196                     //and we don't want to skip elemnts
    197                     i--;
    198                     break;
    199                 }
    200             }
    201         }
    202         psFree(rawDetrend);
    203     }
    204 
    205     return new;
    206 }
    207 
    208 
    209 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp)
     75static p1PendingExpRow *rawScienceTop1PendingExp(rawScienceExpRow *raw)
    21076{
    21177    return p1PendingExpRowAlloc(
    212         newExp->exp_id,
    213         newExp->camera,
    214         newExp->telescope,
    215         newExp->exp_type,
     78        raw->exp_id,
     79        raw->camera,
     80        raw->telescope,
     81        raw->exp_type,
    21682//        newExp->class,
    217         newExp->imfiles,
     83        raw->imfiles,
    21884        "my filter",
    21985        "my stats",
     
    22288    );
    22389}
    224 
    225 static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp)
    226 {
    227     return p2PendingExpRowAlloc(
    228         newExp->exp_id,
    229         newExp->camera,
    230         newExp->telescope,
    231         newExp->exp_type,
    232 //        newExp->class,
    233         newExp->imfiles,
    234         "my filter",
    235         "my stats",
    236         "my recipe",
    237         0xff, // XXX calc version number
    238         0xff // XXX calc version number
    239     );
    240 }
Note: See TracChangeset for help on using the changeset viewer.