Main Page
PHSRM Geometric Event Finding Hands-On Lesson (C)

Table of Contents

   PHSRM Geometric Event Finding Hands-On Lesson (C)
      Overview
      Note About HTML Links
      References
         Tutorials
         Required Readings
         The Permuted Index
         Source Code Header Comments
      Kernels Used
      CSPICE Routines Used
   Find View Periods
      Task Statement
      Learning Goals
      Approach
         Solution steps
      Solution
         Solution Meta-Kernel
         Solution Code
         Solution Sample Output
   Find Times when Target is Visible
      Task Statement
      Learning Goals
      Approach
         Solution steps
      Solution
         Solution Code
         Solution Sample Output




Top

PHSRM Geometric Event Finding Hands-On Lesson (C)





July 21, 2011



Top

Overview




This lesson illustrates how the Geometry Finder (GF) subsystem of the CSPICE Toolkit can be used to find time intervals when specified geometric conditions are satisfied.

In this lesson the student is asked to construct a program that finds the time intervals, within a specified time range, when the Phobos Sample Return spacecraft (PHSRM) is visible from the USSURIYSK tracking station. Possible occultation of the spacecraft by Mars is to be considered.



Top

Note About HTML Links




The HTML version of this lesson contains links pointing to various HTML documents provided with the Toolkit. All of these links are relative and, in order to function, require this document to be in a certain location in the Toolkit HTML documentation directory tree.

In order for the links to be resolved, create a subdirectory called ``lessons'' under the ``doc/html'' directory of the ``cspice/'' tree and copy this document to that subdirectory before loading it into a Web browser.



Top

References






Top

Tutorials



The following SPICE tutorials serve as references for the discussions in this lesson:

 
   Name             Lesson steps/functions it describes
   ---------------  -----------------------------------------
   Time             Time Conversion
   SCLK and LSK     Time Conversion
   SPK              Obtaining Ephemeris Data
   Frames           Reference Frames
   Using Frames     Reference Frames
   PCK              Planetary Constants Data
   Lunar-Earth PCK  Lunar and Earth Orientation Data
   GF               The SPICE Geometry Ginder (GF) subsystem
These tutorials are available from the NAIF ftp server at JPL:

   http://naif.jpl.nasa.gov/naif/tutorials.html


Top

Required Readings



The Required Reading documents are provided with the Toolkit and are located under the ``cspice/doc'' directory in the C installation tree.

   Name             Lesson steps/functions that it describes
   ---------------  -----------------------------------------
   cells.req        Cell/window initialization
   frames.req       Using reference frames
   gf.req           The SPICE geometry finder (GF) subsystem
   kernel.req       Loading SPICE kernels
   naif_ids.req     Body and reference frame names
   pck.req          Obtaining planetary constants data
   spk.req          Computing positions and velocities
   time.req         UTC to ET time conversion
   windows.req      The SPICE window data type


Top

The Permuted Index



Another useful document distributed with the Toolkit is the permuted index. This is located under the ``cspice/doc'' directory in the C installation tree.

This text document provides a simple mechanism by which users can discover which CSPICE routines perform functions of interest, as well as the names of the source files that contain these routines.



Top

Source Code Header Comments



The most detailed specification of a given SPICE C routine is contained in the header section of its source code. The source code is distributed with the Toolkit and is located under the ``cspice/src/cspice'' path.

For example path of the source code of the str2et_c routine is

   cspice/src/cspice/str2et_c.c


Top

Kernels Used




The following kernels are used in examples provided in this lesson:

   File Name                            Type  Description
   -----------------------              ----  --------------------------
   de421xs.bsp                          SPK   Planetary ephemeris SPK
   earthstns_phsrm_itrf93_110118.bsp    SPK   Russian stations SPK
   earthstns_phsrm_topo_110118.tf       FK    Russian stations FK
   earth_070425_370426_predict.bpc      PCK   Binary PCK for Earth
   phsrm_130114_130114_130214_nom2.bsp  SPK   PHSRM trajectory SPK
   naif0009.tls                         LSK   Generic LSK
   pck00009.tpc                         PCK   Generic PCK
   phsrm_v00.tf                         FK    PHSRM FK
