IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 15, 2005, 3:10:36 PM (21 years ago)
Author:
gusciora
Message:

There are a lot of changes here required by the new SDRS. Most changes
involve the new definitions of the psAstrometry types. Not all tests work
correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmAstrometry.c

    r4754 r4770  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-08-11 00:03:51 $
     10 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-08-16 01:10:34 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pmAstrometry.h"
    2424
    25 psDB wow;
    26 
    2725/*****************************************************************************
    28 checkValidImageCoords(): this is a private function which simply
    29 determines if the supplied x,y coordinates are in the range for the supplied
    30 psImage.
     26checkValidImageCoords(): this is a private function which simply determines if
     27the supplied x,y coordinates are in the range for the supplied psImage.
     28 
     29XXX: What about col0 and row0
     30XXX: This should return a psBool.
    3131 *****************************************************************************/
    32 /*
    3332static psS32 checkValidImageCoords(double x,
    3433                                   double y,
     
    3635{
    3736    PS_ASSERT_IMAGE_NON_NULL(tmpImage, 0);
    38  
     37
    3938    if ((x < 0.0) || (x > (double)tmpImage->numCols) ||
    4039            (y < 0.0) || (y > (double)tmpImage->numRows)) {
    4140        return (0);
    4241    }
    43  
     42
    4443    return (1);
    4544}
    46 */
    47 /*
    48 static void FPAFree(psFPA* fpa)
     45
     46/******************************************************************************
     47XXX: Is this the correct way to free metadata?
     48XXX: Is this the correct way to free database structs?
     49 *****************************************************************************/
     50
     51static void FPAFree(pmFPA *fpa)
    4952{
    5053    if (fpa != NULL) {
    51         psFree(fpa->chips);
    52         psFree(fpa->grommit);
    53         psFree(fpa->exposure);
    54         psFree(fpa->metadata);
    5554        psFree(fpa->fromTangentPlane);
    5655        psFree(fpa->toTangentPlane);
    57         psFree(fpa->pattern);
    58         psFree(fpa->colorPlus);
    59         psFree(fpa->colorMinus);
    6056        psFree(fpa->projection);
    61     }
    62 }
    63 */
    64 
    65 /*
    66 static void chipFree(psChip* chip)
     57        psFree(fpa->concepts);
     58        psFree(fpa->analysis);
     59        psFree(fpa->camera);
     60        psFree(fpa->chips);
     61        psFree(fpa->header);
     62        psFree(fpa->db);
     63    }
     64}
     65
     66static void chipFree(pmChip* chip)
    6767{
    6868    if (chip != NULL) {
    69         psFree(chip->cells);
    70         psFree(chip->metadata);
    7169        psFree(chip->toFPA);
    7270        psFree(chip->fromFPA);
    73     }
    74 }
    75 */
    76 
    77 /*
    78 static void cellFree(psCell* cell)
     71        psFree(chip->concepts);
     72        psFree(chip->analysis);
     73        psFree(chip->cells);
     74        psFree(chip->parent);
     75        psFree(chip->extname);
     76        psFree(chip->pixels);
     77        psFree(chip->header);
     78    }
     79}
     80
     81static void cellFree(pmCell *cell)
    7982{
    8083    if (cell != NULL) {
     84        psFree(cell->toChip);
     85        psFree(cell->toFPA);
     86        psFree(cell->toSky);
     87        psFree(cell->concepts);
     88        psFree(cell->analysis);
    8189        psFree(cell->readouts);
    82         psFree(cell->metadata);
    83         psFree(cell->toChip);
    84         psFree(cell->fromChip);
    85         psFree(cell->toFPA);
    86         psFree(cell->toTP);
    87         psFree(cell->toSky);
    88     }
    89 }
    90 */
    91 
    92 static void readoutFree(psReadout* readout)
     90        psFree(cell->parent);
     91        psFree(cell->extname);
     92        psFree(cell->pixels);
     93        psFree(cell->header);
     94    }
     95}
     96
     97static void readoutFree(pmReadout *readout)
    9398{
    9499    if (readout != NULL) {
    95100        psFree(readout->image);
    96101        psFree(readout->mask);
    97         psFree(readout->objects);
    98         psFree(readout->metadata);
    99     }
    100 }
    101 
    102 /*
    103 static void observatoryFree(psObservatory* obs)
    104 {
    105     if (obs != NULL) {
    106         psFree(obs->name);
    107     }
    108 }
    109 */
    110 /*
    111 static void exposureFree(psExposure* exp)
    112 {
    113     if (exp != NULL) {
    114         psFree(exp->time);
    115         psFree(exp->observatory);
    116         psFree(exp->cameraName);
    117         psFree(exp->telescopeName);
    118     }
    119 }
    120 */
    121 /*
    122 static void fixedPatternFree(psFixedPattern* fp)
    123 {
    124     if (fp != NULL) {
    125         for (psS32 i = 0; i < fp->p_ps_xRows; i++) {
    126             psFree(fp->x[i]);
    127         }
    128  
    129         for (psS32 j = 0; j < fp->p_ps_yRows; j++) {
    130             psFree(fp->y[j]);
    131         }
    132  
    133         psFree(fp->x);
    134         psFree(fp->y);
    135     }
    136 }
    137 */
     102        psFree(readout->analysis);
     103        psFree(readout->concepts);
     104        psFree(readout->parent);
     105    }
     106}
     107
     108
     109pmReadout *pmReadoutAlloc(pmCell *cell)
     110{
     111    pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
     112
     113    tmpReadout->col0 = -1;
     114    tmpReadout->row0 = -1;
     115    tmpReadout->colBins = -1;
     116    tmpReadout->rowBins = -1;
     117    tmpReadout->image = NULL;
     118    tmpReadout->mask = NULL;
     119    tmpReadout->analysis = psMetadataAlloc();
     120    tmpReadout->concepts = psMetadataAlloc();
     121    tmpReadout->parent = cell;
     122
     123    if (cell != NULL) {
     124        cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
     125    }
     126    psMemSetDeallocator(tmpReadout, (psFreeFunc) readoutFree);
     127    return(tmpReadout);
     128}
     129
     130pmCell *pmCellAlloc(pmChip *chip)
     131{
     132    pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
     133
     134    tmpCell->col0 = -1;
     135    tmpCell->row0 = -1;
     136    tmpCell->toChip = NULL;
     137    tmpCell->toFPA = NULL;
     138    tmpCell->toSky = NULL;
     139    tmpCell->analysis = psMetadataAlloc();
     140    tmpCell->concepts = psMetadataAlloc();
     141    tmpCell->readouts = psArrayAlloc(0);
     142    tmpCell->parent = chip;
     143    if (chip != NULL) {
     144        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
     145    }
     146    tmpCell->valid = false;
     147    tmpCell->extname = NULL;
     148    tmpCell->pixels = NULL;
     149    tmpCell->header = NULL;
     150
     151    psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
     152    return(tmpCell);
     153}
     154
     155pmChip *pmChipAlloc(pmFPA *fpa)
     156{
     157    pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
     158
     159    tmpChip->col0 = -1;
     160    tmpChip->row0 = -1;
     161    tmpChip->toFPA = NULL;
     162    tmpChip->fromFPA = NULL;
     163    tmpChip->concepts = psMetadataAlloc();
     164    tmpChip->analysis = psMetadataAlloc();
     165    tmpChip->cells = psArrayAlloc(0);
     166    tmpChip->parent = fpa;
     167    if (fpa != NULL) {
     168        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
     169    }
     170    tmpChip->valid = false;
     171    tmpChip->extname = NULL;
     172    tmpChip->pixels = NULL;
     173    tmpChip->header = NULL;
     174
     175    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
     176    return(tmpChip);
     177}
     178
     179pmFPA *pmFPAAlloc(
     180    const psMetadata *camera,
     181    psDB *db)
     182{
     183    pmFPA *tmpFPA = (pmFPA *) psAlloc(sizeof(pmFPA));
     184
     185    tmpFPA->fromTangentPlane = NULL;
     186    tmpFPA->toTangentPlane = NULL;
     187    tmpFPA->projection = NULL;
     188    tmpFPA->concepts = psMetadataAlloc();
     189    tmpFPA->analysis = psMetadataAlloc();
     190    tmpFPA->camera = camera;
     191    tmpFPA->chips = psArrayAlloc(0);
     192    tmpFPA->header = NULL;
     193    tmpFPA->db = db;
     194
     195    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
     196    return(tmpFPA);
     197}
     198
     199bool cellCheckParents(pmCell *cell)
     200{
     201    if (cell == NULL) {
     202        return(true);
     203    }
     204    psBool flag = true;
     205
     206    for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
     207        pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
     208        PS_ASSERT_PTR_NON_NULL(tmpReadout, false);
     209        if (tmpReadout->parent != cell) {
     210            tmpReadout->parent = cell;
     211            flag = false;
     212        }
     213    }
     214    return(flag);
     215}
     216
     217bool chipCheckParents(pmChip *chip)
     218{
     219    if (chip == NULL) {
     220        return(true);
     221    }
     222    psBool flag = true;
     223
     224    for (psS32 i = 0 ; i < chip->cells->n ; i++) {
     225        pmCell *tmpCell = (pmCell *) chip->cells->data[i];
     226        PS_ASSERT_PTR_NON_NULL(tmpCell, false);
     227        if (tmpCell->parent != chip) {
     228            tmpCell->parent = chip;
     229            flag = false;
     230        }
     231
     232        flag &= cellCheckParents(tmpCell);
     233    }
     234    return(flag);
     235}
     236
     237bool pmFPACheckParents(pmFPA *fpa)
     238{
     239    if (fpa == NULL) {
     240        return(true);
     241    }
     242    psBool flag = true;
     243
     244    for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
     245        pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
     246        PS_ASSERT_PTR_NON_NULL(tmpChip, false);
     247        if (tmpChip->parent != fpa) {
     248            tmpChip->parent = fpa;
     249            flag = false;
     250        }
     251
     252        flag &= chipCheckParents(tmpChip);
     253    }
     254    return(flag);
     255}
     256
     257
     258
     259// HEY
    138260/*****************************************************************************/
    139261/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    140262/*****************************************************************************/
    141263
    142 /*
    143  * XXX: Verify that you interpreted the SDR correctly.
    144  *
    145  * XXX: This assumes that x,y must be of type F64
    146  */
    147 /*
    148 psFixedPattern* psFixedPatternAlloc(double x0,
    149                                    double y0,
    150                                    double xScale,
    151                                    double yScale,
    152                                    const psImage *x,
    153                                    const psImage *y)
    154 {
    155    psFixedPattern *tmp;
    156    psS32 i;
    157    psS32 j;
    158  
    159    PS_ASSERT_IMAGE_NON_NULL(x, NULL);
    160    PS_ASSERT_IMAGE_NON_NULL(y, NULL);
    161    PS_ASSERT_IMAGE_TYPE(x, PS_TYPE_F64, NULL);
    162    PS_ASSERT_IMAGE_TYPE(y, PS_TYPE_F64, NULL);
    163  
    164    tmp = (psFixedPattern *) psAlloc(sizeof(psFixedPattern));
    165    // XXX: Is this correct?
    166    tmp->nX = (x->numCols * x->numRows);
    167    tmp->nY = (y->numCols * y->numRows);
    168    tmp->x0 = x0;
    169    tmp->y0 = y0;
    170    tmp->xScale = xScale;
    171    tmp->yScale = yScale;
    172    tmp->p_ps_xRows = x->numRows;
    173    tmp->p_ps_xCols = x->numCols;
    174    tmp->p_ps_yRows = y->numRows;
    175    tmp->p_ps_yCols = y->numCols;
    176    tmp->x = (double **) psAlloc(x->numRows * sizeof(double *));
    177    for (i=0;i<x->numRows;i++) {
    178        (tmp->x)[i] = (double *) psAlloc(x->numCols * sizeof(double));
    179    }
    180    for (i=0;i<x->numRows;i++) {
    181        for (j=0;j<x->numCols;j++) {
    182            (tmp->x)[i][j] = x->data.F64[i][j];
    183        }
    184    }
    185  
    186    tmp->y = (double **) psAlloc(y->numRows * sizeof(double *));
    187    for (i=0;i<y->numRows;i++) {
    188        (tmp->y)[i] = (double *) psAlloc(y->numCols * sizeof(double));
    189    }
    190    for (i=0;i<y->numRows;i++) {
    191        for (j=0;j<y->numCols;j++) {
    192            (tmp->y)[i][j] = y->data.F64[i][j];
    193        }
    194    }
    195  
    196    psMemSetDeallocator(tmp,(psFreeFunc)fixedPatternFree);
    197  
    198    return(tmp);
    199 }
    200 */
    201 /*
    202 psExposure* psExposureAlloc(double ra,
    203                             double dec,
    204                             double hourAngle,
    205                             double zenithDistance,
    206                             double azimuth,
    207                             const psTime* time,
    208                             float rotAngle,
    209                             float temperature,
    210                             float pressure,
    211                             float humidity,
    212                             float exposureTime,
    213                             float wavelength,
    214                             const psObservatory* observatory)
    215 {
    216     PS_ASSERT_PTR_NON_NULL(observatory, NULL);
    217  
    218     psExposure* exp = psAlloc(sizeof(psExposure));
    219     *(double *)&exp->ra = ra;
    220     *(double *)&exp->dec = dec;
    221     *(double *)&exp->hourAngle = hourAngle;
    222     *(double *)&exp->zenithDistance = zenithDistance;
    223     *(double *)&exp->azimuth = azimuth;
    224     *(float *)&exp->rotAngle = rotAngle;
    225     *(float *)&exp->temperature = temperature;
    226     *(float *)&exp->pressure = pressure;
    227     *(float *)&exp->humidity = humidity;
    228     *(float *)&exp->exposureTime = exposureTime;
    229     *(float *)&exp->wavelength = wavelength;
    230  
    231     exp->time = psMemIncrRefCounter((psPtr)time);
    232     exp->observatory = psMemIncrRefCounter((psPtr)observatory);
    233  
    234     // XXX: how is this value derived?
    235     *(double *)&exp->lst = psTimeToLMST((psTime*)time,observatory->longitude);
    236     *(float *)&exp->positionAngle = 0.0f; // XXX: need input, see Bug #207
    237     *(float *)&exp->parallacticAngle = 0.0f; // XXX: need input, see Bug #207
    238     *(float *)&exp->airmass = 0.0f; // XXX: needs calculation!  = slaAirmas(zenithDistance);
    239     *(float *)&exp->parallacticFactor = 0.0f;
    240     exp->cameraName = NULL;
    241     exp->telescopeName = NULL;
    242  
    243     psMemSetDeallocator(exp,(psFreeFunc)exposureFree);
    244  
    245     return exp;
    246 }
    247 */
    248 /*
    249 psObservatory* psObservatoryAlloc(const char* name,
    250                                   double latitude,
    251                                   double longitude,
    252                                   double height,
    253                                   double tlr)
    254 {
    255     psObservatory* obs = psAlloc(sizeof(psObservatory));
    256  
    257     if (name == NULL) {
    258         obs->name = NULL;
    259     } else {
    260         obs->name = psAlloc(strlen(name)+1);
    261         strcpy((char*)obs->name, name);
    262     }
    263  
    264     *(double *)&obs->latitude = latitude;
    265     *(double *)&obs->longitude = longitude;
    266     *(double *)&obs->height = height;
    267     *(double *)&obs->tlr = tlr;
    268  
    269     psMemSetDeallocator(obs,(psFreeFunc)observatoryFree);
    270  
    271     return obs;
    272 }
    273 */
    274 /*
    275 psFPA* psFPAAlloc(psS32 nChips,
    276                   const psExposure* exp)
    277 {
    278     PS_ASSERT_INT_NONNEGATIVE(nChips, NULL);
    279  
    280     psFPA* newFPA = psAlloc(sizeof(psFPA));
    281  
    282     // create array of NULL chips of the size nChips
    283     newFPA->chips = psArrayAlloc(nChips);
    284     psPtr* chips = newFPA->chips->data;
    285     for (psS32 i=0;i<nChips;i++) {
    286         chips[i] = NULL;
    287     }
    288     newFPA->chips->n = 0; // per requirement
    289  
    290     newFPA->metadata = NULL;
    291     newFPA->fromTangentPlane = NULL;
    292     newFPA->toTangentPlane = NULL;
    293     newFPA->pattern = NULL;
    294  
    295     if (exp != NULL) {
    296         newFPA->exposure = psMemIncrRefCounter((psExposure*)exp);
    297         newFPA->grommit = psGrommitAlloc(exp);
    298     } else {
    299         newFPA->exposure = NULL;
    300         newFPA->grommit = NULL;
    301     }
    302  
    303     newFPA->colorPlus = NULL;
    304     newFPA->colorMinus = NULL;
    305     newFPA->projection = NULL;
    306  
    307     newFPA->rmsX = 0.0f;
    308     newFPA->rmsY = 0.0f;
    309     newFPA->chi2 = 0.0f;
    310  
    311     psMemSetDeallocator(newFPA,(psFreeFunc)FPAFree);
    312  
    313     return newFPA;
    314 }
    315 */
    316 /*
    317  * psChip constructor
    318  */
    319 /*
    320 psChip* psChipAlloc(psS32 nCells,
    321                     psFPA *parentFPA)
    322 {
    323     PS_ASSERT_INT_NONNEGATIVE(nCells, NULL);
    324  
    325     psChip* chip = psAlloc(sizeof(psChip));
    326  
    327     // create array of NULL psCells
    328     int n = (nCells > 0) ? nCells : 1;
    329     chip->cells = psArrayAlloc(n);
    330     psPtr* cells = chip->cells->data;
    331     for (psS32 i=0;i<n;i++) {
    332         cells[i] = NULL;
    333     }
    334     chip->cells->n = 0; // per requirement
    335  
    336     *(int*)&chip->row0 = 0;
    337     *(int*)&chip->col0 = 0;
    338  
    339     chip->metadata = NULL;
    340  
    341     chip->toFPA = NULL;
    342     chip->fromFPA = NULL;
    343  
    344     chip->parent = parentFPA;
    345  
    346     psMemSetDeallocator(chip,(psFreeFunc)chipFree);
    347  
    348     return chip;
    349  
    350 }
    351 */
    352 /*
    353  * psCell constructor
    354  */
    355 /*
    356 psCell* psCellAlloc(psS32 nReadouts,
    357                     psChip* parentChip)
    358 {
    359     PS_ASSERT_INT_NONNEGATIVE(nReadouts, NULL);
    360  
    361     psCell* cell = psAlloc(sizeof(psCell));
    362  
    363     // create array of NULL psReadouts
    364     int n = (nReadouts > 0) ? nReadouts : 1;
    365     cell->readouts = psArrayAlloc(n);
    366     psPtr* readouts = cell->readouts->data;
    367     for (psS32 i=0;i<n;i++) {
    368         readouts[i] = NULL;
    369     }
    370     cell->readouts->n = 0; // per requirement
    371  
    372     *(int*)&cell->row0 = 0;
    373     *(int*)&cell->col0 = 0;
    374  
    375     cell->metadata = NULL;
    376  
    377     cell->toChip = NULL;
    378     cell->fromChip = NULL;
    379     cell->toFPA = NULL;
    380     cell->toTP = NULL;
    381     cell->toSky = NULL;
    382  
    383     cell->parent = parentChip;
    384  
    385     psMemSetDeallocator(cell,(psFreeFunc)cellFree);
    386  
    387     return cell;
    388  
    389  
    390 }
    391 */
    392 
    393 psReadout *pmReadoutAlloc(pmCell *cell)
    394 {
    395     psReadout* readout = psAlloc(sizeof(psReadout));
    396 
    397     *(psU32*)&readout->colBins = 1;
    398     *(psU32*)&readout->rowBins = 1;
    399     *(psU32*)&readout->rowParity = 0;
    400     *(psU32*)&readout->colParity = 0;
    401     *(psS32*)&readout->col0 = 0;
    402     *(psS32*)&readout->row0 = 0;
    403 
    404     readout->image = NULL;
    405     readout->mask = NULL;
    406     readout->objects = NULL;
    407     readout->metadata = NULL;
    408 
    409     psMemSetDeallocator(readout,(psFreeFunc)readoutFree);
    410 
    411     return readout;
    412 }
    413 
    414 /*
    415 psGrommit* psGrommitAlloc(const psExposure* exp)
    416 {
    417     PS_ASSERT_PTR_NON_NULL(exp, NULL);
    418  
    419     psSphere* polarMotion = p_psTimeGetPoleCoords(exp->time);
    420  
    421     psGrommit* grommit = (psGrommit* ) psAlloc(sizeof(psGrommit));
    422  
    423     *(double*)&grommit->latitude = exp->observatory->latitude;
    424     *(double*)&grommit->longitude = exp->observatory->longitude;
    425     *(double*)&grommit->height = exp->observatory->height;
    426     *(double*)&grommit->abberationMag = 0.0; // XXX: need to figure out what to set here.
    427     *(double*)&grommit->temperature = exp->temperature;
    428     *(double*)&grommit->pressure = exp->pressure;
    429     *(double*)&grommit->humidity = exp->humidity;
    430     *(double*)&grommit->wavelength = exp->wavelength;
    431     *(double*)&grommit->lapseRate = exp->observatory->tlr;
    432     *(double*)&grommit->refractA = polarMotion->r; // XXX: need to figure out what to set here too.
    433     *(double*)&grommit->refractB = polarMotion->d; // XXX: need to figure out what to set here too.
    434     *(double*)&grommit->siderealTime = psTimeToMJD(exp->time); // XXX: this is probably not correct
    435  
    436     psFree(polarMotion);
    437  
    438     return (grommit);
    439 }
    440 */
    441 /*
    442 psCell* psCellInFPA(const psPlane* fpaCoord,
    443                     const psFPA* FPA)
     264pmCell* pmCellInFPA(const psPlane* fpaCoord,
     265                    const pmFPA* FPA)
    444266{
    445267    PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
    446268    PS_ASSERT_PTR_NON_NULL(FPA, NULL);
    447  
    448     psChip* tmpChip = NULL;
     269
     270    pmChip* tmpChip = NULL;
    449271    psPlane chipCoord;
    450     psCell* outCell = NULL;
    451  
     272    pmCell* outCell = NULL;
     273
    452274    // Determine which chip contains the fpaCoords.
    453     tmpChip = psChipInFPA(fpaCoord, FPA);
     275    tmpChip = pmChipInFPA(fpaCoord, FPA);
    454276    if (tmpChip == NULL) {
    455277        return(NULL);
    456278    }
    457  
     279
    458280    // Convert to those chip coordinates.
    459281    psCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);
    460  
     282
    461283    // Determine which cell contains those chip coordinates.
    462     outCell = psCellInChip(&chipCoord, tmpChip);
    463  
     284    outCell = pmCellInChip(&chipCoord, tmpChip);
     285
    464286    return (outCell);
    465287}
    466 */
    467 /*
    468 psChip* psChipInFPA(const psPlane* fpaCoord,
    469                     const psFPA* FPA)
     288
     289pmChip* pmChipInFPA(const psPlane* fpaCoord,
     290                    const pmFPA* FPA)
    470291{
    471292    PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
    472293    PS_ASSERT_PTR_NON_NULL(FPA, NULL);
    473294    PS_ASSERT_PTR_NON_NULL(FPA->chips, NULL);
    474  
     295
    475296    psArray* chips = FPA->chips;
    476297    psS32 nChips = chips->n;
    477298    psPlane chipCoord;
    478     psCell *tmpCell = NULL;
    479  
     299    pmCell *tmpCell = NULL;
     300
    480301    // Loop through every chip in this FPA.  Convert the original FPA
    481302    // coordinates to chip coordinates for that chip.  Then, determine if any
    482303    // cells in that chip contain those chip coordinates.
    483  
     304
    484305    for (psS32 i = 0; i < nChips; i++) {
    485         psChip* tmpChip = chips->data[i];
     306        pmChip* tmpChip = chips->data[i];
    486307        PS_ASSERT_PTR_NON_NULL(tmpChip, NULL);
    487308        PS_ASSERT_PTR_NON_NULL(tmpChip->fromFPA, NULL);
    488  
     309
    489310        psPlaneTransformApply(&chipCoord, tmpChip->fromFPA, fpaCoord);
    490  
    491         tmpCell = psCellInChip(&chipCoord, tmpChip);
     311
     312        tmpCell = pmCellInChip(&chipCoord, tmpChip);
    492313        if (tmpCell != NULL) {
    493314            return(tmpChip);
    494315        }
    495316    }
    496  
     317
    497318    // XXX: Print warning here?
    498319    return (NULL);
    499320}
    500 */
    501 /*
    502 psCell* psCellInChip(const psPlane* chipCoord,
    503                      const psChip* chip)
     321
     322
     323pmCell* pmCellInChip(const psPlane* chipCoord,
     324                     const pmChip* chip)
    504325{
    505326    PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
    506327    PS_ASSERT_PTR_NON_NULL(chip, NULL);
    507  
     328
    508329    psPlane cellCoord;
    509330    psArray* cells;
    510  
     331
    511332    cells = chip->cells;
    512333    if (cells == NULL) {
    513334        return NULL;
    514335    }
    515  
     336
    516337    // We loop over each cell in the chip.  We transform the chipCoord into
    517338    // a cellCoord for that cell and determine if that cellCoord is valid.
    518339    // If so, then we return that cell.
    519  
     340
    520341    for (psS32 i = 0; i < cells->n; i++) {
    521         psCell* tmpCell = (psCell* ) cells->data[i];
     342        pmCell* tmpCell = (pmCell* ) cells->data[i];
    522343        PS_ASSERT_PTR_NON_NULL(tmpCell, NULL);
    523         PS_ASSERT_PTR_NON_NULL(tmpCell->fromChip, NULL);
     344
     345        psPlaneTransform *chipToCell = NULL;
     346        if (1 != p_psIsProjectionLinear(tmpCell->toChip)) {
     347            // XXX: Generate warning message.
     348            // XXX: Can we use the following function to derive a transform?
     349            // chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);
     350        } else {
     351            chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
     352        }
     353
     354        PS_ASSERT_PTR_NON_NULL(chipToCell, NULL);
    524355        psArray* readouts = tmpCell->readouts;
    525  
     356
    526357        if (readouts != NULL) {
    527358            for (psS32 j = 0; j < readouts->n; j++) {
    528                 psReadout* tmpReadout = readouts->data[j];
     359                pmReadout* tmpReadout = readouts->data[j];
    529360                PS_ASSERT_READOUT_NON_NULL(tmpReadout, NULL);
    530  
     361
    531362                psPlaneTransformApply(&cellCoord,
    532                                       tmpCell->fromChip,
     363                                      chipToCell,
    533364                                      chipCoord);
    534  
     365
    535366                if (checkValidImageCoords(cellCoord.x,
    536367                                          cellCoord.y,
     
    540371            }
    541372        }
    542     }
    543  
     373        psFree(chipToCell);
     374    }
     375
    544376    return (NULL);
    545377}
    546 */
    547 /*
     378
     379
    548380psPlane* psCoordCellToChip(psPlane* outCoord,
    549381                           const psPlane* inCoord,
    550                            const psCell* cell)
     382                           const pmCell* cell)
    551383{
    552384    PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
    553385    PS_ASSERT_PTR_NON_NULL(cell, NULL);
    554  
     386
    555387    return (psPlaneTransformApply(outCoord, cell->toChip, inCoord));
    556388}
    557 */
    558 /*
     389
     390
    559391psPlane* psCoordChipToFPA(psPlane* outCoord,
    560392                          const psPlane* inCoord,
    561                           const psChip* chip)
     393                          const pmChip* chip)
    562394{
    563395    PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
    564396    PS_ASSERT_PTR_NON_NULL(chip, NULL);
    565  
     397
    566398    return (psPlaneTransformApply(outCoord, chip->toFPA, inCoord));
    567399}
    568 */
    569 /*
     400
     401
     402
    570403psPlane* psCoordFPAToTP(psPlane* outCoord,
    571404                        const psPlane* inCoord,
    572405                        double color,
    573406                        double magnitude,
    574                         const psFPA* fpa)
     407                        const pmFPA* fpa)
    575408{
    576409    PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
    577410    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    578  
     411
    579412    return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord,
    580413                               color, magnitude));
    581414}
    582 */
     415
    583416/*****************************************************************************
    584417XXX: What about units for the (x,y) coords?
    585418 *****************************************************************************/
    586 /*
    587419psSphere* psCoordTPToSky(psSphere* outSphere,
    588420                         const psPlane* tpCoord,
    589                          const psGrommit* grommit)
     421                         const psProjection *projection
     422                        )
    590423{
    591424    PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
    592     PS_ASSERT_PTR_NON_NULL(grommit, NULL);
    593  
     425
    594426    if (outSphere == NULL) {
    595427        outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
    596428    }
    597  
     429
    598430    // XXX: this was done by a SLALIB call -- needs to be reimplemented
    599431    psWarning("Warning!  psCoordTPToSky functionality is no longer implemented");
    600432    // slaAopqk(tpCoord->x, tpCoord->y, (double*)grommit,
    601433    //         &AOB, &ZOB, &HOB, &outSphere->r, &outSphere->d);
    602  
     434
    603435    return (outSphere);
    604436}
    605 */
    606 /*
     437
     438
     439
    607440psPlane* psCoordCellToFPA(psPlane* fpaCoord,
    608441                          const psPlane* cellCoord,
    609                           const psCell* cell)
     442                          const pmCell* cell)
    610443{
    611444    PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
    612445    PS_ASSERT_PTR_NON_NULL(cell, NULL);
    613  
     446
    614447    return (psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord));
    615448}
    616 */
    617 /*
     449
     450
     451
    618452psSphere* psCoordCellToSky(psSphere* skyCoord,
    619453                           const psPlane* cellCoord,
    620454                           double color,
    621455                           double magnitude,
    622                            const psCell* cell)
     456                           const pmCell* cell)
    623457{
    624458    PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
     
    628462    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
    629463    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->toTangentPlane, NULL);
    630     PS_ASSERT_PTR_NON_NULL(cell->parent->parent->exposure, NULL);
    631  
     464    //    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->exposure, NULL);
     465
    632466    psPlane* fpaCoord = NULL;
    633467    psPlane* tpCoord = NULL;
    634     psFPA* parFPA = (cell->parent)->parent;
    635     psGrommit* tmpGrommit = NULL;
    636  
     468    pmFPA* parFPA = (cell->parent)->parent;
     469    //    psGrommit* tmpGrommit = NULL;
     470
    637471    // Convert the input cell coordinates to FPA coordinates.
    638472    fpaCoord = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord);
    639  
     473
    640474    // Convert the FPA coordinates to tangent plane Coordinates.
    641475    tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane,
    642476                                  fpaCoord, color, magnitude);
    643  
     477
    644478    // Generate a grommit for this FPA.
    645     tmpGrommit = psGrommitAlloc(parFPA->exposure);
    646  
     479    //    tmpGrommit = psGrommitAlloc(parFPA->exposure);
     480
    647481    // Convert the tangent plane Coordinates to sky coordinates.
    648     skyCoord = psCoordTPToSky(skyCoord, tpCoord, tmpGrommit);
    649  
     482    //    skyCoord = psCoordTPToSky(skyCoord, tpCoord, tmpGrommit);
     483
    650484    psFree(fpaCoord);
    651485    psFree(tpCoord);
    652     psFree(tmpGrommit);
    653  
     486    //    psFree(tmpGrommit);
     487
    654488    return(skyCoord);
    655489}
    656  
    657 */
    658 /*
     490
     491
    659492psSphere* psCoordCellToSkyQuick(psSphere* outSphere,
    660493                                const psPlane* cellCoord,
    661                                 const psCell* cell)
     494                                const pmCell* cell)
    662495{
    663496    PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
     
    667500    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
    668501    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL);
    669     if (cell->toSky) {
    670         // XXX: Should we use toTP or toSky?
    671         psLogMsg(__func__, PS_LOG_WARN,
    672                  "WARNING: psCoordCellToSkyQuick(): The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
    673     }
    674  
    675     psPlane *tpCoord = NULL;
    676     psChip *chip = cell->parent;
    677     psFPA *FPA = chip->parent;
    678     psProjectionType oldProjectionType;
    679  
    680     if (outSphere == NULL) {
    681         outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
    682     }
    683  
    684     // Determine the tangent plane coordinates.
    685     tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord);
    686  
    687     // Save the old projection type and set the new projection type to TAN.
    688     oldProjectionType = FPA->projection->type;
    689     FPA->projection->type = PS_PROJ_TAN;
    690  
    691     // Deproject the tangent plane coordinates a sphere.
    692     outSphere = psDeproject(tpCoord, FPA->projection);
    693  
    694     // Restore old projection type.  Free memory.
    695     FPA->projection->type = oldProjectionType;
    696     psFree(tpCoord);
    697  
    698     return (outSphere);
    699 }
    700 */
     502
     503    psLogMsg(__func__, PS_LOG_WARN,
     504             "WARNING: psCoordCellToSkyQuick(): This function is not fully specified in the SDRS.  Returning NULL.\n");
     505    return(NULL);
     506
     507    /*
     508        if (cell->toSky) {
     509            // XXX: Should we use toTP or toSky?
     510            psLogMsg(__func__, PS_LOG_WARN,
     511                     "WARNING: psCoordCellToSkyQuick(): The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
     512        }
     513     
     514        psPlane *tpCoord = NULL;
     515        pmChip *chip = cell->parent;
     516        pmFPA *FPA = chip->parent;
     517        psProjectionType oldProjectionType;
     518     
     519        if (outSphere == NULL) {
     520            outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
     521        }
     522     
     523        // Determine the tangent plane coordinates.
     524        tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord);
     525     
     526        // Save the old projection type and set the new projection type to TAN.
     527        oldProjectionType = FPA->projection->type;
     528        FPA->projection->type = PS_PROJ_TAN;
     529     
     530        // Deproject the tangent plane coordinates a sphere.
     531        outSphere = psDeproject(tpCoord, FPA->projection);
     532     
     533        // Restore old projection type.  Free memory.
     534        FPA->projection->type = oldProjectionType;
     535        psFree(tpCoord);
     536     
     537        return (outSphere);
     538    */
     539}
     540
    701541
    702542/*****************************************************************************
    703543XXX: What about units for the (x,y) coords?
    704544 *****************************************************************************/
    705 /*
    706545psPlane* psCoordSkyToTP(psPlane* tpCoord,
    707546                        const psSphere* in,
    708                         const psGrommit* grommit)
     547                        const psProjection *projection)
    709548{
    710549    PS_ASSERT_PTR_NON_NULL(in, NULL);
    711     PS_ASSERT_PTR_NON_NULL(grommit, NULL);
    712  
     550    //    PS_ASSERT_PTR_NON_NULL(grommit, NULL);
     551
    713552    // char* type = "RA";
    714  
     553
    715554    if (tpCoord == NULL) {
    716555        tpCoord = (psPlane* ) psAlloc(sizeof(psPlane));
    717556    }
    718  
     557
    719558    // XXX: this was done by a SLALIB call -- needs to be reimplemented
    720559    psWarning("Warning!  psCoordSkyToTP functionality is no longer implemented");
    721560    // slaOapqk(type, in->r, in->d, (double*)grommit, &tpCoord->x, &tpCoord->y);
    722  
     561
    723562    return(tpCoord);
    724563}
    725 */
    726 /*
     564
     565
    727566psPlane* psCoordTPToFPA(psPlane* fpaCoord,
    728567                        const psPlane* tpCoord,
    729568                        double color,
    730569                        double magnitude,
    731                         const psFPA* fpa)
     570                        const pmFPA* fpa)
    732571{
    733572    PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
    734573    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    735574    PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL);
    736  
     575
    737576    return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane,
    738577                                tpCoord, color, magnitude));
    739578}
    740 */
    741 /*
     579
     580
    742581psPlane* psCoordFPAToChip(psPlane* chipCoord,
    743582                          const psPlane* fpaCoord,
    744                           const psChip* chip)
     583                          const pmChip* chip)
    745584{
    746585    PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
    747586    PS_ASSERT_PTR_NON_NULL(chip, NULL);
    748587    PS_ASSERT_PTR_NON_NULL(chip->fromFPA, NULL);
    749  
     588
    750589    chipCoord = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord);
    751590    return(chipCoord);
    752591}
    753 */
    754 /*
     592
     593
    755594psPlane* psCoordChipToCell(psPlane* cellCoord,
    756595                           const psPlane* chipCoord,
    757                            const psCell* cell)
     596                           const pmCell* cell)
    758597{
    759598    PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
    760599    PS_ASSERT_PTR_NON_NULL(cell, NULL);
    761     PS_ASSERT_PTR_NON_NULL(cell->fromChip, NULL);
    762  
    763     cellCoord = psPlaneTransformApply(cellCoord, cell->fromChip, chipCoord);
     600    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
     601
     602    pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent);
     603    PS_ASSERT_PTR_NON_NULL(tmpCell->toChip, NULL);
     604    psPlaneTransform *tmpChipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
     605    PS_ASSERT_PTR_NON_NULL(tmpChipToCell, NULL);
     606    cellCoord = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord);
     607    psFree(tmpChipToCell);
    764608    return(cellCoord);
    765609}
    766 */
    767 /*
     610
     611
    768612psPlane* psCoordSkyToCell(psPlane* cellCoord,
    769613                          const psSphere* skyCoord,
    770                           double color,
    771                           double magnitude,
    772                           const psCell* cell)
     614                          float color,
     615                          float magnitude,
     616                          const pmCell* cell)
    773617{
    774618    PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
     
    776620    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
    777621    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
    778     PS_ASSERT_PTR_NON_NULL(cell->parent->parent->grommit, NULL);
    779  
    780     psChip *parChip = cell->parent;
    781     psFPA *parFPA = parChip->parent;
    782     psGrommit* grommit = parFPA->grommit;
    783  
     622    //    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->grommit, NULL);
     623
     624    pmChip *parChip = cell->parent;
     625    pmFPA *parFPA = parChip->parent;
     626
    784627    // Convert the skyCoords to tangent plane coords.
    785     psPlane *tpCoord = psCoordSkyToTP(tpCoord, skyCoord, grommit);
    786  
     628    psPlane *tpCoord = psCoordSkyToTP(NULL, skyCoord, parFPA->projection);
     629
    787630    // Convert the tangent plane coords to FPA coords.
    788     psPlane *fpaCoord = psCoordTPToFPA(fpaCoord, tpCoord, color,
    789                                        magnitude, parFPA);
    790  
     631    psPlane *fpaCoord = psCoordTPToFPA(NULL, tpCoord, color, magnitude, parFPA);
     632
    791633    // Convert the FPA coords to chip coords.
    792     psPlane *chipCoord = psCoordFPAToChip(chipCoord, fpaCoord, parChip);
    793  
     634    psPlane *chipCoord = psCoordFPAToChip(NULL, fpaCoord, parChip);
     635
    794636    // Convert the chip coords to cell coords.
    795637    cellCoord = psCoordChipToCell(cellCoord, chipCoord, cell);
    796  
     638
    797639    psFree(tpCoord);
    798640    psFree(fpaCoord);
    799641    psFree(chipCoord);
    800  
     642
    801643    return (cellCoord);
    802644}
    803 */
    804 /*
     645
     646
    805647psPlane* psCoordSkyToCellQuick(psPlane* cellCoord,
    806648                               const psSphere* skyCoord,
    807                                const psCell* cell)
     649                               const pmCell* cell)
    808650{
    809651    PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
     
    812654    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
    813655    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL);
    814     PS_ASSERT_PTR_NON_NULL(cell->toTP, NULL);
    815     if (cell->toSky) {
    816         // XXX: Should we use toTP or toSky?
    817         psLogMsg(__func__, PS_LOG_WARN,
    818                  "WARNING: psCoordSkyToCellQuick(): The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
    819     }
    820  
    821     psPlane *tpCoord = NULL;
    822     psChip *whichChip = cell->parent;
    823     psFPA *whichFPA = whichChip->parent;
    824     psProjectionType oldProjectionType;
    825     psPlaneTransform *TPtoCell = NULL;
    826  
    827     // Save the old projection type and set the new projection type to TAN.
    828     oldProjectionType = whichFPA->projection->type;
    829     whichFPA->projection->type = PS_PROJ_TAN;
    830  
    831     if (cellCoord == NULL) {
    832         cellCoord = (psPlane* ) psAlloc(sizeof(psPlane));
    833     }
    834  
    835     tpCoord = psProject(skyCoord, whichFPA->projection);
    836  
    837     // generate an error if cell->toTP is not linear.
    838     if (0 == p_psIsProjectionLinear(cell->toTP)) {
    839         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    840                 PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM,
    841                 "cell to tangent plane");
    842     }
    843  
    844     TPtoCell = p_psPlaneTransformLinearInvert(cell->toTP);
    845     cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord);
    846  
    847     // Restore old projection type.  Free memory.
    848     whichFPA->projection->type = oldProjectionType;
    849     psFree(tpCoord);
    850     return (cellCoord);
    851 }
    852 */
    853 
    854 
     656
     657
     658    psLogMsg(__func__, PS_LOG_WARN,
     659             "WARNING: psCoordSkyToCellQuick(): This function is not fully specified in the SDRS.  Returning NULL.\n");
     660    return(NULL);
     661    /*
     662     
     663        if (cell->toSky) {
     664            // XXX: Should we use toTP or toSky?
     665            psLogMsg(__func__, PS_LOG_WARN,
     666                     "WARNING: psCoordSkyToCellQuick: The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
     667        }
     668     
     669        psPlane *tpCoord = NULL;
     670        pmChip *whichChip = cell->parent;
     671        pmFPA  *whichFPA = whichChip->parent;
     672        psProjectionType oldProjectionType;
     673        psPlaneTransform *TPtoCell = NULL;
     674     
     675        // Save the old projection type and set the new projection type to TAN.
     676        oldProjectionType = whichFPA->projection->type;
     677        whichFPA->projection->type = PS_PROJ_TAN;
     678     
     679        if (cellCoord == NULL) {
     680            cellCoord = (psPlane* ) psAlloc(sizeof(psPlane));
     681        }
     682     
     683        tpCoord = psProject(skyCoord, whichFPA->projection);
     684     
     685        // generate an error if cell->toTP is not linear.
     686        if (0 == p_psIsProjectionLinear(cell->toTP)) {
     687            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     688                    PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM,
     689                    "cell to tangent plane");
     690        }
     691     
     692        TPtoCell = p_psPlaneTransformLinearInvert(cell->toTP);
     693        cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord);
     694     
     695        // Restore old projection type.  Free memory.
     696        whichFPA->projection->type = oldProjectionType;
     697        psFree(tpCoord);
     698        return (cellCoord);
     699    */
     700}
     701
     702
     703
Note: See TracChangeset for help on using the changeset viewer.