Changeset 5012
- Timestamp:
- Sep 12, 2005, 2:54:15 PM (21 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 3 edited
-
astro/psEarthOrientation.c (modified) (5 diffs)
-
astro/psEarthOrientation.h (modified) (2 diffs)
-
sys/psTrace.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psEarthOrientation.c
r4541 r5012 8 8 * @author Robert Daniel DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-0 7-12 19:27:27$10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-09-13 00:49:53 $ 12 12 * 13 13 * Copyright 2005 Maui High Performance Computing Center, University of Hawaii 14 14 */ 15 15 16 #include <math.h> 17 #include <string.h> 18 19 #include "psEarthOrientation.h" 20 #include "psTime.h" 21 #include "psArray.h" 22 #include "psFunctions.h" 23 #include "psVector.h" 24 #include "psMetadata.h" 25 #include "psMetadataConfig.h" 26 #include "psError.h" 27 #include "psErrorText.h" 28 #include "psMemory.h" 29 #include "psCoord.h" 30 #include "psConstants.h" 31 32 // Sun's Mass (src: Google's Calculator Service) 33 #define PS_M 1.98892e30 /* kilograms */ 34 // Newton's Gravitational Constant (src:NIST) 35 #define PS_G 6.6742e-11 /* m^3/kg/s^2 */ 36 // Speed of light in vacuum (src:NIST) 37 #define PS_C0 299792458.0 /* m/s */ 38 // Average distance from earth to sun 39 #define PS_AU 149597890000.0 /* meters */ 40 // Modified Julian Day 1/1/2000 00:00:00 41 #define MJD_2000 51544.0 42 // Days in Julian century 43 #define JULIAN_CENTURY 36525.0 44 45 static psArray* xTable = NULL; 46 static psArray* yTable = NULL; 47 static psArray* sTable = NULL; 48 static psPolynomial1D* xPoly = NULL; 49 static psPolynomial1D* yPoly = NULL; 50 static psPolynomial1D* sPoly = NULL; 51 static bool eocInitialized = false; 52 53 static bool eocInit() 54 { 55 int nFail = 0; 56 57 // Read config file 58 psMetadata* eocMetadata = psMetadataConfigParse(NULL, 59 &nFail, 60 p_psGetConfigFileName(), 61 true); 62 63 if(eocMetadata == NULL) { 64 return false; 65 } else if(nFail != 0) { 66 return false; 67 } 68 69 bool success = false; 70 // Get table format 71 char* tableFormat = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.table.format"); 72 if(! success || tableFormat == NULL) { 73 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 74 "psLib.eoc.precession.table.format"); 75 return false; 76 } 77 78 char* xTableName = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.table.file.x"); 79 if(! success || xTableName == NULL) { 80 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 81 "psLib.eoc.precession.x.file"); 82 return false; 83 } 84 85 char* yTableName = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.table.file.y"); 86 if(! success || yTableName == NULL) { 87 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 88 "psLib.eoc.precession.y.file"); 89 return false; 90 } 91 92 char* sTableName = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.table.file.s"); 93 if(! success || sTableName == NULL) { 94 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 95 "psLib.eoc.precession.s.file"); 96 return false; 97 } 98 xTable = psVectorsReadFromFile(xTableName, tableFormat); 99 yTable = psVectorsReadFromFile(yTableName, tableFormat); 100 sTable = psVectorsReadFromFile(sTableName, tableFormat); 101 if(xTable == NULL || yTable == NULL || sTable == NULL) { 102 // XXX: need to move the error message to the error messages file. 103 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 104 "Failed to read the precession-nutation model tables."); 105 return false; 106 } 107 108 psVector* xCoeff = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.poly.x"); 109 if(! success || xCoeff == NULL || xCoeff->type.type != PS_TYPE_F64) { 110 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 111 "psLib.eoc.precession.poly.x"); 112 return false; 113 } 114 psVector* yCoeff = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.poly.y"); 115 if(! success || yCoeff == NULL || yCoeff->type.type != PS_TYPE_F64) { 116 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 117 "psLib.eoc.precession.poly.y"); 118 return false; 119 } 120 psVector* sCoeff = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.poly.s"); 121 if(! success || sCoeff == NULL || sCoeff->type.type != PS_TYPE_F64) { 122 psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_LOOKUP_METADATA_FAILED, 123 "psLib.eoc.precession.poly.s"); 124 return false; 125 } 126 xPoly = psPolynomial1DAlloc(xCoeff->n, PS_POLYNOMIAL_ORD); 127 memcpy(xPoly->coeff, xCoeff->data.F64,PSELEMTYPE_SIZEOF(PS_TYPE_F64)*xCoeff->n); 128 yPoly = psPolynomial1DAlloc(yCoeff->n, PS_POLYNOMIAL_ORD); 129 memcpy(yPoly->coeff, yCoeff->data.F64,PSELEMTYPE_SIZEOF(PS_TYPE_F64)*yCoeff->n); 130 sPoly = psPolynomial1DAlloc(sCoeff->n, PS_POLYNOMIAL_ORD); 131 memcpy(sPoly->coeff, sCoeff->data.F64,PSELEMTYPE_SIZEOF(PS_TYPE_F64)*sCoeff->n); 132 133 return true; 134 } 135 136 bool p_psEOCFinalize(void) 137 { 138 psFree(xTable); 139 psFree(yTable); 140 psFree(sTable); 141 142 xTable = NULL; 143 yTable = NULL; 144 sTable = NULL; 145 146 psFree(xPoly); 147 psFree(yPoly); 148 psFree(sPoly); 149 150 xPoly = NULL; 151 yPoly = NULL; 152 sPoly = NULL; 153 154 eocInitialized = false; 155 156 return true; 157 } 158 16 159 psSphere *psAberration(psSphere *apparent, const psSphere *actual, const psSphere *direction, double speed) 17 160 { 161 162 18 163 return NULL; 19 164 } … … 21 166 psSphere *psGravityDeflection(psSphere *apparent, psSphere *actual, psSphere *sun) 22 167 { 168 // calculating the apparent angle from the actual angle and the sun position 169 170 // first, calculate the angle between the sun vector and the actual vector 171 172 // Moving to cartesian first: XXX -- is this required? 173 psCube* sunVector = psSphereToCube(sun); 174 psCube* actualVector = psSphereToCube(actual); 175 176 // use dot product to calculate the angle of separation 177 // N.B., assuming the psSphereToCube function returns a unit vector. 178 double theta = acos(sunVector->x*actualVector->x + 179 sunVector->y*actualVector->y + 180 sunVector->z*actualVector->z); 181 182 double r0 = PS_AU * tan(theta); 183 184 double deflection = 4.0*PS_G*PS_M/(PS_C0*PS_C0*r0); 185 186 // make sure the deflection is not greater than 1.75 arcsec 187 double limit = SEC_TO_RAD(1.75); 188 if (deflection > limit) { 189 deflection = limit; 190 } 191 192 // bend the actual vector away from the sun vector by deflection angle. 193 194 23 195 return NULL; 24 196 } … … 27 199 double psEOC_ParallaxFactor(const psSphere *coords, const psTime *time) 28 200 { 201 202 29 203 return NAN; 30 204 } … … 32 206 psEarthPole *psEOC_PrecessionModel(const psTime *time) 33 207 { 34 return NULL; 208 // Check for null parameter 209 PS_ASSERT_PTR_NON_NULL(time, NULL); 210 211 // Convert psTime to MJD 212 double MJD = psTimeToMJD(time); 213 214 // Calculate number of Julian centuries since 2000 215 double t = ( MJD - MJD_2000 ) / JULIAN_CENTURY; 216 double t2 = t*t; 217 double t3 = t*t*t; 218 double t4 = t*t*t*t; 219 220 // N.B., the following formulae are from the ADD 221 // Mean Anomaly of the Moon 222 double F[14]; 223 F[0] = DEG_TO_RAD(134.96340251) + 224 SEC_TO_RAD(1717915923.2178)*t + 225 SEC_TO_RAD(31.8792)*t2 + 226 SEC_TO_RAD(0.051635)*t3 - 227 SEC_TO_RAD(0.00024470)*t4; 228 229 // Mean Anomaly of the Sun 230 F[1] = DEG_TO_RAD(357.52910918) + 231 SEC_TO_RAD(129596581.0481)*t - 232 SEC_TO_RAD(0.5532)*t2 + 233 SEC_TO_RAD(0.000136)*t3 - 234 SEC_TO_RAD(0.00001149)*t4; 235 236 // L â Omega 237 F[2] = DEG_TO_RAD(93.27209062) + 238 SEC_TO_RAD(1739527262.8478)*t - 239 SEC_TO_RAD(12.7512)*t2 - 240 SEC_TO_RAD(0.001037)*t3 + 241 SEC_TO_RAD(0.00000417)*t4; 242 243 // Mean Elongation of the Moon from the Sun 244 F[3] = DEG_TO_RAD(297.85019547) + 245 SEC_TO_RAD(1602961601.2090)*t - 246 SEC_TO_RAD(6.3706)*t2 + 247 SEC_TO_RAD(0.006593)*t3 - 248 SEC_TO_RAD(0.00003169)*t4; 249 250 // Mean Longitude of the Ascending Node of the Moon 251 F[4] = DEG_TO_RAD(125.04455501) - 252 SEC_TO_RAD(6962890.5431)*t + 253 SEC_TO_RAD(7.4722)*t2 + 254 SEC_TO_RAD(0.007702)*t3 - 255 SEC_TO_RAD(0.0000593)*t4; 256 257 F[5] = 4.402608842 + 2608.7903141574*t; 258 F[6] = 3.176146697 + 1021.3285546211*t; 259 F[7] = 1.753470314 + 628.3075849991*t; 260 F[8] = 6.203480913 + 334.0612426700*t; 261 F[9] = 0.599546497 + 52.9690962641*t; 262 F[10] = 0.874016757 + 21.3299104960*t; 263 F[11] = 5.481293872 + 7.4781598567*t; 264 F[12] = 5.311886287 + 3.8133035638*t; 265 F[13] = 0.024381750*t + 0.00000538691*t2; 266 267 // Check if EOC data loaded 268 if(! eocInitialized) { 269 eocInitialized = eocInit(); 270 if(!eocInitialized) { 271 // XXX: Move error message. 272 psError(PS_ERR_UNKNOWN, false, 273 "Could not initialize EOC tables -- check data files."); 274 return NULL; 275 } 276 } 277 278 // calculate the polynomial portion first 279 double X = psPolynomial1DEval(xPoly,t); 280 double Y = psPolynomial1DEval(yPoly,t); 281 double S = psPolynomial1DEval(sPoly,t); 282 283 // now calculate the non-poly portion from the tables 284 285 psF64* cols[17]; 286 for (int lcv = 0; lcv < 17; lcv++) { 287 cols[lcv] = ((psVector*)(xTable->data[lcv]))->data.F64; 288 } 289 int numRows = ((psVector*)(xTable->data[0]))->n; 290 for (int lcv = 0; lcv < numRows; lcv++) { 291 // arg = sum w_(i,j,k)*F_k 292 double arg = 0.0; 293 for (int k = 0; k < 14; k++) { 294 arg += cols[k+3][lcv]*F[k]; 295 } 296 double tj = pow(t,cols[0][lcv]); 297 double as = cols[1][lcv]; 298 double ac = cols[2][lcv]; 299 300 X += as*tj*sin(arg) + ac*tj*cos(arg); 301 } 302 303 for (int lcv = 0; lcv < 17; lcv++) { 304 cols[lcv] = ((psVector*)(yTable->data[lcv]))->data.F64; 305 } 306 numRows = ((psVector*)(yTable->data[0]))->n; 307 for (int lcv = 0; lcv < numRows; lcv++) { 308 // arg = sum w_(i,j,k)*F_k 309 double arg = 0.0; 310 for (int k = 0; k < 14; k++) { 311 arg += cols[k+3][lcv]*F[k]; 312 } 313 double tj = pow(t,cols[0][lcv]); 314 double as = cols[1][lcv]; 315 double ac = cols[2][lcv]; 316 317 Y += as*tj*sin(arg) + ac*tj*cos(arg); 318 } 319 320 for (int lcv = 0; lcv < 17; lcv++) { 321 cols[lcv] = ((psVector*)(sTable->data[lcv]))->data.F64; 322 } 323 numRows = ((psVector*)(sTable->data[0]))->n; 324 for (int lcv = 0; lcv < numRows; lcv++) { 325 // arg = sum w_(i,j,k)*F_k 326 double arg = 0.0; 327 for (int k = 0; k < 14; k++) { 328 arg += cols[k+3][lcv]*F[k]; 329 } 330 double tj = pow(t,cols[0][lcv]); 331 double as = cols[1][lcv]; 332 double ac = cols[2][lcv]; 333 334 S += as*tj*sin(arg) + ac*tj*cos(arg); 335 } 336 337 // now, the tables for S actually gives S + XY/2, so let's get the real S now 338 S -= X*Y/2.0; 339 340 psEarthPole* pole = psAlloc(sizeof(psEarthPole)); 341 pole->x = X; 342 pole->y = Y; 343 pole->s = S; 344 345 return pole; 35 346 } 36 347 … … 42 353 43 354 44 psSphereRot *psSphereRot_CEOtoGCRS(const psEarthPole *pole) 45 { 46 return NULL; 47 } 48 49 50 psSphereRot *psSphereRot_TEOtoCEO(const psTime *time) 51 { 52 return NULL; 53 } 54 55 56 psEarthPole *psEOC_GetPolarMotion(const psTime *time, psTimeBulletin bulletin) 57 { 58 return NULL; 59 } 60 61 62 psEarthPole *psEOC_PolarTideCorr(const psTime *time) 63 { 64 return NULL; 65 } 66 67 68 psEarthPole *psEOC_NutationCorr(psTime *time) 69 { 70 return NULL; 71 } 72 73 74 psSphereRot *psSphereRot_ITRStoTEO(const psEarthPole *motion) 75 { 76 return NULL; 77 } 78 79 355 psSphereRot* psSphereRot_CEOtoGCRS(const psEarthPole *pole) 356 { 357 return NULL; 358 } 359 360 361 psSphereRot* psSphereRot_TEOtoCEO(const psTime *time) 362 { 363 return NULL; 364 } 365 366 367 psEarthPole* psEOC_GetPolarMotion(const psTime *time, psTimeBulletin bulletin) 368 { 369 return NULL; 370 } 371 372 373 psEarthPole* psEOC_PolarTideCorr(const psTime *time) 374 { 375 return NULL; 376 } 377 378 379 psEarthPole* psEOC_NutationCorr(psTime *time) 380 { 381 return NULL; 382 } 383 384 385 psSphereRot* psSphereRot_ITRStoTEO(const psEarthPole* motion) 386 { 387 return NULL; 388 } -
trunk/psLib/src/astro/psEarthOrientation.h
r4541 r5012 8 8 * @author Robert Daniel DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-0 7-12 19:27:27$10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-09-13 00:50:04 $ 12 12 * 13 13 * Copyright 2005 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psCoord.h" 20 20 #include "psTime.h" 21 #include "psSphereOps.h" 21 22 22 23 typedef struct -
trunk/psLib/src/sys/psTrace.h
r4972 r5012 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-09- 08 00:27:50$11 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-09-13 00:54:15 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 16 16 #if !defined(PS_TRACE_H) 17 17 #define PS_TRACE_H 1 18 #include <stdarg.h> 18 19 19 20 #define PS_UNKNOWN_TRACE_LEVEL -9999 // we don't know this name's level
Note:
See TracChangeset
for help on using the changeset viewer.