These SPICE kernels are included in the lesson package available from the PHSRM server at IKI:

   http://spice.ikiweb.ru/PHSRM/kernels


Top

CSPICE Routines Used




This section provides a summary of the functions that are suggested for usage in each of the exercises in this tutorial. (You may wish to not look at this list unless/until you ``get stuck'' while working on your own.)

   Name        Function that it performs
   ----------  ---------------------------------------------------
   furnsh_c    Loads kernels, individually or listed in meta-kernel
   gfoclt_c    Solve for times of occultation or transit
   gfposc_c    Solve for times when a position vector coordinate
               constraint is met
   str2et_c    Converts a time string to ET seconds past J2000
   timout_c    Format a time string for output
   wncard_c    Return cardinality of a SPICE window
   wndifd_c    Find the difference of two d.p. windows
   wnfetd_c    Fetch a specified interval from a d.p. window
   wninsd_c    Insert an interval into a d.p. window
Refer to the headers of the various functions listed above, as detailed interface specifications are provided with the source code.



Top

Find View Periods







Top

Task Statement




Write a program that finds the set of time intervals, within the time range

   2013 JAN 17 TDB
   2013 JAN 27 TDB
when PHSRM is visible from the tracking station USSURIYSK. These time intervals are frequently called ``view periods.''

The spacecraft is considered visible if its apparent position (that is, its position corrected for light time and stellar aberration) has elevation of at least 6 degrees in the topocentric reference frame USSURIYSK_TOPO. In this exercise, we ignore the possibility of occultation of the spacecraft by Mars.

Use a search step size that ensures that no view periods of duration 5 minutes or longer will be missed by the search.

Display the start and stop times of these intervals using TDB calendar dates and millisecond precision.



Top

Learning Goals




Exposure to SPICE GF event finding routines. Familiarity with SPICE windows and routines that manipulate them. Exposure to SPICE time parsing and output formatting routines.



Top

Approach






Top

Solution steps



A possible solution could consist of the following steps:

Preparation:

    1. Review the CSPICE cell and window Required Reading.

    2. Decide what SPICE kernels are necessary. Use the SPICE summary tool BRIEF to examine the coverage of the binary kernels and verify the availability of required data.

    3. Create a meta-kernel listing the SPICE kernels to be loaded. (Hint: consult a programming example tutorial, or the Introduction to Kernels tutorial, for a reminder of how to do this.)

    Name the meta-kernel 'viewpr.tm'.

