void SpicePosition::getinterval(const std::vector<std::string> &kernels, BodyId body, EphemeridesInterval &interval) { SPICEDOUBLE_CELL ( cover, 2000); bool first = true; for (std::vector<std::string>::const_iterator i = kernels.begin(); i != kernels.end(); i++) { scard_c(0, &cover); spkcov_c(i->c_str(), body, &cover); SpiceInt niv = wncard_c (&cover); for (SpiceInt j = 0; j < niv; j++) { SpiceDouble a, b; wnfetd_c(&cover, j, &a, &b); if (first) { first = false; interval.a = a; interval.b = b; } else { interval.a = std::min(interval.a, a); interval.b = std::max(interval.b, b); } } } char timea[1000], timeb[1000]; timout_c (interval.a, "YYYY ::TDB", sizeof(timea), timea); timout_c (interval.b, "YYYY ::TDB", sizeof(timeb), timeb); }
/** * Returns the day of year portion of the time as an int * * @return int */ int iTime::DayOfYear() const { SpiceChar out[4]; // Populate the private year member timout_c(p_et, "DOY", 4, out); return IString(out).ToInteger(); }
/** * Returns the second portion of the time as a double * * @return double */ double iTime::Second() const { SpiceChar out[256]; // Populate the private year member timout_c(p_et, "SC.#######::RND", 256, out); return IString(out).ToDouble(); }
/** * Returns the minute portion of the time as an int * * @return int */ int iTime::Minute() const { SpiceChar out[3]; // Populate the private year member timout_c(p_et, "MN", 3, out); return IString(out).ToInteger(); }
/** * Returns the year portion of the time as an int * * @return int */ int iTime::Year() const { SpiceChar out[5]; // Populate the private year member timout_c(p_et, "YYYY", 5, out); return IString(out).ToInteger(); }
std::string Date::AsString(const std::string& format) const { char timeStr[FORMAT_STRING_BUFFER]; CSPICE_ASSERT(timout_c(etTime, format.c_str(), FORMAT_STRING_BUFFER, timeStr)); return std::string(timeStr); }
int main (int argc, char **argv) { SPICEDOUBLE_CELL (result, 2*MAXWIN); SPICEDOUBLE_CELL (cnfine, 2); // various formats SpiceChar begstr[TIMLEN], classic[100], terse[100]; SpiceDouble beg,end,*array; SpiceInt count,i,j,house; furnsh_c("/home/barrycarter/BCGIT/ASTRO/standard.tm"); // 1 second tolerance (serious overkill, but 1e-6 is default, worse!) gfstol_c(1.); // 1 year window wninsd_c(year2et(atof(argv[1])), year2et(atof(argv[2])), &cnfine); // TODO: figure out how to compute sizeof(iplanets) properly, this is hack for (j=0; j<sizeof(iplanets)/4; j++) { gplanet = iplanets[j]; gfuds_c (gfq, gfdecrx, "=", 0., 0., 86400., MAXWIN, &cnfine, &result); count = wncard_c(&result); for (i=0; i<count; i++) { // find the time of event (beg == end in this case) wnfetd_c (&result, i, &beg, &end); // find ecliptic longitude (and if its increasing/decreasing) array = geom_info(gplanet, beg, FRAME, 399); // pretty print the time timout_c (beg, TIMFMT, TIMLEN, begstr); house = rint(array[11]*dpr_c()/30); if (array[17] < 0) {house--;} house = (house+12)%12; // the classic form sprintf(classic, "%s %s ENTERS %s %s", begstr, planet2str(gplanet, ""), houses[house], array[17]<0?"RETROGRADE":"PROGRADE"); sprintf(terse, "%lld %s%s%s", (long long) floor(beg+0.5), planet2str(gplanet, "TERSE"), house2str(house, "TERSE"), array[17]<0?"-":"+"); printf("%s %s\n", classic, terse); } } return(0); }
void SpicePosition::init() { erract_c("SET", 0, (char*)"IGNORE"); const char * k = "../cfg/kernels.furnsh"; furnsh_c(k); std::vector<std::string> ks; kernels(ks); for (std::vector<std::string>::iterator i = ks.begin(); i != ks.end(); i++) { getbodies(*i); } for (BodyConstantsConstIterator it = m_bodies.begin(); it != m_bodies.end(); it++) { EphemeridesInterval & interval = m_intervals[(*it)->id()]; getinterval(ks, (*it)->id(), interval); if (it == m_bodies.begin()) { m_interval.a = interval.a; m_interval.b = interval.b; } else { m_interval.a = std::max(m_interval.a, interval.a); m_interval.b = std::min(m_interval.b, interval.b); } } m_interval.a += 100; m_interval.b -= 100; char timea[1000], timeb[1000]; timout_c (m_interval.a, "YYYY ::TDB", sizeof(timea), timea); timout_c (m_interval.b, "YYYY ::TDB", sizeof(timeb), timeb); erract_c("SET", 0, (char*)"DEFAULT"); }
int main( int argc, char **argv ) { SpiceInt i,count,j; SPICEDOUBLE_CELL(result, 2*MAXWIN); SPICEDOUBLE_CELL(cnfine,2); char stime[255]; SpiceDouble beg, end, ang; // fill the static planets array for (i=1; i<argc; i++) {planets[i] = atoi(argv[i]);} planetcount = argc-1; // 1 second tolerance (serious overkill, but 1e-6 is default, worse!) gfstol_c(1.); furnsh_c("/home/barrycarter/BCGIT/ASTRO/standard.tm"); // DE431 limits wninsd_c (-479695089600.+86400*468, 479386728000., &cnfine); // 1970 to 2038 (all "Unix time") for testing // wninsd_c(unix2et(0),unix2et(2147483647),&cnfine); gfuds_c(gfq,gfdecrx,"LOCMIN",0.,0.,86400.,MAXWIN,&cnfine,&result); count = wncard_c(&result); for (i=0; i<count; i++) { // we don't use 'end' but need to pass it wnfetd_c(&result,i,&beg,&end); // find the angle at this time gfq(beg,&ang); // format time nicely timout_c(beg, "ERA YYYY##-MM-DD HR:MN:SC ::MCAL",255,stime); // print et and separation as degree printf("%f %f",beg,ang*dpr_c()); // print out the planets involved (redundant, but useful) for (j=1; j<argc; j++) {printf(" %s",argv[j]);} printf(" %s\n",stime); } return 0; }
/** * Uses the Naif routines to convert a double ephemeris reresentation of a * date/time to its individual components. */ void iTime::Extract () { SpiceChar out[256]; Isis::iString tmp; // Populate the private year member timout_c (p_et, "YYYY", 256, out); tmp = out; p_year = tmp.ToInteger(); // Populate the private month member timout_c (p_et, "MM", 256, out); tmp = out; p_month = tmp.ToInteger(); // Populate the private day member timout_c (p_et, "DD", 256, out); tmp = out; p_day = tmp.ToInteger(); // Populate the private hour member timout_c (p_et, "HR", 256, out); tmp = out; p_hour = tmp.ToInteger(); // Populate the private minute member timout_c (p_et, "MN", 256, out); tmp = out; p_minute = tmp.ToInteger(); // Populate the private second member timout_c (p_et, "SC.#######::RND", 256, out); tmp = out; p_second = tmp.ToDouble(); // Populate the private doy member timout_c (p_et, "DOY", 256, out); tmp = out; p_dayOfYear = tmp.ToInteger(); }
int main() { #define TIMFMT "YYYY-MON-DD HR:MN:SC.###### (TDB) ::TDB ::RND" #define MAXVAL 10000 #define STRSIZ 41 #define LNSIZE 81 #define MAXPAR 10 SpiceBoolean bail; SpiceBoolean rpt; SpiceChar begstr [LNSIZE] = "2001 jan 01 00:00:00.000"; SpiceChar endstr [LNSIZE] = "2001 dec 31 00:00:00.000"; SpiceChar event [] = "DISTANCE"; SpiceChar relate [] = "LOCMAX"; SpiceChar qpnams[SPICE_GFEVNT_MAXPAR][LNSIZE]={"TARGET","OBSERVER","ABCORR"}; SpiceChar qcpars[SPICE_GFEVNT_MAXPAR][LNSIZE] = {"MOON","EARTH","LT+S"}; SpiceDouble qdpars[SPICE_GFEVNT_MAXPAR]; SpiceInt qipars[SPICE_GFEVNT_MAXPAR]; SpiceBoolean qlpars[SPICE_GFEVNT_MAXPAR]; SPICEDOUBLE_CELL ( cnfine, MAXVAL ); SPICEDOUBLE_CELL ( result, MAXVAL ); SpiceDouble begtim,endtim,step,refval,adjust,tol,beg,end; SpiceInt lenvals,nintvls,count,qnpars,i; furnsh_c ( "standard.tm" ); str2et_c ( begstr, &begtim ); str2et_c ( endstr, &endtim ); wninsd_c ( begtim, endtim, &cnfine ); count = wncard_c( &cnfine ); printf( "Found %ld intervals in cnfine\n", count ); step = 0.001 * spd_c(); gfsstp_c ( step ); bail = SPICETRUE; rpt = SPICETRUE; lenvals= LNSIZE; qnpars = 3; tol = SPICE_GF_CNVTOL; refval = 0.; adjust = 0.; nintvls= MAXVAL; gfevnt_c ( gfstep_c, gfrefn_c, event, qnpars, lenvals, qpnams, qcpars, qdpars, qipars, qlpars, relate, refval, tol, adjust, rpt, &gfrepi_c, gfrepu_c, gfrepf_c, nintvls, bail, gfbail_c, &cnfine, &result ); if ( gfbail_c() ) { gfclrh_c(); printf ( "\nSearch was interrupted.\n\nThis message " "was written after an interrupt signal\n" "was trapped. By default, the program " "would have terminated \nbefore this message " "could be written.\n\n" ); } else { count = wncard_c( &result); printf( "Found %ld intervals in result\n", count ); for( i=0; i<count; i++ ) { wnfetd_c( &result, i, &beg, &end ); timout_c ( beg, TIMFMT, LNSIZE, begstr ); timout_c ( end, TIMFMT, LNSIZE, endstr ); printf( "Interval %ld\n", i ); printf( "Beginning TDB %s\n", begstr ); printf( "Ending TDB %s\n", endstr ); } } return (0); }
void Force::force_w(double Ti) { ConstSpiceChar *pictur = "YYYY MM DD HR:MN:SC.####### ::UTC"; triple acc, accp, accr, acc_SRP, accA; SRP EFG; AtmosphericDrag HIJ; SpiceChar utcstr[100]; //et2utc_c ( this->time, "C", 10, 80, utcstr ); timout_c(time, pictur, 50, utcstr); fprintf(facc, "%s", utcstr); fprintf(facc, et_F, time); triple acccb = force_cb(); fprintf(facc, et_F, acccb.getAbs()); //Central body + harmonic coefficients if (Global::b_Cunn) { triple accCunn = Global::GravField_CB.getAcceleration(Global::IDC, time, X); fprintf(facc, et_F, accCunn.getAbs()); } else fprintf(facc, " 0"); //Sun if (Global::b_10) { accp = planet(10); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Mercury if (Global::b_1) { accp = planet(1); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Venus if (Global::b_2) { accp = planet(2); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Earth+Moon if (Global::b_3) { accp = planet(3); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Mars if (Global::b_4) { accp = planet(4); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Jupiter if (Global::b_5) { accp = planet(5); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Saturn if (Global::b_6) { accp = planet(6); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Uranus if (Global::b_7) { accp = planet(7); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Neptune if (Global::b_8) { accp = planet(8); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //Pluto if (Global::b_9) { accp = planet(9); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //add1 if (Global::b_add1) { accp = planet(Global::ID1); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //add2 if (Global::b_add2) { accp = planet(Global::ID2); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //add3 if (Global::b_add3) { accp = planet(Global::ID3); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //add4 if (Global::b_add4) { accp = planet(Global::ID4); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } if (Global::b_add5) { //add5's central gravity part accp = planet(Global::ID5); // add5's non-central gravity part if (Global::b_add5_cun_on) { double pos[3], lt; spkgps_c(Global::IDC, time, "J2000", Global::ID5, pos, <); triple pos_CB(pos); triple Xbs = pos_CB + X; triple fs = Global::GravField_add5.getAcceleration(Global::ID5, time, Xbs); triple fcb = Global::GravField_add5.getAcceleration(Global::ID5, time, pos_CB); fprintf(facc, " %13.5e %13.5e ", accp.getAbs(), (fs - fcb).getAbs()); } else { fprintf(facc, " %13.5e 0 ", accp.getAbs()); } } else { fprintf(facc, " 0 0 "); } //SRP if (Global::b_SRP) { EFG.setpos(X); acc_SRP = EFG.getAcceleration(time); fprintf(facc, et_F, acc_SRP.getAbs()); } else { fprintf(facc, " 0"); } //atmospheric drag if (Global::b_atm) { HIJ.setPos(X); HIJ.setVel(V); accA = HIJ.getAcc(time); fprintf(facc, et_F, accA.getAbs()); } else { fprintf(facc, " 0"); } //General relativity effects (Swartsshild metric,PPN=1) if (Global::b_rel) { accp = relativ(); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } //General relativity effects (L-T precession, PPN=1) if (Global::b_rel_LT) { accp = L_T(); fprintf(facc, et_F, accp.getAbs()); } else { fprintf(facc, " 0"); } fprintf(facc, "\n"); }
int main (int argc, char **argv) { SpiceDouble et, mat[3][3], mat2[3][3], jac[3][3], nut, obq, dboq; SpiceDouble pos[3], newpos[3]; SpiceDouble lt; SpiceInt planets[6], i; SPICEDOUBLE_CELL (range, 2); SpiceDouble beg,end,stime,etime,*array; char test2[2000]; furnsh_c("/home/barrycarter/BCGIT/ASTRO/standard.tm"); exit(-1); for (i=-20000; i<=20000; i++) { timout_c(year2et(i), "ERAYYYY##-MON-DD HR:MN:SC.############# ::MCAL", 50, test2); printf("TIME: %d %s\n", i, test2); } exit(-1); spkcov_c("/home/barrycarter/SPICE/KERNELS/de431_part-1.bsp", 399, &range); wnfetd_c (&range, 0, &stime, &end); spkcov_c("/home/barrycarter/SPICE/KERNELS/de431_part-2.bsp", 399, &range); wnfetd_c(&range, 0, &beg, &etime); printf("TIMES: %f %f\n", beg, etime); str2et_c("2017-10-17 07:59", &et); printf("ET: %f\n", et); spkezp_c(1, et, "EQEQDATE", "CN+S", 399, pos, <); printf("ET: %f\n", et); printf("POS: %f %f %f %f %f\n", et, pos[0], pos[1], pos[2], lt); // eqeq2eclip(et, mat, jac); mxv_c(mat, pos, newpos); printf("NEWPOS: %f %f %f\n", newpos[0], newpos[1], newpos[2]); exit(0); zzwahr_(&et, &nut); zzmobliq_(&et, &obq, &dboq); printf("NUTATION: %f\n", nut); printf("OBLIQUITY: %f\n", obq); pxform_c("EQEQDATE", "ECLIPDATE", et, mat); for (i=0; i<=2; i++) { printf("ALPHA: %d %f %f %f\n", i, mat[i][0], mat[i][1], mat[i][2]); } eqeq2eclip(et, mat2); printf("ALPHATEST\n"); for (i=0; i<=2; i++) { printf("BETA: %d %f %f %f\n", i, mat2[i][0], mat2[i][1], mat2[i][2]); } exit(0); str2et_c("10400-FEB-28 00:00:00", &et); printf("ET: %f\n", et); str2et_c("10400-MAR-01 00:00:00", &et); printf("ET: %f\n", et); exit(0); timout_c(0, "ERAYYYY##-MON-DD HR:MN:SC.############# ::MCAL", 41, test2); printf("%s\n", test2); exit(0); long long test = -pow(2,63); printf("TEST: %lld\n",test); exit(0); if (!strcmp(argv[1],"posxyz")) { double time = atof(argv[2]); int planet = atoi(argv[3]); posxyz(time,planet,pos); printf("%f -> %f %f %f\n",time,pos[0],pos[1],pos[2]); }; if (!strcmp(argv[1],"earthvector")) { double time = atof(argv[2]); int planet = atoi(argv[3]); earthvector(time,planet,pos); printf("%f -> %f %f %f\n",time,pos[0],pos[1],pos[2]); }; if (!strcmp(argv[1],"earthangle")) { double time = atof(argv[2]); int p1 = atoi(argv[3]); int p2 = atoi(argv[4]); SpiceDouble sep = earthangle(time,p1,p2); printf("%f -> %f\n",time,sep); }; if (!strcmp(argv[1],"earthmaxangle")) { double time = atof(argv[2]); for (i=3; i<argc; i++) {planets[i-3] = atoi(argv[i]);} SpiceDouble sep = earthmaxangle(time,argc-3,planets); printf("%f -> %f\n",time,sep); }; }