IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astronomy/psAstrometry.c

    r1406 r1407  
     1
    12/** @file  psAstrometry.c
    23*
     
    89*  @author George Gusciora, MHPCC
    910*
    10 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-08-06 22:34:05 $
     11*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-08-07 00:06:06 $
    1213*
    1314*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2021#include "psMemory.h"
    2122
    22 static void grommitFree( psGrommit *grommit );
    23 static int checkValidChipCoords( double x, double y, psChip *tmpChip );
    24 static int checkValidImageCoords( double x, double y, psImage *tmpImage );
    25 
    26 psExposure* psExposureAlloc( double ra, double dec, double hourAngle,
    27                              double zenith, double azimuth, double localTime, float date,
    28                              float rotAngle, float temperature, float pressure, float humidity,
    29                              float exposureTime )
    30 {
    31     psExposure * exp = psAlloc( sizeof( psExposure ) );
    32 
    33     *( double* ) & exp->ra = ra;
    34     *( double* ) & exp->dec = dec;
    35     *( double* ) & exp->hourAngle = hourAngle;
    36     *( double* ) & exp->zenith = zenith;
    37     *( double* ) & exp->azimuth = azimuth;
    38     *( double* ) & exp->localTime = localTime;
    39     *( float* ) & exp->date = date;
    40     *( float* ) & exp->rotAngle = rotAngle;
    41     *( float* ) & exp->temperature = temperature;
    42     *( float* ) & exp->pressure = pressure;
    43     *( float* ) & exp->humidity = humidity;
    44     *( float* ) & exp->exposureTime = exposureTime;
     23static void grommitFree(psGrommit * grommit);
     24static int checkValidChipCoords(double x, double y, psChip * tmpChip);
     25static int checkValidImageCoords(double x, double y, psImage * tmpImage);
     26
     27psExposure *psExposureAlloc(double ra, double dec, double hourAngle,
     28                            double zenith, double azimuth, double localTime, float date,
     29                            float rotAngle, float temperature, float pressure, float humidity,
     30                            float exposureTime)
     31{
     32    psExposure *exp = psAlloc(sizeof(psExposure));
     33
     34    *(double *)&exp->ra = ra;
     35    *(double *)&exp->dec = dec;
     36    *(double *)&exp->hourAngle = hourAngle;
     37    *(double *)&exp->zenith = zenith;
     38    *(double *)&exp->azimuth = azimuth;
     39    *(double *)&exp->localTime = localTime;
     40    *(float *)&exp->date = date;
     41    *(float *)&exp->rotAngle = rotAngle;
     42    *(float *)&exp->temperature = temperature;
     43    *(float *)&exp->pressure = pressure;
     44    *(float *)&exp->humidity = humidity;
     45    *(float *)&exp->exposureTime = exposureTime;
    4546
    4647    return exp;
     
    4849}
    4950
    50 psGrommit* psGrommitAlloc( const psExposure *exp )
    51 {
    52     double * slaGrommit = ( double * ) psAlloc( 14 * sizeof( double ) );
    53     psGrommit *grommit = ( psGrommit * ) psAlloc( sizeof( psGrommit ) );
     51psGrommit *psGrommitAlloc(const psExposure * exp)
     52{
     53    double *slaGrommit = (double *)psAlloc(14 * sizeof(double));
     54    psGrommit *grommit = (psGrommit *) psAlloc(sizeof(psGrommit));
     55
    5456    /*
    55         extern void sla_aoppa(double date,
    56                               double dut,
    57                               double elongm,
    58                               double phim,
    59                               double him,
    60                               double xp,
    61                               double yp,
    62                               double tdk,
    63                               double pmb,
    64                               double rh,
    65                               double wl,
    66                               double tlr,
    67                               double *AOPRMS);
    68      
    69         sla_aoppa(date, deltaUT, meanLongitude, meanLatitude, height, xp, yp,
    70                   exp->temperature, exp->pressure, exp->humidity, wavelength,
    71                   tlr);
    72     */
    73     *( double* ) & grommit->latitude = exp->dec;              // XXX Is this correct?
    74     *( double* ) & grommit->sinLat = sin( grommit->latitude );
    75     *( double* ) & grommit->cosLat = cos( grommit->latitude );
    76     *( double* ) & grommit->abberationMag = 0.0;
    77     *( double* ) & grommit->height = 0.0;
    78     *( double* ) & grommit->temperature = exp->temperature;
    79     *( double* ) & grommit->pressure = exp->pressure;
    80     *( double* ) & grommit->humidity = exp->humidity;
    81     *( double* ) & grommit->wavelength = 0.0;
    82     *( double* ) & grommit->lapseRate = 0.0;
    83     *( double* ) & grommit->refractA = 0.0;
    84     *( double* ) & grommit->refractB = 0.0;
    85     *( double* ) & grommit->longitudeOffset = exp->ra;             // XXX Is this correct?
    86     *( double* ) & grommit->siderealTime = 0.0;
    87 
    88     psFree( slaGrommit );
    89     return ( grommit );
    90 }
    91 
    92 void p_psGrommitFree( psGrommit *grommit )
    93 {
    94     psFree( grommit );
    95 }
    96 
    97 psCell *psCellinFPA( psCell *out,
    98                      const psPlane *coord,
    99                      const psFPA *FPA )
    100 {
    101     psChip * tmpChip = NULL;
     57     * extern void sla_aoppa(double date, double dut, double elongm, double phim, double him, double xp,
     58     * double yp, double tdk, double pmb, double rh, double wl, double tlr, double *AOPRMS);
     59     *
     60     * sla_aoppa(date, deltaUT, meanLongitude, meanLatitude, height, xp, yp, exp->temperature, exp->pressure,
     61     * exp->humidity, wavelength, tlr); */
     62    *(double *)&grommit->latitude = exp->dec;   // XXX Is this correct?
     63    *(double *)&grommit->sinLat = sin(grommit->latitude);
     64    *(double *)&grommit->cosLat = cos(grommit->latitude);
     65    *(double *)&grommit->abberationMag = 0.0;
     66    *(double *)&grommit->height = 0.0;
     67    *(double *)&grommit->temperature = exp->temperature;
     68    *(double *)&grommit->pressure = exp->pressure;
     69    *(double *)&grommit->humidity = exp->humidity;
     70    *(double *)&grommit->wavelength = 0.0;
     71    *(double *)&grommit->lapseRate = 0.0;
     72    *(double *)&grommit->refractA = 0.0;
     73    *(double *)&grommit->refractB = 0.0;
     74    *(double *)&grommit->longitudeOffset = exp->ra;     // XXX Is this correct?
     75    *(double *)&grommit->siderealTime = 0.0;
     76
     77    psFree(slaGrommit);
     78    return (grommit);
     79}
     80
     81void p_psGrommitFree(psGrommit * grommit)
     82{
     83    psFree(grommit);
     84}
     85
     86psCell *psCellinFPA(psCell * out, const psPlane * coord, const psFPA * FPA)
     87{
     88    psChip *tmpChip = NULL;
    10289    psCell *tmpCell = NULL;
    10390
    104     tmpChip = psChipinFPA( tmpChip, coord, FPA );
    105     tmpCell = psCellinChip( tmpCell, coord, tmpChip );
    106     return ( tmpCell );
    107 }
    108 
    109 
    110 int checkValidChipCoords( double x, double y, psChip *tmpChip )
    111 {
    112     return ( 0 );
    113 }
    114 
    115 psChip *psChipinFPA( psChip *out,
    116                      const psPlane *coord,
    117                      const psFPA *FPA )
    118 {
    119     psArray * chips = FPA->chips;
     91    tmpChip = psChipinFPA(tmpChip, coord, FPA);
     92    tmpCell = psCellinChip(tmpCell, coord, tmpChip);
     93    return (tmpCell);
     94}
     95
     96int checkValidChipCoords(double x, double y, psChip * tmpChip)
     97{
     98    return (0);
     99}
     100
     101psChip *psChipinFPA(psChip * out, const psPlane * coord, const psFPA * FPA)
     102{
     103    psArray *chips = FPA->chips;
    120104    int nChips = chips->n;
    121     psPlane* tmpCoord = NULL;
    122 
    123     for ( int i = 0; i < nChips; i++ ) {
    124         psChip* tmpChip = chips->data[ i ];
    125         tmpCoord = psPlaneTransformApply( tmpCoord, tmpChip->fromFPA, coord );
    126         if ( checkValidChipCoords( tmpCoord->x, tmpCoord->y,
    127                                    tmpChip ) ) {
    128             psFree( tmpCoord );
     105    psPlane *tmpCoord = NULL;
     106
     107    for (int i = 0; i < nChips; i++) {
     108        psChip *tmpChip = chips->data[i];
     109
     110        tmpCoord = psPlaneTransformApply(tmpCoord, tmpChip->fromFPA, coord);
     111        if (checkValidChipCoords(tmpCoord->x, tmpCoord->y, tmpChip)) {
     112            psFree(tmpCoord);
    129113            // XXX: George, you didn't use the out parameter!
    130             return ( tmpChip );
     114            return (tmpChip);
    131115        }
    132         psFree( tmpCoord );
    133     }
    134     psFree( tmpCoord );
    135     return ( NULL );
    136 }
    137 
    138 int checkValidImageCoords( double x, double y, psImage *tmpImage )
    139 {
    140     if ( ( x < 0.0 ) ||
    141             ( x > ( double ) tmpImage->numCols ) ||
    142             ( y < 0.0 ) ||
    143             ( y > ( double ) tmpImage->numRows ) ) {
    144         return ( 0 );
    145     }
    146     return ( 1 );
    147 }
    148 
     116        psFree(tmpCoord);
     117    }
     118    psFree(tmpCoord);
     119    return (NULL);
     120}
     121
     122int checkValidImageCoords(double x, double y, psImage * tmpImage)
     123{
     124    if ((x < 0.0) || (x > (double)tmpImage->numCols) || (y < 0.0) || (y > (double)tmpImage->numRows)) {
     125        return (0);
     126    }
     127    return (1);
     128}
    149129
    150130/*****************************************************************************
     
    160140XXX: must deallocate memory.
    161141 *****************************************************************************/
    162 psCell *psCellinChip( psCell *out,
    163                       const psPlane *coord,
    164                       const psChip *chip )
    165 {
    166     psPlane * tmpCoord = NULL;
    167     psArray* cells;
    168 
    169     if ( chip == NULL ) {
     142psCell *psCellinChip(psCell * out, const psPlane * coord, const psChip * chip)
     143{
     144    psPlane *tmpCoord = NULL;
     145    psArray *cells;
     146
     147    if (chip == NULL) {
    170148        return NULL;
    171149    }
     
    173151    cells = chip->cells;
    174152
    175     if ( cells == NULL ) {
     153    if (cells == NULL) {
    176154        return NULL;
    177155    }
    178156
    179     for ( int i = 0; i < cells->n; i++ ) {
    180         psCell* tmpCell = ( psCell* ) cells->data[ i ];
    181         psArray* readouts = tmpCell->readouts;
    182         if ( readouts != NULL ) {
    183             for ( int j = 0; j < readouts->n; j++ ) {
    184                 psReadout* tmpReadout = readouts->data[ j ];
    185                 tmpCoord = psPlaneTransformApply( tmpCoord, tmpCell->fromChip, coord );
    186                 if ( checkValidImageCoords( tmpCoord->x, tmpCoord->y,
    187                                             tmpReadout->image ) ) {
    188                     return ( tmpCell );
     157    for (int i = 0; i < cells->n; i++) {
     158        psCell *tmpCell = (psCell *) cells->data[i];
     159        psArray *readouts = tmpCell->readouts;
     160
     161        if (readouts != NULL) {
     162            for (int j = 0; j < readouts->n; j++) {
     163                psReadout *tmpReadout = readouts->data[j];
     164
     165                tmpCoord = psPlaneTransformApply(tmpCoord, tmpCell->fromChip, coord);
     166                if (checkValidImageCoords(tmpCoord->x, tmpCoord->y, tmpReadout->image)) {
     167                    return (tmpCell);
    189168                }
    190169            }
    191170        }
    192171    }
    193     return ( NULL );
    194 }
    195 
    196 psPlane *psCoordCelltoChip( psPlane *out,
    197                             const psPlane *in,
    198                             const psCell *cell )
    199 {
    200     return ( psPlaneTransformApply( out, cell->toChip, in ) );
    201 }
    202 
    203 psPlane *psCoordChipToFPA( psPlane *out,
    204                            const psPlane *in,
    205                            const psChip *chip )
    206 {
    207     return ( psPlaneTransformApply( out, chip->toFPA, in ) );
    208 }
    209 
    210 psPlane *psCoordFPAtoTP( psPlane *out,
    211                          const psPlane *in,
    212                          const psFPA *fpa )
     172    return (NULL);
     173}
     174
     175psPlane *psCoordCelltoChip(psPlane * out, const psPlane * in, const psCell * cell)
     176{
     177    return (psPlaneTransformApply(out, cell->toChip, in));
     178}
     179
     180psPlane *psCoordChipToFPA(psPlane * out, const psPlane * in, const psChip * chip)
     181{
     182    return (psPlaneTransformApply(out, chip->toFPA, in));
     183}
     184
     185psPlane *psCoordFPAtoTP(psPlane * out, const psPlane * in, const psFPA * fpa)
    213186{
    214187    // XXX: This code doesn't work; fpa->toTangentPlane is of the wrong type.
    215188    // return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
    216     return ( NULL );
     189    return (NULL);
    217190}
    218191
    219192// XXX: must wrap SLA_QAPQK here.
    220 psSphere *psCoordTPtoSky( psSphere *out,
    221                           const psPlane *in,
    222                           const psGrommit *grommit )
     193psSphere *psCoordTPtoSky(psSphere * out, const psPlane * in, const psGrommit * grommit)
    223194{
    224195    /*
    225         double RAP;
    226         double DAP;
    227      
    228         extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP);
    229         sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, &DAP);
    230     */
    231 
    232     return ( out );
    233 }
    234 
    235 
    236 psPlane *psCoordCellToFPA( psPlane *out,
    237                            const psPlane *in,
    238                            const psCell *cell )
    239 {
    240     return ( psPlaneTransformApply( out, cell->toFPA, in ) );
    241 }
    242 
     196     * double RAP; double DAP;
     197     *
     198     * extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP); sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP,
     199     * &DAP); */
     200
     201    return (out);
     202}
     203
     204psPlane *psCoordCellToFPA(psPlane * out, const psPlane * in, const psCell * cell)
     205{
     206    return (psPlaneTransformApply(out, cell->toFPA, in));
     207}
    243208
    244209// XXX: This implementation requires a new psGrommit be created for each
    245210// transformation, as well as a few psPlane structs.  Can this be implemented
    246211// better?
    247 psSphere *psCoordCelltoSky( psSphere *out,
    248                             const psPlane *in,
    249                             const psCell *cell )
    250 {
    251     psPlane * tmp1 = NULL;
     212psSphere *psCoordCelltoSky(psSphere * out, const psPlane * in, const psCell * cell)
     213{
     214    psPlane *tmp1 = NULL;
    252215    psPlane *tmp2 = NULL;
    253     psFPA *parFPA = ( cell->parent ) ->parent;
     216    psFPA *parFPA = (cell->parent)->parent;
    254217    psGrommit *tmpGrommit = NULL;
    255218
    256     tmp1 = psPlaneTransformApply( tmp1, cell->toFPA, in );
    257     tmp2 = psPlaneTransformApply( tmp2, parFPA->toTangentPlane, tmp1 );
    258     tmpGrommit = psGrommitAlloc( parFPA->exposure );
    259     tmp3 = psCoordTPtoSky( out, tmp2, psGrommit );
    260 
    261     psFree( tmp1 );
    262     psFree( tmp2 );
    263     psFree( tmpGrommit );
    264 
    265     return ( psCoordTPtoSky( out, tmp2, psGrommit ) );
    266 
    267 }
    268 
    269 psSphere *psCoordCelltoSkyQuick( psSphere *out,
    270                                  const psPlane *in,
    271                                  const psCell *cell )
    272 {
    273     psPlane * tmp1 = NULL;
    274 
    275     tmp1 = psPlaneTransformApply( tmp1, cell->toSky, in );
    276 
    277     //XXX: Do something to convert the linear coords in tmp1 to spherical
     219    tmp1 = psPlaneTransformApply(tmp1, cell->toFPA, in);
     220    tmp2 = psPlaneTransformApply(tmp2, parFPA->toTangentPlane, tmp1);
     221    tmpGrommit = psGrommitAlloc(parFPA->exposure);
     222    tmp3 = psCoordTPtoSky(out, tmp2, psGrommit);
     223
     224    psFree(tmp1);
     225    psFree(tmp2);
     226    psFree(tmpGrommit);
     227
     228    return (psCoordTPtoSky(out, tmp2, psGrommit));
     229
     230}
     231
     232psSphere *psCoordCelltoSkyQuick(psSphere * out, const psPlane * in, const psCell * cell)
     233{
     234    psPlane *tmp1 = NULL;
     235
     236    tmp1 = psPlaneTransformApply(tmp1, cell->toSky, in);
     237
     238    // XXX: Do something to convert the linear coords in tmp1 to spherical
    278239    // coords in out.
    279240
    280     psFree( tmp1 );
    281 
    282     return ( out );
     241    psFree(tmp1);
     242
     243    return (out);
    283244}
    284245
    285246// XXX: must wrap SLA_AOPQK here.
    286 psPlane *psCoordSkytoTP( psPlane *out,
    287                          const psSphere *in,
    288                          const psGrommit *grommit )
    289 {
    290     extern void sla_AOPQK ( RAP, DAP, AOPRMS, AOB, ZOB, HOB, DOB, ROB );
     247psPlane *psCoordSkytoTP(psPlane * out, const psSphere * in, const psGrommit * grommit)
     248{
     249    extern void sla_AOPQK(RAP, DAP, AOPRMS, AOB, ZOB, HOB, DOB, ROB);
    291250    double AOB;
    292251    double ZOB;
     
    295254    double ROB;
    296255
    297     if ( out == NULL ) {
    298         out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
    299     }
    300 
    301     sla_AOPQK( psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB );
     256    if (out == NULL) {
     257        out = (psPlane *) psAlloc(sizeof(psPlane));
     258    }
     259
     260    sla_AOPQK(psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB);
    302261    out->x = XXX;
    303262    out->y = XXX;
    304     return ( out );
    305 }
    306 
    307 psPlane *psCoordTPtoFPA( psPlane *out,
    308                          const psPlane *in,
    309                          const psFPA *fpa )
    310 {
    311     return ( psPlaneTransformApply( out, fpa->fromTangentPlane, in ) );
    312 }
    313 
    314 psPlane *psCoordFPAtoChip( psPlane *out,
    315                            const psPlane *in,
    316                            const psChip *chip )
    317 {
    318     return ( psPlaneTransformApply( out, chip->fromFPA, in ) );
    319 }
    320 
    321 
    322 psPlane *psCoordChiptoCell( psPlane *out,
    323                             const psPlane *in,
    324                             const psCell *cell )
    325 {
    326     return ( psPlaneTransformApply( out, cell->fromChip, in ) );
    327 }
    328 
    329 psPlane *psCoordSkytoCell( psPlane *out,
    330                            const psSphere *in,
    331                            const psCell *cell )
    332 {
    333     out = psCoordSkytoTP( out, in, tmpGrommit );
    334     out = psCoordTPtoFPA( out, out, whichFPA );
    335     out = psCoordFPAtoChip( out, out, whichChip );
    336     out = psCoordChiptoCell( out, out, whichCell );
    337 
    338     return ( out );
    339 }
    340 
    341 psPlane *psCoordSkytoCellQuick( psPlane *out,
    342                                 const psSphere *in,
    343                                 const psCell *cell )
    344 {
    345     if ( out == NULL ) {
    346         out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
    347     }
    348 
    349     return ( out );
    350 }
    351 
    352 
    353 
    354 
     263    return (out);
     264}
     265
     266psPlane *psCoordTPtoFPA(psPlane * out, const psPlane * in, const psFPA * fpa)
     267{
     268    return (psPlaneTransformApply(out, fpa->fromTangentPlane, in));
     269}
     270
     271psPlane *psCoordFPAtoChip(psPlane * out, const psPlane * in, const psChip * chip)
     272{
     273    return (psPlaneTransformApply(out, chip->fromFPA, in));
     274}
     275
     276psPlane *psCoordChiptoCell(psPlane * out, const psPlane * in, const psCell * cell)
     277{
     278    return (psPlaneTransformApply(out, cell->fromChip, in));
     279}
     280
     281psPlane *psCoordSkytoCell(psPlane * out, const psSphere * in, const psCell * cell)
     282{
     283    out = psCoordSkytoTP(out, in, tmpGrommit);
     284    out = psCoordTPtoFPA(out, out, whichFPA);
     285    out = psCoordFPAtoChip(out, out, whichChip);
     286    out = psCoordChiptoCell(out, out, whichCell);
     287
     288    return (out);
     289}
     290
     291psPlane *psCoordSkytoCellQuick(psPlane * out, const psSphere * in, const psCell * cell)
     292{
     293    if (out == NULL) {
     294        out = (psPlane *) psAlloc(sizeof(psPlane));
     295    }
     296
     297    return (out);
     298}
Note: See TracChangeset for help on using the changeset viewer.