IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16278


Ignore:
Timestamp:
Feb 1, 2008, 2:42:15 PM (18 years ago)
Author:
bills
Message:

more pstampparse functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/pstampparse.c

    r16239 r16278  
    1 // pstampparse  - read a fits table describing a pstamp request and prepares it for processing
     1// pstampparse  - read a fits table describing a postage stamp request and prepare the request
     2// for processing
    23
    34#include <pslib.h>
     
    1314    psString    roiString;
    1415    pspMode     mode;
     16    psS64       req_id;
    1517    bool        verbose;
     18    bool        simple;
    1619} pspOptions;
    1720
     
    6063
    6164    if ((argnum = psArgumentGet(argc, argv, "-mode"))) {
    62         options->verbose = true;
    6365        psArgumentRemove(argnum, &argc, argv);
    6466        if (argnum == argc) {
     
    6971        psArgumentRemove(argnum, &argc, argv);
    7072    }
     73    if ((argnum = psArgumentGet(argc, argv, "-req_id"))) {
     74        psArgumentRemove(argnum, &argc, argv);
     75        if (argnum == argc) {
     76            fprintf(stderr, "value required for mode\n");
     77            usage();
     78        }
     79        options->req_id = atol(argv[argnum]);
     80        psArgumentRemove(argnum, &argc, argv);
     81    }
    7182
    7283    if ((argnum = psArgumentGet(argc, argv, "-verbose"))) {
    7384        options->verbose = true;
     85        psArgumentRemove(argnum, &argc, argv);
     86    }
     87
     88    if ((argnum = psArgumentGet(argc, argv, "-simple"))) {
     89        options->simple = true;
    7490        psArgumentRemove(argnum, &argc, argv);
    7591    }
     
    262278    }
    263279
    264     // XXX: Hmm if we're doing last(runQuery(....)) we need to free the
    265     // result array, however freeing this in here seems like a dangerous API
    266     // but hey it's a static function
     280    // XXX: Hmm if we're doing lastID(runQuery(....)) we need to free the
     281    // result array, however freeing this in here seems like a potentially dangerous API
     282    // but hey we're a static function
    267283
    268284    psFree(array);
     
    571587
    572588static bool
     589queueOneJob (pspOptions *options, psString uri, psString outputBase, psString commandArgs)
     590{
     591    psString cmd = NULL;
     592
     593    psStringAppend(&cmd, "pstamptool -addjob -req_id %ld -uri %s -outputBase %s -args '%s' >/dev/null",
     594                                options->req_id, uri, outputBase, commandArgs);
     595    if (options->verbose) {
     596        fprintf(stderr, "excuting system(%s)\n", cmd);
     597    }
     598
     599    int rstatus = system(cmd);
     600
     601    if (rstatus) {
     602        fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
     603    }
     604    psFree(cmd);
     605
     606    // TODO: should we be returning the exit status so that it can be reported?
     607    return !rstatus;
     608}
     609
     610static bool
     611queueJobs (pspOptions *options, psArray *uris, psString user_tag, psString commandArgs)
     612{
     613    int numURIs = psArrayLength(uris);
     614    bool status = false;
     615
     616    if (numURIs == 1) {
     617        // use the user tag as the outputBase
     618        status = queueOneJob(options, uris->data[0], user_tag, commandArgs);
     619    } else {
     620        for (int i = 0; i< numURIs; i++) {
     621            psString outputBase = NULL;
     622           
     623            // append an integer to the user_tag to get a uniqueu outputBase
     624            psStringAppend(&outputBase, "%s_%d", user_tag, i);
     625
     626            status = queueOneJob(options, uris->data[i], outputBase, commandArgs);
     627            psFree(outputBase);
     628
     629            if (!status) {
     630                break;
     631            }
     632        }
     633    }
     634
     635    return status;
     636}
     637
     638
     639static bool
    573640parseRequestTable(pspOptions *options)
    574641{
     
    581648            options->mode = parseMode(cmd_mode);
    582649        } else {
     650            // default to listing the parameters of the job's that the request would queue
    583651            options->mode = PSP_MODE_LIST_JOB;
    584652        }
     653    }
     654
     655    if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) {
     656        fprintf(stderr, "need request id in order to queue jobs\n");
     657        return false;
    585658    }
    586659
     
    597670    }
    598671
    599     // XXX switch this to have the various parsing functions return the list of uris which
    600     // we will process here
    601672    psArray *uris = NULL;
    602673    if (!strcmp(req_type, "byid")) {
     
    626697            fprintf(stdout, "%s\n", (psString) uris->data[i]);
    627698        }
    628     } else if (options->mode == PSP_MODE_LIST_JOB) {
     699    } else {
    629700        psString commandArgs = roiString;
    630701        psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
    631702        if (class_id) {
     703            // TODO: the ppstamp argument needs to change to class_id
     704            // perhaps allow chip as a synonym
    632705            psStringAppend(&commandArgs, " -chip %s", class_id);
    633706        }
     
    639712        }
    640713
    641         for (int i = 0; i < numURIs; i++) {
    642             printf("%s %s %s\n", (psString) uris->data[i], user_tag, commandArgs);
    643         }
    644     } else {
    645         fprintf(stderr, "PSP_MODE_QUEUE_JOB not implemented yet\n");
    646         return false;
    647     }
    648 
     714        if (options->mode == PSP_MODE_LIST_JOB) {
     715            if (numURIs == 1) {
     716                printf("%s %s %s\n", (psString) uris->data[0], user_tag, commandArgs);
     717            } else {
     718                // add an integer to the user_tag
     719                for (int i = 0; i < numURIs; i++) {
     720                    printf("%s %s_%d %s\n", (psString) uris->data[i], user_tag, i, commandArgs);
     721                }
     722            }
     723        } else if (options->mode == PSP_MODE_QUEUE_JOB) {
     724
     725            if (!queueJobs(options, uris, user_tag, commandArgs)) {
     726                return false;
     727            }
     728
     729        } else {
     730            // this error is actually caught by parseMode but we might as well check
     731            fprintf(stderr, "unknown command mode found: %d\n", options->mode);
     732            exit(1);
     733        }
     734    }
    649735
    650736    return true;
Note: See TracChangeset for help on using the changeset viewer.