22#include "IException.h"
23#include "NaifStatus.h"
24#include "PvlKeyword.h"
54 _kernels = kernels._kernels;
55 _camVersion = kernels._camVersion;
78 if (
this != &kernels) {
80 _kernels = kernels._kernels;
81 _camVersion = kernels._camVersion;
123 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
124 if (!_kernels[i].exists) nMissing++;
181 _kernels.push_back(
examine(kfile,
true));
240 ktotal_c(
"ALL", &count);
242 for (
int i = 0 ; i < count ; i++) {
245 SpiceChar source[128];
248 kdata_c(i,
"ALL",
sizeof(file),
sizeof(ktype),
sizeof(source),
249 file, ktype,source, &handle, &found);
250 if (found == SPICETRUE) {
251 _kernels.push_back(
examine(file,
false));
271 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
272 _kernels[i].managed =
true;
290 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
291 _kernels[i].managed =
false;
310 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
311 if (!_kernels[i].managed)
return (
false);;
338 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
339 _kernels[i].loaded =
false;
368 if (ktypes.isEmpty()) {
369 for (
unsigned int k = 0 ; k < _kernels.size() ; k++) {
370 if (
Load(_kernels[k])) { nLoaded++; }
376 for (
int t = 0 ; t < tlist.size() ; t++) {
377 for (
unsigned int k = 0; k < _kernels.size() ; k++) {
378 if (_kernels[k].ktype == tlist[t]) {
379 if (
Load(_kernels[k])) { nLoaded++; }
409 for (
unsigned int k = 0 ; k < _kernels.size() ; k++) {
410 if (
Load(_kernels[k])) { nLoaded++; }
428 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
429 if (
UnLoad(_kernels[i])) nUnloaded++;
457 if (ktypes.isEmpty()) {
463 for (
int t = 0 ; t < tlist.size() ; t++) {
464 for (
unsigned int k = 0; k < _kernels.size() ; k++) {
465 if (_kernels[k].ktype == tlist[t]) {
466 if (
UnLoad(_kernels[k])) nUnloaded++;
494 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
498 SpiceChar source[128];
503 kinfo_c(_kernels[i].fullpath.toLatin1().data(),
sizeof(ktype),
sizeof(source),
504 ktype,source, &handle, &found);
507 if (found == SPICETRUE) {
508 if (!_kernels[i].loaded) nchanged++;
509 _kernels[i].loaded =
true;
512 if (_kernels[i].loaded) nchanged++;
513 _kernels[i].loaded =
false;
542 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
543 if (_kernels[i].loaded) {
544 _kernels[i].managed =
false;
548 _kernels[i].managed =
true;
602 for (
unsigned int i = 0 ; i < other._kernels.size() ; i++) {
606 kfile.managed =
false;
607 _kernels.push_back(kfile);
611 if (other._kernels[i].loaded) {
612 kernel->loaded =
true;
613 kernel->managed =
false;
654 for (
int i = 0 ; i < kmap.
size() ; i++) {
655 types.append(kmap.
key(i));
677 if (ktypes.isEmpty()) {
678 for (
unsigned int k = 0; k < _kernels.size() ; k++) {
679 flist.push_back(_kernels[k].pathname);
685 for (
int t = 0 ; t < tlist.size() ; t++) {
686 for (
unsigned int k = 0; k < _kernels.size() ; k++) {
687 if (_kernels[k].ktype == tlist[t]) {
688 flist.push_back(_kernels[k].pathname);
724 if (ktypes.isEmpty()) {
725 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
726 if (_kernels[i].loaded) flist.push_back(_kernels[i].pathname);
731 for (
int t = 0 ; t < tlist.size() ; t++ ) {
732 for (
unsigned int k = 0; k < _kernels.size() ; k++) {
733 if (_kernels[k].ktype == tlist[t]) {
734 flist.push_back(_kernels[k].pathname);
755 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
756 if (!_kernels[i].exists) flist.push_back(_kernels[i].pathname);
780 SpiceQL::load(kfile.fullpath.toLatin1().data());
783 kfile.managed =
true;
785 catch (IException &ie) {
790 return (kfile.loaded);
817 bool wasLoaded(
false);
822 unload_c(kfile.fullpath.toLatin1().data());
825 catch (IException &) {
828 kfile.loaded =
false;
869 for (
int k = 0 ; k < tlist.size() ; k++) {
870 tlist[k] = IString(tlist[k]).Trim(
" \r\n\t\v\b\f").UpCase().ToQt();
883 copy(klist.begin(), klist.end(), back_inserter(_kernels));
905 const QString &kname,
906 const bool &manage) {
909 PvlGroup &kernels = pvl.findGroup(
"Kernels",Pvl::Traverse);
911 if (kernels.hasKeyword(kname)) {
912 PvlKeyword &kkey = kernels[kname];
913 for (
int i = 0 ; i < kkey.size() ; i++) {
914 if (!kkey.isNull(i)) {
915 if (kkey[i].toLower() !=
"table") {
916 klist.push_back(
examine(kkey[i], manage));
951 KernelList::iterator klist;
952 for (klist = _kernels.begin() ; klist != _kernels.end() ; ++klist) {
953 if (klist->pathname == kfile) {
return (&(*klist)); }
954 if (klist->name == kfile) {
return (&(*klist)); }
955 if (klist->fullpath == kfile) {
return (&(*klist)); }
971 for (
unsigned int i = 0 ; i < _kernels.size() ; i++) {
973 if (ktypes.
exists(_kernels[i].ktype)) {
974 ktypes.
get(_kernels[i].ktype).push_back(kfile);
977 ktypes.
add(_kernels[i].ktype, KernelFileList(1, kfile));
993 if (ktype.toUpper() ==
"UNKNOWN")
return (
false);
994 if (ktype.toUpper() ==
"DEM")
return (
false);
1046 const bool &manage)
const {
1048 FileName kernfile(kfile);
1050 kf.pathname = kfile;
1051 kf.name = kernfile.name();
1052 kf.fullpath = kernfile.expanded();
1053 kf.exists = kernfile.fileExists();
1054 kf.ktype =
"UNKNOWN";
1056 kf.managed = manage;
1064 SpiceChar ktype[32];
1065 SpiceChar source[128];
1070 kinfo_c(kf.fullpath.toLatin1().data(),
sizeof(ktype),
sizeof(source), ktype,
1071 source, &handle, &found);
1074 if (found == SPICETRUE) {
1077 kf.ktype = IString(ktype).UpCase().ToQt();
1110 FileName kernFile(kfile);
1111 QString kpath = kernFile.expanded();
1112 ifstream ifile(kpath.toLatin1().data(), ios::in | ios::binary);
1113 QString ktype(
"UNKNOWN");
1116 ifile.read(ibuf, 8);
1118 for (
int i = 0 ; i < 8 ; i++)
1119 if (ibuf[i] ==
'\n') ibuf[i] =
'\0';
1123 QString istr = IString(ibuf).Trim(
" \n\r\f\t\v\b").ToQt();
1124 if (istr.contains(
"/")) {
1125 ktype = istr.split(
"/").last();
1129 if ((ktype ==
"UNKNOWN") || (ktype ==
"DAF")) {
1183 const QString &iktype)
const {
1185 QString ktype(iktype);
1189 string ext = IString(kf.extension()).DownCase();
1195 else if (ext ==
"ti") {
1198 string base = IString(kf.baseName()).DownCase();
1199 string::size_type idx = base.find(
"addendum");
1200 if (idx != string::npos) {
1204 else if (ext ==
"tsc") {
1207 else if (ext ==
"tf") {
1210 else if (ext ==
"tls") {
1213 else if (ext ==
"tpc") {
1216 else if (ext ==
"bc") {
1219 else if (ext ==
"bsp") {
1222 else if (ext ==
"bes") {
1225 else if (ext ==
"bds") {
1228 else if (ext ==
"meta") {
1250 PvlGroup &kernels = pvl.findGroup(
"Kernels",Pvl::Traverse);
1253 if (kernels.hasKeyword(
"CameraVersion")) {
1254 PvlKeyword &kkey = kernels[
"CameraVersion"];
1255 cv = IString(kkey[0]).ToInteger();
const K & key(int nth) const
Returns the nth key in the collection.
int size() const
Returns the size of the collection.
T & get(const K &key)
Returns the value associated with the name provided.
bool exists(const K &key) const
Checks the existance of a particular key in the list.
void add(const K &key, const T &value)
Adds the element to the list.
IO Handler for Isis Cubes.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
int UpdateManagedStatus()
Update the managed state of the kernel file list.
void InitializeNaifKernelPool()
Initialize the NAIF kernel keeper pool.
bool Add(const QString &kfile)
Add a new kernel to the list.
bool IsNaifType(const QString &ktype) const
Determine if the type is a NAIF supported kernel type.
void Manage()
Set each kernels management status to managed.
KernelFile examine(const QString &fname, const bool &manage=true) const
Determine type of NAIF kernel file.
int Discover()
Determine which NAIF kernels are currently loaded in the pool.
int getCameraVersion(Pvl &pvl) const
Determine the ISIS camera model version number.
int UpdateLoadStatus()
Determine the load status of all kernels known to this object.
QStringList getTypes(const QString &ktypes) const
Get a vector of comma separated types from a string.
KernelFile * findByName(const QString &kfile)
Search kernel file list of a particular pattern.
void Init(Pvl &pvl)
Determine Spice kernels in an ISIS label.
QString resolveType(const QString &kfile) const
Determines type of NAIF/ISIS kernel we're dealing with.
Kernels()
Default Constructor.
QStringList getKernelList(const QString &ktype="") const
Provide a list of all the kernels found.
QString resolveTypeByExt(const QString &kfile, const QString &iktype="UNKNOWN") const
Check kernel type by file extension and special ISIS kernels.
void Clear()
Remove all kernel files from internal list.
void addKernels(const KernelList &klist)
Add a list of kernel files to internal storage.
QStringList getLoadedList(const QString &ktypes="") const
Returns list of kernel currently loaded according to status.
int Missing() const
Return count of missing kernel files.
bool IsManaged() const
Determine if all kernels are managed by this object.
TypeList categorizeByType() const
Categorizes the kernel list by type.
std::vector< KernelFile > findKernels(Pvl &pvl, const QString &kname, const bool &manage=true)
Retrieve contents of keyword.
int UnLoad()
Unloads all kernels from the NAIF pool.
QStringList getMissingList() const
Returns list of kernels that were not found to exist.
int Merge(const Kernels &other)
Merge the contents of another Kernels object.
int Load()
Load all kernels in list.
QStringList getKernelTypes() const
Return list of types in kernel list.
Kernels & operator=(const Kernels &kernels)
Copy constructor for existing Kernels objecr.
void UnManage()
Set each kernels' management state to unmanaged.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.