Next, write a program that performs the following steps:

    1. Use furnsh_c to load the meta-kernel.

    2. Declare a CSPICE window ```cnfine''' to hold the time period within which the search is to be conducted, and a CSPICE window `riswin' ("rise/set window") to hold the view periods found by the search.

    3. Insert the given time bounds into the confinement window using wninsd_c.

    4. Select a step size for searching for visibility state transitions: in this case, each target rise or set event is a state transition.

    The step size must be large enough so the search proceeds with reasonable speed, but small enough so that no visibility transition events---that is, target rise or set events---are missed.

    5. Use the GF routine gfposc_c to find the window of times, within the confinement window `cnfine', during which the PHSRM spacecraft is above the elevation limit as seen from tracking station USSURIYSK, in the the reference frame USSURIYSK_TOPO.

    Use light time and stellar aberration corrections for the apparent position of the spacecraft as seen from the station.

    6. Fetch and display the contents of the result window. Use wnfetd_c to extract from the result window the start and stop times of each time interval. Display each of the intervals in the result window as a pair of start and stop times. Express each time as a TDB calendar date using the routine timout_c.

You may find it useful to consult the references listed above. In particular, the header of the SPICE GF function gfposc_c contains pertinent documentation.



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'viewpr.tm'. Its contents follow:

 
   KPL/MK
 
      Example meta-kernel for geometric event finding hands-on
      coding lesson.
 
         Version 1.0.0 21-JUL-2011 (BVS)
 
 
      Identify names of kernels to load:
 
   \begindata
 
      KERNELS_TO_LOAD = (
 
              'kernels/spk/de421xs.bsp'
              'kernels/spk/earthstns_phsrm_itrf93_110118.bsp'
              'kernels/fk/earthstns_phsrm_topo_110118.tf'
              'kernels/pck/earth_070425_370426_predict.bpc'
              'kernels/lsk/naif0009.tls'
              'kernels/spk/phsrm_130114_130114_130214_nom2.bsp'
              'kernels/pck/pck00009.tpc'
              'kernels/fk/phsrm_v00.tf'
                        )
 
   \begintext
 


Top

Solution Code



The example program below shows one possible solution.

 
   #include <string.h>
   #include <stdio.h>
   #include "SpiceUsr.h"
 
      /*
      PROGRAM VIEWPR
 
      Find and display the window of times when the PHSRM
      spacecraft is above a specified elevation limit in the
      topocentric reference frame of tracking station USSURIYSK.
      */
 
   int main()
   {
      /*
      Local constants
      */
 
      /*
      The  meta-kernel:
      */
      #define METAKR          "viewpr.tm"
 
      /*
      Maximum number of intervals in any window:
      */
      #define MAXIVL          1000
 
      /*
      Maximum result window size:
      */
      #define MAXWIN          ( 2 * MAXIVL )
 
      /*
      Format string for time output:
      */
      #define TDBFMT          "YYYY MON DD HR:MN:SC.### (TDB) ::TDB"
 
      /*
      String lengths and other bounds:
      */
      #define LNSIZE          201
      #define TIMLEN          51
 
      /*
      Local variables
      */
 
      /*
      Confinement window used to store interval to be searched:
      */
      SPICEDOUBLE_CELL        ( cnfine, MAXWIN );
 
      /*
      Window to hold sets of times when
      target is above the elevation limit:
      */
      SPICEDOUBLE_CELL        ( riswin, MAXWIN );
 
      SpiceChar             * abcorr;
      SpiceChar             * coord;
      SpiceChar             * crdsys;
      SpiceChar             * obsfrm;
      SpiceChar             * relate;
      SpiceChar             * srfpt;
      SpiceChar             * start;
      SpiceChar             * stop;
      SpiceChar             * target;
      SpiceChar               timstr  [ TIMLEN ];
 
      SpiceDouble             adjust;
      SpiceDouble             elvlim;
      SpiceDouble             etbeg;
      SpiceDouble             etend;
      SpiceDouble             intbeg;
      SpiceDouble             intend;
      SpiceDouble             revlim;
 
      /*
      stepsz is the step size, measured in seconds, used to search
      for times bracketing a state transition.
      */
      SpiceDouble             stepsz;
 
      SpiceInt                i;
      SpiceInt                winsiz;
 
 
      /*
      Load the meta-kernel.
      */
      furnsh_c ( METAKR );
 
      /*
      Assign the inputs for our search.
 
      Since we're interested in the apparent location of the
      target, we use light time and stellar aberration
      corrections. We use the "converged Newtonian" form
      of the light time correction because this choice may
      increase the accuracy of the occultation times we'll
      compute using gfoclt_c.
      */
      srfpt  = "USSURIYSK";
      obsfrm = "USSURIYSK_TOPO";
      target = "PHSRM";
      abcorr = "CN+S";
      start  = "2013 JAN 17 TDB";
      stop   = "2013 JAN 27 TDB";
      elvlim =  6.0;
 
      /*
      The elevation limit above has units of degrees; we convert
      this value to radians for computation using SPICE routines.
      We'll store the equivalent value in radians in REVLIM.
      */
      revlim = rpd_c() * elvlim;
 
      /*
      Since SPICE doesn't directly support the AZ/EL coordinate
      system, we use the equivalent constraint
 
         latitude > REVLIM
 
      in the latitudinal coordinate system, where the reference
      frame is topocentric and is centered at the viewing location.
      */
      crdsys = "LATITUDINAL";
      coord  = "LATITUDE";
      relate = ">";
 
      /*
      The adjustment value only applies to absolute extrema
      searches; simply give it an initial value of zero
      for this inequality search.
      */
      adjust = 0.0;
 
      /*
      STEPSZ is the step size, measured in seconds, used to search
      for times bracketing a state transition. Since we don't expect
      any events of interest to be shorter than five minutes, and
      since the separation between events is well over 5 minutes,
      we'll use this value as our step size. Units are seconds.
      */
      stepsz = 300.0;
 
      /*
      Display a banner for the output report:
      */
      printf ( "\n%s\n\n",
               "Inputs for target visibility search:" );
 
      printf ( "   Target                       = %s\n", target );
      printf ( "   Observation surface location = %s\n", srfpt  );
      printf ( "   Observer's reference frame   = %s\n", obsfrm );
      printf ( "   Elevation limit (degrees)    = %f\n", elvlim );
      printf ( "   Aberration correction        = %s\n", abcorr );
      printf ( "   Step size (seconds)          = %f\n", stepsz );
 
      /*
      Convert the start and stop times to ET.
      */
      str2et_c ( start, &etbeg );
      str2et_c ( stop,  &etend );
 
      /*
      Display the search interval start and stop times
      using the format shown below.
 
         2013 JAN 25 20:15:00.000 (TDB)
 
      */
      timout_c ( etbeg, TDBFMT, TIMLEN, timstr );
      printf ( "   Start time                   = %s\n", timstr  );
 
      timout_c ( etend, TDBFMT, TIMLEN, timstr );
      printf ( "   Stop time                    = %s\n", timstr  );
 
      printf ( "\n" );
 
      /*
      Initialize the "confinement" window with the interval
      over which we'll conduct the search.
      */
      wninsd_c ( etbeg, etend, &cnfine );
 
      /*
      In the call below, the maximum number of window
      intervals gfposc_c can store internally is set to MAXIVL.
 
      Now search for the time period, within our confinement
      window, during which the apparent target has elevation
      at least equal to the elevation limit.
      */
      gfposc_c ( target, obsfrm, abcorr, srfpt,
                 crdsys, coord,  relate, revlim,
                 adjust, stepsz, MAXIVL, &cnfine, &riswin );
 
      /*
      The function wncard_c returns the number of intervals
      in a SPICE window.
      */
      winsiz = wncard_c( &riswin );
 
      if ( winsiz == 0 )
      {
         printf ( "No events were found.\n" );
      }
      else
      {
         /*
         Display the visibility time periods.
         */
         printf ( "Visibility times of %s as seen from %s:"
                  "\n\n",
                  target, srfpt                               );
 
         for (  i = 0;   i < winsiz;   i++  )
         {
            /*
            Fetch the start and stop times of the Ith interval
            from the search result window viswin.
            */
            wnfetd_c ( &riswin, i, &intbeg, &intend );
 
            /*
            Convert the rise time to a TDB calendar string.
            */
            timout_c ( intbeg, TDBFMT, TIMLEN, timstr );
 
            /*
            Write the string to standard output.
            */
            if ( i == 0 )
            {
               printf ( "Visibility or window start time:  %s\n",
                         timstr                                  );
            }
            else
            {
               printf ( "Visibility start time:            %s\n",
                         timstr                                  );
            }
 
            /*
            Convert the set time to a TDB calendar string.
            */
            timout_c ( intend, TDBFMT, TIMLEN, timstr );
 
            /*
            Write the string to standard output.
            */
            if ( i == winsiz-1 )
            {
               printf ( "Visibility or window stop time:   %s\n",
                         timstr                                  );
            }
            else
            {
               printf ( "Visibility stop time:             %s\n",
                         timstr                                  );
            }
 
            printf ( "\n" );
         }
      }
 
      return ( 0 );
   }


Top

Solution Sample Output



Numerical results shown for this example may differ across platforms since the results depend on the SPICE kernels used as input and on the host platform's arithmetic implementation.

After compiling the program, execute it. The output is:

 
   Inputs for target visibility search:
 
      Target                       = PHSRM
      Observation surface location = USSURIYSK
      Observer's reference frame   = USSURIYSK_TOPO
      Elevation limit (degrees)    = 6.000000
      Aberration correction        = CN+S
      Step size (seconds)          = 300.000000
      Start time                   = 2013 JAN 17 00:00:00.000 (TDB)
      Stop time                    = 2013 JAN 27 00:00:00.000 (TDB)
 
   Visibility times of PHSRM as seen from USSURIYSK:
 
   Visibility or window start time:  2013 JAN 17 00:33:31.361 (TDB)
   Visibility stop time:             2013 JAN 17 09:02:45.225 (TDB)
 
   Visibility start time:            2013 JAN 18 00:31:30.565 (TDB)
   Visibility stop time:             2013 JAN 18 09:03:09.674 (TDB)
 
   Visibility start time:            2013 JAN 19 00:29:28.884 (TDB)
   Visibility stop time:             2013 JAN 19 09:03:34.081 (TDB)
 
   Visibility start time:            2013 JAN 20 00:27:26.144 (TDB)
   Visibility stop time:             2013 JAN 20 09:03:58.190 (TDB)
 
   Visibility start time:            2013 JAN 21 00:25:22.338 (TDB)
   Visibility stop time:             2013 JAN 21 09:04:21.910 (TDB)
 
   Visibility start time:            2013 JAN 22 00:23:17.607 (TDB)
   Visibility stop time:             2013 JAN 22 09:04:45.379 (TDB)
 
   Visibility start time:            2013 JAN 23 00:21:12.160 (TDB)
   Visibility stop time:             2013 JAN 23 09:05:08.811 (TDB)
 
   Visibility start time:            2013 JAN 24 00:19:06.175 (TDB)
   Visibility stop time:             2013 JAN 24 09:05:32.377 (TDB)
 
   Visibility start time:            2013 JAN 25 00:16:59.683 (TDB)
   Visibility stop time:             2013 JAN 25 09:05:56.090 (TDB)
 
   Visibility start time:            2013 JAN 26 00:14:52.583 (TDB)
   Visibility or window stop time:   2013 JAN 26 09:06:19.734 (TDB)
 


Top

Find Times when Target is Visible







Top

Task Statement




Extend the program of the previous chapter to find times when the PHSRM orbiter is:

    -- Above the elevation limit in the USSURIYSK_TOPO topocentric reference frame.

    -- and is not occulted by Mars

Store the set of time intervals when the spacecraft is visible in a CSPICE window. We'll call this the ``result window.''

Display each of the intervals in the result window as a pair of start and stop times. Express each time as a TDB calendar date using the same format as in the previous program.



Top

Learning Goals




Familiarity with the GF occultation finding routine gfoclt_c. Further experience with the CSPICE window functions.



Top

Approach






Top

Solution steps



A possible solution would consist of the following steps:

    1. Use the meta-kernel of the previous lesson.

    2. Include the code from the program of the previous chapter in a new source file; modify this code to create the new program.

    3. Declare a CSPICE window `occwin' to hold the results of the occultation search. Also declare a second CSPICE window `viswin' to hold the final result.

    4. Search for occultations of the PHSRM orbiter as seen from USSURIYSK using gfoclt_c. Use as the confinement window for this search the result window from the elevation search performed by gfposc_c.

    Since occultations occur when the apparent PHSRM spacecraft position is behind the apparent figure of Mars, light time correction must be performed for the occultation search. To improve accuracy of the occultation state determination, use ``converged Newtonian'' light time correction.

    5. Use the CSPICE window subtraction routine wndifd_c to subtract the window of times when the spacecraft is occulted from the window of times when the spacecraft is above the elevation limit. The difference window `viswin' is the final result.

    6. Modify the code to display the contents of the window `viswin'.

