Changeset 6311 for trunk/psphot/src/psphotOutput.c
- Timestamp:
- Feb 2, 2006, 1:30:35 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotOutput.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotOutput.c
r6117 r6311 1 1 # include "psphot.h" 2 2 3 static int extNumber = -1; 4 5 static char *outputName = NULL; 6 static char *outputRoot = NULL; 7 static char *outputMode = NULL; 8 static char *outputFormat = NULL; 9 10 static char *extNumberFormat = NULL; 11 static char *extNameKey = NULL; 12 static char *extRoot = NULL; 13 14 void psphotOutputPrep (ppFile *file, ppConfig *config) { 15 16 bool status; 17 18 outputRoot = psMetadataLookupPtr (&status, config->arguments, "OUTPUT_ROOT"); 19 if (!status) psAbort ("psphot", "output file not specified"); 20 21 outputName = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_NAME"); 22 outputMode = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_MODE"); 23 outputFormat = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_FORMAT"); 24 25 // rules to construct output names 26 extNumberFormat = psMetadataLookupPtr (&status, config->recipe, "EXTNUMBER_FORMAT"); 27 extNameKey = psMetadataLookupPtr (&status, config->recipe, "EXTNAME"); 28 extRoot = psMetadataLookupPtr (&status, config->recipe, "EXTROOT"); 29 30 if (extNumberFormat == NULL) { 31 extNumberFormat = psStringCopy ("%02d"); 32 } 33 34 psStringStrip (outputName); 35 psStringStrip (extNameKey); 36 psStringStrip (extRoot); 37 38 // validate the outputMode and outputFormat 39 status = false; 40 status |= !strcasecmp (outputFormat, "TEXT"); 41 status |= !strcasecmp (outputFormat, "OBJ"); 42 status |= !strcasecmp (outputFormat, "SX"); 43 status |= !strcasecmp (outputFormat, "CMP"); 44 status |= !strcasecmp (outputFormat, "CMF"); 45 if (!status) { 46 psLogMsg ("psphot", PS_LOG_ERROR, "invalid output format %s", outputFormat); 47 exit (1); 48 } 49 50 // validate the outputMode and outputFormat 51 status = false; 52 status |= !strcasecmp (outputMode, "MEF"); 53 status |= !strcasecmp (outputMode, "SPLIT"); 54 if (!status) { 55 psLogMsg ("psphot", PS_LOG_ERROR, "invalid output mode %s", outputMode); 56 exit (1); 57 } 58 59 // for MEF output, we need to open a file up front 60 if (!strcasecmp (outputMode, "MEF")) { 61 psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable"); 62 exit (1); 63 } 64 65 return; 66 } 67 68 // generate the SPLIT filenames 69 char *psphotSplitName (psMetadata *header) { 70 71 bool status; 72 73 char *newName = NULL; // destination for resulting name 74 char *extNameWord = NULL; // this contains the per-extension word to add 75 char extNumberWord[16]; // this will store the string-formatted number 76 77 // extNumberFormat must be set to a valid entry in psphotOutputPrep 78 sprintf (extNumberWord, extNumberFormat, extNumber); 79 80 // find the extname: 81 char *extNameVal = psMetadataLookupPtr (&status, header, extNameKey); 82 83 extNameWord = extNameVal; 84 if ((extRoot != NULL) && (extNameVal != NULL)) { 85 // check that the extNameVal matches the expected root 86 if (strncmp (extNameVal, extRoot, strlen(extRoot))) { 87 psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format"); 88 } 89 extNameWord = extNameVal + strlen(extRoot); 90 } 91 92 if (extNameWord != NULL) { 93 psStringStrip (extNameWord); 94 } 95 96 // note : if the user mis-specifies the output name, we will happily overwrite files 97 newName = psStringCopy (outputName); 98 newName = psphotNameSubstitute (newName, outputRoot, "%r"); 99 newName = psphotNameSubstitute (newName, extNameWord, "%x"); 100 newName = psphotNameSubstitute (newName, extNumberWord, "%n"); 101 102 return newName; 103 } 104 105 106 // given the input string, search for the key, and replace with the replacement 107 // the input string may be freed if not needed 108 char *psphotNameSubstitute (char *input, char *replace, char *key) { 109 110 char *p; 111 112 if (key == NULL) return input; 113 if (strlen(key) == 0) return input; 114 115 p = strstr (input, key); 116 if (p == NULL) return input; 117 118 // we have input = xxxkeyxxx 119 // we want output = xxxreplacexxx 120 121 // this is safe since we will subtract strlen(key) elements from input 122 char *output = psAlloc(strlen(input) + strlen(replace) + 1); 123 int Nc = p - input; 124 125 // copy the first segement into 'output' 126 strncpy (output, input, Nc); 127 128 // copy the key replacement to the start of the key 129 130 strcpy (&output[Nc], replace); 131 Nc += strlen (replace); 132 133 // copy the remainder to the end of the replacement 134 strcpy (&output[Nc], p + strlen(key)); 135 136 psFree (input); 137 return output; 138 } 139 3 140 // output functions: we have several fixed modes (sx, obj, cmp) 4 void psphotOutput (pmReadout *readout, psMetadata * config) {141 void psphotOutput (pmReadout *readout, psMetadata *arguments) { 5 142 6 143 bool status; 144 char *outputFile; 7 145 8 146 psTimerStart ("psphot"); … … 13 151 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 14 152 15 char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE"); 16 char *outputFile = psMetadataLookupPtr (&status, config, "OUTPUT_FILE"); 17 char *residImage = psMetadataLookupPtr (&status, config, "RESID_IMAGE"); 18 char *psfFile = psMetadataLookupPtr (&status, config, "PSF_OUTPUT_FILE"); 19 153 // starting value is -1 154 extNumber ++; 155 156 // for SPLIT output, we need to open a file for each output call 157 if (!strcasecmp (outputMode, "SPLIT")) { 158 outputFile = psphotSplitName (header); 159 } else { 160 // construct appropriate extname 161 psAbort ("psphotOutput", "programming error"); 162 } 163 164 fprintf (stderr, "output file: %s\n", outputFile); 165 return; 166 167 char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_OUTPUT_FILE"); 168 char *psfSample = psMetadataLookupPtr (&status, arguments, "PSF_SAMPLE_FILE"); 169 char *residImage = psMetadataLookupPtr (&status, arguments, "RESID_IMAGE"); 170 171 if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample); 20 172 if (residImage != NULL) psphotSaveImage (header, readout->image, residImage); 21 psphotSamplePSFs (config, psf, readout->image);22 173 23 174 if (psfFile != NULL) { … … 30 181 return; 31 182 } 32 if (output Mode== NULL) {33 psLogMsg ("output", 3, "no data output modeselected");183 if (outputFormat == NULL) { 184 psLogMsg ("output", 3, "no data output format selected"); 34 185 return; 35 186 } 36 if (!strcasecmp (output Mode, "SX")) {187 if (!strcasecmp (outputFormat, "SX")) { 37 188 pmSourcesWriteSX (sources, outputFile); 38 189 return; 39 190 } 40 if (!strcasecmp (output Mode, "OBJ")) {191 if (!strcasecmp (outputFormat, "OBJ")) { 41 192 pmSourcesWriteOBJ (sources, outputFile); 42 193 return; 43 194 } 44 if (!strcasecmp (output Mode, "CMP")) {195 if (!strcasecmp (outputFormat, "CMP")) { 45 196 pmSourcesWriteCMP (sources, outputFile, header); 46 197 return; 47 198 } 48 if (!strcasecmp (output Mode, "CMF")) {199 if (!strcasecmp (outputFormat, "CMF")) { 49 200 pmSourcesWriteCMF (sources, outputFile, header); 50 201 return; 51 202 } 52 if (!strcasecmp (output Mode, "TEXT")) {203 if (!strcasecmp (outputFormat, "TEXT")) { 53 204 pmSourcesWriteText (sources, outputFile); 54 205 return; 55 206 } 56 207 57 psAbort ("psphot", "unknown output mode %s", output Mode);208 psAbort ("psphot", "unknown output mode %s", outputFormat); 58 209 } 59 210 … … 560 711 } 561 712 562 563 bool psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image) { 564 565 bool status; 713 bool psphotSamplePSFs (pmPSF *psf, psImage *image, char *output) { 566 714 567 715 // make sample PSFs for 4 corners and the center … … 569 717 570 718 // optional dump of all rough source data 571 char *output = psMetadataLookupPtr (&status, config, "PSF_SAMPLE_FILE");572 if (!status) return false;573 if (output == NULL) return false;574 719 if (output[0] == 0) return false; 575 720 … … 580 725 psFits *fits = psFitsOpen (output, "w"); 581 726 727 // the centers are in parent coordinates; they do not need to correspond to valid pixels... 582 728 sample = pmModelPSFatXY (image, modelEXT, psf, 25, 25, 25, 25); 583 729 psFitsWriteImage (fits, NULL, sample, 0);
Note:
See TracChangeset
for help on using the changeset viewer.
