1 /*
2 
3 -Procedure gfpa_c ( GF, phase angle search )
4 
5 -Abstract
6 
7    Determine time intervals for which a specified constraint
8    on the phase angle between an illumination source, a target,
9    and observer body centers is met.
10 
11 -Disclaimer
12 
13    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
14    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
15    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
16    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
17    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
18    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
19    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
20    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
21    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
22    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
23 
24    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
25    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
26    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
27    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
28    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
29    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
30 
31    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
32    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
33    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
34    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
35 
36 -Required_Reading
37 
38    GF
39    NAIF_IDS
40    SPK
41    TIME
42    WINDOWS
43 
44 -Keywords
45 
46    EVENT
47    GEOMETRY
48    EPHEMERIS
49    SEARCH
50    WINDOW
51 
52 */
53 
54    #include <stdlib.h>
55    #include "SpiceGF.h"
56    #include "SpiceUsr.h"
57    #include "SpiceZfc.h"
58    #include "SpiceZmc.h"
59    #include "zzalloc.h"
60 
gfpa_c(ConstSpiceChar * target,ConstSpiceChar * illmn,ConstSpiceChar * abcorr,ConstSpiceChar * obsrvr,ConstSpiceChar * relate,SpiceDouble refval,SpiceDouble adjust,SpiceDouble step,SpiceInt nintvls,SpiceCell * cnfine,SpiceCell * result)61    void gfpa_c ( ConstSpiceChar     * target,
62                  ConstSpiceChar     * illmn,
63                  ConstSpiceChar     * abcorr,
64                  ConstSpiceChar     * obsrvr,
65                  ConstSpiceChar     * relate,
66                  SpiceDouble          refval,
67                  SpiceDouble          adjust,
68                  SpiceDouble          step,
69                  SpiceInt             nintvls,
70                  SpiceCell          * cnfine,
71                  SpiceCell          * result     )
72 
73 /*
74 
75 -Brief_I/O
76 
77    Variable         I/O  Description
78    ---------------  ---  ------------------------------------------------
79    SPICE_GF_CNVTOL   P   Convergence tolerance
80    target            I   Name of the target body.
81    illmn             I   Name of the illuminating body.
82    abcorr            I   Aberration correction flag.
83    obsrvr            I   Name of the observing body.
84    relate            I   Relational operator.
85    refval            I   Reference value.
86    adjust            I   Adjustment value for absolute extrema searches.
87    step              I   Step size used for locating extrema and roots.
88    nintvls           I   Workspace window interval count.
89    cnfine           I-O  SPICE window to which the search is confined.
90    result            O   SPICE window containing results.
91 
92 -Detailed_Input
93 
94    target      is the name of a target body. Optionally, you may supply
95                a string containing the integer ID code for the object.
96                For example both "MOON" and "301" are legitimate strings
97                that indicate the Moon is the target body.
98 
99                Case and leading or trailing blanks are not significant
100                in the string `target'.
101 
102    illmn       the string name of the illuminating body. This will
103                normally be "SUN" but the algorithm can use any
104                ephemeris object
105 
106                Case and leading or trailing blanks are not significant
107                in the string `illmn'.
108 
109    abcorr      indicates the aberration corrections to be applied to
110                the observer-target position vector to account for
111                one-way light time and stellar aberration.
112 
113                Any aberration correction accepted by the SPICE
114                routine spkezr_c is accepted here. See the header
115                of spkezr_c for a detailed description of the
116                aberration correction options. For convenience,
117                the allowed aberation options are listed below:
118 
119                   "NONE"     Apply no correction.
120 
121                   "LT"       "Reception" case:  correct for
122                              one-way light time using a Newtonian
123                              formulation.
124 
125                   "LT+S"     "Reception" case:  correct for
126                              one-way light time and stellar
127                              aberration using a Newtonian
128                              formulation.
129 
130                   "CN"       "Reception" case:  converged
131                              Newtonian light time correction.
132 
133                   "CN+S"     "Reception" case:  converged
134                              Newtonian light time and stellar
135                              aberration corrections.
136 
137                Note that this routine accepts only reception mode
138                aberration corrections.
139 
140                Case and leading or trailing blanks are not significant
141                in the string `abcorr'.
142 
143    obsrvr      is the name of the observing body. Optionally, you may
144                supply a string containing the integer ID code for the
145                object. For example both "MOON" and "301" are legitimate
146                strings that indicate the Moon is the observer.
147 
148                Case and leading or trailing blanks are not significant
149                in the string `obsrvr'.
150 
151    relate      is a relational operator used to define a constraint on
152                the phase angle. The result window found by
153                this routine indicates the time intervals where the
154                constraint is satisfied. Supported values of `relate'
155                and corresponding meanings are shown below:
156 
157                   ">"       The phase angle value is greater than the
158                             reference value REFVAL.
159 
160                   "="       The phase angle value is equal to the
161                             reference value REFVAL.
162 
163                   "<"       The phase angle value is less than the
164                             reference value REFVAL.
165 
166                   "ABSMAX"  The phase angle value is at an absolute
167                             maximum.
168 
169                   "ABSMIN"  The phase angle value is at an absolute
170                             minimum.
171 
172                   "LOCMAX"  The phase angle value is at a local
173                             maximum.
174 
175                   "LOCMIN"  The phase angle value is at a local
176                             minimum.
177 
178                `relate' may be used to specify an "adjusted" absolute
179                extremum constraint: this requires the phase angle
180                to be within a specified offset relative to an
181                absolute extremum. The argument `adjust' (described
182                below) is used to specify this offset.
183 
184                Local extrema are considered to exist only in the
185                interiors of the intervals comprising the confinement
186                window:  a local extremum cannot exist at a boundary
187                point of the confinement window.
188 
189                Case and leading or trailing blanks are not significant
190                in the string `relate'.
191 
192    `refval'    is the reference value used together with the argument
193                `relate' to define an equality or inequality to be
194                satisfied by the phase angle. See the discussion of
195                `relate' above for further information.
196 
197                The units of `refval' are radians.
198 
199    adjust      is a parameter used to modify searches for absolute
200                extrema: when `relate' is set to "ABSMAX" or "ABSMIN"
201                and `adjust' is set to a positive value, gfpa_c will
202                find times when the phase angle is within
203                `adjust' radians of the specified extreme value.
204 
205                If `adjust' is non-zero and a search for an absolute
206                minimum `min' is performed, the result window contains
207                time intervals when the phase angle has values between
208                 `min' and min+adjust.
209 
210                If the search is for an absolute maximum `max', the
211                corresponding range is from max-adjust to `max'.
212 
213                `adjust' is not used for searches for local extrema,
214                equality or inequality conditions.
215 
216    step        is the step size to be used in the search. `step' must
217                be shorter than any maximal time interval on which the
218                specified phase angle function is monotone increasing or
219                decreasing. That is, if the confinement window is
220                partitioned into alternating intervals on which the
221                phase angle function is either monotone increasing or
222                decreasing, `step' must be shorter than any of these
223                intervals.
224 
225                However, `step' must not be *too* short, or the search
226                will take an unreasonable amount of time.
227 
228                The choice of `step' affects the completeness but not
229                the precision of solutions found by this routine; the
230                precision is controlled by the convergence tolerance.
231                See the discussion of the parameter SPICE_GF_CNVTOL for
232                details.
233 
234                STEP has units of TDB seconds.
235 
236    nintvls     is a parameter specifying the number of intervals that
237                can be accommodated by each of the dynamically allocated
238                workspace windows used internally by this routine.
239 
240                In many cases, it's not necessary to compute an accurate
241                estimate of how many intervals are needed; rather, the
242                user can pick a size considerably larger than what's
243                really required.
244 
245                However, since excessively large arrays can prevent
246                applications from compiling, linking, or running
247                properly, sometimes `nintvls' must be set according to
248                the actual workspace requirement. A rule of thumb for
249                the number of intervals needed is
250 
251                   nintvls  =  2*n  +  ( m / step )
252 
253                where
254 
255                   n     is the number of intervals in the confinement
256                         window
257 
258                   m     is the measure of the confinement window, in
259                         units of seconds
260 
261                   `step'  is the search step size in seconds
262 
263    cnfine      is a SPICE window that confines the time period over
264                which the specified search is conducted. `cnfine' may
265                consist of a single interval or a collection of
266                intervals.
267 
268                The endpoints of the time intervals comprising `cnfine'
269                are interpreted as seconds past J2000 TDB.
270 
271                See the Examples section below for a code example that
272                shows how to create a confinement window.
273 
274 -Detailed_Output
275 
276    cnfine      is the input confinement window, updated if necessary so
277                the control area of its data array indicates the
278                window's size and cardinality. The window data are
279                unchanged.
280 
281    result      is the window of intervals, contained within the
282                confinement window `cnfine', on which the specified
283                phase angle constraint is satisfied.
284 
285                The endpoints of the time intervals comprising `result'
286                are interpreted as seconds past J2000 TDB.
287 
288                If `result' is non-empty on input, its contents will be
289                discarded before gfpa_c conducts its search.
290 
291 -Parameters
292 
293    SPICE_GF_CNVTOL
294 
295                is the convergence tolerance used for finding endpoints
296                of the intervals comprising the result window.
297                SPICE_GF_CNVTOL is used to determine when binary
298                searches for roots should terminate: when a root is
299                bracketed within an interval of length SPICE_GF_CNVTOL,
300                the root is considered to have been found.
301 
302                The accuracy, as opposed to precision, of roots found by
303                this routine depends on the accuracy of the input data.
304                In most cases, the accuracy of solutions will be
305                inferior to their precision.
306 
307                SPICE_GF_CNVTOL is declared in the header file
308                SpiceGF.h.
309 
310 -Exceptions
311 
312    1)  In order for this routine to produce correct results,
313        the step size must be appropriate for the problem at hand.
314        Step sizes that are too large may cause this routine to miss
315        roots; step sizes that are too small may cause this routine
316        to run unacceptably slowly and in some cases, find spurious
317        roots.
318 
319        This routine does not diagnose invalid step sizes, except
320        that if the step size is non-positive, an error is signaled
321        by a routine in the call tree of this routine.
322 
323    2)  Due to numerical errors, in particular,
324 
325           - Truncation error in time values
326           - Finite tolerance value
327           - Errors in computed geometric quantities
328 
329        it is *normal* for the condition of interest to not always be
330        satisfied near the endpoints of the intervals comprising the
331        result window.
332 
333        The result window may need to be contracted slightly by the
334        caller to achieve desired results. The SPICE window routine
335        wncond_c can be used to contract the result window.
336 
337    3)  If an error (typically cell overflow) occurs while performing
338        window arithmetic, the error will be diagnosed by a routine
339        in the call tree of this routine.
340 
341    4)  If the relational operator `relate' is not recognized, an
342        error is signaled by a routine in the call tree of this
343        routine.
344 
345    5)  If the aberration correction specifier contains an
346        unrecognized value, an error is signaled by a routine in the
347        call tree of this routine.
348 
349    6)  If `adjust' is negative, an error is signaled by a routine in
350        the call tree of this routine.
351 
352    7)  If either of the input body names do not map to NAIF ID
353        codes, an error is signaled by a routine in the call tree of
354        this routine.
355 
356    8)  If required ephemerides or other kernel data are not
357        available, an error is signaled by a routine in the call tree
358        of this routine.
359 
360    9)  If the workspace interval count is less than 1, the error
361        SPICE(VALUEOUTOFRANGE) will be signaled.
362 
363    10) If the required amount of workspace memory cannot be
364        allocated, the error SPICE(MALLOCFAILURE) will be
365        signaled.
366 
367    11) If the output SPICE window `result' has insufficient capacity to
368        contain the number of intervals on which the specified geometric
369        condition is met, the error will be diagnosed by a routine in
370        the call tree of this routine. If the result window has size
371        less than 2, the error SPICE(INVALIDDIMENSION) will be signaled
372        by this routine.
373 
374    12) If any input string argument pointer is null, the error
375        SPICE(NULLPOINTER) will be signaled.
376 
377    13) If any input string argument is empty, the error
378        SPICE(EMPTYSTRING) will be signaled.
379 
380    14) If either input cell has type other than SpiceDouble,
381        the error SPICE(TYPEMISMATCH) is signaled.
382 
383    15) An error signals from a routine in the call tree of
384        this routine for any transmit mode aberration correction.
385 
386 -Files
387 
388    Appropriate SPK and PCK kernels must be loaded by the calling
389    program before this routine is called.
390 
391    The following data are required:
392 
393       - SPK data: the calling application must load ephemeris data
394         for the targets, observer, and any intermediate objects in
395         a chain connecting the targets and observer that cover the
396         time period specified by the window CNFINE. If aberration
397         corrections are used, the states of target and observer
398         relative to the solar system barycenter must be calculable
399         from the available ephemeris data. Typically ephemeris data
400         are made available by loading one or more SPK files using
401         furnsh_c.
402 
403    Kernel data are normally loaded once per program run, NOT every
404    time this routine is called.
405 
406 -Particulars
407 
408                      ILLMN      OBS
409      ILLMN as seen      *       /
410      from TARG at       |      /
411      ET - LT.           |     /
412                        >|..../< phase angle
413                         |   /
414                       . |  /
415                     .   | /
416                    .     *     TARG as seen from OBS
417              SEP   .   TARG    at ET
418                     .  /
419                       /
420                      *
421 
422    This routine determines if the caller-specified constraint
423    condition on the geometric event (phase angle) is satisfied for
424    any time intervals within the confinement window `cnfine'. If one
425    or more such time intervals exist, those intervals are added
426    to the `result' window.
427 
428    This routine provides a simpler, but less flexible interface
429    than does the routine gfevnt_c for conducting searches for
430    illuminator-target-observer phase angle value events.
431    Applications that require support for progress reporting,
432    interrupt handling, non-default step or refinement functions
433    should call gfevnt_c rather than this routine.
434 
435    Below we discuss in greater detail aspects of this routine's
436    solution process that are relevant to correct and efficient
437    use of this routine in user applications.
438 
439 
440    The Search Process
441    ==================
442 
443    Regardless of the type of constraint selected by the caller, this
444    routine starts the search for solutions by determining the time
445    periods, within the confinement window, over which the
446    phase angle function is monotone increasing and monotone
447    decreasing. Each of these time periods is represented by a SPICE
448    window. Having found these windows, all of the phase angle
449    function's local extrema within the confinement window are known.
450    Absolute extrema then can be found very easily.
451 
452    Within any interval of these "monotone" windows, there will be at
453    most one solution of any equality constraint. Since the boundary
454    of the solution set for any inequality constraint is contained in
455    the union of
456 
457       - the set of points where an equality constraint is met
458       - the boundary points of the confinement window
459 
460    the solutions of both equality and inequality constraints can be
461    found easily once the monotone windows have been found.
462 
463 
464    Step Size
465    =========
466 
467    The monotone windows (described above) are found using a two-step
468    search process. Each interval of the confinement window is
469    searched as follows: first, the input step size is used to
470    determine the time separation at which the sign of the rate of
471    change of phase angle will be sampled. Starting at
472    the left endpoint of an interval, samples will be taken at each
473    step. If a change of sign is found, a root has been bracketed; at
474    that point, the time at which the time derivative of the
475    phase angle is zero can be found by a refinement process, for
476    example, using a binary search.
477 
478    Note that the optimal choice of step size depends on the lengths
479    of the intervals over which the phase angle function is monotone:
480    the step size should be shorter than the shortest of these
481    intervals (within the confinement window).
482 
483    The optimal step size is *not* necessarily related to the lengths
484    of the intervals comprising the result window. For example, if
485    the shortest monotone interval has length 10 days, and if the
486    shortest result window interval has length 5 minutes, a step size
487    of 9.9 days is still adequate to find all of the intervals in the
488    result window. In situations like this, the technique of using
489    monotone windows yields a dramatic efficiency improvement over a
490    state-based search that simply tests at each step whether the
491    specified constraint is satisfied. The latter type of search can
492    miss solution intervals if the step size is longer than the
493    shortest solution interval.
494 
495    Having some knowledge of the relative geometry of the target,
496    illumination source, and observer can be a valuable aid in
497    picking a reasonable step size. In general, the user can
498    compensate for lack of such knowledge by picking a very short
499    step size; the cost is increased computation time.
500 
501    Note that the step size is not related to the precision with which
502    the endpoints of the intervals of the result window are computed.
503    That precision level is controlled by the convergence tolerance.
504 
505 
506    Convergence Tolerance
507    =====================
508 
509    As described above, the root-finding process used by this routine
510    involves first bracketing roots and then using a search process to
511    locate them.  "Roots" include times when extrema are attained and
512    times when the geometric quantity function is equal to a reference
513    value or adjusted extremum. All endpoints of the intervals comprising
514    the result window are either endpoints of intervals of the confinement
515    window or roots.
516 
517    Once a root has been bracketed, a refinement process is used to
518    narrow down the time interval within which the root must lie.
519    This refinement process terminates when the location of the root
520    has been determined to within an error margin called the
521    "convergence tolerance." The convergence tolerance used by this
522    routine is set via the parameter SPICE_GF_CNVTOL.
523 
524    The value of SPICE_GF_CNVTOL is set to a "tight" value so that the
525    tolerance doesn't limit the accuracy of solutions found by this
526    routine. In general the accuracy of input data will be the limiting
527    factor.
528 
529    The user may change the convergence tolerance from the default
530    SPICE_GF_CNVTOL value by calling the routine gfstol_c, e.g.
531 
532       gfstol_c( tolerance value in seconds )
533 
534    Call gfstol_c prior to calling this routine. All subsequent
535    searches will use the updated tolerance value.
536 
537    Searches over time windows of long duration may require use of
538    larger tolerance values than the default: the tolerance must be
539    large enough so that it, when added to or subtracted from the
540    confinement window's lower and upper bounds, yields distinct time
541    values.
542 
543    Setting the tolerance tighter than SPICE_GF_CNVTOL is unlikely to be
544    useful, since the results are unlikely to be more accurate.
545    Making the tolerance looser will speed up searches somewhat,
546    since a few convergence steps will be omitted. However, in most
547    cases, the step size is likely to have a much greater effect
548    on processing time than would the convergence tolerance.
549 
550 
551    The Confinement Window
552    ======================
553 
554    The simplest use of the confinement window is to specify a time
555    interval within which a solution is sought. However, the
556    confinement window can, in some cases, be used to make searches
557    more efficient. Sometimes it's possible to do an efficient search
558    to reduce the size of the time period over which a relatively
559    slow search of interest must be performed. See the "CASCADE"
560    example program in gf.req for a demonstration.
561 
562 -Examples
563 
564    The numerical results shown for these examples may differ across
565    platforms. The results depend on the SPICE kernels used as
566    input, the compiler and supporting libraries, and the machine
567    specific arithmetic implementation.
568 
569       Use the meta-kernel shown below to load the required SPICE
570       kernels.
571 
572          KPL/MK
573 
574          File name: standard.tm
575 
576          This meta-kernel is intended to support operation of SPICE
577          example programs. The kernels shown here should not be
578          assumed to contain adequate or correct versions of data
579          required by SPICE-based user applications.
580 
581          In order for an application to use this meta-kernel, the
582          kernels referenced here must be present in the user's
583          current working directory.
584 
585          The names and contents of the kernels referenced
586          by this meta-kernel are as follows:
587 
588             File name                     Contents
589             ---------                     --------
590             de421.bsp                     Planetary ephemeris
591             pck00009.tpc                  Planet orientation and
592                                           radii
593             naif0009.tls                  Leapseconds
594 
595          \begindata
596 
597             KERNELS_TO_LOAD = ( 'de421.bsp',
598                                 'pck00009.tpc',
599                                 'naif0009.tls'  )
600 
601          \begintext
602 
603    Example:
604 
605       Determine the time windows from December 1, 2006 UTC to
606       January 31, 2007 UTC for which the sun-moon-earth configuration
607       phase angle satisfies the relation conditions with respect to a
608       reference value of .57598845 radians (the phase angle at
609       January 1, 2007 00:00:00.000 UTC, 33.001707 degrees). Also
610       determine the time windows corresponding to the local maximum and
611       minimum phase angles, and the absolute maximum and minimum phase
612       angles during the search interval. The configuration defines the
613       sun as the illuminator, the moon as the target, and the earth as
614       the observer.
615 
616       #include <stdio.h>
617       #include "SpiceUsr.h"
618 
619       #define  TIMFMT  "YYYY MON DD HR:MN:SC.###"
620       #define  NINTVL  5000
621       #define  TIMLEN  41
622       #define  NLOOPS  7
623 
624       int main()
625          {
626 
627          /.
628          Local variables
629          ./
630          SpiceChar               begstr [ TIMLEN ];
631          SpiceChar               endstr [ TIMLEN ];
632 
633          SPICEDOUBLE_CELL      ( cnfine, 2 );
634          SPICEDOUBLE_CELL      ( result, NINTVL*2 );
635 
636          SpiceDouble             adjust;
637          SpiceDouble             et0;
638          SpiceDouble             et1;
639          SpiceDouble             phaseq;
640          SpiceDouble             refval;
641          SpiceDouble             start;
642          SpiceDouble             step;
643          SpiceDouble             stop;
644          SpiceInt                i;
645          SpiceInt                j;
646 
647          /.
648          Define the values for target, observer, illuminator, and
649          aberration correction.
650          ./
651 
652          ConstSpiceChar * target = "moon";
653          ConstSpiceChar * illmn  = "sun";
654          ConstSpiceChar * abcorr = "lt+s";
655          ConstSpiceChar * obsrvr = "earth";
656 
657          ConstSpiceChar * relate [NLOOPS] = { "=",
658                                               "<",
659                                               ">",
660                                               "LOCMIN",
661                                               "ABSMIN",
662                                               "LOCMAX",
663                                               "ABSMAX",
664                                             };
665 
666          /.
667          Load kernels.
668          ./
669          furnsh_c ( "standard.tm" );
670 
671          /.
672          Store the time bounds of our search interval in
673          the confinement window.
674          ./
675          str2et_c ( "2006 DEC 01", &et0 );
676          str2et_c ( "2007 JAN 31", &et1 );
677 
678          wninsd_c ( et0, et1, &cnfine );
679 
680          /.
681          Search using a step size of 1 day (in units of seconds).
682          The reference value is 0.57598845 radians. We're not using the
683          adjustment feature, so we set ADJUST to zero.
684          ./
685          step   = spd_c();
686          refval = 0.57598845;
687          adjust = 0.0;
688 
689          for ( j = 0;  j < NLOOPS;  j++ )
690             {
691 
692             printf ( "Relation condition: %s\n",  relate[j] );
693 
694             /.
695             Perform the search. The SPICE window `result' contains
696             the set of times when the condition is met.
697             ./
698             gfpa_c ( target,    illmn,   abcorr, obsrvr,
699                      relate[j], refval,  adjust, step,
700                      NINTVL,    &cnfine, &result        );
701 
702             /.
703             Display the results.
704             ./
705             if ( wncard_c(&result) == 0 )
706                {
707                printf ( "Result window is empty.\n\n" );
708                }
709             else
710                {
711 
712                for ( i = 0;  i < wncard_c(&result);  i++ )
713                   {
714 
715                   /.
716                   Fetch the endpoints of the Ith interval
717                   of the result window.
718                   ./
719                   wnfetd_c ( &result, i, &start, &stop );
720 
721                   phaseq = phaseq_c ( start, target, illmn, obsrvr, abcorr );
722 
723                   timout_c ( start, TIMFMT, TIMLEN, begstr );
724                   printf ( "Start time = %s %16.9f\n", begstr, phaseq );
725 
726                   phaseq = phaseq_c ( stop, target, illmn, obsrvr, abcorr );
727 
728                   timout_c ( stop, TIMFMT, TIMLEN, endstr );
729                   printf ( "Stop time  = %s %16.9f\n", endstr, phaseq );
730                   }
731 
732                printf("\n");
733 
734                }
735 
736             }
737 
738          return ( 0 );
739          }
740 
741    The program outputs:
742 
743       Relation condition: =
744       Start time = 2006 DEC 02 13:31:34.414      0.575988450
745       Stop time  = 2006 DEC 02 13:31:34.414      0.575988450
746       Start time = 2006 DEC 07 14:07:55.470      0.575988450
747       Stop time  = 2006 DEC 07 14:07:55.470      0.575988450
748       Start time = 2006 DEC 31 23:59:59.997      0.575988450
749       Stop time  = 2006 DEC 31 23:59:59.997      0.575988450
750       Start time = 2007 JAN 06 08:16:25.512      0.575988450
751       Stop time  = 2007 JAN 06 08:16:25.512      0.575988450
752       Start time = 2007 JAN 30 11:41:32.557      0.575988450
753       Stop time  = 2007 JAN 30 11:41:32.557      0.575988450
754 
755       Relation condition: <
756       Start time = 2006 DEC 02 13:31:34.414      0.575988450
757       Stop time  = 2006 DEC 07 14:07:55.470      0.575988450
758       Start time = 2006 DEC 31 23:59:59.997      0.575988450
759       Stop time  = 2007 JAN 06 08:16:25.512      0.575988450
760       Start time = 2007 JAN 30 11:41:32.557      0.575988450
761       Stop time  = 2007 JAN 31 00:00:00.000      0.468279091
762 
763       Relation condition: >
764       Start time = 2006 DEC 01 00:00:00.000      0.940714974
765       Stop time  = 2006 DEC 02 13:31:34.414      0.575988450
766       Start time = 2006 DEC 07 14:07:55.470      0.575988450
767       Stop time  = 2006 DEC 31 23:59:59.997      0.575988450
768       Start time = 2007 JAN 06 08:16:25.512      0.575988450
769       Stop time  = 2007 JAN 30 11:41:32.557      0.575988450
770 
771       Relation condition: LOCMIN
772       Start time = 2006 DEC 05 00:16:50.317      0.086121423
773       Stop time  = 2006 DEC 05 00:16:50.317      0.086121423
774       Start time = 2007 JAN 03 14:18:31.977      0.079899769
775       Stop time  = 2007 JAN 03 14:18:31.977      0.079899769
776 
777       Relation condition: ABSMIN
778       Start time = 2007 JAN 03 14:18:31.977      0.079899769
779       Stop time  = 2007 JAN 03 14:18:31.977      0.079899769
780 
781       Relation condition: LOCMAX
782       Start time = 2006 DEC 20 14:09:10.392      3.055062862
783       Stop time  = 2006 DEC 20 14:09:10.392      3.055062862
784       Start time = 2007 JAN 19 04:27:54.600      3.074603891
785       Stop time  = 2007 JAN 19 04:27:54.600      3.074603891
786 
787       Relation condition: ABSMAX
788       Start time = 2007 JAN 19 04:27:54.600      3.074603891
789       Stop time  = 2007 JAN 19 04:27:54.600      3.074603891
790 
791 -Restrictions
792 
793    1) The kernel files to be used by this routine must be loaded
794       (normally using the CSPICE routine furnsh_c) before this
795       routine is called.
796 
797 -Literature_References
798 
799    None.
800 
801 -Author_and_Institution
802 
803    N.J. Bachman   (JPL)
804    E.D. Wright    (JPL)
805 
806 -Version
807 
808    -CSPICE Version 1.0.0, 15-JUL-2014 (EDW) (NJB)
809 
810 -Index_Entries
811 
812  GF phase angle search
813 
814 -&
815 */
816 
817 { /* Begin gfpa_c */
818 
819    /*
820    Static local variables
821    */
822    static SpiceInt         nw  =  SPICE_GF_NWPA;
823 
824    /*
825    Local variables
826    */
827    doublereal            * work;
828 
829    SpiceInt                nBytes;
830 
831 
832    /*
833    Participate in error tracing.
834    */
835    if ( return_c() )
836       {
837       return;
838       }
839    chkin_c ( "gfpa_c" );
840 
841 
842    /*
843    Make sure cell data types are d.p.
844    */
845    CELLTYPECHK2 ( CHK_STANDARD, "gfpa_c", SPICE_DP, cnfine, result );
846 
847    /*
848    Initialize the input cells if necessary.
849    */
850    CELLINIT2 ( cnfine, result );
851 
852    /*
853    Check the input strings to make sure each pointer is non-null
854    and each string length is non-zero.
855    */
856    CHKFSTR ( CHK_STANDARD, "gfpa_c", target );
857    CHKFSTR ( CHK_STANDARD, "gfpa_c", illmn  );
858    CHKFSTR ( CHK_STANDARD, "gfpa_c", abcorr );
859    CHKFSTR ( CHK_STANDARD, "gfpa_c", obsrvr );
860    CHKFSTR ( CHK_STANDARD, "gfpa_c", relate );
861 
862    /*
863    Check the workspace size; some mallocs have a violent
864    dislike for negative allocation amounts. To be safe,
865    rule out a count of zero intervals as well.
866    */
867    if ( nintvls < 1 )
868       {
869       setmsg_c ( "The specified workspace interval count # was "
870                  "less than the minimum allowed value (1)."     );
871       errint_c ( "#",  nintvls                                  );
872       sigerr_c ( "SPICE(VALUEOUTOFRANGE)"                       );
873       chkout_c ( "gfpa_c"                                      );
874       return;
875       }
876 
877    /*
878    Allocate the workspace.
879 
880    We have `nw' "doublereal" cells, each having cell size 2*nintvls.
881    Each cell also has a control area containing SPICE_CELL_CTRLSZ
882    double precision values.
883    */
884 
885    nintvls = nintvls * 2;
886 
887    nBytes  = ( nintvls + SPICE_CELL_CTRLSZ ) * nw * sizeof(SpiceDouble);
888 
889    work    = (doublereal *) alloc_SpiceMemory( nBytes );
890 
891    if ( !work )
892       {
893       setmsg_c ( "Workspace allocation of # bytes failed due to "
894                  "malloc failure"                                 );
895       errint_c ( "#",  nBytes                                     );
896       sigerr_c ( "SPICE(MALLOCFAILURE)"                           );
897       chkout_c ( "gfpa_c"                                         );
898       return;
899       }
900 
901    /*
902    Let the f2'd routine do the work.
903    */
904    gfpa_ ( ( char          * ) target,
905            ( char          * ) illmn,
906            ( char          * ) abcorr,
907            ( char          * ) obsrvr,
908            ( char          * ) relate,
909            ( doublereal    * ) &refval,
910            ( doublereal    * ) &adjust,
911            ( doublereal    * ) &step,
912            ( doublereal    * ) (cnfine->base),
913            ( integer       * ) &nintvls,
914            ( integer       * ) &nw,
915            ( doublereal    * ) work,
916            ( doublereal    * ) (result->base),
917            ( ftnlen          ) strlen(target),
918            ( ftnlen          ) strlen(illmn),
919            ( ftnlen          ) strlen(abcorr),
920            ( ftnlen          ) strlen(obsrvr),
921            ( ftnlen          ) strlen(relate) );
922 
923    /*
924    De-allocate the workspace.
925    */
926    free_SpiceMemory( work );
927 
928    /*
929    Sync the output cell.
930    */
931    if ( !failed_c() )
932       {
933       zzsynccl_c ( F2C, result ) ;
934       }
935 
936    ALLOC_CHECK;
937 
938    chkout_c ( "gfpa_c" );
939 
940 } /* End gfpa_c */
941 
942