This completes the assignment.



Top

Solution






Top

Solution Code



 
   #include <string.h>
   #include <stdio.h>
   #include "SpiceUsr.h"
 
      /*
      PROGRAM VISIBL
 
      Find and display the window of times when the PHSRM
      spacecraft is above a specified elevation limit in the
      topocentric reference frame of tracking station USSURIYSK
      and is not occulted by Mars.
      */
 
   int main()
   {
      /*
      Local constants
      */
 
      /*
      The  meta-kernel:
      */
      #define METAKR          "viewpr.tm"
 
      /*
      Maximum number of intervals in any window:
      */
      #define MAXIVL          1000
 
      /*
      Maximum result window size:
      */
      #define MAXWIN          ( 2 * MAXIVL )
 
      /*
      Format string for time output:
      */
      #define TDBFMT          "YYYY MON DD HR:MN:SC.### (TDB) ::TDB"
 
      /*
      String lengths and other bounds:
      */
      #define TIMLEN          51
 
      /*
      Local variables
      */
 
      /*
      Confinement window used to store interval to be searched:
      */
      SPICEDOUBLE_CELL        ( cnfine, MAXWIN );
 
      /*
      Windows to hold sets of times when
 
         - target is occulted
         - target is above the elevation limit
         - target is visible
      */
      SPICEDOUBLE_CELL        ( occwin, MAXWIN );
      SPICEDOUBLE_CELL        ( riswin, MAXWIN );
      SPICEDOUBLE_CELL        ( viswin, MAXWIN );
 
      SpiceChar             * abcorr;
      SpiceChar             * back;
      SpiceChar             * bframe;
      SpiceChar             * bshape;
      SpiceChar             * coord;
      SpiceChar             * crdsys;
      SpiceChar             * fframe;
      SpiceChar             * front;
      SpiceChar             * fshape;
      SpiceChar             * obsfrm;
      SpiceChar             * occtyp;
      SpiceChar             * relate;
      SpiceChar             * srfpt;
      SpiceChar             * start;
      SpiceChar             * stop;
      SpiceChar             * target;
      SpiceChar               timstr  [ TIMLEN ];
 
      SpiceDouble             adjust;
      SpiceDouble             elvlim;
      SpiceDouble             etbeg;
      SpiceDouble             etend;
      SpiceDouble             intbeg;
      SpiceDouble             intend;
      SpiceDouble             revlim;
 
      /*
      stepsz is the step size, measured in seconds, used to search
      for times bracketing a state transition.
      */
      SpiceDouble             stepsz;
 
      SpiceInt                i;
      SpiceInt                winsiz;
 
 
      /*
      Load the meta-kernel.
      */
      furnsh_c ( METAKR );
 
      /*
      Assign the inputs for our search.
 
      Since we're interested in the apparent location of the
      target, we use light time and stellar aberration
      corrections. We use the "converged Newtonian" form
      of the light time correction because this choice may
      increase the accuracy of the occultation times we'll
      compute using gfoclt_c.
      */
      srfpt  = "USSURIYSK";
      obsfrm = "USSURIYSK_TOPO";
      target = "PHSRM";
      abcorr = "CN+S";
      start  = "2013 JAN 17 TDB";
      stop   = "2013 JAN 27 TDB";
      elvlim =  6.0;
 
      /*
      The elevation limit above has units of degrees; we convert
      this value to radians for computation using SPICE routines.
      We'll store the equivalent value in radians in REVLIM.
      */
      revlim = rpd_c() * elvlim;
 
      /*
      We model the target shape as a point and the blocking body's
      shape as an ellipsoid. No body-fixed reference frame is
      required for the target since its orientation is not used.
      */
      back   = target;
      bshape = "POINT";
      bframe = " ";
      front  = "MARS";
      fshape = "ELLIPSOID";
      fframe = "IAU_MARS";
 
      /*
      The occultation type should be set to "ANY" for a point
      target.
      */
      occtyp = "any";
 
      /*
      Since SPICE doesn't directly support the AZ/EL coordinate
      system, we use the equivalent constraint
 
         latitude > REVLIM
 
      in the latitudinal coordinate system, where the reference
      frame is topocentric and is centered at the viewing location.
      */
      crdsys = "LATITUDINAL";
      coord  = "LATITUDE";
      relate = ">";
 
      /*
      The adjustment value only applies to absolute extrema
      searches; simply give it an initial value of zero
      for this inequality search.
      */
      adjust = 0.0;
 
      /*
      STEPSZ is the step size, measured in seconds, used to search
      for times bracketing a state transition. Since we don't expect
      any events of interest to be shorter than five minutes, and
      since the separation between events is well over 5 minutes,
      we'll use this value as our step size. Units are seconds.
      */
      stepsz = 300.0;
 
      /*
      Display a banner for the output report:
      */
      printf ( "\n%s\n\n",
               "Inputs for target visibility search:" );
 
      printf ( "   Target                       = %s\n", target );
      printf ( "   Observation surface location = %s\n", srfpt  );
      printf ( "   Observer's reference frame   = %s\n", obsfrm );
      printf ( "   Blocking body                = %s\n", front  );
      printf ( "   Blocker's reference frame    = %s\n", fframe );
      printf ( "   Elevation limit (degrees)    = %f\n", elvlim );
      printf ( "   Aberration correction        = %s\n", abcorr );
      printf ( "   Step size (seconds)          = %f\n", stepsz );
 
      /*
      Convert the start and stop times to ET.
      */
      str2et_c ( start, &etbeg );
      str2et_c ( stop,  &etend );
 
      /*
      Display the search interval start and stop times
      using the format shown below.
 
         2013 JAN 25 20:15:00.000 (TDB)
      */
      timout_c ( etbeg, TDBFMT, TIMLEN, timstr );
      printf ( "   Start time                   = %s\n", timstr  );
 
      timout_c ( etend, TDBFMT, TIMLEN, timstr );
      printf ( "   Stop time                    = %s\n", timstr  );
 
      printf ( "\n" );
 
      /*
      Initialize the "confinement" window with the interval
      over which we'll conduct the search.
      */
      wninsd_c ( etbeg, etend, &cnfine );
 
      /*
      In the call below, the maximum number of window
      intervals gfposc_c can store internally is set to MAXIVL.
 
      Now search for the time period, within our confinement
      window, during which the apparent target has elevation
      at least equal to the elevation limit.
      */
      gfposc_c ( target, obsfrm, abcorr, srfpt,
                 crdsys, coord,  relate, revlim,
                 adjust, stepsz, MAXIVL, &cnfine, &riswin );
 
      /*
      Now find the times when the apparent target is above
      the elevation limit and is not occulted by the
      blocking body (Mars). We'll find the window of times when
      the target is above the elevation limit and *is* occulted,
      then subtract that window from the view period window
      riswin found above.
 
      For this occultation search, we can use riswin as
      the confinement window because we're not interested in
      occultations that occur when the target is below the
      elevation limit.
 
      Find occultations within the view period window.
      */
      gfoclt_c ( occtyp, front,  fshape,  fframe,
                 back,   bshape, bframe,  abcorr,
                 srfpt,  stepsz, &riswin, &occwin );
 
      /*
      Subtract the occultation window from the view period
      window: this yields the time periods when the target
      is visible.
      */
      wndifd_c ( &riswin, &occwin, &viswin );
 
      /*
      The function wncard_c returns the number of intervals
      in a SPICE window.
      */
      winsiz = wncard_c( &viswin );
 
      if ( winsiz == 0 )
      {
         printf ( "No events were found.\n" );
      }
      else
      {
         /*
         Display the visibility time periods.
         */
         printf ( "Visibility times of %s as seen from %s:"
                  "\n\n",
                  target, srfpt                               );
 
         for (  i = 0;   i < winsiz;   i++  )
         {
            /*
            Fetch the start and stop times of the Ith interval
            from the search result window viswin.
            */
            wnfetd_c ( &viswin, i, &intbeg, &intend );
 
            /*
            Convert the rise time to a TDB calendar string.
            */
            timout_c ( intbeg, TDBFMT, TIMLEN, timstr );
 
            /*
            Write the string to standard output.
            */
            if ( i == 0 )
            {
               printf ( "Visibility or window start time:  %s\n",
                         timstr                                  );
            }
            else
            {
               printf ( "Visibility start time:            %s\n",
                         timstr                                  );
            }
 
            /*
            Convert the set time to a TDB calendar string.
            */
            timout_c ( intend, TDBFMT, TIMLEN, timstr );
 
            /*
            Write the string to standard output.
            */
            if ( i == winsiz-1 )
            {
               printf ( "Visibility or window stop time:   %s\n",
                         timstr                                  );
            }
            else
            {
               printf ( "Visibility stop time:             %s\n",
                         timstr                                  );
            }
 
            printf ( "\n" );
         }
      }
 
      return ( 0 );
   }


