コード例 #1
0
ファイル: correct.c プロジェクト: agongdai/peta
void correct_bases(bwa_seq_t *seqs, bwa_seq_t *ori_read, alignarray *aligns,
		const int tid) {
	pool *p = NULL;
	int j = 0, cursor = 0, i = 0, index = 0, has_hit = 0;
	alg *a = NULL;
	bwa_seq_t *s = NULL;
	int *counter = NULL;

	//p_query("ORI", ori_read);
	p = new_pool();
	ori_read->cursor = 0;
	for (i = 0; i < aligns->len; i++) {
		a = g_ptr_array_index(aligns, i);
		index = a->r_id;
		s = &seqs[index];
		if (s->is_in_c_pool > 0 && s->is_in_c_pool != tid)
			continue;
		if (s->status == USED || strcmp(s->name, ori_read->name) == 0)
			continue;
		s->rev_com = a->rev_comp;
		if (s->rev_com)
			s->cursor = s->len - ori_read->len - a->pos;
		else
			s->cursor = a->pos;
		if (s->is_in_c_pool == 0)
			pool_add(p, s, tid);
	}
	if (p->n >= 4) {
		//p_pool(__func__, p, NULL);
		counter = (int*) calloc(5, sizeof(int));
		for (j = 0; j < ori_read->len; j++) {
			reset_c(counter, NULL);
			has_hit = 0;
			for (i = 0; i < p->n; i++) {
				s = g_ptr_array_index(p->reads, i);
				cursor = s->cursor + j;
				if (cursor >= 0 || cursor < s->len) {
					has_hit = 1;
					if (s->rev_com) {
						counter[s->rseq[cursor]]++;
					} else {
						counter[s->seq[cursor]]++;
					}
				}
			}
			//show_debug_msg(__func__, "Correcting %d: %d:%d:%d:%d\n", j, counter[0],
			//		counter[1], counter[2], counter[3]);
			if (has_hit) {
				ori_read->seq[j] = get_pure_most(counter);
				ori_read->rseq[ori_read->len - 1 - j] = 3 - ori_read->seq[j];
			}
		}
		free(counter);
	}
	free_pool(p);
	//p_query("AFT", ori_read);
}
コード例 #2
0
ファイル: spice_rub.c プロジェクト: mohawkjohn/spice_rub
bool spice_error(int error_detail) {
  SpiceInt buffer_size = 1024;
  char error_message[buffer_size];


  if (failed_c()) {
    
    switch(error_detail) {
      
      case ALL :
        //TODO: Neat way to concat all error messages.
        //reset_c();
        break;

      case SHORT :
        getmsg_c("SHORT", buffer_size, error_message);
        reset_c();
        rb_raise(rb_spice_error, "%s\n", error_message);
        break;

      case LONG :
        getmsg_c("LONG", buffer_size, error_message);
        reset_c();
        rb_raise(rb_spice_error, "%s\n", error_message);
        break;

      case EXPLAIN :
        getmsg_c("EXPLAIN", buffer_size, error_message);
        reset_c();
        rb_raise(rb_spice_error, "%s\n", error_message);
        break;

      default :
        reset_c();
        break;
    }
  }
  
  return false;
}
コード例 #3
0
ファイル: spice.cpp プロジェクト: Boxx-Obspm/DOCKing_System
void spice::eph_impl(double mjd2000, array3D &r, array3D &v) const{
	SpiceDouble spice_epoch = kep_toolbox::util::epoch_to_spice(mjd2000);
	spkezr_c ( m_target.c_str(), spice_epoch, m_reference_frame.c_str(), m_aberrations.c_str(), m_observer.c_str(), m_state, &m_lt );
	r[0] = m_state[0] * 1000; 	r[1] = m_state[1] * 1000; 	r[2] = m_state[2] * 1000;
	v[0] = m_state[3] * 1000; 	v[1] = m_state[4] * 1000; 	v[2] = m_state[5] * 1000;
    /// Handling errors
    if (failed_c()) {
    	std::ostringstream msg;
    	msg << "SPICE cannot compute the ephemerides, have you loaded all needed Kernel files?" << std::endl;
        reset_c();
    	throw_value_error(msg.str());
    }
}
コード例 #4
0
ファイル: qcktrc_c.c プロジェクト: Boxx-Obspm/DOCKing_System
   void qcktrc_c ( SpiceInt     tracelen,
                   SpiceChar  * trace    )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   tracelen   I   Maximum length of output traceback string.
   trace      O   A traceback string. 
   SPICE_ERROR_MAXMOD   
              P   Maximum traceback module count.
   SPICE_ERROR_MODLEN 
              P   Maximum module name length. 
   SPICE_ERROR_TRCLEN
              P   Maximum length of output traceback string.

