IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16239 for trunk/pstamp/src


Ignore:
Timestamp:
Jan 25, 2008, 1:09:44 PM (18 years ago)
Author:
bills
Message:

various changes to get the protoype limping along

Location:
trunk/pstamp/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src

    • Property svn:ignore
      •  

        old new  
        66config.h.in
        77stamp-h1
        8 ppstampErrorCodes.c
        9 ppstampErrorCodes.h
         8pstampErrorCodes.c
         9pstampErrorCodes.h
        1010.libs
  • trunk/pstamp/src/.cvsignore

    r16132 r16239  
    66config.h.in
    77stamp-h1
    8 ppstampErrorCodes.c
    9 ppstampErrorCodes.h
     8pstampErrorCodes.c
     9pstampErrorCodes.h
    1010.libs
  • trunk/pstamp/src/ppstampArguments.c

    r16132 r16239  
    55#include "ppstamp.h"
    66#include "ppstampOptions.h"
     7#include <ctype.h>
    78
    89static void usage (void)
  • trunk/pstamp/src/ppstampMakeStamp.c

    r16132 r16239  
    454454        // If the user specified a name of a chip name wait until we get to that one.
    455455        // If no chip name was specified, select this one (the first one that had data)
    456         if ((options->chipName == NULL) || !strcmp(chipName, options->chipName)) {
     456        if ((options->chipName == NULL) || !strcasecmp(chipName, options->chipName)) {
    457457            psLogMsg("ppstampMakeStamp", 2, "Center on chip: %s\n", chipName);
    458458            center->chip->x = options->roip.centerX;
  • trunk/pstamp/src/pstamp.h

    r16132 r16239  
    2222} pstampImageType;
    2323
     24
     25// command modes for pstampparse
     26typedef enum {
     27    PSP_MODE_UNKNOWN = 0,
     28    PSP_MODE_QUEUE_JOB,
     29    PSP_MODE_LIST_URI,
     30    PSP_MODE_LIST_JOB
     31} pspMode;
     32
     33
     34
    2435#define STAMP_REQUEST_EXTNAME "PS1_PS_REQUEST"
    2536#define STAMP_REQUEST_VERSION "1.0"
  • trunk/pstamp/src/pstampparse.c

    r16132 r16239  
    1111    psString    fileName;
    1212    psMetadata  *md;
    13     psString    commandLine;
    1413    psString    roiString;
     14    pspMode     mode;
     15    bool        verbose;
    1516} pspOptions;
     17
    1618
    1719static void usage()
     
    2224}
    2325
     26static pspMode parseMode(char *modeString)
     27{
     28    pspMode mode = PSP_MODE_UNKNOWN;
     29
     30    if (!strcasecmp(modeString, "list_uri")) {
     31        mode = PSP_MODE_LIST_URI;
     32    } else if (!strcasecmp(modeString, "list_job")) {
     33        mode = PSP_MODE_LIST_JOB;
     34    } else if (!strcasecmp(modeString, "queue_job")) {
     35        mode = PSP_MODE_QUEUE_JOB;
     36    } else {
     37        fprintf(stderr, "unknown command mode: %s\n", modeString);
     38        exit(1);
     39    }
     40    return mode;
     41}
     42
    2443
    2544static pspOptions *parseArguments(int argc, char *argv[])
    2645{
     46    int argnum;
    2747    pspOptions *options = psAlloc(sizeof(pspOptions));
     48
    2849    memset(options, 0, sizeof(*options));
    29     // int         argnum;
    3050
    3151    // options to add
    32     //      mode:   -queuejobs -execute -preview
     52    //      mode:   -queuejobs -execute
    3353
    3454    options->config = pmConfigRead(&argc, argv, NULL);
     
    3757        psFree(options);
    3858        return NULL;
     59    }
     60
     61    if ((argnum = psArgumentGet(argc, argv, "-mode"))) {
     62        options->verbose = true;
     63        psArgumentRemove(argnum, &argc, argv);
     64        if (argnum == argc) {
     65            fprintf(stderr, "value required for mode\n");
     66            usage();
     67        }
     68        options->mode = parseMode(argv[argnum]);
     69        psArgumentRemove(argnum, &argc, argv);
     70    }
     71
     72    if ((argnum = psArgumentGet(argc, argv, "-verbose"))) {
     73        options->verbose = true;
     74        psArgumentRemove(argnum, &argc, argv);
    3975    }
    4076
     
    5793}
    5894
    59 static bool readTable(pspOptions *options)
     95static bool readRequestTable(pspOptions *options)
    6096{
    6197    psFits *fitsFile = psFitsOpen(options->fileName, "r");
     
    180216            psString val = psMetadataLookupStr(NULL, row, target);
    181217            if (val != 0) {
    182                 output = psArrayAdd(output, len -i, val);
     218                output = psArrayAdd(output, len - i, val);
    183219            }
    184220        } else {
    185221            psU64 val = psMetadataLookupU64(NULL, row, target);
    186222            if (val != 0) {
    187                 output = psArrayAdd(output, len -i, idToStr(val));
     223                output = psArrayAdd(output, len - i, idToStr(val));
    188224            }
    189225        }
     
    303339
    304340    psString warp_id = warpIDForCam(options, cam_id);
    305 
    306     psArray *stackIDs = runQuery(options, "SELECT %%S FROM stackInputSkyfile WHERE warp_id = %s",
     341    if (warp_id == NULL)
     342        return NULL;
     343
     344    psArray *stackIDs = runQuery(options, "SELECT %s FROM stackInputSkyfile WHERE warp_id = %s",
    307345                            "stack_id", warp_id, NULL, false, NULL);
    308346
     
    500538            return NULL;
    501539        }
    502         psStringAppend(&roiString, " -skycenter %s %s", ra, dec);
     540        psStringAppend(&roiString, "-skycenter %s %s", ra, dec);
    503541    } else {
    504542        psString x = psMetadataLookupStr(&status, options->md, "CENTER_X");
     
    507545            return NULL;
    508546        }
    509         psString y = psMetadataLookupStr(&status, options->md, "CENTER_X");
    510         psStringAppend(&roiString, " -pixcenter %s %s", x, y);
     547        psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y");
     548        psStringAppend(&roiString, "-pixcenter %s %s", x, y);
    511549    }
    512550
     
    533571
    534572static bool
    535 parseTable(pspOptions *options)
    536 {
     573parseRequestTable(pspOptions *options)
     574{
     575    bool status;
     576    psString cmd_mode = psMetadataLookupStr(&status, options->md, "CMD_MODE");
     577
     578    // if mode is set on the command line ignore the value in the request file
     579    if (options->mode == PSP_MODE_UNKNOWN) {
     580        if (cmd_mode != NULL) {
     581            options->mode = parseMode(cmd_mode);
     582        } else {
     583            options->mode = PSP_MODE_LIST_JOB;
     584        }
     585    }
     586
    537587    // how are we to select the images ?
    538     psString req_type = psMetadataLookupStr(NULL, options->md, "REQ_TYPE");
     588    psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
    539589
    540590    if ( !req_type) {
     
    566616    if (uris == NULL) {
    567617        // may need a finer grained status code: did something go wrong with the system
    568         // or are there just no images matching the request
     618        // or are there simply no images matching the request
     619        fprintf(stderr, "No matching images found.\n");
     620        return true;
     621    }
     622
     623    int numURIs = psArrayLength(uris);
     624    if (options->mode == PSP_MODE_LIST_URI) {
     625        for (int i=0; i<numURIs; i++) {
     626            fprintf(stdout, "%s\n", (psString) uris->data[i]);
     627        }
     628    } else if (options->mode == PSP_MODE_LIST_JOB) {
     629        psString commandArgs = roiString;
     630        psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
     631        if (class_id) {
     632            psStringAppend(&commandArgs, " -chip %s", class_id);
     633        }
     634
     635        psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");
     636        if (user_tag == NULL) {
     637            psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
     638            return false;
     639        }
     640
     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");
    569646        return false;
    570647    }
    571648
    572     int len = psArrayLength(uris);
    573     fprintf(stderr, "URIS:\n");
    574     for (int i=0; i<len; i++) {
    575         fprintf(stderr, "  %3d %s\n", i, (psString) uris->data[i]);
    576     }
    577 
    578 #ifdef notyet
    579     // XXX: We need more than a single command line since we might have multiple images
    580     psStringAppend(&options->commandLine, "ppstamp ");
    581 
    582     // For now just take the last image returned as the Image of interest
    583     psString imageFile = uris->data[psArrayLength(uris) - 1];
    584 
    585     psStringAppend(&options->commandLine, " -file %s", imageFile);
    586 
    587     // Set the output file name to user_tag.fits
    588     psString user_tag = psMetadataLookupStr(NULL, options->md, "USER_TAG");
    589     if (user_tag == NULL) {
    590         psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
    591         return false;
    592     }
    593 
    594     // XXX: need configurable output directory: get from database, recipe, site file, command line arg?
    595 
    596     psStringAppend(&options->commandLine, " %s.fits", user_tag);
    597 #endif
    598649
    599650    return true;
     
    603654{
    604655    pspOptions *options = parseArguments(argc, argv);
    605     bool verbose = true;
    606656
    607657    // XXX: create a set of status codes to return so the
     
    617667    }
    618668
    619     if (!readTable(options)) {
     669    if (!readRequestTable(options)) {
    620670        return 1;
    621671    }
     
    625675    }
    626676
    627     if (verbose) {
     677    if (options->verbose) {
    628678        psMetadataPrint(stderr, options->md, 0);
    629679    }
    630680
    631     if (!parseTable(options)) {
    632         psErrorStackPrint(stderr, "unable to parse request table");
     681    if (!parseRequestTable(options)) {
     682        // psErrorStackPrint(stderr, "unable to parse request table");
    633683        return 1;
    634684    }
    635685
    636     // XXX: We need to have multiple modes of operation depending on command line options
    637     //      1. add a job to the database.
    638     //      2. print the ppstamp command line
    639     //      3. execute the command
    640     // Actually should probably just let pstampparse do the last one so as
    641     // to keep the ippTools model for database interactions intact.
    642     // So far in this program I'm only doing reads from the database not edits.
    643 
    644     if (options->commandLine) {
    645         printf("%s\n", options->commandLine);
    646     }
    647 
    648686    return 0;
    649687}
  • trunk/pstamp/src/pstamprequest.c

    r16132 r16239  
    334334    }
    335335
    336     // TODO: find other optional arguments
     336    if ((argnum = psArgumentGet(argc, argv, "-list"))) {
     337        psMetadataAdd (options->md, PS_LIST_TAIL, "CMD_MODE", PS_DATA_STRING, "", "LIST_URI");
     338        psArgumentRemove(argnum, &argc, argv);
     339    }
     340
     341    // only argument left should be the required file name for the request file
    337342
    338343    if (argc == 2) {
Note: See TracChangeset for help on using the changeset viewer.