- Timestamp:
- Jun 25, 2009, 2:00:56 PM (17 years ago)
- Location:
- branches/eam_branches/20090522
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
magic/remove/src (modified) (1 prop)
-
magic/remove/src/streaksio.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090522
- Property svn:mergeinfo changed
-
branches/eam_branches/20090522/magic/remove/src
- Property svn:ignore
-
old new 3 3 streakscompare 4 4 streaksrelease 5 makefile
-
- Property svn:ignore
-
branches/eam_branches/20090522/magic/remove/src/streaksio.c
r23965 r24557 19 19 psMemSetDeallocator(sf, (psFreeFunc) streakFilesFree); 20 20 memset(sf, 0, sizeof(*sf)); 21 22 if (remove) { 23 // remember pointer so that streaksExit can delete temps 24 setStreakFiles(sf); 25 } 21 26 22 27 sf->config = config; … … 160 165 } 161 166 167 // figure out if a nebulous instance is a non-destreaked file 168 static bool 169 nebFileIsDestreaked(sFile *sfile) 170 { 171 if (!sfile->resolved_name) { 172 psError(PS_ERR_PROGRAMMING, true, "resolved name is null"); 173 return false; 174 } 175 psFits *fits = psFitsOpen(sfile->resolved_name, "r"); 176 if (!fits) { 177 psError(PS_ERR_IO, true, "failed open %s", sfile->name); 178 // can't tell if it is a destreaked file 179 return false; 180 } 181 psMetadata *header = psFitsReadHeader(NULL, fits); 182 if (!header) { 183 psError(PS_ERR_IO, true, "failed to read header for: %s", sfile->name); 184 return false; 185 } 186 bool mdok; 187 bool isDestreaked = psMetadataLookupBool(&mdok, header, "PSDESTRK"); 188 if (mdok && isDestreaked) { 189 return true; 190 } else { 191 psError(PS_ERR_IO, false, "output file already exists and may not be de-streaked: %s", sfile->name); 192 return false; 193 } 194 } 195 162 196 static psString 163 197 resolveFilename(pmConfig *config, sFile *sfile, bool create) … … 171 205 // delete the existing file, since there may be more than one 172 206 // instance. It will get created below in pmConfigConvertFilename 173 if (nebFind(server, sfile->name)) { 207 if ((sfile->resolved_name = nebFind(server, sfile->name)) != NULL) { 208 if (!nebFileIsDestreaked(sfile)) { 209 psError(PS_ERR_IO, false, "attempting to delete file that has not been destreaked %s", sfile->name); 210 return NULL; 211 } 212 nebFree(sfile->resolved_name); 213 sfile->resolved_name = NULL; 174 214 nebDelete(server, sfile->name); 175 215 } … … 193 233 // all of the keywords in the raw image files written to the output destreaked files 194 234 195 if (! CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {235 if (!outputFilename && !CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) { 196 236 // stage is warp or diff AND fileSelect eq "INPUT" 197 237 // get data from pmFPAfile. … … 250 290 } 251 291 252 // if outputFilename is not null name it contains the "directory" 292 // if outputFilename is not null name it contains the "directory" (perhaps with a prefix like SR_) 253 293 // and outputFilename is the basename name of the file (or nebulous key) 254 294 // and the file is to be opened for writing … … 334 374 335 375 void 376 addDestreakKeyword(psMetadata *header) 377 { 378 psMetadataAddBool(header, PS_LIST_TAIL, "PSDESTRK", PS_META_REPLACE, 379 "Have streaks been removed from image?", true); 380 } 381 382 void 383 addRecoveryKeyword(psMetadata *header) 384 { 385 psMetadataAddBool(header, PS_LIST_TAIL, "PSRECOVR", PS_META_REPLACE, 386 "Does this image contain excised streak pixels?", true); 387 } 388 389 void 336 390 copyPHU(streakFiles *sfiles, bool remove) 337 391 { … … 344 398 streaksExit("", PS_EXIT_DATA_ERROR); 345 399 } 346 347 // TODO: add keyword indicating that streaks have been removed 400 psMetadata *recHeader = NULL; 401 if (remove && sfiles->recImage) { 402 recHeader = psMetadataCopy(NULL, imageHeader); 403 addRecoveryKeyword(recHeader); 404 } 405 406 // add keyword indicating that streaks have been removed 407 addDestreakKeyword(imageHeader); 408 348 409 if (!psFitsWriteBlank(sfiles->outImage->fits, imageHeader, NULL)) { 349 410 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 351 412 streaksExit("", PS_EXIT_DATA_ERROR); 352 413 } 353 // TODO: add keyword indicating that this is the recovery image 354 if (remove && sfiles->recImage && !psFitsWriteBlank(sfiles->recImage->fits, imageHeader, NULL)) { 414 if (recHeader && !psFitsWriteBlank(sfiles->recImage->fits, recHeader, NULL)) { 355 415 psError(PS_ERR_IO, false, "failed to write primary header to %s", 356 416 sfiles->recImage->resolved_name); 357 417 streaksExit("", PS_EXIT_DATA_ERROR); 358 418 } 419 psFree(recHeader); 420 recHeader = NULL; 359 421 psFree(imageHeader); 360 422 … … 367 429 streaksExit("", 1); 368 430 } 369 // TODO: add keyword indicating that streaks have been removed 431 if (remove && sfiles->recMask) { 432 recHeader = psMetadataCopy(NULL, maskHeader); 433 // add keyword indicating that this is the recovery image 434 addRecoveryKeyword(recHeader); 435 } 436 // add keyword indicating that streaks have been removed 437 addDestreakKeyword(maskHeader); 370 438 if (!psFitsWriteBlank(sfiles->outMask->fits, maskHeader, NULL)) { 371 439 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 373 441 streaksExit("", PS_EXIT_DATA_ERROR); 374 442 } 375 // TODO: add keyword indicating that this is the recovery image 376 if (remove && sfiles->recMask && !psFitsWriteBlank(sfiles->recMask->fits, maskHeader, NULL)) { 443 if (recHeader && !psFitsWriteBlank(sfiles->recMask->fits, recHeader, NULL)) { 377 444 psError(PS_ERR_IO, false, "failed to write primary header to %s", 378 445 sfiles->recMask->resolved_name); 379 446 streaksExit("", PS_EXIT_DATA_ERROR); 380 447 } 448 psFree(recHeader); 449 recHeader = NULL; 381 450 psFree(maskHeader); 382 451 } … … 389 458 streaksExit("", 1); 390 459 } 391 // TODO: add keyword indicating that streaks have been removed 460 if (remove && sfiles->recWeight) { 461 recHeader = psMetadataCopy(NULL, weightHeader); 462 // add keyword indicating that this is a recovery image 463 addRecoveryKeyword(recHeader); 464 } 465 466 // add keyword indicating that streaks have been removed 467 addDestreakKeyword(weightHeader); 392 468 if (!psFitsWriteBlank(sfiles->outWeight->fits, weightHeader, NULL)) { 393 469 psError(PS_ERR_IO, false, "failed to write primary header to %s", … … 395 471 streaksExit("", PS_EXIT_DATA_ERROR); 396 472 } 397 // TODO: add keyword indicating that this is a recovery image 398 if (remove && sfiles->recWeight && !psFitsWriteBlank(sfiles->recWeight->fits, weightHeader, NULL)) { 473 if (recHeader && !psFitsWriteBlank(sfiles->recWeight->fits, recHeader, NULL)) { 399 474 psError(PS_ERR_IO, false, "failed to write primary header to %s", 400 475 sfiles->recWeight->resolved_name); … … 402 477 } 403 478 psFree(weightHeader); 479 psFree(recHeader); 404 480 } 405 481 } … … 566 642 567 643 static void 568 setFitsOptions(sFile *sfile, int bitpix, float bscale, float bzero) 644 setFitsOptions(sFile *sfile, int bitpix, float bscale, float bzero, psFitsCompressionType compType, 645 psVector *tiles) 569 646 { 570 647 if (!sfile) { … … 579 656 sfile->fits->options->bscale = bscale; 580 657 sfile->fits->options->bzero = bzero; 581 } 582 583 void 584 copyFitsOptions(sFile *out, sFile *rec, sFile *in) 585 { 658 659 psFitsSetCompression(sfile->fits, compType, tiles, 8, 0, 0); 660 } 661 662 void 663 copyFitsOptions(sFile *out, sFile *rec, sFile *in, psVector *tiles) 664 { 665 bool mdok; 666 psString compTypeStr = psMetadataLookupStr(&mdok, in->header, "ZCMPTYPE"); 667 psFitsCompressionType compType = psFitsCompressionTypeFromString(compTypeStr); 668 if (compType == PS_FITS_COMPRESS_NONE) { 669 return; 670 } 586 671 // Get current BITPIX, BSCALE, BZERO, EXTNAME 587 672 // Probably not necessary to look the numerical values up in this … … 610 695 611 696 #ifdef STREAKS_COMPRESS_OUTPUT 612 // Paul says that I should be able to leave this blank 613 bitpix = 0; 614 setFitsOptions(out, bitpix, bscale, bzero); 615 setFitsOptions(rec, bitpix, bscale, bzero); 697 // printf("%d %f %f\n", bitpix, bscale, bzero); 698 setFitsOptions(out, bitpix, bscale, bzero, compType, tiles); 699 setFitsOptions(rec, bitpix, bscale, bzero, compType, tiles); 616 700 #endif 617 701 } … … 790 874 791 875 bool 792 replicate(sFile * sfile, void *xattr)793 { 794 if (! sfile->inNebulous) {876 replicate(sFile *outFile, sFile *inFile) 877 { 878 if (!outFile->inNebulous) { 795 879 return true; 796 880 } 797 881 nebServer *server = getNebServer(NULL); 798 882 799 // for now just set "user.copies" to 2 800 if (!nebSetXattr(server, sfile->name, "user.copies", "2", NEB_REPLACE)) { 801 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server)); 883 char *user_copies = nebGetXattr(server, inFile->name, "user.copies"); 884 bool free_user_copies = true; 885 if (user_copies == NULL) { 886 user_copies = "2"; 887 free_user_copies = false; 888 } 889 if (!nebSetXattr(server, outFile->name, "user.copies", user_copies, NEB_REPLACE)) { 890 psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", outFile->name, nebErr(server)); 802 891 return false; 803 892 } 804 if (!nebReplicate(server, sfile->name, NULL, NULL)) {805 psError(PM_ERR_UNKNOWN, true, "neb SetXattr failed for %s\n%s", sfile->name, nebErr(server));893 if (!nebReplicate(server, outFile->name, "any", NULL)) { 894 psError(PM_ERR_UNKNOWN, true, "nebReplicate failed for %s\n%s", outFile->name, nebErr(server)); 806 895 return false; 896 } 897 if (free_user_copies) { 898 nebFree(user_copies); 807 899 } 808 900 return true; … … 817 909 bool status = false; 818 910 819 // XXX: TODO: need a nebGetXatrr function, but there isn't one 820 // another option would be to take the number of copies to be 821 // created as an option. That way the system could decide 822 // whether to replicate anything other than raw Image files 823 void *xattr = NULL; 824 825 if (!replicate(sfiles->outImage, xattr)) { 911 if (!replicate(sfiles->outImage, sfiles->inImage)) { 826 912 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 827 913 return false; 828 914 } 829 915 830 #ifdef notyet831 // XXX: don't replicate mask and weight images until we can look up832 // the input's xattr. There may be a perl program that can getXattr833 916 if (sfiles->outMask) { 834 // get xattr from input to see if we need to replicate 835 if (!replicate(sfiles->outMask, xattr)) { 917 if (!replicate(sfiles->outMask, sfiles->inMask)) { 836 918 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 837 919 return false; 838 920 } 839 921 } 840 if (sfiles->outWeight) { 841 // get xattr from input to see if we need to replicate 842 if (!replicate(sfiles->outWeight, xattr)) { 922 if (sfiles->outChMask) { 923 if (!replicate(sfiles->outChMask, sfiles->inChMask)) { 843 924 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 844 925 return false; 845 926 } 846 927 } 847 #endif 848 849 // replicate the recovery images (if in nebulous) 928 if (sfiles->outWeight) { 929 if (!replicate(sfiles->outWeight, sfiles->inWeight)) { 930 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 931 return false; 932 } 933 } 934 935 // XXX: replicate the recovery images (if in nebulous) 850 936 // perhaps whether we do that or not should be configurable. 851 937 // Sounds like we need a recipe … … 904 990 } 905 991 992 if (sfiles->outChMask) { 993 if (!swapOutputToInput(sfiles->inChMask, sfiles->outChMask)) { 994 psError(PM_ERR_SYS, false, "failed to swap instances for chip mask."); 995 return false; 996 } 997 } 998 906 999 if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) { 907 1000 psError(PM_ERR_SYS, false, "failed to swap instances for Image."); … … 936 1029 { 937 1030 if (sfiles->outMask) { 938 if (!deleteFile(sfiles->outMask)) { 939 psError(PM_ERR_SYS, false, "failed to delete Mask."); 940 return false; 941 } 1031 deleteFile(sfiles->outMask); 1032 } 1033 1034 if (sfiles->outChMask) { 1035 deleteFile(sfiles->outChMask); 942 1036 } 943 1037 944 1038 if (sfiles->outWeight) { 945 if (!deleteFile(sfiles->outWeight)) { 946 psError(PM_ERR_SYS, false, "failed to delete Weight."); 947 return false; 948 } 949 } 950 951 if (!deleteFile(sfiles->outImage)) { 952 psError(PM_ERR_SYS, false, "failed to delete Image."); 953 return false; 1039 deleteFile(sfiles->outWeight); 1040 } 1041 1042 if (sfiles->outImage) { 1043 deleteFile(sfiles->outImage); 954 1044 } 955 1045
Note:
See TracChangeset
for help on using the changeset viewer.
