Isis 3 Programmer Reference
NaifStatus.cpp
Go to the documentation of this file.
1 
22 #include "NaifStatus.h"
23 
24 #include <iostream>
25 
26 #include <SpiceUsr.h>
27 
28 #include "IException.h"
29 #include "IString.h"
30 #include "Pvl.h"
32 
33 namespace Isis {
34  bool NaifStatus::initialized = false;
35 
43  void NaifStatus::CheckErrors(bool resetNaif) {
44  if(!initialized) {
45  SpiceChar returnAct[32] = "RETURN";
46  SpiceChar printAct[32] = "NONE";
47  erract_c("SET", sizeof(returnAct), returnAct); // Reset action to return
48  errprt_c("SET", sizeof(printAct), printAct); // ... and print nothing
49  initialized = true;
50  }
51 
52  // Do nothing if NAIF didn't fail
53  //getmsg_c("", 0, NULL);
54  if(!failed_c()) return;
55 
56  // This method has been documented with the information provided
57  // from the NAIF documentation at:
58  // naif/cspice61/packages/cspice/doc/html/req/error.html
59 
60 
61  // This message is a character string containing a very terse, usually
62  // abbreviated, description of the problem. The message is a character
63  // string of length not more than 25 characters. It always has the form:
64  // SPICE(...)
65  // Short error messages used in CSPICE are CONSTANT, since they are
66  // intended to be used in code. That is, they don't contain any data which
67  // varies with the specific instance of the error they indicate.
68  // Because of the brief format of the short error messages, it is practical
69  // to use them in a test to determine which type of error has occurred.
70  const int SHORT_DESC_LEN = 26;
71  SpiceChar naifShort[SHORT_DESC_LEN];
72  getmsg_c("SHORT", SHORT_DESC_LEN, naifShort);
73 
74  // This message may be up to 1840 characters long. The CSPICE error handling
75  // mechanism makes no use of its contents. Its purpose is to provide human-readable
76  // information about errors. Long error messages generated by CSPICE routines often
77  // contain data relevant to the specific error they describe.
78  const int LONG_DESC_LEN = 1841;
79  SpiceChar naifLong[LONG_DESC_LEN];
80  getmsg_c("LONG", LONG_DESC_LEN, naifLong);
81 
82  // Search for known naif errors...
83  QString errMsg;
84 
85  Pvl error;
86  PvlGroup errorDescription("ErrorDescription");
87  errorDescription.addKeyword(PvlKeyword("ShortMessage", naifShort));
88  errorDescription.addKeyword(PvlKeyword("LongMessage", naifLong));
89  error.addGroup(errorDescription);
90 
91  PvlToPvlTranslationManager trans(error, "$base/translations/NaifErrors.trn");
92 
93  try {
94  errMsg = trans.Translate("ShortMessage");
95  }
96  catch(IException &) {
97  errMsg = "An unknown NAIF error has been encountered.";
98  }
99 
100  try {
101  errMsg += " " + trans.Translate("LongMessage");
102  }
103  catch(IException &) {
104  }
105 
106  // Now process the error
107  if(resetNaif) {
108  reset_c();
109  }
110 
111  errMsg += " The short explanation ";
112  errMsg += "provided by NAIF is [" + QString(naifShort) + "]. ";
113  errMsg += "The Naif error is [" + QString(naifLong) + "]";
114 
115  throw IException(IException::Unknown, errMsg, _FILEINFO_);
116  }
117 }
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Allows applications to translate simple text files.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
virtual QString Translate(QString translationGroupName, int findex=0)
Returns a translated value.
Container for cube-like labels.
Definition: Pvl.h:135
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:43
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31