IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13414


Ignore:
Timestamp:
May 17, 2007, 2:17:12 PM (19 years ago)
Author:
Paul Price
Message:

Added in some error handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmPSF_IO.c

    r13212 r13414  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-05-04 00:53:15 $
     8 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-05-18 00:17:12 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949
    5050    if (view->chip == -1) {
    51         bool exists = pmFPACheckDataStatusForPSFmodel (fpa);
     51        bool exists = pmFPACheckDataStatusForPSFmodel (fpa);
    5252        return exists;
    5353    }
    5454    if (view->chip >= fpa->chips->n) {
    55         psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
     55        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
    5656        return false;
    5757    }
     
    6363    }
    6464    if (view->cell >= chip->cells->n) {
    65         psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
     65        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
    6666        return false;
    6767    }
     
    7474
    7575    if (view->readout >= cell->readouts->n) {
    76         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
     76        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
    7777        return false;
    7878    }
    7979    pmReadout *readout = cell->readouts->data[view->readout];
    8080
    81     bool exists = pmReadoutCheckDataStatusForPSFmodel (readout);
    82     return exists;
     81    return pmReadoutCheckDataStatusForPSFmodel (readout);
    8382}
    8483
     
    8685
    8786    for (int i = 0; i < fpa->chips->n; i++) {
    88         pmChip *chip = fpa->chips->data[i];
    89         if (!chip) continue;
    90         if (pmChipCheckDataStatusForPSFmodel (chip)) return true;
     87        pmChip *chip = fpa->chips->data[i];
     88        if (!chip) continue;
     89        if (pmChipCheckDataStatusForPSFmodel (chip)) return true;
    9190    }
    9291    return false;
     
    9695
    9796    for (int i = 0; i < chip->cells->n; i++) {
    98         pmCell *cell = chip->cells->data[i];
    99         if (!cell) continue;
    100         if (pmCellCheckDataStatusForPSFmodel (cell)) return true;
     97        pmCell *cell = chip->cells->data[i];
     98        if (!cell) continue;
     99        if (pmCellCheckDataStatusForPSFmodel (cell)) return true;
    101100    }
    102101    return false;
     
    106105
    107106    for (int i = 0; i < cell->readouts->n; i++) {
    108         pmReadout *readout = cell->readouts->data[i];
    109         if (!readout) continue;
    110         if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true;
     107        pmReadout *readout = cell->readouts->data[i];
     108        if (!readout) continue;
     109        if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true;
    111110    }
    112111    return false;
     
    118117
    119118    // select the psf of interest
    120     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    121     if (!psf) return false;
    122     return true;
     119    pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");
     120    return psf ? true : false;
    123121}
    124122
     
    129127
    130128    if (view->chip == -1) {
    131         if (!pmFPAWritePSFmodel (fpa, view, file, config)) {
     129        if (!pmFPAWritePSFmodel(fpa, view, file, config)) {
    132130            psError(PS_ERR_IO, false, "Failed to write PSF for fpa");
    133131            return false;
     
    168166
    169167    if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
    170         psError(PS_ERR_IO, false, "Failed to write PSF for readout");
    171         return false;
     168        psError(PS_ERR_IO, false, "Failed to write PSF for readout");
     169        return false;
    172170    }
    173171    return true;
     
    179177
    180178    for (int i = 0; i < fpa->chips->n; i++) {
    181 
    182179        pmChip *chip = fpa->chips->data[i];
    183180        if (!pmChipWritePSFmodel (chip, view, file, config)) {
     
    192189bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    193190{
    194 
    195191    for (int i = 0; i < chip->cells->n; i++) {
    196 
    197192        pmCell *cell = chip->cells->data[i];
    198193        if (!pmCellWritePSFmodel (cell, view, file, config)) {
     
    207202bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    208203{
    209 
    210204    for (int i = 0; i < cell->readouts->n; i++) {
    211 
    212205        pmReadout *readout = cell->readouts->data[i];
    213206        if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
     
    219212}
    220213
    221 // for each Readout (ie, analysed image), we write out: header + table with PSF model parameters, 
     214// for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
    222215// and header + image for the PSF residual images
    223216bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     
    228221    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    229222    if (!psf) {
    230         psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");
    231         return false;
     223        psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");
     224        return false;
    232225    }
    233226
     
    238231    psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
    239232    if (!menu) {
    240         psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
    241         return false;
     233        psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
     234        return false;
    242235    }
    243236    // EXTNAME for table data
    244237    rule = psMetadataLookupStr(&status, menu, "PSF.TABLE");
    245238    if (!rule) {
    246         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
    247         return false;
     239        psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
     240        return false;
    248241    }
    249242    char *tableName = pmFPAfileNameFromRule (rule, file, view);
     
    251244    // write the PSF model parameters in a FITS table
    252245
    253     // we need to write a header for the table, 
     246    // we need to write a header for the table,
    254247    psMetadata *header = psMetadataAlloc();
    255248
     
    264257    // save the dimensions of each parameter
    265258    for (int i = 0; i < nPar; i++) {
    266         char name[9];
     259        char name[9];
    267260        psPolynomial2D *poly = psf->params_NEW->data[i];
    268261        if (poly == NULL) continue;
    269         snprintf (name, 9, "PAR%02d_NX", i);
     262        snprintf (name, 9, "PAR%02d_NX", i);
    270263        psMetadataAddS32 (header, PS_LIST_TAIL, name, 0, "", poly->nX);
    271         snprintf (name, 9, "PAR%02d_NY", i);
     264        snprintf (name, 9, "PAR%02d_NY", i);
    272265        psMetadataAddS32 (header, PS_LIST_TAIL, name, 0, "", poly->nY);
    273266    }
     
    287280        psPolynomial2D *poly = psf->params_NEW->data[i];
    288281        if (poly == NULL) continue; // skip unset parameters (eg, XPOS)
    289         for (int ix = 0; ix < poly->nX; ix++) {
    290             for (int iy = 0; iy < poly->nY; iy++) {
    291 
    292                 psMetadata *row = psMetadataAlloc ();
    293                 psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TERM", 0, "", i);
    294                 psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
    295                 psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
    296                 psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
    297                 psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
    298                 psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->mask[ix][iy]);
    299 
    300                 psArrayAdd (psfTable, 100, row);
    301                 psFree (row);
    302             }
    303         }
    304     }
    305    
     282        for (int ix = 0; ix < poly->nX; ix++) {
     283            for (int iy = 0; iy < poly->nY; iy++) {
     284
     285                psMetadata *row = psMetadataAlloc ();
     286                psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TERM", 0, "", i);
     287                psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
     288                psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
     289                psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
     290                psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
     291                psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->mask[ix][iy]);
     292
     293                psArrayAdd (psfTable, 100, row);
     294                psFree (row);
     295            }
     296        }
     297    }
     298
    306299    // write an empty FITS segment if we have no PSF information
    307300    if (psfTable->n == 0) {
    308         // XXX this is probably an error (if we have a PSF, how do we have no data?)
     301        // XXX this is probably an error (if we have a PSF, how do we have no data?)
    309302        psFitsWriteBlank (file->fits, header, tableName);
    310303    } else {
    311         psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName);
    312         if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {
    313             psError(PS_ERR_IO, false, "writing psf table data %s\n", tableName);
    314             psFree (tableName);
    315             psFree (psfTable);
    316             psFree (header);
    317             return false;
    318         }
     304        psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName);
     305        if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {
     306            psError(PS_ERR_IO, false, "writing psf table data %s\n", tableName);
     307            psFree (tableName);
     308            psFree (psfTable);
     309            psFree (header);
     310            return false;
     311        }
    319312    }
    320313    psFree (tableName);
     
    325318    rule = psMetadataLookupStr(&status, menu, "PSF.RESID");
    326319    if (!rule) {
    327         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
    328         return false;
     320        psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
     321        return false;
    329322    }
    330323    char *imageName = pmFPAfileNameFromRule (rule, file, view);
    331324
    332     // write the residual images (3D) 
     325    // write the residual images (3D)
    333326    header = psMetadataAlloc ();
    334327    if (psf->residuals == NULL) {
    335         // set some header keywords to make it clear there are no residuals?
     328        // set some header keywords to make it clear there are no residuals?
    336329        psFitsWriteBlank (file->fits, header, imageName);
    337         psFree (imageName);
     330        psFree (imageName);
    338331        psFree (header);
    339332        return true;
     
    348341    // this call creates an extension with NAXIS3 = 3
    349342    if (psf->residuals->Rx) {
    350         // this call creates an extension with NAXIS3 = 3
    351         psArray *images = psArrayAllocEmpty (3);
    352         psArrayAdd (images, 1, psf->residuals->Ro);
    353         psArrayAdd (images, 1, psf->residuals->Rx);
    354         psArrayAdd (images, 1, psf->residuals->Ry);
    355 
    356         psFitsWriteImageCube (file->fits, header, images, imageName);
    357         psFree (images);
     343        // this call creates an extension with NAXIS3 = 3
     344        psArray *images = psArrayAllocEmpty (3);
     345        psArrayAdd (images, 1, psf->residuals->Ro);
     346        psArrayAdd (images, 1, psf->residuals->Rx);
     347        psArrayAdd (images, 1, psf->residuals->Ry);
     348
     349        psFitsWriteImageCube (file->fits, header, images, imageName);
     350        psFree (images);
    358351    } else {
    359         // this call creates an extension with NAXIS3 = 1
    360         psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, imageName);
    361     }
    362  
     352        // this call creates an extension with NAXIS3 = 1
     353        psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, imageName);
     354    }
     355
    363356    psFree (imageName);
    364357    psFree (header);
     
    373366    psPolynomial4D *poly = psf->ApTrend;
    374367    for (int ix = 0; ix < poly->nX; ix++) {
    375         for (int iy = 0; iy < poly->nY; iy++) {
    376 
    377             row = psMetadataAlloc ();
    378             psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
    379             psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
    380             psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
    381             psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
    382             psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->mask[ix][iy]);
    383 
    384             psArrayAdd (psfTable, 100, row);
    385             psFree (row);
    386         }
     368        for (int iy = 0; iy < poly->nY; iy++) {
     369
     370            row = psMetadataAlloc ();
     371            psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
     372            psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
     373            psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
     374            psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
     375            psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->mask[ix][iy]);
     376
     377            psArrayAdd (psfTable, 100, row);
     378            psFree (row);
     379        }
    387380    }
    388381# endif
    389382}
    390383
    391 // XXX add in error handling
    392384bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    393385{
     
    396388
    397389    if (view->chip == -1) {
    398         pmFPAReadPSFmodel (fpa, view, file, config);
    399         return true;
     390        return pmFPAReadPSFmodel(fpa, view, file, config);
    400391    }
    401392
    402393    if (view->chip >= fpa->chips->n) {
    403         return false;
     394        psAbort("Programming error: view does not apply to FPA.");
    404395    }
    405396    pmChip *chip = fpa->chips->data[view->chip];
    406397
    407398    if (view->cell == -1) {
    408         pmChipReadPSFmodel (chip, view, file, config);
    409         return true;
     399        return pmChipReadPSFmodel(chip, view, file, config);
    410400    }
    411401
    412402    if (view->cell >= chip->cells->n) {
    413         return false;
     403        psAbort("Programming error: view does not apply to FPA.");
    414404    }
    415405    pmCell *cell = chip->cells->data[view->cell];
    416406
    417407    if (view->readout == -1) {
    418         pmCellReadPSFmodel (cell, view, file, config);
    419         return true;
     408        return pmCellReadPSFmodel(cell, view, file, config);
    420409    }
    421410
    422411    if (view->readout >= cell->readouts->n) {
    423         return false;
     412        psAbort("Programming error: view does not apply to FPA.");
    424413    }
    425414    pmReadout *readout = cell->readouts->data[view->readout];
    426415
    427     pmReadoutReadPSFmodel (readout, view, file, config);
    428     return true;
     416    return pmReadoutReadPSFmodel(readout, view, file, config);
    429417}
    430418
     
    432420bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    433421{
    434 
     422    bool success = true;                // Was everything successful?
    435423    for (int i = 0; i < fpa->chips->n; i++) {
    436 
    437424        pmChip *chip = fpa->chips->data[i];
    438         pmChipReadPSFmodel (chip, view, file, config);
    439     }
    440     return true;
     425        success &= pmChipReadPSFmodel(chip, view, file, config);
     426    }
     427    return success;
    441428}
    442429
     
    444431bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    445432{
    446 
     433    bool success = true;                // Was everything successful?
    447434    for (int i = 0; i < chip->cells->n; i++) {
    448 
    449435        pmCell *cell = chip->cells->data[i];
    450         pmCellReadPSFmodel (cell, view, file, config);
    451     }
    452     return true;
     436        success &= pmCellReadPSFmodel (cell, view, file, config);
     437    }
     438    return success;
    453439}
    454440
     
    456442bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    457443{
    458 
     444    bool success = true;                // Was everything successful?
    459445    for (int i = 0; i < cell->readouts->n; i++) {
    460 
    461446        pmReadout *readout = cell->readouts->data[i];
    462         pmReadoutReadPSFmodel (readout, view, file, config);
    463     }
    464     return true;
    465 }
    466 
    467 // for each Readout (ie, analysed image), we write out: header + table with PSF model parameters, 
     447        success &= pmReadoutReadPSFmodel(readout, view, file, config);
     448    }
     449    return success;
     450}
     451
     452// for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
    468453// and header + image for the PSF residual images
    469 bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    470 {
    471     bool status; 
     454bool pmReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     455{
     456    bool status;
    472457    char *rule = NULL;
    473458    psMetadata *header = NULL;
     
    476461    psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES");
    477462    if (!menu) {
    478         psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
    479         return false;
     463        psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");
     464        return false;
    480465    }
    481466    // EXTNAME for table data
    482467    rule = psMetadataLookupStr(&status, menu, "PSF.TABLE");
    483468    if (!rule) {
    484         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
    485         return false;
     469        psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");
     470        return false;
    486471    }
    487472    char *tableName = pmFPAfileNameFromRule (rule, file, view);
     
    489474    rule = psMetadataLookupStr(&status, menu, "PSF.RESID");
    490475    if (!rule) {
    491         psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
    492         return false;
     476        psError(PS_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");
     477        return false;
    493478    }
    494479    char *imageName = pmFPAfileNameFromRule (rule, file, view);
     
    498483    // since we have read the IMAGE header, the TABLE header should exist
    499484    if (!psFitsMoveExtName (file->fits, tableName)) {
    500         psAbort("cannot find data extension %s in %s", tableName, file->filename);
     485        psAbort("cannot find data extension %s in %s", tableName, file->filename);
    501486    }
    502487
     
    521506    // load the dimensions of each parameter
    522507    for (int i = 0; i < nPar; i++) {
    523         char name[9];
    524         snprintf (name, 9, "PAR%02d_NX", i);
     508        char name[9];
     509        snprintf (name, 9, "PAR%02d_NX", i);
    525510        int nXorder = psMetadataLookupS32 (&status, header, name);
    526         snprintf (name, 9, "PAR%02d_NY", i);
     511        snprintf (name, 9, "PAR%02d_NY", i);
    527512        int nYorder = psMetadataLookupS32 (&status, header, name);
    528         psf->params_NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
     513        psf->params_NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
    529514    }
    530515
     
    543528    // fill in the matching psf->params entries
    544529    for (int i = 0; i > table->n; i++) {
    545         psMetadata *row = table->data[i];
    546         int iPar = psMetadataLookupS32 (&status, row, "MODEL_TERM");
    547         int xPow = psMetadataLookupS32 (&status, row, "X_POWER");
    548         int yPow = psMetadataLookupS32 (&status, row, "Y_POWER");
    549         // XXX sanity check here
     530        psMetadata *row = table->data[i];
     531        int iPar = psMetadataLookupS32 (&status, row, "MODEL_TERM");
     532        int xPow = psMetadataLookupS32 (&status, row, "X_POWER");
     533        int yPow = psMetadataLookupS32 (&status, row, "Y_POWER");
     534        // XXX sanity check here
    550535
    551536        psPolynomial2D *poly = psf->params_NEW->data[iPar];
    552537
    553         poly->coeff[xPow][yPow]    = psMetadataLookupF32 (&status, row, "VALUE");
    554         poly->coeffErr[xPow][yPow] = psMetadataLookupF32 (&status, row, "ERROR");
    555         poly->mask[xPow][yPow]     = psMetadataLookupU8  (&status, row, "MASK");
     538        poly->coeff[xPow][yPow]    = psMetadataLookupF32 (&status, row, "VALUE");
     539        poly->coeffErr[xPow][yPow] = psMetadataLookupF32 (&status, row, "ERROR");
     540        poly->mask[xPow][yPow]     = psMetadataLookupU8  (&status, row, "MASK");
    556541    }
    557542    psFree (header);
     
    562547    // since we have read the IMAGE header, the TABLE header should exist
    563548    if (!psFitsMoveExtName (file->fits, imageName)) {
    564         psAbort("cannot find data extension %s in %s", imageName, file->filename);
     549        psAbort("cannot find data extension %s in %s", imageName, file->filename);
    565550    }
    566551
     
    569554    if (Naxis != 0) {
    570555
    571         int Nx = psMetadataLookupS32 (&status, header, "NAXIS1");
    572         int Ny = psMetadataLookupS32 (&status, header, "NAXIS2");
    573         int Nz = psMetadataLookupS32 (&status, header, "NAXIS3");
    574 
    575         int xBin  = psMetadataLookupS32 (&status, header, "XBIN");
    576         int yBin  = psMetadataLookupS32 (&status, header, "YBIN");
    577 
    578         int xSize = Nx / xBin;
    579         int ySize = Ny / yBin;
    580 
    581         psf->residuals = pmResidualsAlloc (xSize, ySize, xBin, yBin);
    582 
    583         psf->residuals->xCenter = psMetadataLookupS32 (&status, header, "XCENTER");
    584         psf->residuals->yCenter = psMetadataLookupS32 (&status, header, "YCENTER");
    585 
    586         psRegion fullImage = {0, 0, 0, 0};
    587         psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels
    588         if (Nz > 1) {
    589             assert (Nz == 3);
    590             psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels
    591             psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels
    592         }
     556        int Nx = psMetadataLookupS32 (&status, header, "NAXIS1");
     557        int Ny = psMetadataLookupS32 (&status, header, "NAXIS2");
     558        int Nz = psMetadataLookupS32 (&status, header, "NAXIS3");
     559
     560        int xBin  = psMetadataLookupS32 (&status, header, "XBIN");
     561        int yBin  = psMetadataLookupS32 (&status, header, "YBIN");
     562
     563        int xSize = Nx / xBin;
     564        int ySize = Ny / yBin;
     565
     566        psf->residuals = pmResidualsAlloc (xSize, ySize, xBin, yBin);
     567
     568        psf->residuals->xCenter = psMetadataLookupS32 (&status, header, "XCENTER");
     569        psf->residuals->yCenter = psMetadataLookupS32 (&status, header, "YCENTER");
     570
     571        psRegion fullImage = {0, 0, 0, 0};
     572        psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels
     573        if (Nz > 1) {
     574            assert (Nz == 3);
     575            psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels
     576            psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels
     577        }
    593578    }
    594579
Note: See TracChangeset for help on using the changeset viewer.