-Detailed_Input
 
   None. 
 
-Detailed_Output
 
   trace          is a list of module names, delimited by the string, 
                  " --> ".  An example would be
 
                     "SPUD --> SPAM --> FOOBAR". 
 
                  The maximum length of the returned string is given
                  by the parameter SPICE_ERROR_TRCLEN. The value of this
                  parameter includes room for the terminating null.

                  In general, the meaning of the trace is as follows:
 
                  The first name in the list is the name of the first
                  module to check in (that hasn't yet checked out). The
                  last name is the name of the module at the end of the
                  call chain; this is the last module that checked in.
 
                  The meaning of the traceback depends on the state 
                  of the error handling mechanism.  There are two 
                  cases: 
 
                     1)  In RETURN mode, when an error is signaled, the
                         traceback at that point is saved. trcdep_c,
                         trcnam_c, and qcktrc_c return values
                         pertaining to the saved traceback.
 
                     2)  In all other modes, the traceback represents
                         the CURRENT call chain. trcdep_c, trcnam_c,
                         and qcktrc_c return values pertaining to the
                         current trace representation.
 
                  Any module names exceeding SPICE_ERROR_MODLEN
                  characters in length are truncated on the right.
 
-Parameters
 
   The following parameters are declared in the header file SpiceErr.h:


   SPICE_ERROR_MAXMOD    is the maximum number of module names that can
                         be accommodated in the SPICE trace stack; this
                         is the maximum number of names that can appear
                         in the output traceback.

   SPICE_ERROR_MODLEN    is the maximum module name length that can be
                         accommodated by this routine. 

   SPICE_ERROR_TRCLEN    is the maximum length of the string returned
                         by this routine. The value of this parameter
                         includes room for the terminating null.
 
-Exceptions
 
   1)  If the output string pointer is null, the error SPICE(NULLPOINTER)
       will be signaled.


   2)  If the output string has length less than 2 characters, the error
       SPICE(STRINGTOOSHORT) will be signaled.
 
-Files
 
   None. 
 
-Particulars
 
   This routine is part of the CSPICE error handling mechanism. 
 
-Examples
 
   1) Deliberately generate a SPICE error to demonstrate use of 
      this routine together with trcnam_c. We'll attempt to look up 
      a state vector via spkezr_c without first having loaded any
      SPK files.


      Example code begins here.
 

         #include <stdio.h>
         #include "SpiceUsr.h"

         int main()
         {
            /.
            Local constants 
            ./
            #define ACTION          "RETURN"

            /.
            Local variables 
            ./   
            SpiceChar             * abcorr;
            SpiceChar               trace  [ SPICE_ERROR_TRCLEN ];
            SpiceChar             * obsrvr;
            SpiceChar             * frame;
            SpiceChar             * target;

            SpiceDouble             et;
            SpiceDouble             lt;
            SpiceDouble             state [6];

            /.
            Set error handling action to RETURN so that this program
            won't terminate when a SPICE error is signaled. Note that
            the input string length argument is unused for a "SET"
            operation.
            ./
            erract_c ( "SET", 0, ACTION );

            /.
            Generate a SPICE error: call spkezr_c without first having
            loaded an SPK file. 
            ./ 
            et     = 0.0;
            target = "Moon";
            obsrvr = "Earth";
            frame  = "J2000";
            abcorr = "NONE";

            spkezr_c ( target, et, frame, abcorr, obsrvr, state, &lt );

            if ( failed_c() ) 
            {
               /.
               An error has been signaled. Fetch and display
               the traceback.
               ./
               qcktrc_c ( SPICE_ERROR_TRCLEN, trace );

               printf ( "Traceback: \n%s\n", trace );
               /.
               Reset the error status so that CSPICE can resume normal
               operation. 
               ./
               reset_c();
            }

            return ( 0 );
         }

      When this program was executed on a PC/Linux/gcc platform, the
      output (which has been reformatted to fit in the available 
      space in this header) was:


         ====================================================================
         ============

         Toolkit version: N0065

         SPICE(NOLOADEDFILES) --

         At least one SPK file needs to be loaded by SPKLEF before beginning 
         a search.

         A traceback follows.  The name of the highest level module is first.
         spkezr_c --> SPKEZR --> SPKEZ --> SPKGEO --> SPKSFS

         ====================================================================
         ============
         Traceback:
         spkezr_c --> SPKEZR --> SPKEZ --> SPKGEO --> SPKSFS


