IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14208


Ignore:
Timestamp:
Jul 13, 2007, 5:20:44 PM (19 years ago)
Author:
magnier
Message:

creating pmSource_CMF_WritePHU

Location:
trunk/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceIO.c

    r14134 r14208  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-07-11 03:09:23 $
     5 *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-07-14 03:20:44 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    243243    char *headname;
    244244    pmHDU *hdu;
    245     pmHDU *phu;
    246245    psMetadata *updates;
    247246    psMetadata *outhead;
     
    294293
    295294      case PM_FPA_FILE_CMF:
    296         // write a PHU? (only if input image is MEF)
    297295        // write a header? (only if this is the first readout for cell)
    298296        //   note that the file->header is set to track the last hdu->header written
     
    301299        // get the current header
    302300        hdu = pmFPAviewThisHDU (view, file->fpa);
    303 
    304         // if file does not yet have a PHU, attempt to write one to disk
    305         // we only need a PHU if chips->n > 1 and file->fileLevel == FPA
    306         // otherwise, the chip header fills the PHU location
    307         // XXX this code could be placed in a 'pmSource_CMF_WritePHU' function and called
    308         // from pmFPAfileIO.c.
    309         if ((file->fileLevel == PM_FPA_LEVEL_FPA) && (file->fpa->chips->n > 1) && !file->phu) {
    310 
    311             // find the FPA phu
    312             phu = pmFPAviewThisPHU (view, file->fpa);
    313 
    314             // if there is no PHU, this is a single header+image (extension-less) file
    315             // if there is a PHU, write it out as a 'blank'
    316             outhead = psMetadataAlloc();
    317             if (phu) {
    318                 psMetadataCopy (outhead, phu->header);
    319             } else {
    320                 pmConfigConformHeader (outhead, file->format);
    321 
    322                 psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information
    323                 const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME");
    324                 if (fpaNameHdr && strlen(fpaNameHdr) > 0) {
    325                     const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME");
    326                     psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName);
    327                 }
    328 
    329 #if 0
    330                 // We need to get some FPA-level concepts in there
    331                 // This is a hack, not very pretty.  But then, so is writing the FPA in this manner without
    332                 // using the pmFPAMosaic functions....
    333 
    334                 psMetadata *headers = psMetadataLookupMetadata(NULL, file->fpa->camera,
    335                                                                BLANK_HEADERS); // Header names
    336                 if (!headers) {
    337                     psError(PS_ERR_UNEXPECTED_NULL, false,
    338                             "Unable to find %s metadata within camera configuration", BLANK_HEADERS);
    339                     psFree(outhead);
    340                     return false;
    341                 }
    342 
    343                 {
    344                     const char *mjdName = psMetadataLookupStr(NULL, headers, "FPA.TIME"); // Header name
    345                     if (!mjdName || strlen(mjdName) == 0) {
    346                         psError(PS_ERR_UNEXPECTED_NULL, false,
    347                                 "Unable to find FPA.TIME in %s within camera configuration.", BLANK_HEADERS);
    348                         psFree(outhead);
    349                         return false;
    350                     }
    351                     psTime *time = psMetadataLookupTime(NULL, file->fpa->concepts,
    352                                                         "FPA.TIME"); // Time of observation
    353                     double mjd = psTimeToMJD(time); // The MJD of observation
    354                     psMetadataAddF64(outhead, PS_LIST_TAIL, mjdName, PS_META_REPLACE,
    355                                      "Time of observation", mjd);
    356                 }
    357 
    358                 {
    359                     const char *expName = psMetadataLookupStr(NULL, headers, "FPA.EXPOSURE"); // Header name
    360                     if (!expName || strlen(expName) == 0) {
    361                         psError(PS_ERR_UNEXPECTED_NULL, false,
    362                                 "Unable to find FPA.EXPOSURE in %s within camera configuration.",
    363                                 BLANK_HEADERS);
    364                         psFree(outhead);
    365                         return false;
    366                     }
    367                     float exptime = psMetadataLookupF32(NULL, file->fpa->concepts,
    368                                                         "FPA.EXPOSURE"); // Exposure time
    369                     psMetadataAddF32(outhead, PS_LIST_TAIL, expName, PS_META_REPLACE,
    370                                      "Exposure time (sec)", exptime);
    371                 }
    372 
    373                 {
    374                     const char *amName = psMetadataLookupStr(NULL, headers, "FPA.AIRMASS"); // Header name
    375                     if (!amName || strlen(amName) == 0) {
    376                         psError(PS_ERR_UNEXPECTED_NULL, false,
    377                                 "Unable to find FPA.AIRMASS in %s within camera configuration.",
    378                                 BLANK_HEADERS);
    379                         psFree(outhead);
    380                         return false;
    381                     }
    382                     float airmass = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.AIRMASS"); // Airmass
    383                     psMetadataAddF32(outhead, PS_LIST_TAIL, amName, PS_META_REPLACE,
    384                                      "Observation airmass", airmass);
    385                 }
    386 #endif
    387 
    388             }
    389 
    390             // if we have mosaic-level astrometry information, add it here:
    391             updates = psMetadataLookupPtr (&status, file->fpa->analysis, "PSASTRO.HEADER");
    392             if (updates) {
    393                 psMetadataCopy (outhead, updates);
    394             }
    395 
    396             psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
    397             psFitsWriteBlank (file->fits, outhead, "");
    398             file->phu = true;
    399             psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
    400             psFree (outhead);
    401         }
    402301
    403302        // define the EXTNAME values for the different data segments:
     
    430329        }
    431330
    432         // write out the IMAGE header segment
     331        // write out the IMAGE header segment (only for the first readout of the cell)
    433332        {
    434333            // this header block is new, write it to disk
     
    437336                psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTDATA", PS_META_REPLACE, "name of table extension", dataname);
    438337                psMetadataAddStr (hdu->header, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "IMAGE");
    439                 if (!file->phu) {
     338                if (!file->wrote_phu) {
    440339                    // this hdu->header acts as the PHU: set EXTEND to be true
    441340                    psMetadataAddBool (hdu->header, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
     341                    file->wrote_phu = true;
    442342                }
    443343
     
    512412// a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
    513413
     414// if this file needs to have a PHU written out, write one
     415bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
     416
     417    bool status;
     418
     419    // not needed if already written
     420    if (file->wrote_phu) return true;
     421
     422    // not needed if not FPA
     423    // XXX this prevents us from defining a SPLIT/MEF CMF file...
     424    if (file->fileLevel != PM_FPA_LEVEL_FPA) return true;
     425
     426    // not needed if only one chip
     427    if (file->fpa->chips->n == 1) return true;
     428
     429    // find the FPA phu
     430    pmHDU *phu = pmFPAviewThisPHU (view, file->fpa);
     431
     432    // if there is no PHU, this is a single header+image (extension-less) file. This could be
     433    // the case for an input SPLIT set of files being written out as a MEF.  if there is a PHU,
     434    // write it out as a 'blank'
     435    psMetadata *outhead = psMetadataAlloc();
     436    if (phu) {
     437        psMetadataCopy (outhead, phu->header);
     438    } else {
     439        pmConfigConformHeader (outhead, file->format);
     440
     441        psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information
     442        const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME");
     443        if (fpaNameHdr && strlen(fpaNameHdr) > 0) {
     444            const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME");
     445            psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName);
     446        }
     447    }
     448
     449    // if we have mosaic-level astrometry information, add it here:
     450    psMetadata *updates = psMetadataLookupPtr (&status, file->fpa->analysis, "PSASTRO.HEADER");
     451    if (updates) {
     452        psMetadataCopy (outhead, updates);
     453    }
     454
     455    psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
     456    psFitsWriteBlank (file->fits, outhead, "");
     457    file->wrote_phu = true;
     458
     459    psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
     460    psFree (outhead);
     461
     462    return true;
     463}
     464
    514465// Given a FITS file pointer, read the table of object data
    515466// XXX add in error handling
  • trunk/psModules/src/objects/pmSourceIO.h

    r13192 r14208  
    44 * @author EAM, IfA; GLG, MHPCC
    55 *
    6  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-05-03 20:04:31 $
     6 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-07-14 03:20:44 $
    88 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    99 *
     
    2626bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
    2727bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
     28
     29bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    2830
    2931psArray *pmSourcesReadCMP (char *filename, psMetadata *header);
Note: See TracChangeset for help on using the changeset viewer.