Changeset 1407 for trunk/psLib/src/astro
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- Location:
- trunk/psLib/src/astro
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r1406 r1407 1 1 2 /** @file psCoord.c 2 3 * … … 10 11 * @author George Gusciora, MHPCC 11 12 * 12 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 6 22:34:05$13 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-08-07 00:06:06 $ 14 15 * 15 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 28 #include <float.h> 28 29 29 static float cot( float x);30 static float arg( float x, float y);30 static float cot(float x); 31 static float arg(float x, float y); 31 32 32 33 // This is the only function in this file which I understand. 33 psPlane *psPlaneTransformApply( psPlane *out, 34 const psPlaneTransform *transform, 35 const psPlane *coords ) 36 { 37 if ( out == NULL ) { 38 out = ( psPlane * ) psAlloc( sizeof( psPlane ) ); 39 } 40 out->x = transform->x->coeff[ 0 ][ 0 ] + 41 ( transform->x->coeff[ 1 ][ 0 ] * coords->x ) + 42 ( transform->x->coeff[ 0 ][ 1 ] * coords->y ); 43 44 out->y = transform->y->coeff[ 0 ][ 0 ] + 45 ( transform->y->coeff[ 1 ][ 0 ] * coords->x ) + 46 ( transform->y->coeff[ 0 ][ 1 ] * coords->y ); 47 48 return ( out ); 49 } 50 34 psPlane *psPlaneTransformApply(psPlane * out, const psPlaneTransform * transform, const psPlane * coords) 35 { 36 if (out == NULL) { 37 out = (psPlane *) psAlloc(sizeof(psPlane)); 38 } 39 out->x = transform->x->coeff[0][0] + 40 (transform->x->coeff[1][0] * coords->x) + (transform->x->coeff[0][1] * coords->y); 41 42 out->y = transform->y->coeff[0][0] + 43 (transform->y->coeff[1][0] * coords->x) + (transform->y->coeff[0][1] * coords->y); 44 45 return (out); 46 } 51 47 52 48 // This transformation takes into account parameters beyond an objects 53 49 // spatial coordinates: term3 and term4. 54 psPlane *psPlaneDistortApply( psPlane *out, 55 const psPlaneDistort *transform, 56 const psPlane *coords, 57 float term3, 58 float term4 ) 59 { 60 if ( out == NULL ) { 61 out = ( psPlane * ) psAlloc( sizeof( psPlane ) ); 62 } 63 64 out->x = transform->x->coeff[ 0 ][ 0 ][ 0 ][ 0 ] + 65 ( transform->x->coeff[ 1 ][ 0 ][ 0 ][ 0 ] * coords->x ) + 66 ( transform->x->coeff[ 0 ][ 1 ][ 0 ][ 0 ] * coords->y ) + 67 ( transform->x->coeff[ 0 ][ 0 ][ 1 ][ 0 ] * term3 ) + 68 ( transform->x->coeff[ 0 ][ 0 ][ 0 ][ 1 ] * term4 ); 69 70 out->y = transform->y->coeff[ 0 ][ 0 ][ 0 ][ 0 ] + 71 ( transform->y->coeff[ 1 ][ 0 ][ 0 ][ 0 ] * coords->x ) + 72 ( transform->y->coeff[ 0 ][ 1 ][ 0 ][ 0 ] * coords->y ) + 73 ( transform->y->coeff[ 0 ][ 0 ][ 1 ][ 0 ] * term3 ) + 74 ( transform->y->coeff[ 0 ][ 0 ][ 0 ][ 1 ] * term4 ); 75 76 return ( out ); 77 } 78 50 psPlane *psPlaneDistortApply(psPlane * out, 51 const psPlaneDistort * transform, 52 const psPlane * coords, float term3, float term4) 53 { 54 if (out == NULL) { 55 out = (psPlane *) psAlloc(sizeof(psPlane)); 56 } 57 58 out->x = transform->x->coeff[0][0][0][0] + 59 (transform->x->coeff[1][0][0][0] * coords->x) + 60 (transform->x->coeff[0][1][0][0] * coords->y) + 61 (transform->x->coeff[0][0][1][0] * term3) + (transform->x->coeff[0][0][0][1] * term4); 62 63 out->y = transform->y->coeff[0][0][0][0] + 64 (transform->y->coeff[1][0][0][0] * coords->x) + 65 (transform->y->coeff[0][1][0][0] * coords->y) + 66 (transform->y->coeff[0][0][1][0] * term3) + (transform->y->coeff[0][0][0][1] * term4); 67 68 return (out); 69 } 79 70 80 71 // This function prototype has been modified since the SDRS. 81 psSphereTransform *psSphereTransformAlloc( double NPlat, 82 double Xo, 83 double xo ) 84 { 85 psSphereTransform * tmp = ( psSphereTransform * ) psAlloc( sizeof( psSphereTransform ) ); 86 87 tmp->sinPhi = sin( NPlat ); 88 tmp->cosPhi = cos( NPlat ); 72 psSphereTransform *psSphereTransformAlloc(double NPlat, double Xo, double xo) 73 { 74 psSphereTransform *tmp = (psSphereTransform *) psAlloc(sizeof(psSphereTransform)); 75 76 tmp->sinPhi = sin(NPlat); 77 tmp->cosPhi = cos(NPlat); 89 78 tmp->Xo = Xo; 90 79 tmp->xo = xo; 91 80 92 return ( tmp);81 return (tmp); 93 82 } 94 83 … … 100 89 // there are no typo's. 101 90 102 psSphere *psSphereTransformApply( psSphere *out, 103 const psSphereTransform *transform, 104 const psSphere *coord ) 91 psSphere *psSphereTransformApply(psSphere * out, const psSphereTransform * transform, const psSphere * coord) 105 92 { 106 93 double sinY = 0.0; … … 112 99 double dx = 0.0; 113 100 114 if ( out == NULL) {115 out = ( psSphere * ) psAlloc( sizeof( psSphere ));101 if (out == NULL) { 102 out = (psSphere *) psAlloc(sizeof(psSphere)); 116 103 } 117 104 … … 119 106 y = coord->d; 120 107 dx = x - transform->xo; 121 sinY = cos( y ) * sin( dx ) * transform->sinPhi + sin( y ) * transform->cosPhi; 122 cosY = sqrt( 1.0 - sinY * sinY ); 123 sinX = ( cos( y ) * sin( dx ) * transform->cosPhi - sin( y ) * transform->sinPhi ) / 124 cos( y ); 125 cosX = cos( y ) * cos( dx ) / cos( y ); 126 127 out->r = atan2( sinX, cosX ) + transform->Xo; 128 out->d = atan2( sinY, cosY ); 129 130 return ( out ); 131 } 132 133 psSphereTransform *psSphereTransformICRStoEcliptic( psTime time ) 134 { 135 struct tm * tmTime = psTimeToTM( time ); 136 double year = ( double ) ( 1900 + tmTime->tm_year ); 108 sinY = cos(y) * sin(dx) * transform->sinPhi + sin(y) * transform->cosPhi; 109 cosY = sqrt(1.0 - sinY * sinY); 110 sinX = (cos(y) * sin(dx) * transform->cosPhi - sin(y) * transform->sinPhi) / cos(y); 111 cosX = cos(y) * cos(dx) / cos(y); 112 113 out->r = atan2(sinX, cosX) + transform->Xo; 114 out->d = atan2(sinY, cosY); 115 116 return (out); 117 } 118 119 psSphereTransform *psSphereTransformICRStoEcliptic(psTime time) 120 { 121 struct tm *tmTime = psTimeToTM(time); 122 double year = (double)(1900 + tmTime->tm_year); 137 123 double T = year / 100.0; 138 124 double phi = -23.452294 + 0.013013 * T + 0.000001639 * T * T - 0.000000503 * T * T * T; … … 140 126 double xo = 0.0; 141 127 142 return ( psSphereTransformAlloc( phi, Xo, xo ));143 } 144 145 psSphereTransform *psSphereTransformEcliptictoICRS( psTime time)146 { 147 struct tm * tmTime = psTimeToTM( time);148 double year = ( double ) ( 1900 + tmTime->tm_year);128 return (psSphereTransformAlloc(phi, Xo, xo)); 129 } 130 131 psSphereTransform *psSphereTransformEcliptictoICRS(psTime time) 132 { 133 struct tm *tmTime = psTimeToTM(time); 134 double year = (double)(1900 + tmTime->tm_year); 149 135 double T = year / 100.0; 150 double phi = + 23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T;136 double phi = +23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T; 151 137 double Xo = 0.0; 152 138 double xo = 0.0; 153 139 154 return ( psSphereTransformAlloc( phi, Xo, xo ));155 } 156 157 psSphereTransform *psSphereTransformICRStoGalatic( void)158 { 159 return ( psSphereTransformAlloc( 62.6, 282.25, 33.0 ));160 } 161 162 psSphereTransform *psSphereTransformGalatictoICRS( void)163 { 164 return ( psSphereTransformAlloc( -62.6, 33.0, 282.25 ));140 return (psSphereTransformAlloc(phi, Xo, xo)); 141 } 142 143 psSphereTransform *psSphereTransformICRStoGalatic(void) 144 { 145 return (psSphereTransformAlloc(62.6, 282.25, 33.0)); 146 } 147 148 psSphereTransform *psSphereTransformGalatictoICRS(void) 149 { 150 return (psSphereTransformAlloc(-62.6, 33.0, 282.25)); 165 151 } 166 152 167 153 // XXX: Is this the correct way to calculate this? 168 float cot( float x)169 { 170 return ( 1.0 / atan( x ));154 float cot(float x) 155 { 156 return (1.0 / atan(x)); 171 157 } 172 158 173 159 // This is some kind of arc tan function. 174 float arg( float x, float y ) 175 { 176 if ( x > 0 ) { 177 return ( atan( y / x ) ); 178 } else 179 if ( ( x == 0 ) && ( y == 0 ) ) { 180 return ( 0.5 * M_PI ); 181 } else 182 if ( ( x == 0 ) && ( y == 0 ) ) { 183 return ( -0.5 * M_PI ); 184 } else 185 if ( ( x == 0 ) && ( y == 0 ) ) { 186 return ( M_PI + atan( y / x ) ); 187 } else 188 if ( ( x == 0 ) && ( y == 0 ) ) { 189 return ( -M_PI + atan( y / x ) ); 190 } 191 192 psAbort( __func__, "Unacceptable range for (arg(%f, %f).\n", x, y ); 193 return ( 0.0 ); 160 float arg(float x, float y) 161 { 162 if (x > 0) { 163 return (atan(y / x)); 164 } else if ((x == 0) && (y == 0)) { 165 return (0.5 * M_PI); 166 } else if ((x == 0) && (y == 0)) { 167 return (-0.5 * M_PI); 168 } else if ((x == 0) && (y == 0)) { 169 return (M_PI + atan(y / x)); 170 } else if ((x == 0) && (y == 0)) { 171 return (-M_PI + atan(y / x)); 172 } 173 174 psAbort(__func__, "Unacceptable range for (arg(%f, %f).\n", x, y); 175 return (0.0); 194 176 } 195 177 196 178 // XXX: Waiting for the definition of the PS_PROJ_PAR projection. 197 179 // XXX: Waiting for the definition of the PS_PROJ_GLS projection. 198 psPlane *psProject( const psSphere *coord, 199 const psProjection *projection ) 180 psPlane *psProject(const psSphere * coord, const psProjection * projection) 200 181 { 201 182 float R = 0.0; 202 183 float alpha = 0.0; 203 psPlane *tmp = ( psPlane * ) psAlloc( sizeof( psPlane ) ); 204 205 if ( projection->type == PS_PROJ_TAN ) { 206 R = cot( coord->r ) * ( 180.0 / M_PI ); 207 tmp->x = R * sin( coord->d ); 208 tmp->y = R * cos( coord->d ); 209 210 } else 211 if ( projection->type == PS_PROJ_SIN ) { 212 R = cos( coord->r ) * ( 180.0 / M_PI ); 213 tmp->x = R * sin( coord->d ); 214 tmp->y = R * cos( coord->d ); 215 216 } else 217 if ( projection->type == PS_PROJ_CAR ) { 218 tmp->x = coord->d; 219 tmp->y = coord->r; 220 221 } else 222 if ( projection->type == PS_PROJ_MER ) { 223 tmp->x = coord->d; 224 tmp->y = log( tan( 45.0 + ( 0.5 * coord->r ) ) ) * 180.0 / M_PI; 225 226 } else 227 if ( projection->type == PS_PROJ_AIT ) { 228 alpha = 1.0 / ( ( 180.0 / M_PI ) * 229 sqrt( 1.0 + ( cos( coord->r ) * cos( 0.5 * coord->d ) * 0.5 ) ) ); 230 231 tmp->x = 2.0 * alpha * cos( coord->r ) * sin( 0.5 * coord->d ); 232 tmp->y = alpha * sin( coord->d ); 233 234 } else 235 if ( projection->type == PS_PROJ_PAR ) { 236 psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" ); 237 238 } else 239 if ( projection->type == PS_PROJ_GLS ) { 240 psAbort( __func__, "The projection type PS_PROJ_GLS is undefined.\n" ); 241 } 242 243 return ( tmp ); 184 psPlane *tmp = (psPlane *) psAlloc(sizeof(psPlane)); 185 186 if (projection->type == PS_PROJ_TAN) { 187 R = cot(coord->r) * (180.0 / M_PI); 188 tmp->x = R * sin(coord->d); 189 tmp->y = R * cos(coord->d); 190 191 } else if (projection->type == PS_PROJ_SIN) { 192 R = cos(coord->r) * (180.0 / M_PI); 193 tmp->x = R * sin(coord->d); 194 tmp->y = R * cos(coord->d); 195 196 } else if (projection->type == PS_PROJ_CAR) { 197 tmp->x = coord->d; 198 tmp->y = coord->r; 199 200 } else if (projection->type == PS_PROJ_MER) { 201 tmp->x = coord->d; 202 tmp->y = log(tan(45.0 + (0.5 * coord->r))) * 180.0 / M_PI; 203 204 } else if (projection->type == PS_PROJ_AIT) { 205 alpha = 1.0 / ((180.0 / M_PI) * sqrt(1.0 + (cos(coord->r) * cos(0.5 * coord->d) * 0.5))); 206 207 tmp->x = 2.0 * alpha * cos(coord->r) * sin(0.5 * coord->d); 208 tmp->y = alpha * sin(coord->d); 209 210 } else if (projection->type == PS_PROJ_PAR) { 211 psAbort(__func__, "The projection type PS_PROJ_PAR is undefined.\n"); 212 213 } else if (projection->type == PS_PROJ_GLS) { 214 psAbort(__func__, "The projection type PS_PROJ_GLS is undefined.\n"); 215 } 216 217 return (tmp); 244 218 } 245 219 246 220 // XXX: Waiting for the definition of the PS_PROJ_PAR projection. 247 221 // XXX: Waiting for the definition of the PS_PROJ_GLS projection. 248 psSphere *psDeproject( const psPlane *coord, 249 const psProjection *projection ) 222 psSphere *psDeproject(const psPlane * coord, const psProjection * projection) 250 223 { 251 224 float R = 0.0; … … 253 226 float chu1 = 0.0; 254 227 float chu2 = 0.0; 255 psSphere *tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) ); 256 257 if ( projection->type == PS_PROJ_TAN ) { 258 R = sqrt( ( coord->x * coord->x ) + ( coord->y * coord->y ) ); 259 tmp->d = arg( -coord->y, coord->x ); 260 tmp->r = atan( 180.0 / ( R * M_PI ) ); 261 262 } else 263 if ( projection->type == PS_PROJ_SIN ) { 264 R = sqrt( ( coord->x * coord->x ) + ( coord->y * coord->y ) ); 265 tmp->d = arg( -coord->y, coord->x ); 266 tmp->r = acos( ( R * M_PI ) / 180.0 ); 267 268 } else 269 if ( projection->type == PS_PROJ_CAR ) { 270 tmp->d = coord->x; 271 tmp->r = coord->y; 272 273 } else 274 if ( projection->type == PS_PROJ_MER ) { 275 tmp->d = coord->x; 276 tmp->r = ( 2.0 * atan( exp( ( coord->y * M_PI / 180.0 ) ) ) ) - 180.0; 277 278 } else 279 if ( projection->type == PS_PROJ_AIT ) { 280 chu1 = ( coord->x * M_PI ) / 720.0; 281 chu1 *= chu1; 282 chu2 = ( coord->y * M_PI ) / 360.0; 283 chu2 *= chu2; 284 chu = sqrt( 1.0 - chu1 - chu2 ); 285 tmp->d = 2.0 * arg( ( 2.0 * chu * chu ) - 1.0, 286 ( coord->x * chu * M_PI ) / 360.0 ); 287 tmp->r = asin( ( coord->y * chu * M_PI ) / 180.0 ); 288 289 } else 290 if ( projection->type == PS_PROJ_PAR ) { 291 psAbort( __func__, "The projection type PS_PROJ_PAR is undefined.\n" ); 292 293 } else 294 if ( projection->type == PS_PROJ_GLS ) { 295 psAbort( __func__, "The projection type PS_PROJ_GLG is undefined.\n" ); 296 } 297 298 return ( tmp ); 228 psSphere *tmp = (psSphere *) psAlloc(sizeof(psSphere)); 229 230 if (projection->type == PS_PROJ_TAN) { 231 R = sqrt((coord->x * coord->x) + (coord->y * coord->y)); 232 tmp->d = arg(-coord->y, coord->x); 233 tmp->r = atan(180.0 / (R * M_PI)); 234 235 } else if (projection->type == PS_PROJ_SIN) { 236 R = sqrt((coord->x * coord->x) + (coord->y * coord->y)); 237 tmp->d = arg(-coord->y, coord->x); 238 tmp->r = acos((R * M_PI) / 180.0); 239 240 } else if (projection->type == PS_PROJ_CAR) { 241 tmp->d = coord->x; 242 tmp->r = coord->y; 243 244 } else if (projection->type == PS_PROJ_MER) { 245 tmp->d = coord->x; 246 tmp->r = (2.0 * atan(exp((coord->y * M_PI / 180.0)))) - 180.0; 247 248 } else if (projection->type == PS_PROJ_AIT) { 249 chu1 = (coord->x * M_PI) / 720.0; 250 chu1 *= chu1; 251 chu2 = (coord->y * M_PI) / 360.0; 252 chu2 *= chu2; 253 chu = sqrt(1.0 - chu1 - chu2); 254 tmp->d = 2.0 * arg((2.0 * chu * chu) - 1.0, (coord->x * chu * M_PI) / 360.0); 255 tmp->r = asin((coord->y * chu * M_PI) / 180.0); 256 257 } else if (projection->type == PS_PROJ_PAR) { 258 psAbort(__func__, "The projection type PS_PROJ_PAR is undefined.\n"); 259 260 } else if (projection->type == PS_PROJ_GLS) { 261 psAbort(__func__, "The projection type PS_PROJ_GLG is undefined.\n"); 262 } 263 264 return (tmp); 299 265 } 300 266 301 267 // XXX: Do I need to check for unacceptable transformation parameters? 302 268 // Maybe, if the points are on the North/South Pole, etc? 303 psSphere *psSphereGetOffset( const psSphere *restrict position1, 304 const psSphere *restrict position2, 305 psSphereOffsetMode mode, 306 psSphereOffsetUnit unit ) 307 { 308 // psPlane *lin; 269 psSphere *psSphereGetOffset(const psSphere * restrict position1, 270 const psSphere * restrict position2, 271 psSphereOffsetMode mode, psSphereOffsetUnit unit) 272 { 273 // psPlane *lin; 309 274 psProjection proj; 310 275 psSphere *tmp; … … 312 277 double tmpD = 0.0; 313 278 314 if ( mode == PS_LINEAR) {279 if (mode == PS_LINEAR) { 315 280 // XXX: I have no idea how to construct this. Maybe project both 316 281 // sperical positions onto the plane, set the origin at one of the … … 318 283 319 284 // XXX: Do I need to somehow scale this projection? 320 // project position1? Will it project to (0.0, 0.0)?285 // project position1? Will it project to (0.0, 0.0)? 321 286 proj.R = position1->r; 322 287 proj.D = position1->d; … … 325 290 proj.type = PS_PROJ_TAN; 326 291 327 // lin = psProject(position2, proj);328 // tmp = psDeproject(lin, proj);292 // lin = psProject(position2, proj); 293 // tmp = psDeproject(lin, proj); 329 294 330 295 // XXX: Do we need to convert units in tmp? 331 return ( tmp ); 332 } else 333 if ( mode == PS_SPHERICAL ) { 334 tmpR = position2->r - position1->r; 335 tmpD = position2->d - position1->d; 336 337 if ( unit == PS_ARCSEC ) { 338 tmpR = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI; 339 tmpD = ( tmpR * 180.0 * 60.0 * 60.0 ) / M_PI; 340 } else 341 if ( unit == PS_ARCMIN ) { 342 tmpR = ( tmpR * 180.0 * 60.0 ) / M_PI; 343 tmpD = ( tmpR * 180.0 * 60.0 ) / M_PI; 344 } else 345 if ( unit == PS_DEGREE ) { 346 tmpR = ( tmpR * 180.0 ) / M_PI; 347 tmpD = ( tmpR * 180.0 ) / M_PI; 348 } else 349 if ( unit == PS_RADIAN ) {} 350 else { 351 psAbort( __func__, "Unknown offset unit: 0x%x\n", unit ); 352 } 353 354 tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) ); 355 tmp->r = tmpR; 356 tmp->d = tmpD; 357 tmp->rErr = 0.0; 358 tmp->dErr = 0.0; 359 // XXX: Do we need to wrap these to an acceptable range? 360 return ( tmp ); 296 return (tmp); 297 } else if (mode == PS_SPHERICAL) { 298 tmpR = position2->r - position1->r; 299 tmpD = position2->d - position1->d; 300 301 if (unit == PS_ARCSEC) { 302 tmpR = (tmpR * 180.0 * 60.0 * 60.0) / M_PI; 303 tmpD = (tmpR * 180.0 * 60.0 * 60.0) / M_PI; 304 } else if (unit == PS_ARCMIN) { 305 tmpR = (tmpR * 180.0 * 60.0) / M_PI; 306 tmpD = (tmpR * 180.0 * 60.0) / M_PI; 307 } else if (unit == PS_DEGREE) { 308 tmpR = (tmpR * 180.0) / M_PI; 309 tmpD = (tmpR * 180.0) / M_PI; 310 } else if (unit == PS_RADIAN) {} 311 else { 312 psAbort(__func__, "Unknown offset unit: 0x%x\n", unit); 361 313 } 362 psAbort( __func__, "Unrecognized offset mode\n" ); 363 return ( NULL ); 364 } 365 314 315 tmp = (psSphere *) psAlloc(sizeof(psSphere)); 316 tmp->r = tmpR; 317 tmp->d = tmpD; 318 tmp->rErr = 0.0; 319 tmp->dErr = 0.0; 320 // XXX: Do we need to wrap these to an acceptable range? 321 return (tmp); 322 } 323 psAbort(__func__, "Unrecognized offset mode\n"); 324 return (NULL); 325 } 366 326 367 327 // XXX: Do I need to check for unacceptable transformation parameters? 368 328 // Maybe, if the points are on the North/South Pole, etc? 369 329 // XXX: I copied the algorithm from the ADD exactly. 370 psSphere *psSphereSetOffset( const psSphere *restrict position, 371 const psSphere *restrict offset, 372 psSphereOffsetMode mode, 373 psSphereOffsetUnit unit ) 330 psSphere *psSphereSetOffset(const psSphere * restrict position, 331 const psSphere * restrict offset, 332 psSphereOffsetMode mode, psSphereOffsetUnit unit) 374 333 { 375 334 psPlane lin; … … 379 338 double tmpD = 0.0; 380 339 381 if ( mode == PS_LINEAR) {340 if (mode == PS_LINEAR) { 382 341 proj.R = position->r; 383 342 proj.D = position->d; … … 389 348 lin.y = offset->d; 390 349 391 tmp = psDeproject( &lin, &proj ); 392 return ( tmp ); 393 394 } else 395 if ( mode == PS_SPHERICAL ) { 396 if ( unit == PS_ARCSEC ) { 397 tmpR = ( M_PI * offset->r ) / ( 180.0 * 60.0 * 60.0 ); 398 tmpD = ( M_PI * offset->d ) / ( 180.0 * 60.0 * 60.0 ); 399 } else 400 if ( unit == PS_ARCMIN ) { 401 tmpR = ( M_PI * offset->r ) / ( 180.0 * 60.0 ); 402 tmpD = ( M_PI * offset->d ) / ( 180.0 * 60.0 ); 403 } else 404 if ( unit == PS_DEGREE ) { 405 tmpR = ( M_PI * offset->r ) / ( 180.0 ); 406 tmpD = ( M_PI * offset->d ) / ( 180.0 ); 407 } else 408 if ( unit == PS_RADIAN ) { 409 tmpR = offset->r; 410 tmpD = offset->d; 411 } else { 412 psAbort( __func__, "Unknown offset unit: 0x%x\n", unit ); 413 } 414 415 tmp = ( psSphere * ) psAlloc( sizeof( psSphere ) ); 416 tmp->r = position->r + tmpR; 417 tmp->r = position->d + tmpD; 418 tmp->rErr = 0.0; 419 tmp->dErr = 0.0; 420 421 // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI) 422 // and (0 to 2*PI). 423 return ( tmp ); 350 tmp = psDeproject(&lin, &proj); 351 return (tmp); 352 353 } else if (mode == PS_SPHERICAL) { 354 if (unit == PS_ARCSEC) { 355 tmpR = (M_PI * offset->r) / (180.0 * 60.0 * 60.0); 356 tmpD = (M_PI * offset->d) / (180.0 * 60.0 * 60.0); 357 } else if (unit == PS_ARCMIN) { 358 tmpR = (M_PI * offset->r) / (180.0 * 60.0); 359 tmpD = (M_PI * offset->d) / (180.0 * 60.0); 360 } else if (unit == PS_DEGREE) { 361 tmpR = (M_PI * offset->r) / (180.0); 362 tmpD = (M_PI * offset->d) / (180.0); 363 } else if (unit == PS_RADIAN) { 364 tmpR = offset->r; 365 tmpD = offset->d; 366 } else { 367 psAbort(__func__, "Unknown offset unit: 0x%x\n", unit); 424 368 } 425 psAbort( __func__, "Unrecognized offset mode\n" ); 426 return ( NULL ); 427 } 369 370 tmp = (psSphere *) psAlloc(sizeof(psSphere)); 371 tmp->r = position->r + tmpR; 372 tmp->r = position->d + tmpD; 373 tmp->rErr = 0.0; 374 tmp->dErr = 0.0; 375 376 // XXX: wrap tmp->r and tmp->d to the allowed range (-PI to PI) 377 // and (0 to 2*PI). 378 return (tmp); 379 } 380 psAbort(__func__, "Unrecognized offset mode\n"); 381 return (NULL); 382 } -
trunk/psLib/src/astro/psCoord.h
r1393 r1407 1 1 2 /** @file psCoord.h 2 3 * … … 10 11 * @author George Gusciora, MHPCC 11 12 * 12 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 5 19:38:51$13 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-08-07 00:06:06 $ 14 15 * 15 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 17 */ 17 18 18 # ifndef PS_COORD_H19 # define PS_COORD_H20 21 # include "psType.h"22 # include "psImage.h"23 # include "psArray.h"24 # include "psList.h"25 # include "psFunctions.h"26 # include "psTime.h"19 #ifndef PS_COORD_H 20 # define PS_COORD_H 21 22 # include "psType.h" 23 # include "psImage.h" 24 # include "psArray.h" 25 # include "psList.h" 26 # include "psFunctions.h" 27 # include "psTime.h" 27 28 28 29 /// @addtogroup CoordinateTransform … … 38 39 typedef struct 39 40 { 40 double x; ///< x position41 double y; ///< y position42 double xErr; ///< Error in x position43 double yErr; ///< Error in y position41 double x; // /< x position 42 double y; // /< y position 43 double xErr; // /< Error in x position 44 double yErr; // /< Error in y position 44 45 } 45 46 psPlane; … … 54 55 typedef struct 55 56 { 56 double r; ///< RA57 double d; ///< Dec58 double rErr; ///< Error in RA59 double dErr; ///< Error in Dec57 double r; // /< RA 58 double d; // /< Dec 59 double rErr; // /< Error in RA 60 double dErr; // /< Error in Dec 60 61 } 61 62 psSphere; … … 71 72 typedef struct 72 73 { 73 psDPolynomial2D *x; ///< 2D polynomial transform of X coordinates74 psDPolynomial2D *y; ///< 2D polynomial transform of Y coordinates74 psDPolynomial2D *x; // /< 2D polynomial transform of X coordinates 75 psDPolynomial2D *y; // /< 2D polynomial transform of Y coordinates 75 76 } 76 77 psPlaneTransform; … … 90 91 typedef struct 91 92 { 92 psDPolynomial4D *x; ///< 4D polynomial transform of X coordinates93 psDPolynomial4D *y; ///< 4D polynomial transform of Y coordinates93 psDPolynomial4D *x; // /< 4D polynomial transform of X coordinates 94 psDPolynomial4D *y; // /< 4D polynomial transform of Y coordinates 94 95 } 95 96 psPlaneDistort; … … 107 108 typedef struct 108 109 { 109 double sinPhi; ///< sin of North Pole lattitude110 double cosPhi; ///< cos of North Pole lattitude111 double Xo; ///< First PT of Ares lon112 double xo; ///< First PT of Ares equiv lon110 double sinPhi; // /< sin of North Pole lattitude 111 double cosPhi; // /< cos of North Pole lattitude 112 double Xo; // /< First PT of Ares lon 113 double xo; // /< First PT of Ares equiv lon 113 114 } 114 115 psSphereTransform; … … 120 121 */ 121 122 typedef enum { 122 PS_PROJ_TAN, ///< Tangent projection123 PS_PROJ_SIN, ///< Sine projection124 PS_PROJ_AIT, ///< Aitoff projection125 PS_PROJ_PAR, ///< Par projection126 PS_PROJ_GLS, ///< GLS projection127 PS_PROJ_CAR, ///< CAR projection128 PS_PROJ_MER, ///< MER projection129 PS_PROJ_NTYPE ///< Number of types; must be last.123 PS_PROJ_TAN, // /< Tangent projection 124 PS_PROJ_SIN, // /< Sine projection 125 PS_PROJ_AIT, // /< Aitoff projection 126 PS_PROJ_PAR, // /< Par projection 127 PS_PROJ_GLS, // /< GLS projection 128 PS_PROJ_CAR, // /< CAR projection 129 PS_PROJ_MER, // /< MER projection 130 PS_PROJ_NTYPE // /< Number of types; must be last. 130 131 } psProjectionType; 131 132 … … 137 138 typedef struct 138 139 { 139 double R; ///< Coordinates of projection center140 double D; ///< Coordinates of projection center141 double Xs; ///< plate-scale in X direction142 double Ys; ///< plate-scale in Y direction143 psProjectionType type; ///< Projection type140 double R; // /< Coordinates of projection center 141 double D; // /< Coordinates of projection center 142 double Xs; // /< plate-scale in X direction 143 double Ys; // /< plate-scale in Y direction 144 psProjectionType type; // /< Projection type 144 145 } 145 146 psProjection; … … 151 152 */ 152 153 typedef enum { 153 PS_SPHERICAL, ///< offset corresponds to an angular offset154 PS_LINEAR ///< offset corresponds to a linear offset154 PS_SPHERICAL, // /< offset corresponds to an angular offset 155 PS_LINEAR // /< offset corresponds to a linear offset 155 156 } psSphereOffsetMode; 156 157 … … 161 162 */ 162 163 typedef enum { 163 PS_ARCSEC, ///< Arcseconds164 PS_ARCMIN, ///< Arcminutes165 PS_DEGREE, ///< Degrees166 PS_RADIAN ///< Radians164 PS_ARCSEC, // /< Arcseconds 165 PS_ARCMIN, // /< Arcminutes 166 PS_DEGREE, // /< Degrees 167 PS_RADIAN // /< Radians 167 168 } psSphereOffsetUnit; 168 169 … … 170 171 * 171 172 */ 172 psPlane *psPlaneTransformApply( 173 psPlane *out, ///< a psPlane to recycle. If NULL, a new one is generated. 174 const psPlaneTransform *transform, ///< the transform to apply 175 const psPlane *coords ///< the coordinate to apply the transform above. 176 ); 173 psPlane *psPlaneTransformApply(psPlane * out, // /< a psPlane to recycle. If NULL, a new one is generated. 174 const psPlaneTransform * transform, // /< the transform to apply 175 const psPlane * coords // /< the coordinate to apply the transform above. 176 ); 177 177 178 178 /** Applies the psPlaneDistort transform to a specified coordinate 179 179 * 180 180 */ 181 psPlane *psPlaneDistortApply( 182 psPlane *out, ///< a psPlane to recycle. If NULL, a new one is generated. 183 const psPlaneDistort *transform, ///< the transform to apply 184 const psPlane *coords, ///< the coordinate to apply the transform above. 185 float term3, ///< third term -- maybe magnitude 186 float term4 ///< forth term -- maybe color 187 ); 181 psPlane *psPlaneDistortApply(psPlane * out, // /< a psPlane to recycle. If NULL, a new one is generated. 182 const psPlaneDistort * transform, // /< the transform to apply 183 const psPlane * coords, // /< the coordinate to apply the transform above. 184 float term3, // /< third term -- maybe magnitude 185 float term4 // /< forth term -- maybe color 186 ); 188 187 189 188 /** Allocator for psSphereTransform 190 189 * 191 190 */ 192 psSphereTransform *psSphereTransformAlloc( 193 double NPlat, ///< north pole latitude 194 double Xo, ///< First PT of Ares lon 195 double xo ///< First PT of Ares equiv lon 196 ); 197 191 psSphereTransform *psSphereTransformAlloc(double NPlat, // /< north pole latitude 192 double Xo, // /< First PT of Ares lon 193 double xo // /< First PT of Ares equiv lon 194 ); 198 195 199 196 /** Applies the psSphereTransform transform for a specified coordinate 200 197 * 201 198 */ 202 psSphere *psSphereTransformApply( 203 psSphere *out, ///< a psSphere to recycle. If NULL, a new one is generated. 204 const psSphereTransform *transform,///< the transform to apply 205 const psSphere *coord ///< the coordinate to apply the transform above.x 206 ); 207 208 psSphereTransform *psSphereTransformICRStoEcliptic( 209 psTime time 210 ); 211 212 psSphereTransform *psSphereTransformEcliptictoICRS( 213 psTime time 214 ); 215 216 psSphereTransform *psSphereTransformICRStoGalatic( void ); 217 218 psSphereTransform *psSphereTransformGalatictoICRS( void ); 219 220 psPlane *psProject( 221 const psSphere *coord, 222 const psProjection *projection 223 ); 224 225 psSphere *psDeproject( 226 const psPlane *coord, 227 const psProjection *projection 228 ); 229 230 psSphere *psSphereGetOffset( 231 const psSphere *restrict position1, 232 const psSphere *restrict position2, 233 psSphereOffsetMode mode, 234 psSphereOffsetUnit unit 235 ); 236 237 psSphere *psSphereSetOffset( 238 const psSphere *restrict position, 239 const psSphere *restrict offset, 240 psSphereOffsetMode mode, 241 psSphereOffsetUnit unit 242 ); 199 psSphere *psSphereTransformApply(psSphere * out, // /< a psSphere to recycle. If NULL, a new one is 200 // generated. 201 const psSphereTransform * transform, // /< the transform to apply 202 const psSphere * coord // /< the coordinate to apply the transform above.x 203 ); 204 205 psSphereTransform *psSphereTransformICRStoEcliptic(psTime time); 206 207 psSphereTransform *psSphereTransformEcliptictoICRS(psTime time); 208 209 psSphereTransform *psSphereTransformICRStoGalatic(void); 210 211 psSphereTransform *psSphereTransformGalatictoICRS(void); 212 213 psPlane *psProject(const psSphere * coord, const psProjection * projection); 214 215 psSphere *psDeproject(const psPlane * coord, const psProjection * projection); 216 217 psSphere *psSphereGetOffset(const psSphere * restrict position1, 218 const psSphere * restrict position2, 219 psSphereOffsetMode mode, psSphereOffsetUnit unit); 220 221 psSphere *psSphereSetOffset(const psSphere * restrict position, 222 const psSphere * restrict offset, 223 psSphereOffsetMode mode, psSphereOffsetUnit unit); 243 224 244 225 /// @} -
trunk/psLib/src/astro/psTime.c
r1406 r1407 1 1 2 /** @file psTime.c 2 3 * … … 12 13 * @author Ross Harman, MHPCC 13 14 * 14 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-08-0 6 22:34:05$15 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2004-08-07 00:06:06 $ 16 17 * 17 18 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 18 19 */ 19 20 20 21 21 /******************************************************************************/ 22 22 23 /* INCLUDE FILES */ 24 23 25 /******************************************************************************/ 24 26 … … 32 34 33 35 /******************************************************************************/ 36 34 37 /* DEFINE STATEMENTS */ 38 35 39 /******************************************************************************/ 36 40 … … 73 77 } \ 74 78 79 75 80 /******************************************************************************/ 81 76 82 /* TYPE DEFINITIONS */ 83 77 84 /******************************************************************************/ 78 85 … … 80 87 81 88 /*****************************************************************************/ 89 82 90 /* GLOBAL VARIABLES */ 91 83 92 /*****************************************************************************/ 84 93 … … 86 95 87 96 /*****************************************************************************/ 97 88 98 /* FILE STATIC VARIABLES */ 99 89 100 /*****************************************************************************/ 90 101 … … 119 130 120 131 // Table for Julian date of leapsecond update and current total number of leapseconds at that date 121 static double leapseconds[NUM_LEAPSECOND_UPDATES][2] = 122 { 123 { 124 2441317.5, 10.0 125 }, 126 { 127 2441499.5, 11.0 128 }, 129 { 130 2441683.5, 12.0 131 }, 132 { 133 2442048.5, 13.0 134 }, 135 { 136 2442413.5, 14.0 137 }, 138 { 139 2442778.5, 15.0 140 }, 141 { 142 2443144.5, 16.0 143 }, 144 { 145 2443509.5, 17.0 146 }, 147 { 148 2443874.5, 18.0 149 }, 150 { 151 2444239.5, 19.0 152 }, 153 { 154 2444786.5, 20.0 155 }, 156 { 157 2445151.5, 21.0 158 }, 159 { 160 2445516.5, 22.0 161 }, 162 { 163 2446247.5, 23.0 164 }, 165 { 166 2447161.5, 24.0 167 }, 168 { 169 2447892.5, 25.0 170 }, 171 { 172 2448257.5, 26.0 173 }, 174 { 175 2448804.5, 27.0 176 }, 177 { 178 2449169.5, 28.0 179 }, 180 { 181 2449534.5, 29.0 182 }, 183 { 184 2450083.5, 30.0 185 }, 186 { 187 2450630.5, 31.0 188 }, 189 { 190 2451179.5, 32.0 191 } 192 }; 193 194 /*****************************************************************************/ 132 static double leapseconds[NUM_LEAPSECOND_UPDATES][2] = { 133 { 134 2441317.5, 10.0}, 135 { 136 2441499.5, 11.0}, 137 { 138 2441683.5, 12.0}, 139 { 140 2442048.5, 13.0}, 141 { 142 2442413.5, 14.0}, 143 { 144 2442778.5, 15.0}, 145 { 146 2443144.5, 16.0}, 147 { 148 2443509.5, 17.0}, 149 { 150 2443874.5, 18.0}, 151 { 152 2444239.5, 19.0}, 153 { 154 2444786.5, 20.0}, 155 { 156 2445151.5, 21.0}, 157 { 158 2445516.5, 22.0}, 159 { 160 2446247.5, 23.0}, 161 { 162 2447161.5, 24.0}, 163 { 164 2447892.5, 25.0}, 165 { 166 2448257.5, 26.0}, 167 { 168 2448804.5, 27.0}, 169 { 170 2449169.5, 28.0}, 171 { 172 2449534.5, 29.0}, 173 { 174 2450083.5, 30.0}, 175 { 176 2450630.5, 31.0}, 177 { 178 2451179.5, 32.0} 179 }; 180 181 /*****************************************************************************/ 182 195 183 /* FUNCTION IMPLEMENTATION - LOCAL */ 184 196 185 /*****************************************************************************/ 197 186 … … 199 188 200 189 /*****************************************************************************/ 190 201 191 /* FUNCTION IMPLEMENTATION - PUBLIC */ 192 202 193 /*****************************************************************************/ 203 194 … … 210 201 time.tv_usec = 0; 211 202 212 if (gettimeofday(&now,(struct timezone *)0) == -1) {203 if (gettimeofday(&now, (struct timezone *)0) == -1) { 213 204 psError(__func__, " : Line %d - Failed to get time", __LINE__); 214 205 return time; 215 206 } 216 217 207 // Convert timeval time to psTime 218 208 time.tv_sec = now.tv_sec; … … 220 210 221 211 // Add most current leapseconds value to UTC time to get TAI time 222 time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES -1][1];212 time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES - 1][1]; 223 213 224 214 return time; 225 215 } 226 216 227 char *psTimeToISO(psTime time)217 char *psTimeToISO(psTime time) 228 218 { 229 219 int ms = 0; … … 232 222 struct tm *tmTime = NULL; 233 223 234 CHECK_NEGATIVE_TIME_STRUCT(time, NULL);224 CHECK_NEGATIVE_TIME_STRUCT(time, NULL); 235 225 236 226 tempString = psAlloc(MAX_TIME_STRING_LENGTH); … … 238 228 239 229 // Converts psTime to YYYY/MM/DD,HH:MM:SS.SSS in string form 240 ms = time.tv_usec /1000;230 ms = time.tv_usec / 1000; 241 231 242 232 // tmTime variable is statically allocated, no need to free 243 233 tmTime = gmtime(&time.tv_sec); 244 if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y/%m/%d,%H:%M:%S", tmTime)) {234 if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y/%m/%d,%H:%M:%S", tmTime)) { 245 235 psError(__func__, " : Line %d - Failed strftime conversion", __LINE__); 246 236 } 247 237 248 if (snprintf(timeString,MAX_TIME_STRING_LENGTH,"%s.%3.3d", tempString, ms) < 0) {238 if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3d", tempString, ms) < 0) { 249 239 psError(__func__, " : Line %d - Failed snprintf conversion", __LINE__); 250 240 } … … 262 252 psTime outTime; 263 253 264 CHECK_NEGATIVE_TIME_STRUCT(time, outTime);254 CHECK_NEGATIVE_TIME_STRUCT(time, outTime); 265 255 266 256 // Find leapseconds to subtract from psTime to get UTC time 267 257 jd = psTimeToJD(time); 268 258 jdTable = leapseconds[0]; 269 for (i=0; i<NUM_LEAPSECOND_UPDATES; i++, jdTable+=2) {270 if (jd > *jdTable) {259 for (i = 0; i < NUM_LEAPSECOND_UPDATES; i++, jdTable += 2) { 260 if (jd > *jdTable) { 271 261 ls = *(jdTable + 1); 272 262 } … … 276 266 outTime.tv_usec = time.tv_usec; 277 267 278 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);268 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 279 269 280 270 return outTime; … … 285 275 double mjd = 0.0; 286 276 287 CHECK_NEGATIVE_TIME_STRUCT(time, mjd);277 CHECK_NEGATIVE_TIME_STRUCT(time, mjd); 288 278 289 279 // Modified Julian date conversion courtesy of Eugene Magnier 290 mjd = time.tv_sec /SEC_PER_DAY + time.tv_usec/USEC_PER_DAY + 40587.0;280 mjd = time.tv_sec / SEC_PER_DAY + time.tv_usec / USEC_PER_DAY + 40587.0; 291 281 292 282 return mjd; … … 297 287 double jd = 0.0; 298 288 299 CHECK_NEGATIVE_TIME_STRUCT(time, jd);289 CHECK_NEGATIVE_TIME_STRUCT(time, jd); 300 290 301 291 // Julian date conversion courtesy of Eugene Magnier 302 jd = time.tv_sec /SEC_PER_DAY + time.tv_usec/USEC_PER_DAY + 2440587.5;292 jd = time.tv_sec / SEC_PER_DAY + time.tv_usec / USEC_PER_DAY + 2440587.5; 303 293 304 294 return jd; … … 309 299 struct timeval timevalTime; 310 300 311 CHECK_NEGATIVE_TIME_STRUCT(time, timevalTime);301 CHECK_NEGATIVE_TIME_STRUCT(time, timevalTime); 312 302 timevalTime.tv_sec = time.tv_sec; 313 303 timevalTime.tv_usec = time.tv_usec; … … 316 306 } 317 307 318 struct tm *psTimeToTM(psTime time)308 struct tm *psTimeToTM(psTime time) 319 309 { 320 310 struct tm *tmTime = NULL; 321 311 322 CHECK_NEGATIVE_TIME_STRUCT(time, tmTime);312 CHECK_NEGATIVE_TIME_STRUCT(time, tmTime); 323 313 tmTime = gmtime(&time.tv_sec); 324 314 … … 343 333 // Convert YYYY/MM/DD,HH:MM:SS.SSS in string form to tm time 344 334 year = atoi(strtok(tempString, "/")); 345 if (year < 1900) {346 psError(__func__, "Years less than 1900 not allowed. Value: %d", year);335 if (year < 1900) { 336 psError(__func__, "Years less than 1900 not allowed. Value: %d", year); 347 337 return outTime; 348 338 } 349 339 350 340 month = atoi(strtok(NULL, "/")); 351 if (month<1 || month>12) {352 psError(__func__, "Month must have a value from 1 to 12. Value: %d", month);341 if (month < 1 || month > 12) { 342 psError(__func__, "Month must have a value from 1 to 12. Value: %d", month); 353 343 return outTime; 354 344 } 355 345 356 346 day = atoi(strtok(NULL, ",")); 357 if (day<1 || day>31) {358 psError(__func__, "Day must have a value from 1 to 31. Value: %d", day);347 if (day < 1 || day > 31) { 348 psError(__func__, "Day must have a value from 1 to 31. Value: %d", day); 359 349 return outTime; 360 350 } 361 351 362 352 hour = atoi(strtok(NULL, ":")); 363 if (hour<0 || hour>23) {364 psError(__func__, "Hour must have a value from 0 to 23. Value: %d", hour);353 if (hour < 0 || hour > 23) { 354 psError(__func__, "Hour must have a value from 0 to 23. Value: %d", hour); 365 355 return outTime; 366 356 } 367 357 368 358 minute = atoi(strtok(NULL, ":")); 369 if (minute<0 || minute>59) {370 psError(__func__, "Minute must have a value from 0 to 59. Value: %d", minute);359 if (minute < 0 || minute > 59) { 360 psError(__func__, "Minute must have a value from 0 to 59. Value: %d", minute); 371 361 return outTime; 372 362 } 373 363 374 364 second = atoi(strtok(NULL, ".")); 375 if (second<0 || second>59) {376 psError(__func__, "Second must have a value from 0 to 59. Value: %d", second);365 if (second < 0 || second > 59) { 366 psError(__func__, "Second must have a value from 0 to 59. Value: %d", second); 377 367 return outTime; 378 368 } 379 369 380 370 millisecond = atoi(strtok(NULL, "X")); 381 if (millisecond<0 || millisecond>1000) {382 psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond);371 if (millisecond < 0 || millisecond > 1000) { 372 psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond); 383 373 return outTime; 384 374 } … … 394 384 // Convert tm time to psTime 395 385 outTime = psTMToTime(&tmTime); 396 outTime.tv_usec = millisecond *1000;386 outTime.tv_usec = millisecond * 1000; 397 387 398 388 return outTime; … … 403 393 psTime outTime; 404 394 405 CHECK_NEGATIVE_TIME_STRUCT(time, outTime);395 CHECK_NEGATIVE_TIME_STRUCT(time, outTime); 406 396 407 397 // Convert UTC time to psTime/TAI 408 outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES -1][1];398 outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES - 1][1]; 409 399 outTime.tv_usec = time.tv_usec; 410 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);400 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 411 401 412 402 return outTime; … … 419 409 double seconds = 0.0; 420 410 421 CHECK_NEGATIVE_TIME(time, outTime);411 CHECK_NEGATIVE_TIME(time, outTime); 422 412 423 413 // Modified Julian date conversion courtesy of Eugene Magnier … … 425 415 426 416 // Convert to psTime/TAI 427 seconds = days *SEC_PER_DAY;428 outTime.tv_usec = (seconds - (long)seconds)*1000000.0;417 seconds = days * SEC_PER_DAY; 418 outTime.tv_usec = (seconds - (long)seconds) * 1000000.0; 429 419 outTime.tv_sec = seconds; 430 420 431 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);421 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 432 422 433 423 return outTime; … … 440 430 psTime outTime; 441 431 442 CHECK_NEGATIVE_TIME(time, outTime);432 CHECK_NEGATIVE_TIME(time, outTime); 443 433 444 434 // Julian date conversion courtesy of Eugene Magnier … … 446 436 447 437 // Convert to psTime/TAI 448 seconds = days *SEC_PER_DAY;438 seconds = days * SEC_PER_DAY; 449 439 outTime.tv_sec = seconds; 450 outTime.tv_usec = (seconds -(long)seconds)*1000000.0; 451 452 CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime); 453 454 return outTime; 455 } 456 457 psTime psTimevalToTime(struct timeval *time) 458 { 459 psTime outTime; 460 if(time == NULL) 461 { 462 psError(__func__,"Null value for timeval arg not allowed"); 463 return outTime; 464 } else 465 if(time->tv_sec < 0) 466 { 467 psError(__func__,"Negative seconds are not allowed: %ld", time->tv_sec); 468 return outTime; 469 } else 470 if(time->tv_usec<0) 471 { 472 psError(__func__,"Negative microseconds are not allowed: %ld", time->tv_usec); 473 return outTime; 474 } 475 440 outTime.tv_usec = (seconds - (long)seconds) * 1000000.0; 441 442 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 443 444 return outTime; 445 } 446 447 psTime psTimevalToTime(struct timeval * time) 448 { 449 psTime outTime; 450 451 if (time == NULL) 452 { 453 psError(__func__, "Null value for timeval arg not allowed"); 454 return outTime; 455 } else if (time->tv_sec < 0) 456 { 457 psError(__func__, "Negative seconds are not allowed: %ld", time->tv_sec); 458 return outTime; 459 } else if (time->tv_usec < 0) 460 { 461 psError(__func__, "Negative microseconds are not allowed: %ld", time->tv_usec); 462 return outTime; 463 } 476 464 // Convert to psTime/TAI 477 465 outTime.tv_sec = time->tv_sec; 478 466 outTime.tv_usec = time->tv_usec; 479 467 480 CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime); 481 482 return outTime; 483 } 484 485 486 psTime psTMToTime(struct tm *time) 468 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 469 470 return outTime; 471 } 472 473 psTime psTMToTime(struct tm * time) 487 474 { 488 475 int i; 489 476 int n; 490 477 int y; 491 int mon [] = 492 { 493 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 494 }; 478 int mon[] = { 479 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 480 }; 495 481 long epoch; 496 482 psTime outTime; 497 483 498 i = 0;484 i = 0; 499 485 n = 0; 500 486 y = 0; 501 487 epoch = 0; 502 488 503 if(time == NULL) 504 { 505 psError(__func__,"Null value for tm arg not allowed"); 506 return outTime; 507 } else 508 if(time->tm_year < 70) 509 { 510 psError(__func__,"Input times earlier than 1970 not allowed. Value: %d", time->tm_year+1900); 511 return outTime; 512 } else 513 if(time->tm_mon<0 || time->tm_mon>11) 514 { 515 psError(__func__,"Month must have a value from 0 to 11. Value: %d", time->tm_mon); 516 return outTime; 517 } else 518 if(time->tm_mday<1 || time->tm_mday>31) 519 { 520 psError(__func__,"Day must have a value from 1 to 31. Value: %d", time->tm_mday); 521 return outTime; 522 } else 523 if(time->tm_hour<0 || time->tm_hour>23) 524 { 525 psError(__func__,"Hour must have a value from 0 to 23. Value: %d", time->tm_hour); 526 return outTime; 527 } else 528 if(time->tm_min<0 || time->tm_min>59) 529 { 530 psError(__func__,"Minute must have a value from 0 to 59. Value: %d", time->tm_min); 531 return outTime; 532 } else 533 if(time->tm_sec<0 || time->tm_sec>59) 534 { 535 psError(__func__,"Second must have a value from 0 to 59. Value: %d", time->tm_sec); 536 return outTime; 537 } 489 if (time == NULL) 490 { 491 psError(__func__, "Null value for tm arg not allowed"); 492 return outTime; 493 } else if (time->tm_year < 70) 494 { 495 psError(__func__, "Input times earlier than 1970 not allowed. Value: %d", time->tm_year + 1900); 496 return outTime; 497 } else if (time->tm_mon < 0 || time->tm_mon > 11) 498 { 499 psError(__func__, "Month must have a value from 0 to 11. Value: %d", time->tm_mon); 500 return outTime; 501 } else if (time->tm_mday < 1 || time->tm_mday > 31) 502 { 503 psError(__func__, "Day must have a value from 1 to 31. Value: %d", time->tm_mday); 504 return outTime; 505 } else if (time->tm_hour < 0 || time->tm_hour > 23) 506 { 507 psError(__func__, "Hour must have a value from 0 to 23. Value: %d", time->tm_hour); 508 return outTime; 509 } else if (time->tm_min < 0 || time->tm_min > 59) 510 { 511 psError(__func__, "Minute must have a value from 0 to 59. Value: %d", time->tm_min); 512 return outTime; 513 } else if (time->tm_sec < 0 || time->tm_sec > 59) 514 { 515 psError(__func__, "Second must have a value from 0 to 59. Value: %d", time->tm_sec); 516 return outTime; 517 } 538 518 539 519 n = time->tm_year + 1900 - 1; 540 epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n /4 - n/100 + n/400) -541 (1969 /4 - 1969/100 + 1969/400)) * SEC_PER_DAY;520 epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n / 4 - n / 100 + n / 400) - 521 (1969 / 4 - 1969 / 100 + 1969 / 400)) * SEC_PER_DAY; 542 522 543 523 y = time->tm_year + 1900; 544 524 545 525 // Adjust for leap years 546 for (i = 0; i<time->tm_mon; i++)547 { 548 epoch += mon [i] * SEC_PER_DAY;549 if (i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {526 for (i = 0; i < time->tm_mon; i++) 527 { 528 epoch += mon[i] * SEC_PER_DAY; 529 if (i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { 550 530 epoch += SEC_PER_DAY; 551 531 } … … 554 534 // Add everything 555 535 epoch += (time->tm_mday - 1) * SEC_PER_DAY; 556 epoch += time->tm_hour * SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec;536 epoch += time->tm_hour * SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec; 557 537 558 538 // Create psTime … … 560 540 outTime.tv_sec = epoch; 561 541 562 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);563 564 return outTime; 565 } 542 CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime); 543 544 return outTime; 545 } -
trunk/psLib/src/astro/psTime.h
r1406 r1407 1 1 2 /** @file psTime.h 2 3 * … … 12 13 * @author Ross Harman, MHPCC 13 14 * 14 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-08-0 6 22:34:05$15 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2004-08-07 00:06:06 $ 16 17 * 17 18 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 20 20 21 #ifndef PSTIME_H 21 # define PSTIME_H22 23 # include <time.h>24 # include <sys/types.h>25 # include <sys/time.h>26 27 # include "psType.h"22 # define PSTIME_H 23 24 # include <time.h> 25 # include <sys/types.h> 26 # include <sys/time.h> 27 28 # include "psType.h" 28 29 29 30 /// @addtogroup Time … … 31 32 32 33 /******************************************************************************/ 34 33 35 /* TYPE DEFINITIONS */ 36 34 37 /******************************************************************************/ 35 38 … … 42 45 typedef struct 43 46 { 44 time_t tv_sec; /**< Seconds since epoch, Jan 1, 1970. */ 45 suseconds_t tv_usec; /**< Microseconds since last second. */ 47 48 time_t tv_sec; /**< Seconds since epoch, Jan 1, 1970. */ 49 50 suseconds_t tv_usec; /**< Microseconds since last second. */ 46 51 } 47 52 psTime; 48 53 49 54 /*****************************************************************************/ 55 50 56 /* FUNCTION PROTOTYPES */ 57 51 58 /*****************************************************************************/ 52 59 … … 57 64 * @return psTime: Struct with current time. 58 65 */ 59 psTime psTimeGetTime( 60 void /** No argument. */ 61 ); 66 67 psTime psTimeGetTime(void 68 /** No argument. */ 69 ); 62 70 63 71 /** Convert psTime to ISO time in TAI units. … … 68 76 * @return char*: Pointer null terminated array of chars in ISO time. 69 77 */ 70 char* psTimeToISO( 71 psTime time /** Input time to be converted. */ 72 ); 78 79 char *psTimeToISO(psTime time 80 /** Input time to be converted. */ 81 ); 73 82 74 83 /** Convert psTime to UTC time. … … 80 89 * @return psTime: UTC time psTime format. 81 90 */ 82 psTime psTimeToUTC( 83 psTime time /** Input time to be converted. */ 84 ); 91 92 psTime psTimeToUTC(psTime time 93 /** Input time to be converted. */ 94 ); 85 95 86 96 /** Convert psTime to modified Julian date time. … … 91 101 * @return double: Modified Julian Days (MJD) time. 92 102 */ 93 double psTimeToMJD( 94 psTime time /** Input time to be converted. */ 95 ); 103 104 double psTimeToMJD(psTime time 105 /** Input time to be converted. */ 106 ); 96 107 97 108 /** Convert psTime to Julian date time. … … 102 113 * @return double: Julian Date (JD) time. 103 114 */ 104 double psTimeToJD( 105 psTime time /** Input time to be converted. */ 106 ); 115 116 double psTimeToJD(psTime time 117 /** Input time to be converted. */ 118 ); 107 119 108 120 /** Convert psTime to timeval time. … … 113 125 * @return timeval: timeval struct time. 114 126 */ 115 struct timeval psTimeToTimeval( 116 psTime time /** Input time to be converted. */ 117 ); 127 128 struct timeval psTimeToTimeval(psTime time 129 /** Input time to be converted. */ 130 ); 118 131 119 132 /** Convert psTime to tm time. … … 124 137 * @return tm: tm struct time. 125 138 */ 126 struct tm* psTimeToTM( 127 psTime time /** Input time to be converted. */ 128 ); 139 140 struct tm *psTimeToTM(psTime time 141 /** Input time to be converted. */ 142 ); 129 143 130 144 /** Convert ISO to psTime. … … 135 149 * @return psTime: time 136 150 */ 137 psTime psISOToTime( 138 char *time /** Input time to be converted. */ 139 ); 151 152 psTime psISOToTime(char *time 153 /** Input time to be converted. */ 154 ); 140 155 141 156 /** Convert UTC to psTime. … … 146 161 * @return psTime: time in TAI units. 147 162 */ 148 psTime psUTCToTime( 149 psTime time /** Input time to be converted. */ 150 ); 163 164 psTime psUTCToTime(psTime time 165 /** Input time to be converted. */ 166 ); 151 167 152 168 /** Convert MJD to psTime. … … 157 173 * @return psTime: time. 158 174 */ 159 psTime psMJDToTime( 160 double time /** Input time to be converted. */ 161 ); 175 176 psTime psMJDToTime(double time 177 /** Input time to be converted. */ 178 ); 162 179 163 180 /** Convert JD to psTime. … … 168 185 * @return psTime: time. 169 186 */ 170 psTime psJDToTime( 171 double time /** Input time to be converted. */ 172 ); 187 188 psTime psJDToTime(double time 189 /** Input time to be converted. */ 190 ); 173 191 174 192 /** Convert timeval to psTime. … … 179 197 * @return psTime: time. 180 198 */ 181 psTime psTimevalToTime( 182 struct timeval *time /** Input time to be converted. */ 183 ); 199 200 psTime psTimevalToTime(struct timeval *time 201 /** Input time to be converted. */ 202 ); 184 203 185 204 /** Convert tm time to psTime. … … 190 209 * @return psTime: time. 191 210 */ 192 psTime psTMToTime( 193 struct tm *time /** Input time to be converted. */ 194 ); 211 212 psTime psTMToTime(struct tm *time 213 /** Input time to be converted. */ 214 ); 215 195 216 /// @} 196 217
Note:
See TracChangeset
for help on using the changeset viewer.
