IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/psModules

  • branches/simtest_nebulous_branches/psModules/src/camera/pmFPAfileDefine.c

    r23370 r27840  
    5757        return NAN;
    5858    }
    59     int value = psMetadataItemParseF32(item); // Value of interst
     59    float value = psMetadataItemParseF32(item); // Value of interst
    6060    return value;
    6161}
     
    7272        return NAN;
    7373    }
    74     int value = psMetadataItemParseF64(item); // Value of interst
     74    double value = psMetadataItemParseF64(item); // Value of interst
    7575    return value;
    7676}
     
    9191    psMetadata *data = pmConfigFileRule(config, camera, name); // File rule
    9292    if (!data) {
    93         psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
     93        psError(psErrorCodeLast(), false, "Can't find file rule %s!", name);
    9494        return NULL;
    9595    }
     
    105105    file->type = pmFPAfileTypeFromString(type);
    106106    if (file->type == PM_FPA_FILE_NONE) {
    107         psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
     107        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
    108108        psFree(file);
    109109        return NULL;
     
    115115    file->dataLevel = pmFPALevelFromName(psMetadataLookupStr (&status, data, "DATA.LEVEL"));
    116116    if (file->dataLevel == PM_FPA_LEVEL_NONE) {
    117         psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
     117        psError(PM_ERR_CONFIG, true, "DATA.LEVEL is not set for %s\n", name);
    118118        psFree(file);
    119119        return NULL;
     
    137137    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, name,
    138138                          PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
    139         psError(PS_ERR_IO, false, "could not add %s to config files", name);
     139        psError(PM_ERR_CONFIG, false, "could not add %s to config files", name);
    140140        return NULL;
    141141    }
     
    167167        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // Known cameras
    168168        if (!mdok || !cameras) {
    169             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
     169            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the system configuration.\n");
    170170            return NULL;
    171171        }
    172172        camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest
    173173        if (!mdok || !camera) {
    174             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
    175                     "camera configuration %s in system configuration.\n", cameraName);
     174            psError(PM_ERR_CONFIG, true,
     175                    "Unable to find automatically generated camera configuration %s in system configuration.",
     176                    cameraName);
    176177            return NULL;
    177178        }
     
    184185    psMetadata *filerule = pmConfigFileRule(config, camera, name); // File rule
    185186    if (!filerule) {
    186         psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
     187        psError(psErrorCodeLast(), false, "Can't find file rule %s!", name);
    187188        return NULL;
    188189    }
     
    199200    file->type = pmFPAfileTypeFromString(type);
    200201    if (file->type == PM_FPA_FILE_NONE) {
    201         psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
     202        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
    202203        psFree(file);
    203204        return NULL;
     
    230231    psMetadata *format = psMetadataLookupMetadata(&status, formats, formatName); // Camera format to use
    231232    if (!format) {
    232         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find format %s for file %s.\n",
     233        psError(PM_ERR_CONFIG, true, "Unable to find format %s for file %s.\n",
    233234                formatName, file->name);
    234235        psFree(file);
     
    287288                options->stdevNum = parseOptionFloat(scheme, "STDEV.NUM", source); // Padding to edge
    288289                if (!isfinite(options->stdevNum)) {
    289                     psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.NUM for %s", source);
     290                    psError(PM_ERR_CONFIG, true, "Bad value for STDEV.NUM for %s", source);
    290291                    psFree(source);
    291292                    psFree(file);
     
    296297                options->stdevBits = parseOptionInt(scheme, "STDEV.BITS", source, 0); // Bits for stdev
    297298                if (options->stdevBits <= 0) {
    298                     psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Bad value for STDEV.BITS (%d) for %s",
     299                    psError(PM_ERR_CONFIG, true, "Bad value for STDEV.BITS (%d) for %s",
    299300                            options->stdevBits, source);
    300301                    psFree(source);
     
    310311                psAbort("Should never get here.");
    311312            }
     313        }
     314
     315        psMetadataItem *fuzz = psMetadataLookup(scheme, "FUZZ"); // Quantisation fuzz?
     316        if (fuzz) {
     317            if (fuzz->type != PS_TYPE_BOOL) {
     318                psWarning("FUZZ in compression scheme %s isn't boolean.", fitsType);
     319                goto FITS_OPTIONS_DONE;
     320            }
     321            options->fuzz = fuzz->data.B;
    312322        }
    313323
     
    337347    file->fileLevel = pmFPAPHULevel(format);
    338348    if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    339         psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", name);
     349        psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s\n", name);
    340350        psFree(file);
    341351        return NULL;
     
    344354    file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, filerule, "DATA.LEVEL"));
    345355    if (file->dataLevel == PM_FPA_LEVEL_NONE) {
    346         psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
     356        psError(PM_ERR_CONFIG, true, "DATA.LEVEL is not set for %s\n", name);
    347357        psFree(file);
    348358        return NULL;
     
    443453        psString realName = pmConfigConvertFilename(filenames->data[0], config, false, false);
    444454        if (!realName) {
    445             psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *)filenames->data[0]);
     455            psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char *)filenames->data[0]);
    446456            return NULL;
    447457        }
     
    451461        psFits *fits = psFitsOpen(realName, "r"); // FITS file
    452462        if (!fits) {
    453             psError(PS_ERR_IO, false, "Failed to open file %s", realName);
     463            psError(psErrorCodeLast(), false, "Failed to open file %s", realName);
    454464            psFree(realName);
    455465            return NULL;
     
    457467        phu = psFitsReadHeader (NULL, fits); // Primary header
    458468        if (!phu) {
    459             psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
     469            psError(psErrorCodeLast(), false, "Failed to read file header %s", realName);
    460470            psFree(realName);
    461471            return NULL;
    462472        }
    463         psFitsClose(fits);
     473        if (!psFitsClose(fits)) {
     474            psError(psErrorCodeLast(), false, "Failed to close file %s", realName);
     475            psFree(realName);
     476            return NULL;
     477        }
    464478
    465479        // Determine the current format from the header; determine camera if not specified already.
     
    467481        format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true);
    468482        if (!format) {
    469             psError(PS_ERR_IO, false, "Failed to determine camera format for %s", realName);
     483            psError(psErrorCodeLast(), false, "Failed to determine camera format for %s", realName);
    470484            psFree(camera);
    471485            psFree(formatName);
     
    477491        fileLevel = pmFPAPHULevel(format);
    478492        if (fileLevel == PM_FPA_LEVEL_NONE) {
    479             psError(PS_ERR_IO, true, "Unable to determine file level for %s", realName);
     493            psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s", realName);
    480494            psFree(camera);
    481495            psFree(formatName);
     
    490504        psFree(camera);
    491505        if (!fpa) {
    492             psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
     506            psError(psErrorCodeLast(), false, "Failed to construct FPA from %s", realName);
    493507            psFree(formatName);
    494508            psFree(realName);
     
    504518    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, cameraName, name); // File, to return
    505519    if (!file) {
    506         psError(PS_ERR_IO, false, "File %s not defined", name);
     520        psError(psErrorCodeLast(), false, "File %s not defined", name);
    507521        psFree(formatName);
    508522        psFree(format);
     
    531545            psString realName = pmConfigConvertFilename(filenames->data[i], config, false, false);
    532546            if (!realName) {
    533                 psError(PS_ERR_IO, false, "Failed to convert file name %s", (char*)filenames->data[i]);
     547                psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char*)filenames->data[i]);
    534548                return NULL;
    535549            }
    536550            psFits *fits = psFitsOpen(realName, "r"); // FITS file
    537551            if (!fits) {
    538                 psError(PS_ERR_IO, false, "Failed to open file %s", realName);
     552                psError(psErrorCodeLast(), false, "Failed to open file %s", realName);
    539553                psFree(realName);
    540554                return NULL;
    541555            }
    542556            phu = psFitsReadHeader(NULL, fits);
    543             psFitsClose(fits);
     557            if (!psFitsClose(fits)) {
     558                psError(psErrorCodeLast(), false, "Failed to close file %s", realName);
     559                psFree(realName);
     560                return NULL;
     561            }
    544562            if (!phu) {
    545                 psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
     563                psError(psErrorCodeLast(), false, "Failed to read file header %s", realName);
    546564                psFree(realName);
    547565                return NULL;
     
    552570        if (i == 0 && file->type == PM_FPA_FILE_MASK) {
    553571            if (!pmConfigMaskReadHeader(config, phu)) {
    554                 psError(PS_ERR_IO, false, "Error reading mask bits");
     572                psError(psErrorCodeLast(), false, "Error reading mask bits");
    555573                psFree(phu);
    556574                return NULL;
     
    562580                bool valid = false;
    563581                if (!pmConfigValidateCameraFormat(&valid, format, phu)) {
    564                     psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
     582                    psError(psErrorCodeLast(), false, "Error in config scripts\n");
    565583                    psFree(phu);
    566584                    return NULL;
    567585                }
    568586                if (!valid) {
    569                     psError(PS_ERR_IO, false, "File %s is not from the required camera",
     587                    psError(psErrorCodeLast(), false, "File %s is not from the required camera",
    570588                            (char*)filenames->data[i]);
    571589                    psFree(phu);
     
    575593                format = pmConfigCameraFormatFromHeader(NULL, NULL, NULL, config, phu, true);
    576594                if (!format) {
    577                     psError(PS_ERR_IO, false, "Failed to determine camera format from %s",
     595                    psError(psErrorCodeLast(), false, "Failed to determine camera format from %s",
    578596                            (char*)filenames->data[i]);
    579597                    psFree(phu);
     
    601619        phu = NULL;
    602620        if (!view) {
    603             psError(PS_ERR_IO, false, "Unable to determine source for %s", name);
     621            psError(PM_ERR_CONFIG, true, "Unable to determine source for %s", name);
    604622            return NULL;
    605623        }
     
    633651    }
    634652    if (filenames->n == 0) {
    635         psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
     653        psError(PM_ERR_CONFIG, true, "No files in array in %s in arguments", argname);
    636654        if (success) {
    637655            *success = false;
     
    667685    }
    668686    if (filenames->n == 0) {
    669         psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
     687        psError(PM_ERR_CONFIG, true, "No files in array in %s in arguments", argname);
    670688        if (success) {
    671689            *success = false;
     
    700718    }
    701719    if (filenames->n <= entry) {
    702         psError(PS_ERR_IO, false, "Insufficient files (%ld) in array in %s in arguments",
     720        psError(PM_ERR_CONFIG, true, "Insufficient files (%ld) in array in %s in arguments",
    703721                filenames->n, argname);
    704722        if (success) {
     
    760778    }
    761779    if (bind && files->n != bind->n) {
    762         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     780        psError(PM_ERR_CONFIG, true,
    763781                "Length of filenames (%ld) and bind files (%ld) does not match.",
    764782                files->n, bind->n);
     
    774792        files->data[i] = psMemIncrRefCounter(fpaFileDefineFromArray(config, bindFile, filename, dummy));
    775793        if (!files->data[i]) {
    776             psError(PS_ERR_UNKNOWN, false, "Unable to define file %s %d", filename, i);
     794            psError(psErrorCodeLast(), false, "Unable to define file %s %d", filename, i);
    777795            psFree(dummy);
    778796            psFree(files);
     
    802820    // a camera config is needed (as source of file rule)
    803821    if (config->camera == NULL) {
    804         psError(PS_ERR_IO, true, "camera is not defined");
     822        psError(PM_ERR_PROG, true, "camera is not defined");
    805823        return NULL;
    806824    }
     
    809827    pmFPA *fpa = pmFPAConstruct(config->camera, config->cameraName);
    810828    if (!fpa) {
    811         psError(PS_ERR_IO, false, "Failed to construct FPA for %s", filename);
     829        psError(psErrorCodeLast(), false, "Failed to construct FPA for %s", filename);
    812830        return NULL;
    813831    }
     
    818836    psFree (fpa);
    819837    if (!file) {
    820         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
     838        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
    821839        return NULL;
    822840    }
     
    824842    // image names may not come from file->names
    825843    if (!strcasecmp(file->filerule, "@FILES")) {
    826         psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES");
     844        psError(PM_ERR_CONFIG, true, "supplied filerule uses illegal value @FILES");
    827845        // XXX remove the file from config->files
    828846        return NULL;
     
    881899    // a camera config is needed (as source of file rule)
    882900    if (config->camera == NULL) {
    883         psError(PS_ERR_IO, true, "camera is not defined");
     901        psError(PM_ERR_PROG, true, "camera is not defined");
    884902        return NULL;
    885903    }
     
    895913        fpa = pmFPAConstruct(config->camera, config->cameraName);
    896914        if (!fpa) {
    897             psError(PS_ERR_IO, false, "Failed to construct FPA for %s", filename);
     915            psError(psErrorCodeLast(), false, "Failed to construct FPA for %s", filename);
    898916            return NULL;
    899917        }
     
    902920        file = pmFPAfileDefineInput (config, fpa, NULL, filename);
    903921        if (!file) {
    904             psError(PS_ERR_IO, false, "file %s not defined\n", filename);
     922            psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
    905923            psFree(fpa);
    906924            return NULL;
     
    934952    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PPIMAGE");
    935953    if (!status) {
    936         psError(PS_ERR_UNEXPECTED_NULL, true, "PPIMAGE recipe not found.");
     954        psError(PM_ERR_CONFIG, true, "PPIMAGE recipe not found.");
    937955        psFree(options);
    938956        psFree(fpa);
     
    10121030        pmDetrendSelectResults *results = pmDetrendSelect (options, config);
    10131031        if (!results) {
    1014             psError (PS_ERR_IO, false, "no matching detrend data");
     1032            psError (psErrorCodeLast(), false, "no matching detrend data");
    10151033            return NULL;
    10161034        }
     
    10181036        file->fileLevel = pmFPALevelFromName(results->level);
    10191037        if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    1020             psError (PS_ERR_IO, false, "invalid file level for selected detrend data");
     1038            psError (PM_ERR_CONFIG, false, "invalid file level for selected detrend data");
    10211039            return NULL;
    10221040        }
     
    10431061    pmFPAfile *file = pmFPAfileDefineOutput (config, fpa, filename);
    10441062    if (!file) {
    1045         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1063        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
    10461064        return NULL;
    10471065    }
     
    10621080    pmFPAfile *file = pmFPAfileDefineOutputForFormat(config, NULL, filename, src->cameraName, src->formatName);
    10631081    if (!file) {
    1064         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1082        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
    10651083        return NULL;
    10661084    }
     
    10841102    pmFPAfile *file = pmFPAfileDefineOutput (config, NULL, filename);
    10851103    if (!file) {
    1086         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1104        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
    10871105        return NULL;
    10881106    }
    10891107    if (!file->camera) {
    1090         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s does not define a new camera\n", filename);
     1108        psError(PM_ERR_CONFIG, false, "file %s does not define a new camera\n", filename);
    10911109        return NULL;
    10921110    }
     
    11271145    }
    11281146    if (!file) {
    1129         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1147        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
    11301148        return NULL;
    11311149    }
     
    11701188    }
    11711189    if (!file) {
    1172         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1190        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
    11731191        return NULL;
    11741192    }
     
    11771195    if (src) {
    11781196        if (!pmConceptsCopyFPA(file->fpa, src, true, false)) {
    1179             psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
     1197            psError(psErrorCodeLast(), false, "Unable to copy concepts from source to new FPA");
    11801198            return NULL;
    11811199        }
     
    12211239    }
    12221240    if (!file) {
    1223         psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1241        psError(PM_ERR_CONFIG, true, "file %s not defined\n", filename);
    12241242        return NULL;
    12251243    }
     
    12281246    if (src) {
    12291247        if (!pmConceptsCopyFPA(file->fpa, src, false, false)) {
    1230             psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
     1248            psError(psErrorCodeLast(), false, "Unable to copy concepts from source to new FPA");
    12311249            return NULL;
    12321250        }
     
    12531271    file->name = psStringCopy (name);
    12541272
     1273    // free a previously existing readout
     1274    psFree(file->readout);
    12551275    file->readout = readout;
    1256     psMetadataAddPtr(files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
     1276
     1277    // allow for multiple entries
     1278    // XXX handle replace vs multiple?
     1279    psMetadataAddPtr(files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file);
    12571280    psFree(file);
    12581281    // we free this copy of file, but 'files' still has a copy
     
    12741297    }
    12751298    if (file == NULL) {
    1276         psError(PS_ERR_IO, true, "file %s is NULL", name);
     1299        psError(PM_ERR_CONFIG, true, "file %s is NULL", name);
    12771300        return false;
    12781301    }
     
    12951318                                const char *name, // name of internal/external file
    12961319                                const pmFPA *fpa, // use this fpa to generate
    1297                                 const psImageBinning *binning) {
     1320                                const psImageBinning *binning,
     1321                                int index) {
    12981322  pmReadout *readout = NULL;
    12991323
    1300   bool status = true;
    1301   pmFPAfile *file = psMetadataLookupPtr(&status, config->files, name);
     1324  pmFPAfile *file = pmFPAfileSelectSingle(config->files, name, index);
    13021325
    13031326  // if the file does not exist, it is not being used as an I/O file: define an internal version
    13041327  if (file == NULL) {
    1305     readout = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
    1306     return readout;
     1328      // XXX currently, we do not guarantee that the defined file lands on entry 'index'
     1329      psAssert (binning, "internal files must be supplied a psImageBinning for the output images size");
     1330      readout = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
     1331      return readout;
    13071332  }
    13081333
Note: See TracChangeset for help on using the changeset viewer.