IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 31, 2008, 4:59:42 PM (18 years ago)
Author:
bills
Message:

Treat ouput arguments -tmproot -recovery as directories.
Use the basenames of the input files for the output basnames.
encapsulated code to detete files in a function

File:
1 edited

Legend:

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

    r20360 r20496  
    22#include "streaksextern.h"
    33#include "libgen.h"
     4#include "unistd.h"
    45
    56extern bool  sFileLock(sFile * sfile);
     
    9091
    9192sFile *sFileOpen(pmConfig *config, ippStage stage, psString fileSelect,
    92     psString outputExt, bool required)
     93    psString outputFilename, bool required)
    9394{
    9495    bool status;
     
    9697    memset(sfile, 0, sizeof(sFile));
    9798
    98     // We use psFits directly to read the image file unless the stage is warp
     99    // We use psFits directly to read the image unless the stage is warp
    99100    // or diff. In those cases we use the pmFPAfile functions to read the image file
    100     // to make managing the astrometry easy
     101    // to make managing the astrometry easy.
     102    // The reason we don't use pmFPAfile in all cases is that I was having trouble getting
     103    // all of the keywords in the raw image files written to the output destreaked files
    101104
    102105    if (!CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {
    103106        // stage is warp or diff AND fileSelect eq "INPUT"
    104         // get data from pmFPAfile. We read the mask and weight files using psFits
     107        // get data from pmFPAfile.
    105108
    106109        // we need to know what the nebulous and real filenames are so we steal
     
    112115            streaksremoveExit("", PS_EXIT_PROG_ERROR);
    113116        }
    114         if (infiles->n < 1) {
    115             psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, "INPUT");
     117        if (infiles->n != 1) {
     118            psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments expencted 1\n",
     119                infiles->n, "INPUT");
    116120            streaksremoveExit("", PS_EXIT_DATA_ERROR);
    117121        }
     122        // end of file name lookup code adapted from pmFPAfileDefineFromArgs
     123        //
    118124        sfile->name = psStringCopy(infiles->data[0]);
    119         // end of file name lookup code adapted from pmFPAfileDefineFromArgs
    120 
    121125        sfile->inNebulous = IN_NEBULOUS(sfile->name);
    122126
     127        // XXX: I should probably be using a different file rule for the diff, but I don't
     128        // have an input rule that takes a diff image. This should be compatible
    123129        sfile->pmfile = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT");
    124130        if (!sfile->pmfile) {
     
    141147    }
    142148
    143     // using psFits for i/o
    144 
    145     sfile->name = psMetadataLookupStr(&status, config->arguments, fileSelect);
    146     if (!status || !sfile->name) {
     149    // For all other files we use using psFits for i/o
     150
     151    psString name = psMetadataLookupStr(&status, config->arguments, fileSelect);
     152    if (!status || !name) {
    147153        if (required) {
    148154            psError(PS_ERR_IO, false, "Failed to lookup name for %s", fileSelect);
     
    153159    }
    154160
    155     // if outputExt is not null it contains the extension to append to name
     161    // if outputFilename is not null name it contains the "directory"
     162    // and outputFilename is the basename name of the file (or nebulous key)
    156163    // and the file is to be opened for writing
    157     if (outputExt) {
    158         psStringAppend(&sfile->name, outputExt);
     164    if (outputFilename) {
     165        psStringAppend(&sfile->name, "%s%s", name, outputFilename);
    159166        sfile->resolved_name = resolveFilename(config, sfile, true);
    160167        if (!sfile->resolved_name) {
     
    166173        sfile->fits->options = psFitsOptionsAlloc();
    167174    } else {
     175        sfile->name = psStringCopy(name);
    168176        sfile->resolved_name = resolveFilename(config, sfile, false);
    169177        if (!sfile->resolved_name) {
     
    180188    if (!sfile->fits) {
    181189        psError(PS_ERR_IO, false, "failed to open fits file %s for %s",
    182                     sfile->resolved_name, outputExt ? "writing" : "reading");
     190                    sfile->resolved_name, outputFilename ? "writing" : "reading");
    183191        sFileFree(sfile);
    184192        streaksremoveExit("", 1);
     
    274282    sf->nHDU = sf->inImage->nHDU;
    275283
    276     // don't need to free this see basename(3)
     284    // don't need to free inputBasename see basename(3)
     285    // The names of the temporary and recovery files are taken from the input
    277286    char *inputBasename = basename(sf->inImage->name);
    278287    sf->outImage = sFileOpen(config, stage, "OUTPUT", inputBasename, true);
     
    362371    // unless stage is raw or chip when we get here we're done
    363372    if (!CHIP_LEVEL_INPUT(sf->stage)) {
     373        sf->view->readout = -1;
     374        pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER);
     375        sf->view->cell = -1;
     376        pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER);
     377        sf->view->chip = -1;
     378        pmFPAfileIOChecks(sf->config, sf->view, PM_FPA_AFTER);
    364379        return false;
    365380    }
     
    673688readImageFrom_pmFile(streakFiles *sf)
    674689{
    675     // XXX: Currently this function assumes that it is only used for a single
     690    // XXX: This function assumes that it is only used for a single
    676691    // chip single cell FPA (i.e. a skycell)
    677692    pmFPAview *view = sf->view;
     
    754769    }
    755770    sfile->fits->options = psFitsOptionsAlloc();
    756     sfile->fits->options->extword = psStringCopy(extname);
    757771    sfile->fits->options->scaling = PS_FITS_SCALE_MANUAL;
    758772    sfile->fits->options->bitpix = bitpix;
     
    978992        streaksremoveExit("", PS_EXIT_DATA_ERROR);
    979993    }
     994    psFree(sfile->header);
     995    psFree(sfile->image);
     996    psFree(sfile->imagecube);
     997    psFree(sfile->name);
     998    psFree(sfile->resolved_name);
     999    psFree(sfile);
    9801000}
    9811001
     
    11191139
    11201140static bool
     1141deleteFile(sFile *sfile)
     1142{
     1143
     1144    if (sfile->inNebulous) {
     1145        nebServer *server = getNebServer(NULL);
     1146        if (!nebDelete(server, sfile->name)) {
     1147            psError(PM_ERR_SYS, false, "failed to delete %s\n%s.", sfile->name,
     1148                nebErr(server));
     1149            return false;
     1150        }
     1151    } else {
     1152        if (unlink(sfile->resolved_name)) {
     1153            psError(PM_ERR_SYS, false, "failed to delete %s\n%s.", sfile->resolved_name,
     1154                strerror(errno));
     1155            return false;
     1156        }
     1157    }
     1158    return true;
     1159}
     1160
     1161static bool
    11211162deleteTemps(streakFiles *sfiles)
    11221163{
    1123     bool status = false;
    1124 
    1125     nebServer *server = getNebServer(NULL);
    1126 
    1127     if (!server) {
    1128         // TODO: handle this
    1129         //
    1130         // no files are in nebulous
    1131         return true;
    1132     }
    1133     if (sfiles->outImage->inNebulous) {
    1134         if (!nebDelete(server, sfiles->outImage->name)) {
    1135             psError(PM_ERR_SYS, false, "failed to delete %s\n%s.", sfiles->outImage->name,
    1136                 nebErr(getNebServer(NULL)));
     1164    if (sfiles->outMask) {
     1165        if (!deleteFile(sfiles->outMask)) {
     1166            psError(PM_ERR_SYS, false, "failed to delete Mask.");
    11371167            return false;
    11381168        }
    11391169    }
    11401170
    1141     // TODO: weight and mask images
     1171    if (sfiles->outWeight) {
     1172        if (!deleteFile(sfiles->outWeight)) {
     1173            psError(PM_ERR_SYS, false, "failed to delete Weight.");
     1174            return false;
     1175        }
     1176    }
     1177
     1178    if (!deleteFile(sfiles->outImage)) {
     1179        psError(PM_ERR_SYS, false, "failed to delete Image.");
     1180        return false;
     1181    }
    11421182
    11431183    return true;
     
    11511191    StreakPixels *pixels;
    11521192    PixelPos *pixelPos;
     1193
     1194    psLibInit(NULL);
     1195
    11531196    pmConfig *config = parseArguments(argc, argv);
    11541197    if (!config) {
     
    12861329        }
    12871330    }
     1331    psFree(ourNebServer);
     1332    psFree(config);
     1333    pmConceptsDone();
     1334    pmConfigDone();
     1335    psLibFinalize();
     1336#ifdef notyet
     1337#endif
    12881338
    12891339    //  PAU
     1340    fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "streaksremove");
    12901341
    12911342    return 0;
Note: See TracChangeset for help on using the changeset viewer.