IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11801


Ignore:
Timestamp:
Feb 14, 2007, 2:51:20 PM (19 years ago)
Author:
Paul Price
Message:

Fixing issues with file formats: some formats weren't getting the PHU where required (because the create was following the open, and the open was attempting to write the blank PHU). Added pmFPAfileBlank to write a blank where required. Cleaned up the pmFPAfile stuff a little.

Location:
trunk/psModules/src/camera
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAConstruct.c

    r11792 r11801  
    469469// It returns a view corresponding to the PHU
    470470static pmFPAview *addSource(pmFPA *fpa,       // The FPA
     471                            const char *fpaname, // The desired FPA name
    471472                            const pmFPAview *phuView, // The view corresponding to the PHU, or NULL
    472473                            const psMetadata *header, // The PHU header, or NULL
     
    479480    assert(format);
    480481
    481     bool mdok = true;                   // Status from metadata lookups
     482    bool mdok;                          // Status of MD lookup
     483
     484    // If FPA.NAME is already defined, new name must match it; otherwise, warn the user that something
     485    // potentially bad is happening.
     486    if (fpaname && install) {
     487        const char *currentName = psMetadataLookupStr(&mdok, fpa->concepts, "FPA.NAME"); // Current name
     488        if (mdok && currentName && strlen(currentName) > 0 && strcmp(currentName, fpaname) != 0) {
     489            psLogMsg(__func__, PS_LOG_WARN, "FPA.NAME for new source (%s) doesn't match FPA.NAME for current "
     490                     "fpa (%s).\n", fpaname, currentName);
     491        }
     492        psMetadataAddStr(fpa->concepts, PS_LIST_HEAD, "FPA.NAME", PS_META_REPLACE, "Name of FPA", fpaname);
     493    } else if (!psMetadataLookup(fpa->concepts, "FPA.NAME")) {
     494        // Make sure there is an FPA.NAME
     495        psMetadataAddStr(fpa->concepts, PS_LIST_HEAD, "FPA.NAME", 0, "Name of FPA", "UNKNOWN");
     496    }
     497
    482498    psMetadata *fileInfo = psMetadataLookupMetadata(&mdok, format, "FILE"); // The file information
    483499    if (!mdok || !fileInfo) {
     
    759775
    760776
    761 bool pmFPAAddSourceFromView(pmFPA *fpa, const pmFPAview *phuView, const psMetadata *format)
     777bool pmFPAAddSourceFromView(pmFPA *fpa, const char *fpaname, const pmFPAview *phuView,
     778                            const psMetadata *format)
    762779{
    763780    PS_ASSERT_PTR_NON_NULL(fpa, false);
     
    765782    PS_ASSERT_PTR_NON_NULL(format, false);
    766783
    767     pmFPAview *view = addSource(fpa, phuView, NULL, format, true);
     784    pmFPAview *view = addSource(fpa, fpaname, phuView, NULL, format, true);
    768785    bool status = (view != NULL);
    769786    psFree(view);
     
    785802
    786803    // Check the name of the FPA
    787     psString newFPAname = phuNameFromHeader("FPA.NAME", fileInfo, phu); // New name for the FPA
    788     if (!newFPAname) {
    789         psError(PS_ERR_IO, true, "Unable to determine FPA.NAME : check for FPA.NAME in FILE in FORMAT");
    790         return NULL;
    791     }
    792 
    793     // If FPAname already defined, new name must match it; otherwise, warn the user that something potentially
    794     // bad is happening.
    795     const char *currentFPAname = psMetadataLookupStr(&mdok, fpa->concepts, "FPA.NAME"); // Current name
    796     if (mdok && currentFPAname && strlen(currentFPAname) > 0 && strcmp(currentFPAname, newFPAname) != 0) {
    797         psLogMsg(__func__, PS_LOG_WARN, "FPA.NAME for new source (%s) doesn't match FPA.NAME for current "
    798                  "fpa (%s).\n", newFPAname, currentFPAname);
    799     }
    800     psMetadataAddStr(fpa->concepts, PS_LIST_HEAD, "FPA.NAME", PS_META_REPLACE, "Name of FPA", newFPAname);
    801     psFree(newFPAname);                 // Drop reference
    802 
    803     return addSource(fpa, NULL, phu, format, true);
     804    psString fpaname = phuNameFromHeader("FPA.NAME", fileInfo, phu); // New name for the FPA
     805    if (!fpaname || strlen(fpaname) == 0) {
     806        psError(PS_ERR_IO, true, "Unable to determine FPA.NAME: check for FPA.NAME in FILE in camera format");
     807        return NULL;
     808    }
     809
     810    pmFPAview *view = addSource(fpa, fpaname, NULL, phu, format, true); // View of PHU, to return
     811    psFree(fpaname);
     812
     813    return view;
    804814}
    805815
     
    811821    PS_ASSERT_PTR_NON_NULL(format, NULL);
    812822
    813     return addSource(fpa, NULL, phu, format, false);
     823    return addSource(fpa, NULL, NULL, phu, format, false);
    814824}
    815825
  • trunk/psModules/src/camera/pmFPAConstruct.h

    r11255 r11801  
    44 * @author Paul Price, IfA
    55 *
    6  * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 03:11:19 $
     6 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-02-15 00:51:20 $
    88 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    99 */
     
    3333/// configuration is required in order to describe how the FPA is laid out in terms of disk files.
    3434bool pmFPAAddSourceFromView(pmFPA *fpa,   ///< The FPA
     35                            const char *fpaname, ///< FPA.NAME for the source
    3536                            const pmFPAview *phuView, ///< The view, corresponding to the PHU
    3637                            const psMetadata *format ///< Format of file
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r11687 r11801  
    180180    }
    181181
    182     file->camera = psMemIncrRefCounter(config->camera);
     182    psMetadata *camera;                 // Camera to use
     183    if (fpa && fpa->camera) {
     184        camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file
     185    } else {
     186        camera = config->camera;
     187    }
     188    file->camera = psMemIncrRefCounter(camera);
     189
     190    // select the format list from the selected camera
    183191    const char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT");
    184     psMetadata *format = NULL;          // Camera format to use
    185     if (formatName && strcasecmp(formatName, "NONE") != 0) {
    186         // select the format list from the selected camera
    187         psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats
    188 
    189         // select the desired format
    190         format = psMetadataLookupMetadata(&status, formats, formatName);
    191         if (!format) {
    192             psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name);
    193             psFree(file);
    194             return NULL;
    195         }
    196         file->format = psMemIncrRefCounter(format);
    197         #if 0
    198 
    199         file->src = psMemIncrRefCounter(fpa);
    200         file->fpa = pmFPAConstruct(file->camera);
    201         #endif
    202 
    203     } else {
     192    if (!formatName) {
     193        formatName = config->formatName;
     194    }
     195    psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats
     196    psMetadata *format = psMetadataLookupMetadata(&status, formats, formatName); // Camera format to use
     197    if (!format) {
     198        // Try to get by with the default
    204199        format = config->format;
    205         #if 0
    206 
    207         file->fpa = psMemIncrRefCounter(fpa);
    208         #endif
    209 
    210     }
    211     #if 1
     200    }
     201    file->format = psMemIncrRefCounter(format);
     202
    212203    file->fpa = psMemIncrRefCounter(fpa);
    213     #endif
    214 
    215204
    216205    file->fileLevel = pmFPAPHULevel(format);
     
    925914    file->xBin = xBin;
    926915    file->yBin = yBin;
    927     psFree (file->format);
    928     file->format = psMemIncrRefCounter(format);
    929 
    930916    psFree (fpa);
    931917    return file;
  • trunk/psModules/src/camera/pmFPAfileFitsIO.c

    r11793 r11801  
    2323    PS_ASSERT_PTR_NON_NULL(view, NULL);
    2424
    25     if (file->camera == config->camera || // Need to mosaic, not copy
     25    if (//file->camera == config->camera || // Need to mosaic, not copy
    2626            !file->format) {                // Working with the same output format as input format
    2727        return psMemIncrRefCounter(file->fpa);
     
    5050    }
    5151
    52     if (!pmFPAAddSourceFromView(fpa, phuView, file->format)) {
     52    pmFPA *nameSource = file->src; // Source of FPA.NAME
     53    if (!nameSource) {
     54        nameSource = file->fpa;
     55    }
     56    bool mdok;                  // Status of MD lookup
     57    const char *fpaname = psMetadataLookupStr(&mdok, nameSource->concepts, "FPA.NAME"); // Name of FPA
     58
     59    if (!pmFPAAddSourceFromView(fpa, fpaname, phuView, file->format)) {
    5360        psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n");
    5461        psFree(fpa);
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r11793 r11801  
    107107        }
    108108    }
     109#if 0
     110    // This should be done by pmFPAfileBlank
    109111    if (file->mode == PM_FPA_MODE_WRITE) {
    110112        // Want to write out any potential blank
     
    132134        psFree(fpa);
    133135    }
    134 
     136#endif
    135137    return true;
    136138
     
    475477}
    476478
     479bool pmFPAfileBlank(pmFPAfile *file, const pmFPAview *view, pmConfig *config)
     480{
     481    PS_ASSERT_PTR_NON_NULL(file, false);
     482    PS_ASSERT_PTR_NON_NULL(view, false);
     483
     484    if (file->state & PM_FPA_STATE_INACTIVE) {
     485        psTrace("psModules.camera", 6, "skip blank for %s, files is inactive", file->name);
     486        return true;
     487    }
     488
     489    if (file->mode != PM_FPA_MODE_WRITE) {
     490        psTrace("psModules.camera", 6, "skip blank for %s, mode is not WRITE", file->name);
     491        return true;
     492    }
     493
     494    // an internal file should not be returned to here
     495    if (file->mode == PM_FPA_MODE_INTERNAL) {
     496        psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_INTERNAL");
     497        return false;
     498    }
     499
     500    if (!file->save) {
     501        psTrace("psModules.camera", 6, "skip blank for %s, save is FALSE", file->name);
     502        return true;
     503    }
     504
     505    // get the current level
     506    pmFPALevel level = pmFPAviewLevel (view);
     507
     508    if (level != file->fileLevel) {
     509        psTrace("psModules.camera", 6, "skip blank for %s, level is %s", file->name,
     510                pmFPALevelToName(file->freeLevel));
     511        return true;
     512    }
     513
     514    // do we need to open this file?
     515    if (!pmFPAfileOpen (file, view, config)) {
     516        psError(PS_ERR_IO, false, "failed to open %s", file->filename);
     517        return false;
     518    }
     519
     520    switch (file->type) {
     521    case PM_FPA_FILE_IMAGE:
     522    case PM_FPA_FILE_MASK:
     523    case PM_FPA_FILE_WEIGHT:
     524    case PM_FPA_FILE_FRINGE:
     525    if (file->mode == PM_FPA_MODE_WRITE) {
     526        // Want to write out any potential blank
     527        pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config); // FPA, ensuring it's ready to write a blank
     528
     529        switch (file->fileLevel) {
     530        case PM_FPA_LEVEL_FPA:
     531            pmFPAWrite(fpa, file->fits, NULL, true, false);
     532            break;
     533        case PM_FPA_LEVEL_CHIP: {
     534                pmChip *chip = pmFPAviewThisChip(view, fpa);
     535                pmChipWrite(chip, file->fits, NULL, true, false);
     536                break;
     537            }
     538        case PM_FPA_LEVEL_CELL: {
     539                pmCell *cell = pmFPAviewThisCell(view, fpa);
     540                pmCellWrite(cell, file->fits, NULL, true);
     541                break;
     542            }
     543        default:
     544            psAbort("fileLevel not correctly set");
     545            break;
     546        }
     547
     548        psFree(fpa);
     549    }
     550    case PM_FPA_FILE_SX:
     551    case PM_FPA_FILE_RAW:
     552    case PM_FPA_FILE_OBJ:
     553    case PM_FPA_FILE_CMP:
     554    case PM_FPA_FILE_CMF:
     555    case PM_FPA_FILE_PSF:
     556    case PM_FPA_FILE_JPEG:
     557    case PM_FPA_FILE_MANAPLOT:
     558    case PM_FPA_FILE_KAPA:
     559      break;
     560    default:
     561        fprintf (stderr, "warning: type mismatch\n");
     562        return false;
     563    }
     564    return true;
     565}
     566
     567
    477568bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view, pmConfig *config)
    478569{
     
    630721    case PM_FPA_FILE_WEIGHT:
    631722    case PM_FPA_FILE_FRINGE: {
    632         // create FPA structure component based on view
    633         // XXX drop this ifdef'ed out code??
    634 #if 0
    635         psMetadata *format = file->format; // Camera format configuration
    636         if (!format) {
    637             // It's likely a mosaic, for which we don't yet know the appropriate format
    638             const psMetadata *camera = file->fpa->camera; // Camera configuration
    639             psMetadata *formats = psMetadataLookupMetadata(NULL, camera, "FORMATS"); // The FORMATS
    640             if (!formats) {
    641                 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FORMATS in camera configuration.\n");
    642                 return false;
    643             }
    644             format = psMetadataLookupMetadata(NULL, formats, config->formatName);
    645             if (!format) {
    646                 psError(PS_ERR_UNEXPECTED_NULL, false,
    647                         "Unable to find format %s in camera configuration.\n", config->formatName);
    648                 return false;
    649             }
    650             file->format = psMemIncrRefCounter(format);
    651         }
    652 #endif
    653         pmFPAAddSourceFromView (file->fpa, view, file->format);
    654         psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
    655         break;
     723            // create FPA structure component based on view
     724            psMetadata *format = file->format; // Camera format configuration
     725            if (!format) {
     726                format = config->format;
     727            }
     728
     729            pmFPA *nameSource = file->src; // Source of FPA.NAME
     730            if (!nameSource) {
     731                nameSource = file->fpa;
     732            }
     733            bool mdok;                  // Status of MD lookup
     734            const char *fpaname = psMetadataLookupStr(&mdok, nameSource->concepts, "FPA.NAME"); // Name of FPA
     735
     736            pmFPAAddSourceFromView(file->fpa, fpaname, view, format);
     737            psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
     738            break;
    656739    }
    657740    case PM_FPA_FILE_HEADER:
     
    807890                goto failure;
    808891            }
     892            if (!pmFPAfileBlank(file, view, config)) {
     893                psError(PS_ERR_IO, false, "failed BLANK in FPA_BEFORE block for %s", file->name);
     894                goto failure;
     895            }
    809896            break;
    810897        case PM_FPA_AFTER:
  • trunk/psModules/src/camera/pmFPAfileIO.h

    r11253 r11801  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-24 02:54:14 $
     6 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-02-15 00:51:20 $
    88 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    99 */
     
    2121bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view, pmConfig *config);
    2222
    23 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view, pmConfig *config);
     23bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view, const pmConfig *config);
    2424
    2525// write to the real file corresponding to the given pmFPAfile for the current view
Note: See TracChangeset for help on using the changeset viewer.