-Restrictions
 
   1) It is assumed no module names exceed SPICE_ERROR_MODLEN
      characters in length. 
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL) 
   K.R. Gehringer  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 05-NOV-2013 (NJB) (KRG)

-Index_Entries
 
   get quick traceback 
 
-&
*/

{ /* Begin qcktrc_c */

 
   /*
   This routine does not check in unless an input error occurs.
   */


   /* 
   Make sure the output string has at least enough room for one output
   character and a null terminator. Also check for a null pointer.

   We don't use the usual CHKOSTR macro here because we must reset
   the error status before signaling an error.
   */
   if ( trace == NULL )
   {
      reset_c  ();

      chkin_c  ( "qcktrc_c"                                   );
      setmsg_c ( "The output string pointer 'trace' is null." );
      sigerr_c ( "SPICE(NULLPOINTER)"                         );
      chkout_c ( "qcktrc_c"                                   );
      return;
   }

   if ( tracelen < 2 )
   {
      reset_c  ();

      chkin_c  ( "qcktrc_c"                                     );
      setmsg_c ( "The output string 'trace' has length #; the "
                 "minimum allowed length is 2 characters."      );
      errint_c ( "#",  tracelen                                 );
      sigerr_c ( "SPICE(STRINGTOOSHORT)"                        );
      chkout_c ( "qcktrc_c"                                     );
      return;
   }


   /*
   Fetch the traceback. 
   */
   qcktrc_ ( ( char       * ) trace,
             ( ftnlen       ) tracelen-1 );

   /*
   Convert the output name string to a null-terminated,
   C style string. 
   */
   F2C_ConvertStr ( tracelen, trace );


} /* End qcktrc_c */
コード例 #5
0
ファイル: NaifStatus.cpp プロジェクト: assutech/isis3
  /** 
   * This method looks for any naif errors that might have occurred. It 
   * then compares the error to a list of known naif errors and converts
   * the error into an iException.
   * 
   * @param resetNaif True if the NAIF error status should be reset (naif calls valid)
   */
  void NaifStatus::CheckErrors(bool resetNaif) {
    if(!initialized) {
      SpiceChar returnAct[32] = "RETURN";
      SpiceChar printAct[32] = "NONE";
      erract_c ( "SET", sizeof(returnAct), returnAct); // Reset action to return
      errprt_c ( "SET", sizeof(printAct), printAct);   // ... and print nothing
      initialized = true;
    }

    // Do nothing if NAIF didn't fail
    //getmsg_c("", 0, NULL);
    if(!failed_c()) return;

    // This method has been documented with the information provided
    //   from the NAIF documentation at:
    //    naif/cspice61/packages/cspice/doc/html/req/error.html


    // This message is a character string containing a very terse, usually 
    // abbreviated, description of the problem. The message is a character 
    // string of length not more than 25 characters. It always has the form:
    // SPICE(...)
    // Short error messages used in CSPICE are CONSTANT, since they are 
    // intended to be used in code. That is, they don't contain any data which 
    // varies with the specific instance of the error they indicate.
    // Because of the brief format of the short error messages, it is practical 
    // to use them in a test to determine which type of error has occurred. 
    const int SHORT_DESC_LEN = 26;
    SpiceChar naifShort[SHORT_DESC_LEN];
    getmsg_c("SHORT", SHORT_DESC_LEN, naifShort);

    // This message may be up to 1840 characters long. The CSPICE error handling 
    // mechanism makes no use of its contents. Its purpose is to provide human-readable 
    // information about errors. Long error messages generated by CSPICE routines often 
    // contain data relevant to the specific error they describe.
    const int LONG_DESC_LEN = 1841;
    SpiceChar naifLong[LONG_DESC_LEN];
    getmsg_c("LONG", LONG_DESC_LEN, naifLong);

    // Search for known naif errors...
    iString errMsg;

    Pvl error;
    PvlGroup errorDescription("ErrorDescription");
    errorDescription.AddKeyword(PvlKeyword("ShortMessage", naifShort));
    errorDescription.AddKeyword(PvlKeyword("LongMessage", naifLong));
    error.AddGroup(errorDescription);

    PvlTranslationManager trans(error, "$base/translations/NaifErrors.trn");

    try {
      errMsg = trans.Translate("ShortMessage");
    }
    catch(iException &e) {
      e.Clear();
      errMsg = "An unknown NAIF error has been encountered.";
    }

    try {
      errMsg += " " + trans.Translate("LongMessage");
    }
    catch(iException &e) {
      e.Clear();
    }

    // Now process the error
    if(resetNaif) {
      reset_c();
    }

    errMsg += " The short explanation ";
    errMsg += "provided by NAIF is [" + iString(naifShort) + "]. "; 
    errMsg += "The Naif error is [" + iString(naifLong) + "]";

    throw iException::Message(iException::Spice, errMsg, _FILEINFO_);
  }
