IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2009, 6:15:31 PM (17 years ago)
Author:
beaumont
Message:

merged with head

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
49 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/psModules

  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryDistortion.c

    r21183 r23594  
    4040}
    4141
    42 pmAstromGradient *pmAstromGradientAlloc ()
     42pmAstromGradient *pmAstromGradientAlloc (void)
    4343{
    4444
     
    126126            grad = pmAstromGradientAlloc ();
    127127
    128             // XXX psTraceSetLevel("psLib.math.psVectorClipFitPolynomial2D", 7);
     128            // XXX psTraceSetLevel("psLib.math.psVectorClipFitPolynomial2D", 7);
    129129
    130130            // fit the collection of positions and offsets with a local 1st order gradient
     
    138138            grad->dTPdM.x = local->coeff[0][1];
    139139
    140             // XXX psTraceSetLevel("psLib.math.psVectorClipFitPolynomial2D", 0);
     140            // XXX psTraceSetLevel("psLib.math.psVectorClipFitPolynomial2D", 0);
    141141
    142142            // fit the collection of positions and offsets with a local 1st order gradient
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryDistortion.h

    r12486 r23594  
    2727pmAstromGradient;
    2828
    29 pmAstromGradient *pmAstromGradientAlloc ();
     29pmAstromGradient *pmAstromGradientAlloc (void);
    3030
    3131/* The following function determines the position residual, in the tangent
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryVisual.c

    r23351 r23594  
    4747/* Initialization Routines  */
    4848
    49 bool pmAstromVisualClose()
     49bool pmAstromVisualClose(void)
    5050{
    5151    if(kapa != -1)
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryVisual.h

    r23351 r23594  
    2626/** Close plotting windows at the end of a run
    2727 * @return true for success */
    28 bool pmAstromVisualClose();
     28bool pmAstromVisualClose(void);
    2929
    3030
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPARead.c

    r22699 r23594  
    554554          }
    555555          psFree(header);
    556           bad = pmConfigMaskGet("BAD", config);
     556          bad = pmConfigMaskGet("LOW", config);
     557          if (!bad) {
     558              // XXX look up old name for compatability
     559              bad = pmConfigMaskGet("BAD", config);
     560          }
    557561          break;
    558562      }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAWrite.c

    r23351 r23594  
    172172
    173173    if (writeBlank || writeImage) {
    174         pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
    175                                  PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE;
    176         if (!pmConceptsWriteCell(cell, source, true, config)) {
     174        if (!pmConceptsWriteCell(cell, true, config)) {
    177175            psError(PS_ERR_IO, false, "Unable to write concepts for cell.");
    178176            return false;
     
    225223
    226224        if (writeBlank || writeImage) {
    227             pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
    228                                      PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE;
    229             if (!pmConceptsWriteChip(chip, source, true, true, config)) {
     225            if (!pmConceptsWriteChip(chip, true, true, config)) {
    230226                psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n");
    231227                return false;
     
    294290
    295291        if (writeBlank || writeImage) {
    296             pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
    297                                      PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE;
    298             if (!pmConceptsWriteFPA(fpa, source, true, config)) {
     292            if (!pmConceptsWriteFPA(fpa, true, config)) {
    299293                psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
    300294                return false;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfile.c

    r23351 r23594  
    2020#include "pmConceptsCopy.h"
    2121
     22static int fileNum = 0;                 // Number of file
     23
    2224static void pmFPAfileFree(pmFPAfile *file)
    2325{
     
    5658}
    5759
    58 pmFPAfile *pmFPAfileAlloc()
     60pmFPAfile *pmFPAfileAlloc(void)
    5961{
    6062    pmFPAfile *file = psAlloc(sizeof(pmFPAfile));
     
    100102
    101103    file->save = false;
     104
     105    file->index = fileNum++;
    102106
    103107    file->imageId = 0;
     
    350354            psStringSubstitute(&newRule, name, "{OUTPUT}");
    351355        }
     356    }
     357
     358    if (strstr(newRule, "{FILE.INDEX}")) {
     359        // Number of the file in list
     360        psString num = NULL;            // Number to use
     361        psStringAppend(&num, "%d", file->index);
     362        psStringSubstitute(&newRule, num, "{FILE.INDEX}");
     363        psFree(num);
    352364    }
    353365
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfile.h

    r23351 r23594  
    109109    psString formatName;                // name of the camera format
    110110
     111    int index;                          // Index of file
     112
    111113    psS64 imageId, sourceId;            // Image and source identifiers
    112114} pmFPAfile;
    113115
    114116// allocate an empty pmFPAfile structure
    115 pmFPAfile *pmFPAfileAlloc ();
     117pmFPAfile *pmFPAfileAlloc(void);
    116118
    117119// select the readout from the named pmFPAfile; if the named file does not exist,
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileDefine.c

    r23351 r23594  
    382382
    383383    // place the resulting file in the config system
    384     psMetadataAddPtr(config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "Output file", file);
     384    psMetadataAddPtr(config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK,
     385                     "Output file", file);
    385386    psFree(file);                       // we free this copy of file, but 'files' still has a copy
    386387    return file;                        // the returned value is a view into the version on 'files'
     
    719720}
    720721
    721 pmFPAfile *pmFPAfileDefineFromRun(bool *success, pmConfig *config, const char *filename)
     722pmFPAfile *pmFPAfileDefineFromRun(bool *success, pmFPAfile *bind, pmConfig *config, const char *filename)
    722723{
    723724    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    732733    }
    733734
    734     pmFPAfile *file = fpaFileDefineFromArray(config, NULL, filename, filenames); // File of interest
     735    pmFPAfile *file = fpaFileDefineFromArray(config, bind, filename, filenames); // File of interest
    735736    psFree(filenames);
    736737
     
    742743}
    743744
     745psArray *pmFPAfileDefineMultipleFromRun(bool *success, psArray *bind, pmConfig *config, const char *filename)
     746{
     747    PS_ASSERT_PTR_NON_NULL(config, NULL);
     748    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     749
     750    if (success) {
     751        *success = false;
     752    }
     753
     754    psArray *files = pmConfigRunFileGet(config, filename); // Filenames used, to return
     755    if (!files || files->n == 0) {
     756        if (success) {
     757            *success = true;
     758        }
     759        return NULL;
     760    }
     761    if (bind && files->n != bind->n) {
     762        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     763                "Length of filenames (%ld) and bind files (%ld) does not match.",
     764                files->n, bind->n);
     765        psFree(files);
     766        return NULL;
     767    }
     768
     769    psArray *dummy = psArrayAlloc(1);   // Dummy array of single filename
     770    for (int i = 0; i < files->n; i++) {
     771        psFree(dummy->data[0]);
     772        dummy->data[0] = files->data[i];
     773        pmFPAfile *bindFile = bind ? bind->data[i] : NULL; // File to which to bind
     774        files->data[i] = psMemIncrRefCounter(fpaFileDefineFromArray(config, bindFile, filename, dummy));
     775        if (!files->data[i]) {
     776            psError(PS_ERR_UNKNOWN, false, "Unable to define file %s %d", filename, i);
     777            psFree(dummy);
     778            psFree(files);
     779            return NULL;
     780        }
     781    }
     782    psFree(dummy);
     783
     784    if (success) {
     785        *success = true;
     786    }
     787
     788    return files;
     789}
    744790
    745791// define the named pmFPAfile from the camera->config
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileDefine.h

    r23351 r23594  
    6767pmFPAfile *pmFPAfileDefineFromRun(
    6868    bool *found,                        ///< Found files?
     69    pmFPAfile *bind,                    ///< File to which to bind, or NULL
    6970    pmConfig *config,                   ///< Configuration
    7071    const char *filename                ///< Name of file
    7172    );
    7273
     74/// Define multiple files based on the filenames in the RUN metadata in the configuration
     75///
     76/// An array of the files defined is returned
     77psArray *pmFPAfileDefineMultipleFromRun(
     78    bool *found,                        ///< Found files?
     79    psArray *bind,                      ///< Files to which to bind, or NULL
     80    pmConfig *config,                   ///< Configuration
     81    const char *filename                ///< Name of file
     82    );
    7383
    7484// look for the given argname on the argument list.  find the give filename from the file rules
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileFitsIO.c

    r22699 r23594  
    183183          }
    184184
    185           pmConceptSource sources = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS |
    186               PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE; // Concept sources to write
    187185          if (cell) {
    188               if (!pmConceptsWriteCell(cell, sources, true, config)) {
     186              if (!pmConceptsWriteCell(cell, true, config)) {
    189187                  psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n");
    190188                  return false;
    191189              }
    192190          } else if (chip) {
    193               if (!pmConceptsWriteChip(chip, sources, true, true, config)) {
     191              if (!pmConceptsWriteChip(chip, true, true, config)) {
    194192                  psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n");
    195193                  return false;
    196194              }
    197           } else if (!pmConceptsWriteFPA(fpa, sources, true, config)) {
     195          } else if (!pmConceptsWriteFPA(fpa, true, config)) {
    198196              psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
    199197              return false;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileIO.c

    r23351 r23594  
    166166    }
    167167
    168     if (!pmConfigRunFileAdd(config, file)) {
     168    if (!pmConfigRunFileAddRead(config, file)) {
    169169        psError(PS_ERR_UNKNOWN, false, "Unable to add file to run-time information");
    170170        return false;
     
    421421    }
    422422
    423     if (!pmConfigRunFileAdd(config, file)) {
     423    if (!pmConfigRunFileAddWrite(config, file)) {
    424424        psError(PS_ERR_UNKNOWN, false, "Unable to add file to run-time information");
    425425        return false;
     
    635635}
    636636
     637psString pmFPAfileName(const pmFPAfile *file, const pmFPAview *view, pmConfig *config)
     638{
     639    PS_ASSERT_PTR_NON_NULL(file, NULL);
     640    PS_ASSERT_PTR_NON_NULL(view, NULL);
     641    PS_ASSERT_PTR_NON_NULL(config, NULL);
     642
     643    psString filename = pmFPAfileNameFromRule(file->filerule, file, view); // Filename, based on rule
     644    if (!filename) {
     645        psError(PS_ERR_IO, true, "Cannot determine file name from rule");
     646        return false;
     647    }
     648
     649    // indirect filenames: these come from a list on the command line or elsewhere
     650    if (!strcasecmp(filename, "@FILES")) {
     651        psString filesrc = pmFPAfileNameFromRule(file->filesrc, file, view); // Source of file name
     652        if (!filesrc) {
     653            psError(PS_ERR_IO, false, "error converting filesrc to name %s", file->filesrc);
     654            return false;
     655        }
     656        psFree(filename);
     657        filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, file->names, filesrc));
     658        if (!filename) {
     659            psError(PS_ERR_IO, false, "filename lookup error (@FILES) for %s : %s", file->filesrc, filesrc);
     660            psFree(filesrc);
     661            return false;
     662        }
     663        psFree(filesrc);
     664    }
     665
     666    // get name from detrend database
     667    // file->detrend->detID contains the desired -det_id detID -iteration iter string
     668    if (!strcasecmp(filename, "@DETDB")) {
     669        if (!file->detrend) {
     670            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find information about selected detrend.");
     671            return false;
     672        }
     673        psMetadata *menu = psMetadataLookupMetadata(NULL, file->camera, "CLASSID"); // Menu of class IDs
     674        if (!menu) {
     675            psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
     676            return false;
     677        }
     678        const char *rule = psMetadataLookupStr(NULL, menu, file->detrend->level); // Rule for class_id
     679        if (!rule || strlen(rule) == 0) {
     680            psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration",
     681                    file->detrend->level);
     682            return false;
     683        }
     684        psString classId = pmFPAfileNameFromRule(rule, file, view); // The class identifier, for pmDetrendFile
     685        if (!classId) {
     686            psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
     687            return false;
     688        }
     689
     690        psTrace("psModules.camera", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
     691        psFree(filename);
     692        filename = pmDetrendFile(file->detrend->detID, classId, config);
     693        if (!filename) {
     694            psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s",
     695                    file->detrend->detID, classId);
     696            psFree(classId);
     697            return false;
     698        }
     699
     700        psTrace("psModules.camera", 6, "got detrend file %s", filename);
     701        psFree(classId);
     702    }
     703
     704    return filename;
     705}
     706
    637707// open file (if not already opened).
    638708// this function is only called only within pmFPAfileRead or pmFPAfileWrite.
     
    672742
    673743    // determine the file name, free a name allocated earlier
    674     psFree (file->filename);
    675     file->filename = pmFPAfileNameFromRule (file->filerule, file, view);
    676     if (file->filename == NULL) {
    677         psError(PS_ERR_IO, true, "Filename is NULL");
    678         return false;
    679     }
    680 
    681     // indirect filenames: these come from a list on the command line or elsewhere
    682     if (!strcasecmp (file->filename, "@FILES")) {
    683         char *filesrc = pmFPAfileNameFromRule (file->filesrc, file, view);
    684         if (filesrc == NULL) {
    685             psError(PS_ERR_IO, false, "error converting filesrc to name %s\n", file->filesrc);
    686             return false;
    687         }
    688 
    689         psFree (file->filename);
    690         file->filename = psMetadataLookupStr (&status, file->names, filesrc);
    691 
    692         if (file->filename == NULL) {
    693             psError(PS_ERR_IO, true, "filename lookup error (@FILES) for %s : %s\n", file->filesrc, filesrc);
    694             psFree (filesrc);
    695             return false;
    696         }
    697         // psMetadataLookupStr just returns a view, file->filename must be protected
    698         psMemIncrRefCounter (file->filename);
    699         psFree (filesrc);
    700     }
    701 
    702     // get name from detrend database
    703     // file->detrend->detID contains the desired -det_id detID -iteration iter string
    704     if (!strcasecmp (file->filename, "@DETDB")) {
    705         if (!file->detrend) {
    706             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find information about selected detrend.");
    707             return false;
    708         }
    709 
    710         psString classId = NULL;        // The class identifier, to pass to pmDetrendFile
    711         psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "CLASSID"); // Menu of class IDs
    712         if (!status || !menu) {
    713             psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
    714             return false;
    715         }
    716         const char *rule = psMetadataLookupStr(&status, menu, file->detrend->level); // Rule for class_id
    717         if (!status || !rule || strlen(rule) == 0) {
    718             psError(PS_ERR_IO, false, "Unable to find %s in CLASSID in camera configuration", file->detrend->level);
    719             return false;
    720         }
    721         classId = pmFPAfileNameFromRule(rule, file, view);
    722         if (!classId) {
    723             psError(PS_ERR_IO, false, "error converting CLASSID rule to name: %s\n", rule);
    724             return false;
    725         }
    726         psTrace ("psModules.camera", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
    727         psFree (file->filename);
    728 
    729         file->filename = pmDetrendFile(file->detrend->detID, classId, config);
    730         if (file->filename == NULL) {
    731             psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s\n", file->detrend->detID, classId);
    732             psFree (classId);
    733             return false;
    734         }
    735 
    736         psTrace ("psModules.camera", 6, "got detrend file %s\n", file->filename);
    737         psFree (classId);
     744    psFree(file->filename);
     745    file->filename = pmFPAfileName(file, view, config);
     746    if (!file->filename) {
     747        psError(PS_ERR_IO, true, "Unable to determine filename");
     748        return false;
    738749    }
    739750
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileIO.h

    r18364 r23594  
    1515/// @addtogroup Camera Camera Layout
    1616/// @{
     17
     18// Determine appropriate file name
     19psString pmFPAfileName(const pmFPAfile *file, const pmFPAview *view, pmConfig *config);
    1720
    1821// open the real file corresponding to the given pmFPAfile appropriate to the current view
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsStandard.c

    r23351 r23594  
    606606}
    607607
     608// Get the current value of a concept
     609static psMetadataItem *conceptGet(const pmFPA *fpa, // FPA of interest
     610                                  const pmChip *chip, // Chip of interest, or NULL
     611                                  const pmCell *cell, // Cell of interest, or NULL
     612                                  const char *name // Concept name
     613    )
     614{
     615    psMetadataItem *item = NULL;        // Item with time system
     616    if (cell) {
     617        item = psMetadataLookup(cell->concepts, name);
     618    }
     619    if (!item && chip) {
     620        item = psMetadataLookup(chip->concepts, name);
     621    }
     622    if (!item && fpa) {
     623        item = psMetadataLookup(fpa->concepts, name);
     624    }
     625    if (!item) {
     626        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find %s in concepts", name);
     627        return NULL;
     628    }
     629    return item;
     630}
     631
     632// Determine the corresponding TIMESYS for one of the TIME concepts
     633static psTimeType conceptGetTimesysForTime(const char *name, // Concept name ("CELL.TIME" or "FPA.TIME")
     634                                           const pmFPA *fpa, // FPA of interest
     635                                           const pmChip *chip, // Chip of interest, or NULL
     636                                           const pmCell *cell // Cell of interest, or NULL
     637                                           )
     638{
     639    assert(name);
     640
     641    psString timesysName = psStringCopy(name); // e.g., "CELL.TIME" --> "CELL.TIMESYS"
     642    psStringSubstitute(&timesysName, "TIMESYS", "TIME");
     643    psMetadataItem *item = conceptGet(fpa, chip, cell, timesysName); // Time system
     644    psFree(timesysName);
     645
     646    if (!item || item->type != PS_TYPE_S32) {
     647        psWarning("Unable to find %s --- assuming UTC", timesysName);
     648        return PS_TIME_UTC;
     649    }
     650    return item->data.S32;
     651}
     652
     653// Set the corresponding TIMESYS for one of the TIME concepts
     654static bool conceptSetTimesysForTime(const char *name, // Concept name ("CELL.TIME" or "FPA.TIME")
     655                                     const pmFPA *fpa, // FPA of interest
     656                                     const pmChip *chip, // Chip of interest, or NULL
     657                                     const pmCell *cell, // Cell of interest, or NULL
     658                                     psTimeType timeSys // The time system value
     659                                     )
     660{
     661    assert(name);
     662
     663    psString timesysName = psStringCopy(name); // e.g., "CELL.TIME" --> "CELL.TIMESYS"
     664    psStringSubstitute(&timesysName, "TIMESYS", "TIME");
     665    psMetadataItem *item = conceptGet(fpa, chip, cell, timesysName); // Time system
     666    psFree(timesysName);
     667
     668    if (!item) {
     669        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find %s in concepts when setting %s\n",
     670                timesysName, name);
     671        return false;
     672    }
     673
     674    if (item->data.S32 != -1 && item->data.S32 != timeSys) {
     675        psWarning("Time system is set to %x; but should be %x", item->data.S32, timeSys);
     676    }
     677
     678    item->data.S32 = timeSys;
     679
     680    return true;
     681}
    608682
    609683psMetadataItem *p_pmConceptParse_TIMESYS(const psMetadataItem *concept,
     
    622696    if (concept->type != PS_DATA_STRING || strlen(sys) <= 0) {
    623697        // XXX is this too low verbosity?
    624         psLogMsg ("psModules.concepts", PS_LOG_DETAIL, "Can't interpret %s --- assuming UTC.\n", pattern->name);
     698        psWarning("Can't interpret %s --- assuming UTC.", pattern->name);
    625699    } else if (strcasecmp(sys, "TAI") == 0) {
    626700        timeSys = PS_TIME_TAI;
     
    633707    } else {
    634708        // XXX is this too low verbosity?
    635         psLogMsg ("psModules.concepts", PS_LOG_DETAIL, "Can't interpret %s --- assuming UTC.\n", pattern->name);
     709        psWarning("Can't interpret %s --- assuming UTC.", pattern->name);
     710    }
     711
     712    psMetadataItem *old = conceptGet(fpa, chip, cell, pattern->name); // Old value
     713    if (old && old->data.S32 != -1 && old->data.S32 != timeSys) {
     714        psWarning("%s is already set (%x) and not consistent with new value (%x)",
     715                  pattern->name, old->data.S32, timeSys);
    636716    }
    637717
     
    639719}
    640720
    641 // Determine the corresponding TIMESYS for one of the TIME concepts
    642 static psTimeType conceptGetTimesysForTime(const char *name, // Concept name ("CELL.TIME" or "FPA.TIME")
    643                                            const pmFPA *fpa, // FPA of interest
    644                                            const pmChip *chip, // Chip of interest, or NULL
    645                                            const pmCell *cell // Cell of interest, or NULL
    646                                            )
    647 {
    648     assert(name);
    649 
    650     psString timesysName = psStringCopy(name); // e.g., "CELL.TIME" --> "CELL.TIMESYS"
    651     psStringSubstitute(&timesysName, "TIMESYS", "TIME");
    652     bool mdok = false;                  // Result of MD lookup
    653     psTimeType timeSys = 0xFFFFFFFF;    // The time system
    654     if (cell) {
    655         timeSys = psMetadataLookupS32(&mdok, cell->concepts, timesysName);
    656     }
    657     if (!mdok && chip) {
    658         timeSys = psMetadataLookupS32(&mdok, chip->concepts, timesysName);
    659     }
    660     if (!mdok && fpa) {
    661         timeSys = psMetadataLookupS32(&mdok, fpa->concepts, timesysName);
    662     }
    663     if (!mdok || (timeSys == 0xFFFFFFFF)) {
    664         psWarning("Unable to find %s in concepts when parsing %s --- assuming UTC.\n",
    665                   timesysName, name);
    666         timeSys = PS_TIME_UTC;
    667     }
    668     psFree(timesysName);
    669 
    670     return timeSys;
    671 }
     721
    672722
    673723psMetadataItem *p_pmConceptParse_TIME(const psMetadataItem *concept,
     
    896946    }
    897947
    898     time->type = timeSys;
     948    if (jdTime || mjdTime) {
     949        conceptSetTimesysForTime(pattern->name, fpa, chip, cell, PS_TIME_TAI);
     950    } else {
     951        time->type = timeSys;
     952    }
    899953
    900954    psMetadataItem *item = psMetadataItemAllocPtr(pattern->name, PS_DATA_TIME, pattern->comment, time);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsWrite.c

    r22699 r23594  
    6262        while ((cItem = psListGetAndIncrement(cIter))) {
    6363            if (cItem->type != PS_DATA_STRING) {
    64                 psWarning("psMetadataItem from list is of type %x instead of "
    65                          "%x (PS_DATA_STRING) --- can't interpret.\n", cItem->type, PS_DATA_STRING);
     64                psWarning("psMetadataItem from list is of type %x instead of %x (PS_DATA_STRING) --- can't interpret.\n", cItem->type, PS_DATA_STRING);
    6665                psFree(cIter);
    6766                psFree(sIter);
     
    183182        }
    184183    default:
    185         psWarning("Type of %s is not suitable for a FITS header --- not added.\n",
     184      psWarning("Type of %s is not suitable for a FITS header --- not added.\n",
    186185                 item->name);
    187186        return false;
     
    226225}
    227226
     227// Return the camera format appropriate for a focal plane hierarchy
     228static psMetadata *conceptsCameraFormat(const pmFPA *fpa, const pmChip *chip, const pmCell *cell)
     229{
     230    pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     231    if (!hdu) {
     232        return NULL;
     233    }
     234    return hdu->format;
     235}
     236
     237// Return the DATABASE metadata from the format
     238static psMetadata *conceptsDatabase(const psMetadata *format)
     239{
     240    bool mdok;                          // Status of MD lookup
     241    return psMetadataLookupMetadata(&mdok, format, "DEFAULTS");
     242}
     243
     244// Return the TRANSLATION metadata from the format
     245static psMetadata *conceptsTranslation(const psMetadata *format)
     246{
     247    bool mdok;                          // Status of MD lookup
     248    return psMetadataLookupMetadata(&mdok, format, "TRANSLATION");
     249}
     250
     251// Return the DEFAULTS metadata from the format
     252static psMetadata *conceptsDefaults(const psMetadata *format)
     253{
     254    bool mdok;                          // Status of MD lookup
     255    return psMetadataLookupMetadata(&mdok, format, "DEFAULTS");
     256}
     257
    228258
    229259//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    231261//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    232262
    233 bool p_pmConceptsWriteToCells(const psMetadata *specs, const pmCell *cell, const psMetadata *concepts)
    234 {
    235     PS_ASSERT_PTR_NON_NULL(specs, false);
    236     PS_ASSERT_PTR_NON_NULL(concepts, false);
     263bool p_pmConceptWriteToCells(const pmCell *cell, const pmConceptSpec *spec,
     264                             const psMetadataItem *conceptItem, const psMetadata *format)
     265{
    237266    if (!cell) {
    238267        return false;
     
    242271    }
    243272
    244     pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     273    if (!format) {
     274        format = conceptsCameraFormat(NULL, NULL, cell);
     275        if (!format) {
     276            return false;
     277        }
     278    }
     279
     280    psMetadataItem *cameraItem = psMetadataLookup(cell->config, conceptItem->name); // Version in the config
     281    if (!cameraItem) {
     282        return false;
     283    }
     284
     285    psString nameSource = NULL; // String with the concept name and ".SOURCE" added
     286    psStringAppend(&nameSource, "%s.SOURCE", conceptItem->name);
     287    bool mdok = true;       // Status of MD lookup
     288    psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
     289    if (mdok && strlen(source) > 0) {
     290        psTrace("psModules.concepts", 8, "%s is %s\n", nameSource, source);
     291        if (strcasecmp(source, "HEADER") == 0) {
     292            if (cameraItem->type != PS_DATA_STRING) {
     293                psWarning("Concept %s is specified by header, but is not of type STR --- ignored.",
     294                          conceptItem->name);
     295                psFree(nameSource);
     296                return false;
     297            }
     298
     299            // Formatted version
     300            psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
     301                                                      format, NULL, NULL, cell);
     302            if (!formatted) {
     303                psFree(nameSource);
     304                return true;
     305            }
     306
     307            psTrace("psModules.concepts", 8, "Writing %s to header %s\n",
     308                    conceptItem->name, cameraItem->data.str);
     309            pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // Header data unit
     310            if (!hdu) {
     311                psError(PS_ERR_UNEXPECTED_NULL, false,
     312                        "Unable to find HDU to write concept %s", conceptItem->name);
     313                return false;
     314            }
     315            writeHeader(hdu, cameraItem->data.V, formatted);
     316            psFree(formatted);
     317        } else if (strcasecmp(source, "VALUE") == 0) {
     318            // Formatted version
     319            psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
     320                                                      format, NULL, NULL, cell);
     321            if (!formatted) {
     322                psFree(nameSource);
     323                return true;
     324            }
     325
     326            psTrace("psModules.concepts", 8, "Checking %s against camera format.\n", conceptItem->name);
     327            if (!compareConcepts(formatted, cameraItem)) {
     328                psWarning("Concept %s is specified by value in the camera format, but the values don't match",
     329                          conceptItem->name);
     330            }
     331            psFree(formatted);
     332        } else {
     333            psWarning("Concept source %s isn't HEADER or VALUE --- can't write", nameSource);
     334        }
     335    } else {
     336        // Assume it's specified by value
     337        psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
     338                                                  format, NULL, NULL, cell);
     339        if (!formatted) {
     340            psFree(nameSource);
     341            return true;
     342        }
     343
     344        if (!compareConcepts(formatted, cameraItem)) {
     345            psWarning("Concept %s is specified by value in the camera format, but the values don't match.",
     346                      conceptItem->name);
     347        }
     348        psFree(formatted);
     349    }
     350    psFree(nameSource);
     351
     352    return true;
     353}
     354
     355bool p_pmConceptWriteToDefaults(const pmFPA *fpa, const pmChip *chip, const pmCell *cell,
     356                                const pmConceptSpec *spec, const psMetadataItem *conceptItem,
     357                                const psMetadata *format, const psMetadata *defaults)
     358{
     359    if (!format) {
     360        format = conceptsCameraFormat(fpa, chip, cell);
     361        if (!format) {
     362            return false;
     363        }
     364    }
     365    if (!defaults) {
     366        defaults = conceptsDefaults(format);
     367        if (!defaults) {
     368            return false;
     369        }
     370    }
     371
     372    psMetadataItem *defaultItem = p_pmConceptsReadSingleFromDefaults(conceptItem->name, defaults,
     373                                                                     fpa, chip, cell);
     374    if (!defaultItem) {
     375        return false;
     376    }
     377    psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS,
     378                                              format, fpa, chip, cell);
     379    if (!formatted) {
     380        return true;
     381    }
     382
     383    if (strcmp(defaultItem->name, conceptItem->name) != 0) {
     384        // Correct the name to match the concept name
     385        defaultItem = psMetadataItemCopy(defaultItem);
     386        psFree(defaultItem->name);
     387        defaultItem->name = psStringCopy(conceptItem->name);
     388    } else {
     389        psMemIncrRefCounter(defaultItem);
     390    }
     391
     392    if (!compareConcepts(formatted, defaultItem)) {
     393        psWarning("Concept %s is specified by the DEFAULTS in the camera format, but the values don't match.",
     394                  conceptItem->name);
     395    }
     396    psFree(defaultItem);
     397    psFree(formatted);
     398
     399    return true;
     400}
     401
     402
     403bool p_pmConceptWriteToHeader(const pmFPA *fpa, const pmChip *chip, const pmCell *cell,
     404                              const pmConceptSpec *spec, const psMetadataItem *conceptItem,
     405                              const psMetadata *format, const psMetadata *translation)
     406{
     407    if (!format) {
     408        format = conceptsCameraFormat(fpa, chip, cell);
     409        if (!format) {
     410            return false;
     411        }
     412    }
     413    if (!translation) {
     414        translation = conceptsTranslation(format);
     415        if (!translation) {
     416            return false;
     417        }
     418    }
     419
     420    psMetadataItem *headerItem = psMetadataLookup(translation, conceptItem->name); // How to format for header
     421    if (!headerItem) {
     422        return false;
     423    }
     424    if (headerItem->type == PS_DATA_METADATA) {
     425        // This is a menu
     426        psTrace("psModules.concepts", 5, "%s is of type METADATA.\n", conceptItem->name);
     427        headerItem = p_pmConceptsDepend(conceptItem->name, headerItem->data.md, translation, fpa, chip, cell);
     428        if (!headerItem) {
     429            return false;
     430        }
     431    }
     432    if (headerItem->type != PS_DATA_STRING) {
     433        psWarning("TRANSLATION keyword for concept %s isn't of type STR --- ignored.", conceptItem->name);
     434        return false;
     435    }
     436    psTrace("psModules.concepts", 3, "Writing %s to header %s\n", conceptItem->name, headerItem->data.str);
     437    psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
     438                                              format, fpa, chip, cell);
     439    if (!formatted) {
     440        // Found it, but it doesn't need to be written
     441        return true;
     442    }
     443
     444    pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // HDU to which to write
    245445    if (!hdu) {
    246         return false;
    247     }
    248     psMetadata *cameraFormat = hdu->format; // The camera format
    249     psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    250     psMetadataItem *specItem = NULL;    // Item from the specs metadata
    251     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    252         pmConceptSpec *spec = specItem->data.V; // The specification
    253         psString name = specItem->name; // The concept name
    254         psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera,
    255         // or NULL
    256         if (cameraItem) {
    257             // Grab the concept
    258             psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept
    259 
    260             psString nameSource = NULL; // String with the concept name and ".SOURCE" added
    261             psStringAppend(&nameSource, "%s.SOURCE", name);
    262             bool mdok = true;       // Status of MD lookup
    263             psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
    264             if (mdok && strlen(source) > 0) {
    265                 psTrace("psModules.concepts", 8, "%s is %s\n", nameSource, source);
    266                 if (strcasecmp(source, "HEADER") == 0) {
    267                     if (cameraItem->type != PS_DATA_STRING) {
    268                         psWarning("Concept %s is specified by header, but is not "
    269                                  "of type STR --- ignored.\n", conceptItem->name);
    270                         continue;
    271                     }
    272 
    273                     // Formatted version
    274                     psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
    275                                                               cameraFormat, NULL, NULL, cell);
    276                     if (!formatted) {
    277                         continue;
    278                     }
    279 
    280                     psTrace("psModules.concepts", 8, "Writing %s to header %s\n", name, cameraItem->data.str);
    281                     writeHeader(hdu, cameraItem->data.V, formatted);
    282                     psFree(formatted);
    283                 } else if (strcasecmp(source, "VALUE") == 0) {
    284                     // Formatted version
    285                     psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
    286                                                               cameraFormat, NULL, NULL, cell);
    287                     if (!formatted) {
    288                         continue;
    289                     }
    290 
    291                     psTrace("psModules.concepts", 8, "Checking %s against camera format.\n", name);
    292                     if (! compareConcepts(formatted, cameraItem)) {
    293                         psWarning("Concept %s is specified by value in the camera "
    294                                  "format, but the values don't match.\n", name);
    295                     }
    296                     psFree(formatted);
    297                 } else {
    298                     psWarning("Concept source %s isn't HEADER or VALUE --- can't "
    299                              "write\n", nameSource);
    300                 }
    301             } else {
    302                 // Assume it's specified by value
    303                 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
    304                                                           cameraFormat, NULL, NULL, cell);
    305                 if (!formatted) {
    306                     continue;
    307                 }
    308 
    309                 if (! compareConcepts(formatted, cameraItem)) {
    310                     psWarning("Concept %s is specified by value in the camera "
    311                              "format, but the values don't match.\n", name);
    312                 }
    313                 psFree(formatted);
    314             }
    315             psFree(nameSource);
    316         }
    317 
    318     }
    319     psFree(specsIter);
     446        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU to write concept %s", conceptItem->name);
     447        return false;
     448    }
     449    writeHeader(hdu, headerItem->data.V, formatted);
     450    psFree(formatted);
     451
    320452    return true;
    321453}
    322454
    323 bool p_pmConceptsWriteToDefaults(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip,
    324                                  const pmCell *cell, const psMetadata *concepts)
    325 {
    326     PS_ASSERT_PTR_NON_NULL(specs, false);
    327     PS_ASSERT_PTR_NON_NULL(concepts, false);
    328 
    329     pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
    330     if (!hdu) {
    331         return false;
    332     }
    333     psMetadata *cameraFormat = hdu->format; // The camera format
    334     bool mdok = true;                   // Status of MD lookup
    335     psMetadata *defaults = psMetadataLookupMetadata(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec
    336     if (!mdok || !defaults) {
    337         return false;
    338     }
    339 
    340     psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    341     psMetadataItem *specItem = NULL;    // Item from the specs metadata
    342     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    343         pmConceptSpec *spec = specItem->data.V; // The specification
    344         psString name = specItem->name; // The concept name
    345 
    346         psMetadataItem *defaultItem = p_pmConceptsReadSingleFromDefaults(name, defaults, fpa, chip, cell);
    347         if (!defaultItem) {
    348             continue;
    349         }
    350         psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    351         psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS,
    352                                                   cameraFormat, fpa, chip, cell);
    353         if (!formatted) {
    354             continue;
    355         }
    356 
    357         if (strcmp(defaultItem->name, name) != 0) {
    358             // Correct the name to match the concept name
    359             defaultItem = psMetadataItemCopy(defaultItem);
    360             psFree(defaultItem->name);
    361             defaultItem->name = psStringCopy(name);
    362         } else {
    363             psMemIncrRefCounter(defaultItem);
    364         }
    365 
    366         if (!compareConcepts(formatted, defaultItem)) {
    367             psWarning("Concept %s is specified by the DEFAULTS in the camera "
    368                       "format, but the values don't match.\n", name);
    369         }
    370         psFree(defaultItem);
    371         psFree(formatted);
    372     }
    373     psFree(specsIter);
     455bool p_pmConceptWriteToDatabase(const pmFPA *fpa, const pmChip *chip, const pmCell *cell,
     456                                pmConfig *config, const pmConceptSpec *spec,
     457                                const psMetadataItem *conceptItem, const psMetadata *format,
     458                                const psMetadata *database)
     459{
     460    PS_ASSERT_PTR_NON_NULL(config, false);
     461
     462#ifndef HAVE_PSDB
     463    return false;
     464#else
     465
     466    if (!format) {
     467        format = conceptsCameraFormat(fpa, chip, cell);
     468        if (!format) {
     469            return false;
     470        }
     471    }
     472    if (!database) {
     473        database = conceptsDatabase(format);
     474        if (!database) {
     475            return false;
     476        }
     477    }
     478
     479    psMetadataItem *dbItem = p_pmConceptsReadSingleFromDatabase(conceptItem->name, database, config,
     480                                                                fpa, chip, cell); // Database version
     481    if (!dbItem) {
     482        return false;
     483    }
     484
     485    psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE,
     486                                              format, fpa, chip, cell);
     487    if (!formatted) {
     488        return false;
     489    }
     490
     491    if (strcmp(dbItem->name, conceptItem->name) != 0) {
     492        // Correct the name to match the concept name
     493        dbItem = psMetadataItemCopy(dbItem);
     494        psFree(dbItem->name);
     495        dbItem->name = psStringCopy(conceptItem->name);
     496    } else {
     497        psMemIncrRefCounter(dbItem);
     498    }
     499
     500    if (!compareConcepts(formatted, dbItem)) {
     501        psWarning("Concept %s is specified by the DATABASE in the camera "
     502                  "format, but the values don't match.\n", conceptItem->name);
     503    }
     504    psFree(dbItem);
     505    psFree(formatted);
     506
    374507    return true;
    375 }
    376 
    377 
    378 bool p_pmConceptsWriteToHeader(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip,
    379                                const pmCell *cell, const psMetadata *concepts)
    380 {
    381     PS_ASSERT_PTR_NON_NULL(specs, false);
    382     PS_ASSERT_PTR_NON_NULL(concepts, false);
    383 
    384     pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
    385     if (!hdu) {
    386         return false;
    387     }
    388     psMetadata *cameraFormat = hdu->format; // The camera format
    389     bool mdok = true;                   // Status of MD lookup
    390     psMetadata *translation = psMetadataLookupMetadata(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec
    391     if (!mdok || !translation) {
    392         return false;
    393     }
    394 
    395     psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    396     psMetadataItem *specItem = NULL;    // Item from the specs metadata
    397     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    398         pmConceptSpec *spec = specItem->data.V; // The specification
    399         psString name = specItem->name; // The concept name
    400         psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION
    401         if (!headerItem) {
    402             continue;
    403         }
    404         if (headerItem->type == PS_DATA_METADATA) {
    405             // This is a menu
    406             psTrace("psModules.concepts", 5, "%s is of type METADATA.\n", name);
    407             headerItem = p_pmConceptsDepend(name, headerItem->data.md, translation, fpa, chip, cell);
    408             if (!headerItem) {
    409                 continue;
    410             }
    411         }
    412         if (headerItem->type != PS_DATA_STRING) {
    413             psWarning("TRANSLATION keyword for concept %s isn't of type STR --- ignored.", name);
    414             continue;
    415         }
    416         psTrace("psModules.concepts", 3, "Writing %s to header %s\n", name, headerItem->data.str);
    417         psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    418         psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
    419                                                   cameraFormat, fpa, chip, cell);
    420         if (!formatted) {
    421             continue;
    422         }
    423         writeHeader(hdu, headerItem->data.V, formatted);
    424         psFree(formatted);
    425     }
    426     psFree(specsIter);
     508#endif
     509}
     510
     511
     512bool pmConceptWriteSingle(const pmFPA *fpa, const pmChip *chip, const pmCell *cell,
     513                          pmConfig *config, const psMetadataItem *conceptItem)
     514{
     515    pmConceptsInit();
     516
     517    psMetadata *format = conceptsCameraFormat(fpa, chip, cell); // Camera format
     518    if (!format) {
     519        psError(PS_ERR_UNKNOWN, false, "Unable to retrieve camera format.");
     520        return false;
     521    }
     522
     523    const char *name = conceptItem->name; // Name of concept
     524
     525    psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications for FPA
     526    bool mdok;                          // Status of MD lookup
     527    pmConceptSpec *spec = psMetadataLookupPtr(&mdok, conceptsFPA, name); // Concept specification of interest
     528    if (!spec) {
     529        psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications for Chip
     530        spec = psMetadataLookupPtr(&mdok, conceptsChip, name);
     531        if (!spec) {
     532            psMetadata *conceptsCell = pmConceptsSpecs(PM_FPA_LEVEL_CELL); // Concept specifications for Cell
     533            spec = psMetadataLookupPtr(&mdok, conceptsCell, name);
     534            if (!spec) {
     535                psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find specification for concept %s", name);
     536                return false;
     537            }
     538        }
     539    }
     540
     541    if (!p_pmConceptWriteToCells(cell, spec, conceptItem, format) &&
     542        !p_pmConceptWriteToDefaults(fpa, chip, cell, spec, conceptItem, format, NULL) &&
     543        !p_pmConceptWriteToHeader(fpa, chip, cell, spec, conceptItem, format, NULL) &&
     544        !p_pmConceptWriteToDatabase(fpa, chip, cell, config, spec, conceptItem, format, NULL)) {
     545        return false;
     546    }
    427547    return true;
    428548}
    429 
    430 // XXX Warning: This code has not been tested at all
    431 bool p_pmConceptsWriteToDatabase(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip,
    432                                  const pmCell *cell, pmConfig *config, const psMetadata *concepts)
    433 {
    434     PS_ASSERT_PTR_NON_NULL(specs, false);
    435     PS_ASSERT_PTR_NON_NULL(concepts, false);
    436     PS_ASSERT_PTR_NON_NULL(config, false);
    437 
    438     #ifndef HAVE_PSDB
    439     return false;
    440     #else
    441 
    442     pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
    443     if (!hdu) {
    444         return false;
    445     }
    446     psMetadata *cameraFormat = hdu->format; // The camera format
    447     bool mdok = true;                   // Status of MD lookup
    448     psMetadata *database = psMetadataLookupMetadata(&mdok, cameraFormat, "DATABASE"); // The DATABASE spec
    449     if (!mdok || !database) {
    450         return false;
    451     }
    452     psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    453     psMetadataItem *specItem = NULL;    // Item from the specs metadata
    454     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    455         pmConceptSpec *spec = specItem->data.V; // The specification
    456         psString name = specItem->name; // The concept name
    457 
    458         psMetadataItem *dbItem = p_pmConceptsReadSingleFromDatabase(name, database, config, fpa, chip, cell);
    459         if (!dbItem) {
    460             continue;
    461         }
    462 
    463         psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    464         psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE,
    465                                                   cameraFormat, fpa, chip, cell);
    466         if (!formatted) {
    467             continue;
    468         }
    469 
    470         if (strcmp(dbItem->name, name) != 0) {
    471             // Correct the name to match the concept name
    472             dbItem = psMetadataItemCopy(dbItem);
    473             psFree(dbItem->name);
    474             dbItem->name = psStringCopy(name);
    475         } else {
    476             psMemIncrRefCounter(dbItem);
    477         }
    478 
    479         if (!compareConcepts(formatted, dbItem)) {
    480             psWarning("Concept %s is specified by the DATABASE in the camera "
    481                       "format, but the values don't match.\n", name);
    482         }
    483         psFree(dbItem);
    484         psFree(formatted);
    485     }
    486     psFree(specsIter);
    487     return true;
    488     #endif
    489 }
    490 
    491 
    492 
    493549
    494550
     
    498554                          const pmChip *chip, // The chip
    499555                          const pmCell *cell, // The cell
    500                           pmConceptSource source, // The source of the concepts to write
    501556                          pmConfig *config, // Configuration
    502557                          psMetadata *concepts // The concepts to write out
     
    508563    pmConceptsInit();
    509564
    510     psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p): %d\n", fpa, chip, cell, source);
    511 
    512     if (source & PM_CONCEPT_SOURCE_CELLS) {
    513         p_pmConceptsWriteToCells(*specs, cell, concepts);
    514     }
    515     if (source & PM_CONCEPT_SOURCE_DEFAULTS) {
    516         p_pmConceptsWriteToDefaults(*specs, fpa, chip, cell, concepts);
    517     }
    518     if (source & (PM_CONCEPT_SOURCE_PHU | PM_CONCEPT_SOURCE_HEADER)) {
    519         p_pmConceptsWriteToHeader(*specs, fpa, chip, cell, concepts);
    520     }
    521     if (source & PM_CONCEPT_SOURCE_DATABASE) {
    522         p_pmConceptsWriteToDatabase(*specs, fpa, chip, cell, config, concepts);
    523     }
     565    psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p)\n", fpa, chip, cell);
     566
     567    psMetadata *format = conceptsCameraFormat(fpa, chip, cell); // Camera format
     568    if (!format) {
     569        psError(PS_ERR_UNKNOWN, false, "Unable to retrieve camera format.");
     570        return false;
     571    }
     572
     573    psMetadata *defaults = conceptsDefaults(format); // DEFAULTS configuration
     574    psMetadata *translation = conceptsTranslation(format); // TRANSLATION configuration
     575    psMetadata *database = conceptsDatabase(format); // DATABASE configuration
     576
     577    psMetadataIterator *iter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator
     578    psMetadataItem *item = NULL;    // Item from the specs metadata
     579    while ((item = psMetadataGetAndIncrement(iter))) {
     580        pmConceptSpec *spec = item->data.V; // The specification
     581        psString name = item->name; // The concept name
     582
     583        psMetadataItem *concept = psMetadataLookup(concepts, name); // Concept to write
     584
     585        if (!p_pmConceptWriteToCells(cell, spec, concept, format) &&
     586            !p_pmConceptWriteToDefaults(fpa, chip, cell, spec, concept, format, defaults) &&
     587            !p_pmConceptWriteToHeader(fpa, chip, cell, spec, concept, format, translation) &&
     588            !p_pmConceptWriteToDatabase(fpa, chip, cell, config, spec, concept, format, database)) {
     589            psTrace("psModules.concepts", 1, "Unable to write concept %s to any output", name);
     590        }
     591    }
     592    psFree(iter);
    524593
    525594    return true;
     
    527596
    528597
    529 bool pmConceptsWriteFPA(const pmFPA *fpa, pmConceptSource source, bool propagateDown, pmConfig *config)
     598bool pmConceptsWriteFPA(const pmFPA *fpa, bool propagateDown, pmConfig *config)
    530599{
    531600    PS_ASSERT_PTR_NON_NULL(fpa, false);
    532601    psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
    533602    psTrace("psModules.concepts", 5, "Writing FPA concepts: %p %p\n", conceptsFPA, fpa->concepts);
    534     bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source, config, fpa->concepts);
     603    bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, config, fpa->concepts);
    535604    if (propagateDown) {
    536605        psArray *chips = fpa->chips;        // Array of chips
     
    538607            pmChip *chip = chips->data[i];  // Chip of interest
    539608            if (chip && !chip->hdu) {
    540                 success &= pmConceptsWriteChip(chip, source, false, true, config);
     609                success &= pmConceptsWriteChip(chip, false, true, config);
    541610            }
    542611        }
     
    546615
    547616
    548 bool pmConceptsWriteChip(const pmChip *chip, pmConceptSource source, bool propagateUp,
    549                          bool propagateDown, pmConfig *config)
     617bool pmConceptsWriteChip(const pmChip *chip, bool propagateUp, bool propagateDown, pmConfig *config)
    550618{
    551619    PS_ASSERT_PTR_NON_NULL(chip, false);
     
    553621    psTrace("psModules.concepts", 5, "Writing chip concepts: %p %p\n", conceptsChip, chip->concepts);
    554622    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    555     bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, source, config, chip->concepts);
     623    bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, config, chip->concepts);
    556624    if (propagateUp && !fpa->hdu) {
    557625        psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
    558         success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, source, config, fpa->concepts);
     626        success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, config, fpa->concepts);
    559627    }
    560628    if (propagateDown) {
     
    563631            pmCell *cell = cells->data[i];  // Cell of interest
    564632            if (cell && !cell->hdu) {
    565                 success &= pmConceptsWriteCell(cell, source, false, config);
     633                success &= pmConceptsWriteCell(cell, false, config);
    566634            }
    567635        }
     
    571639
    572640
    573 bool pmConceptsWriteCell(const pmCell *cell, pmConceptSource source, bool propagateUp, pmConfig *config)
     641bool pmConceptsWriteCell(const pmCell *cell, bool propagateUp, pmConfig *config)
    574642{
    575643    PS_ASSERT_PTR_NON_NULL(cell, false);
     
    579647    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    580648
    581     bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, source, config, cell->concepts);
     649    bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, config, cell->concepts);
    582650    if (propagateUp) {
    583651        if (!chip->hdu) {
    584652            psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
    585             success &= conceptsWrite(&conceptsChip, fpa, chip, cell, source, config, chip->concepts);
     653            success &= conceptsWrite(&conceptsChip, fpa, chip, cell, config, chip->concepts);
    586654            if (!fpa->hdu) {
    587655                psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
    588                 success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, source, config, fpa->concepts);
     656                success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, config, fpa->concepts);
    589657            }
    590658        }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsWrite.h

    r22699 r23594  
    2020/// @{
    2121
    22 /// "Write" concepts to (actually, check against) the camera format file's CELLS.
     22/// "Write" concept to (actually, check against) the camera format file's CELLS.
    2323///
    2424/// Examines the CELLS metadata in the camera format file for the current type of cell, and checks that the
    25 /// concepts as defined there match the ones defined in the cell.  A warning is produced if the concepts do
     25/// concept as defined there match the ones defined in the cell.  A warning is produced if the concept does
    2626/// not match.
    27 bool p_pmConceptsWriteToCells(const psMetadata *specs, ///< The concept specifications
     27bool p_pmConceptWriteToCells(const pmCell *cell, ///< The cell
     28                             const pmConceptSpec *spec, ///< Concept specification
     29                             const psMetadataItem *conceptItem, ///< Concept to write
     30                             const psMetadata *format ///< Camera format, or NULL
     31    );
     32
     33/// "Write" concept to (actually, check against) the camera format file's DEFAULTS.
     34///
     35/// Examines the DEFAULTS metadata in the camera format file, and checks that the concept as defined there
     36/// match the one defined in the cell.  A warning is produced if the concept does not match.
     37bool p_pmConceptWriteToDefaults(const pmFPA *fpa, ///< The FPA
     38                                const pmChip *chip, ///< The chip
     39                                const pmCell *cell, ///< The cell
     40                                const pmConceptSpec *spec, ///< Concept specification
     41                                const psMetadataItem *conceptItem,      ///< Concept to write
     42                                const psMetadata *format, ///< Camera format, or NULL
     43                                const psMetadata *defaults ///< DEFAULTS configuration, or NULL
     44    );
     45
     46/// "Write" concept to (actually, add to, pending a later write) the FITS header.
     47///
     48/// Examines the FITS header TRANSLATION metadata in the camera format file, and writes concept to the
     49/// appropriate FITS header(s) in the HDU, in preparation for a future write of the HDU.
     50bool p_pmConceptWriteToHeader(const pmFPA *fpa, ///< The FPA
     51                              const pmChip *chip, ///< The chip
    2852                              const pmCell *cell, ///< The cell
    29                               const psMetadata *concepts ///< The concepts
    30                              );
     53                              const pmConceptSpec *spec, ///< Concept specification
     54                              const psMetadataItem *conceptItem, ///< Concept to write
     55                              const psMetadata *format, ///< Camera format, or NULL
     56                              const psMetadata *translation ///< TRANSLATION configuration, or NULL
     57                              );
    3158
    32 /// "Write" concepts to (actually, check against) the camera format file's DEFAULTS.
     59/// Write concept to the database.
    3360///
    34 /// Examines the DEFAULTS metadata in the camera format file, and checks that the concepts as defined there
    35 /// match the ones defined in the cell.  A warning is produced if the concepts do not match.
    36 bool p_pmConceptsWriteToDefaults(const psMetadata *specs, ///< The concept specifications
    37                                  const pmFPA *fpa, ///< The FPA
    38                                  const pmChip *chip, ///< The chip
    39                                  const pmCell *cell, ///< The cell
    40                                  const psMetadata *concepts ///< The concepts
     61/// Examines the DATABASE metadata in the camera format file, and writes (actually, check against)
     62/// concept to the database.
     63bool p_pmConceptWriteToDatabase(const pmFPA *fpa, ///< The FPA
     64                                const pmChip *chip, ///< The chip
     65                                const pmCell *cell, ///< The cell
     66                                pmConfig *config, ///< Configuration
     67                                const pmConceptSpec *spec, ///< Concept specification
     68                                const psMetadataItem *conceptItem, ///< Concept to write
     69                                const psMetadata *format, ///< Camera format, or NULL
     70                                const psMetadata *database ///< DATABASE configuration, or NULL
    4171                                );
    4272
    43 /// "Write" concepts to (actually, add to, pending a later write) the FITS header.
    44 ///
    45 /// Examines the FITS header TRANSLATION metadata in the camera format file, and writes concepts to the
    46 /// appropriate FITS headers in the HDU, in preparation for a future write of the HDU.
    47 bool p_pmConceptsWriteToHeader(const psMetadata *specs, ///< The concept specifications
    48                                const pmFPA *fpa, ///< The FPA
    49                                const pmChip *chip, ///< The chip
    50                                const pmCell *cell, ///< The cell
    51                                const psMetadata *concepts ///< The concepts
    52                               );
    5373
    54 /// Write concepts to the database.
    55 ///
    56 /// Examines the DATABASE metadata in the camera format file, and writes concepts to the database.
    57 /// Warning: This function has not been tested; use at your own risk.
    58 bool p_pmConceptsWriteToDatabase(const psMetadata *specs, ///< The concept specifications
    59                                  const pmFPA *fpa, ///< The FPA
    60                                  const pmChip *chip, ///< The chip
    61                                  const pmCell *cell, ///< The cell
    62                                  pmConfig *config,///< Configuration
    63                                  const psMetadata *concepts ///< The concepts
    64                                 );
     74bool pmConceptWriteSingle(const pmFPA *fpa, ///< The FPA
     75                          const pmChip *chip, ///< The chip
     76                          const pmCell *cell, ///< The cell
     77                          pmConfig *config, ///< Configuration
     78                          const psMetadataItem *concept ///< Concept to write
     79    );
    6580
    6681
     
    7085/// written for all lower levels by iterating over the components.
    7186bool pmConceptsWriteFPA(const pmFPA *fpa,     ///< FPA for which to write concepts
    72                         pmConceptSource source, ///< Source for concepts
    7387                        bool propagateDown, ///< Propagate to lower levels?
    7488                        pmConfig *config        ///< Configuration
     
    8094/// written for the FPA, and the cell level by iterating over the components.
    8195bool pmConceptsWriteChip(const pmChip *chip,  ///< Chip for which to write concepts
    82                          pmConceptSource source, ///< Source for concepts
    8396                         bool propagateUp,///< Propagate to higher levels?
    8497                         bool propagateDown, ///< Propagate to lower levels?
     
    92105/// only the parent of this cell).
    93106bool pmConceptsWriteCell(const pmCell *cell,  ///< FPA for which to write concepts
    94                          pmConceptSource source, ///< Source for concepts
    95107                         bool propagateUp, ///< Propagate to higher levels?
    96108                         pmConfig *config ///< Configuration
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfig.c

    r23351 r23594  
    806806    pmConfigLoadRecipeOptions(argc, argv, config, "-Df");
    807807    pmConfigLoadRecipeOptions(argc, argv, config, "-Db");
     808
     809    if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) {
     810        psError(PS_ERR_IO, false, "Failed to read recipes from command-line");
     811        psFree(config);
     812        return NULL;
     813    }
    808814
    809815    // Look for command-line options for files to replace
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigCamera.c

    r23351 r23594  
    159159// Don't update these skycell concepts; last one MUST be 0 (i.e., NULL).
    160160const static char *skycellConceptsCell[] = { "CELL.BIASSEC", "CELL.TRIMSEC", "CELL.READDIR", "CELL.XPARITY",
    161                                              "CELL.YPARITY", "CELL.X0", "CELL.Y0", 0 };
     161                                             "CELL.YPARITY", "CELL.X0", "CELL.Y0", "CELL.TIMESYS", 0 };
    162162const static char *skycellConceptsChip[] = { "CHIP.XPARITY", "CHIP.YPARITY", 0 };
    163 const static char *skycellConceptsFPA[] = { 0 };
     163const static char *skycellConceptsFPA[] = { "FPA.TIMESYS" };
    164164
    165165// What do we call the skycell concept in the FITS header?
     
    332332        psMetadataAddS32(defaults, PS_LIST_TAIL, "CHIP.X0", 0, NULL, 0);
    333333        psMetadataAddS32(defaults, PS_LIST_TAIL, "CELL.READDIR", 0, "Read direction (rows)", 1);
     334        psMetadataAddStr(defaults, PS_LIST_TAIL, "CELL.TIMESYS", 0, "Time system", "TAI");
     335        psMetadataAddStr(defaults, PS_LIST_TAIL, "FPA.TIMESYS", 0, "Time system", "TAI");
    334336
    335337        psMetadataAddMetadata(format, PS_LIST_TAIL, "DEFAULTS", 0, "Default values for concepts", defaults);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigMask.c

    r21386 r23594  
    1010
    1111static pmConfigMaskInfo masks[] = {
    12     { "DETECTOR",  NULL,       0x00, true  },   // Something is wrong with the detector
    13     { "DARK",      "DETECTOR", 0x00, true  },   // Pixel doesn't dark-subtract properly
    14     { "FLAT",      "DETECTOR", 0x01, true  },   // Pixel doesn't flat-field properly
    15     { "BLANK",     "DETECTOR", 0x01, true  },   // Pixel doesn't contain valid data
    16     { "RANGE",     NULL,       0x00, true  },   // Pixel is out-of-range of linearity
    17     { "SAT",       "RANGE",    0x01, true  },   // Pixel is saturated
    18     { "BAD",       "RANGE",    0x01, true  },   // Pixel is low
    19     { "BAD.WARP",  NULL,       0x01, true  },   // Pixel is bad after convolution with a bad pixel
    20     { "CR",        NULL,       0x00, true  },   // Pixel contains a cosmic ray
    21     { "GHOST",     NULL,       0x00, true  },   // Pixel contains an optical ghost
    22     { "POOR.WARP", NULL,       0x00, false },   // Pixel is poor after convolution with a bad pixel
    23     // "LOW"  Pixel is low
    24     // "CONV" Pixel is bad after convolution with a bad pixel
     12    // Features of the detector
     13    { "DETECTOR",  NULL,       0x01, true  }, // Something is wrong with the detector
     14    { "FLAT",      "DETECTOR", 0x01, true  }, // Pixel doesn't flat-field properly
     15    { "DARK",      "DETECTOR", 0x01, true  }, // Pixel doesn't dark-subtract properly
     16    { "BLANK",     "DETECTOR", 0x01, true  }, // Pixel doesn't contain valid data
     17    { "CTE",       "DETECTOR", 0x01, true  }, // Pixel has poor CTE
     18    // Invalid signal ranges
     19    { "SAT",       NULL,       0x02, true  }, // Pixel is saturated or non-linear
     20    { "LOW",       "SAT",      0x02, true  }, // Pixel is low
     21    { "SUSPECT",   NULL,       0x04, false }, // Pixel is suspected of being bad
     22    // Non-astronomical structures
     23    { "CR",        NULL,       0x08, true  }, // Pixel contains a cosmic ray
     24    { "SPIKE",     NULL,       0x08, true  }, // Pixel contains a diffraction spike
     25    { "GHOST",     NULL,       0x08, true  }, // Pixel contains an optical ghost
     26    { "STREAK",    NULL,       0x08, true  }, // Pixel contains streak data
     27    { "STARCORE",  NULL,       0x08, true  }, // Pixel contains a bright star core
     28    // Effects of convolution and interpolation
     29    { "CONV.BAD",  NULL,       0x02, true  }, // Pixel is bad after convolution with a bad pixel
     30    { "CONV.POOR", NULL,       0x04, false }, // Pixel is poor after convolution with a bad pixel
    2531};
    2632
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigRun.c

    r23351 r23594  
    3939}
    4040
    41 
    42 bool pmConfigRunFileAdd(pmConfig *config, const pmFPAfile *file)
     41// Add a file to a nominated metadata in the RUN information
     42static bool configRunFileAdd(pmConfig *config, // Configuration
     43                             const pmFPAfile *file, // File to add
     44                             const char *target // Name of metadata to which to add
     45                             )
    4346{
    4447    PS_ASSERT_PTR_NON_NULL(config, false);
     
    4750    psMetadata *run = configRun(config);// RUN information
    4851    psAssert(run, "Require run-time information");
    49     psMetadata *files = configElement(run, "FILES", "Filerules used during execution");
     52    psMetadata *files = configElement(run, target, "Filerules used during execution");
    5053    psAssert(files, "Require list of files");
    5154
     
    7174}
    7275
    73 psArray *pmConfigRunFileGet(pmConfig *config, const char *name)
     76bool pmConfigRunFileAddRead(pmConfig *config, const pmFPAfile *file)
    7477{
    7578    PS_ASSERT_PTR_NON_NULL(config, false);
    76     PS_ASSERT_STRING_NON_EMPTY(name, false);
     79    PS_ASSERT_PTR_NON_NULL(file, false);
    7780
     81    return configRunFileAdd(config, file, "FILES.INPUT");
     82}
     83
     84bool pmConfigRunFileAddWrite(pmConfig *config, const pmFPAfile *file)
     85{
     86    PS_ASSERT_PTR_NON_NULL(config, false);
     87    PS_ASSERT_PTR_NON_NULL(file, false);
     88
     89    return configRunFileAdd(config, file, "FILES.OUTPUT");
     90}
     91
     92// Get an array of filenames from the nominated RUN information
     93static psArray *configRunFileGet(pmConfig *config, // Configuration
     94                                 const char *name, // Name of file
     95                                 const char *source // Source metadata for file
     96                                 )
     97{
    7898    psMetadata *run = configRun(config);// RUN information
    7999    psAssert(run, "Require run-time information");
    80     psMetadata *files = configElement(run, "FILES", "Filerules used during execution");
     100    psMetadata *files = configElement(run, source, "Filerules used during execution");
    81101    psAssert(files, "Require list of files");
     102
     103    if (psListLength(files->list) == 0) {
     104        // Can't find anything
     105        return NULL;
     106    }
    82107
    83108    psList *list = psListAlloc(NULL);   // List of file names
     
    104129
    105130    return array;
     131}
     132
     133
     134psArray *pmConfigRunFileGet(pmConfig *config, const char *name)
     135{
     136    PS_ASSERT_PTR_NON_NULL(config, false);
     137    PS_ASSERT_STRING_NON_EMPTY(name, false);
     138
     139    // Try the input and output, in turn
     140    psArray *files = configRunFileGet(config, name, "FILES.INPUT"); // Files from RUN metadata
     141    if (!files) {
     142        configRunFileGet(config, name, "FILES.OUTPUT");
     143    }
     144
     145    return files;
    106146}
    107147
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigRun.h

    r23351 r23594  
    66#include <pmFPAfile.h>
    77
    8 /// Add a file to the list of files used in the run-time information
    9 bool pmConfigRunFileAdd(
     8/// Add a file to the list of files read in the run-time information
     9bool pmConfigRunFileAddRead(
     10    pmConfig *config,                   ///< Configuration
     11    const pmFPAfile *file               ///< File to add
     12    );
     13
     14/// Add a file to the list of files written in the run-time information
     15bool pmConfigRunFileAddWrite(
    1016    pmConfig *config,                   ///< Configuration
    1117    const pmFPAfile *file               ///< File to add
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmDetrendDB.h

    r23351 r23594  
    6363
    6464pmDetrendSelectOptions *pmDetrendSelectOptionsAlloc(const char *camera, psTime time, pmDetrendType type);
    65 pmDetrendSelectResults *pmDetrendSelectResultsAlloc();
     65pmDetrendSelectResults *pmDetrendSelectResultsAlloc(void);
    6666pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options, const pmConfig *config);
    6767char *pmDetrendFile (const char *detID, const char *classID, const pmConfig *config);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmDetrendThreads.h

    r18893 r23594  
    1818
    1919/// get the requested number of scan rows per thread
    20 int pmDetrendGetScanRows ();
     20int pmDetrendGetScanRows(void);
    2121
    2222/// @}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmShutterCorrection.c

    r23351 r23594  
    7171}
    7272
    73 pmShutterCorrection *pmShutterCorrectionAlloc()
     73pmShutterCorrection *pmShutterCorrectionAlloc(void)
    7474{
    7575    pmShutterCorrection *corr = (pmShutterCorrection*)psAlloc(sizeof(pmShutterCorrection));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmShutterCorrection.h

    r21509 r23594  
    6969
    7070/// Allocator for shutter correction parameters
    71 pmShutterCorrection *pmShutterCorrectionAlloc();
     71pmShutterCorrection *pmShutterCorrectionAlloc(void);
    7272
    7373/// Guess a shutter correction, based on plot of counts vs exposure time
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/pmKapaPlots.c

    r13896 r23594  
    4747}
    4848
    49 bool pmKapaClose ()
     49bool pmKapaClose (void)
    5050{
    5151
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/pmKapaPlots.h

    r12696 r23594  
    11/* @file  pmKapaPlots.h
    2  * @brief functions to make plots with the external program 'kapa' 
     2 * @brief functions to make plots with the external program 'kapa'
    33 *
    44 * @author EAM, IfA
     
    1717// move to psLib or psModules
    1818int pmKapaOpen (bool showWindow);
    19 bool pmKapaClose ();
     19bool pmKapaClose(void);
    2020bool pmKapaPlotVectorPair (psVector *xVec, psVector *yVec);
    2121
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/psPipe.c

    r12888 r23594  
    3535}
    3636
    37 psPipe *psPipeAlloc ()
     37psPipe *psPipeAlloc (void)
    3838{
    3939    psPipe *pipe = (psPipe *)psAlloc(sizeof(psPipe));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/psPipe.h

    r11253 r23594  
    11/* @file  psPipe.h
    2  * @brief 3-stream pipe 
     2 * @brief 3-stream pipe
    33 *
    44 * @author EAM, IfA
     
    2626
    2727// psPipe functions
    28 psPipe *psPipeAlloc ();
     28psPipe *psPipeAlloc (void);
    2929psPipe *psPipeOpen (char *command);
    3030int     psPipeClose (psPipe *pipe);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmStack.c

    r23351 r23594  
    4646    psVector *weights;                  // Pixel weightings
    4747    psVector *sources;                  // Pixel sources (which image did they come from?)
     48    psVector *limits;                   // Rejection limits
    4849    psVector *sort;                     // Buffer for sorting (to get a robust estimator of the standard dev)
    4950} combineBuffer;
     
    5657    psFree(buffer->weights);
    5758    psFree(buffer->sources);
     59    psFree(buffer->limits);
    5860    psFree(buffer->sort);
    5961    return;
     
    7173    buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32);
    7274    buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16);
     75    buffer->limits = psVectorAlloc(numImages, PS_TYPE_F32);
    7376    buffer->sort = psVectorAlloc(numImages, PS_TYPE_F32);
    7477    return buffer;
     
    319322                          bool useVariance, // Use variance for rejection when combining?
    320323                          bool safe,    // Combine safely?
     324                          bool rejectInspect, // Reject values marked for inspection from combination?
    321325                          combineBuffer *buffer // Buffer for combination; to avoid multiple allocations
    322326                         )
     
    336340    psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest
    337341    psVector *pixelSources = buffer->sources; // Sources for the pixel of interest
     342    psVector *pixelLimits = buffer->limits; // Limits for the pixel of interest
    338343    psVector *sort = buffer->sort;      // Sort buffer
    339344
     
    375380    pixelWeights->n = num;
    376381    pixelSources->n = num;
     382    pixelLimits->n = num;
    377383
    378384#ifdef TESTING
     
    389395    // Default option is that the pixel is bad
    390396    float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map
    391     psImageMaskType maskValue = bad;         // Value for combined mask
     397    psImageMaskType maskValue = bad;    // Value for combined mask
    392398    switch (num) {
    393399      case 0:
     
    449455              if (PS_SQR(diff) > PS_SQR(rej) * sigma2) {
    450456                  // Not consistent: mark both for inspection
    451                   combineInspect(inputs, x, y, pixelSources->data.U16[0]);
    452                   combineInspect(inputs, x, y, pixelSources->data.U16[1]);
     457                  if (rejectInspect) {
     458                      imageValue = NAN;
     459                      varianceValue = NAN;
     460                      maskValue = bad;
     461                  } else {
     462                      combineInspect(inputs, x, y, pixelSources->data.U16[0]);
     463                      combineInspect(inputs, x, y, pixelSources->data.U16[1]);
     464                  }
    453465#ifdef TESTING
    454466                  if (x == TEST_X && y == TEST_Y) {
     
    501513#endif
    502514
    503                       pixelVariances->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar);
     515                      pixelLimits->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar);
    504516                  }
    505517              }
     
    541553#define MASK_PIXEL_FOR_INSPECTION() \
    542554    pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff; \
    543     combineInspect(inputs, x, y, pixelSources->data.U16[j]); \
     555    if (!rejectInspect) { \
     556        combineInspect(inputs, x, y, pixelSources->data.U16[j]); \
     557    } \
    544558    numClipped++; \
    545559    totalClipped++;
     
    553567                      // Comparing squares --- cheaper than lots of sqrts
    554568                      // pixelVariances includes the rejection limit, from above
    555                       if (PS_SQR(diff) > pixelVariances->data.F32[j]) {
     569                      if (PS_SQR(diff) > pixelLimits->data.F32[j]) {
    556570                          MASK_PIXEL_FOR_INSPECTION();
    557571#ifdef TESTING
    558572                          if (x == TEST_X && y == TEST_Y) {
    559573                              fprintf(stderr, "Rejecting input %d based on variance: %f > %f\n",
    560                                       j, diff, sqrtf(pixelVariances->data.F32[j]));
     574                                      j, diff, sqrtf(pixelLimits->data.F32[j]));
    561575                          }
    562576#endif
     
    573587              }
    574588          }
     589
     590          if (rejectInspect && totalClipped > 0) {
     591              // Get rid of the masked values
     592              // The alternative to this is to make combinationMeanVariance() accept a mask
     593              int good = 0;            // Index of good value
     594              for (int i = 0; i < num; i++) {
     595                  if (pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     596                      continue;
     597                  }
     598                  if (i != good) {
     599                      pixelData->data.F32[good] = pixelData->data.F32[i];
     600                      pixelVariances->data.F32[good] = pixelVariances->data.F32[i];
     601                      pixelWeights->data.F32[good] = pixelWeights->data.F32[i];
     602                      pixelData->data.F32[good] = pixelData->data.F32[i];
     603                  }
     604                  good++;
     605              }
     606              pixelData->n = good;
     607              pixelVariances->n = good;
     608              pixelWeights->n = good;
     609              if (combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) {
     610                  imageValue = mean;
     611                  varianceValue = var;
     612                  maskValue = 0;
     613              } else {
     614                  imageValue = NAN;
     615                  varianceValue = NAN;
     616                  maskValue = bad;
     617              }
     618          }
     619
    575620          break;
    576621      }
     
    734779bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad,
    735780                    int kernelSize, int numIter, float rej, float sys, float discard,
    736                     bool entire, bool useVariance, bool safe)
     781                    bool entire, bool useVariance, bool safe, bool rejectInspect)
    737782{
    738783    PS_ASSERT_PTR_NON_NULL(combined, false);
     
    838883                    combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    839884                                  addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    840                                   useVariance, safe, buffer);
     885                                  useVariance, safe, rejectInspect, buffer);
    841886                }
    842887            }
     
    853898                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    854899                              addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    855                               useVariance, safe, buffer);
     900                              useVariance, safe, rejectInspect, buffer);
    856901            }
    857902        }
     
    881926                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    882927                              addVariance, NULL, x, y, maskVal, bad, numIter, rej, sys, discard,
    883                               useVariance, safe, buffer);
     928                              useVariance, safe, rejectInspect, buffer);
    884929            }
    885930        }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmStack.h

    r21476 r23594  
    5252                    bool entire,        ///< Combine entire image even if rejection lists provided?
    5353                    bool useVariance,   ///< Use variance values for rejection?
    54                     bool safe           ///< Play safe with small numbers of input pixels (mask if N <= 2)?
     54                    bool safe,          ///< Play safe with small numbers of input pixels (mask if N <= 2)?
     55                    bool rejectInspect  ///< Reject pixels instead of marking them for inspection?
    5556    );
    5657
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionIO.c

    r23351 r23594  
    44
    55#include "pmHDU.h"
     6#include "pmHDUUtils.h"
    67#include "pmFPA.h"
    78#include "pmFPAview.h"
     
    143144    psMetadata *header = psMetadataAlloc(); // Header for FITS file
    144145
     146    pmCell *cell = ro->parent;          // Cell of interest
     147    if (cell) {
     148        pmChip *chip = cell->parent;    // Chip of interest
     149        pmFPA *fpa = chip->parent;      // FPA of interest
     150        pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // HDU for readout
     151        if (hdu) {
     152            header = psMetadataCopy(header, hdu->header);
     153        }
     154    }
     155
    145156    // CVS tags, used to identify the version of this file (in case incompatibilities are introduced)
    146157    psString cvsFile = psStringCopy("$RCSfile: pmSubtractionIO.c,v $");
     
    533544        return true;
    534545    }
    535     if (file->fileLevel != PM_FPA_LEVEL_FPA) {
    536         return true;
    537     }
    538     if (file->fpa->chips->n == 1) {
    539         return true;
    540     }
    541546
    542547    // find the FPA phu
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionVisual.c

    r23351 r23594  
    4444
    4545/** destroy windows at the end of a run*/
    46 bool pmSubtractionVisualClose()
     46bool pmSubtractionVisualClose(void)
    4747{
    4848    if(kapa != -1)
     
    256256
    257257#else
    258 bool pmSubtractionVisualClose() {return true;}
     258bool pmSubtractionVisualClose(void) {return true;}
    259259bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {return true;}
    260260bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) {return true;}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionVisual.h

    r23351 r23594  
    22#define PM_SUBTRACTION_VISUAL_H
    33
    4 bool pmSubtractionVisualClose();
     4bool pmSubtractionVisualClose(void);
    55bool pmSubtractionVisualPlotConvKernels(psImage *convKernels);
    66bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmDetections.c

    r18828 r23594  
    3030
    3131// generate a pmDetections container with empty (allocated) footprints and peaks containers
    32 pmDetections *pmDetectionsAlloc() {
     32pmDetections *pmDetectionsAlloc(void) {
    3333
    3434    pmDetections *detections = (pmDetections *)psAlloc(sizeof(pmDetections));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmDetections.h

    r18828 r23594  
    2020 */
    2121typedef struct {
    22   psArray *footprints;        // collection of footprints in the image
    23   psArray *peaks;             // collection of all peaks contained by the footprints
    24   psArray *oldPeaks;          // collection of all peaks previously found
     22  psArray *footprints;        // collection of footprints in the image
     23  psArray *peaks;             // collection of all peaks contained by the footprints
     24  psArray *oldPeaks;          // collection of all peaks previously found
    2525  int last;
    2626} pmDetections;
    2727
    28 pmDetections *pmDetectionsAlloc ();
     28pmDetections *pmDetectionsAlloc (void);
    2929
    3030/// @}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmMoments.c

    r23351 r23594  
    2525to zero.
    2626*****************************************************************************/
    27 pmMoments *pmMomentsAlloc()
     27pmMoments *pmMomentsAlloc(void)
    2828{
    2929    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmMoments.h

    r19879 r23594  
    5353 *
    5454 */
    55 pmMoments *pmMomentsAlloc();
     55pmMoments *pmMomentsAlloc(void);
    5656
    5757/// @}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmPSF.c

    r20937 r23594  
    5454}
    5555
    56 pmPSFOptions *pmPSFOptionsAlloc () {
     56pmPSFOptions *pmPSFOptionsAlloc (void) {
    5757
    5858    pmPSFOptions *options = (pmPSFOptions *) psAlloc(sizeof(pmPSFOptions));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmPSF.h

    r21183 r23594  
    9696pmPSF *pmPSFAlloc (const pmPSFOptions *options);
    9797bool psMemCheckPSF(psPtr ptr);
    98 pmPSFOptions *pmPSFOptionsAlloc();
     98pmPSFOptions *pmPSFOptionsAlloc(void);
    9999bool psMemCheckPSFOptions(psPtr ptr);
    100100
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSource.h

    r23351 r23594  
    105105 *
    106106 */
    107 pmSource  *pmSourceAlloc();
     107pmSource  *pmSourceAlloc(void);
    108108
    109109/** pmSourceCopy()
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceExtendedPars.c

    r21363 r23594  
    4646}
    4747
    48 pmSourceExtendedPars *pmSourceExtendedParsAlloc () {
     48pmSourceExtendedPars *pmSourceExtendedParsAlloc (void) {
    4949    pmSourceExtendedPars *pars = (pmSourceExtendedPars *) psAlloc(sizeof(pmSourceExtendedPars));
    5050    psMemSetDeallocator(pars, (psFreeFunc) pmSourceExtendedParsFree);
     
    7575}
    7676
    77 pmSourceRadialProfile *pmSourceRadialProfileAlloc () {
     77pmSourceRadialProfile *pmSourceRadialProfileAlloc (void) {
    7878
    7979    pmSourceRadialProfile *profile = (pmSourceRadialProfile *) psAlloc(sizeof(pmSourceRadialProfile));
     
    9999}
    100100
    101 pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc () {
     101pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc (void) {
    102102
    103103    pmSourceIsophotalValues *isophot = (pmSourceIsophotalValues *) psAlloc(sizeof(pmSourceIsophotalValues));
     
    125125}
    126126
    127 pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc () {
     127pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc (void) {
    128128
    129129    pmSourcePetrosianValues *petrosian = (pmSourcePetrosianValues *) psAlloc(sizeof(pmSourcePetrosianValues));
     
    150150}
    151151
    152 pmSourceKronValues *pmSourceKronValuesAlloc () {
     152pmSourceKronValues *pmSourceKronValuesAlloc (void) {
    153153
    154154    pmSourceKronValues *kron = (pmSourceKronValues *) psAlloc(sizeof(pmSourceKronValues));
     
    181181}
    182182
    183 pmSourceAnnuli *pmSourceAnnuliAlloc () {
     183pmSourceAnnuli *pmSourceAnnuliAlloc (void) {
    184184
    185185    pmSourceAnnuli *annuli = (pmSourceAnnuli *) psAlloc(sizeof(pmSourceAnnuli));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceExtendedPars.h

    r21363 r23594  
    5555} pmSourceExtendedPars;
    5656
    57 pmSourceExtendedPars *pmSourceExtendedParsAlloc ();
     57pmSourceExtendedPars *pmSourceExtendedParsAlloc(void);
    5858bool psMemCheckSourceExtendedPars(psPtr ptr);
    59 pmSourceRadialProfile *pmSourceRadialProfileAlloc ();
     59pmSourceRadialProfile *pmSourceRadialProfileAlloc(void);
    6060bool psMemCheckSourceRadialProfile(psPtr ptr);
    61 pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc ();
     61pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc(void);
    6262bool psMemCheckSourceIsophotalValues(psPtr ptr);
    63 pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc ();
     63pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc(void);
    6464bool psMemCheckSourcePetrosianValues(psPtr ptr);
    65 pmSourceKronValues *pmSourceKronValuesAlloc ();
     65pmSourceKronValues *pmSourceKronValuesAlloc(void);
    6666bool psMemCheckSourceKronValues(psPtr ptr);
    67 pmSourceAnnuli *pmSourceAnnuliAlloc ();
     67pmSourceAnnuli *pmSourceAnnuliAlloc(void);
    6868bool psMemCheckSourceAnnuli(psPtr ptr);
    6969
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceFitSet.c

    r23351 r23594  
    6767}
    6868
    69 void pmSourceFitSetDone () {
     69void pmSourceFitSetDone (void) {
    7070    psFree (fitSets);
    7171}
     
    150150}
    151151
    152 pmSourceFitSetData *pmSourceFitSetDataGet () {
     152pmSourceFitSetData *pmSourceFitSetDataGet (void) {
    153153
    154154    psAssert (fitSets, "pmSourceFitSetInit not called");
     
    172172}
    173173
    174 void pmSourceFitSetDataClear () {
     174void pmSourceFitSetDataClear (void) {
    175175
    176176    int i;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceFitSet.h

    r21183 r23594  
    2424// use this function to init the fit sets based on the number of threads
    2525bool pmSourceFitSetInit (int nThreads);
    26 void pmSourceFitSetDone ();
     26void pmSourceFitSetDone (void);
    2727
    2828// initialize data for a group of object models
     
    3232// functions for selecting the FitSet corresponding to the current thread
    3333pmSourceFitSetData *pmSourceFitSetDataSet (psArray *modelSet);
    34 pmSourceFitSetData *pmSourceFitSetDataGet ();
    35 void pmSourceFitSetDataClear ();
     34pmSourceFitSetData *pmSourceFitSetDataGet (void);
     35void pmSourceFitSetDataClear (void);
    3636
    3737// function used to set limits for a group of models
     
    5454 */
    5555bool pmSourceFitSet(
    56     pmSource *source,                   ///< The input pmSource
    57     psArray *modelSet,                  ///< model to be fitted
    58     pmSourceFitMode mode,               ///< define parameters to be fitted
    59     psImageMaskType maskVal             ///< Vale to mask
     56    pmSource *source,                   ///< The input pmSource
     57    psArray *modelSet,                  ///< model to be fitted
     58    pmSourceFitMode mode,               ///< define parameters to be fitted
     59    psImageMaskType maskVal             ///< Vale to mask
    6060
    6161);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourcePlots.c

    r19849 r23594  
    139139}
    140140
    141 pmSourcePlotLayout *pmSourcePlotLayoutAlloc()
     141pmSourcePlotLayout *pmSourcePlotLayoutAlloc(void)
    142142{
    143143    pmSourcePlotLayout *layout = (pmSourcePlotLayout *)psAlloc(sizeof(pmSourcePlotLayout));
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourcePlots.h

    r15562 r23594  
    2929// typedef bool (*pmSourcePlotFunction)(pmConfig *config, pmFPAview *view, pmSourcePlotLayout *layout);
    3030
    31 pmSourcePlotLayout *pmSourcePlotLayoutAlloc();
     31pmSourcePlotLayout *pmSourcePlotLayoutAlloc(void);
    3232bool psMemCheckSourcePlotLayout(psPtr ptr);
    3333
Note: See TracChangeset for help on using the changeset viewer.