char* spkezr_custom(char* target, double et, char* ref, char* abcorr, char* observer, double starg[6], double* lt) { //SpiceDouble* starg_spice = malloc(sizeof(SpiceDouble) * 6); SpiceDouble lt_spice; spkezr_c(target, et, ref, abcorr, observer, starg, <_spice); CHECK_EXCEPTION //*starg = (double) starg_spice; *lt = (double) lt_spice; FINALIZE }
void spice::eph_impl(double mjd2000, array3D &r, array3D &v) const{ SpiceDouble spice_epoch = kep_toolbox::util::epoch_to_spice(mjd2000); spkezr_c ( m_target.c_str(), spice_epoch, m_reference_frame.c_str(), m_aberrations.c_str(), m_observer.c_str(), m_state, &m_lt ); r[0] = m_state[0] * 1000; r[1] = m_state[1] * 1000; r[2] = m_state[2] * 1000; v[0] = m_state[3] * 1000; v[1] = m_state[4] * 1000; v[2] = m_state[5] * 1000; /// Handling errors if (failed_c()) { std::ostringstream msg; msg << "SPICE cannot compute the ephemerides, have you loaded all needed Kernel files?" << std::endl; reset_c(); throw_value_error(msg.str()); } }
int eom_impactor(double t,const double x[],double dxdt[],void *params) { char *param=(char *)params; const double *r,*v; double R_io,R_europa,R_calisto,R_ganymede,R_uranus,x_ie[4]; double Rj,R_sun,R_saturn,rho,G1,G2,alpha,delta; double *a,gx,gy,gz,r_ie; double ratio,zdivR; double RI,Vimpc; double xeqj[3],xecl[3]; int i; SpiceDouble et,ET; SpiceDouble lt; SpiceDouble x_io[6],x_calisto[6],x_ganymede[6],x_uranus[6]; SpiceDouble x_europa[6],x_sun[6],x_saturn[6],x_earth[6],x_jup[6]; r=&x[0]; v=&x[3]; a=&dxdt[3]; /* RI=sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])*UL; Vimpc=sqrt(x[3]*x[3]+x[4]*x[4]+x[5]*x[5])*(UL/UT); cout.setf(ios::scientific); cout.setf(ios::showpoint); cout.precision(15); cout<<"***************************************************"<<endl; cout<<"Elementos de estado del impactor en EOM-impactor: "<<endl; cout<<"x: "<<x[0]*UL<<" y: "<<x[1]*UL<<" z: "<<x[2]*UL<<"\n" <<"vx: "<<x[3]*(UL/UT)<<" vy: "<<x[4]*(UL/UT)<<" vz: "<<x[5]*(UL/UT)<<"\n" <<"Distance: "<<RI<<" Velocity: "<< Vimpc<<"\n"<<endl; cout<<"***************************************************"<<endl; //*/ if(!strcmp(param,"NOMOONS")) { //cout<<"In if of NOMOONS"<<endl; //Velocidades en x, y, z dxdt[0]=x[3]; dxdt[1]=x[4]; dxdt[2]=x[5]; et=t*UT; spkezr_c("399",et,FRAME,"NONE","599",x_earth,<); spkezr_c("10",et,FRAME,"NONE","599",x_sun,<); spkezr_c("6",et,FRAME,"NONE","599",x_saturn,<); x_sun[0]/=UL; x_sun[1]/=UL; x_sun[2]/=UL; x_saturn[0]/=UL; x_saturn[1]/=UL; x_saturn[2]/=UL; rho=sqrt(x[0]*x[0]+x[1]*x[1]); // Distancia polar (plano x-y) de la nave Rj=magnitud(x); R_sun=Distance(x,x_sun); R_saturn=Distance(x,x_saturn); gx=-G*MASA_JUPITER*x[0]/(Rj*Rj*Rj); gy=-G*MASA_JUPITER*x[1]/(Rj*Rj*Rj); gz=-G*MASA_JUPITER*x[2]/(Rj*Rj*Rj); // ACELERACIONES EN X, Y, Z dxdt[3]= gx-(G*MASA_SUN*(x[0]-x_sun[0])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[0]-x_saturn[0])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[0]-x_uranus[0])/(R_uranus*R_uranus*R_uranus)); dxdt[4]= gy-(G*MASA_SUN*(x[1]-x_sun[1])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[1]-x_saturn[1])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[1]-x_uranus[1])/(R_uranus*R_uranus*R_uranus)); dxdt[5]= gz-(G*MASA_SUN*(x[2]-x_sun[2])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[2]-x_saturn[2])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[2]-x_uranus[2])/(R_uranus*R_uranus*R_uranus)); } if(!strcmp(param,"MOONS")) { //cout<<"In if of MOONS"<<endl; //Velocidades en x, y, z dxdt[0]=x[3]; dxdt[1]=x[4]; dxdt[2]=x[5]; //Se calculan las efemerides del sol, saturno y las lunas mayores de jupiter //Tengase en cuenta que el t pasado a esta rutina es el et de la efemeride. //--------------------------------------------------------------------------- et=t*UT; // spkezr_c("599",et,FRAME,"NONE","399",x_jup,<); spkezr_c("399",et,FRAME,"NONE","599",x_earth,<); spkezr_c("10",et,FRAME,"NONE","599",x_sun,<); spkezr_c("501",et,FRAME,"NONE","599",x_io,<); spkezr_c("502",et,FRAME,"NONE","599",x_europa,<); spkezr_c("503",et,FRAME,"NONE","599",x_ganymede,<); spkezr_c("504",et,FRAME,"NONE","599",x_calisto,<); spkezr_c("6",et,FRAME,"NONE","599",x_saturn,<); //spkezr_c("7",et,FRAME,"NONE","599",x_uranus,<); // Se hace la conversion al sistema de unidades utilizados //-------------------------------------------------------- x_sun[0]/=UL; x_sun[1]/=UL; x_sun[2]/=UL; x_io[0]/=UL; x_io[1]/=UL; x_io[2]/=UL; x_europa[0]/=UL; x_europa[1]/=UL; x_europa[2]/=UL; x_ganymede[0]/=UL; x_ganymede[1]/=UL; x_ganymede[2]/=UL; x_calisto[0]/=UL; x_calisto[1]/=UL; x_calisto[2]/=UL; x_saturn[0]/=UL; x_saturn[1]/=UL; x_saturn[2]/=UL; //x_uranus[0]/=UL; x_uranus[1]/=UL; x_uranus[2]/=UL; // Se calcula la distancia de la nave a cada luna galileana, // a saturno y al sol: //----------------------------------------------------------- rho=sqrt(x[0]*x[0]+x[1]*x[1]); // Distancia polar (plano x-y) de la nave //* Rj=magnitud(x); R_sun=Distance(x,x_sun); R_io=Distance(x,x_io); R_europa=Distance(x,x_europa); R_ganymede=Distance(x,x_ganymede); R_calisto=Distance(x,x_calisto); R_saturn=Distance(x,x_saturn); //R_uranus=Distance(x,x_uranus); //*/ /* // PARA EL POTENCIAL AXISIMETRICO DE JUPITER: // Se hace la transformacion de coordenadas, del // sistema ecliptico al sistema ecuatorial de jupiter //---------------------------------------------------- xecl[0]=x[0]; xecl[1]=x[1]; xecl[2]=x[2]; Ecl2EqJ(xecl,xeqj); /* xeqj[0]=x[0]; xeqj[1]=x[1]; xeqj[2]=x[2]; /// // Terminos del potencial axisimetrico de jupiter //----------------------------------------------- ratio=(R_eq/UL)/Rj; zdivR=xeqj[2]/Rj; /* cout<<"IN EOM_IMPACTOR:"<<endl; cout<<"Rj-ecl: "<<Rj*UL/AU<<" Rj-eq: "<<magnitud(xeqj)*UL/AU<<endl; cout<<"xeqj: "<<xeqj[0]<<" yeqj: "<<xeqj[1]<<" zeqj: "<<xeqj[2]<<"\n" <<"xecl: "<<xecl[0]<<" yecl: "<<xecl[1]<<" zecl: "<<xecl[2]<<"\n"<<endl; /// //*************************************************** // Aceleracion de la particula debida a Jupiter // considerando un potencial axisimetrico. //*************************************************** //* if(param=="OBLATE") { //cout<<"in oblate"<<endl; gx=-xeqj[0]*(G*MASA_JUPITER/(Rj*Rj*Rj))* ( 1 - (3*J2/2.)*ratio*ratio*( 5*zdivR*zdivR - 1 )); // -(5*J4*pow(ratio,4)/8.0)*( 3 - 42*zdivR*zdivR + 63*pow(zdivR,4))); gy=xeqj[1]*gx/xeqj[0]; gz=-xeqj[2]*(G*MASA_JUPITER/(Rj*Rj*Rj))* ( 1 + (3*J2/2.)*pow(ratio,3)*( 3 - 5*zdivR*zdivR)); // -(5*J4/8.)*pow(ratio,4)*( 15 - 70*zdivR*zdivR + 63*pow(zdivR,4))); } // PARA EL POTENCIAL ESFERICO: //----------------------------- if(param=="SPHERICAL") { //cout<<"in spherical"<<endl; gx=-G*MASA_JUPITER*x[0]/(Rj*Rj*Rj); gy=-G*MASA_JUPITER*x[1]/(Rj*Rj*Rj); gz=-G*MASA_JUPITER*x[2]/(Rj*Rj*Rj); }//*/ gx=-G*MASA_JUPITER*x[0]/(Rj*Rj*Rj); gy=-G*MASA_JUPITER*x[1]/(Rj*Rj*Rj); gz=-G*MASA_JUPITER*x[2]/(Rj*Rj*Rj); // ACELERACIONES EN X, Y, Z dxdt[3]= gx-(G*MASA_IO*(x[0]-x_io[0])/(R_io*R_io*R_io)- G*MASA_EUROPA*(x[0]-x_europa[0])/(R_europa*R_europa*R_europa)- G*MASA_GANYMEDE*(x[0]-x_ganymede[0])/(R_ganymede*R_ganymede*R_ganymede)- G*MASA_CALISTO*(x[0]-x_calisto[0])/(R_calisto*R_calisto*R_calisto)- G*MASA_SUN*(x[0]-x_sun[0])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[0]-x_saturn[0])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[0]-x_uranus[0])/(R_uranus*R_uranus*R_uranus)); dxdt[4]= gy-(G*MASA_IO*(x[1]-x_io[1])/(R_io*R_io*R_io)- G*MASA_EUROPA*(x[1]-x_europa[1])/(R_europa*R_europa*R_europa)- G*MASA_GANYMEDE*(x[1]-x_ganymede[1])/(R_ganymede*R_ganymede*R_ganymede)- G*MASA_CALISTO*(x[1]-x_calisto[1])/(R_calisto*R_calisto*R_calisto)- G*MASA_SUN*(x[1]-x_sun[1])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[1]-x_saturn[1])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[1]-x_uranus[1])/(R_uranus*R_uranus*R_uranus)); dxdt[5]= gz-(G*MASA_IO*(x[2]-x_io[2])/(R_io*R_io*R_io)- G*MASA_EUROPA*(x[2]-x_europa[2])/(R_europa*R_europa*R_europa)- G*MASA_GANYMEDE*(x[2]-x_ganymede[2])/(R_ganymede*R_ganymede*R_ganymede)- G*MASA_CALISTO*(x[2]-x_calisto[2])/(R_calisto*R_calisto*R_calisto)- G*MASA_SUN*(x[2]-x_sun[2])/(R_sun*R_sun*R_sun)- G*MASA_SATURNO*(x[2]-x_saturn[2])/(R_saturn*R_saturn*R_saturn)); //G*MASA_URANUS*(x[2]-x_uranus[2])/(R_uranus*R_uranus*R_uranus)); } return 0; }
//------------------------------------------------------------------------------ Rvector6 SpiceOrbitKernelReader::GetTargetState(const wxString &targetName, const Integer targetNAIFId, const A1Mjd &atTime, const wxString &observingBodyName, const wxString &referenceFrame, const wxString &aberration) { #ifdef DEBUG_SPK_READING MessageInterface::ShowMessage( wxT("Entering SPKReader::GetTargetState with target = %s, naifId = %d, time = %12.10f, observer = %s\n"), targetName.c_str(), targetNAIFId, atTime.Get(), observingBodyName.c_str()); Real start, end; GetCoverageStartAndEnd(loadedKernels, targetNAIFId, start, end); MessageInterface::ShowMessage(wxT(" coverage for object %s : %12.10f --> %12.10f\n"), targetName.c_str(), start, end); #endif wxString targetNameToUse = GmatStringUtil::ToUpper(targetName); if (targetNameToUse == wxT("LUNA")) // We use Luna, instead of Moon, for GMAT targetNameToUse = wxT("MOON"); if (targetNameToUse == wxT("SOLARSYSTEMBARYCENTER")) targetNameToUse = wxT("SSB"); objectNameSPICE = targetNameToUse.char_str(); observingBodyNameSPICE = observingBodyName.char_str(); referenceFrameSPICE = referenceFrame.char_str(); aberrationSPICE = aberration.char_str(); // convert time to Ephemeris Time (TDB) etSPICE = A1ToSpiceTime(atTime.Get()); naifIDSPICE = targetNAIFId; boddef_c(objectNameSPICE, naifIDSPICE); // CSPICE method to set NAIF ID for an object #ifdef DEBUG_SPK_READING MessageInterface::ShowMessage(wxT("SET NAIF Id for object %s to %d\n"), targetNameToUse.c_str(), targetNAIFId); // MessageInterface::ShowMessage( // wxT("In SPKReader::Converted (to TBD) time = %12.10f\n"), etMjdAtTime); // MessageInterface::ShowMessage(wxT(" then the full JD = %12.10f\n"), // (etMjdAtTime + GmatTimeConstants::JD_JAN_5_1941)); MessageInterface::ShowMessage(wxT("So time passed to SPICE is %12.14f\n"), (Real) etSPICE); #endif SpiceDouble state[6]; SpiceDouble oneWayLightTime; spkezr_c(objectNameSPICE, etSPICE, referenceFrameSPICE, aberrationSPICE, observingBodyNameSPICE, state, &oneWayLightTime); #ifdef DEBUG_SPK_PLANETS Real ttMjdAtTime = TimeConverterUtil::Convert(atTime.Get(), TimeConverterUtil::A1MJD, TimeConverterUtil::TTMJD, GmatTimeConstants::JD_JAN_5_1941); // Real etJd = etMjdAtTime + GmatTimeConstants::JD_JAN_5_1941; Real ttJd = ttMjdAtTime + GmatTimeConstants::JD_JAN_5_1941; MessageInterface::ShowMessage(wxT("Asking CSPICE for state of body %s, with observer %s, referenceFrame %s, and aberration correction %s\n"), objectNameSPICE, observingBodyNameSPICE, referenceFrameSPICE, aberrationSPICE); MessageInterface::ShowMessage( wxT(" Body: %s TT Time: %12.10f TDB Time: %12.10f state: %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f\n"), targetName.c_str(), ttJd, /*etJd,*/ state[0], state[1], state[2], state[3], state[4], state[5]); #endif if (failed_c()) { // ConstSpiceChar option[] = wxT("SHORT"); // retrieve short error message, for now // SpiceInt numChar = MAX_SHORT_MESSAGE; // SpiceChar err[MAX_SHORT_MESSAGE]; ConstSpiceChar option[] = "LONG"; // retrieve long error message, for now SpiceInt numChar = MAX_LONG_MESSAGE_VALUE; //SpiceChar err[MAX_LONG_MESSAGE_VALUE]; SpiceChar *err = new SpiceChar[MAX_LONG_MESSAGE_VALUE]; getmsg_c(option, numChar, err); wxString errStr(wxString::FromAscii(err)); wxString errmsg = wxT("Error getting state for body \""); errmsg += targetName + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); delete [] err; throw UtilityException(errmsg); } #ifdef DEBUG_SPK_READING MessageInterface::ShowMessage( wxT("In SPKReader::Called spkezr_c and got state out\n")); #endif Rvector6 r6(state[0],state[1],state[2],state[3],state[4],state[5]); return r6; }
/** Cache J2000 rotation quaternion over a time range. * * This method will load an internal cache with frames over a time * range. This prevents the NAIF kernels from being read over-and-over * again and slowing an application down due to I/O performance. Once the * cache has been loaded then the kernels can be unloaded from the NAIF * system. * * @internal * @history 2010-12-23 Debbie A. Cook Added set of full cache time * parameters */ void LineScanCameraRotation::LoadCache() { NaifStatus::CheckErrors(); double startTime = p_cacheTime[0]; int size = p_cacheTime.size(); double endTime = p_cacheTime[size-1]; SetFullCacheParameters(startTime, endTime, size); // TODO Add a label value to indicate pointing is already decomposed to line scan angles // and set p_pointingDecomposition=none,framing angles, or line scan angles. // Also add a label value to indicate jitterOffsets=jitterFileName // Then we can decide whether to simply grab the crot angles or do new decomposition and whether // to apply jitter or throw an error because jitter has already been applied. // *** May need to do a frame trace and load the frames (at least the constant ones) *** // Loop and load the cache double state[6]; double lt; NaifStatus::CheckErrors(); double R[3]; // Direction of radial axis of line scan camera double C[3]; // Direction of cross-track axis double I[3]; // Direction of in-track axis double *velocity; std::vector<double> IB(9); std::vector<double> CI(9); SpiceRotation *prot = p_spi->bodyRotation(); SpiceRotation *crot = p_spi->instrumentRotation(); for(std::vector<double>::iterator i = p_cacheTime.begin(); i < p_cacheTime.end(); i++) { double et = *i; prot->SetEphemerisTime(et); crot->SetEphemerisTime(et); // The following code will be put into method LoadIBcache() spkezr_c("MRO", et, "IAU_MARS", "NONE", "MARS", state, <); NaifStatus::CheckErrors(); // Compute the direction of the radial axis (3) of the line scan camera vscl_c(1. / vnorm_c(state), state, R); // vscl and vnorm only operate on first 3 members of state // Compute the direction of the cross-track axis (2) of the line scan camera velocity = state + 3; vscl_c(1. / vnorm_c(velocity), velocity, C); vcrss_c(R, C, C); // Compute the direction of the in-track axis (1) of the line scan camera vcrss_c(C, R, I); // Load the matrix IB and enter it into the cache vequ_c(I, (SpiceDouble( *)) &IB[0]); vequ_c(C, (SpiceDouble( *)) &IB[3]); vequ_c(R, (SpiceDouble( *)) &IB[6]); p_cacheIB.push_back(IB); // end IB code // Compute the CIcr matrix - in-track, cross-track, radial frame to constant frame mxmt_c((SpiceDouble( *)[3]) & (crot->TimeBasedMatrix())[0], (SpiceDouble( *)[3]) & (prot->Matrix())[0], (SpiceDouble( *)[3]) &CI[0]); // Put CI into parent cache to use the parent class methods on it mxmt_c((SpiceDouble( *)[3]) &CI[0], (SpiceDouble( *)[3]) &IB[0], (SpiceDouble( *)[3]) &CI[0]); p_cache.push_back(CI); } p_cachesLoaded = true; SetSource(Memcache); NaifStatus::CheckErrors(); }
/* Function: Calculate the state vector of an object. Parameters: object: ID of the target. t: ephemeris time. origin: object in the origin. frame: frame of reference. Returns: state: State vector (x,y,z,vx,vy,vz) */ int whereIsIt(SpiceChar* object,SpiceDouble t,SpiceChar* origin,SpiceChar* frame,SpiceDouble state[]) { SpiceDouble state[6],lt spkezr_c(object,t,frame,"NONE",origin,state,<); return 0; }