コード例 #6
0
//---------------------------------------------------------------------------
void SpiceAttitudeKernelReader::GetTargetOrientation(const wxString &objectName,
                                                     Integer           naifID,
                                                     Integer           forFrameNaifId,
                                                     const A1Mjd       &atTime,
//                                                     Real              tolerance,
                                                     Rmatrix33         &r33,
                                                     Rvector3          &angVel,
                                                     const wxString &referenceFrame)
{
   #ifdef DEBUG_CK_READING
      MessageInterface::ShowMessage(wxT("Entering GetTargetOrientation for object %s, with NAIF ID %d, at time %12.10f, with frame = %s\n"),
         objectName.c_str(), naifID, atTime.Get(), referenceFrame.c_str());
   #endif
   wxString objectNameToUse = objectName;

   objectNameToUse       = GmatStringUtil::ToUpper(objectNameToUse);
   objectNameSPICE       = objectNameToUse.char_str();
   naifIDSPICE           = naifID;
   frameNaifIDSPICE      = forFrameNaifId;
   referenceFrameSPICE   = referenceFrame.char_str();
   etSPICE               = A1ToSpiceTime(atTime.Get());

//   boddef_c(objectNameSPICE, naifIDSPICE);        // CSPICE method to set NAIF ID for an object - is this valid for spacecraft?
   // Convert the time (in TDB) to spacecaft ticks
   SpiceDouble scTime;
   sce2c_c(naifIDSPICE, etSPICE, &scTime);
   if (failed_c())
   {
      ConstSpiceChar option[] = "LONG"; // retrieve long error message, for now
      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 spacecraft time (ticks) for object \"");
      errmsg += objectName + wxT("\".  Message received from CSPICE is: ");
      errmsg += errStr + wxT("\n");
      reset_c();
      delete [] err;
      throw UtilityException(errmsg);
   }
   // get the tolerance in spacecraft clock ticks
   wxString    tolerance = wxT("01");  // this should probably be user input, or set as a constant
   ConstSpiceChar *tol = tolerance.char_str();
   SpiceDouble    tolTicks;
   sctiks_c(naifIDSPICE, tol, &tolTicks);
   if (failed_c())
   {
      ConstSpiceChar option[] = "LONG"; // retrieve long error message, for now
      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 tolerance (ticks) for object \"");
      errmsg += objectName + wxT("\".  Message received from CSPICE is: ");
      errmsg += errStr + wxT("\n");
      reset_c();
      delete [] err;
      throw UtilityException(errmsg);
   }
   #ifdef DEBUG_CK_READING
      MessageInterface::ShowMessage(wxT("First, check for coverage for object \"%s\", with NAIF ID %d\n"),
         objectName.c_str(), naifID);
   #endif
   Real beginCov = 0.0;
   Real endCov   = 0.0;
   GetCoverageStartAndEnd(loadedKernels, forFrameNaifId, beginCov, endCov, false);

   // Now get the C-matrix and angular velocity at the requested time
   SpiceDouble    cmat[3][3];
   SpiceDouble    av[3];
   SpiceBoolean   found;
   SpiceDouble    clkout;
   #ifdef DEBUG_CK_READING
      MessageInterface::ShowMessage(wxT("about to call ckgpav: \n"));
      MessageInterface::ShowMessage(wxT("   NAIF ID  = %d\n")
                                    wxT("   etSPICE  = %12.10f\n")
                                    wxT("   scTime   = %12.10fn")
                                    wxT("   tolTicks = %12.10f\n")
                                    wxT("   refFrame = %s\n"),
         (Integer) naifIDSPICE, (Real) etSPICE, (Real) scTime, (Real) tolTicks,
         referenceFrame.c_str());
   #endif
   ckgpav_c(frameNaifIDSPICE, scTime, tolTicks, referenceFrameSPICE, cmat, av, &clkout, &found);
