Changeset 16278
- Timestamp:
- Feb 1, 2008, 2:42:15 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/src/pstampparse.c (modified) (10 diffs)
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 2 3 3 4 #include <pslib.h> … … 13 14 psString roiString; 14 15 pspMode mode; 16 psS64 req_id; 15 17 bool verbose; 18 bool simple; 16 19 } pspOptions; 17 20 … … 60 63 61 64 if ((argnum = psArgumentGet(argc, argv, "-mode"))) { 62 options->verbose = true;63 65 psArgumentRemove(argnum, &argc, argv); 64 66 if (argnum == argc) { … … 69 71 psArgumentRemove(argnum, &argc, argv); 70 72 } 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 } 71 82 72 83 if ((argnum = psArgumentGet(argc, argv, "-verbose"))) { 73 84 options->verbose = true; 85 psArgumentRemove(argnum, &argc, argv); 86 } 87 88 if ((argnum = psArgumentGet(argc, argv, "-simple"))) { 89 options->simple = true; 74 90 psArgumentRemove(argnum, &argc, argv); 75 91 } … … 262 278 } 263 279 264 // XXX: Hmm if we're doing last (runQuery(....)) we need to free the265 // result array, however freeing this in here seems like a dangerous API266 // but hey it'sa static function280 // 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 267 283 268 284 psFree(array); … … 571 587 572 588 static bool 589 queueOneJob (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 610 static bool 611 queueJobs (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 639 static bool 573 640 parseRequestTable(pspOptions *options) 574 641 { … … 581 648 options->mode = parseMode(cmd_mode); 582 649 } else { 650 // default to listing the parameters of the job's that the request would queue 583 651 options->mode = PSP_MODE_LIST_JOB; 584 652 } 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; 585 658 } 586 659 … … 597 670 } 598 671 599 // XXX switch this to have the various parsing functions return the list of uris which600 // we will process here601 672 psArray *uris = NULL; 602 673 if (!strcmp(req_type, "byid")) { … … 626 697 fprintf(stdout, "%s\n", (psString) uris->data[i]); 627 698 } 628 } else if (options->mode == PSP_MODE_LIST_JOB){699 } else { 629 700 psString commandArgs = roiString; 630 701 psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID"); 631 702 if (class_id) { 703 // TODO: the ppstamp argument needs to change to class_id 704 // perhaps allow chip as a synonym 632 705 psStringAppend(&commandArgs, " -chip %s", class_id); 633 706 } … … 639 712 } 640 713 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 } 649 735 650 736 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
