void findmins (SpiceDouble beg, SpiceDouble end) { SpiceInt i, count; // SPICEDOUBLE_CELLs are static, so must reinit them each time, sigh SPICEDOUBLE_CELL(result, 200); SPICEDOUBLE_CELL(cnfine,2); scard_c(0,&result); scard_c(0,&cnfine); // create interval wninsd_c(beg,end,&cnfine); // get results gfuds_c(gfq,gfdecrx,"LOCMIN",0.,0.,86400.,MAXWIN,&cnfine,&result); count = wncard_c(&result); for (i=0; i<count; i++) { wnfetd_c(&result,i,&beg,&end); // becuase beg and end are equal, overwriting end with actual value gfq(beg,&end); printf("M %f %f %f\n",et2jd(beg),r2d(end),r2d(sunminangle(beg,planetcount,planets))); } }
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); }
// Extract the objects in an SPK kernel std::vector<int> spkobjects(std::string kernel) { SPICEINT_CELL(ids,100); scard_c(0,&ids); std::vector<int> ret; spkobj_c(kernel.c_str(),&ids); for(int i=0;i<card_c(&ids);i++) ret.push_back(SPICE_CELL_ELEM_I(&ids,i)); return ret; }
// Extract the temporal coverages for a given object in an SPK kernel std::vector< std::vector<double> > spkcoverage(std::string kernel, int obj) { SPICEDOUBLE_CELL(cover,2000); scard_c(0,&cover); spkcov_c(kernel.c_str(),obj,&cover); int niv = wncard_c(&cover); std::vector< std::vector<double> > ret(niv,std::vector<double>(2,0.0)); for(int j=0; j<niv; j++) { double b,e; wnfetd_c(&cover,j,&b,&e); ret[j][0] = b; ret[j][1] = e; } return ret; }
//------------------------------------------------------------------------------ void SpiceAttitudeKernelReader::GetCoverageStartAndEnd(StringArray &kernels, Integer forNaifId, Real &start, Real &end, bool needAngVel) { // first check to see if a kernel specified is not loaded; if not, // try to load it for (unsigned int ii = 0; ii < kernels.size(); ii++) if (!IsLoaded(kernels.at(ii))) LoadKernel(kernels.at(ii)); SpiceInt idSpice = forNaifId; SpiceInt arclen = 4; SpiceInt typlen = 5; bool firstInt = true; bool idOnKernel = false; char kStr[5] = " "; char aStr[4] = " "; char levelStr[8] = "SEGMENT"; char timeStr[4] = "TDB"; SpiceBoolean needAv = needAngVel; ConstSpiceChar *kernelName = NULL; ConstSpiceChar *level = levelStr; ConstSpiceChar *timeSys = timeStr; SpiceDouble tol = 0.0; SpiceInt objId = 0; SpiceInt numInt = 0; SpiceChar *kernelType; SpiceChar *arch; SpiceDouble b; SpiceDouble e; Real bA1; Real eA1; SPICEINT_CELL(ids, 200); SPICEDOUBLE_CELL(cover, 200000); // look through each kernel for (unsigned int ii = 0; ii < kernels.size(); ii++) { #ifdef DEBUG_CK_COVERAGE MessageInterface::ShowMessage(wxT("Checking coverage for ID %d on kernel %s\n"), forNaifId, (kernels.at(ii)).c_str()); #endif kernelName = kernels[ii].char_str(); // check the type of kernel arch = aStr; kernelType = kStr; getfat_c(kernelName, arclen, typlen, arch, kernelType); if (failed_c()) { ConstSpiceChar option[] = "LONG"; SpiceInt numChar = MAX_LONG_MESSAGE_VALUE; SpiceChar err[MAX_LONG_MESSAGE_VALUE]; getmsg_c(option, numChar, err); wxString errStr(wxString::FromAscii( err)); wxString errmsg = wxT("Error determining type of kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); throw UtilityException(errmsg); } #ifdef DEBUG_CK_COVERAGE MessageInterface::ShowMessage(wxT("Kernel is of type %s\n"), kernelType); #endif // only deal with CK kernels if (eqstr_c(kernelType, "ck") || eqstr_c(kernelType, "CK")) { ckobj_c(kernelName, &ids); // get the list of objects (IDs) for which data exists in the CK kernel for (SpiceInt jj = 0; jj < card_c(&ids); jj++) { objId = SPICE_CELL_ELEM_I(&ids,jj); #ifdef DEBUG_CK_COVERAGE MessageInterface::ShowMessage(wxT("Kernel contains data for object %d\n"), (Integer) objId); #endif // look to see if this kernel contains data for the object we're interested in if (objId == idSpice) { idOnKernel = true; break; } // if (objId == (idSpice * 1000)) // { // idSpice = idSpice * 1000; // naifIDSPICE = idSpice; // not the way to do this - should pass it back // idOnKernel = true; // break; // } } // only deal with kernels containing data for the object we're interested in if (idOnKernel) { #ifdef DEBUG_CK_COVERAGE MessageInterface::ShowMessage(wxT("Checking kernel %s for data for object %d\n"), (kernels.at(ii)).c_str(), (Integer) objId); #endif scard_c(0, &cover); // reset the coverage cell ckcov_c (kernelName, idSpice, needAv, level, tol, timeSys, &cover); if (failed_c()) { ConstSpiceChar option[] = "LONG"; SpiceInt numChar = MAX_LONG_MESSAGE_VALUE; SpiceChar err[MAX_LONG_MESSAGE_VALUE]; getmsg_c(option, numChar, err); wxString errStr(wxString::FromAscii(err)); wxString errmsg = wxT("Error determining coverage for CK kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); throw UtilityException(errmsg); } numInt = wncard_c(&cover); #ifdef DEBUG_CK_COVERAGE MessageInterface::ShowMessage(wxT("Number of intervals found = %d\n"), (Integer) numInt); #endif if ((firstInt) && (numInt > 0)) { wnfetd_c(&cover, 0, &b, &e); if (failed_c()) { ConstSpiceChar option[] = "LONG"; SpiceInt numChar = MAX_LONG_MESSAGE_VALUE; SpiceChar err[MAX_LONG_MESSAGE_VALUE]; getmsg_c(option, numChar, err); wxString errStr(wxString::FromAscii(err)); wxString errmsg = wxT("Error getting interval times for CK kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); throw UtilityException(errmsg); } start = SpiceTimeToA1(b); end = SpiceTimeToA1(e); firstInt = false; } for (SpiceInt jj = 0; jj < numInt; jj++) { wnfetd_c(&cover, jj, &b, &e); bA1 = SpiceTimeToA1(b); eA1 = SpiceTimeToA1(e); if (bA1 < start) start = bA1; if (eA1 > end) end = eA1; } } } } if (firstInt) { char itsName[256]; SpiceChar *itsNameSPICE = itsName; SpiceBoolean found2; bodc2n_c(naifIDSPICE, 256, itsNameSPICE, &found2); if (found2 == SPICEFALSE) { wxString errmsg = wxT("Error - unable to find name for body in SPICE kernel pool"); throw UtilityException(errmsg); } else { wxString nameStr = wxString::FromAscii(itsNameSPICE); wxString errmsg = wxT("Error - no data available for body "); errmsg += nameStr + wxT(" on specified CK kernels"); throw UtilityException(errmsg); } } }
//------------------------------------------------------------------------------ void SpiceOrbitKernelReader::GetCoverageStartAndEnd(StringArray &kernels, Integer forNaifId, Real &start, Real &end) { // first check to see if a kernel specified is not loaded; if not, // try to load it for (unsigned int ii = 0; ii < kernels.size(); ii++) if (!IsLoaded(kernels.at(ii))) LoadKernel(kernels.at(ii)); SpiceInt idSpice = forNaifId; SpiceInt arclen = 4; SpiceInt typlen = 5; bool firstInt = true; bool idOnKernel = false; ConstSpiceChar *kernelName = NULL; SpiceInt objId = 0; SpiceInt numInt = 0; SpiceChar *kernelType; SpiceChar *arch; SpiceDouble b; SpiceDouble e; Real bA1; Real eA1; SPICEINT_CELL(ids, 200); SPICEDOUBLE_CELL(cover, 200000); char kStr[5] = " "; char aStr[4] = " "; // look through each kernel for (unsigned int ii = 0; ii < kernels.size(); ii++) { #ifdef DEBUG_SPK_COVERAGE MessageInterface::ShowMessage(wxT("Checking coverage for ID %d on kernel %s\n"), forNaifId, (kernels.at(ii)).c_str()); #endif kernelName = kernels[ii].char_str(); // check the type of kernel arch = aStr; kernelType = kStr; getfat_c(kernelName, arclen, typlen, arch, kernelType); if (failed_c()) { ConstSpiceChar option[] = "LONG"; 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 determining type of kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); delete [] err; throw UtilityException(errmsg); } #ifdef DEBUG_SPK_COVERAGE MessageInterface::ShowMessage(wxT("Kernel is of type %s\n"), kernelType); #endif // only deal with SPK kernels if (eqstr_c( kernelType, "spk" )) { spkobj_c(kernelName, &ids); // get the list of objects (IDs) for which data exists in the SPK kernel for (SpiceInt jj = 0; jj < card_c(&ids); jj++) { objId = SPICE_CELL_ELEM_I(&ids,jj); #ifdef DEBUG_SPK_COVERAGE MessageInterface::ShowMessage(wxT("Kernel contains data for object %d\n"), (Integer) objId); #endif // look to see if this kernel contains data for the object we're interested in if (objId == idSpice) { idOnKernel = true; break; } } // only deal with kernels containing data for the object we're interested in if (idOnKernel) { #ifdef DEBUG_SPK_COVERAGE MessageInterface::ShowMessage(wxT("Checking kernel %s for data for object %d\n"), (kernels.at(ii)).c_str(), (Integer) objId); #endif scard_c(0, &cover); // reset the coverage cell spkcov_c (kernelName, idSpice, &cover); if (failed_c()) { ConstSpiceChar option[] = "LONG"; 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 determining coverage for SPK kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); delete [] err; throw UtilityException(errmsg); } numInt = wncard_c(&cover); #ifdef DEBUG_SPK_COVERAGE MessageInterface::ShowMessage(wxT("Number of intervals found = %d\n"), (Integer) numInt); #endif if ((firstInt) && (numInt > 0)) { wnfetd_c(&cover, 0, &b, &e); if (failed_c()) { ConstSpiceChar option[] = "LONG"; 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 interval times for SPK kernel \""); errmsg += kernels.at(ii) + wxT("\". Message received from CSPICE is: "); errmsg += errStr + wxT("\n"); reset_c(); delete [] err; throw UtilityException(errmsg); } start = SpiceTimeToA1(b); end = SpiceTimeToA1(e); firstInt = false; } for (SpiceInt jj = 0; jj < numInt; jj++) { wnfetd_c(&cover, jj, &b, &e); bA1 = SpiceTimeToA1(b); eA1 = SpiceTimeToA1(e); if (bA1 < start) start = bA1; if (eA1 > end) end = eA1; } } } } if (firstInt) { wxString errmsg(wxT("")); errmsg << wxT("Error - no data available for body with NAIF ID ") << forNaifId << wxT(" on specified SPK kernels\n"); throw UtilityException(errmsg); } }