Changeset 1475 for trunk/psLib/src/astronomy/psAstrometry.c
- Timestamp:
- Aug 11, 2004, 10:07:44 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psAstrometry.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psAstrometry.c
r1463 r1475 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-08-1 0 23:59:41$10 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-08-11 20:07:44 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psAstrometry.h" 20 20 #include "psMemory.h" 21 22 static int checkValidChipCoords(double x, double y, psChip* tmpChip);23 static int checkValidImageCoords(double x, double y, psImage* tmpImage);24 21 25 22 psExposure* psExposureAlloc(double ra, double dec, double hourAngle, … … 44 41 45 42 return exp; 46 47 43 } 48 44 49 45 /* 50 Several members of the psGrommit data structure have no direct counterpart51 in the psExposure structure. How are we to determine them?46 XXX: Several members of the psGrommit data structure have no direct 47 counterpart in the psExposure structure. How are we to determine them? 52 48 */ 53 49 psGrommit* psGrommitAlloc(const psExposure* exp) 54 50 { 55 double *slaGrommit = (double *)psAlloc(14 * sizeof(double)); 51 // XXX: is this the correct action? 52 if (exp == NULL) { 53 return(NULL); 54 } 55 56 56 psGrommit* grommit = (psGrommit* ) psAlloc(sizeof(psGrommit)); 57 57 … … 77 77 *(double *)&grommit->siderealTime = 0.0; 78 78 79 psFree(slaGrommit);80 79 return (grommit); 81 80 } 82 81 82 /* 83 * XXX: The SDRS states this should be a private p_ps() procedure. 84 */ 83 85 void psGrommitFree(psGrommit* grommit) 84 86 { … … 86 88 } 87 89 88 psCell* psCellinFPA(psCell* out, const psPlane* coord, const psFPA* FPA) 90 psCell* psCellinFPA(psCell* outCell, 91 const psPlane* fpaCoord, 92 const psFPA* FPA) 89 93 { 90 94 psChip* tmpChip = NULL; 91 psCell* tmpCell = NULL; 92 93 tmpChip = psChipinFPA(tmpChip, coord, FPA); 94 tmpCell = psCellinChip(tmpCell, coord, tmpChip); 95 return (tmpCell); 96 } 97 98 /* 99 XXX: do this 100 */ 101 int checkValidChipCoords(double x, double y, psChip* tmpChip) 102 { 103 return (0); 104 } 105 106 psChip* psChipinFPA(psChip* out, const psPlane* coord, const psFPA* FPA) 95 psPlane* chipCoord = NULL; 96 97 if (FPA == NULL) { 98 return(NULL); 99 } 100 if (fpaCoord == NULL) { 101 return(NULL); 102 } 103 104 // Determine which chip contains the fpaCoords. 105 tmpChip = psChipinFPA(tmpChip, fpaCoord, FPA); 106 107 // Convert to those chip coordinates. 108 chipCoord = psCoordFPAtoChip(chipCoord, fpaCoord, tmpChip); 109 110 // Determine which cell contains those chip coordinates. 111 outCell = psCellinChip(outCell, chipCoord, tmpChip); 112 113 psFree(tmpChip); 114 psFree(chipCoord); 115 116 return (outCell); 117 } 118 119 int p_psCheckValidImageCoords(double x, 120 double y, 121 psImage* tmpImage) 122 { 123 if (tmpImage == NULL) { 124 return(0); 125 } 126 127 if ((x < 0.0) || 128 (x > (double)tmpImage->numCols) || 129 (y < 0.0) || 130 (y > (double)tmpImage->numRows)) { 131 return (0); 132 } 133 134 return (1); 135 } 136 137 /***************************************************************************** 138 XXX: Return the answer in "out". 139 *****************************************************************************/ 140 psChip* psChipinFPA(psChip* out, 141 const psPlane* fpaCoord, 142 const psFPA* FPA) 107 143 { 108 144 psArray* chips = FPA->chips; 109 145 int nChips = chips->n; 110 psPlane* tmpCoord = NULL; 111 146 psPlane* chipCoord = NULL; 147 psCell *tmpCell = NULL; 148 149 // Loop through every chip in this FPA. Convert the original 150 // FPA coordinates to chip coordinates for that chip. Then, 151 // determine if any cells in that chip contain those chip 152 // coordinates. 112 153 for (int i = 0; i < nChips; i++) { 113 154 psChip* tmpChip = chips->data[i]; 114 155 115 tmpCoord = psPlaneTransformApply(tmpCoord, tmpChip->fromFPA, coord);116 if (checkValidChipCoords(tmpCoord->x, tmpCoord->y, tmpChip)) {117 psFree(tmpCoord);118 // XXX: George, you didn't use the out parameter!119 return (tmpChip);156 chipCoord = psPlaneTransformApply(chipCoord, tmpChip->fromFPA, fpaCoord); 157 tmpCell = psCellinChip(tmpCell, chipCoord, tmpChip); 158 if (tmpCell != NULL) { 159 psFree(chipCoord); 160 return(tmpChip); 120 161 } 121 psFree( tmpCoord);122 } 123 psFree(tmpCoord); 162 psFree(chipCoord); 163 } 164 124 165 return (NULL); 125 166 } 126 167 127 /*128 XXX: do this129 */130 int checkValidImageCoords(double x, double y, psImage* tmpImage)131 {132 if ((x < 0.0) || (x > (double)tmpImage->numCols) || (y < 0.0) || (y > (double)tmpImage->numRows)) {133 return (0);134 }135 return (1);136 }137 138 168 /***************************************************************************** 139 169 XXX: We assume that readouts have valid coordinates from the range 140 (0,numRows or numCols) in each dimension, and that they are square with the 141 x/y axis. 142 170 (0,numRows or numCols) in each dimension, and that they are square with the 171 x/y axis. 143 172 XXX: We assume that if a cell has more than one readout, all readouts have 144 the same coordinates. 145 173 the same coordinates. 146 174 XXX: if we find no cell with has this coordinate, we return NULL. 147 148 175 XXX: must deallocate memory. 149 *****************************************************************************/ 150 psCell* psCellinChip(psCell* out, const psPlane* coord, const psChip* chip) 151 { 152 int i = 0; 153 psPlane* tmpCoord = NULL; 176 XXX: must return the cell in the "outCell" parameter. 177 XXX: verify the NULL parameter error handling. 178 *****************************************************************************/ 179 psCell* psCellinChip(psCell* outCell, 180 const psPlane* chipCoord, 181 const psChip* chip) 182 { 183 psPlane* cellCoord = NULL; 154 184 psArray* cells; 155 185 186 // We return NULL if either of the input parameters is NULL. 156 187 if (chip == NULL) { 157 188 return NULL; 158 189 } 159 190 191 if (chipCoord == NULL) { 192 return NULL; 193 } 194 160 195 cells = chip->cells; 161 162 196 if (cells == NULL) { 163 197 return NULL; 164 198 } 165 199 166 for (i = 0; i < cells->n; i++) { 200 // We loop over each cell in the chip. We transform the chipCoord into 201 // a cellCoord for that cell and determine if that cellCoord is valid. 202 // If so, then we return that cell. 203 for (int i = 0; i < cells->n; i++) { 167 204 psCell* tmpCell = (psCell* ) cells->data[i]; 168 205 psArray* readouts = tmpCell->readouts; 169 206 207 // We only check a single readout for this cell since we assume that 208 // all readouts for a cell have identical parameters. 170 209 if (readouts != NULL) { 171 for (int j = 0; j < readouts->n; j++) { 172 psReadout* tmpReadout = readouts->data[j]; 173 174 tmpCoord = psPlaneTransformApply(tmpCoord, tmpCell->fromChip, coord); 175 if (checkValidImageCoords(tmpCoord->x, tmpCoord->y, tmpReadout->image)) { 176 return (tmpCell); 177 } 210 psReadout* tmpReadout = readouts->data[0]; 211 212 cellCoord = psPlaneTransformApply(cellCoord, 213 tmpCell->fromChip, 214 chipCoord); 215 216 if (p_psCheckValidImageCoords(cellCoord->x, cellCoord->y, tmpReadout->image)) { 217 psFree(cellCoord); 218 return (tmpCell); 178 219 } 179 220 } 180 221 } 222 223 psFree(cellCoord); 181 224 return (NULL); 182 225 } 183 226 184 psPlane* psCoordCelltoChip(psPlane* out, const psPlane* in, const psCell* cell) 185 { 186 return (psPlaneTransformApply(out, cell->toChip, in)); 187 } 188 189 psPlane* psCoordChipToFPA(psPlane* out, const psPlane* in, const psChip* chip) 190 { 191 return (psPlaneTransformApply(out, chip->toFPA, in)); 192 } 193 194 psPlane* psCoordFPAtoTP(psPlane* out, const psPlane* in, const psFPA* fpa) 195 { 196 // XXX: This code doesn't work; fpa->toTangentPlane is of the wrong type. 197 // return(psPlaneTransformApply(out, fpa->toTangentPlane, in)); 198 return (NULL); 227 psPlane* psCoordCelltoChip(psPlane* outCoord, 228 const psPlane* inCoord, 229 const psCell* cell) 230 { 231 return (psPlaneTransformApply(outCoord, cell->toChip, inCoord)); 232 } 233 234 psPlane* psCoordChipToFPA(psPlane* outCoord, 235 const psPlane* inCoord, 236 const psChip* chip) 237 { 238 return (psPlaneTransformApply(outCoord, chip->toFPA, inCoord)); 239 } 240 241 /***************************************************************************** 242 XXX: must determine the correct values for XXX_Mag and XXX_Col; 243 *****************************************************************************/ 244 psPlane* psCoordFPAtoTP(psPlane* outCoord, 245 const psPlane* inCoord, 246 const psFPA* fpa) 247 { 248 float XXX_Mag = 0.0; 249 float XXX_Col = 0.0; 250 251 return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, 252 XXX_Mag, XXX_Col)); 199 253 } 200 254 201 255 // XXX: must wrap SLA_QAPQK here. 202 psSphere* psCoordTPtoSky(psSphere* out, const psPlane* in, const psGrommit* grommit) 203 { 256 psSphere* psCoordTPtoSky(psSphere* outSphere, 257 const psPlane* tpCoord, 258 const psGrommit* grommit) 259 { 260 if (outSphere == NULL) { 261 outSphere = (psSphere* ) psAlloc(sizeof(psSphere)); 262 } 263 204 264 /* 205 265 * double RAP; double DAP; 206 266 * 207 * extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP); sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, 208 * &DAP); */ 209 210 return (out); 211 } 212 213 psPlane* psCoordCellToFPA(psPlane* out, const psPlane* in, const psCell* cell) 214 { 215 return (psPlaneTransformApply(out, cell->toFPA, in)); 216 } 217 218 // XXX: This implementation requires a new psGrommit be created for each 219 // transformation, as well as a few psPlane structs. Can this be implemented 220 // better? 221 psSphere* psCoordCelltoSky(psSphere* out, 222 const psPlane* in, 267 * extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP); 268 * sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, &DAP); 269 */ 270 271 return (outSphere); 272 } 273 274 psPlane* psCoordCellToFPA(psPlane* fpaCoord, 275 const psPlane* cellCoord, 276 const psCell* cell) 277 { 278 return (psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord)); 279 } 280 281 /***************************************************************************** 282 XXX: This implementation requires a new psGrommit be created for each 283 transformation, as well as a few psPlane structs. Can this be implemented 284 better? 285 XXX: must determine the correct values for XXX_Mag and XXX_Col; 286 *****************************************************************************/ 287 psSphere* psCoordCelltoSky(psSphere* skyCoord, 288 const psPlane* cellCoord, 223 289 const psCell* cell) 224 290 { 225 psPlane* tmp1= NULL;226 psPlane* t mp2= NULL;291 psPlane* fpaCoord = NULL; 292 psPlane* tpCoord = NULL; 227 293 psFPA* parFPA = (cell->parent)->parent; 228 294 psGrommit* tmpGrommit = NULL; 229 float XXX1 = 0.0; 230 float XXX2 = 0.0; 231 232 233 tmp1 = psPlaneTransformApply(tmp1, cell->toFPA, in); 234 // XXX: 235 // 236 tmp2 = psPlaneDistortApply(tmp2, parFPA->toTangentPlane, tmp1, XXX1, XXX2); 295 float XXX_Mag = 0.0; 296 float XXX_Col = 0.0; 297 298 // Convert the input cell coordinates to FPA coordinates. 299 fpaCoord = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord); 300 301 // Convert the FPA coordinates to tangent plane Coordinates. 302 tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane, fpaCoord, XXX_Mag, XXX_Col); 303 304 // Generate a grommit for this FPA. 237 305 tmpGrommit = psGrommitAlloc(parFPA->exposure); 306 307 // Convert the tangent plane Coordinates to sky coordinates. 308 skyCoord = psCoordTPtoSky(skyCoord, tpCoord, tmpGrommit); 309 310 psFree(fpaCoord); 311 psFree(tpCoord); 312 psFree(tmpGrommit); 313 314 return(skyCoord); 315 } 316 317 /***************************************************************************** 318 XXX: not done 319 *****************************************************************************/ 320 psSphere* psCoordCelltoSkyQuick(psSphere* outSphere, 321 const psPlane* cellCoord, 322 const psCell* cell) 323 { 324 psPlane* tmp1 = NULL; 325 326 if (outSphere == NULL) { 327 outSphere = (psSphere* ) psAlloc(sizeof(psSphere)); 328 } 329 330 tmp1 = psPlaneTransformApply(tmp1, cell->toSky, cellCoord); 331 332 // XXX: Do something to convert the linear coords in tmp1 to spherical 333 // coords in outSphere. 334 238 335 psFree(tmp1); 239 psFree(tmp2); 240 psFree(tmpGrommit); 241 242 return(psCoordTPtoSky(out, tmp2, tmpGrommit)); 243 } 244 245 psSphere* psCoordCelltoSkyQuick(psSphere* out, const psPlane* in, const psCell* cell) 246 { 247 psPlane* tmp1 = NULL; 248 249 tmp1 = psPlaneTransformApply(tmp1, cell->toSky, in); 250 251 // XXX: Do something to convert the linear coords in tmp1 to spherical 252 // coords in out. 253 254 psFree(tmp1); 255 256 return (out); 257 } 258 259 // XXX: must wrap SLA_AOPQK here. 260 psPlane* psCoordSkytoTP(psPlane* out, const psSphere* in, const psGrommit* grommit) 336 337 return (outSphere); 338 } 339 340 /***************************************************************************** 341 XXX: must wrap SLA_AOPQK here. 342 *****************************************************************************/ 343 psPlane* psCoordSkytoTP(psPlane* tpCoord, 344 const psSphere* in, 345 const psGrommit* grommit) 261 346 { 262 347 /* … … 268 353 double ROB; 269 354 270 if ( out== NULL) {271 out= (psPlane* ) psAlloc(sizeof(psPlane));355 if (tpCoord == NULL) { 356 tpCoord = (psPlane* ) psAlloc(sizeof(psPlane)); 272 357 } 273 358 274 359 sla_AOPQK(psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB); 275 out->x = XXX;276 out->y = XXX;277 return ( out);360 tpCoord->x = XXX; 361 tpCoord->y = XXX; 362 return (tpCoord); 278 363 */ 279 364 return(NULL); … … 281 366 282 367 283 /* 284 XXX: What are the XXX1 and XXX2 args supposed to be? 285 */ 286 psPlane* psCoordTPtoFPA(psPlane* out, const psPlane* in, const psFPA* fpa) 287 { 288 float XXX1 = 0.0; 289 float XXX2 = 0.0; 290 291 return (psPlaneDistortApply(out, fpa->fromTangentPlane, in, XXX1, XXX2)); 292 } 293 294 psPlane* psCoordFPAtoChip(psPlane* out, const psPlane* in, const psChip* chip) 295 { 296 return (psPlaneTransformApply(out, chip->fromFPA, in)); 297 } 298 299 psPlane* psCoordChiptoCell(psPlane* out, const psPlane* in, const psCell* cell) 300 { 301 return (psPlaneTransformApply(out, cell->fromChip, in)); 302 } 303 304 psPlane* psCoordSkytoCell(psPlane* out, const psSphere* in, const psCell* cell) 368 /***************************************************************************** 369 XXX: must determine the correct values for XXX_Mag and XXX_Col; 370 *****************************************************************************/ 371 psPlane* psCoordTPtoFPA(psPlane* fpaCoord, 372 const psPlane* tpCoord, 373 const psFPA* fpa) 374 { 375 float XXX_Mag = 0.0; 376 float XXX_Col = 0.0; 377 378 return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, 379 tpCoord, XXX_Mag, XXX_Col)); 380 } 381 382 /***************************************************************************** 383 XXX: must first determine which chip contains this chipcoord. 384 *****************************************************************************/ 385 psPlane* psCoordFPAtoChip(psPlane* chipCoord, 386 const psPlane* fpaCoord, 387 const psChip* chip) 388 { 389 return (psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord)); 390 } 391 392 /***************************************************************************** 393 XXX: must first determine which cell contains this chipcoord. 394 *****************************************************************************/ 395 psPlane* psCoordChiptoCell(psPlane* cellCoord, 396 const psPlane* chipCoord, 397 const psCell* cell) 398 { 399 return (psPlaneTransformApply(cellCoord, cell->fromChip, chipCoord)); 400 } 401 402 /***************************************************************************** 403 XXX: once this works, get rid of the individual pointers for the various 404 coords. 405 XXX: How do we determine the grommit for the sky->tp coordinate conversion? 406 XXX: must determine which cell contains this chipcoord. 407 *****************************************************************************/ 408 psPlane* psCoordSkytoCell(psPlane* cellCoord, 409 const psSphere* skyCoord, 410 const psCell* cell) 305 411 { 306 412 psGrommit* XXXGrommit = NULL; 307 psFPA *whichFPA = NULL; 308 psChip *whichChip = NULL; 309 psCell *whichCell = NULL; 310 311 out = psCoordSkytoTP(out, in, XXXGrommit); 312 out = psCoordTPtoFPA(out, out, whichFPA); 313 out = psCoordFPAtoChip(out, out, whichChip); 314 out = psCoordChiptoCell(out, out, whichCell); 315 316 return (out); 317 } 318 319 psPlane* psCoordSkytoCellQuick(psPlane* out, const psSphere* in, const psCell* cell) 320 { 321 if (out == NULL) { 322 out = (psPlane* ) psAlloc(sizeof(psPlane)); 323 } 324 325 return (out); 326 } 413 psChip *whichChip = cell->parent; 414 psFPA *whichFPA = whichChip->parent; 415 416 // Convert the skyCoords to tangent plane coords. 417 psPlane *tpCoord = psCoordSkytoTP(tpCoord, skyCoord, XXXGrommit); 418 419 // Convert the tangent plane coords to FPA coords. 420 psPlane *fpaCoord = psCoordTPtoFPA(fpaCoord, tpCoord, whichFPA); 421 422 // Convert the FPA coords to chip coords. 423 psPlane *chipCoord = psCoordFPAtoChip(chipCoord, fpaCoord, whichChip); 424 425 // Convert the chip coords to cell coords. 426 cellCoord = psCoordChiptoCell(cellCoord, chipCoord, cell); 427 428 psFree(tpCoord); 429 psFree(fpaCoord); 430 psFree(chipCoord); 431 432 return (cellCoord); 433 } 434 435 /***************************************************************************** 436 XXX: It is unclear how to perform this transformation. 437 *****************************************************************************/ 438 psPlane* psCoordSkytoCellQuick(psPlane* cellCoord, 439 const psSphere* skyCoord, 440 const psCell* cell) 441 { 442 if (cellCoord == NULL) { 443 cellCoord = (psPlane* ) psAlloc(sizeof(psPlane)); 444 } 445 446 return (cellCoord); 447 }
Note:
See TracChangeset
for help on using the changeset viewer.
