IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 22, 2008, 9:42:57 PM (18 years ago)
Author:
bills
Message:

first cut at nebulous operations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/streaksremove.c

    r20280 r20340  
    66extern bool  sFileReplace(sFile *dest, sFile *src);
    77
    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
     10void streaksremoveExit(psString str, int exitCode) {
    911    psErrorStackPrint(stderr, str);
    1012    exit(exitCode);
     
    2022
    2123psString
    22 resolveName(pmConfig *config, sFile *sfile)
    23 {
    24     // TODO: do the nebulous lookup
    25     sfile->inNebulous = false;
    26 
    27     return psStringCopy(sfile->name);
     24resolveFilename(pmConfig *config, sFile *sfile, bool create)
     25{
     26    sfile->inNebulous = IN_NEBULOUS(sfile->name);
     27
     28    return pmConfigConvertFilename(sfile->name, config, create, create);
    2829}
    2930
     
    3536    memset(sfile, 0, sizeof(sFile));
    3637
    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")) {
    5043        // 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
    5263        sfile->pmfile = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT");
    5364        if (!sfile->pmfile) {
    5465            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);
    5770        pmFPAview *view = pmFPAviewAlloc(0);
    5871        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    5972            psError(PS_ERR_UNKNOWN, false, "Failed to load input.");
    60             bail_out("", PS_EXIT_DATA_ERROR);
     73            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    6174        }
    6275        psFree(view);
    63         sfile->name = sfile->pmfile->filename;
    64         sfile->resolved_name = psStringCopy(sfile->name);
     76       
    6577        // copy header from fpu
    6678        sfile->header = (psMetadata*) psMemIncrRefCounter(sfile->pmfile->fpa->hdu->header);
     79
    6780        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;
    6891    }
    6992
     
    7295    if (outputExt) {
    7396        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        }
    75103        sfile->fits = psFitsOpen(sfile->resolved_name, "w");
    76104        sfile->fits->options = psFitsOptionsAlloc();
    77105    } else {
    78         sfile->resolved_name = resolveName(config, sfile);
     106        sfile->resolved_name = resolveFilename(config, sfile, false);
    79107        if (!sfile->resolved_name) {
    80108            psError(PS_ERR_IO, false, "Failed to resolve name for %s", sfile->name);
    81109            sFileFree(sfile);
    82             bail_out("", 1);
     110            streaksremoveExit("", 1);
    83111        }
    84112        sfile->fits = psFitsOpen(sfile->resolved_name, "r");
     
    92120                    sfile->resolved_name, outputExt ? "writing" : "reading");
    93121        sFileFree(sfile);
    94         bail_out("", 1);
     122        streaksremoveExit("", 1);
    95123    }
    96124
    97125    return sfile;
    98126}
    99 
    100 #ifdef notyet
    101         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 #endif
    109127
    110128
     
    121139
    122140    if (sf->bilevelAstrometry) {
    123 #ifdef notyet
    124141        // Do we get here for GPC1 ? I don't necessarily have an fpa for the input image
    125         if (!pmAstromReadBilevelMosaic(sf->inImage->file->fpa, phu->header)) {
     142        if (!pmAstromReadBilevelMosaic(sf->inAstrom->fpa, phu->header)) {
    126143            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");
    127144            return false;
    128145        }
    129 #endif
    130146    } else {
    131147        pmHDU *hdu = pmFPAviewThisHDU(sf->view, sf->inAstrom->fpa);
     
    150166    if (!pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_BEFORE)) {
    151167        psError(PS_ERR_UNKNOWN, false, "Failed to load input.");
    152         bail_out("", PS_EXIT_DATA_ERROR);
     168        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    153169    }
    154170
     
    166182    if (!sf->chip) {
    167183        psError(PS_ERR_UNKNOWN, true, "Failed to find chip with data.");
    168         bail_out("", PS_EXIT_DATA_ERROR);
     184        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    169185    }
    170186    if (!pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_BEFORE)) {
    171187        psError(PS_ERR_UNKNOWN, false, "failed to load chip");
    172         bail_out("", PS_EXIT_DATA_ERROR);
     188        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    173189    }
    174190
     
    185201    sf->config = config;
    186202
    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
    189204    ippStage stage = psMetadataLookupS32(&status, config->arguments, "STAGE");
    190205
     
    216231        sf->inAstrom = sf->inImage->pmfile;
    217232        if (!sf->inImage->pmfile) {
    218             bail_out("unexpected null pmFPAfile", PS_EXIT_CONFIG_ERROR);
     233            streaksremoveExit("unexpected null pmFPAfile", PS_EXIT_CONFIG_ERROR);
    219234        }
    220235    }
     
    269284        psError(PS_ERR_IO, false,
    270285            "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);
    272287    }
    273288    return true;
     
    315330    } else {
    316331        psError(PS_ERR_UNKNOWN, true, "unknown stage string: %s\n", stageStr);
    317         bail_out("", PS_EXIT_DATA_ERROR);
     332        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    318333        // notreached
    319334        return IPP_STAGE_NONE;
     
    326341    pmConfig *config = pmConfigRead(&argc, argv, NULL);
    327342    if (!config) {
    328         bail_out("failed to parse arguments", PS_EXIT_CONFIG_ERROR);
     343        streaksremoveExit("failed to parse arguments", PS_EXIT_CONFIG_ERROR);
    329344    }
    330345
     
    384399   
    385400    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)) {
    387402            psError(PS_ERR_UNKNOWN, true, "-astrom is required for raw and chip stages\n");
    388403            return NULL;
     
    418433        psError(PS_ERR_UNKNOWN, true, "-recovery is required for -stage raw\n");
    419434        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);
    420445    }
    421446
     
    432457        psError(PS_ERR_IO, false, "failed to read primary header from %s\n",
    433458            sfiles->inImage->resolved_name);
    434         bail_out("", PS_EXIT_DATA_ERROR);
     459        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    435460    }
    436461   
     
    439464        psError(PS_ERR_IO, false, "failed to write primary header to %s",
    440465            sfiles->outImage->resolved_name);
    441         bail_out("", PS_EXIT_DATA_ERROR);
     466        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    442467    }
    443468    // TODO: add keyword indicating that this is the recovery image
     
    445470        psError(PS_ERR_IO, false, "failed to write primary header to %s",
    446471            sfiles->recImage->resolved_name);
    447         bail_out("", PS_EXIT_DATA_ERROR);
     472        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    448473    }
    449474    psFree(imageHeader);
     
    455480            psError(PS_ERR_IO, false, "failed to read primary header from %s\n",
    456481                sfiles->inMask->resolved_name);
    457             bail_out("", 1);
     482            streaksremoveExit("", 1);
    458483        }
    459484        // TODO: add keyword indicating that streaks have been removed
     
    461486            psError(PS_ERR_IO, false, "failed to write primary header to %s",
    462487                sfiles->outMask->resolved_name);
    463             bail_out("", PS_EXIT_DATA_ERROR);
     488            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    464489        }
    465490        // TODO: add keyword indicating that this is the recovery image
     
    467492            psError(PS_ERR_IO, false, "failed to write primary header to %s",
    468493                sfiles->recMask->resolved_name);
    469             bail_out("", PS_EXIT_DATA_ERROR);
     494            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    470495        }
    471496        psFree(maskHeader);
     
    477502            psError(PS_ERR_IO, false, "failed to read primary header from %s\n",
    478503                sfiles->inWeight->resolved_name);
    479             bail_out("", 1);
     504            streaksremoveExit("", 1);
    480505        }
    481506        // TODO: add keyword indicating that streaks have been removed
     
    483508            psError(PS_ERR_IO, false, "failed to write primary header to %s",
    484509                sfiles->outWeight->resolved_name);
    485             bail_out("", PS_EXIT_DATA_ERROR);
     510            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    486511        }
    487512        // TODO: add keyword indicating that this is a recovery image
     
    489514            psError(PS_ERR_IO, false, "failed to write primary header to %s",
    490515                sfiles->recWeight->resolved_name);
    491             bail_out("", PS_EXIT_DATA_ERROR);
     516            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    492517        }
    493518        psFree(weightHeader);
     
    528553{
    529554    // XXX: Currently this function assumes that it is only used for a single
    530     // chip single cell FPA (i.e. a skyfile)
     555    // chip single cell FPA (i.e. a skycell)
    531556    pmFPAview *view = sf->view;
    532557    assert(view->chip == 0);
     
    535560
    536561    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);
    538563    }
    539564    if (sf->cell->readouts->n != 1) {
    540565        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);
    542567    }
    543568    view->readout = 0;
    544569    pmReadout *readout = pmFPAviewThisReadout(view, sf->inImage->pmfile->fpa);
    545570    if (!readout) {
    546         bail_out("readout 0 not found", PS_EXIT_PROG_ERROR);
     571        streaksremoveExit("readout 0 not found", PS_EXIT_PROG_ERROR);
    547572    }
    548573
     
    569594        psError(PS_ERR_IO, false, "failed to read header from %s extnum: %d",
    570595            in->resolved_name, extnum);
    571         bail_out("", PS_EXIT_DATA_ERROR);
    572     }
    573 
     596        streaksremoveExit("", PS_EXIT_DATA_ERROR);
     597    }
    574598
    575599    if (!isImage(in)) {
     
    584608            psError(PS_ERR_IO, false, "failed to read image from %s extnum: %d",
    585609                in->resolved_name, extnum);
    586             bail_out("", PS_EXIT_DATA_ERROR);
     610            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    587611        }
    588612        in->numCols = in->image->numCols;
     
    593617            psError(PS_ERR_IO, false, "failed to read image cube from %s extnum: %d",
    594618                in->resolved_name, extnum);
    595             bail_out("", PS_EXIT_DATA_ERROR);
     619            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    596620        }
    597621        psImage *image = (psImage *) (in->imagecube->data[0]);
     
    603627
    604628static void
    605 setOptions(sFile *sfile, psString extname, int bitpix, float bscale, float bzero)
     629setFitsOptions(sFile *sfile, psString extname, int bitpix, float bscale, float bzero)
    606630{
    607631    if (sfile->fits->options) {
     
    646670
    647671    psString extname = psMetadataLookupStr(&mdok, in->header, "EXTNAME");
    648     setOptions(out, extname, bitpix, bscale, bzero);
    649     setOptions(rec, extname, bitpix, bscale, bzero);
     672    setFitsOptions(out, extname, bitpix, bscale, bzero);
     673    setFitsOptions(rec, extname, bitpix, bscale, bzero);
    650674}
    651675
     
    673697    if (!table) {
    674698        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);
    676700    }
    677701
    678702    if (!psFitsWriteTable(out->fits, out->header, table, extname)) {
    679703        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);
    681705    }
    682706}
     
    689713    if (!rec->image) {
    690714        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);
    692716    }
    693717    psImageInit(rec->image, 0);
     
    707731        readImage(sf->inImage, sf->extnum);
    708732        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);
    711735        }
    712736    }
     
    734758    // psFitsCompressionGet(sf->inImage->image) gives compression none
    735759    // 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);
    737762    psFitsSetCompression(sf->recImage->fits, PS_FITS_COMPRESS_RICE, sf->tiles, 8, 0, 0);
    738763
     
    778803        psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d",
    779804            sfile->resolved_name, extnum);
    780         bail_out("", PS_EXIT_DATA_ERROR);
     805        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    781806    }
    782807    psFree(sfile->image);
     
    791816        psError(PS_ERR_IO, false, "failed to write image to %s extnum: %d",
    792817            sfile->resolved_name, extnum);
    793         bail_out("", PS_EXIT_DATA_ERROR);
     818        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    794819    }
    795820    psFree(sfile->header);
     
    832857        psError(PS_ERR_IO, false, "failed to close image to %s",
    833858            sfile->resolved_name);
    834         bail_out("", PS_EXIT_DATA_ERROR);
     859        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    835860    }
    836861}
     
    854879}
    855880
    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 
     881static bool
     882replicate(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
     902static bool
     903replicateOutputs(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}
     962static bool
     963swapOutputsToInputs(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}
     990static bool
     991deleteTemps(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}
    8711018
    8721019int
     
    9421089            pixelPos = psArrayGet (pixels, i);
    9431090            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 
    9471091            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 
    9511092            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            }
    9571106        }
    9581107        psArrayElementsFree (pixels);
    9591108
    960         // dumpAstro(sfiles);
    961         // write out the destreaked temporary images
     1109        // write out the destreaked temporary images and the recovery images
    9621110        writeImages(sfiles);
    9631111    } while (streakFilesNextExtension(sfiles));
    9641112
    965     // close the destreaked temporary images
     1113    // close all files
    9661114    closeImages(sfiles);
    9671115
    968     // TODO:
    969     // Now copy the destreaked images files that we made above
    970     // over each nebulous instances of input files
    971 
    9721116    // 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
    9751152
    9761153    return 0;
Note: See TracChangeset for help on using the changeset viewer.