IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 2, 2006, 1:30:35 PM (20 years ago)
Author:
eugene
Message:

updated to use new image/subimage/region coordinate consistency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotOutput.c

    r6117 r6311  
    11# include "psphot.h"
    22
     3static int   extNumber  = -1;
     4
     5static char *outputName = NULL;
     6static char *outputRoot = NULL;
     7static char *outputMode = NULL;
     8static char *outputFormat = NULL;
     9
     10static char *extNumberFormat = NULL;
     11static char *extNameKey = NULL;
     12static char *extRoot    = NULL;
     13
     14void 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
     69char *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
     108char *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
    3140// output functions: we have several fixed modes (sx, obj, cmp)
    4 void psphotOutput (pmReadout *readout, psMetadata *config) {
     141void psphotOutput (pmReadout *readout, psMetadata *arguments) {
    5142
    6143    bool status;
     144    char *outputFile;
    7145
    8146    psTimerStart ("psphot");
     
    13151    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    14152
    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);
    20172    if (residImage != NULL) psphotSaveImage (header, readout->image, residImage);
    21     psphotSamplePSFs (config, psf, readout->image);
    22173
    23174    if (psfFile != NULL) {
     
    30181        return;
    31182    }
    32     if (outputMode == NULL) {
    33         psLogMsg ("output", 3, "no data output mode selected");
     183    if (outputFormat == NULL) {
     184        psLogMsg ("output", 3, "no data output format selected");
    34185        return;
    35186    }
    36     if (!strcasecmp (outputMode, "SX")) {
     187    if (!strcasecmp (outputFormat, "SX")) {
    37188        pmSourcesWriteSX (sources, outputFile);
    38189        return;
    39190    }
    40     if (!strcasecmp (outputMode, "OBJ")) {
     191    if (!strcasecmp (outputFormat, "OBJ")) {
    41192        pmSourcesWriteOBJ (sources, outputFile);
    42193        return;
    43194    }
    44     if (!strcasecmp (outputMode, "CMP")) {
     195    if (!strcasecmp (outputFormat, "CMP")) {
    45196        pmSourcesWriteCMP (sources, outputFile, header);
    46197        return;
    47198    }
    48     if (!strcasecmp (outputMode, "CMF")) {
     199    if (!strcasecmp (outputFormat, "CMF")) {
    49200        pmSourcesWriteCMF (sources, outputFile, header);
    50201        return;
    51202    }
    52     if (!strcasecmp (outputMode, "TEXT")) {
     203    if (!strcasecmp (outputFormat, "TEXT")) {
    53204        pmSourcesWriteText (sources, outputFile);
    54205        return;
    55206    }
    56207
    57     psAbort ("psphot", "unknown output mode %s", outputMode);
     208    psAbort ("psphot", "unknown output mode %s", outputFormat);
    58209}
    59210
     
    560711}
    561712
    562 
    563 bool psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image) {
    564 
    565     bool status;
     713bool psphotSamplePSFs (pmPSF *psf, psImage *image, char *output) {
    566714
    567715    // make sample PSFs for 4 corners and the center
     
    569717
    570718    // 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;
    574719    if (output[0] == 0) return false;
    575720
     
    580725    psFits *fits = psFitsOpen (output, "w");
    581726
     727    // the centers are in parent coordinates; they do not need to correspond to valid pixels...
    582728    sample = pmModelPSFatXY (image, modelEXT, psf, 25, 25, 25, 25);
    583729    psFitsWriteImage (fits, NULL, sample, 0);
Note: See TracChangeset for help on using the changeset viewer.