IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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:
Note: See TracChangeset for help on using the changeset viewer.