//   ckgpav_c(naifIDSPICE, scTime, tolTicks, referenceFrameSPICE, cmat, av, &clkout, &found);
   if (failed_c())
   {
      ConstSpiceChar option[] = "LONG"; // retrieve long error message, for now
      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 C-matrix and/or angular velocity for object \"");
      errmsg += objectName + wxT("\".  Message received from CSPICE is: ");
      errmsg += errStr + wxT("\n");
      reset_c();
      delete [] err;
      throw UtilityException(errmsg);
   }
   if (found == SPICEFALSE)
   {
      wxString errmsg = wxT("Pointing data for object ");
      errmsg += objectName + wxT(" not found on loaded CK/SCLK kernels.\n");
      throw UtilityException(errmsg);
   }
   #ifdef DEBUG_CK_READING
      MessageInterface::ShowMessage(wxT("results from ckgpav: \n"));
      MessageInterface::ShowMessage(wxT("   cosMat = %12.10f  %12.10f  %12.10f\n")
                                    wxT("            %12.10f  %12.10f  %12.10f\n")
                                    wxT("            %12.10f  %12.10f  %12.10f\n"),
                                    (Real)cmat[0][0], (Real)cmat[0][1], (Real)cmat[0][2],
                                    (Real)cmat[1][0], (Real)cmat[1][1], (Real)cmat[1][2],
                                    (Real)cmat[2][0], (Real)cmat[2][1], (Real)cmat[2][2]);
      MessageInterface::ShowMessage(wxT("   angvel = %12.10f  %12.10f  %12.10f\n"),
                                   (Real)av[0], (Real)av[1], (Real)av[2]);
      MessageInterface::ShowMessage(wxT("   and clkout = %12.10f\n"), (Real) clkout);
   #endif
   // Set output values
   r33.Set(cmat[0][0], cmat[0][1], cmat[0][2],
           cmat[1][0], cmat[1][1], cmat[1][2],
           cmat[2][0], cmat[2][1], cmat[2][2]);
   angVel.Set(av[0], av[1], av[2]);

}
コード例 #7
0
//------------------------------------------------------------------------------
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);
      }
   }
}
コード例 #8
0
ファイル: zzerror.c プロジェクト: Boxx-Obspm/DOCKing_System
const char * zzerror( long cnt )

