IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7311


Ignore:
Timestamp:
Jun 2, 2006, 3:02:08 PM (20 years ago)
Author:
Paul Price
Message:

Applying RHL patch. Generally improves the error handling and traceback. pmConcepts.c and pmConceptsRead.c done by PAP (RHL did this also, but I had already done them). Resolved conflicts, except for pmFPAfile.c, which uses psAbort in some instances where RHL's patch had psError; leave this for Gene to decide.

Location:
trunk/psModules/src
Files:
28 edited

Legend:

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

    r7278 r7311  
    2626    bool status = true;                 // Result of MD lookup
    2727    psMetadata *cells = psMetadataLookupMD(&status, format, "CELLS"); // The CELLS
    28     if (! status) {
    29         psError(PS_ERR_IO, false, "Unable to determine CELLS of camera.\n");
     28    if (!status || !cells) {
     29        psError(PS_ERR_IO, true, "Unable to determine CELLS of camera.\n");
    3030        return NULL;
    3131    }
     
    114114    }
    115115    psMetadataItem *resultItem = psMetadataLookup(header, keyword);
    116     if (! resultItem) {
    117         psError(PS_ERR_IO, false, "Unable to find %s in primary header to identify %s.\n", keyword, name);
     116    if (!resultItem) {
     117        psError(PS_ERR_IO, true, "Unable to find %s in primary header to identify %s.\n", keyword, name);
    118118        return NULL;
    119119    }
     
    138138    fpa->hdu = psMemIncrRefCounter(hdu);
    139139    if (hdu->header) {
    140         pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL);
     140        if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL)) {
     141            psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for FPA");
     142            return false;
     143        }
    141144    }
    142145    pmFPASetFileStatus(fpa, true);
     
    256259
    257260    if (hdu && level == PM_FPA_LEVEL_FPA) {
    258         addHDUtoFPA(fpa, hdu);
     261        if (!addHDUtoFPA(fpa, hdu)) {
     262            psError(PS_ERR_UNKNOWN, false, "Adding HDU to FPA (%s)", contents);
     263            return -1;
     264        }
    259265    }
    260266
     
    333339        }
    334340        newCell->config = psMemIncrRefCounter(cellData);
    335         pmConceptsReadCell(newCell, PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS, false, NULL);
     341        if (!pmConceptsReadCell(newCell, PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS, false, NULL)) {
     342            psError(PS_ERR_IO, false, "Reading concepts for cell %d", numCells);
     343            return -1;
     344        }
    336345        numCells++;
    337346    }
     
    388397    bool mdok = true;                   // Status from MD lookups
    389398    psMetadata *components = psMetadataLookupMD(&mdok, camera, "FPA"); // FPA components
     399    if (!mdok || !components) {
     400        psError(PS_ERR_IO, true, "Failed to lookup \"FPA\"");
     401        psFree(fpa);
     402        return NULL;
     403    }
    390404    psMetadataIterator *componentsIter = psMetadataIteratorAlloc(components, PS_LIST_HEAD, NULL);
    391405    psMetadataItem *componentsItem = NULL; // Item from components
     
    500514        hdu->format = psMemIncrRefCounter(format);
    501515        const char *content = contentsItem->data.V; // The content data
    502         processContents(fpa, chip, cell, hdu, level, content, format);
     516        if (processContents(fpa, chip, cell, hdu, level, content, format) < 0) {
     517            psError(PS_ERR_IO, false, "Error setting contents for %s", contentsItem->name);
     518            psFree(hdu);
     519            psFree(contentsIter);
     520
     521            return false;
     522        }
    503523        psFree(hdu);
    504524    }
     
    568588        if (!mdok || !contents || strlen(contents) == 0) {
    569589            psError(PS_ERR_IO, true, "Unable to find CONTENTS in the camera format configuration.\n");
     590            psFree(phdu);
    570591            psFree(view);
    571592            return NULL;
    572593        }
    573594
    574         processContents(fpa, NULL, NULL, phdu, PM_FPA_LEVEL_FPA, contents, format);
     595        if (processContents(fpa, NULL, NULL, phdu, PM_FPA_LEVEL_FPA, contents, format) < 0) {
     596            psError(PS_ERR_IO, false, "Error setting CONTENTS");
     597            psFree(phdu);
     598            psFree(view);
     599
     600            return NULL;
     601        }
     602
    575603        psFree(phdu);
    576604        return view;
     
    581609    psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file
    582610    if (!mdok || !contents) {
    583         psError(PS_ERR_IO, false, "Unable to find CONTENTS in the camera format configuration.\n");
     611        if (mdok && !contents) {
     612            psError(PS_ERR_IO, true, "CONTENTS metadata is NULL in the camera format configuration.");
     613        } else {
     614            if(psMetadataLookup(format, "CONTENTS") != NULL) {
     615                psError(PS_ERR_IO, true, "CONTENTS is of wrong type in camera format configuration");
     616            } else {
     617                psError(PS_ERR_IO, true, "Unable to find CONTENTS in the camera format configuration.");
     618            }
     619        }
     620
    584621        psFree(view);
    585622        return NULL;
  • trunk/psModules/src/camera/pmFPARead.c

    r7278 r7311  
    3535    if (psRegionIsBad(*trimsec)) {
    3636        psString regionString = psRegionToString(*trimsec);
    37         psError(PS_ERR_IO, true, "Invalid trim section: %s\n", regionString);
     37        psError(PS_ERR_UNKNOWN, true, "Invalid trim section: %s\n", regionString);
    3838        psFree(regionString);
    3939        psFree(readout);
     
    319319    }
    320320    if (!hdu->images && !pmHDURead(hdu, fits)) {
    321         psError(PS_ERR_IO, false, "Unable to read HDU for cell.\n");
    322         return false;
    323     }
    324 
    325     pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL);
     321        psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
     322        return false;
     323    }
     324
     325    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL)) {
     326        psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
     327        return false;
     328    }
    326329
    327330    // Having read the cell, we now have to cut it up
     
    397400        pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL);
    398401    } else {
    399         psLogMsg(__func__, PS_LOG_WARN, "Unable to read any chips in FPA.\n");
     402        psError(PS_ERR_UNKNOWN, false, "Unable to read any chips in FPA");
    400403    }
    401404
  • trunk/psModules/src/camera/pmFPA_JPEG.c

    r7278 r7311  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-06-02 00:55:22 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-06-03 01:02:08 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    141141
    142142        // XXX we need to decide where the scale will come from in the long term
    143         psImageClippedStatsInit (10000);
     143        unsigned long seed = 0;
     144        psImageClippedStatsInit (10000, seed);
    144145
    145146        psStats *stats = psImageClippedStats (readout->image, NULL, 0, 0.25, 0.75);
  • trunk/psModules/src/camera/pmFPAfile.c

    r7307 r7311  
    2121#include "pmPSF_IO.h"
    2222#include "pmFPA_JPEG.h"
     23#define WERROR 0                        // if true, warnings in this file are treated as errors
    2324
    2425static void pmFPAfileFree(pmFPAfile *file)
     
    8485    return file;
    8586}
     87
     88static const char *depthEnumToName(pmFPAdepth depth)
     89{
     90    const char *val = NULL;
     91
     92    switch (depth) {
     93    case PM_FPA_DEPTH_NONE:
     94        val = "NONE";
     95        break;
     96    case PM_FPA_DEPTH_FPA:
     97        val = "FPA";
     98        break;
     99    case PM_FPA_DEPTH_CHIP:
     100        val = "CHIP";
     101        break;
     102    case PM_FPA_DEPTH_CELL:
     103        val = "CELL";
     104        break;
     105    case PM_FPA_DEPTH_READOUT:
     106        val = "READOUT";
     107        break;
     108    default:
     109        psAbort(PS_FILE_LINE, "You can't get here; depth = %d", depth);
     110    }
     111
     112    return val;
     113}
     114
     115static pmFPAdepth depthNameToEnum(const char *name)
     116{
     117    pmFPAdepth val;
     118
     119    if (name == NULL) {
     120        val = PM_FPA_DEPTH_NONE;
     121    } else if (!strcasecmp(name, "FPA"))     {
     122        val = PM_FPA_DEPTH_FPA;
     123    } else if (!strcasecmp(name, "CHIP"))    {
     124        val = PM_FPA_DEPTH_CHIP;
     125    } else if (!strcasecmp(name, "CELL"))    {
     126        val = PM_FPA_DEPTH_CELL;
     127    } else if (!strcasecmp(name, "READOUT")) {
     128        val = PM_FPA_DEPTH_READOUT;
     129    } else {
     130        val = PM_FPA_DEPTH_NONE;
     131    }
     132
     133    return val;
     134}
     135
    86136
    87137pmFPAfile *pmFPAfileDefine(psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name)
     
    94144
    95145    bool status;
    96     char *depth;
    97146    char *type;
    98147
     
    100149    psMetadata *filerules = psMetadataLookupPtr (&status, camera, "FILERULES");
    101150    if (filerules == NULL) {
    102         psErrorStackPrint(stderr, "Can't find FILERULES in the CAMERA configuration!\n");
     151        psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!");
    103152        return NULL;
    104153    }
     
    107156    // check for alias name (type == STR, name is aliased name)
    108157    char *realname = psMetadataLookupStr (&status, filerules, name);
    109     if (realname == NULL)
     158    if (!realname || strlen(realname) == 0) {
    110159        realname = name;
     160    }
    111161
    112162    psMetadata *data = psMetadataLookupPtr (&status, filerules, realname);
    113163    if (data == NULL) {
    114         psErrorStackPrint(stderr, "Can't find file concept %s!\n", name);
     164        psError(PS_ERR_IO, true, "Can't find file concept %s!", name);
    115165        return NULL;
    116166    }
     
    126176    file->extxtra  = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "EXTNAME.XTRA"));
    127177
    128     file->fileDepth = PM_FPA_DEPTH_NONE;
    129     depth = psMetadataLookupStr (&status, data, "FILE.DEPTH");
    130     if (depth != NULL) {
    131         if (!strcasecmp (depth, "FPA"))     {
    132             file->fileDepth = PM_FPA_DEPTH_FPA;
    133         }
    134         if (!strcasecmp (depth, "CHIP"))    {
    135             file->fileDepth = PM_FPA_DEPTH_CHIP;
    136         }
    137         if (!strcasecmp (depth, "CELL"))    {
    138             file->fileDepth = PM_FPA_DEPTH_CELL;
    139         }
    140         if (!strcasecmp (depth, "READOUT")) {
    141             file->fileDepth = PM_FPA_DEPTH_READOUT;
    142         }
    143     }
     178    file->fileDepth = depthNameToEnum(psMetadataLookupStr(&status, data, "FILE.DEPTH"));
    144179    if (file->fileDepth == PM_FPA_DEPTH_NONE) {
    145180        psLogMsg (__func__, 3, "warning: FILE.DEPTH is not set for %s\n", name);
    146181    }
    147182
    148     file->dataDepth = PM_FPA_DEPTH_NONE;
    149     depth = psMetadataLookupStr (&status, data, "DATA.DEPTH");
    150     if (depth != NULL) {
    151         if (!strcasecmp (depth, "FPA"))     {
    152             file->dataDepth = PM_FPA_DEPTH_FPA;
    153         }
    154         if (!strcasecmp (depth, "CHIP"))    {
    155             file->dataDepth = PM_FPA_DEPTH_CHIP;
    156         }
    157         if (!strcasecmp (depth, "CELL"))    {
    158             file->dataDepth = PM_FPA_DEPTH_CELL;
    159         }
    160         if (!strcasecmp (depth, "READOUT")) {
    161             file->dataDepth = PM_FPA_DEPTH_READOUT;
    162         }
    163     }
     183    file->dataDepth = depthNameToEnum(psMetadataLookupStr (&status, data, "DATA.DEPTH"));
    164184    if (file->dataDepth == PM_FPA_DEPTH_NONE) {
    165185        psLogMsg (__func__, 3, "warning: DATA.DEPTH is not set for %s\n", name);
     
    240260    pmFPAfile *file = pmFPAfileDefine (files, format, fpa, name);
    241261    psFree (fpa);
     262    if (!file) {
     263        psErrorStackPrint(stderr, "file %s not defined\n", name);
     264        return NULL;
     265    }
    242266    return file;
    243267}
     
    257281
    258282    if (file->state & PM_FPA_STATE_INACTIVE) {
     283        psError(PS_ERR_IO, true, "Atempted to read an inactive file");
    259284        return false;
    260285    }
     
    265290
    266291    if (file->mode == PM_FPA_MODE_NONE) {
     292        psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_NONE");
    267293        return false;
    268294    }
    269295    if (file->mode == PM_FPA_MODE_INTERNAL) {
     296        psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_INTERNAL");
    270297        return false;
    271298    }
     
    279306    // determine the file name
    280307    file->filename = pmFPAfileNameFromRule (file->filerule, file, view);
    281     if (file->filename == NULL)
    282         return false;
     308    if (file->filename == NULL) {
     309        psError(PS_ERR_IO, true, "Filename is NULL");
     310        return false;
     311    }
    283312
    284313    // indirect filenames
     
    288317        file->filename = psMetadataLookupStr (&status, file->names, extra);
    289318        psFree (extra);
    290         if (file->filename == NULL)
     319        if (file->filename == NULL) {
    291320            psAbort ("pmFPAfile", "no file specified");
     321        }
    292322        // psMetadataLookupStr just returns a view, file->filename must be protected
    293323        psMemIncrRefCounter (file->filename);
     
    298328        // file->filename = pmDetrendSelect (extra);
    299329        psFree (extra);
    300         if (file->filename == NULL)
     330        if (file->filename == NULL) {
    301331            psAbort ("pmFPAfile", "no file specified");
     332        }
    302333        psMemIncrRefCounter (file->filename);
    303334    }
     
    309340        psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
    310341        file->fits = psFitsOpen (file->filename, mode);
    311         if (file->fits == NULL)
    312             psAbort (__func__, "error opening file %s\n", file->filename);
     342        if (file->fits == NULL) {
     343            psError(PS_ERR_IO, false, "error opening file %s\n", file->filename);
     344            return false;
     345        }
    313346        file->state = PM_FPA_STATE_OPEN;
    314347        break;
     
    325358
    326359    default:
    327         fprintf (stderr, "warning: type mismatch for %s : %d\n", file->filename, file->type);
     360        psError(PS_ERR_IO, true, "type mismatch for %s : %d\n", file->filename, file->type);
    328361        return false;
    329362    }
     
    336369    PS_ASSERT_PTR_NON_NULL(view, false);
    337370
    338     if (file->state & PM_FPA_STATE_INACTIVE)
    339         return false;
    340 
    341     if (file->mode != PM_FPA_MODE_READ)
    342         return false;
     371    if (file->state & PM_FPA_STATE_INACTIVE) {
     372        psError(PS_ERR_IO, true, "Atempted to read an inactive file");
     373        return false;
     374    }
     375
     376    if (file->mode != PM_FPA_MODE_READ) {
     377        psError(PS_ERR_IO, true, "File isn't mode PM_FPA_MODE_READ");
     378        return false;
     379    }
    343380
    344381    // get the current depth
     
    347384    // do we need to open this file?
    348385    if (depth == file->fileDepth) {
    349         pmFPAfileOpen (file, view);
     386        if (!pmFPAfileOpen (file, view)) {
     387            psError(PS_ERR_IO, false, "Opening file");
     388            return false;
     389        }
    350390    }
    351391
    352392    // do we need to read this file?
    353     if (depth != file->dataDepth)
    354         return false;
     393    if (depth != file->dataDepth) {
     394        #if WERROR
     395        psError(PS_ERR_IO, true, "Desired depth %s doesn't match dataDepth %s",
     396                depthEnumToName(depth), depthEnumToName(file->dataDepth));
     397        return false;
     398        #else
     399
     400        return true;
     401        #endif
     402
     403    }
    355404
    356405    switch (file->type) {
     
    359408            psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
    360409        } else {
    361             psTrace ("pmFPAfile", 5, "skipping %s (type: %d)\n", file->filename, file->type);
     410            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
     411            return false;
    362412        }
    363413        break;
     
    381431
    382432    default:
    383         fprintf (stderr, "warning: type mismatch\n");
     433        psError(PS_ERR_IO, true, "warning: type mismatch; saw type %d", file->type);
    384434        return false;
    385435    }
     
    393443
    394444    if (file->state & PM_FPA_STATE_INACTIVE) {
     445        psError(PS_ERR_IO, true, "Atempted to write an inactive file");
    395446        return false;
    396447    }
    397448
    398449    if (file->mode != PM_FPA_MODE_WRITE) {
     450        psError(PS_ERR_IO, true, "File isn't mode PM_FPA_MODE_WRITE");
    399451        return false;
    400452    }
     
    404456
    405457    // do we need to write this file?
    406     if (depth != file->dataDepth)
    407         return false;
     458    if (depth != file->dataDepth) {
     459        #if WERROR
     460        psError(PS_ERR_IO, true, "Desired depth %s doesn't match dataDepth %s",
     461                depthEnumToName(depth), depthEnumToName(file->dataDepth));
     462        return false;
     463        #else
     464
     465        return true;
     466        #endif
     467
     468    }
    408469
    409470    // do we need to open this file?
    410471    if (depth >= file->fileDepth) {
    411         pmFPAfileOpen (file, view);
     472        if (!pmFPAfileOpen (file, view)) {
     473            psError(PS_ERR_IO, false, "failed to open %s", file->filename);
     474            return false;
     475        }
    412476    }
    413477
     
    423487    case PM_FPA_FILE_CMP:
    424488    case PM_FPA_FILE_CMF:
    425         pmFPAviewWriteObjects (view, file);
    426         psTrace ("pmFPAfile", 5, "wrote object %s (fpa: %p)\n", file->filename, file->fpa);
     489        psTrace ("pmFPAfile", 5, "writing object %s (fpa: %p)\n", file->filename, file->fpa);
     490        if (!pmFPAviewWriteObjects (view, file)) {
     491            psError(PS_ERR_IO, false, "Failed to write object %s", file->filename);
     492            return false;
     493        }
     494
    427495        break;
    428496
     
    451519
    452520    if (file->state & PM_FPA_STATE_INACTIVE) {
    453         return false;
    454     }
    455     if (file->mode != PM_FPA_MODE_WRITE)
    456         return false;
     521        psError(PS_ERR_IO, true, "Atempted to create an inactive file");
     522        return false;
     523    }
     524    if (file->mode != PM_FPA_MODE_WRITE) {
     525        psError(PS_ERR_IO, true, "File isn't mode PM_FPA_MODE_WRITE");
     526        return false;
     527    }
    457528
    458529    // get the current depth
    459530    pmFPAdepth depth = pmFPAviewDepth (view);
    460531
     532    // XXX is this a sufficient check to avoid creating elements?
     533    if (file->src == NULL) {
     534        #if WERROR
     535        psError(PS_ERR_IO, true, "file->src is NULL");
     536        return false;
     537        #else
     538
     539        return true;
     540        #endif
     541
     542    }
     543
    461544    // do we need to write this file?
    462     if (depth != file->dataDepth)
    463         return false;
    464 
    465     // XXX is this a sufficient check to avoid creating elements?
    466     if (file->src == NULL)
    467         return false;
     545    if (depth != file->dataDepth) {
     546        psError(PS_ERR_IO, true, "Desired depth %s doesn't match dataDepth %s",
     547                depthEnumToName(depth), depthEnumToName(file->dataDepth));
     548        return false;
     549    }
    468550
    469551    switch (file->type) {
     
    484566
    485567    default:
    486         fprintf (stderr, "warning: type mismatch\n");
     568        psError(PS_ERR_IO, true, "Unsupported type: %d", file->type);
    487569        return false;
    488570    }
     
    496578
    497579    if (file->state & PM_FPA_STATE_INACTIVE) {
     580        psError(PS_ERR_IO, true, "Atempted to close an inactive file");
    498581        return false;
    499582    }
     
    505588    pmFPAdepth depth = pmFPAviewDepth (view);
    506589    if (file->fileDepth != depth) {
    507         return false;
     590        #if WERROR
     591        psError(PS_ERR_IO, true, "Desired depth %s doesn't match fileDepth %s",
     592                depthEnumToName(depth), depthEnumToName(file->fileDepth));
     593        return false;
     594        #else
     595
     596        return true;
     597        #endif
     598
    508599    }
    509600
     
    531622
    532623    default:
    533         fprintf (stderr, "warning: type mismatch\n");
     624        psError(PS_ERR_IO, true, "type mismatch: %d", file->type);
    534625        return false;
    535626    }
     
    560651    bool status = false;
    561652    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     653    if (!status) {
     654        psError(PS_ERR_IO, true, "Failed to look up file %s", name);
     655        return false;
     656    }
    562657    if (!file) {
     658        psError(PS_ERR_IO, true, "file %s is NULL", name);
    563659        return false;
    564660    }
     
    583679        pmFPAfile *file = item->data.V;
    584680
    585         if (place == PM_FPA_BEFORE) {
    586             pmFPAfileRead (file, view);
    587             pmFPAfileCreate (file, view);
    588         } else {
    589             pmFPAfileWrite (file, view);
    590             pmFPAfileClose (file, view);
     681        switch (place) {
     682        case PM_FPA_BEFORE:
     683            if (file->mode == PM_FPA_MODE_READ && !pmFPAfileRead (file, view)) {
     684                psError(PS_ERR_IO, false, "failed in FPA_BEFORE block for %s", file->name);
     685                psFree(iter);
     686                return false;
     687            }
     688            if (file->mode == PM_FPA_MODE_WRITE && !pmFPAfileCreate(file, view)) {
     689                psError(PS_ERR_IO, false, "failed in FPA_BEFORE block for %s", file->name);
     690                psFree(iter);
     691                return false;
     692            }
     693            break;
     694        case PM_FPA_AFTER:
     695            if (file->mode == PM_FPA_MODE_WRITE && !pmFPAfileWrite (file, view)) {
     696                psError(PS_ERR_IO, false, "failed in FPA_AFTER block for %s", file->name);
     697                psFree(iter);
     698                return false;
     699            }
     700            if (!pmFPAfileClose(file, view)) {
     701                psError(PS_ERR_IO, false, "failed in FPA_AFTER block for %s", file->name);
     702                psFree(iter);
     703                return false;
     704            }
     705            break;
     706        default:
     707            psAbort(PS_FILE_LINE, "You can't get here");
    591708        }
    592709    }
    593710    psFree (iter);
     711
    594712    return true;
    595713}
     
    627745
    628746    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    629     if (file == NULL)
    630         return false;
    631 
    632     if (file->mode != PM_FPA_MODE_INTERNAL)
    633         return false;
     747    if (file == NULL) {
     748        psError(PS_ERR_IO, true, "Failed to lookup %s", name);
     749        return false;
     750    }
     751
     752    if (file->mode != PM_FPA_MODE_INTERNAL) {
     753        psError(PS_ERR_IO, true, "File %s has mode %d != PM_FPA_MODE_INTERNAL", name, file->mode);
     754        return false;
     755    }
    634756
    635757    psMetadataRemoveKey (files, name);
     
    648770
    649771    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    650     if (file == NULL)
    651         return NULL;
     772    if (file == NULL) {
     773        return NULL;
     774    }
    652775
    653776    // internal files have the readout as a separate element:
     
    677800
    678801    if (view->chip >= fpa->chips->n) {
     802        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
    679803        return false;
    680804    }
     
    687811
    688812    if (view->cell >= chip->cells->n) {
     813        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
    689814        return false;
    690815    }
     
    695820        return status;
    696821    }
     822    psError(PS_ERR_UNKNOWN, true, "Returning false");
    697823    return false;
    698824
    699825    // XXX pmReadoutRead, pmReadoutReadSegement disabled for now
    700     # if (0)
    701 
    702         if (view->readout >= cell->readouts->n) {
    703             return false;
    704         }
     826    #if 0
     827
     828    if (view->readout >= cell->readouts->n) {
     829        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
     830                view->readout, cell->readouts->n);
     831        return false;
     832    }
    705833    pmReadout *readout = cell->readouts->data[view->readout];
    706834
     
    711839    }
    712840    return true;
    713     # endif
     841    #endif
    714842}
    715843
     
    731859
    732860    if (view->chip >= fpa->chips->n) {
     861        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
    733862        return false;
    734863    }
     
    757886
    758887    if (view->cell >= chip->cells->n) {
     888        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
    759889        return false;
    760890    }
     
    762892
    763893    if (view->readout == -1) {
    764         pmCellWrite (cell, fits, NULL, true);
    765         return true;
    766     }
     894        return pmCellWrite (cell, fits, NULL, true);
     895    }
     896    psError(PS_ERR_UNKNOWN, true, "Returning false");
    767897    return false;
    768898
    769899    // XXX disable readout write for now
    770     # if (0)
    771 
    772         if (view->readout >= cell->readouts->n) {
    773             return false;
    774         }
     900    #if 0
     901
     902    if (view->readout >= cell->readouts->n) {
     903        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
     904                view->readout, cell->readouts->n);
     905        return false;
     906    }
    775907    pmReadout *readout = cell->readouts->data[view->readout];
    776908
     
    781913    }
    782914    return true;
    783     # endif
     915    #endif
    784916}
    785917
     
    808940    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    809941    if (!status) {
     942        psError(PS_ERR_IO, false, "Failed to read %s from metadata\n", argname);
    810943        return NULL;
    811944    }
    812945    if (infiles->n < 1) {
     946        psError(PS_ERR_IO, false, "Found n == %d files in %s from metadata\n", infiles->n, argname);
    813947        return NULL;
    814948    }
     
    819953    phu = psFitsReadHeader (NULL, fits);
    820954    format = pmConfigCameraFormatFromHeader (config, phu);
    821     psFitsClose (fits);
     955    psFitsClose (fits);                        // don't close phu; we'll use it below
     956    if (!format) {
     957        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", infiles->data[0]);
     958        psFree(phu);
     959        return NULL;
     960    }
    822961
    823962    // build the template fpa, set up the basic view
    824963    fpa = pmFPAConstruct (config->camera);
     964    if (!fpa) {
     965        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", infiles->data[0]);
     966        return NULL;
     967    }
    825968
    826969    // load the given filerule (from config->camera) and associate it with the fpa
     
    828971    file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    829972    if (!file) {
    830         psErrorStackPrint(stderr, "file %s not defined\n", filename);
     973        psError(PS_ERR_IO, false, "file %s not defined", filename);
     974        psFree(phu);
    831975        psFree (fpa);
    832976        psFree (format);
     
    854998        // set the view to the corresponding entry for this phu
    855999        pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
     1000        if (!view) {
     1001            psError(PS_ERR_IO, false, "Failed to set view from file %s", infiles->data[i]);
     1002            psFree(phu);
     1003            psFree (fpa);
     1004            psFree (format);
     1005            return NULL;
     1006        }
    8561007
    8571008        // XXX is this the correct psMD to save the filename?
     
    8711022
    8721023// XXX this this function through, then finish
    873 # if 0
     1024#if 0
    8741025// look for the given name on the argument list.
    8751026// returns the file (a view to the one saved on config->files)
     
    9251076    file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    9261077    if (!file) {
    927         psErrorStackPrint(stderr, "file %s not defined\n", filename);
     1078        psError(PS_ERR_IO, false, "file %s not defined", filename);
    9281079        psFree (fpa);
    9291080        psFree (format);
     
    9661117    return file;
    9671118}
    968 # endif
     1119#endif
    9691120
    9701121// create a new output pmFPAfile based on an existing FPA
     
    9791130    pmFPA *fpa = pmFPAConstruct (config->camera);
    9801131    pmFPAfile *file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
     1132    if (!file) {
     1133        psErrorStackPrint(stderr, "file %s not defined\n", filename);
     1134        return NULL;
     1135    }
    9811136    file->src = src; // inherit output elements from this source pmFPA
    9821137    file->xBin = xBin;
     
    10141169    file = pmFPAfileDefine (config->files, config->camera, NULL, filename);
    10151170    if (!file) {
    1016         psErrorStackPrint(stderr, "file %s not defined\n", filename);
     1171        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    10171172        return NULL;
    10181173    }
     
    11201275    newName = psStringCopy (rule);
    11211276
     1277    if (strstr (newName, "{OUTPUT}") != NULL) {
     1278        char *name = psMetadataLookupStr (NULL, file->names, "OUTPUT");
     1279        if (name != NULL) {
     1280            newName = psStringSubstitute (newName, name, "{OUTPUT}");
     1281        }
     1282    }
    11221283    if (strstr (newName, "{CHIP.NAME}") != NULL) {
    11231284        pmChip *chip = pmFPAviewThisChip (view, file->fpa);
     
    11441305        }
    11451306    }
    1146     if (strstr (newName, "{OUTPUT}") != NULL) {
    1147         char *name = psMetadataLookupStr (NULL, file->names, "OUTPUT");
    1148         if (name != NULL) {
    1149             newName = psStringSubstitute (newName, name, "{OUTPUT}");
    1150         }
    1151     }
    11521307    return newName;
    11531308}
     
    11671322    }
    11681323    if (view->chip >= in->chips->n) {
     1324        psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %d", view->chip, in->chips->n);
    11691325        return false;
    11701326    }
     
    11771333    }
    11781334    if (view->cell >= inChip->cells->n) {
     1335        psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %d",
     1336                view->cell, inChip->cells->n);
    11791337        return false;
    11801338    }
     
    11861344        return true;
    11871345    }
     1346    psError(PS_ERR_UNKNOWN, true, "Returning false");
    11881347    return false;
    11891348
     
    12031362    if (view->chip == -1) {
    12041363        pmFPAAddSourceFromView (out, view, format);
    1205         pmFPACopyStructure (out, in, xBin, yBin);
    1206         return true;
     1364        return pmFPACopyStructure (out, in, xBin, yBin);
    12071365    }
    12081366    if (view->chip >= in->chips->n) {
     1367        psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %d", view->chip, in->chips->n);
    12091368        return false;
    12101369    }
     
    12141373    if (view->cell == -1) {
    12151374        pmFPAAddSourceFromView (out, view, format);
    1216         pmChipCopyStructure (outChip, inChip, xBin, yBin);
    1217         return true;
     1375        return pmChipCopyStructure (outChip, inChip, xBin, yBin);
    12181376    }
    12191377    if (view->cell >= inChip->cells->n) {
     1378        psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %d",
     1379                view->cell, inChip->cells->n);
    12201380        return false;
    12211381    }
     
    12251385    if (view->readout == -1) {
    12261386        pmFPAAddSourceFromView (out, view, format);
    1227         pmCellCopyStructure (outCell, inCell, xBin, yBin);
    1228         return true;
    1229     }
     1387        return pmCellCopyStructure (outCell, inCell, xBin, yBin);
     1388    }
     1389    psError(PS_ERR_UNKNOWN, true, "Returning false");
    12301390    return false;
    12311391
  • trunk/psModules/src/camera/pmReadout.c

    r7017 r7311  
    7676            readout->mask = psMemIncrRefCounter(psImageSubset(masks->data[i], *trimsec));
    7777        }
     78        if (readout->weight == NULL || readout->mask == NULL) {
     79            psError(PS_ERR_UNKNOWN, false, "Trimming readout %d", i);
     80            return false;
     81        }
    7882
    7983        // Set up the mask
  • trunk/psModules/src/concepts/pmConcepts.c

    r7310 r7311  
    131131    }
    132132
     133    bool success = true;                // Success in reading concepts?
    133134    if (source & PM_CONCEPT_SOURCE_CAMERA && !(*read & PM_CONCEPT_SOURCE_CAMERA)) {
    134         pmConceptsReadFromCamera(*specs, cell, target);
    135         *read |= PM_CONCEPT_SOURCE_CAMERA;
     135        if (pmConceptsReadFromCamera(*specs, cell, target)) {
     136            *read |= PM_CONCEPT_SOURCE_CAMERA;
     137        } else {
     138            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from camera configuration.\n");
     139            success = false;
     140        }
    136141    }
    137142
    138143    if (source & PM_CONCEPT_SOURCE_DEFAULTS && !(*read & PM_CONCEPT_SOURCE_DEFAULTS)) {
    139         pmConceptsReadFromDefaults(*specs, fpa, chip, cell, target);
    140         *read |= PM_CONCEPT_SOURCE_DEFAULTS;
     144        if (pmConceptsReadFromDefaults(*specs, fpa, chip, cell, target)) {
     145            *read |= PM_CONCEPT_SOURCE_DEFAULTS;
     146        } else {
     147            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from defaults.\n");
     148            success = false;
     149        }
    141150    }
    142151
    143152    if (source & PM_CONCEPT_SOURCE_HEADER && !(*read & PM_CONCEPT_SOURCE_HEADER)) {
    144         pmConceptsReadFromHeader(*specs, fpa, chip, cell, target);
    145         *read |= PM_CONCEPT_SOURCE_HEADER;
    146     }
    147 
     153        if (pmConceptsReadFromHeader(*specs, fpa, chip, cell, target)) {
     154            *read |= PM_CONCEPT_SOURCE_HEADER;
     155        } else {
     156            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from header.\n");
     157            success = false;
     158        }
     159    }
     160
     161    #ifndef OMIT_PSDB
    148162    if (source & PM_CONCEPT_SOURCE_DATABASE && !(*read & PM_CONCEPT_SOURCE_DATABASE)) {
    149         pmConceptsReadFromDatabase(*specs, fpa, chip, cell, db, target);
    150         *read |= PM_CONCEPT_SOURCE_DATABASE;
    151     }
    152 
    153     return true;
     163        if (pmConceptsReadFromDatabase(*specs, fpa, chip, cell, db, target)) {
     164            *read |= PM_CONCEPT_SOURCE_DATABASE;
     165        } else {
     166            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from database.\n");
     167            success = false;
     168        }
     169    }
     170    #endif
     171
     172    return success;
    154173}
    155174
  • trunk/psModules/src/concepts/pmConcepts.h

    r7017 r7311  
    66
    77// Function to call to parse a concept once it has been read
    8 typedef psMetadataItem* (*pmConceptParseFunc)(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
     8typedef psMetadataItem* (*pmConceptParseFunc)(const psMetadataItem *concept, const psMetadataItem *pattern, const psMetadata *cameraFormat, const pmFPA *fpa, const pmChip *chip, const pmCell *cell);
    99// Function to call to format a concept for writing
    10 typedef psMetadataItem* (*pmConceptFormatFunc)(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
     10typedef psMetadataItem* (*pmConceptFormatFunc)(const psMetadataItem *concept, const psMetadata *cameraFormat, const pmFPA *fpa, const pmChip *chip, const pmCell *cell);
    1111
    1212// A "concept" specification
  • trunk/psModules/src/concepts/pmConceptsRead.c

    r7280 r7311  
    7171        parsed = parsePlain(concept, spec->blank);
    7272    }
    73     if (!parsed)
    74         return false;
     73    if (!parsed) {
     74        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s\n", spec->blank->name);
     75        return false;
     76    }
    7577
    7678    // Plug the parsed concept into a new psMetadataItem, so each "concept" has its own version that can
     
    117119
    118120    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
    119     if (! hdu) {
     121    if (!hdu) {
    120122        return false;
    121123    }
     
    124126    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    125127    psMetadataItem *specItem = NULL;    // Item from the specs metadata
     128    bool status = true;                 // Status of reading concepts
    126129    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    127130        pmConceptSpec *spec = specItem->data.V; // The specification
    128131        psString name = specItem->name; // The concept name
    129132        psMetadataItem *conceptItem = psMetadataLookup(cellConfig, name); // The concept, or NULL
    130         psMetadataItem *value = NULL; // The value of the concept
    131133        if (conceptItem) {
    132134            if (conceptItem->type == PS_DATA_STRING) {
     
    138140                psFree(nameSource);
    139141                if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) {
    140                     value = conceptItem;
    141                     conceptParse(spec, value, cameraFormat, target, NULL, NULL, cell);
     142                    if (!conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell)) {
     143                        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from camera "
     144                                "configuration\n", name);
     145                        status = false;
     146                    }
    142147                } else if (source && (strlen(source) == 0 || strcasecmp(source, "HEADER") != 0)) {
    143148                    // We leave "HEADER" to pmConceptsReadFromHeader
     
    148153            } else {
    149154                // Another type --- should be OK
    150                 conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell);
     155                if (!conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell)) {
     156                    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from camera "
     157                            "configuration.  It has a weird %s.SOURCE: %s\n", name, name);
     158                    status = false;
     159                }
    151160            }
    152161        }
    153162    }
    154163    psFree(specsIter);
    155     return true;
     164    return status;
    156165}
    157166
     
    179188    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    180189    psMetadataItem *specItem = NULL;    // Item from the specs metadata
     190    bool status = true;                 // Status of reading concepts
    181191    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    182192        pmConceptSpec *spec = specItem->data.V; // The specification
    183193        psString name = specItem->name; // The concept name
    184194        psMetadataItem *conceptItem = psMetadataLookup(defaults, name); // The concept, or NULL
    185         conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
     195        if (conceptItem && !conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell)) {
     196            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from DEFAULTS.\n", name);
     197            status = false;
     198        }
    186199    }
    187200    psFree(specsIter);
    188     return true;
     201    return status;
    189202}
    190203
     
    213226    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    214227    psMetadataItem *specItem = NULL;    // Item from the specs metadata
     228    bool status = true;                 // Status of reading concepts
    215229    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    216230        pmConceptSpec *spec = specItem->data.V; // The specification
     
    257271
    258272        // This will also clean up the name
    259         conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell);
     273        if (headerItem && !conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell)) {
     274            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from header.\n", name);
     275            status = false;
     276        }
    260277    }
    261278    psFree(specsIter);
    262     return true;
     279    return status;
    263280}
    264281
     
    294311    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
    295312    psMetadataItem *specItem = NULL;    // Item from the specs metadata
     313    bool status = true;                 // Status of reading concepts
    296314    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    297315        pmConceptSpec *spec = specItem->data.V; // The specification
     
    374392
    375393                    // Now we have the result
    376                     conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
     394                    if (!conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell)) {
     395                        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from database.\n",
     396                                name);
     397                        status = false;
     398                    }
    377399
    378400                }
     
    385407    psFree(specsIter);
    386408
    387     return true;
     409    return status;
    388410    #endif
    389411}
  • trunk/psModules/src/concepts/pmConceptsStandard.c

    r7281 r7311  
    6969                    sscanf(concept->data.V, "%d %d %f", &big, &medium, &small) != 3)
    7070            {
    71                 psError(PS_ERR_IO, true, "Cannot interpret FPA.RA: %s\n", concept->data.V);
     71                psError(PS_ERR_UNKNOWN, true, "Cannot interpret FPA.RA: %s\n", concept->data.V);
    7272                break;
    7373            }
     
    8080        break;
    8181    default:
    82         psError(PS_ERR_IO, true, "%s concept is of an unexpected type: %x\n", pattern->name, concept->type);
     82        psError(PS_ERR_UNKNOWN, true, "%s concept is of an unexpected type: %x\n", pattern->name, concept->type);
    8383        return NULL;
    8484    }
     
    171171    assert(pattern);
    172172
    173     psRegion *trimsec = psAlloc(sizeof(psRegion)); // Make space for a psRegion (usually passed by value)
     173    psRegion *trimsec = psRegionAlloc(0, 0, 0, 0);
    174174
    175175    if (concept->type != PS_DATA_STRING) {
    176         psError(PS_ERR_IO, true, "CELL.TRIMSEC after read is not of type STR (%x)\n", concept->type);
    177         *trimsec = psRegionSet(0.0, 0.0, 0.0, 0.0);
     176        psError(PS_ERR_UNKNOWN, true, "CELL.TRIMSEC after read is not of type STR (%x)\n", concept->type);
    178177    } else {
    179178        *trimsec = psRegionFromString(concept->data.V);
     
    231230        }
    232231    default:
    233         psError(PS_ERR_IO, true, "CELL.BIASSEC after read is not of type STRING or LIST --- assuming "
     232        psError(PS_ERR_UNKNOWN, true, "CELL.BIASSEC after read is not of type STRING or LIST --- assuming "
    234233                "blank.\n");
    235234    }
     
    259258                    (strcmp(pattern->name, "CELL.YBIN") == 0 && sscanf(binString, "%*d %d", &binning) != 1 &&
    260259                     sscanf(binString, "%*d,%d", &binning) != 1)) {
    261                 psError(PS_ERR_IO, true, "Unable to parse string to get %s: %s\n", pattern->name, binString);
     260                psError(PS_ERR_UNKNOWN, true, "Unable to parse string to get %s: %s\n", pattern->name, binString);
    262261            }
    263262        }
     
    269268        TYPE_CASE(binning, concept, S32);
    270269    default:
    271         psError(PS_ERR_IO, true, "Note sure how to parse %s of type %x --- assuming 1.\n", pattern->name,
     270        psError(PS_ERR_UNKNOWN, true, "Note sure how to parse %s of type %x --- assuming 1.\n", pattern->name,
    272271                concept->type);
    273272    }
     
    290289    psString sys = concept->data.V;     // The time system string
    291290    if (concept->type != PS_DATA_STRING || strlen(sys) <= 0) {
    292         psError(PS_ERR_IO, true, "Can't interpret CELL.TIMESYS --- assuming UTC.\n");
     291        psError(PS_ERR_UNKNOWN, true, "Can't interpret CELL.TIMESYS --- assuming UTC.\n");
    293292    } else if (strcasecmp(sys, "TAI") == 0) {
    294293        timeSys = PS_TIME_TAI;
     
    300299        timeSys = PS_TIME_TT;
    301300    } else {
    302         psError(PS_ERR_IO, true, "Can't interpret CELL.TIMESYS --- assuming UTC.\n");
     301        psError(PS_ERR_UNKNOWN, true, "Can't interpret CELL.TIMESYS --- assuming UTC.\n");
    303302    }
    304303
     
    334333    // Get format
    335334    psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS");
    336     if (!mdok || !formats)
     335    if (!mdok || !formats) {
     336        psError(PS_ERR_UNKNOWN, false, "Unable to find FORMATS in camera configuration.\n");
    337337        return NULL;
     338    }
    338339
    339340    psString timeFormat = psMetadataLookupStr(&mdok, formats, "CELL.TIME");
    340     if (!mdok || !timeFormat || !strlen(timeFormat))
     341    if (!mdok || !timeFormat || !strlen(timeFormat)) {
     342        psError(PS_ERR_UNKNOWN, false, "Unable to find CELL.TIME in FORMATS.\n");
    341343        return NULL;
     344    }
    342345
    343346    // Parse the time format
     
    385388            psMetadataItem *timeItem = psListGet(dateTime, PS_LIST_HEAD + 1); // Item containing the time
    386389            if (dateItem->type != PS_DATA_STRING) {
    387                 psError(PS_ERR_IO, true, "Date is not of type STR.\n");
     390                psError(PS_ERR_UNKNOWN, true, "Date is not of type STR.\n");
    388391                return NULL;
    389392            }
     
    392395            if (sscanf(dateString, "%d-%d-%d", &year, &month, &day) != 3 &&
    393396                    sscanf(dateString, "%d/%d/%d", &year, &month, &day) != 3) {
    394                 psError(PS_ERR_IO, true, "Unable to read date: %s\n", dateString);
     397                psError(PS_ERR_UNKNOWN, true, "Unable to read date: %s\n", dateString);
    395398                return NULL;
    396399            }
     
    408411                year = temp;
    409412            }
    410             if (pre2000Time || year < 2000) {
    411                 year += 2000;
    412             }
     413            if (year < 100) {
     414                if (pre2000Time) {
     415                    year += 1900;
     416                } else {
     417                    year += 2000;
     418                }
     419            }
     420            sprintf(dateString,"%04d-%02d-%02d", year, month, day);
     421
    413422            psString timeString = NULL; // The string with the time
    414423            if (timeItem->type == PS_DATA_STRING) {
     
    427436                    TYPE_CASE(seconds, timeItem, F64);
    428437                default:
    429                     psError(PS_ERR_IO, true, "Time is not of an expected type: %x\n", timeItem->type);
     438                    psError(PS_ERR_UNKNOWN, true, "Time is not of an expected type: %x\n", timeItem->type);
    430439                    return NULL;
    431440                }
     
    440449            psStringAppend(&dateTimeString, "%sT%s", dateString, timeString);
    441450            time = psTimeFromISO(dateTimeString, timeSys);
     451            psFree(dateTimeString);
    442452            break;
    443453        }
     
    463473                time = psTimeFromMJD(timeValue);
    464474            } else {
    465                 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue);
     475                psError(PS_ERR_UNKNOWN, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n",
     476                        timeValue);
    466477                time = psTimeFromJD(timeValue);
    467478            }
     
    475486                time = psTimeFromMJD(timeValue);
    476487            } else {
    477                 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue);
     488                psError(PS_ERR_UNKNOWN, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n",
     489                        timeValue);
    478490                time = psTimeFromJD(timeValue);
    479491            }
     
    481493        }
    482494    default:
    483         psError(PS_ERR_IO, true, "Unable to parse CELL.TIME.\n");
     495        psError(PS_ERR_UNKNOWN, true, "Unable to parse CELL.TIME.\n");
    484496        return NULL;
    485497    }
     
    526538        TYPE_CASE(offset, concept, S32);
    527539    default:
    528         psError(PS_ERR_IO, true, "Concept %s is not of integer type, as expected.\n", pattern->name);
     540        psError(PS_ERR_UNKNOWN, true, "Concept %s is not of integer type, as expected.\n", pattern->name);
    529541        return NULL;
    530542    }
     
    724736        // XXX: Couldn't be bothered doing these right now
    725737        if (pre2000Time) {
    726             psError(PS_ERR_IO, true, "Don't you realise it's the twenty-first century?\n");
     738            psError(PS_ERR_UNKNOWN, true, "Don't you realise it's the twenty-first century?\n");
    727739            return NULL;
    728740        }
    729741        if (backwardsTime) {
    730             psError(PS_ERR_IO, true, "You want it BACKWARDS?  Not right now, thanks.\n");
     742            psError(PS_ERR_UNKNOWN, true, "You want it BACKWARDS?  Not right now, thanks.\n");
    731743            return NULL;
    732744        }
    733745        if (usaTime) {
    734             psError(PS_ERR_IO, true, "USA?  No OK --- yet.\n");
     746            psError(PS_ERR_UNKNOWN, true, "USA?  No OK.\n");
    735747            return NULL;
    736748        }
     
    778790
    779791    if (concept->type != PS_TYPE_S32) {
    780         psError(PS_ERR_IO, true, "Concept %s is not of type S32, as expected.\n", concept->name);
     792        psError(PS_ERR_UNKNOWN, true, "Concept %s is not of type S32, as expected.\n", concept->name);
    781793        return NULL;
    782794    }
  • trunk/psModules/src/config/pmConfig.c

    r7278 r7311  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-02 00:55:22 $
     5 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-03 01:02:08 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1212#include <string.h>
    1313#include <unistd.h>
     14#include <libgen.h>
    1415#include <assert.h>
    1516#include <sys/types.h>
     
    5253}
    5354
     55void pmConfigSet(const char *path)
     56{
     57    pmConfigDone();
     58
     59    psList *list = psStringSplit(path, ":", false);
     60    configPath = psListToArray(list);
     61    psFree(list);
     62}
     63
    5464void pmConfigDone(void)
    5565{
    5666    psFree(configPath);
     67    configPath = NULL;
    5768}
    5869
     
    100111
    101112    if (configPath == NULL) {
    102         psError(PS_ERR_IO, false, "Cannot find %s configuration file (%s) in path\n", description, name);
     113        psError(PS_ERR_IO, true, "Cannot find %s configuration file (%s) in path\n", description, name);
    103114        return false;
    104115    }
     
    121132    }
    122133
    123     psError(PS_ERR_IO, false, "Cannot find %s configuration file %s in path\n", description, name);
     134    psError(PS_ERR_IO, true, "Cannot find %s configuration file %s in path\n", description, name);
    124135    return false;
    125136
     
    127138    *config = psMetadataConfigParse(NULL, &numBadLines, realName, true);
    128139    if (numBadLines > 0) {
    129         psLogMsg(__func__, PS_LOG_WARN, "%d bad lines in %s configuration file (%s)\n",
    130                  description, realName);
     140        psError(PS_ERR_IO, false, "%d bad lines in %s configuration file (%s)",
     141                numBadLines, description, realName);
     142        psFree (realName);
     143
     144        return false;
    131145    }
    132146    if (!*config) {
    133         psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n",
     147        psError(PS_ERR_IO, true, "Unable to read %s configuration from %s",
    134148                description, realName);
    135149        psFree (realName);
     
    214228        return NULL;
    215229    }
     230
     231    // define the config-file search path (configPath).  Ensure that
     232    // it contains the directory where we found the config file in
     233    // the first place
     234    if (configPath) {
     235        pmConfigDone();
     236    }
     237
     238    psString siteNameDir = psStringCopy(dirname(siteName));
    216239    psFree(siteName);
    217240
    218     // define the config-file search path (configPath)
    219     if (configPath) {
    220         psFree(configPath);
    221         configPath = NULL;
    222     }
    223     char *path = psMetadataLookupStr(NULL, config->site, "PATH");
     241    psString path = psMetadataLookupStr(NULL, config->site, "PATH");
    224242    if (path) {
    225         psList *list = psStringSplit(path, ":", false);
    226         configPath = psListToArray(list);
    227         psFree(list);
    228     }
     243        psStringAppend(&path, ":%s", siteNameDir);
     244    } else {
     245        path = psMemIncrRefCounter(siteNameDir);
     246    }
     247    pmConfigSet(path);
     248    psFree(siteNameDir);
    229249
    230250    // Next, we do a similar thing for the camera configuration file.  The
     
    349369    }
    350370
     371    psErrorClear();   // we may have failed to find some items in the metadata
     372
    351373    return config;
    352374}
     
    468490        psMetadata *cameras = psMetadataLookupMD(&mdok, config->site, "CAMERAS");
    469491        if (! mdok) {
    470             psError(PS_ERR_IO, false, "Unable to find CAMERAS in the configuration.\n");
     492            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
    471493            return false;
    472494        }
     
    502524
    503525        if (! config->camera) {
    504             psError(PS_ERR_IO, true, "Unable to find a camera that matches input FITS header!\n");
     526            psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
    505527            return NULL;
    506528        }
     
    611633    psMetadata *rules = psMetadataLookupMD(&mdok, format, "RULE"); // How to identify this format
    612634    if (!mdok || !rules) {
    613         psError(PS_ERR_IO, false, "Unable to find RULE in camera format.\n");
     635        psError(PS_ERR_IO, true, "Unable to find RULE in camera format.\n");
    614636        return false;
    615637    }
     
    651673        globList.gl_offs = 0;
    652674        glob (argv[Narg], 0, NULL, &globList);
     675
     676        if (globList.gl_pathc == 0) {
     677            psError(PS_ERR_IO, true, "No match for %s", argv[Narg]);
     678            return input;
     679        }
     680
    653681        for (int i = 0; i < globList.gl_pathc; i++) {
    654682            char *filename = psStringCopy (globList.gl_pathv[i]);
     
    706734    PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
    707735
     736    psErrorClear();   // pmConfigFileSets may or may not call psError, so
     737    // if files->n == 0 we'll want to call psError(..., false, ...)
    708738    psArray *files = pmConfigFileSets (argc, argv, file, list);
    709739    if (files->n == 0) {
     740        psError(PS_ERR_IO, false, "pmConfigFileSets failed to find desired files in metadata");
    710741        psFree (files);
    711742        return false;
  • trunk/psModules/src/config/pmConfig.h

    r7026 r7311  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-05-02 00:47:01 $
     5 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-03 01:02:08 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828
    2929pmConfig *pmConfigAlloc(void);
     30
     31void pmConfigSet(const char *path); // set the configPath
    3032
    3133// Free static variables
  • trunk/psModules/src/objects/pmPSF.c

    r6960 r7311  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-23 01:07:51 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9797    // the ApTrend components are (x, y, r2rflux, flux)
    9898    psf->ApTrend = psPolynomial4DAlloc (PS_POLYNOMIAL_ORD, 2, 2, 1, 1);
    99     pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
     99    pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
    100100
    101101    if (psf->poissonErrors) {
     
    239239 * to enable the specific subset of the coefficients
    240240 **********************************************/
    241 bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option)
     241bool pmPSF_MaskApTrend (psPolynomial4D *trend,
     242                        pmPSF_ApTrendOptions option)
    242243{
    243244
    244245    switch (option) {
    245246    case PM_PSF_NONE:
    246         maskAllTerms (psf->ApTrend);
     247        maskAllTerms (trend);
    247248        return true;
    248249
    249250    case PM_PSF_CONSTANT:
    250         maskAllTerms (psf->ApTrend);
    251         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     251        maskAllTerms (trend);
     252        trend->mask[0][0][0][0] = 0;  // unmask constant
    252253        return true;
    253254
    254255    case PM_PSF_SKYBIAS:
    255         maskAllTerms (psf->ApTrend);
    256         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    257         psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     256        maskAllTerms (trend);
     257        trend->mask[0][0][0][0] = 0;  // unmask constant
     258        trend->mask[0][0][1][0] = 0;  // unmask skybias
    258259        return true;
    259260
    260261    case PM_PSF_SKYSAT:
    261         maskAllTerms (psf->ApTrend);
    262         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    263         psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
    264         psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skybias
     262        maskAllTerms (trend);
     263        trend->mask[0][0][0][0] = 0;  // unmask constant
     264        trend->mask[0][0][1][0] = 0;  // unmask skybias
     265        trend->mask[0][0][0][1] = 0;  // unmask skysat
    265266        return true;
    266267
    267268    case PM_PSF_XY_LIN:
    268         maskAllTerms (psf->ApTrend);
    269         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    270         psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
    271         psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     269        maskAllTerms (trend);
     270        trend->mask[0][0][0][0] = 0;  // unmask constant
     271        trend->mask[1][0][0][0] = 0;  // unmask x
     272        trend->mask[0][1][0][0] = 0;  // unmask y
    272273        return true;
    273274
    274275    case PM_PSF_XY_QUAD:
    275         maskAllTerms (psf->ApTrend);
    276         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    277         psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
    278         psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
    279         psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
    280         psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
    281         psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
     276        maskAllTerms (trend);
     277        trend->mask[0][0][0][0] = 0;  // unmask constant
     278        trend->mask[1][0][0][0] = 0;  // unmask x
     279        trend->mask[2][0][0][0] = 0;  // unmask x^2
     280        trend->mask[1][1][0][0] = 0;  // unmask x y
     281        trend->mask[0][1][0][0] = 0;  // unmask y
     282        trend->mask[0][2][0][0] = 0;  // unmask y^2
    282283        return true;
    283284
    284285    case PM_PSF_SKY_XY_LIN:
    285         maskAllTerms (psf->ApTrend);
    286         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    287         psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
    288         psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
    289         psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     286        maskAllTerms (trend);
     287        trend->mask[0][0][0][0] = 0;  // unmask constant
     288        trend->mask[1][0][0][0] = 0;  // unmask x
     289        trend->mask[0][1][0][0] = 0;  // unmask y
     290        trend->mask[0][0][1][0] = 0;  // unmask skybias
    290291        return true;
    291292
    292293    case PM_PSF_SKYSAT_XY_LIN:
    293         maskAllTerms (psf->ApTrend);
    294         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    295         psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
    296         psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
    297         psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
    298         psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
     294        maskAllTerms (trend);
     295        trend->mask[0][0][0][0] = 0;  // unmask constant
     296        trend->mask[1][0][0][0] = 0;  // unmask x
     297        trend->mask[0][1][0][0] = 0;  // unmask y
     298        trend->mask[0][0][1][0] = 0;  // unmask skybias
     299        trend->mask[0][0][0][1] = 0;  // unmask skysat
    299300        return true;
    300301
    301302    case PM_PSF_ALL:
    302303    default:
    303         maskAllTerms (psf->ApTrend);
    304         psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
    305         psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
    306         psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
    307 
    308         psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
    309         psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
    310         psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
    311         psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
    312         psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
     304        maskAllTerms (trend);
     305        trend->mask[0][0][0][0] = 0;  // unmask constant
     306        trend->mask[0][0][1][0] = 0;  // unmask skybias
     307        trend->mask[0][0][0][1] = 0;  // unmask skysat
     308
     309        trend->mask[1][0][0][0] = 0;  // unmask x
     310        trend->mask[2][0][0][0] = 0;  // unmask x^2
     311        trend->mask[1][1][0][0] = 0;  // unmask x y
     312        trend->mask[0][1][0][0] = 0;  // unmask y
     313        trend->mask[0][2][0][0] = 0;  // unmask y^2
    313314        return true;
    314315    }
  • trunk/psModules/src/objects/pmPSF.h

    r6873 r7311  
    3131    psArray *params;   ///< Model parameters (psPolynomial2D)
    3232    psPolynomial1D *ChiTrend;  ///< Chisq vs flux fit (correction for systematic errors)
    33     psPolynomial4D *ApTrend;  ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst)
    34     pmGrowthCurve *growth;  ///< apMag vs Radius
     33    psPolynomial4D *ApTrend;  ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst))
     34    //pmGrowthCurve *growth;  ///< apMag vs Radius // move to end as gdb is confused by it here
    3535    float ApResid;   ///< apMag - psfMag (for PSF stars)
    3636    float dApResid;   ///< scatter of ApResid
     
    4141    int nApResid;   ///< number of stars used to measure ApResid
    4242    bool poissonErrors;
     43    pmGrowthCurve *growth;  ///< apMag vs Radius
    4344}
    4445pmPSF;
     
    100101);
    101102
    102 bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option);
     103bool pmPSF_MaskApTrend (psPolynomial4D *trend, pmPSF_ApTrendOptions option);
    103104
    104105# endif
  • trunk/psModules/src/objects/pmPSF_IO.c

    r6872 r7311  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-17 18:01:05 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    287287{
    288288
    289     int Nfail;
     289    unsigned int Nfail;
    290290    char *filename;
    291291
  • trunk/psModules/src/objects/pmPSFtry.c

    r7283 r7311  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-06-02 02:16:05 $
     7 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-06-03 01:02:08 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    263263    psLogMsg ("pmPSFtryMetric", 4, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
    264264
    265     pmPSF_MaskApTrend (psfTry->psf, PM_PSF_SKYBIAS);
     265    pmPSF_MaskApTrend (psfTry->psf->ApTrend, PM_PSF_SKYBIAS);
    266266    psfTry->psf->ApTrend->coeff[0][0][0][0] = poly->coeff[0];
    267267    psfTry->psf->ApTrend->coeff[0][0][1][0] = 0;
  • trunk/psModules/src/objects/pmPSFtry.h

    r6873 r7311  
    66 *  @author EAM, IfA
    77 *
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    810 *
    911 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7678 *
    7779 */
    78 pmPSFtry *pmPSFtryAlloc(
    79     psArray *stars,                     ///< Add comment.
    80     char *modelName,                     ///< Add comment.
    81     bool poissonErrors   // use poissonian or constant errors?
    82 );
    83 
     80pmPSFtry *pmPSFtryAlloc (psArray *sources, char *modelName, bool poissonErrors);
    8481
    8582/** pmPSFtryModel()
     
    9087 *
    9188 */
    92 pmPSFtry *pmPSFtryModel(
    93     psArray *sources,                   ///< Add comment.
    94     char *modelName,                    ///< Add comment.
    95     float radius,                     ///< Add comment.
    96     bool poissonErrors   // use poissonian or constant errors?
    97 );
    98 
     89pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float RADIUS, bool poissonErrors);
    9990
    10091/** pmPSFtryMetric()
  • trunk/psModules/src/objects/pmPeaks.c

    r6943 r7311  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-21 21:26:44 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9494pmPeakAlloc(): Allocate the pmPeak data structure and set appropriate members.
    9595*****************************************************************************/
     96static void peakFree(pmPeak *tmp)
     97{} // used by pmIsPeak()
     98
    9699pmPeak *pmPeakAlloc(psS32 x,
    97100                    psS32 y,
     
    100103{
    101104    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     105    static int id = 1;
    102106    pmPeak *tmp = (pmPeak *) psAlloc(sizeof(pmPeak));
     107    *(int *)&tmp->id = id++;
    103108    tmp->x = x;
    104109    tmp->y = y;
     
    106111    tmp->type = type;
    107112
     113    psMemSetDeallocator(tmp, (psFreeFunc) peakFree);
     114
    108115    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
    109116    return(tmp);
     117}
     118
     119bool pmIsPeak(const psPtr ptr)
     120{
     121    return (psMemGetDeallocator(ptr) == (psFreeFunc)peakFree);
    110122}
    111123
  • trunk/psModules/src/objects/pmPeaks.h

    r6872 r7311  
    1010 *  @author GLG, MHPCC
    1111 *
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-04-17 18:01:05 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-06-03 01:02:08 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4747typedef struct
    4848{
     49    const int id;   ///< Unique ID for object
    4950    int x;                              ///< X-coordinate of peak pixel.
    5051    int y;                              ///< Y-coordinate of peak pixel.
     
    6667);
    6768
     69bool pmIsPeak(const psPtr ptr);
    6870
    6971/** pmFindVectorPeaks()
  • trunk/psModules/src/objects/pmSource.c

    r7283 r7311  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-06-02 02:16:05 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4646{
    4747    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     48    static int id = 1;
    4849    pmSource *tmp = (pmSource *) psAlloc(sizeof(pmSource));
     50    *(int *)&tmp->id = id++;
    4951    tmp->peak = NULL;
    5052    tmp->pixels = NULL;
     
    6971}
    7072
     73bool pmIsSource(const psPtr ptr)
     74{
     75    return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree);
     76}
     77
    7178// x,y are defined in the parent image coords of readout->image
    7279bool pmSourceDefinePixels(pmSource *mySource,
     
    8289    srcRegion = psRegionForImage (readout->image, srcRegion);
    8390
    84     mySource->pixels = psImageSubset(readout->image, srcRegion);
    85     mySource->weight = psImageSubset(readout->weight, srcRegion);
    86     mySource->mask   = psImageSubset(readout->mask,  srcRegion);
     91    mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, srcRegion));
     92    mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, srcRegion));
     93    mySource->mask   = psMemIncrRefCounter(psImageSubset(readout->mask,  srcRegion));
    8794    mySource->region = srcRegion;
    8895
     
    123130        psFree (mySource->mask);
    124131
    125         mySource->pixels = psImageSubset(readout->image,  newRegion);
    126         mySource->weight = psImageSubset(readout->weight, newRegion);
    127         mySource->mask   = psImageSubset(readout->mask,   newRegion);
     132        mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image,  newRegion));
     133        mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, newRegion));
     134        mySource->mask   = psMemIncrRefCounter(psImageSubset(readout->mask,   newRegion));
    128135        mySource->region = newRegion;
    129136    }
  • trunk/psModules/src/objects/pmSource.h

    r6905 r7311  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-04-19 20:29:57 $
     5 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-03 01:02:08 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7373typedef struct
    7474{
     75    const int id;   ///< Unique ID for object
    7576    pmPeak *peak;   ///< Description of peak pixel.
    7677    psImage *pixels;   ///< Rectangular region including object pixels.
     
    114115pmSource  *pmSourceAlloc();
    115116
     117bool pmIsSource(const psPtr ptr);
    116118
    117119/** pmSourceDefinePixels()
  • trunk/psModules/src/objects/pmSourceFitModel.c

    r6960 r7311  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-04-23 01:07:51 $
     8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-03 01:02:08 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    515515    psTrace (__func__, 5, "fitting function\n");
    516516    fitStatus = psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, pmModelFitSet);
     517    if (!fitStatus) {
     518        psError(PS_ERR_UNKNOWN, false, "Failed to fit model\n");
     519    }
    517520
    518521    // parameter errors from the covariance matrix
  • trunk/psModules/src/objects/pmSourceIO.c

    r7306 r7311  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-03 00:40:28 $
     5 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-03 01:02:08 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5757}
    5858
    59 // Given a FITS file pointer, read the table of object data
     59// Given a FITS file pointer, write the table of object data
    6060bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file)
    6161{
     
    6464
    6565    if (view->chip == -1) {
    66         pmFPAWriteObjects (fpa, view, file);
     66        if (!pmFPAWriteObjects (fpa, view, file)) {
     67            psError(PS_ERR_IO, false, "Failed to write objects from fpa");
     68            return false;
     69        }
    6770        return true;
    6871    }
    6972
    7073    if (view->chip >= fpa->chips->n) {
     74        psError(PS_ERR_UNKNOWN, false, "Writing chip == %d (>= chips->n == %d)", view->chip, fpa->chips->n);
    7175        return false;
    7276    }
     
    7478
    7579    if (view->cell == -1) {
    76         pmChipWriteObjects (chip, view, file);
     80        if (!pmChipWriteObjects (chip, view, file)) {
     81            psError(PS_ERR_IO, false, "Failed to write objects from chip");
     82            return false;
     83        }
    7784        return true;
    7885    }
    7986
    8087    if (view->cell >= chip->cells->n) {
     88        psError(PS_ERR_UNKNOWN, false, "Writing cell == %d (>= cells->n == %d)",
     89                view->cell, chip->cells->n);
    8190        return false;
    8291    }
     
    8493
    8594    if (view->readout == -1) {
    86         pmCellWriteObjects (cell, view, file);
     95        if (!pmCellWriteObjects (cell, view, file)) {
     96            psError(PS_ERR_IO, false, "Failed to write objects from cell");
     97            return false;
     98        }
     99
    87100        return true;
    88101    }
    89102
    90103    if (view->readout >= cell->readouts->n) {
     104        psError(PS_ERR_UNKNOWN, false, "Writing readout == %d (>= readouts->n == %d)",
     105                view->readout, cell->readouts->n);
    91106        return false;
    92107    }
    93108    pmReadout *readout = cell->readouts->data[view->readout];
    94109
    95     pmReadoutWriteObjects (readout, view, file);
     110    if (!pmReadoutWriteObjects (readout, view, file)) {
     111        psError(PS_ERR_IO, false, "Failed to write objects from readout %d", view->readout);
     112        return false;
     113    }
     114
    96115    return true;
    97116}
     
    104123
    105124        pmChip *chip = fpa->chips->data[i];
    106         pmChipWriteObjects (chip, view, file);
     125        if (!pmChipWriteObjects (chip, view, file)) {
     126            psError(PS_ERR_IO, false, "Failed to write %dth chip", i);
     127            return false;
     128        }
    107129    }
    108130    return true;
     
    116138
    117139        pmCell *cell = chip->cells->data[i];
    118         pmCellWriteObjects (cell, view, file);
     140        if (!pmCellWriteObjects (cell, view, file)) {
     141            psError(PS_ERR_IO, false, "Failed to write %dth cell", i);
     142            return false;
     143        }
    119144    }
    120145    return true;
     
    128153
    129154        pmReadout *readout = cell->readouts->data[i];
    130         pmReadoutWriteObjects (readout, view, file);
     155        if (!pmReadoutWriteObjects (readout, view, file)) {
     156            psError(PS_ERR_IO, false, "Failed to write %dth readout", i);
     157            return false;
     158        }
    131159    }
    132160    return true;
     
    181209        psMetadataCopy (outhead, updates);
    182210
    183         pmSourcesWriteCMP (sources, filename, outhead);
     211        bool status = pmSourcesWriteCMP (sources, filename, outhead);
    184212        psFree (outhead);
    185213        psFree (filename);
     214
     215        if (!status) {
     216            psError(PS_ERR_IO, false, "Failed to write CMP file\n");
     217            return false;
     218        }
    186219        break;
    187220
  • trunk/psModules/src/objects/pmSourceIO_CMP.c

    r7306 r7311  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-03 00:40:46 $
     5 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-03 01:02:08 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6969
    7070    psFits *fits = psFitsOpen (filename, "w");
    71     psFitsWriteBlank(fits, header);
    72     psFitsClose (fits);
     71    if (fits == NULL) {
     72        psError(PS_ERR_IO, false, "can't open output file for write %s\n", filename);
     73        return false;
     74    }
     75    if (!psFitsWriteBlank(fits, header)) {
     76        psError(PS_ERR_IO, false, "Writing header to %s\n", filename);
     77        (void)psFitsClose(fits);
     78        return false;
     79    }
     80    if (!psFitsClose(fits)) {
     81        const psErrorCode code = psErrorCodeLast();
     82
     83        if (code == PS_ERR_BAD_FITS) {
     84            psErrorClear();
     85        } else {
     86            psError(PS_ERR_IO, false, "Closing %s\n", filename);
     87            return false;
     88        }
     89    }
    7390
    7491    // re-open, add data to end of file
    7592    FILE *f = fopen (filename, "a+");
    7693    if (f == NULL) {
    77         psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
     94        psLogMsg ("WriteSourceOBJ", 3, "can't reopen output file for append %s\n", filename);
     95        psError(PS_ERR_IO, false, "can't open output file for output %s\n", filename);
    7896        return false;
    7997    }
  • trunk/psModules/src/pslib/psAdditionals.c

    r7238 r7311  
    6868        fits_get_errstatus (status, fitsErr);
    6969        psError (PS_ERR_IO, true, PS_ERRORTEXT_psFits_WRITE_FAILED, fitsErr);
    70         exit (2);
     70        return false;
    7171    }
    7272
  • trunk/psModules/src/pslib/psImageUnbin.c

    r6872 r7311  
    143143        }
    144144        // Nx,Ny
    145         V = vIn[nx-1][ny-1];
     145        V = vIn[ny-1][nx-1];
    146146        for (int iy = ny*DY - dy; iy < Ny; iy++)
    147147        {
     
    161161static int MAX_SAMPLE_PIXELS;
    162162
    163 void psImageClippedStatsInit (int nMax)
     163void psImageClippedStatsInit (int nMax, unsigned long seed)
    164164{
    165165
    166166    MAX_SAMPLE_PIXELS = nMax;
    167167
     168    if (rnd && seed) {
     169        psFree(rnd);
     170        rnd = NULL;
     171    }
    168172    if (!rnd) {
    169         rnd = psRandomAlloc (PS_RANDOM_TAUS, 0);
     173        rnd = psRandomAlloc (PS_RANDOM_TAUS, seed);
    170174    }
    171175    return;
  • trunk/psModules/src/pslib/psImageUnbin.h

    r6872 r7311  
    77psImage *psImageUnbin (psImage *out, psImage *in, int DX, int DY, int dx, int dy);
    88
    9 void psImageClippedStatsInit (int nMax);
     9void psImageClippedStatsInit (int nMax, unsigned long seed);
    1010void psImageClippedStatsCleanup ();
    1111
  • trunk/psModules/src/pslib/psMetadataItemParse.c

    r6997 r7311  
    228228    return value; } \
    229229
    230 psString psMetadataItemParseString(psMetadataItem *item
     230psString psMetadataItemParseString(const psMetadataItem *item
    231231                                  )
    232232{
  • trunk/psModules/src/pslib/psMetadataItemParse.h

    r6997 r7311  
    44#include "pslib.h"
    55
    6 psBool psMetadataItemParseBool(psMetadataItem *item);
     6psBool psMetadataItemParseBool(const psMetadataItem *item);
    77
    8 psF32 psMetadataItemParseF32(psMetadataItem *item);
    9 psF64 psMetadataItemParseF64(psMetadataItem *item);
     8psF32 psMetadataItemParseF32(const psMetadataItem *item);
     9psF64 psMetadataItemParseF64(const psMetadataItem *item);
    1010
    11 psS8  psMetadataItemParseS8 (psMetadataItem *item);
    12 psS16 psMetadataItemParseS16(psMetadataItem *item);
    13 psS32 psMetadataItemParseS32(psMetadataItem *item);
     11psS8  psMetadataItemParseS8 (const psMetadataItem *item);
     12psS16 psMetadataItemParseS16(const psMetadataItem *item);
     13psS32 psMetadataItemParseS32(const psMetadataItem *item);
    1414
    15 psU8  psMetadataItemParseU8 (psMetadataItem *item);
    16 psU16 psMetadataItemParseU16(psMetadataItem *item);
    17 psU32 psMetadataItemParseU32(psMetadataItem *item);
     15psU8  psMetadataItemParseU8 (const psMetadataItem *item);
     16psU16 psMetadataItemParseU16(const psMetadataItem *item);
     17psU32 psMetadataItemParseU32(const psMetadataItem *item);
    1818
    19 psString psMetadataItemParseString(psMetadataItem *item);
     19psString psMetadataItemParseString(const psMetadataItem *item);
    2020
    2121#endif
Note: See TracChangeset for help on using the changeset viewer.