Top

Solution Sample Output



Numerical results shown for this example may differ across platforms since the results depend on the SPICE kernels used as input and on the host platform's arithmetic implementation.

After compiling the program, execute it. The output is:

 
   Inputs for target visibility search:
 
      Target                       = PHSRM
      Observation surface location = USSURIYSK
      Observer's reference frame   = USSURIYSK_TOPO
      Blocking body                = MARS
      Blocker's reference frame    = IAU_MARS
      Elevation limit (degrees)    = 6.000000
      Aberration correction        = CN+S
      Step size (seconds)          = 300.000000
      Start time                   = 2013 JAN 17 00:00:00.000 (TDB)
      Stop time                    = 2013 JAN 27 00:00:00.000 (TDB)
 
   Visibility times of PHSRM as seen from USSURIYSK:
 
   Visibility or window start time:  2013 JAN 17 00:33:31.361 (TDB)
   Visibility stop time:             2013 JAN 17 01:47:16.462 (TDB)
 
   Visibility start time:            2013 JAN 17 02:07:19.374 (TDB)
   Visibility stop time:             2013 JAN 17 09:02:45.225 (TDB)
 
   Visibility start time:            2013 JAN 18 00:31:30.565 (TDB)
   Visibility stop time:             2013 JAN 18 00:47:36.315 (TDB)
 
   Visibility start time:            2013 JAN 18 01:05:44.180 (TDB)
   Visibility stop time:             2013 JAN 18 08:26:58.267 (TDB)
 
   Visibility start time:            2013 JAN 18 08:45:15.036 (TDB)
   Visibility stop time:             2013 JAN 18 09:03:09.674 (TDB)
 
   Visibility start time:            2013 JAN 19 00:29:28.884 (TDB)
   Visibility stop time:             2013 JAN 19 07:26:28.944 (TDB)
 
   Visibility start time:            2013 JAN 19 07:42:20.612 (TDB)
   Visibility stop time:             2013 JAN 19 09:03:34.081 (TDB)
 
   Visibility start time:            2013 JAN 20 00:27:26.144 (TDB)
   Visibility stop time:             2013 JAN 20 06:25:05.813 (TDB)
 
   Visibility start time:            2013 JAN 20 06:40:32.764 (TDB)
   Visibility stop time:             2013 JAN 20 09:03:58.190 (TDB)
 
   Visibility start time:            2013 JAN 21 00:25:22.338 (TDB)
   Visibility stop time:             2013 JAN 21 05:25:49.659 (TDB)
 
   Visibility start time:            2013 JAN 21 05:38:51.869 (TDB)
   Visibility stop time:             2013 JAN 21 09:04:21.910 (TDB)
 
   Visibility start time:            2013 JAN 22 00:23:17.607 (TDB)
   Visibility stop time:             2013 JAN 22 04:24:38.313 (TDB)
 
   Visibility start time:            2013 JAN 22 04:35:28.127 (TDB)
   Visibility stop time:             2013 JAN 22 09:04:45.379 (TDB)
 
   Visibility start time:            2013 JAN 23 00:21:12.160 (TDB)
   Visibility stop time:             2013 JAN 23 03:24:26.753 (TDB)
 
   Visibility start time:            2013 JAN 23 03:34:27.263 (TDB)
   Visibility stop time:             2013 JAN 23 09:05:08.811 (TDB)
 
   Visibility start time:            2013 JAN 24 00:19:06.175 (TDB)
   Visibility stop time:             2013 JAN 24 02:26:30.810 (TDB)
 
   Visibility start time:            2013 JAN 24 02:29:39.646 (TDB)
   Visibility stop time:             2013 JAN 24 09:05:32.377 (TDB)
 
   Visibility start time:            2013 JAN 25 00:16:59.683 (TDB)
   Visibility stop time:             2013 JAN 25 09:05:56.090 (TDB)
 
   Visibility start time:            2013 JAN 26 00:14:52.583 (TDB)
   Visibility or window stop time:   2013 JAN 26 09:06:19.734 (TDB)