USGS

Isis 3.0 Object Programmers' Reference

Home

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"
31 #include "PvlTranslationManager.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  PvlTranslationManager 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 }