//! Function to calculate CIP and CIO locator according to requested IAU conventions std::pair< Eigen::Vector2d, double > getPositionOfCipInGcrs( const double terrestrialTime, const double julianDaysEpochShift, const basic_astrodynamics::IAUConventions precessionNutationTheory ) { // Declare Sofa function return arguments (by reference) double xAngle, yAngle; double originLocator; // Check for IAU convention and retrieve requested values. switch( precessionNutationTheory ) { case basic_astrodynamics::iau_2000_a: iauXys00a( julianDaysEpochShift, terrestrialTime / physical_constants::JULIAN_DAY, &xAngle, &yAngle, &originLocator ); break; case basic_astrodynamics::iau_2000_b: iauXys00b( julianDaysEpochShift, terrestrialTime / physical_constants::JULIAN_DAY, &xAngle, &yAngle, &originLocator ); break; case basic_astrodynamics::iau_2006: iauXys06a( julianDaysEpochShift, terrestrialTime / physical_constants::JULIAN_DAY, &xAngle, &yAngle, &originLocator ); break; default: throw std::runtime_error( "Warning, precession nutation theory selection not recongnized" ); } // Set and return requested values. Eigen::Vector2d cioPosition; cioPosition << xAngle, yAngle; return std::pair< Eigen::Vector2d, double >( cioPosition, originLocator ); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double TT1, TT2, dX, dY, *xVec; size_t numRow, numVec; mxArray *retMat; double *retData; double GCRS2CIRS[3][3]; if(nrhs<3||nrhs>4){ mexErrMsgTxt("Wrong number of inputs"); } if(nlhs>2) { mexErrMsgTxt("Wrong number of outputs."); } checkRealDoubleArray(prhs[0]); numRow = mxGetM(prhs[0]); numVec = mxGetN(prhs[0]); if(!(numRow==3||numRow==6)) { mexErrMsgTxt("The input vector has a bad dimensionality."); } xVec=(double*)mxGetData(prhs[0]); TT1=getDoubleFromMatlab(prhs[1]); TT2=getDoubleFromMatlab(prhs[2]); //If some values from the function getEOP will be needed. if(nrhs<4||mxGetM(prhs[3])==0) { mxArray *retVals[2]; double *dXdY; mxArray *JulUTCMATLAB[2]; double JulUTC[2]; int retVal; //Get the time in UTC to look up the parameters by going to TAI and //then UTC. retVal=iauTttai(TT1, TT2, &JulUTC[0], &JulUTC[1]); if(retVal!=0) { mexErrMsgTxt("An error occurred computing TAI."); } retVal=iauTaiutc(JulUTC[0], JulUTC[1], &JulUTC[0], &JulUTC[1]); switch(retVal){ case 1: mexWarnMsgTxt("Dubious Date entered."); break; case -1: mexErrMsgTxt("Unacceptable date entered"); break; default: break; } JulUTCMATLAB[0]=doubleMat2Matlab(&JulUTC[0],1,1); JulUTCMATLAB[1]=doubleMat2Matlab(&JulUTC[1],1,1); //Get the Earth orientation parameters for the given date. mexCallMATLAB(2,retVals,2,JulUTCMATLAB,"getEOP"); mxDestroyArray(JulUTCMATLAB[0]); mxDestroyArray(JulUTCMATLAB[1]); //%We do not need the polar motion coordinates. mxDestroyArray(retVals[0]); checkRealDoubleArray(retVals[1]); if(mxGetM(retVals[1])!=2||mxGetN(retVals[1])!=1) { mxDestroyArray(retVals[1]); mexErrMsgTxt("Error using the getEOP function."); return; } dXdY=(double*)mxGetData(retVals[1]); dX=dXdY[0]; dY=dXdY[1]; //Free the returned arrays. mxDestroyArray(retVals[1]); } else {//Get the celestial pole offsets size_t dim1, dim2; checkRealDoubleArray(prhs[4]); dim1 = mxGetM(prhs[4]); dim2 = mxGetN(prhs[4]); if((dim1==2&&dim2==1)||(dim1==1&&dim2==2)) { double *dXdY=(double*)mxGetData(prhs[4]); dX=dXdY[0]; dY=dXdY[1]; } else { mexErrMsgTxt("The celestial pole offsets have the wrong dimensionality."); return; } } { double x, y, s; double omega; //Get the X,Y coordinates of the Celestial Intermediate Pole (CIP) and //the Celestial Intermediate Origin (CIO) locator s, using the IAU 2006 //precession and IAU 2000A nutation models. iauXys06a(TT1, TT2, &x, &y, &s); //Add the CIP offsets. x += dX; y += dY; //Get the GCRS-to-CIRS matrix iauC2ixys(x, y, s, GCRS2CIRS); } //Allocate space for the return vectors. retMat=mxCreateDoubleMatrix(numRow,numVec,mxREAL); retData=(double*)mxGetData(retMat); { size_t curVec; for(curVec=0;curVec<numVec;curVec++) { //Multiply the position vector with the rotation matrix. iauRxp(GCRS2CIRS, xVec+numRow*curVec, retData+numRow*curVec); //If a velocity vector was given. if(numRow>3) { double *velGCRS=xVec+numRow*curVec+3;//Velocity in GCRS double *retDataVel=retData+numRow*curVec+3; //Convert velocity from GCRS to CIRS. iauRxp(GCRS2CIRS, velGCRS, retDataVel); } } } plhs[0]=retMat; //If the rotation matrix is desired on the output. if(nlhs>1) { double *elPtr; size_t i,j; plhs[1]=mxCreateDoubleMatrix(3,3,mxREAL); elPtr=(double*)mxGetData(plhs[1]); for (i=0;i<3;i++) { for(j=0;j<3;j++) { elPtr[i+3*j]=GCRS2CIRS[i][j]; } } } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { size_t numRow,numVec; mxArray *retMat; double *xVec, *retData; double TT1, TT2, UT11, UT12; //The if-statements below should properly initialize all of the EOP. //The following initializations to zero are to suppress warnings when //compiling with -Wconditional-uninitialized. double dX=0; double dY=0; double deltaT=0; double LOD=0; double GCRS2TIRS[3][3]; //Polar motion matrix. ITRS=POM*TIRS. We will just be setting it to the //identity matrix as polar motion is not taken into account when going //to the TIRS. double rident[3][3]={{1,0,0},{0,1,0},{0,0,1}}; double Omega[3];//The rotation vector in the TIRS if(nrhs<3||nrhs>6){ mexErrMsgTxt("Wrong number of inputs"); } if(nlhs>2) { mexErrMsgTxt("Wrong number of outputs."); } checkRealDoubleArray(prhs[0]); numRow = mxGetM(prhs[0]); numVec = mxGetN(prhs[0]); if(!(numRow==3||numRow==6)) { mexErrMsgTxt("The input vector has a bad dimensionality."); } xVec=(double*)mxGetData(prhs[0]); TT1=getDoubleFromMatlab(prhs[1]); TT2=getDoubleFromMatlab(prhs[2]); //If some values from the function getEOP will be needed if(nrhs<=5||mxIsEmpty(prhs[3])||mxIsEmpty(prhs[4])||mxIsEmpty(prhs[5])) { mxArray *retVals[5]; double *dXdY; mxArray *JulUTCMATLAB[2]; double JulUTC[2]; int retVal; //Get the time in UTC to look up the parameters by going to TAI and //then UTC. retVal=iauTttai(TT1, TT2, &JulUTC[0], &JulUTC[1]); if(retVal!=0) { mexErrMsgTxt("An error occurred computing TAI."); } retVal=iauTaiutc(JulUTC[0], JulUTC[1], &JulUTC[0], &JulUTC[1]); switch(retVal){ case 1: mexWarnMsgTxt("Dubious Date entered."); break; case -1: mexErrMsgTxt("Unacceptable date entered"); break; default: break; } JulUTCMATLAB[0]=doubleMat2Matlab(&JulUTC[0],1,1); JulUTCMATLAB[1]=doubleMat2Matlab(&JulUTC[1],1,1); //Get the Earth orientation parameters for the given date. mexCallMATLAB(5,retVals,2,JulUTCMATLAB,"getEOP"); mxDestroyArray(JulUTCMATLAB[0]); mxDestroyArray(JulUTCMATLAB[1]); //%We do not need the polar motion coordinates. mxDestroyArray(retVals[0]); checkRealDoubleArray(retVals[1]); if(mxGetM(retVals[1])!=2||mxGetN(retVals[1])!=1) { mxDestroyArray(retVals[1]); mxDestroyArray(retVals[2]); mxDestroyArray(retVals[3]); mxDestroyArray(retVals[4]); mexErrMsgTxt("Error using the getEOP function."); return; } dXdY=(double*)mxGetData(retVals[1]); dX=dXdY[0]; dY=dXdY[1]; //This is TT-UT1 deltaT=getDoubleFromMatlab(retVals[3]); LOD=getDoubleFromMatlab(retVals[4]); //Free the returned arrays. mxDestroyArray(retVals[1]); mxDestroyArray(retVals[2]); mxDestroyArray(retVals[3]); mxDestroyArray(retVals[4]); } //If deltaT=TT-UT1 is given if(nrhs>3&&!mxIsEmpty(prhs[3])) { deltaT=getDoubleFromMatlab(prhs[3]); } //Obtain UT1 from terestrial time and deltaT. iauTtut1(TT1, TT2, deltaT, &UT11, &UT12); //Get celestial pole offsets, if given. if(nrhs>4&&!mxIsEmpty(prhs[4])) { size_t dim1, dim2; checkRealDoubleArray(prhs[4]); dim1 = mxGetM(prhs[4]); dim2 = mxGetN(prhs[4]); if((dim1==2&&dim2==1)||(dim1==1&&dim2==2)) { double *dXdY=(double*)mxGetData(prhs[4]); dX=dXdY[0]; dY=dXdY[1]; } else { mexErrMsgTxt("The celestial pole offsets have the wrong dimensionality."); return; } } //If LOD is given if(nrhs>5&&mxIsEmpty(prhs[5])) { LOD=getDoubleFromMatlab(prhs[5]); } //Compute the rotation matrix for going from GCRS to ITRS as well as //the instantaneous vector angular momentum due to the Earth's rotation //in TIRS coordinates. { double x, y, s, era; double rc2i[3][3]; double omega; //Get the X,Y coordinates of the Celestial Intermediate Pole (CIP) and //the Celestial Intermediate Origin (CIO) locator s, using the IAU 2006 //precession and IAU 2000A nutation models. iauXys06a(TT1, TT2, &x, &y, &s); //Add the CIP offsets. x += dX; y += dY; //Get the GCRS-to-CIRS matrix iauC2ixys(x, y, s, rc2i); //Find the Earth rotation angle for the given UT1 time. era = iauEra00(UT11, UT12); //Set the polar motion matrix to the identity matrix so that the //conversion stops at the TIRS instead of the ITRS. //Combine the GCRS-to-CIRS matrix, the Earth rotation angle, and use //the identity matrix instead of the polar motion matrix to get a //to get the rotation matrix to go from GCRS to TIRS. iauC2tcio(rc2i, era, rident,GCRS2TIRS); //Next, to be able to transform the velocity, the rotation of the Earth //has to be taken into account. //The angular velocity vector of the Earth in the TIRS in radians. omega=getScalarMatlabClassConst("Constants","IERSMeanEarthRotationRate"); //Adjust for LOD omega=omega*(1-LOD/86400.0);//86400.0 is the number of seconds in a TT //day. Omega[0]=0; Omega[1]=0; Omega[2]=omega; } //Allocate space for the return vectors. retMat=mxCreateDoubleMatrix(numRow,numVec,mxREAL); retData=(double*)mxGetData(retMat); { size_t curVec; for(curVec=0;curVec<numVec;curVec++) { //Multiply the position vector with the rotation matrix. iauRxp(GCRS2TIRS, xVec+numRow*curVec, retData+numRow*curVec); //If a velocity vector was given. if(numRow>3) { double *posGCRS=xVec+numRow*curVec; double posTIRS[3]; double *velGCRS=xVec+numRow*curVec+3;//Velocity in GCRS double velTIRS[3]; double *retDataVel=retData+numRow*curVec+3; double rotVel[3]; //If a velocity was provided with the position, first //convert to TIRS coordinates, then account for the //rotation of the Earth. //Convert velocity from GCRS to TIRS. iauRxp(GCRS2TIRS, velGCRS, velTIRS); //Convert position from GCRS to TIRS iauRxp(GCRS2TIRS, posGCRS, posTIRS); //Evaluate the cross product for the angular velocity due //to the Earth's rotation. iauPxp(Omega, posTIRS, rotVel); //Subtract out the instantaneous velocity due to rotation. iauPmp(velTIRS, rotVel, retDataVel); } } } plhs[0]=retMat; //If the rotation matrix is desired on the output. if(nlhs>1) { double *elPtr; size_t i,j; plhs[1]=mxCreateDoubleMatrix(3,3,mxREAL); elPtr=(double*)mxGetData(plhs[1]); for (i=0;i<3;i++) { for(j=0;j<3;j++) { elPtr[i+3*j]=GCRS2TIRS[i][j]; } } } }