IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6425


Ignore:
Timestamp:
Feb 13, 2006, 2:09:27 PM (20 years ago)
Author:
drobbin
Message:

Added psMemThreadSafety. Removed p_lock from psList. Added comments and made minor changes to EOC.

Location:
trunk/psLib/src
Files:
6 edited

Legend:

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

    r6328 r6425  
    88 *  @author Robert Daniel DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-02-06 21:57:04 $
     10 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-02-14 00:09:26 $
    1212 *
    1313 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    356356                              psSphere *sun)
    357357{
     358    //Check for valid inputs
    358359    PS_ASSERT_PTR_NON_NULL(actual, NULL);
    359360    PS_ASSERT_PTR_NON_NULL(sun, NULL);
    360361
    361362    psSphere *temp = psSphereAlloc();
    362     // calculating the apparent angle from the actual angle and the sun position
    363 
    364363    psCube* sunVector = psSphereToCube(sun);
    365364    psCube* actualVector = psSphereToCube(actual);
    366365
    367366    // use dot product to calculate the angle of separation
    368     // N.B., assuming the psSphereToCube function returns a unit vector.
    369     //    double theta = acos(sunVector->x*actualVector->x +
    370367    double dotProd = (sunVector->x*actualVector->x +
    371368                      sunVector->y*actualVector->y + sunVector->z*actualVector->z);
     
    378375    theta = acos(dotProd);
    379376
    380     //    theta = acos( cos(sun->d)*cos(actual->d)*cos(sun->r-actual->r) + sin(sun->r)*sin(actual->r) );
    381 
    382377    printf(" Theta = %.13g\n", theta);
    383     //    theta = acos(-theta);
    384     //    printf("\n Theta = %lf\n", theta);
    385378    double r0 = PS_AU * tan(theta);
    386379    printf(" r0 = %.19e\n", r0);
     
    389382    // make sure the deflection is not greater than 1.75 arcsec
    390383    double limit = SEC_TO_RAD(1.75);
    391     printf(" deflection = %.13g\n", deflection);
    392     //printf(" limit = %lf\n", limit);
    393384    if (deflection > limit) {
    394         //       deflection = limit;
    395385        //if deflection is greater than limit, the light rays will hit the sun
    396386        psWarning("Invalid positions.  Light ray will not be seen on earth.\n");
     
    400390    }
    401391
    402     /*    if (apparent == NULL) {
    403             apparent = psSphereAlloc();
    404         } else {
    405             apparent->r = 0.0;
    406             apparent->d = 0.0;
    407             apparent->rErr = 0.0;
    408             apparent->dErr = 0.0;
    409         }
    410     */
     392
    411393    if (apparent != NULL) {
    412394        psFree(apparent);
    413395    }
    414396    // bend the actual vector away from the sun vector by deflection angle.
    415     // XXX: Not sure how to do this.  Dave thinks the formula should be:
    416     //      theta = atan(r0/d)*tan(deflection), phi = thete/tan(deflection)
    417397    theta = 0.0;
    418398    double phi = 0.0;
     
    477457    double t4 = t*t*t*t;
    478458
    479     // N.B., the following formulae are from the ADD
    480     // Mean Anomaly of the Moon
     459    // The following formulae are from the ADD (& s5.8 of IERS Technical Note 32):
    481460    double F[14];
     461    // Mean Anomaly of the Moon (l)
    482462    F[0] = DEG_TO_RAD(134.96340251) +
    483463           SEC_TO_RAD(1717915923.2178)*t +
     
    485465           SEC_TO_RAD(0.051635)*t3 -
    486466           SEC_TO_RAD(0.00024470)*t4;
    487 
    488     // Mean Anomaly of the Sun
     467    // Mean Anomaly of the Sun (l')
    489468    F[1] = DEG_TO_RAD(357.52910918) +
    490469           SEC_TO_RAD(129596581.0481)*t -
     
    492471           SEC_TO_RAD(0.000136)*t3 -
    493472           SEC_TO_RAD(0.00001149)*t4;
    494 
    495     // L - Omega
     473    // L - Omega    (L = Mean Longitude of the Moon, Omega = F4)
    496474    F[2] = DEG_TO_RAD(93.27209062) +
    497475           SEC_TO_RAD(1739527262.8478)*t -
     
    499477           SEC_TO_RAD(0.001037)*t3 +
    500478           SEC_TO_RAD(0.00000417)*t4;
    501 
    502     // Mean Elongation of the Moon from the Sun
     479    // Mean Elongation of the Moon from the Sun (D)
    503480    F[3] = DEG_TO_RAD(297.85019547) +
    504481           SEC_TO_RAD(1602961601.2090)*t -
     
    506483           SEC_TO_RAD(0.006593)*t3 -
    507484           SEC_TO_RAD(0.00003169)*t4;
    508 
    509     // Mean Longitude of the Ascending Node of the Moon
     485    // Mean Longitude of the Ascending Node of the Moon (Omega)
    510486    F[4] = DEG_TO_RAD(125.04455501) -
    511487           SEC_TO_RAD(6962890.5431)*t +
     
    513489           SEC_TO_RAD(0.007702)*t3 -
    514490           SEC_TO_RAD(0.0000593)*t4;
    515 
     491    //F5-F13 are the mean longitudes of the planets
    516492    F[5] = 4.402608842 + 2608.7903141574*t;
    517493    F[6] = 3.176146697 + 1021.3285546211*t;
     
    528504        eocInitialized = p_psEOCInit();
    529505        if(!eocInitialized) {
    530             // XXX: Move error message.
    531506            psError(PS_ERR_UNKNOWN, false,
    532507                    "Could not initialize EOC tables -- check data files.");
     
    534509        }
    535510    }
    536 
    537511    // calculate the polynomial portion first
    538512    double X = psPolynomial1DEval(xPoly,t);
    539513    double Y = psPolynomial1DEval(yPoly,t);
    540514    double S = psPolynomial1DEval(sPoly,t);
    541 
     515    //Units from the table & coefficients are in micro-arcseconds so convert to radians.
    542516    X = SEC_TO_RAD(X * 1e-6);
    543517    Y = SEC_TO_RAD(Y * 1e-6);
     
    545519
    546520    // now calculate the non-poly portion from the tables
    547     psF64* cols[17];
     521    psF64* cols[17];  //Used to store all of the table information from tab5.2?.dat
    548522    for (int lcv = 0; lcv < 17; lcv++) {
    549523        cols[lcv] = ((psVector*)(xTable->data[lcv]))->data.F64;
    550524    }
     525    //Get the number of rows in the table and loop through the non-poly contributions.
    551526    int numRows = ((psVector*)(xTable->data[0]))->n;
    552527    for (int lcv = 0; lcv < numRows; lcv++) {
    553         // arg = sum w_(i,j,k)*F_k
    554528        double arg = 0.0;
     529        //Get the argument- from the table and corresponding F-value.  Convert to radians.
    555530        for (int k = 0; k < 14; k++) {
    556531            arg += cols[k+3][lcv]*F[k];
    557532        }
    558         double tj = pow(t,cols[0][lcv]);
    559         double as = cols[1][lcv];
    560         double ac = cols[2][lcv];
    561         //        printf("as-x, ac-x, = %.13g, %.13g\n", as, ac);
    562         as = SEC_TO_RAD(as) * 1e-6;
    563         ac = SEC_TO_RAD(ac) * 1e-6;
    564         //        X += as*tj*sin(arg) + ac*tj*cos(arg);
    565         X += (as*tj*sin(arg) + ac*cos(arg)) * tj;
    566     }
    567 
    568     for (int lcv = 0; lcv < 17; lcv++) {
    569         cols[lcv] = ((psVector*)(yTable->data[lcv]))->data.F64;
    570     }
    571     numRows = ((psVector*)(yTable->data[0]))->n;
    572     for (int lcv = 0; lcv < numRows; lcv++) {
    573         // arg = sum w_(i,j,k)*F_k
    574         double arg = 0.0;
    575         for (int k = 0; k < 14; k++) {
    576             arg += cols[k+3][lcv]*F[k];
    577         }
     533        //The order of t for each part is specified by a column in the tab.dat files.
    578534        double tj = pow(t,cols[0][lcv]);
    579535        double as = cols[1][lcv];
     
    581537        as = SEC_TO_RAD(as) * 1e-6;
    582538        ac = SEC_TO_RAD(ac) * 1e-6;
    583 
    584         //        Y += as*tj*sin(arg) + ac*tj*cos(arg);
    585         Y += (as*tj*sin(arg) + ac*cos(arg)) * tj;
    586     }
    587 
     539        X += (as*tj*sin(arg) + ac*cos(arg)) * tj;
     540    }
     541    //Do the same procedure from the previous 15 lines for Y.
    588542    for (int lcv = 0; lcv < 17; lcv++) {
    589         cols[lcv] = ((psVector*)(sTable->data[lcv]))->data.F64;
    590     }
    591     numRows = ((psVector*)(sTable->data[0]))->n;
     543        cols[lcv] = ((psVector*)(yTable->data[lcv]))->data.F64;
     544    }
     545    numRows = ((psVector*)(yTable->data[0]))->n;
    592546    for (int lcv = 0; lcv < numRows; lcv++) {
    593         // arg = sum w_(i,j,k)*F_k
    594547        double arg = 0.0;
    595548        for (int k = 0; k < 14; k++) {
     
    601554        as = SEC_TO_RAD(as) * 1e-6;
    602555        ac = SEC_TO_RAD(ac) * 1e-6;
    603 
    604         //        S += as*tj*sin(arg) + ac*tj*cos(arg);
     556        Y += (as*tj*sin(arg) + ac*cos(arg)) * tj;
     557    }
     558    //Again for S.
     559    for (int lcv = 0; lcv < 17; lcv++) {
     560        cols[lcv] = ((psVector*)(sTable->data[lcv]))->data.F64;
     561    }
     562    numRows = ((psVector*)(sTable->data[0]))->n;
     563    for (int lcv = 0; lcv < numRows; lcv++) {
     564        double arg = 0.0;
     565        for (int k = 0; k < 14; k++) {
     566            arg += cols[k+3][lcv]*F[k];
     567        }
     568        double tj = pow(t,cols[0][lcv]);
     569        double as = cols[1][lcv];
     570        double ac = cols[2][lcv];
     571        as = SEC_TO_RAD(as) * 1e-6;
     572        ac = SEC_TO_RAD(ac) * 1e-6;
    605573        S += (as*tj*sin(arg) + ac*cos(arg)) * tj;
    606574    }
    607575
    608     // now, the tables for S actually gives S + XY/2, so let's get the real S now
     576    //the tables for S actually gives S + XY/2, so let's get the real S now. (from ADD)
    609577    S -= X*Y/2.0;
    610578
    611     //    psEarthPole* pole = psAlloc(sizeof(psEarthPole));
     579    //Create the output psEarthPole and set the corresponding component values.
    612580    psEarthPole* pole = psEarthPoleAlloc();
    613581    pole->x = X;
     
    621589                                  psTimeBulletin bulletin)
    622590{
     591    // Check for null parameter or invalid bulletin
    623592    PS_ASSERT_PTR_NON_NULL(time,NULL);
    624593    PS_ASSERT_INT_WITHIN_RANGE(bulletin, PS_IERS_A, PS_IERS_B, NULL);
    625 
    626     psEarthPole *out = psEarthPoleAlloc();
    627     out->x = 0.0;
    628     out->y = 0.0;
    629     out->s = 0.0;
    630 
     594    //Convert the input time to MJD.  If NAN is returned, return NULL for the function.
    631595    double MJD = psTimeToMJD(time);
    632596    if (MJD == NAN) {
     
    635599        return NULL;
    636600    }
    637     /*
    638         if (MJD < 41684.0 || MJD > 53334.0) {
    639             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    640                     "Invalid time input.  Date, %lf, is out of range (41684-53334)\n", MJD);
    641             return out;
    642         }
    643     */
     601    //Allocate space for the psEarthPole output.
     602    psEarthPole *out = psEarthPoleAlloc();
     603
    644604    // Check if EOC data loaded
    645605    if(!eocInitialized) {
    646606        eocInitialized = p_psEOCInit();
    647607        if(!eocInitialized) {
    648             // XXX: Move error message.
    649608            psError(PS_ERR_UNKNOWN, false,
    650609                    "Could not initialize EOC tables -- check data files.");
     
    653612    }
    654613
     614    //Load the data table and store in the corresponding, newly-allocated vectors.
    655615    psF64* cols[5];
    656616    for (int colNum = 0; colNum < 5; colNum++) {
     
    658618    }
    659619    int numRows = ((psVector*)(iersTable->data[0]))->n;
    660     /*
    661         for (int rowNum = 0; rowNum < numRows; rowNum++) {
    662             if ( (MJD - cols[0][rowNum]) < 1.0 ) {
    663                 if (bulletin == PS_IERS_A) {
    664                     out->x = cols[1][rowNum];
    665                     out->y = cols[2][rowNum];
    666                     out->x = SEC_TO_RAD(out->x) * 1e-3;
    667                     out->y = SEC_TO_RAD(out->y) * 1e-3;
    668                     rowNum = numRows;
    669                 } else {
    670                     out->x = cols[3][rowNum];
    671                     out->y = cols[4][rowNum];
    672                     out->x = SEC_TO_RAD(out->x) * 1e-3;
    673                     out->y = SEC_TO_RAD(out->y) * 1e-3;
    674                     rowNum = numRows;
    675                 }
    676             }
    677         }
    678     */
    679620    psVector *X = psVectorAlloc(numRows, PS_TYPE_F64);
    680621    psVector *Y = psVectorAlloc(numRows, PS_TYPE_F64);
     
    694635    }
    695636
     637    //The following uses lagrange interpolation to calculate the corrections to X & Y.
    696638    double xOut = 0.0;
    697639    double yOut = 0.0;
     
    724666        }
    725667    }
     668    //Convert the values from milli-arcsecond to radian.
    726669    out->x = SEC_TO_RAD(xOut) * 1e-3;
    727670    out->y = SEC_TO_RAD(yOut) * 1e-3;
     
    736679{
    737680    int i;
    738     psSphereRot *new = (psSphereRot*)psAlloc(sizeof(psSphereRot));
    739     //    psMemSetDeallocator(new, (psFreeFunc)sphereRotFree);
    740     //Convert rotation matrix to quaternions
     681    psSphereRot *new = psSphereRotAlloc(0.0, 0.0, 0.0);
     682    new->q3 = 0.0;
     683
     684    //Convert rotation matrix to quaternions.  Formula directly from ADD.
    741685    double diag_sum[3];
    742686    int maxi;
     
    783727psSphereRot* psSphereRot_CEOtoGCRS(const psEarthPole *pole)
    784728{
     729    // Check for null parameter
    785730    PS_ASSERT_PTR_NON_NULL(pole,NULL);
    786731    double A[3][3];
     
    788733
    789734    //Setup the rotation matrix and scalar value, a, as outlined by the ADD
    790     //XXX: Used formula for rotation matrix D from mathworld for z-axis rotation
    791735    double a =  1.0 / (1.0 + sqrt(1.0 - (pole->x*pole->x + pole->y*pole->y) ) );
    792     /*    A[0][0] = (1.0 - a*pole->x*pole->x)*cos(pole->s) - a*pole->x*pole->y*sin(pole->s);
    793         A[0][1] = -a*pole->x*pole->y*cos(pole->s) + (1.0 - a*pole->y*pole->y)*sin(pole->s);
    794         A[0][2] = pole->x*cos(pole->s) + pole->y*sin(pole->s);
    795         A[1][0] = -(1.0 - a*pole->x*pole->x)*sin(pole->s) - a*pole->x*pole->y*cos(pole->s);
    796         A[1][1] = a*pole->x*pole->y*sin(pole->s) + (1.0 - a*pole->y*pole->y)*cos(pole->s);
    797         A[1][2] = -pole->x*sin(pole->s) + pole->y*cos(pole->s);
    798         A[2][0] = -pole->x;
    799         A[2][1] = -pole->y;
    800         A[2][2] = 1.0 - a*(pole->x*pole->x + pole->y*pole->y);
    801     */
    802 
    803736    A[0][0] = (1.0 - a*pole->x*pole->x)*cos(pole->s) - a*pole->x*pole->y*sin(pole->s);
    804737    A[1][0] = -a*pole->x*pole->y*cos(pole->s) + (1.0 - a*pole->y*pole->y)*sin(pole->s);
     
    811744    A[2][2] = 1.0 - a*(pole->x*pole->x + pole->y*pole->y);
    812745
    813     double x, y, s;
    814     x = pole->x;
    815     y = pole->y;
    816     s = pole->s;
    817     /*    A[0][0] = (1.0 - a*x*x)*cos(s) + a*x*y*sin(s);
    818         A[0][1] = (1.0 - a*x*x)*sin(s) - a*x*y*cos(s);
    819         A[0][2] = x;
    820         A[1][0] = -a*x*y*cos(s) - (1.0 - a*y*y)*sin(s);
    821         A[1][1] = -a*x*y*sin(s) + (1.0 - a*y*y)*cos(s);
    822         A[1][2] = y;
    823         A[2][0] = -x*cos(s) + y*sin(s);
    824         A[2][1] = -x*sin(s) - y*cos(s);
    825         A[2][2] = 1.0 - a * (x*x + y*y);
    826     */
    827     /*    A[0][0] = (1.0 - a*x*x)*cos(s) + a*x*y*sin(s);
    828         A[1][0] = (1.0 - a*x*x)*sin(s) - a*x*y*cos(s);
    829         A[2][0] = x;
    830         A[0][1] = -a*x*y*cos(s) - (1.0 - a*y*y)*sin(s);
    831         A[1][1] = -a*x*y*sin(s) + (1.0 - a*y*y)*cos(s);
    832         A[2][1] = y;
    833         A[0][2] = -x*cos(s) + y*sin(s);
    834         A[1][2] = -x*sin(s) - y*cos(s);
    835         A[2][2] = 1.0 - a * (x*x + y*y);
    836     */
     746    //Convert the rotation matrix to a psSphereRot (quaternions)
    837747    out = rotMatrix_To_Quat(A);
    838748
     
    843753                                  psEarthPole *tidalCorr)
    844754{
     755    // Check for null parameter
    845756    PS_ASSERT_PTR_NON_NULL(time,NULL);
    846     psTime *in = psTimeAlloc(time->type);
    847     *in = *time;
     757    //Create a copy of the input time that can be manipulated/changed (input time is const).
     758    psTime *in = p_psTimeCopy(time);
    848759    if (in->type != PS_TIME_UT1) {
    849760        in = psTimeConvert(in, PS_TIME_UT1);
    850761    }
     762    //Check if tidal corrections should be included.
     763    //If so, make sure values are positive and in the correct range.
    851764    if (tidalCorr != NULL && tidalCorr->s != 0.0) {
    852765        int nsec = in->nsec + (int)(tidalCorr->s * 1e9);
     766        if (nsec > 1e9) {
     767            nsec += -1e9;
     768            in->sec += 1;
     769        }
    853770        if (nsec < 0) {
    854771            in->sec += -1;
     
    858775        }
    859776    }
     777    //Calculate the Julian Date from the input time in UT1 format.
    860778    double T = psTimeToJD(in);
    861779    if (T == NAN) {
     
    865783    }
    866784    T += -2451545.0;
     785    //Formula for theta comes directly from the ADD.  Create output psSphereRot from theta.
    867786    double theta = 2.0 * M_PI * (0.7790572732640 + 1.00273781191135448 * T);
    868787    psSphereRot *out = psSphereRotAlloc(theta, 0.0, 0.0);
     
    1003922static double DMOD(double x, double y)
    1004923{
     924    //Internal function for calculating the remainder of a double quotient.
     925    //used often in the algorithm for psEOC_PolarTideCorr which is the Ray model of
     926    //Simon et. al. from its fortran implementation.
    1005927    double value = x - y * trunc(x/y);
    1006928    return value;
     
    1011933    // Check for null parameter
    1012934    PS_ASSERT_PTR_NON_NULL(time, NULL);
    1013     psEarthPole *out = psEarthPoleAlloc();
    1014 
    1015935    // Convert psTime to MJD
    1016936    double MJD = psTimeToMJD(time);
     
    1020940        return NULL;
    1021941    }
    1022 
    1023     // Calculate number of Julian centuries since 2000
    1024     double RJD = MJD;
    1025 
    1026     //Formula comes from fortran reference
    1027     //DMOD in fortran ref. = double remainder -> x - y * trunc(x/y)
     942    psEarthPole *out = psEarthPoleAlloc();
     943
     944    //Formula comes from fortran reference of the Ray model of Simon et. al.
    1028945    double T, L, LPRIME, CAPF, CAPD, OMEGA, THETA, CORX, CORY, CORZ;
    1029946    double ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8;
    1030947    double T2, T3, T4;
    1031     T = (RJD - 51544.5) / 36525.0;
     948    // Calculate number of Julian centuries since 2000
     949    T = (MJD - 51544.5) / 36525.0;
    1032950    T2 = T*T;
    1033951    T3 = T*T*T;
     
    10861004    CORX = SEC_TO_RAD(CORX);
    10871005    CORY = SEC_TO_RAD(CORY);
    1088     //    CORZ = SEC_TO_RAD(CORZ);
    10891006
    10901007    out->x = CORX;
     
    10991016    // Check for null parameter
    11001017    PS_ASSERT_PTR_NON_NULL(time, NULL);
    1101     /*    if (time->type == PS_TIME_UT1) {
    1102             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    1103                     "Invalid time input.  Time cannot be of type UT1.\n");
    1104             return NULL;
    1105         }
    1106     */
    11071018    // Convert psTime to MJD
    11081019    double MJD = psTimeToMJD(time);
     
    11201031    double t4 = t*t*t*t;
    11211032
     1033    // The following formulae are from the ADD (& s5.8 of IERS Technical Note 32):
    11221034    double F[5];
    11231035    // Mean Anomaly of the Moon
     
    11351047           SEC_TO_RAD(0.00001149)*t4;
    11361048
    1137     // L − Omega
     1049    // L − Omega    (L = Mean Longitude of the Moon, Omega = F4)
    11381050    F[2] = DEG_TO_RAD(93.27209062) +
    11391051           SEC_TO_RAD(1739527262.8478)*t -
     
    12521164    double X = 0.0;
    12531165    double Y = 0.0;
    1254     //    double arg = 0.0;
    1255     //This is from eqn 131 in the ADD - Note: pj_tj isn't included the first time.
    1256     //XXX: The xp_sin, yp_cos, etc. may need to be multiplied by pow(t,i) here? adding now...
    1257     //    double tj = 0.0;
    1258 
    1259     // calculate the polynomial portion first - the pj * t^j (poly coeff's)
    1260     //    X = psPolynomial1DEval(xPoly,t);
    1261     //    Y = psPolynomial1DEval(yPoly,t);
    1262     //    X = SEC_TO_RAD(X * 1e-6);
    1263     //    Y = SEC_TO_RAD(Y * 1e-6);
    1264     /*    for (int i = 0; i < 10; i++) {
    1265             double arg = 0.0;
    1266             double as = 0.0;
    1267             double ac = 0.0;
    1268             arg = w_l[i]*F[0] + w_l_p[i]*F[1] + w_F[i]*F[2] + w_D[i]*F[3] + w_Omega[i]*F[4];
    1269             tj = 1.0;
    1270             as = xp_sin[i] * 1e-6;
    1271             ac = xp_cos[i] * 1e-6;
    1272             X += (as*tj*sin(arg) + ac*cos(arg)) * tj;
    1273             as = yp_sin[i] * 1e-6;
    1274             ac = yp_cos[i] * 1e-6;
    1275             Y += (as*tj*sin(arg) + ac*cos(arg)) * tj;
    1276         }
    1277     */
    12781166
    12791167    //Implementation adapted from PM_GRAVI in interp.f from hpiers.obspm.fr/eop-pc/models/interp.f
     
    13061194        ag = RAD_TO_SEC(ag);
    13071195        ag = DMOD(ag, 2.0*M_PI);
    1308         //        ag = SEC_TO_RAD(ag);
    13091196        X += xp_sin[j] * SEC_TO_RAD(sin(ag)) + xp_cos[j] * SEC_TO_RAD(cos(ag));
    13101197        Y += yp_sin[j] * SEC_TO_RAD(sin(ag)) + yp_cos[j] * SEC_TO_RAD(cos(ag));
    1311         //        X += xp_sin[j] * sin(ag) + xp_cos[j] * cos(ag);
    1312         //        Y += yp_sin[j] * sin(ag) + yp_cos[j] * cos(ag);
    13131198    }
    13141199
     
    13161201    pole->x = X;
    13171202    pole->y = Y;
     1203    //The value of s is simply: s = -4.7e-5 * t as specified by the ADD and IERS 32.
    13181204    pole->s = -SEC_TO_RAD(4.7e-5) * t;
    13191205
     
    13231209psSphereRot* psSphereRot_ITRStoTEO(const psEarthPole* motion)
    13241210{
     1211    // Check for null parameter
    13251212    PS_ASSERT_PTR_NON_NULL(motion,NULL);
    13261213    double A[3][3];
     
    13331220    s = -s;
    13341221
    1335 
    1336     //Setup Rotation Matrix for transformation (x,y,z rotation)
    1337     //XXX: May need to be (z,y,x as in Mathworld?)
    1338     /*   A[0][0] = cos(motion->x)*cos(-motion->s);
    1339         A[0][1] = sin(motion->y)*sin(motion->x)*cos(-motion->s) + cos(motion->y)*sin(-motion->s);
    1340         A[0][2] = -cos(motion->y)*sin(motion->x)*cos(-motion->s) + sin(motion->y)*sin(-motion->s);
    1341         A[1][0] = -cos(motion->x)*sin(-motion->s);
    1342         A[1][1] = -sin(motion->y)*sin(motion->x)*sin(-motion->s) + cos(motion->y)*cos(-motion->s);
    1343         A[1][2] = cos(motion->y)*sin(motion->x)*sin(-motion->s) + sin(motion->y)*cos(-motion->s);
    1344         A[2][0] = sin(motion->x);
    1345         A[2][1] = -sin(motion->y)*cos(motion->x);
    1346         A[2][2] = cos(motion->y)*cos(motion->x);
    1347     */
    1348     /*
    1349         A[0][0] = cos(motion->x)*cos(-motion->s);
    1350         A[1][0] = sin(motion->y)*sin(motion->x)*cos(-motion->s) + cos(motion->y)*sin(-motion->s);
    1351         A[2][0] = -cos(motion->y)*sin(motion->x)*cos(-motion->s) + sin(motion->y)*sin(-motion->s);
    1352         A[0][1] = -cos(motion->x)*sin(-motion->s);
    1353         A[1][1] = -sin(motion->y)*sin(motion->x)*sin(-motion->s) + cos(motion->y)*cos(-motion->s);
    1354         A[2][1] = cos(motion->y)*sin(motion->x)*sin(-motion->s) + sin(motion->y)*cos(-motion->s);
    1355         A[0][2] = sin(motion->x);
    1356         A[1][2] = -sin(motion->y)*cos(motion->x);
    1357         A[2][2] = cos(motion->y)*cos(motion->x);
    1358     */
    1359     /*
    1360         A[0][0] = cos(s)*cos(x);
    1361         A[0][1] = sin(s)*sin(y) + cos(s)*sin(x)*sin(y);
    1362         A[0][2] = sin(s)*sin(y) - cos(s)*sin(x)*cos(y);
    1363         A[1][0] = -sin(s)*cos(x);
    1364         A[1][1] = cos(s)*cos(y) - sin(s)*sin(x)*sin(y);
    1365         A[1][2] = cos(s)*sin(y) + sin(s)*sin(x)*cos(y);
    1366         A[2][0] = sin(x);
    1367         A[2][1] = -cos(x)*sin(y);
    1368         A[2][2] = cos(x)*cos(y);
    1369     */
    1370     /*
    1371         A[0][0] = cos(s)*cos(x);
    1372         A[1][0] = sin(s)*sin(y) + cos(s)*sin(x)*sin(y);
    1373         A[2][0] = sin(s)*sin(y) - cos(s)*sin(x)*cos(y);
    1374         A[0][1] = -sin(s)*cos(x);
    1375         A[1][1] = cos(s)*cos(y) - sin(s)*sin(x)*sin(y);
    1376         A[2][1] = cos(s)*sin(y) + sin(s)*sin(x)*cos(y);
    1377         A[0][2] = sin(x);
    1378         A[1][2] = -cos(x)*sin(y);
    1379         A[2][2] = cos(x)*cos(y);
    1380     */
    1381 
    1382     /*
    1383                 psSphereRot r,p,t;
    1384 
    1385                 r.q0=sin(y/2.0);
    1386                 r.q1=0;
    1387                 r.q2=0;
    1388                 r.q3=cos(y/2.0);
    1389 
    1390                 p.q0=0;
    1391                 p.q1=sin(x/2.0);
    1392                 p.q2=0;
    1393                 p.q3=cos(x/2.0);
    1394 
    1395                 t.q0=0;
    1396                 t.q1=0;
    1397                 t.q2=sin(s/2.0);
    1398                 t.q3=cos(s/2.0);
    1399 
    1400                 // calculate t*s*r.
    1401                 psSphereRot* temp = psSphereRotCombine(NULL,&t,&p);
    1402                 out = psSphereRotCombine(NULL, temp, &r);
    1403                 psFree(temp);
    1404 
    1405                 return out;
    1406     */
    1407 
    1408     //Newest trial - mult. y matrix * x * z
    1409 
     1222    //Setup Rotation matrix.  Rotation is constructed by rotation about the X-axis by y,
     1223    // about the Y-axis by x, and about the Z-axis by s' (where s' = -s).
    14101224    A[0][0] = cos(x)*cos(s);
    14111225    A[1][0] = cos(x)*sin(s);
     
    14181232    A[2][2] = cos(x)*cos(y);
    14191233
    1420     /*
    1421             A[0][0] = cos(x)*cos(s);
    1422             A[0][1] = cos(x)*sin(s);
    1423             A[0][2] = -sin(x);
    1424             A[1][0] = sin(x)*sin(y)*cos(s) - cos(y)*sin(s);
    1425             A[1][1] = sin(x)*sin(y)*sin(s) + cos(y)*cos(s);
    1426             A[1][2] = cos(x)*sin(y);
    1427             A[2][0] = sin(x)*cos(y)*cos(s) + sin(y)*sin(s);
    1428             A[2][1] = sin(x)*cos(y)*sin(s) - sin(y)*cos(s);
    1429             A[2][2] = cos(x)*cos(y);
    1430     */
    1431     //New trial - mult z * y * x
    1432     /*    A[0][0] = cos(s)*cos(x);
    1433         A[1][0] = sin(s)*cos(y) + cos(s)*sin(x)*sin(y);
    1434         A[2][0] = sin(s)*sin(y) - cos(s)*sin(x)*cos(y);
    1435         A[0][1] = -sin(s)*cos(x);
    1436         A[1][1] = cos(s)*cos(y) - sin(s)*sin(x)*sin(y);
    1437         A[2][1] = cos(s)*sin(y) + sin(s)*sin(x)*cos(y);
    1438         A[0][2] = sin(x);
    1439         A[1][2] = -cos(x)*sin(y);
    1440         A[2][2] = cos(x)*cos(y);
    1441     */
    1442     /*
    1443         A[0][0] = cos(s)*cos(x);
    1444         A[0][1] = sin(s)*cos(y) + cos(s)*sin(x)*sin(y);
    1445         A[0][2] = sin(s)*sin(y) - cos(s)*sin(x)*cos(y);
    1446         A[1][0] = -sin(s)*cos(x);
    1447         A[1][1] = cos(s)*cos(y) - sin(s)*sin(x)*sin(y);
    1448         A[1][2] = cos(s)*sin(y) + sin(s)*sin(x)*cos(y);
    1449         A[2][0] = sin(x);
    1450         A[2][1] = -cos(x)*sin(y);
    1451         A[2][2] = cos(x)*cos(y);
    1452     */
    1453 
    14541234    //Convert rotation matrix to quaternions
    14551235    out = rotMatrix_To_Quat(A);
     
    14841264    psTime *from = NULL;
    14851265    psTime *to = NULL;
     1266    if (fromMJD > toMJD) {
     1267        psWarning("From time is later than to time in psSpherePrecess.\n");
     1268    }
    14861269
    14871270    if (mode == PS_PRECESS_ROUGH) {
     
    15251308            to = p_psTimeCopy(toTime);
    15261309        }
    1527 
     1310        //Calculate the earthpoles and quaternions corresponding to each time (from, to).
     1311        //Combine the quaternions to produce the output psSphereRot.
    15281312        psEarthPole *fromEP = psEOC_PrecessionModel(from);
    15291313        psSphereRot *fromRot = psSphereRot_CEOtoGCRS(fromEP);
     
    15571341            to = p_psTimeCopy(toTime);
    15581342        }
    1559 
     1343        //Calculate the earthpoles and quaternions corresponding to each time (from, to).
     1344        //Add in the precession corrections from IERS bulletin A.
     1345        //Combine the quaternions to produce the output psSphereRot.
    15601346        psEarthPole *fromEP = psEOC_PrecessionModel(from);
    15611347        psEarthPole *fromCorr = psEOC_PrecessionCorr(from, PS_IERS_A);
    15621348        fromEP->x += fromCorr->x;
    15631349        fromEP->y += fromCorr->y;
    1564         fromEP->s += fromCorr->s;
    15651350        psSphereRot *fromRot = psSphereRot_CEOtoGCRS(fromEP);
    15661351        psEarthPole *toEP = psEOC_PrecessionModel(to);
     
    15681353        toEP->x += toCorr->x;
    15691354        toEP->y += toCorr->y;
    1570         toEP->s += toCorr->s;
    15711355        psSphereRot *toRot = psSphereRot_CEOtoGCRS(toEP);
    15721356        psSphereRot *fromConj = psSphereRotConjugate(NULL, fromRot);
     
    16001384        }
    16011385
     1386        //Calculate the earthpoles and quaternions corresponding to each time (from, to).
     1387        //Add in the precession corrections from IERS bulletin B.
     1388        //Combine the quaternions to produce the output psSphereRot.
    16021389        psEarthPole *fromEP = psEOC_PrecessionModel(from);
    16031390        psEarthPole *fromCorr = psEOC_PrecessionCorr(from, PS_IERS_B);
    16041391        fromEP->x += fromCorr->x;
    16051392        fromEP->y += fromCorr->y;
    1606         fromEP->s += fromCorr->s;
    16071393        psSphereRot *fromRot = psSphereRot_CEOtoGCRS(fromEP);
    16081394        psEarthPole *toEP = psEOC_PrecessionModel(to);
     
    16101396        toEP->x += toCorr->x;
    16111397        toEP->y += toCorr->y;
    1612         toEP->s += toCorr->s;
    16131398        psSphereRot *toRot = psSphereRot_CEOtoGCRS(toEP);
    16141399        psSphereRot *fromConj = psSphereRotConjugate(NULL, fromRot);
     
    16251410        return out;
    16261411    }
    1627     // Apply transform to coordinates
    1628     //    psSphere *out = psSphereRotApply(NULL, tmpST, coords);
    1629     //    if (out->r < -0.0001) {
    1630     //        out->r += 2.0 * M_PI;
    1631     //    }
    1632 }
     1412}
  • trunk/psLib/src/astro/psEarthOrientation.h

    r6184 r6425  
    99*  @author Robert Daniel DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2006-01-23 20:04:31 $
     11*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2006-02-14 00:09:27 $
    1313*
    1414*  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    131131/** Calculates the rotation of the Earth about the CIP.
    132132 *
    133  *  @return psSphereRot*:       sphereical rotation
     133 *  If tidalCorr is non-NULL, use the S-component to provide tidal corrections to the
     134 *  UT1 time.  If tidalCorr is NULL, no corrections are made & this step is skipped.
     135 *
     136 *  @return psSphereRot*:       spherical rotation of the Earth about the CIP.
    134137 */
    135138psSphereRot *psSphereRot_TEOtoCEO(
     
    187190 */
    188191psSphereRot* psSpherePrecess(
    189     //    psSphere *coords,                  ///< coordinates (modified in-place)
    190192    const psTime *fromTime,            ///< equinox of coords input
    191193    const psTime *toTime,              ///< equinox of coords output
  • trunk/psLib/src/astro/psSphereOps.h

    r6187 r6425  
    88 *  @author David Robbins, MHPCC
    99 *
    10  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-01-23 23:52:15 $
     10 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-02-14 00:09:27 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020/// @{
    2121
    22 //#include "psCoord.h"
    2322#include "psTime.h"
    2423
  • trunk/psLib/src/sys/psMemory.c

    r6419 r6425  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.68 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-02-10 02:44:46 $
     10*  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-02-14 00:09:27 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    10761076    bool out = safeThreads;
    10771077    safeThreads = safe;
    1078     if ( out != p_psListThreadSafety(safe) ) {
    1079         psWarning("Thread safety setting in psMemory didn't match that of psList.\n");
    1080     }
    10811078    return out;
    10821079}
  • trunk/psLib/src/types/psList.c

    r6419 r6425  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-10 02:44:46 $
     8 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-14 00:09:27 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333static psBool listIteratorRemove(psListIterator* iterator);
    3434
    35 //private boolean for enabling/disabling thread safety.  Default = enabled.
    36 static bool safeThreads = true;
    37 
    3835static void listFree(psList* list)
    3936{
    4037    if (list == NULL) {
    4138        return;
    42     }
    43 
    44     if (safeThreads) {
    45         pthread_mutex_lock(&list->p_lock);
    46         //        pthread_mutex_lock(&p_lock);
    4739    }
    4840
     
    6961        ptr = next;
    7062    }
    71 
    72     if (safeThreads) {
    73         pthread_mutex_unlock(&list->p_lock);
    74         pthread_mutex_destroy(&list->p_lock);
    75         //        pthread_mutex_unlock(&p_lock);
    76         //        pthread_mutex_destroy(&p_lock);
    77     } else {
    78         safeThreads = true;
    79     }
    8063}
    8164
     
    11093    int index = iterator->index;
    11194
    112     if (safeThreads) {
    113         pthread_mutex_lock(&list->p_lock);
    114         //        pthread_mutex_lock(&p_lock);
    115     }
    11695    if (elem == list->head) {        // head of list?
    11796        list->head = elem->next;
     
    138117    list->n--;
    139118
    140     if (safeThreads) {
    141         pthread_mutex_unlock(&list->p_lock);
    142         //        pthread_mutex_unlock(&p_lock);
    143     }
    144 
    145119    // OK, delete orphaned list element and its data
    146120    psFree(elem->data);
     
    164138    psListIteratorAlloc(list,PS_LIST_HEAD,true);
    165139
    166     if (safeThreads) {
    167         pthread_mutex_init(&(list->p_lock), NULL);
    168         //        pthread_mutex_init(&p_lock, NULL);
    169     }
    170 
    171140    if (data != NULL) {
    172141        psListAdd(list, PS_LIST_TAIL, data);
     
    179148{
    180149    return ( psMemGetDeallocator(ptr) == (psFreeFunc)listFree );
    181 }
    182 
    183 bool p_psListThreadSafety(bool safe)
    184 {
    185     bool out = safeThreads;
    186     safeThreads = safe;
    187     return out;
    188150}
    189151
     
    347309
    348310    psListElem* elem = psAlloc(sizeof(psListElem));
    349 
    350     if (safeThreads) {
    351         pthread_mutex_lock(&list->p_lock);
    352         //        pthread_mutex_lock(&p_lock);
    353     }
    354311
    355312    // set the new list element's attributes
     
    387344    }
    388345
    389     if (safeThreads) {
    390         pthread_mutex_unlock(&list->p_lock);
    391         //        pthread_mutex_unlock(&p_lock);
    392     }
    393 
    394346    return true;
    395347}
     
    426378
    427379    psListElem* elem = psAlloc(sizeof(psListElem));
    428 
    429     if (safeThreads) {
    430         pthread_mutex_lock(&list->p_lock);
    431         //        pthread_mutex_lock(&p_lock);
    432     }
    433380
    434381    // set the new list element's attributes
     
    466413    }
    467414
    468     if (safeThreads) {
    469         pthread_mutex_unlock(&list->p_lock);
    470         //        pthread_mutex_unlock(&p_lock);
    471     }
    472 
    473415    return true;
    474416}
  • trunk/psLib/src/types/psList.h

    r6419 r6425  
    77 *  @ingroup LinkedList
    88 *
    9  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-10 02:44:46 $
     9 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-02-14 00:09:27 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5959    ///< used internally to improve performance when using indexed access, all
    6060    ///< others are user-level iterators created by psListIteratorAlloc.
    61     pthread_mutex_t p_lock;            ///< mutex to lock a node during changes
    6261    void *lock;                        ///< Optional lock for thread safety
    6362}
     
    9493;
    9594
    96 /** Private function used by psMemThreadSafety to activate/deactivate thread safety.
    97  *
    98  *  @return bool:       The previous value of the thread safety.
    99  */
    100 bool p_psListThreadSafety(
    101     bool safe                          ///< current value of thread safety to set
    102 );
    103 
    10495/** Creates a psList linked list object.
    10596 *
Note: See TracChangeset for help on using the changeset viewer.