Changeset 20496 for trunk/magic/remove/src/streaksremove.c
- Timestamp:
- Oct 31, 2008, 4:59:42 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/streaksremove.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/streaksremove.c
r20360 r20496 2 2 #include "streaksextern.h" 3 3 #include "libgen.h" 4 #include "unistd.h" 4 5 5 6 extern bool sFileLock(sFile * sfile); … … 90 91 91 92 sFile *sFileOpen(pmConfig *config, ippStage stage, psString fileSelect, 92 psString output Ext, bool required)93 psString outputFilename, bool required) 93 94 { 94 95 bool status; … … 96 97 memset(sfile, 0, sizeof(sFile)); 97 98 98 // We use psFits directly to read the image fileunless the stage is warp99 // We use psFits directly to read the image unless the stage is warp 99 100 // 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 101 104 102 105 if (!CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) { 103 106 // stage is warp or diff AND fileSelect eq "INPUT" 104 // get data from pmFPAfile. We read the mask and weight files using psFits107 // get data from pmFPAfile. 105 108 106 109 // we need to know what the nebulous and real filenames are so we steal … … 112 115 streaksremoveExit("", PS_EXIT_PROG_ERROR); 113 116 } 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"); 116 120 streaksremoveExit("", PS_EXIT_DATA_ERROR); 117 121 } 122 // end of file name lookup code adapted from pmFPAfileDefineFromArgs 123 // 118 124 sfile->name = psStringCopy(infiles->data[0]); 119 // end of file name lookup code adapted from pmFPAfileDefineFromArgs120 121 125 sfile->inNebulous = IN_NEBULOUS(sfile->name); 122 126 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 123 129 sfile->pmfile = pmFPAfileDefineFromArgs(&status, config, "PPSUB.INPUT", "INPUT"); 124 130 if (!sfile->pmfile) { … … 141 147 } 142 148 143 // using psFits for i/o144 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) { 147 153 if (required) { 148 154 psError(PS_ERR_IO, false, "Failed to lookup name for %s", fileSelect); … … 153 159 } 154 160 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) 156 163 // and the file is to be opened for writing 157 if (output Ext) {158 psStringAppend(&sfile->name, outputExt);164 if (outputFilename) { 165 psStringAppend(&sfile->name, "%s%s", name, outputFilename); 159 166 sfile->resolved_name = resolveFilename(config, sfile, true); 160 167 if (!sfile->resolved_name) { … … 166 173 sfile->fits->options = psFitsOptionsAlloc(); 167 174 } else { 175 sfile->name = psStringCopy(name); 168 176 sfile->resolved_name = resolveFilename(config, sfile, false); 169 177 if (!sfile->resolved_name) { … … 180 188 if (!sfile->fits) { 181 189 psError(PS_ERR_IO, false, "failed to open fits file %s for %s", 182 sfile->resolved_name, output Ext? "writing" : "reading");190 sfile->resolved_name, outputFilename ? "writing" : "reading"); 183 191 sFileFree(sfile); 184 192 streaksremoveExit("", 1); … … 274 282 sf->nHDU = sf->inImage->nHDU; 275 283 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 277 286 char *inputBasename = basename(sf->inImage->name); 278 287 sf->outImage = sFileOpen(config, stage, "OUTPUT", inputBasename, true); … … 362 371 // unless stage is raw or chip when we get here we're done 363 372 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); 364 379 return false; 365 380 } … … 673 688 readImageFrom_pmFile(streakFiles *sf) 674 689 { 675 // XXX: Currently this function assumes that it is only used for a single690 // XXX: This function assumes that it is only used for a single 676 691 // chip single cell FPA (i.e. a skycell) 677 692 pmFPAview *view = sf->view; … … 754 769 } 755 770 sfile->fits->options = psFitsOptionsAlloc(); 756 sfile->fits->options->extword = psStringCopy(extname);757 771 sfile->fits->options->scaling = PS_FITS_SCALE_MANUAL; 758 772 sfile->fits->options->bitpix = bitpix; … … 978 992 streaksremoveExit("", PS_EXIT_DATA_ERROR); 979 993 } 994 psFree(sfile->header); 995 psFree(sfile->image); 996 psFree(sfile->imagecube); 997 psFree(sfile->name); 998 psFree(sfile->resolved_name); 999 psFree(sfile); 980 1000 } 981 1001 … … 1119 1139 1120 1140 static bool 1141 deleteFile(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 1161 static bool 1121 1162 deleteTemps(streakFiles *sfiles) 1122 1163 { 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."); 1137 1167 return false; 1138 1168 } 1139 1169 } 1140 1170 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 } 1142 1182 1143 1183 return true; … … 1151 1191 StreakPixels *pixels; 1152 1192 PixelPos *pixelPos; 1193 1194 psLibInit(NULL); 1195 1153 1196 pmConfig *config = parseArguments(argc, argv); 1154 1197 if (!config) { … … 1286 1329 } 1287 1330 } 1331 psFree(ourNebServer); 1332 psFree(config); 1333 pmConceptsDone(); 1334 pmConfigDone(); 1335 psLibFinalize(); 1336 #ifdef notyet 1337 #endif 1288 1338 1289 1339 // PAU 1340 fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "streaksremove"); 1290 1341 1291 1342 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.
