Changeset 6328
- Timestamp:
- Feb 6, 2006, 11:57:04 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astro/psEarthOrientation.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psEarthOrientation.c
r6314 r6328 8 8 * @author Robert Daniel DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-02-0 3 00:11:54 $10 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-02-06 21:57:04 $ 12 12 * 13 13 * Copyright 2005 Maui High Performance Computing Center, University of Hawaii … … 18 18 19 19 #include "psEarthOrientation.h" 20 //#include "psTime.h"21 20 #include "psArray.h" 22 21 #include "psPolynomial.h" … … 43 42 #define JULIAN_CENTURY 36525.0 44 43 44 //The arrays used for storage of x,y,&s-values extracted from the precession data tables. 45 // Created in p_psEOCInit from finalsTable and used in psPrecessionModel. 45 46 static psArray* xTable = NULL; 46 47 static psArray* yTable = NULL; 47 48 static psArray* sTable = NULL; 49 50 //used for storage of the IERS precession table. Should contain MJD date followed by the 51 // corresponding dX & dY values from the finals2000A table. (Used in psPrecessionCorr.) 48 52 static psArray* iersTable = NULL; 53 //used for precession data. Should contain MJD date followed by the corresponding X, Y, & 54 // UT1-UTC values from the finals2000A table. (Used in psPrecessionModel, psGetPolarMotion). 49 55 static psArray* finalsTable = NULL; 56 57 //1D Polynomials created from the coefficients given by the tab5.2?.txt files. Used 58 // by psPrecessionModel to determine psEarthPole components. 50 59 static psPolynomial1D* xPoly = NULL; 51 60 static psPolynomial1D* yPoly = NULL; 52 61 static psPolynomial1D* sPoly = NULL; 62 63 //Boolean variable to tell whether the above EOC data has been initialized. 53 64 static bool eocInitialized = false; 54 65 66 //Internal function used for conversion from a 3x3 rotation matrix to a quaternion (psSphereRot). 55 67 static psSphereRot *rotMatrix_To_Quat(double A[3][3]); 56 68 … … 79 91 p_psGetConfigFileName(), 80 92 true); 81 93 //Make sure reading of config file worked correctly 82 94 if(eocMetadata == NULL) { 83 95 return false; … … 87 99 88 100 bool success = false; 89 // Get table format 101 // Get table formats & error if lookups fail. 90 102 char* tableFormat = psMetadataLookupStr(&success, eocMetadata, 91 103 "psLib.eoc.precession.table.format"); … … 105 117 } 106 118 107 char* yTableName = psMetadataLookupStr(&success, eocMetadata, "psLib.eoc.precession.table.file.y"); 119 char* yTableName = psMetadataLookupStr(&success, eocMetadata, 120 "psLib.eoc.precession.table.file.y"); 108 121 if(! success || yTableName == NULL) { 109 122 psFree(tableFormat); … … 179 192 } 180 193 194 //Extract the necessary data to setup the tables 181 195 xTable = psVectorsReadFromFile(xTableName, tableFormat); 182 196 yTable = psVectorsReadFromFile(yTableName, tableFormat); … … 185 199 finalsTable = psVectorsReadFromFile(finalsTableName, finalsTableFormat); 186 200 201 //Check that the data extraction was performed successfully. 187 202 if(xTable == NULL || yTable == NULL || sTable == NULL) { 188 // XXX: need to move the error message to the error messages file.189 203 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 190 204 "Failed to read the precession-nutation model tables."); 191 205 return false; 192 206 } 193 194 207 if(iersTable == NULL || finalsTable == NULL) { 195 // XXX: need to move the error message to the error messages file.196 208 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 197 209 "Failed to read the IERS/finals tables."); … … 199 211 } 200 212 213 //Load the coefficient data to setup the polynomials. 201 214 psVector* xCoeff = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.poly.x"); 202 215 if(! success || xCoeff == NULL || xCoeff->type.type != PS_TYPE_F64) { … … 220 233 return false; 221 234 } 235 //Allocate the X,Y,&S polynomials to be used for earthpole calculations 222 236 xPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, xCoeff->n); 223 237 memcpy(xPoly->coeff, xCoeff->data.F64,PSELEMTYPE_SIZEOF(PS_TYPE_F64)*xCoeff->n); … … 264 278 double speed) 265 279 { 280 //Check for valid inputs 266 281 PS_ASSERT_PTR_NON_NULL(actual, NULL); 267 282 PS_ASSERT_PTR_NON_NULL(direction, NULL); … … 272 287 } 273 288 274 if (apparent == NULL) {275 apparent = psSphereAlloc();276 } else {277 apparent->r = 0.0;278 apparent->d = 0.0;279 apparent->rErr = 0.0;280 apparent->dErr = 0.0;281 }282 // psSphere *rp = psSphereAlloc();283 289 psCube *rp = psCubeAlloc(); 284 // psSphere *r_p = psSphereAlloc();285 290 psCube *r_p = psCubeAlloc(); 286 291 double mu = 0.0; … … 288 293 double a = 0.0; 289 294 290 psCube* directionVector = psSphereToCube(direction); 291 if (directionVector == NULL) 292 printf("directionVector is null\n"); 293 psCube* actualVector = psSphereToCube(actual); 294 if (actualVector == NULL) 295 printf("actualVector is null\n"); 296 // mu = acos(directionVector->x*actualVector->x + 295 //Convert the spherical input coords direction and actual to cubic coords for computations. 296 psCube* directionVector = NULL; 297 directionVector = psSphereToCube(direction); 298 if (directionVector == NULL) { 299 PS_ASSERT_PTR_NON_NULL(directionVector, NULL); 300 } 301 psCube* actualVector = NULL; 302 actualVector = psSphereToCube(actual); 303 if (actualVector == NULL) { 304 PS_ASSERT_PTR_NON_NULL(actualVector, NULL); 305 } 306 307 //Calculate mu as the dot-product of direction and actual (from ADD) 297 308 mu = (directionVector->x*actualVector->x + 298 309 directionVector->y*actualVector->y + 299 310 directionVector->z*actualVector->z); 311 //Calculate r-perpendicular (as in sec 3.5.3.2 of ADD). actual = r-hat, direction = beta-hat. 300 312 rp->x = actualVector->x - mu * directionVector->x; 301 313 rp->y = actualVector->y - mu * directionVector->y; 302 314 rp->z = actualVector->z - mu * directionVector->z; 303 315 //Calculate mu-prime. (Eqn. 129 of ADD). 304 316 mu_p = mu - speed * ((mu * mu - 1.0) / (1.0 - speed * mu)); 305 306 //Not sure if this is right. ADD gets a scalar from division of rp (a vector) 307 //Paul claims rp is the modulus or square of the vector components 308 /* psCube* rpVector = psSphereToCube(rp); 309 a = sqrt( (1.0 - mu_p * mu_p) / ( rpVector->x*rpVector->x + 310 rpVector->y*rpVector->y + rpVector->z*rpVector->z) ); 311 */ 317 //Calculate a-value. (a = sqrt[ (1 - mu-prime^2) / modulus(r-perpendicular) ] ) 312 318 a = (1.0 - mu_p * mu_p) / (rp->x * rp->x + rp->y * rp->y + rp->z * rp->z); 313 319 if (a < 0.0) { 314 printf("a is negative\n"); 320 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 321 "Invalid parameter. a-value cannot be negative.\n"); 315 322 psFree(rp); 316 323 psFree(r_p); … … 319 326 psFree(apparent) 320 327 return NULL; 321 } else 328 } else { 322 329 a = sqrt(a); 323 330 } 331 //Calculate r-prime values. r-prime = mu-prime * beta-hat + a * r-perpendicular 324 332 r_p->x = mu_p * directionVector->x + a * rp->x; 325 333 r_p->y = mu_p * directionVector->y + a * rp->y; 326 334 r_p->z = mu_p * directionVector->z + a * rp->z; 327 328 //XXX: Must be a sign error somewhere above? Magnitude of change is correct but wrong way... 329 //This will fix the problem but is somewhat of a hack. 330 // r_p->x = actualVector->x - (r_p->x - actualVector->x); 331 // r_p->y = actualVector->y - (r_p->y - actualVector->y); 332 // r_p->z = actualVector->z - (r_p->z - actualVector->z); 333 334 psSphere *r_pSphere = psCubeToSphere(r_p); 335 if (r_pSphere == NULL) 336 printf("r_pSphere is null\n"); 337 338 *apparent = *r_pSphere; 335 //If apparent is non-NULL, deallocate it for use with psCubeToSphere 336 if (apparent != NULL) { 337 psFree(apparent); 338 } 339 //Convert r-prime to spherical coordinates for output. 340 apparent = psCubeToSphere(r_p); 341 if (apparent == NULL) { 342 psError(PS_ERR_BAD_PARAMETER_NULL, true, 343 "psCubeToSphere returned a NULL sphere in psAberration.\n"); 344 return NULL; 345 } 339 346 psFree(rp); 340 347 psFree(r_p); 341 psFree(r_pSphere)342 348 psFree(directionVector); 343 349 psFree(actualVector); 344 // psFree(rpVector); 350 345 351 return apparent; 346 352 }
Note:
See TracChangeset
for help on using the changeset viewer.
