Angle LunarPhase( double julianDay ) { shared_ptr< JPLEphemeris > spEphemeris = JPLEphemeris::GetEphemeris( julianDay ); if ( spEphemeris == 0 ) return Angle( 0. ); //!!! Point3D earthBarycentric; Vector3D earthBarycentricVelocity; Matrix3D nutAndPrecMatrix; Angle obliquity; #ifdef DEBUG bool earthRslt = #endif GetEarthBarycentric( julianDay, &earthBarycentric, &earthBarycentricVelocity, spEphemeris ); Assert( earthRslt ); #ifdef DEBUG bool oblRslt = #endif GetNutPrecAndObliquity( julianDay, &nutAndPrecMatrix, &obliquity, spEphemeris ); Assert( oblRslt ); Angle solarLong = SolarLongitude( julianDay, earthBarycentric, earthBarycentricVelocity, nutAndPrecMatrix, obliquity, spEphemeris ); Angle lunarLong = LunarLongitude( julianDay, nutAndPrecMatrix, obliquity, spEphemeris ); Angle phase = lunarLong - solarLong; return phase; }
//------------------------------------------------------ // Class: TChineseCalendar // Function: CurrentMajorSolarTerm // Arguments: TReal // // Comments: Returns the index of the last major solar term // // Return: see comment //------------------------------------------------------ TReal TChineseCalendar::CurrentMajorSolarTerm(TReal& aJulianDay) const { TReal sigma; TInt sigmaI; AdjustJDToNoon(aJulianDay); sigma = ChineseTimeZone(aJulianDay); sigma = UniversalFromLocal(aJulianDay,sigma); SolarLongitude(sigma,sigma); sigma /= 30.0; Floor(sigmaI,sigma); sigmaI += 2; Amod(sigma,sigmaI,12.0); Round(sigmaI,sigma); return sigmaI; }
// TODO: DOCUMENT EVERYTHING Spice::Spice (Isis::Pvl &lab) { NaifStatus::CheckErrors(); // Initialization p_startTime = 0.0; p_endTime = 0.0; p_cacheSize = 0; p_et = -DBL_MAX; p_allowDownsizing = false; // Get the kernel group and load main kernels Isis::PvlGroup kernels = lab.FindGroup("Kernels",Isis::Pvl::Traverse); // Get the time padding first if(kernels.HasKeyword("StartPadding")) { p_startTimePadding = kernels["StartPadding"][0]; } else { p_startTimePadding = 0.0; } if(kernels.HasKeyword("EndPadding")) { p_endTimePadding = kernels["EndPadding"][0]; } else { p_endTimePadding = 0.0; } // Modified to load planetary ephemeris SPKs before s/c SPKs since some // missions (e.g., MESSENGER) may augment the s/c SPK with new planet // ephemerides. (2008-02-27 (KJB)) Load(kernels["TargetPosition"]); Load(kernels["InstrumentPosition"]); Load(kernels["InstrumentPointing"]); if (kernels.HasKeyword("Frame")) { Load(kernels["Frame"]); } if (kernels.HasKeyword("Extra")) { Load(kernels["Extra"]); } Load(kernels["TargetAttitudeShape"]); Load(kernels["Instrument"]); Load(kernels["InstrumentAddendum"]); // Always load after instrument Load(kernels["LeapSecond"]); Load(kernels["SpacecraftClock"]); // Get NAIF ik, spk, sclk, and ck codes // // Use ikcode to get parameters from instrument kernel such as focal // length, distortions, focal plane maps, etc // // Use spkcode to get spacecraft position from spk file // // Use sclkcode to transform times from et to tics // // Use ckcode to transform between frames // // Use bodycode to obtain radii and attitude (pole position/omega0) // // Use spkbodycode to read body position from spk string trykey = "NaifIkCode"; if (kernels.HasKeyword("NaifFrameCode")) trykey = "NaifFrameCode"; p_ikCode = (int) kernels[trykey]; p_spkCode = p_ikCode / 1000; p_sclkCode = p_spkCode; p_ckCode = p_ikCode; Isis::PvlGroup &inst = lab.FindGroup("Instrument",Isis::Pvl::Traverse); p_target = (string) inst["TargetName"]; if (iString(p_target).UpCase() == "SKY") { p_bodyCode = p_spkCode; p_radii[0] = p_radii[1] = p_radii[2] = 1.0; p_sky = true; } else { p_bodyCode = NaifBodyCode(); SpiceInt n; bodvar_c(p_bodyCode,"RADII",&n,p_radii); p_sky = false; } p_spkBodyCode = p_bodyCode; // Override them if they exist in the labels if (kernels.HasKeyword("NaifSpkCode")) p_spkCode = (int) kernels["NaifSpkCode"]; if (kernels.HasKeyword("NaifCkCode")) p_ckCode = (int) kernels["NaifCkCode"]; if (kernels.HasKeyword("NaifSclkCode")) p_sclkCode = (int) kernels["NaifSclkCode"]; if (kernels.HasKeyword("NaifBodyCode")) p_bodyCode = (int) kernels["NaifBodyCode"]; if (!p_sky) { if (kernels.HasKeyword("NaifSpkBodyCode")) p_spkBodyCode = (int) kernels["NaifSpkBodyCode"]; } // Create our SpicePosition and SpiceRotation objects p_bodyRotation = 0; p_instrumentRotation = 0; p_instrumentPosition = 0; p_sunPosition = 0; if (p_sky) { // Create the identity rotation for sky targets // Everything in bodyfixed will really be J2000 p_bodyRotation = new SpiceRotation(1); } else { char frameName[32]; SpiceInt frameCode; SpiceBoolean found; cidfrm_c (p_spkBodyCode, sizeof(frameName), &frameCode, frameName, &found); if (!found) { string naifTarget = string("IAU_") + iString(p_target).UpCase(); namfrm_c(naifTarget.c_str(),&frameCode); if (frameCode == 0) { string msg = "Can not find NAIF code for [" + naifTarget + "]"; throw Isis::iException::Message(Isis::iException::Io,msg,_FILEINFO_); } } p_bodyRotation = new SpiceRotation(frameCode); } p_instrumentRotation = new SpiceRotation(p_ckCode); p_instrumentPosition = new SpicePosition(p_spkCode,p_spkBodyCode); p_sunPosition = new SpicePosition(10,p_bodyCode); // Check to see if we have nadir pointing that needs to be computed & // See if we have table blobs to load if (iString((std::string)kernels["TargetPosition"]).UpCase() == "TABLE") { Table t("SunPosition",lab.Filename()); p_sunPosition->LoadCache(t); Table t2("BodyRotation",lab.Filename()); p_bodyRotation->LoadCache(t2); if (t2.Label().HasKeyword("SolarLongitude")) { p_solarLongitude = t2.Label()["SolarLongitude"]; } else { SolarLongitude(); } } // We can't assume InstrumentPointing & InstrumentPosition exist, old // files may be around with the old keywords, SpacecraftPointing & // SpacecraftPosition. The old keywords were in existance before the // Table option, so we don't need to check for Table under the old // keywords. if(kernels["InstrumentPointing"].Size() == 0) { throw iException::Message(iException::Camera, "No camera pointing available", _FILEINFO_); } // 2009-03-18 Tracie Sucharski - Removed test for old keywords, any files // with the old keywords should be re-run through spiceinit. if (iString((std::string)kernels["InstrumentPointing"]).UpCase() == "NADIR") { delete p_instrumentRotation; p_instrumentRotation = new SpiceRotation(p_ikCode,p_spkBodyCode); } else if (iString((std::string)kernels["InstrumentPointing"]).UpCase() == "TABLE") { Table t("InstrumentPointing",lab.Filename()); p_instrumentRotation->LoadCache(t); } if(kernels["InstrumentPosition"].Size() == 0) { throw iException::Message(iException::Camera, "No instrument position available", _FILEINFO_); } if (iString((std::string)kernels["InstrumentPosition"]).UpCase() == "TABLE") { Table t("InstrumentPosition",lab.Filename()); p_instrumentPosition->LoadCache(t); } NaifStatus::CheckErrors(); }