/*

-Brief_I/O

   Variable  I/O  Description 
   --------  ---  -------------------------------------------------- 
   cnt        I   Either a flag (less than 0) indicating a scalar or an 
                  array index.

   The function returns a string version of the SPICE error output.

-Detailed_Input

   cnt        A long integer defining the index of a vector at which
              the error signaled or a negative value indicating the
              error occurred during a scalar operation.

-Detailed_Output

   The function returns a pointer to a string (char *), the string
   containing the SPICE short and long error messages, plus
   the full trace back. If the error signaled during a vectorized
   operation, the error string includes the vector index at failure.

-Parameters

   MSG_LEN    one half the max length of the return string. The return 
              string has dimension 2*MSG_LEN.

   TRC_LEN    the max length of a string returned from trcnam_.
   
   MAXMOD     is the maximum storage depth for names in the
              traceback stack. Value copied from trcpkg.f.

-Exceptions

   1) If trcdep_ returns a 'depth' value larger than the maximum depth
      as assigned to MAXMOD, the routine returns a SPICE(BUG) error
      and error message to the caller.

-Files

   None.

-Particulars

   All interface functions immediately check failed_c() after
   calling CSPICE. When failed_c() returns SPICETRUE, 
   the interface performs the appropriate action to return the
   error state to the interpreter.
       
   Call after detecting a failed_c() event.

   The user should call zzerrorinit prior to a zzerror call.
   zzerrorinit places the error subsystem in the RETURN/NULL
   state.

   This routine makes a call to reset_c to reset the error
   system to an non-error state. The call causes the following:

      failed_c returns `false' value until another error signal. 

      return_c returns `false' value until another error signal. 

      getsms_ and getlms_ return blank strings. 

      The traceback routines return a traceback of the current
      active call chain, not the active call chain at the time
      of the last error. 

-Examples

   Expected use, check failed, return the error string:
   
      /.
      Initialize the error system to RETURN/NULL
      ./
      zzerrorinit();

         ... CSPICE calls ...
   
      /.
      Check for a failure, return the error string if
      failed_c returns true.
      ./ 
      if( failed_c() )
         {
         error_str = zzerror( index );
         
         /.
         Return the error string traceback to
         the calling program.
         ./
         error_return( error_str );
         }

   Example of a string returned by zzerror:
   
      In scalar context-

      SPICE(NOLEAPSECONDS): [str2et_c->STR2ET->TTRANS] The variable 
      that points to the leapseconds (DELTET/DELTA_AT) could not be 
      located in the kernel pool.  It is likely that the leapseconds 
      kernel has not been loaded via the routine FURNSH.
      
      In a vector context-

      cspice_str2et, 'Jan 1, 2049', et
      et_vec = dindgen(5)*10000d + et

      cspice_spkezr, 'MOON', et_vec, 'J2000', 'NONE', 'EARTH', starg, ltime

      Creates the string
      
      SPICE(SPKINSUFFDATA): [spkezr_c->SPKEZR->SPKEZ->SPKGEO]
      Insufficient ephemeris data has been loaded to compute the
      state of 301 (MOON) relative to 399 (EARTH) at the
      ephemeris epoch 2050 JAN 01 01:07:44.183. Failure at input
      vector index 3154.

-Restrictions

   Use with the SPICE error system in RETURN mode and the error
   device set to NULL.

-Literature_References

   None.

-Author_and_Institution
   
   E. D. Wright    (JPL)

-Version

   CSPICE 1.1.1 08-MAR-2007 (EDW)

      Corrected spelling mistake in error message string.

   CSPICE 1.1.0 24-APR-2006 (EDW)

      Version 1.0.0 contained an extraneous chkin_c call which caused a
      cascade of 'zzerror_c' strings prefixed to error strings. This call
      bug was removed.
      
      Replaced LDPOOL reference in header docs with FURNSH.

   CSPICE 1.0.0 17-OCT-2005 (EDW)

      Initial release to CSPICE

-Index_Entries

   error message

-&

*/
   {

   /*
   Local variables. Tag the 'msg_short' as static so the memory
   remains after return.

   We append to 'msg_short' hence the reason for it having the
   largest size.

   */
   static char msg_short [OUT_LEN];
   char        msg_long  [MSG_LEN];
   char        trname    [TRC_LEN];


   /*
   Define an error message string for the case if the trcdep_
   call returns a value larger than MAXMOD.
   */
   char      * depth_err = "SPICE(BUG): [zzerror]. An error "
                           "occurred during the processing of a SPICE "
                           "error signal. The trcdep_ routine "
                           "returned a depth, %i, larger than the "
                           "maximum allowed depth, %i. Please "
                           "contact NAIF.";

   SpiceInt    i;

   SpiceInt    depth;
   SpiceChar   trlist[MAXMOD*TRC_LEN];


   /*
   Zero out the char arrays, just-in-case.
   */
   memset( msg_short, 0, 2 *MSG_LEN        );
   memset( msg_long,  0,    MSG_LEN        );
   memset( trlist,    0,    MAXMOD*TRC_LEN );

   /*
   Retrieve the depth of the call traceback stack.
   */
   (void) trcdep_( &depth );

   /*
   Check 'depth' as less-than or equal-to MAXMOD. Signal a 
   SPICE error if not confirmed.
   */
   if ( depth > MAXMOD )
      {
      reset_c();

      sprintf(msg_short, depth_err, depth, MAXMOD );
      return(msg_short);
      }


   /*
   Loop over the number of items in the trace list.
   Index starts at 1 as trcnam_ is an f2c'd routine.
   */
   for ( i=1; i<= depth; i++)
      {
      
      /*
      Retrieve the name (as a FORTRAN string) of the ith routine's name
      from the trace stack. No SPICE call name has a string length longer
      than TRC_LEN characters.
      */
      (void) trcnam_( (integer *) &i, trname, (ftnlen) TRC_LEN );

      /* 
      The f2c code returns a FORTRAN type string, so null terminate
      the string for C.
      */
      F2C_ConvertStr( TRC_LEN, trname);

      /* 
      Create the trace list string by concatenation. Add '->' as a
      marker between the routine names except on the first pass through 
      the loop.
      */
      if ( i != 1 )
         {
         strcat( trlist, "->" );
         }
      strcat( trlist, trname );

      }

   /*
   Retrieve the short message from the error subsystem. The string has
   form "SPICE(MSGNAME)".
   */
   (void) getsms_(msg_short, (SpiceInt) sizeof msg_short);

   /* 
   Null terminate the FORTRAN 'msg_short' string for use in C routines.
   */
   F2C_ConvertStr( 2*MSG_LEN, msg_short);

   /*
   Obtain the long message string, a brief description of the error. 
   */
   (void) getlms_(msg_long, (ftnlen) sizeof(msg_long));

   /*
   Null terminate the FORTRAN 'msg_long' string for use in C routines.
   */
   F2C_ConvertStr( MSG_LEN, msg_long);

   /*
   Remember to reset the error system, so subsequent calls work.
   */
   reset_c();

   /*
   Combine the short, long and trace strings into a single string, then
   return the string.
   */
   sprintf( msg_short + strlen(msg_short), 
            ": [%s] %s", trlist, msg_long );

   /*
   Add the index value for errors from vectorized functions. Scalar 
   functions set 'cnt' to anything less than zero (normally -1 or -2).
   */
   if ( cnt >= 0 )
      {
      sprintf( msg_short + strlen(msg_short), 
               " Failure occurred at input vector index %ld.", cnt);
      }

   return(msg_short);
   }
