1 /*
2 
3 -Procedure trcdep_c ( Traceback depth )
4 
5 -Abstract
6 
7    Return the number of modules in the traceback representation.
8 
9 -Disclaimer
10 
11    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
12    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
13    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
14    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
15    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
16    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
17    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
18    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
19    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
20    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
21 
22    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
23    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
24    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
25    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
26    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
27    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
28 
29    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
30    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
31    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
32    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
33 
34 -Required_Reading
35 
36    ERROR
37 
38 -Keywords
39 
40    ERROR
41 
42 */
43 
44    #include "SpiceUsr.h"
45    #include "SpiceZfc.h"
46 
trcdep_c(SpiceInt * depth)47    void trcdep_c ( SpiceInt  * depth )
48 
49 /*
50 
51 -Brief_I/O
52 
53    VARIABLE  I/O  DESCRIPTION
54    --------  ---  ---------------------------------------------------
55    depth      O   The number of modules in the traceback.
56 
57 -Detailed_Input
58 
59    None.
60 
61 -Detailed_Output
62 
63    depth          indicates the number of module names in the traceback
64                   representation.
65 
66                   The module names represent modules in a call chain,
67                   with the first name being the top-level module, and
68                   the name with index `depth' being the lowest level
69                   module.
70 
71                   The meaning of the traceback depends on the state of
72                   the error handling mechanism. There are two cases:
73 
74                      1)  In RETURN mode, when an error is
75                          signaled, the traceback at that point is
76                          saved. trcdep_c, trcnam_c, and qcktrc_c
77                          return values pertaining to the saved
78                          traceback.
79 
80                      2)  In all other modes, the traceback represents
81                          the CURRENT call chain. trcdep_c, trcnam_c,
82                          and qcktrc_c return values pertaining to
83                          the current trace representation.
84 
85 -Parameters
86 
87    None.
88 
89 -Exceptions
90 
91    Error free.
92 
93 -Files
94 
95    None.
96 
97 -Particulars
98 
99    SPICE-based applications can use this routine, together with
100    trcnam_c, to create a customized traceback report. This is normally
101    done after an application detects a SPICE error condition using
102    failed_c.
103 
104    The CSPICE routine qcktrc_c is an alternative to the combination of
105    trcdep_c and trcnam_c; qcktrc_c can be used to fetch a complete,
106    fixed-format traceback string in a single call.
107 
108 -Examples
109 
110    1) Deliberately generate a SPICE error to demonstrate use of
111       this routine together with trcnam_c. We'll attempt to look up
112       a state vector via spkezr_c without first having loaded any
113       SPK files.
114 
115       Example code begins here.
116 
117 
118          #include <stdio.h>
119          #include "SpiceUsr.h"
120 
121          int main()
122          {
123             /.
124             Local constants
125             ./
126             #define ACTION          "RETURN"
127 
128             /.
129             Local variables
130             ./
131             SpiceChar             * abcorr;
132             SpiceChar               longms  [ SPICE_ERROR_LMSGLN ];
133             SpiceChar               modnam  [ SPICE_ERROR_MODLEN ];
134             SpiceChar               shrtms  [ SPICE_ERROR_SMSGLN ];
135             SpiceChar             * obsrvr;
136             SpiceChar             * frame;
137             SpiceChar             * target;
138 
139             SpiceDouble             et;
140             SpiceDouble             lt;
141             SpiceDouble             state [6];
142 
143             SpiceInt                depth;
144             SpiceInt                i;
145 
146             /.
147             Set error handling action to RETURN so that this program
148             won't terminate when a SPICE error is signaled. Note that
149             the input string length argument is unused for a "SET"
150             operation.
151             ./
152             erract_c ( "SET", 0, ACTION );
153 
154             /.
155             Generate a SPICE error: call spkezr_c without first having
156             loaded an SPK file.
157             ./
158             et     = 0.0;
159             target = "Moon";
160             obsrvr = "Earth";
161             frame  = "J2000";
162             abcorr = "NONE";
163 
164             spkezr_c ( target, et, frame, abcorr, obsrvr, state, &lt );
165 
166             if ( failed_c() )
167             {
168                /.
169                An error has been signaled. First fetch the long
170                and short error message. Next fetch the traceback depth,
171                then fetch and display the module names.
172                ./
173                getmsg_c ( "SHORT", SPICE_ERROR_SMSGLN, shrtms );
174                getmsg_c ( "LONG",  SPICE_ERROR_LMSGLN, longms );
175 
176                printf ( "\n%s\n", shrtms );
177                printf ( "%s\n\n", longms );
178 
179                trcdep_c ( &depth );
180 
181                for ( i = 0;  i < depth;  i++ )
182                {
183                   trcnam_c ( i, SPICE_ERROR_MODLEN, modnam );
184 
185                   printf ( "Trace level: %d. Module name = %s\n",
186                            (int)i,
187                            modnam                                 );
188                }
189 
190                /.
191                Reset the error status so that CSPICE can resume normal
192                operation.
193                ./
194                reset_c();
195             }
196 
197             return ( 0 );
198          }
199 
200 
201       When this program was executed on a PC/Linux/gcc platform, the
202       output (which has been reformatted to fit in the available
203       space in this header) was:
204 
205 
206          ====================================================================
207          ============
208 
209          Toolkit version: N0065
210 
211          SPICE(NOLOADEDFILES) --
212 
213          At least one SPK file needs to be loaded by SPKLEF before beginning
214          a search.
215 
216          A traceback follows.  The name of the highest level module is first.
217          spkezr_c --> SPKEZR --> SPKEZ --> SPKGEO --> SPKSFS
218 
219          ====================================================================
220          ============
221 
222          SPICE(NOLOADEDFILES)
223          At least one SPK file needs to be loaded by SPKLEF before beginning
224          a search.
225 
226          Trace level: 0. Module name = spkezr_c
227          Trace level: 1. Module name = SPKEZR
228          Trace level: 2. Module name = SPKEZ
229          Trace level: 3. Module name = SPKGEO
230          Trace level: 4. Module name = SPKSFS
231 
232 
233 -Restrictions
234 
235    None.
236 
237 -Literature_References
238 
239    None.
240 
241 -Author_and_Institution
242 
243    N.J. Bachman    (JPL)
244    K.R. Gehringer  (JPL)
245 
246 -Version
247 
248    -CSPICE Version 1.0.1, 12-JUL-2016 (EDW)
249 
250       Edit to example program to use "%d" with explicit casts
251       to int for printing SpiceInts with printf.
252 
253    -CSPICE Version 1.0.0, 05-NOV-2013 (NJB) (KRG)
254 
255 -Index_Entries
256 
257    return traceback depth
258 
259 -&
260 */
261 
262 { /* Begin trcdep_c */
263 
264 
265    /*
266    This routine does not check in.
267    */
268 
269    trcdep_ ( (integer *) depth );
270 
271 
272 } /* End trcdep_c */
273