Changeset 20340
- Timestamp:
- Oct 22, 2008, 9:42:57 PM (18 years ago)
- Location:
- trunk/magic/remove/src
- Files:
-
- 3 edited
-
Makefile.simple (modified) (1 diff)
-
streaks.h (modified) (4 diffs)
-
streaksremove.c (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/Makefile.simple
r20280 r20340 7 7 Line.o 8 8 9 CFLAGS=`psmodules-config --cflags` 9 CFLAGS=`psmodules-config --cflags` -g 10 10 LDFLAGS=`psmodules-config --libs` 11 11 -
trunk/magic/remove/src/streaks.h
r20280 r20340 9 9 #include "pslib.h" 10 10 #include "psmodules.h" 11 #include "nebclient.h" 11 12 12 13 typedef struct { … … 15 16 16 17 #include "streaksastrom.h" 17 18 // WES file names are ipp uris usually neb://19 // we need to resolve these to unix file names20 // sFile is a wrapper containing the information for our files21 18 22 19 typedef struct { … … 71 68 float recoveryMaskValue; 72 69 float recoveryWeightValue; 70 nebServer *nebServer; 73 71 } streakFiles; 74 72 … … 80 78 81 79 #define SFILE_IS_IMAGE(_sfile) (_sfile->image || _sfile->imagecube) 80 #define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://"))) 81 82 82 83 83 #endif // STREAKS_H -
trunk/magic/remove/src/streaksremove.c
r20280 r20340 6 6 extern bool sFileReplace(sFile *dest, sFile *src); 7 7 8 static void bail_out(psString str, int exitCode) { 8 // for clarity in this program we don't propagate errors up the stack 9 // we just bail out 10 void streaksremoveExit(psString str, int exitCode) { 9 11 psErrorStackPrint(stderr, str); 10 12 exit(exitCode); … … 20 22 21 23 psString 22 resolveName(pmConfig *config, sFile *sfile) 23 { 24 // TODO: do the nebulous lookup 25 sfile->inNebulous = false; 26 27 return psStringCopy(sfile->name); 24 resolveFilename(pmConfig *config, sFile *sfile, bool create) 25 { 26 sfile->inNebulous = IN_NEBULOUS(sfile->name); 27 28 return pmConfigConvertFilename(sfile->name, config, create, create); 28 29 } 29 30 … … 35 36 memset(sfile, 0, sizeof(sFile)); 36 37 37 // if stage is raw or chip use psFits for input, if warp or diff start with FPA 38 // so we have it for astrometry 39 if ((CHIP_LEVEL_INPUT(stage)) || strcmp(fileSelect, "INPUT")) { 40 sfile->name = psMetadataLookupStr(&status, config->arguments, fileSelect); 41 if (!status || !sfile->name) { 42 if (required) { 43 psError(PS_ERR_IO, false, "Failed to lookup name for %s", fileSelect); 44 sFileFree(sfile); 45 bail_out("", 1); 46 } 47 return NULL; 48 } 49 } else { 38 // We use directly use psFits to read the image file unless the stage is warp 39 // or diff. In that case we use the pmFPAfile functions to read the image file 40 // so that it handles managing the astrometry. 41 42 if (!CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) { 50 43 // stage is warp or diff AND fileSelect eq "INPUT" 51 // get data from pmFPAfile 44 // get data from pmFPAfile. We read the mask and weight files using psFits 45 46 // we need to know what the nebulous and real filenames are so we steal 47 // some code from pmFPAfileDefineFromArgs 48 // XXX: create a pmFPAfile function that does this and use it there 49 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, "INPUT"); 50 if (!status) { 51 psError(PS_ERR_PROGRAMMING, false, "INPUT not found in config->arguments"); 52 streaksremoveExit("", PS_EXIT_PROG_ERROR); 53 } 54 if (infiles->n < 1) { 55 psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, "INPUT"); 56 streaksremoveExit("", PS_EXIT_DATA_ERROR); 57 } 58 sfile->name = psStringCopy(infiles->data[0]); 59 // end of file name lookup code adapted from pmFPAfileDefineFromArgs 60 61 sfile->inNebulous = IN_NEBULOUS(sfile->name); 62 52 63 sfile->pmfile = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT"); 53 64 if (!sfile->pmfile) { 54 65 psError(PS_ERR_IO, false, "Failed to defile file for name for %s", fileSelect); 55 bail_out("", PS_EXIT_DATA_ERROR); 56 } 66 streaksremoveExit("", PS_EXIT_DATA_ERROR); 67 } 68 69 sfile->resolved_name = psStringCopy(sfile->pmfile->filename); 57 70 pmFPAview *view = pmFPAviewAlloc(0); 58 71 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 59 72 psError(PS_ERR_UNKNOWN, false, "Failed to load input."); 60 bail_out("", PS_EXIT_DATA_ERROR);73 streaksremoveExit("", PS_EXIT_DATA_ERROR); 61 74 } 62 75 psFree(view); 63 sfile->name = sfile->pmfile->filename; 64 sfile->resolved_name = psStringCopy(sfile->name); 76 65 77 // copy header from fpu 66 78 sfile->header = (psMetadata*) psMemIncrRefCounter(sfile->pmfile->fpa->hdu->header); 79 67 80 return sfile; 81 } 82 83 sfile->name = psMetadataLookupStr(&status, config->arguments, fileSelect); 84 if (!status || !sfile->name) { 85 if (required) { 86 psError(PS_ERR_IO, false, "Failed to lookup name for %s", fileSelect); 87 sFileFree(sfile); 88 streaksremoveExit("", 1); 89 } 90 return NULL; 68 91 } 69 92 … … 72 95 if (outputExt) { 73 96 psStringAppend(&sfile->name, outputExt); 74 sfile->resolved_name = psStringCopy(sfile->name); 97 sfile->resolved_name = resolveFilename(config, sfile, true); 98 if (!sfile->resolved_name) { 99 psError(PS_ERR_IO, false, "Failed to create file %s", sfile->name); 100 sFileFree(sfile); 101 streaksremoveExit("", 1); 102 } 75 103 sfile->fits = psFitsOpen(sfile->resolved_name, "w"); 76 104 sfile->fits->options = psFitsOptionsAlloc(); 77 105 } else { 78 sfile->resolved_name = resolve Name(config, sfile);106 sfile->resolved_name = resolveFilename(config, sfile, false); 79 107 if (!sfile->resolved_name) { 80 108 psError(PS_ERR_IO, false, "Failed to resolve name for %s", sfile->name); 81 109 sFileFree(sfile); 82 bail_out("", 1);110 streaksremoveExit("", 1); 83 111 } 84 112 sfile->fits = psFitsOpen(sfile->resolved_name, "r"); … … 92 120 sfile->resolved_name, outputExt ? "writing" : "reading"); 93 121 sFileFree(sfile); 94 bail_out("", 1);122 streaksremoveExit("", 1); 95 123 } 96 124 97 125 return sfile; 98 126 } 99 100 #ifdef notyet101 sfile->file = pmFPAfileDefineFromArgs(&status, config, name, fileSelect);102 if (!status || !sfile->file) {103 if (required) {104 psError(PS_ERR_IO, false, "Failed to build FPA for %s", name);105 }106 return NULL;107 }108 #endif109 127 110 128 … … 121 139 122 140 if (sf->bilevelAstrometry) { 123 #ifdef notyet124 141 // Do we get here for GPC1 ? I don't necessarily have an fpa for the input image 125 if (!pmAstromReadBilevelMosaic(sf->in Image->file->fpa, phu->header)) {142 if (!pmAstromReadBilevelMosaic(sf->inAstrom->fpa, phu->header)) { 126 143 psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA."); 127 144 return false; 128 145 } 129 #endif130 146 } else { 131 147 pmHDU *hdu = pmFPAviewThisHDU(sf->view, sf->inAstrom->fpa); … … 150 166 if (!pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_BEFORE)) { 151 167 psError(PS_ERR_UNKNOWN, false, "Failed to load input."); 152 bail_out("", PS_EXIT_DATA_ERROR);168 streaksremoveExit("", PS_EXIT_DATA_ERROR); 153 169 } 154 170 … … 166 182 if (!sf->chip) { 167 183 psError(PS_ERR_UNKNOWN, true, "Failed to find chip with data."); 168 bail_out("", PS_EXIT_DATA_ERROR);184 streaksremoveExit("", PS_EXIT_DATA_ERROR); 169 185 } 170 186 if (!pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_BEFORE)) { 171 187 psError(PS_ERR_UNKNOWN, false, "failed to load chip"); 172 bail_out("", PS_EXIT_DATA_ERROR);188 streaksremoveExit("", PS_EXIT_DATA_ERROR); 173 189 } 174 190 … … 185 201 sf->config = config; 186 202 187 // error checking is done by sFileOpen. If a file can't be open we 188 // exit 203 // error checking is done by sFileOpen. If a file can't be opened we just exit 189 204 ippStage stage = psMetadataLookupS32(&status, config->arguments, "STAGE"); 190 205 … … 216 231 sf->inAstrom = sf->inImage->pmfile; 217 232 if (!sf->inImage->pmfile) { 218 bail_out("unexpected null pmFPAfile", PS_EXIT_CONFIG_ERROR);233 streaksremoveExit("unexpected null pmFPAfile", PS_EXIT_CONFIG_ERROR); 219 234 } 220 235 } … … 269 284 psError(PS_ERR_IO, false, 270 285 "failed to move to extension %d for %s", extnum, sfile->resolved_name); 271 bail_out("", PS_EXIT_DATA_ERROR);286 streaksremoveExit("", PS_EXIT_DATA_ERROR); 272 287 } 273 288 return true; … … 315 330 } else { 316 331 psError(PS_ERR_UNKNOWN, true, "unknown stage string: %s\n", stageStr); 317 bail_out("", PS_EXIT_DATA_ERROR);332 streaksremoveExit("", PS_EXIT_DATA_ERROR); 318 333 // notreached 319 334 return IPP_STAGE_NONE; … … 326 341 pmConfig *config = pmConfigRead(&argc, argv, NULL); 327 342 if (!config) { 328 bail_out("failed to parse arguments", PS_EXIT_CONFIG_ERROR);343 streaksremoveExit("failed to parse arguments", PS_EXIT_CONFIG_ERROR); 329 344 } 330 345 … … 384 399 385 400 if (!pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", NULL)) { ; 386 if ( (stage == IPP_STAGE_RAW) || (stage == IPP_STAGE_CHIP)) {401 if (CHIP_LEVEL_INPUT(stage)) { 387 402 psError(PS_ERR_UNKNOWN, true, "-astrom is required for raw and chip stages\n"); 388 403 return NULL; … … 418 433 psError(PS_ERR_UNKNOWN, true, "-recovery is required for -stage raw\n"); 419 434 return NULL; 435 } 436 if ((argnum = psArgumentGet(argc, argv, "-replace"))) { 437 psArgumentRemove(argnum, &argc, argv); 438 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REPLACE", 0, "replace input files", 439 true); 440 } 441 if ((argnum = psArgumentGet(argc, argv, "-remove"))) { 442 psArgumentRemove(argnum, &argc, argv); 443 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REMOVE", 0, "remove input files", 444 true); 420 445 } 421 446 … … 432 457 psError(PS_ERR_IO, false, "failed to read primary header from %s\n", 433 458 sfiles->inImage->resolved_name); 434 bail_out("", PS_EXIT_DATA_ERROR);459 streaksremoveExit("", PS_EXIT_DATA_ERROR); 435 460 } 436 461 … … 439 464 psError(PS_ERR_IO, false, "failed to write primary header to %s", 440 465 sfiles->outImage->resolved_name); 441 bail_out("", PS_EXIT_DATA_ERROR);466 streaksremoveExit("", PS_EXIT_DATA_ERROR); 442 467 } 443 468 // TODO: add keyword indicating that this is the recovery image … … 445 470 psError(PS_ERR_IO, false, "failed to write primary header to %s", 446 471 sfiles->recImage->resolved_name); 447 bail_out("", PS_EXIT_DATA_ERROR);472 streaksremoveExit("", PS_EXIT_DATA_ERROR); 448 473 } 449 474 psFree(imageHeader); … … 455 480 psError(PS_ERR_IO, false, "failed to read primary header from %s\n", 456 481 sfiles->inMask->resolved_name); 457 bail_out("", 1);482 streaksremoveExit("", 1); 458 483 } 459 484 // TODO: add keyword indicating that streaks have been removed … … 461 486 psError(PS_ERR_IO, false, "failed to write primary header to %s", 462 487 sfiles->outMask->resolved_name); 463 bail_out("", PS_EXIT_DATA_ERROR);488 streaksremoveExit("", PS_EXIT_DATA_ERROR); 464 489 } 465 490 // TODO: add keyword indicating that this is the recovery image … … 467 492 psError(PS_ERR_IO, false, "failed to write primary header to %s", 468 493 sfiles->recMask->resolved_name); 469 bail_out("", PS_EXIT_DATA_ERROR);494 streaksremoveExit("", PS_EXIT_DATA_ERROR); 470 495 } 471 496 psFree(maskHeader); … … 477 502 psError(PS_ERR_IO, false, "failed to read primary header from %s\n", 478 503 sfiles->inWeight->resolved_name); 479 bail_out("", 1);504 streaksremoveExit("", 1); 480 505 } 481 506 // TODO: add keyword indicating that streaks have been removed … … 483 508 psError(PS_ERR_IO, false, "failed to write primary header to %s", 484 509 sfiles->outWeight->resolved_name); 485 bail_out("", PS_EXIT_DATA_ERROR);510 streaksremoveExit("", PS_EXIT_DATA_ERROR); 486 511 } 487 512 // TODO: add keyword indicating that this is a recovery image … … 489 514 psError(PS_ERR_IO, false, "failed to write primary header to %s", 490 515 sfiles->recWeight->resolved_name); 491 bail_out("", PS_EXIT_DATA_ERROR);516 streaksremoveExit("", PS_EXIT_DATA_ERROR); 492 517 } 493 518 psFree(weightHeader); … … 528 553 { 529 554 // XXX: Currently this function assumes that it is only used for a single 530 // chip single cell FPA (i.e. a sky file)555 // chip single cell FPA (i.e. a skycell) 531 556 pmFPAview *view = sf->view; 532 557 assert(view->chip == 0); … … 535 560 536 561 if (!sf->cell) { 537 bail_out("no cells found in chip", PS_EXIT_PROG_ERROR);562 streaksremoveExit("no cells found in chip", PS_EXIT_PROG_ERROR); 538 563 } 539 564 if (sf->cell->readouts->n != 1) { 540 565 psError(PS_ERR_PROGRAMMING, true, "unexpected number of readouts found: %ld", sf->cell->readouts->n); 541 bail_out("", PS_EXIT_PROG_ERROR);566 streaksremoveExit("", PS_EXIT_PROG_ERROR); 542 567 } 543 568 view->readout = 0; 544 569 pmReadout *readout = pmFPAviewThisReadout(view, sf->inImage->pmfile->fpa); 545 570 if (!readout) { 546 bail_out("readout 0 not found", PS_EXIT_PROG_ERROR);571 streaksremoveExit("readout 0 not found", PS_EXIT_PROG_ERROR); 547 572 } 548 573 … … 569 594 psError(PS_ERR_IO, false, "failed to read header from %s extnum: %d", 570 595 in->resolved_name, extnum); 571 bail_out("", PS_EXIT_DATA_ERROR); 572 } 573 596 streaksremoveExit("", PS_EXIT_DATA_ERROR); 597 } 574 598 575 599 if (!isImage(in)) { … … 584 608 psError(PS_ERR_IO, false, "failed to read image from %s extnum: %d", 585 609 in->resolved_name, extnum); 586 bail_out("", PS_EXIT_DATA_ERROR);610 streaksremoveExit("", PS_EXIT_DATA_ERROR); 587 611 } 588 612 in->numCols = in->image->numCols; … … 593 617 psError(PS_ERR_IO, false, "failed to read image cube from %s extnum: %d", 594 618 in->resolved_name, extnum); 595 bail_out("", PS_EXIT_DATA_ERROR);619 streaksremoveExit("", PS_EXIT_DATA_ERROR); 596 620 } 597 621 psImage *image = (psImage *) (in->imagecube->data[0]); … … 603 627 604 628 static void 605 set Options(sFile *sfile, psString extname, int bitpix, float bscale, float bzero)629 setFitsOptions(sFile *sfile, psString extname, int bitpix, float bscale, float bzero) 606 630 { 607 631 if (sfile->fits->options) { … … 646 670 647 671 psString extname = psMetadataLookupStr(&mdok, in->header, "EXTNAME"); 648 set Options(out, extname, bitpix, bscale, bzero);649 set Options(rec, extname, bitpix, bscale, bzero);672 setFitsOptions(out, extname, bitpix, bscale, bzero); 673 setFitsOptions(rec, extname, bitpix, bscale, bzero); 650 674 } 651 675 … … 673 697 if (!table) { 674 698 psError(PS_ERR_UNKNOWN, false, "failed to read table in extension %d from in->resolved name", extnum); 675 bail_out("", PS_EXIT_DATA_ERROR);699 streaksremoveExit("", PS_EXIT_DATA_ERROR); 676 700 } 677 701 678 702 if (!psFitsWriteTable(out->fits, out->header, table, extname)) { 679 703 psError(PS_ERR_UNKNOWN, false, "failed to copy table in extension %d", extnum); 680 bail_out("", PS_EXIT_DATA_ERROR);704 streaksremoveExit("", PS_EXIT_DATA_ERROR); 681 705 } 682 706 } … … 689 713 if (!rec->image) { 690 714 psError(PS_ERR_UNKNOWN, false, "failed to allocate recoveyr image for extnsion %d", extnum); 691 bail_out("", PS_EXIT_UNKNOWN_ERROR);715 streaksremoveExit("", PS_EXIT_UNKNOWN_ERROR); 692 716 } 693 717 psImageInit(rec->image, 0); … … 707 731 readImage(sf->inImage, sf->extnum); 708 732 if (SFILE_IS_IMAGE(sf->inImage)) { 709 sf->astrom = streakSetAstrometry(sf->astrom, sf->inAstrom->fpa, sf->chip, false, sf->inImage->header,710 sf->inImage-> numCols, sf->inImage->numRows);733 sf->astrom = streakSetAstrometry(sf->astrom, sf->inAstrom->fpa, sf->chip, false, 734 sf->inImage->header, sf->inImage->numCols, sf->inImage->numRows); 711 735 } 712 736 } … … 734 758 // psFitsCompressionGet(sf->inImage->image) gives compression none 735 759 // perhaps we should just use the definition of COMP_IMG in the configuration 736 psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 760 // XXX: turn off compression as a test 761 // psFitsSetCompression(sf->outImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 737 762 psFitsSetCompression(sf->recImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0); 738 763 … … 778 803 psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d", 779 804 sfile->resolved_name, extnum); 780 bail_out("", PS_EXIT_DATA_ERROR);805 streaksremoveExit("", PS_EXIT_DATA_ERROR); 781 806 } 782 807 psFree(sfile->image); … … 791 816 psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d", 792 817 sfile->resolved_name, extnum); 793 bail_out("", PS_EXIT_DATA_ERROR);818 streaksremoveExit("", PS_EXIT_DATA_ERROR); 794 819 } 795 820 psFree(sfile->header); … … 832 857 psError(PS_ERR_IO, false, "failed to close image to %s", 833 858 sfile->resolved_name); 834 bail_out("", PS_EXIT_DATA_ERROR);859 streaksremoveExit("", PS_EXIT_DATA_ERROR); 835 860 } 836 861 } … … 854 879 } 855 880 856 void 857 dumpAstro(streakFiles *sf) 858 { 859 strkPt pt; 860 if (!sf->inImage->image) { 861 return; 862 } 863 864 cellToSky(&pt, sf->astrom, 0, 0); 865 866 psString extname = psMetadataLookupStr(NULL, sf->inImage->header, "EXTNAME"); 867 868 printf("%2d %s %f %f\n", sf->extnum, extname, pt.x, pt.y); 869 } 870 881 static bool 882 replicate(nebServer *server, sFile *sfile, void *xattr) 883 { 884 if (!sfile->inNebulous) { 885 return true; 886 } 887 // for now just set "user.copies" to 2 888 if (!nebSetXattr(server, sfile->name, "user.copies", "2", NEB_REPLACE)) { 889 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server)); 890 return false; 891 } 892 if (!nebReplicate(server, sfile->name, NULL, NULL)) { 893 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server)); 894 return false; 895 } 896 return true; 897 } 898 899 // for any of the outputs that are stored in Nebulous set their extended attributes 900 // and replicate the files 901 902 static bool 903 replicateOutputs(streakFiles *sfiles) 904 { 905 bool status = false; 906 psString neb_server = getenv("NEB_SERVER"); 907 908 // XXX: Note: all of the flags to psError should be true, but I don't think nebclient 909 // uses psError 910 if (!neb_server) { 911 neb_server = psMetadataLookupStr(&status, sfiles->config->site, "NEB_SERVER"); 912 if (!status) { 913 psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER."); 914 return false; 915 } 916 } 917 918 if (!neb_server) { 919 psError(PM_ERR_CONFIG, true, "Could not determine nebulous server URI."); 920 return false; 921 } 922 923 sfiles->nebServer = nebServerAlloc(neb_server); 924 if (!sfiles->nebServer) { 925 psError(PM_ERR_SYS, true, "failed to create a nebServer object."); 926 return false; 927 } 928 929 // XXX: TODO: need a nebGetXatrr function, but there isn't one 930 void *xattr = NULL; 931 932 if (!replicate(sfiles->nebServer, sfiles->outImage, xattr)) { 933 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 934 return false; 935 } 936 937 #ifdef notyet 938 // don't replicate mask and weight images until we can look up 939 // the input's xattr. There may be a perl program that can getXattr 940 if (sfiles->outMask) { 941 // get xattr from input to see if we need to replicate 942 if (!replicate(sfiles->nebServer, sfiles->outMask, xattr)) { 943 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 944 return false; 945 } 946 } 947 if (sfiles->outWeight) { 948 // get xattr from input to see if we need to replicate 949 if (!replicate(sfiles->nebServer, sfiles->outWeight, xattr)) { 950 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 951 return false; 952 } 953 } 954 #endif 955 956 // replicate the recovery images (if in nebulous) 957 // perhaps whether we do that or not should be configurable. 958 // Sounds like we need a recipe 959 960 return true; 961 } 962 static bool 963 swapOutputsToInputs(streakFiles *sfiles) 964 { 965 bool status = false; 966 967 if (!sfiles->nebServer) { 968 // no output files are in nebulous 969 return true; 970 } 971 972 // XXX: we should check for consistency before here 973 // We need to insure that the database is consistent 974 // If input is in nebulous, output must be 975 // if input is not in nebulous output must not be Catch in parseArguments 976 // if not in nebulous create a backup of input before overwriting 977 978 if (sfiles->inImage->inNebulous && sfiles->outImage->inNebulous) { 979 if (!nebSwap(sfiles->nebServer, sfiles->outImage->name, sfiles->inImage->name)) { 980 psError(PM_ERR_SYS, false, "failed to swap instances for Image\n%s.", 981 nebErr(sfiles->nebServer)); 982 return false; 983 } 984 } 985 986 // TODO: handle weight and mask images 987 988 return true; 989 } 990 static bool 991 deleteTemps(streakFiles *sfiles) 992 { 993 bool status = false; 994 995 if (!sfiles->nebServer) { 996 // no output files are in nebulous 997 return true; 998 } 999 1000 // XXX: we should check for consistency before here 1001 // We need to insure that the database is consistent 1002 // If input is in nebulous, output must be 1003 // if input is not in nebulous output must not be Catch in parseArguments 1004 // if not in nebulous create a backup of input before overwriting 1005 1006 if (sfiles->outImage->inNebulous) { 1007 if (!nebDelete(sfiles->nebServer, sfiles->outImage->name)) { 1008 psError(PM_ERR_SYS, false, "failed to delete %s\n%s.", sfiles->outImage->name, 1009 nebErr(sfiles->nebServer)); 1010 return false; 1011 } 1012 } 1013 1014 // TODO: weight and mask images 1015 1016 return true; 1017 } 871 1018 872 1019 int … … 942 1089 pixelPos = psArrayGet (pixels, i); 943 1090 imageValue = psImageGet (sfiles->inImage->image, pixelPos->x, pixelPos->y); 944 weightValue = psImageGet (sfiles->inWeight->image, pixelPos->x, pixelPos->y);945 maskValue = psImageGet (sfiles->inMask->image, pixelPos->x, pixelPos->y);946 947 1091 psImageSet (sfiles->recImage->image, pixelPos->x, pixelPos->y, imageValue); 948 psImageSet (sfiles->recWeight->image, pixelPos->x, pixelPos->y, weightValue);949 psImageSet (sfiles->recMask->image, pixelPos->x, pixelPos->y, maskValue);950 951 1092 psImageSet (sfiles->outImage->image, pixelPos->x, pixelPos->y, NAN); 952 psImageSet (sfiles->outWeight->image, pixelPos->x, pixelPos->y, NAN); 953 // TODO: 954 // Need to get mask weight for PM_MASK_DETECTOR. Is this stored 955 // in a config somewhere? Not sure how to properly set the maskValue. 956 psImageSet (sfiles->outMask->image, pixelPos->x, pixelPos->y, maskValue); 1093 if (sfiles->inWeight) { 1094 weightValue = psImageGet (sfiles->inWeight->image, pixelPos->x, pixelPos->y); 1095 psImageSet (sfiles->recWeight->image, pixelPos->x, pixelPos->y, weightValue); 1096 psImageSet (sfiles->outWeight->image, pixelPos->x, pixelPos->y, NAN); 1097 } 1098 if (sfiles->inMask) { 1099 maskValue = psImageGet (sfiles->inMask->image, pixelPos->x, pixelPos->y); 1100 psImageSet (sfiles->recMask->image, pixelPos->x, pixelPos->y, maskValue); 1101 // TODO: 1102 // Need to get mask weight for PM_MASK_DETECTOR. Is this stored 1103 // in a config somewhere? Not sure how to properly set the maskValue. 1104 psImageSet (sfiles->outMask->image, pixelPos->x, pixelPos->y, maskValue); 1105 } 957 1106 } 958 1107 psArrayElementsFree (pixels); 959 1108 960 // dumpAstro(sfiles); 961 // write out the destreaked temporary images 1109 // write out the destreaked temporary images and the recovery images 962 1110 writeImages(sfiles); 963 1111 } while (streakFilesNextExtension(sfiles)); 964 1112 965 // close the destreaked temporary images1113 // close all files 966 1114 closeImages(sfiles); 967 1115 968 // TODO:969 // Now copy the destreaked images files that we made above970 // over each nebulous instances of input files971 972 1116 // NOTE: from here on we can't just quit if something goes wrong. 973 // especially if we're working on a rawImage 974 1117 // especially if we're working at the raw stage 1118 1119 if (!replicateOutputs(sfiles)) { 1120 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files"); 1121 psErrorStackPrint(stderr, ""); 1122 exit(PS_EXIT_UNKNOWN_ERROR); 1123 } 1124 1125 bool status; 1126 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) { 1127 // swap the instances for the input and output 1128 // Note this is a database operation. No file I/O is performed 1129 if (!swapOutputsToInputs(sfiles)) { 1130 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files"); 1131 // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that 1132 // it has done and give a detailed report of what happened 1133 psErrorStackPrint(stderr, ""); 1134 exit(PS_EXIT_UNKNOWN_ERROR); 1135 } 1136 } 1137 1138 if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) { 1139 // delete the temporary storage objects (which now points to the original image(s) 1140 if (!deleteTemps(sfiles)) { 1141 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files"); 1142 // XXX: Now what? At this point the output files have been swapped, so we can't 1143 // repeat the operation. 1144 // Returning error status is problematic. Maybe just print an error message and 1145 // let other system tools clean up 1146 psErrorStackPrint(stderr, ""); 1147 exit(PS_EXIT_UNKNOWN_ERROR); 1148 } 1149 } 1150 1151 // PAU 975 1152 976 1153 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.