コード例 #9
0
//------------------------------------------------------------------------------
Rvector6 SpiceOrbitKernelReader::GetTargetState(const wxString &targetName,
                                 const Integer     targetNAIFId,
                                 const A1Mjd       &atTime,
                                 const wxString &observingBodyName,
                                 const wxString &referenceFrame,
                                 const wxString &aberration)
{
   #ifdef DEBUG_SPK_READING
      MessageInterface::ShowMessage(
            wxT("Entering SPKReader::GetTargetState with target = %s, naifId = %d, time = %12.10f, observer = %s\n"),
            targetName.c_str(), targetNAIFId, atTime.Get(), observingBodyName.c_str());
      Real start, end;
      GetCoverageStartAndEnd(loadedKernels, targetNAIFId, start, end);
      MessageInterface::ShowMessage(wxT("   coverage for object %s : %12.10f --> %12.10f\n"),
            targetName.c_str(), start, end);
   #endif
   wxString targetNameToUse = GmatStringUtil::ToUpper(targetName);
   if (targetNameToUse == wxT("LUNA"))  // We use Luna, instead of Moon, for GMAT
      targetNameToUse        = wxT("MOON");
   if (targetNameToUse == wxT("SOLARSYSTEMBARYCENTER"))
      targetNameToUse = wxT("SSB");
   objectNameSPICE           = targetNameToUse.char_str();
   observingBodyNameSPICE    = observingBodyName.char_str();
   referenceFrameSPICE       = referenceFrame.char_str();
   aberrationSPICE           = aberration.char_str();
   // convert time to Ephemeris Time (TDB)
   etSPICE                   = A1ToSpiceTime(atTime.Get());
   naifIDSPICE               = targetNAIFId;
   boddef_c(objectNameSPICE, naifIDSPICE);        // CSPICE method to set NAIF ID for an object

   #ifdef DEBUG_SPK_READING
      MessageInterface::ShowMessage(wxT("SET NAIF Id for object %s to %d\n"),
            targetNameToUse.c_str(), targetNAIFId);
//      MessageInterface::ShowMessage(
//            wxT("In SPKReader::Converted (to TBD) time = %12.10f\n"), etMjdAtTime);
//      MessageInterface::ShowMessage(wxT("  then the full JD = %12.10f\n"),
//            (etMjdAtTime + GmatTimeConstants::JD_JAN_5_1941));
      MessageInterface::ShowMessage(wxT("So time passed to SPICE is %12.14f\n"), (Real) etSPICE);
   #endif
   SpiceDouble state[6];
   SpiceDouble oneWayLightTime;
   spkezr_c(objectNameSPICE, etSPICE, referenceFrameSPICE, aberrationSPICE,
            observingBodyNameSPICE, state, &oneWayLightTime);
#ifdef DEBUG_SPK_PLANETS
   Real        ttMjdAtTime   = TimeConverterUtil::Convert(atTime.Get(), TimeConverterUtil::A1MJD,
                               TimeConverterUtil::TTMJD, GmatTimeConstants::JD_JAN_5_1941);
//   Real etJd                 = etMjdAtTime + GmatTimeConstants::JD_JAN_5_1941;
   Real ttJd                 = ttMjdAtTime + GmatTimeConstants::JD_JAN_5_1941;
   MessageInterface::ShowMessage(wxT("Asking CSPICE for state of body %s, with observer %s, referenceFrame %s, and aberration correction %s\n"),
         objectNameSPICE, observingBodyNameSPICE, referenceFrameSPICE, aberrationSPICE);
   MessageInterface::ShowMessage(
         wxT("           Body: %s   TT Time:  %12.10f  TDB Time: %12.10f   state:  %12.10f  %12.10f  %12.10f  %12.10f  %12.10f  %12.10f\n"),
         targetName.c_str(), ttJd, /*etJd,*/ state[0], state[1], state[2], state[3], state[4], state[5]);
#endif
   if (failed_c())
   {
//      ConstSpiceChar option[] = wxT("SHORT"); // retrieve short error message, for now
//      SpiceInt       numChar  = MAX_SHORT_MESSAGE;
//      SpiceChar      err[MAX_SHORT_MESSAGE];
      ConstSpiceChar option[] = "LONG"; // retrieve long error message, for now
      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 state for body \"");
      errmsg += targetName + wxT("\".  Message received from CSPICE is: ");
      errmsg += errStr + wxT("\n");
      reset_c();
      delete [] err;
      throw UtilityException(errmsg);
   }
   #ifdef DEBUG_SPK_READING
      MessageInterface::ShowMessage(
            wxT("In SPKReader::Called spkezr_c and got state out\n"));
   #endif


   Rvector6 r6(state[0],state[1],state[2],state[3],state[4],state[5]);
   return r6;
}
コード例 #10
0
//------------------------------------------------------------------------------
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);
   }
}
コード例 #11
0
ファイル: body.cpp プロジェクト: kartikkumar/emtg
	//function to load new data into the body
	void body::load_body_data(const int& ibody_code, const string& iname, const string& ishortname, const int& ispice_ID, const double& imininum_altitude, const double& imass, const double& iradius, const double& iepoch, vector<double>& ireference_angles, vector<double>& iclassical_orbit_elements, const double& iuniverse_mu, const int& icentral_body_SPICE_ID, const string& icentral_body_name, const double& icentral_body_radius, missionoptions* options)
	{
		//copy information from the inputs into the body
		this->name = iname;
		this->short_name = ishortname;
		this->universe_mu = iuniverse_mu;
		this->body_code = ibody_code;
		this->central_body_spice_ID = icentral_body_SPICE_ID;
		this->central_body_name = icentral_body_name;
		this->central_body_radius = icentral_body_radius;

		this->spice_ID = ispice_ID;
		this->minimum_safe_flyby_altitude = imininum_altitude;
		this->mass = imass;
		this->radius = iradius;
		this->reference_epoch = iepoch;
		this->SMA = iclassical_orbit_elements[0];
		this->ECC = iclassical_orbit_elements[1];
		this->INC = iclassical_orbit_elements[2] * EMTG::math::PI / 180.0;
		this->RAAN = iclassical_orbit_elements[3] * EMTG::math::PI / 180.0;
		this->AOP = iclassical_orbit_elements[4] * EMTG::math::PI / 180.0;
		this->MA = iclassical_orbit_elements[5] * EMTG::math::PI / 180.0;
		


		//compute additional values
		mu = options->G * mass;
		if (ECC < 0.2)
			r_SOI = SMA * pow(mu / universe_mu, 0.4);
		else
			r_SOI = SMA * (1 - ECC) * pow(mu / (3.0 * universe_mu), 0.333333333333333333333333);

		//determine which ephemeris to draw from
		if (options->ephemeris_source == 0)
		{
			body_ephemeris_source = 0; //use static ephemeris
			ephemeris_start_date = -0;
			ephemeris_end_date = 1e+10;
		}
		else if (options->ephemeris_source == 1)
		{
			//first, check to see if the body exists in the currently loaded SPICE kernels
			double temp_state[6];
			double LT_dump;
			spkez_c (spice_ID, reference_epoch - (51544.5 * 86400.0), "J2000", "NONE", central_body_spice_ID, temp_state, &LT_dump);
			if (failed_c())
				reset_c();


			if (fabs(temp_state[0]) > 1.0e-6 && fabs(temp_state[0]) < 1.0e+50)
			{
				body_ephemeris_source = 1; //body can be located using SPICE
			}
			else
			{
				cout << "Warning, body " << name << " does not have a SPICE ephemeris file." << endl;
				body_ephemeris_source = 0; //use static ephemeris
				ephemeris_start_date = 0;
				ephemeris_end_date = 1e+10;
			}
		}

		J2000_body_equatorial_frame.initialize(ireference_angles[0], ireference_angles[1], ireference_angles[2], ireference_angles[3], ireference_angles[4], ireference_angles[5]);
	}