IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 22, 2008, 5:10:51 PM (18 years ago)
Author:
Paul Price
Message:

Merging pap_branch_080117 into the mainline.

File:
1 edited

Legend:

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

    r15946 r16186  
    3535    }
    3636    int value = psMetadataItemParseS32(item); // Value of interst
     37    return value;
     38}
     39
     40// Parse an option from a metadata, returning the appropriate float value
     41static float parseOptionFloat(const psMetadata *md, // Metadata containing the option
     42                              const char *name, // Option name
     43                              const char *source // Description of source, for warning messages
     44                              )
     45{
     46    psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest
     47    if (!item) {
     48        psWarning("Unable to find value for %s in %s", name, source);
     49        return NAN;
     50    }
     51    int value = psMetadataItemParseF32(item); // Value of interst
     52    return value;
     53}
     54
     55// Parse an option from a metadata, returning the appropriate double value
     56static double parseOptionDouble(const psMetadata *md, // Metadata containing the option
     57                                const char *name, // Option name
     58                                const char *source // Description of source, for warning messages
     59                                )
     60{
     61    psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest
     62    if (!item) {
     63        psWarning("Unable to find value for %s in %s", name, source);
     64        return NAN;
     65    }
     66    int value = psMetadataItemParseF64(item); // Value of interst
    3767    return value;
    3868}
     
    212242        psMetadata *fitsTypes = psMetadataLookupMetadata(&status, camera, "FITS"); // The FITS schemes
    213243        if (!fitsTypes) {
    214             psWarning("Unable to find FITS in camera configuration --- compression disabled.");
    215             goto COMPRESSION_DONE;
     244            psWarning("Unable to find FITS in camera configuration.");
     245            goto FITS_OPTIONS_DONE;
    216246        }
    217247        psMetadata *scheme = psMetadataLookupMetadata(NULL, fitsTypes, fitsType); // FITS scheme
    218248        if (!scheme) {
    219             psWarning("Unable to find %s in FITS in camera configuration --- compression disabled.",
    220                       fitsType);
    221             goto COMPRESSION_DONE;
    222         }
    223         const char *typeString = psMetadataLookupStr(NULL, scheme, "COMP"); // Compression type
    224         if (!typeString || strlen(typeString) == 0) {
    225             psWarning("Can't find COMP in FITS scheme %s --- compression disabled.", fitsType);
    226             goto COMPRESSION_DONE;
    227         }
    228         psFitsCompressionType type = psFitsCompressionTypeFromString(typeString); // Compression type enum
    229 
    230         psString source = NULL;         // Source of options
     249            psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType);
     250            goto FITS_OPTIONS_DONE;
     251        }
     252
     253        psString source = NULL;     // Source of options
    231254        psStringAppend(&source, "%s in FITS in camera %s", fitsType, cameraName);
    232         file->bitpix = parseOptionInt(scheme, "BITPIX", source, 0); // Bits per pixel
     255
     256        psFitsOptions *options = file->options = psFitsOptionsAlloc(); // FITS I/O options
    233257
    234258        // Custom floating-point
    235         const char *floatName = psMetadataLookupStr(NULL, scheme, "FLOAT"); // Name of custom floating-point
     259        const char *floatName = psMetadataLookupStr(NULL, scheme, "FLOAT"); // Name of custom float
    236260        if (floatName) {
    237261            psString fullName = NULL;   // Full name of custom floating-point
    238262            psStringAppend(&fullName, "FLOAT_%s", floatName);
    239             file->floatType = psFitsFloatTypeFromString(fullName);
     263            options->floatType = psFitsFloatTypeFromString(fullName);
    240264            psFree(fullName);
    241265        }
    242266
    243         psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes
    244         tile->data.S32[0] = parseOptionInt(scheme, "TILE.X", source, 0); // Tiling in x
    245         tile->data.S32[1] = parseOptionInt(scheme, "TILE.Y", source, 1); // Tiling in y
    246         tile->data.S32[2] = parseOptionInt(scheme, "TILE.Z", source, 1); // Tiling in z
    247         int noise = parseOptionInt(scheme, "NOISE", source, 16); // Noise bits
    248         int hscale = parseOptionInt(scheme, "HSCALE", source, 0); // Scaling for HCOMPRESS
    249         int hsmooth = parseOptionInt(scheme, "HSMOOTH", source, 0); // Smoothing for HCOMPRESS
     267        options->bitpix = parseOptionInt(scheme, "BITPIX", source, 0); // Bits per pixel
     268
     269        // Scaling options
     270        bool mdok;                  // Status of MD lookup
     271        const char *scalingString = psMetadataLookupStr(&mdok, scheme, "SCALING"); // Scaling name
     272        if (scalingString) {
     273            options->scaling = psFitsScalingFromString(scalingString); // Scaling method
     274
     275            switch (options->scaling) {
     276              case PS_FITS_SCALE_NONE:
     277              case PS_FITS_SCALE_RANGE:
     278                // No options required
     279                break;
     280              case PS_FITS_SCALE_STDEV_POSITIVE:
     281              case PS_FITS_SCALE_STDEV_NEGATIVE:
     282                options->stdevNum = parseOptionFloat(scheme, "STDEV.NUM", source); // Padding to edge
     283                if (!isfinite(options->stdevNum)) {
     284                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.NUM for %s", source);
     285                    psFree(source);
     286                    psFree(file);
     287                    return NULL;
     288                }
     289                // Flow through
     290              case PS_FITS_SCALE_STDEV_BOTH:
     291                options->stdevBits = parseOptionInt(scheme, "STDEV.BITS", source, 0); // Bits for stdev
     292                if (options->stdevBits <= 0) {
     293                    psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.BITS (%d) for %s",
     294                            options->stdevBits, source);
     295                    psFree(source);
     296                    psFree(file);
     297                    return NULL;
     298                }
     299                break;
     300              case PS_FITS_SCALE_MANUAL:
     301                options->bscale = parseOptionDouble(scheme, "BSCALE", source); // Scaling
     302                options->bzero = parseOptionDouble(scheme, "BZERO", source); // Zero point
     303                break;
     304              default:
     305                psAbort("Should never get here.");
     306            }
     307        }
     308
     309        // Compression options
     310        const char *compressString = psMetadataLookupStr(NULL, scheme, "COMPRESSION"); // Compression type
     311        if (compressString) {
     312            psFitsCompressionType type = psFitsCompressionTypeFromString(compressString); // Compression
     313            psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes
     314            tile->data.S32[0] = parseOptionInt(scheme, "TILE.X", source, 0); // Tiling in x
     315            tile->data.S32[1] = parseOptionInt(scheme, "TILE.Y", source, 1); // Tiling in y
     316            tile->data.S32[2] = parseOptionInt(scheme, "TILE.Z", source, 1); // Tiling in z
     317            int noise = parseOptionInt(scheme, "NOISE", source, 16); // Noise bits
     318            int hscale = 0, hsmooth = 0;// Scaling and smoothing for HCOMPRESS
     319            if (type == PS_FITS_COMPRESS_HCOMPRESS) {
     320                hscale = parseOptionInt(scheme, "HSCALE", source, 0);
     321                hsmooth = parseOptionInt(scheme, "HSMOOTH", source, 0);
     322            }
     323
     324            file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth);
     325            psFree(tile);
     326        }
     327
    250328        psFree(source);
    251 
    252         file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth);
    253         psFree(tile);
    254     }
    255 COMPRESSION_DONE:
     329    }
     330 FITS_OPTIONS_DONE:
    256331
    257332    file->fileLevel = pmFPAPHULevel(format);
     
    9711046        }
    9721047        file->detrend = results;
    973         file->fileLevel = pmFPALevelFromName(results->level);
    974         if (file->fileLevel == PM_FPA_LEVEL_NONE) {
     1048        file->fileLevel = pmFPALevelFromName(results->level);
     1049        if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    9751050            psError (PS_ERR_IO, false, "invalid file level for selected detrend data");
    9761051            return NULL;
     
    10211096    // inherit the concepts from the src fpa:
    10221097    pmFPACopyConcepts(file->fpa, file->src);
    1023    
     1098
    10241099    return file;
    10251100}
     
    12331308// pmFPAfile is being used internally.
    12341309pmReadout *pmFPAGenerateReadout(const pmConfig *config, // configuration information
    1235                                 const pmFPAview *view, // select background for this entry
    1236                                 const char *name, // name of internal/external file
    1237                                 const pmFPA *fpa, // use this fpa to generate
    1238                                 const psImageBinning *binning) {
     1310                                const pmFPAview *view, // select background for this entry
     1311                                const char *name, // name of internal/external file
     1312                                const pmFPA *fpa, // use this fpa to generate
     1313                                const psImageBinning *binning) {
    12391314  pmReadout *readout = NULL;
    12401315
     
    12461321    readout = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
    12471322    return readout;
    1248   } 
     1323  }
    12491324
    12501325  // if the mode is INTERNAL, it has been defined in a previous call.  XXX This seems to require
     
    12531328    readout = file->readout;
    12541329    return readout;
    1255   } 
     1330  }
    12561331
    12571332  // we are using this pmFPAfile as an I/O file: select readout or create
Note: See TracChangeset for help on using the changeset viewer.