IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6328


Ignore:
Timestamp:
Feb 6, 2006, 11:57:04 AM (20 years ago)
Author:
drobbin
Message:

added comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psEarthOrientation.c

    r6314 r6328  
    88 *  @author Robert Daniel DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-02-03 00:11:54 $
     10 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-02-06 21:57:04 $
    1212 *
    1313 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919#include "psEarthOrientation.h"
    20 //#include "psTime.h"
    2120#include "psArray.h"
    2221#include "psPolynomial.h"
     
    4342#define JULIAN_CENTURY 36525.0
    4443
     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.
    4546static psArray* xTable = NULL;
    4647static psArray* yTable = NULL;
    4748static 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.)
    4852static 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).
    4955static 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.
    5059static psPolynomial1D* xPoly = NULL;
    5160static psPolynomial1D* yPoly = NULL;
    5261static psPolynomial1D* sPoly = NULL;
     62
     63//Boolean variable to tell whether the above EOC data has been initialized.
    5364static bool eocInitialized = false;
    5465
     66//Internal function used for conversion from a 3x3 rotation matrix to a quaternion (psSphereRot).
    5567static psSphereRot *rotMatrix_To_Quat(double A[3][3]);
    5668
     
    7991                              p_psGetConfigFileName(),
    8092                              true);
    81 
     93    //Make sure reading of config file worked correctly
    8294    if(eocMetadata == NULL) {
    8395        return false;
     
    8799
    88100    bool success = false;
    89     // Get table format
     101    // Get table formats & error if lookups fail.
    90102    char* tableFormat = psMetadataLookupStr(&success, eocMetadata,
    91103                                            "psLib.eoc.precession.table.format");
     
    105117    }
    106118
    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");
    108121    if(! success || yTableName == NULL) {
    109122        psFree(tableFormat);
     
    179192    }
    180193
     194    //Extract the necessary data to setup the tables
    181195    xTable = psVectorsReadFromFile(xTableName, tableFormat);
    182196    yTable = psVectorsReadFromFile(yTableName, tableFormat);
     
    185199    finalsTable = psVectorsReadFromFile(finalsTableName, finalsTableFormat);
    186200
     201    //Check that the data extraction was performed successfully.
    187202    if(xTable == NULL || yTable == NULL || sTable == NULL) {
    188         // XXX: need to move the error message to the error messages file.
    189203        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    190204                "Failed to read the precession-nutation model tables.");
    191205        return false;
    192206    }
    193 
    194207    if(iersTable == NULL || finalsTable == NULL) {
    195         // XXX: need to move the error message to the error messages file.
    196208        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    197209                "Failed to read the IERS/finals tables.");
     
    199211    }
    200212
     213    //Load the coefficient data to setup the polynomials.
    201214    psVector* xCoeff = psMetadataLookupPtr(&success, eocMetadata, "psLib.eoc.precession.poly.x");
    202215    if(! success || xCoeff == NULL || xCoeff->type.type != PS_TYPE_F64) {
     
    220233        return false;
    221234    }
     235    //Allocate the X,Y,&S polynomials to be used for earthpole calculations
    222236    xPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, xCoeff->n);
    223237    memcpy(xPoly->coeff, xCoeff->data.F64,PSELEMTYPE_SIZEOF(PS_TYPE_F64)*xCoeff->n);
     
    264278                       double speed)
    265279{
     280    //Check for valid inputs
    266281    PS_ASSERT_PTR_NON_NULL(actual, NULL);
    267282    PS_ASSERT_PTR_NON_NULL(direction, NULL);
     
    272287    }
    273288
    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();
    283289    psCube *rp = psCubeAlloc();
    284     //    psSphere *r_p = psSphereAlloc();
    285290    psCube *r_p = psCubeAlloc();
    286291    double mu = 0.0;
     
    288293    double a = 0.0;
    289294
    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)
    297308    mu = (directionVector->x*actualVector->x +
    298309          directionVector->y*actualVector->y +
    299310          directionVector->z*actualVector->z);
     311    //Calculate r-perpendicular (as in sec 3.5.3.2 of ADD). actual = r-hat, direction = beta-hat.
    300312    rp->x = actualVector->x - mu * directionVector->x;
    301313    rp->y = actualVector->y - mu * directionVector->y;
    302314    rp->z = actualVector->z - mu * directionVector->z;
    303 
     315    //Calculate mu-prime.  (Eqn. 129 of ADD).
    304316    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) ] )
    312318    a = (1.0 - mu_p * mu_p) / (rp->x * rp->x + rp->y * rp->y + rp->z * rp->z);
    313319    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");
    315322        psFree(rp);
    316323        psFree(r_p);
     
    319326        psFree(apparent)
    320327        return NULL;
    321     } else
     328    } else {
    322329        a = sqrt(a);
    323 
     330    }
     331    //Calculate r-prime values.  r-prime = mu-prime * beta-hat  +  a * r-perpendicular
    324332    r_p->x = mu_p * directionVector->x + a * rp->x;
    325333    r_p->y = mu_p * directionVector->y + a * rp->y;
    326334    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    }
    339346    psFree(rp);
    340347    psFree(r_p);
    341     psFree(r_pSphere)
    342348    psFree(directionVector);
    343349    psFree(actualVector);
    344     //    psFree(rpVector);
     350
    345351    return apparent;
    346352}
Note: See TracChangeset for help on using the changeset viewer.