IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2006, 2:02:35 PM (20 years ago)
Author:
eugene
Message:

working on file I/O modifications

File:
1 edited

Legend:

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

    r6495 r6522  
    1414static char *psfSample  = NULL;
    1515
    16 void psphotOutputCleanup () {
    17 
    18     psFree (outputRoot);
    19     psFree (outputName);
    20     psFree (outputMode);
    21     psFree (outputFormat);
    22     psFree (extNumberFormat);
    23     psFree (extNameKey);
    24     psFree (extRoot);
    25     psFree (psfFile);
    26     psFree (psfSample);
    27     return;
     16static psFits *outputFits = NULL;
     17static FILE   *outputFile = NULL;
     18
     19bool psphotDataIO (psphotData *data, ppConfig *config, int chip, int cell) {
     20
     21    // load input data, if depth is appropriate
     22    ppImageLoadDepth loadDepth = ppImageCheckDepth (config->recipe, "LOAD.DEPTH");
     23    if ((chip == -1) && (cell == -1) && (loadDepth == PP_LOAD_FPA)) {
     24        psTrace(__func__, 1, "Loading pixels for FPA...\n");
     25        ppImageLoadPixels(data->input, config->database, -1, -1);
     26    }
     27    if ((chip != -1) && (cell == -1) && (loadDepth == PP_LOAD_CHIP)) {
     28        psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
     29        ppImageLoadPixels(data->input, config->database, chip, -1);
     30    }
     31    if ((chip != -1) && (cell != -1) && (loadDepth == PP_LOAD_CELL)) {
     32        psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
     33        ppImageLoadPixels(data->input, config->database, chip, cell);
     34    }
     35
     36
     37
     38    if (saveDepth == PP_LOAD_FPA) {
     39        psTrace(__func__, 1, "Saving objects for FPA...\n");
     40        psphotOutputOpen (file->fpa->phu);
     41    }
     42
     43    ppImageLoadDepth saveDepth = ppImageCheckDepth (config->recipe, "SAVE.DEPTH");
     44   
     45
    2846}
    2947
     
    4664    extNameKey      = psMetadataLookupStr (&status, config->recipe, "EXTNAME");
    4765    extRoot         = psMetadataLookupStr (&status, config->recipe, "EXTROOT");
     66
     67    headExtname     = psMetadataLookupStr (&status, config->recipe, "HEAD_EXTNAME");
     68    dataExtname     = psMetadataLookupStr (&status, config->recipe, "DATA_EXTNAME");
    4869
    4970    if (extNumberFormat == NULL) {
     
    7697    }
    7798
    78     // for MEF output, we need to open a file up front
     99    // for MEF output, we only allow certain output formats
    79100    if (!strcasecmp (outputMode, "MEF")) {
     101        if (!strcasecmp (outputFormat, "CMF")) goto valid_format;
    80102        psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable");
    81103        exit (1);
    82104    }
     105valid_format:
    83106
    84107    // register background image-file names
     
    99122}
    100123
    101 // generate the SPLIT filenames
    102 char *psphotSplitName (psMetadata *header) {
    103 
    104     bool status;
    105 
    106     char *newName = NULL;     // destination for resulting name
    107     char *extNameWord = NULL; // this contains the per-extension word to add
    108     char  extNumberWord[16];  // this will store the string-formatted number
    109 
    110     // extNumberFormat must be set to a valid entry in psphotOutputPrep
    111     sprintf (extNumberWord, extNumberFormat, extNumber);
    112 
    113     // find the extname:
    114     char *extNameVal = psMetadataLookupStr (&status, header, extNameKey);
    115            
    116     extNameWord = extNameVal;
    117     if ((extRoot != NULL) && (extNameVal != NULL)) {
    118         // check that the extNameVal matches the expected root
    119         if (strncmp (extNameVal, extRoot, strlen(extRoot))) {
    120             psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format");
     124bool psphotOutputOpen (psMetadata *phu){
     125
     126    /* outputFile is used by text-format outputs */
     127
     128    psFree (outputFile);
     129    outputFile = psphotOutputName (phu, outputName);
     130
     131    /* for fits-format output, open outputFits */
     132    if (!strcasecmp (outputFormat, "CMF")) {
     133        if (outputFits != NULL) {
     134            psFitsClose (outputFits);
    121135        }
    122         extNameWord = extNameVal + strlen(extRoot);
    123     }
    124 
    125     if (extNameWord != NULL) {
    126         psStringStrip (extNameWord);
    127     }
    128 
    129     // note : if the user mis-specifies the output name, we will happily overwrite files
    130     newName = psStringCopy (outputName);
    131     newName = psphotNameSubstitute (newName, outputRoot, "%r");
    132     newName = psphotNameSubstitute (newName, extNameWord, "%x");
    133     newName = psphotNameSubstitute (newName, extNumberWord, "%n");
    134 
    135     return newName;
    136 }
    137 
    138 
    139 // given the input string, search for the key, and replace with the replacement
    140 // the input string may be freed if not needed
    141 char *psphotNameSubstitute (char *input, char *replace, char *key) {
    142 
    143     char *p;
    144 
    145     if (key == NULL) return input;
    146     if (strlen(key) == 0) return input;
    147 
    148     p = strstr (input, key);
    149     if (p == NULL) return input;
    150 
    151     // we have input = xxxkeyxxx
    152     // we want output = xxxreplacexxx
    153 
    154     // this is safe since we will subtract strlen(key) elements from input
    155     char *output = psAlloc(strlen(input) + strlen(replace) + 1);
    156     int Nc = p - input;
    157 
    158     // copy the first segement into 'output'
    159     strncpy (output, input, Nc);
    160 
    161     // copy the key replacement to the start of the key
    162 
    163     strcpy (&output[Nc], replace);
    164     Nc += strlen (replace);
    165    
    166     // copy the remainder to the end of the replacement
    167     strcpy (&output[Nc], p + strlen(key));
    168 
    169     psFree (input);
    170     return output;
     136        outputFits = psFitsOpen (outputFile, "w");
     137
     138        if (!strcasecmp (outputMode, "MEF")) {
     139            psFitsWriteHeader (outputFits, phu);
     140        }
     141    }
     142    return true;
     143}
     144
     145bool psphotOutputClose (void) {
     146
     147    if (outputFile != NULL) {
     148        psFitsClose (outputFile);
     149    }
     150    return true;
    171151}
    172152
     
    190170    }
    191171
     172    if (!strcasecmp (outputMode, "MEF")) {
     173        headExt = psphotOutputName (header, headExtname);
     174        dataExt = psphotOutputName (header, dataExtname);
     175    }
     176    if (!strcasecmp (outputMode, "SPLIT")) {
     177        dataExt = psphotOutputName (header, dataExtname);
     178    }
     179
    192180    char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE");
    193 
    194181    if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample);
    195182    if (residImage != NULL) psphotSaveImage (header, readout->image, residImage);
     
    225212    }
    226213    if (!strcasecmp (outputFormat, "CMF")) {
    227         pmSourcesWriteCMF (sources, outputFile, header);
     214        pmSourcesWriteCMF (sources, header, headExt, dataExt);
    228215        psFree (outputFile);
    229216        return;
     
    483470        psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT);
    484471        psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", (int)(1000*dmag));
    485         psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", type);
    486         psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP",  PS_DATA_F32, "", lsky);
    487         psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", 32.0);
    488         psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X",  PS_DATA_F32, "", source->apMag + ZERO_POINT);
     472        psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", 32.0);
     473        psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP",  PS_DATA_F32, "", source->apMag + ZERO_POINT);
     474        psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", lsky);
     475        psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X",  PS_DATA_F32, "", type);
    489476        psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y",  PS_DATA_F32, "", PAR[4]);
    490477        psMetadataAdd (row, PS_LIST_TAIL, "THETA",   PS_DATA_F32, "", PAR[5]);
Note: See TracChangeset for help on using the changeset viewer.