IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6139


Ignore:
Timestamp:
Jan 21, 2006, 4:21:24 PM (20 years ago)
Author:
jhoblitt
Message:

move modes into functions

File:
1 edited

Legend:

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

    r6135 r6139  
    22
    33#include "p2tools.h"
     4
     5static bool quickMode(p2Config *config);
     6static bool defineMode(p2Config *config);
     7static bool pendingMode(p2Config *config);
     8static bool doneMode(p2Config *config);
    49
    510int main(int argc, char **argv) {
     
    1015    switch (config.mode) {
    1116        case P2_MODE_QUICK:
    12         {
    13             psArray *rawFrames = p2searchRawFrames(&config);
    14             if (!rawFrames) {
    15                 psError(PS_ERR_UNKNOWN, false, "no ppRawFrames found");
     17            if (!quickMode(&config)) {
    1618                exit(EXIT_FAILURE);
    1719            }
    18             psArray *pendingFrames = p2rawToPending(&config, rawFrames);
    19             if (!pendingFrames) {
    20                 psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
     20            break;
     21        case P2_MODE_DEFINE:
     22            if (!defineMode(&config)) {
    2123                exit(EXIT_FAILURE);
    2224            }
    23             bool status = p2writePendingFrames(&config, pendingFrames);
    24             if (!status) {
    25                 psError(PS_ERR_UNKNOWN, false, "p2writePendingFrames() failed");
     25            break;
     26        case P2_MODE_PENDING:
     27            if (!pendingMode(&config)) {
    2628                exit(EXIT_FAILURE);
    2729            }
    28         }
    29             break;
    30         case P2_MODE_DEFINE:
    31         {
    32             psArray *rawFrames = p2searchRawFrames(&config);
    33             if (!rawFrames) {
    34                 psError(PS_ERR_UNKNOWN, false, "no ppRawFrames found");
    35                 exit(EXIT_FAILURE);
    36             }
    37             psArray *pendingFrames = p2searchPendingFrames(&config);
    38             // XXX compare raw frames to pending frames and remove duplicate
    39             // frames from the raw set.  This may not be quiet right as it's
    40             // possible (likely?) that a rawScienceExp is inserted into the
    41             // database prior to /ALL/ of that exposure's Imfiles
    42             if (pendingFrames) {
    43                 for (int i = 0; i < rawFrames->n; i++) {
    44                     ppRawFrame *rawFrame = rawFrames->data[i];
    45                     for (int j = 0; j < pendingFrames->n; j++) {
    46                         p2PendingFrame *pendingFrame = pendingFrames->data[j];
    47                         if (strcmp(rawFrame->exposure->exp_id,
    48                                    pendingFrame->exposure->exp_id) == 0) {
    49                             psArrayRemove(rawFrames, rawFrame);
    50                             // dec the counter as the array just got shorter
    51                             // and we don't want to skip elemnts
    52                             i--;
    53                             break;
    54                         }
    55                     }
    56                 }
    57 
    58                 psFree(pendingFrames);
    59             }
    60 
    61             psArray *doneFrames = p2searchDoneFrames(&config);
    62             if (doneFrames && (rawFrames->n > 0)) {
    63                 for (int i = 0; i < rawFrames->n; i++) {
    64                     ppRawFrame *rawFrame = rawFrames->data[i];
    65                     for (int j = 0; j < pendingFrames->n; j++) {
    66                         p2DoneFrame *doneFrame = pendingFrames->data[j];
    67                         if (strcmp(rawFrame->exposure->exp_id,
    68                                    doneFrame->exposure->exp_id) == 0) {
    69                             psArrayRemove(rawFrames, rawFrame);
    70                             // dec the counter as the array just got shorter
    71                             // and we don't want to skip elemnts
    72                             i--;
    73                             break;
    74                         }
    75                     }
    76                 }
    77 
    78                 psFree(doneFrames);
    79             }
    80 
    81             if (!rawFrames->n > 0) {
    82                 psError(PS_ERR_UNKNOWN, false, "no unprocessed ppRawFrames found");
    83                 psFree(rawFrames);
    84                 exit(EXIT_FAILURE);
    85             }
    86 
    87             bool status = p2insertPendingFrames(&config, rawFrames);
    88             if (!status) {
    89                 psError(PS_ERR_UNKNOWN, false,"p2insertPendingFrames() failed");
    90                 exit(EXIT_FAILURE);
    91             }
    92         }
    93             break;
    94         case P2_MODE_PENDING:
    95         {
    96             psArray *pendingFrames = p2searchPendingFrames(&config);
    97             if (!pendingFrames) {
    98                 psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
    99                 exit(EXIT_FAILURE);
    100             }
    101             bool status = p2writePendingFrames(&config, pendingFrames);
    102             if (!status) {
    103                 psError(PS_ERR_UNKNOWN, false,"p2insertPendingFrames() failed");
    104                 exit(EXIT_FAILURE);
    105             }
    106         }
    10730            break;
    10831    /*
     
    11538    */
    11639        case P2_MODE_DONE:
    117         {
    118             psArray *pendingFrames = p2searchPendingFrames(&config);
    119             if (!pendingFrames) {
    120                 psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
     40            if (!doneMode(&config)) {
    12141                exit(EXIT_FAILURE);
    12242            }
    123             psArray *doneFrames = p2pendingToDone(&config, pendingFrames);
    124             if (!doneFrames) {
    125                 psError(PS_ERR_UNKNOWN, false, "p2pendingToDone() failed");
    126                 exit(EXIT_FAILURE);
    127             }
    128             bool status = p2insertDoneFrames(&config, doneFrames);
    129             if (!status) {
    130                 psError(PS_ERR_UNKNOWN, false, "p2insertDoneFrames() failed");
    131                 exit(EXIT_FAILURE);
    132             }
    133         }
    13443            break;
    13544        default:
     
    13948    exit(EXIT_SUCCESS);
    14049}
     50
     51static bool quickMode(p2Config *config)
     52{
     53    psArray *rawFrames = p2searchRawFrames(config);
     54    if (!rawFrames) {
     55        psError(PS_ERR_UNKNOWN, false, "no ppRawFrames found");
     56        return false;
     57    }
     58    psArray *pendingFrames = p2rawToPending(config, rawFrames);
     59    if (!pendingFrames) {
     60        psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
     61        return false;
     62    }
     63    bool status = p2writePendingFrames(config, pendingFrames);
     64    if (!status) {
     65        psError(PS_ERR_UNKNOWN, false, "p2writePendingFrames() failed");
     66        return false;
     67    }
     68
     69    return true;
     70}
     71
     72static bool defineMode(p2Config *config)
     73{
     74    psArray *rawFrames = p2searchRawFrames(config);
     75    if (!rawFrames) {
     76        psError(PS_ERR_UNKNOWN, false, "no ppRawFrames found");
     77        return false;
     78    }
     79    psArray *pendingFrames = p2searchPendingFrames(config);
     80    // XXX compare raw frames to pending frames and remove duplicate
     81    // frames from the raw set.  This may not be quiet right as it's
     82    // possible (likely?) that a rawScienceExp is inserted into the
     83    // database prior to /ALL/ of that exposure's Imfiles
     84    if (pendingFrames) {
     85        for (int i = 0; i < rawFrames->n; i++) {
     86            ppRawFrame *rawFrame = rawFrames->data[i];
     87            for (int j = 0; j < pendingFrames->n; j++) {
     88                p2PendingFrame *pendingFrame = pendingFrames->data[j];
     89                if (strcmp(rawFrame->exposure->exp_id,
     90                           pendingFrame->exposure->exp_id) == 0) {
     91                    psArrayRemove(rawFrames, rawFrame);
     92                    // dec the counter as the array just got shorter
     93                    // and we don't want to skip elemnts
     94                    i--;
     95                    break;
     96                }
     97            }
     98        }
     99
     100        psFree(pendingFrames);
     101    }
     102
     103    psArray *doneFrames = p2searchDoneFrames(config);
     104    if (doneFrames && (rawFrames->n > 0)) {
     105        for (int i = 0; i < rawFrames->n; i++) {
     106            ppRawFrame *rawFrame = rawFrames->data[i];
     107            for (int j = 0; j < pendingFrames->n; j++) {
     108                p2DoneFrame *doneFrame = pendingFrames->data[j];
     109                if (strcmp(rawFrame->exposure->exp_id,
     110                           doneFrame->exposure->exp_id) == 0) {
     111                    psArrayRemove(rawFrames, rawFrame);
     112                    // dec the counter as the array just got shorter
     113                    // and we don't want to skip elemnts
     114                    i--;
     115                    break;
     116                }
     117            }
     118        }
     119
     120        psFree(doneFrames);
     121    }
     122
     123    if (!rawFrames->n > 0) {
     124        psError(PS_ERR_UNKNOWN, false, "no unprocessed ppRawFrames found");
     125        psFree(rawFrames);
     126        return false;
     127    }
     128
     129    bool status = p2insertPendingFrames(config, rawFrames);
     130    if (!status) {
     131        psError(PS_ERR_UNKNOWN, false,"p2insertPendingFrames() failed");
     132        return false;
     133    }
     134
     135    return true;
     136}
     137
     138static bool pendingMode(p2Config *config)
     139{
     140    psArray *pendingFrames = p2searchPendingFrames(config);
     141    if (!pendingFrames) {
     142        psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
     143        return false;
     144    }
     145    bool status = p2writePendingFrames(config, pendingFrames);
     146    if (!status) {
     147        psError(PS_ERR_UNKNOWN, false,"p2insertPendingFrames() failed");
     148        return false;
     149    }
     150
     151    return true;
     152}
     153
     154static bool doneMode(p2Config *config)
     155{
     156    psArray *pendingFrames = p2searchPendingFrames(config);
     157    if (!pendingFrames) {
     158        psError(PS_ERR_UNKNOWN, false, "no p2PendingFrames found");
     159        return false;
     160    }
     161    psArray *doneFrames = p2pendingToDone(config, pendingFrames);
     162    if (!doneFrames) {
     163        psError(PS_ERR_UNKNOWN, false, "p2pendingToDone() failed");
     164        return false;
     165    }
     166    bool status = p2insertDoneFrames(config, doneFrames);
     167    if (!status) {
     168        psError(PS_ERR_UNKNOWN, false, "p2insertDoneFrames() failed");
     169        return false;
     170    }
     171
     172    return true;
     173}
Note: See TracChangeset for help on using the changeset viewer.