 
Remote Sensing Hands-On Lesson (FORTRAN)
===========================================================================
 
   September 2, 2016
 
 
Overview
--------------------------------------------------------
 
   In this lesson you will develop a series of simple programs that
   demonstrate the usage of SPICE to compute a variety of different
   geometric quantities applicable to experiments carried out by a remote
   sensing instrument flown on an interplanetary spacecraft. This
   particular lesson focuses on a spectrometer flying on the ExoMars-16 TGO
   spacecraft, but many of the concepts are easily extended and generalized
   to other scenarios.
 
 
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 Toolkit tree and
   copy this document to that subdirectory before loading it into a Web
   browser.
 
 
References
--------------------------------------------------------
 
 
Tutorials
 
   The following SPICE tutorials are referred to by the discussions in this
   lesson:
 
      Name             Lesson steps/routines 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
      CK               Spacecraft Orientation Data
 
   These tutorials are available from the NAIF ftp server at JPL:
 
      http://naif.jpl.nasa.gov/naif/tutorials.html
 
 
Required Readings
 
   The Required Reading documents are provided with the Toolkit and are
   located under the ``toolkit/doc'' directory in the FORTRAN installation
   tree.
 
      Name             Lesson steps/routines that it describes
      ---------------  -----------------------------------------
      time.req         Time Conversion
      sclk.req         SCLK Time Conversion
      spk.req          Obtaining Ephemeris Data
      frames.req       Using Reference Frames
      pck.req          Obtaining Planetary Constants Data
      ck.req           Obtaining Spacecraft Orientation Data
      naif_ids.req     Determining Body ID Codes
 
 
The Permuted Index
 
   Another useful document distributed with the Toolkit is the permuted
   index. This is located under the ``toolkit/doc'' directory in the
   FORTRAN installation tree.
 
   This text document provides a simple mechanism to discover what SPICE
   routines perform a particular function of interest as well as the name
   of the source module that contains the routine. This is particularly
   useful for FORTRAN programmers because some of the routines are entry
   points and, therefore, the name does not translate directly into the
   name of the source module that contains them.
 
 
Source Code Header Comments
 
   The most detailed specification of a given SPICE FORTRAN or C routine is
   contained in the header section of its source code. The source code is
   distributed with the Toolkit and is located under
   ``toolkit/src/spicelib'' in FORTRAN and under ``cspice/src/cspice'' in C
   Toolkits.
 
   For example the source code of the STR2ET/str2et_c routine is
 
      toolkit/src/spicelib/str2et.for
 
   in the FORTRAN Toolkit and in
 
      cspice/src/cspice/str2et_c.c
 
   in the C Toolkit.
 
   Since some of the FORTRAN routines are entry points they are usually
   part of a source file that has different name. The ``Permuted Index''
   document mentioned above can be used to locate the name of their source
   file.
 
 
Kernels Used
--------------------------------------------------------
 
   The following kernels are used in examples provided in this lesson:
 
      1.  Generic LSK:
 
             naif0012.tls
 
      2.  ExoMars-16 TGO SCLK:
 
             em16_tgo_step_20160414.tsc
 
      3.  Solar System Ephemeris SPK, subsetted to cover only the time
          range of interest:
 
             de430.bsp
 
      4.  Martian Satellite Ephemeris SPK, subsetted to cover only the
          time range of interest:
 
             mar085.bsp
 
      5.  ExoMars-16 TGO Spacecraft Trajectory SPK, subsetted to cover
          only the time range of interest:
 
             em16_tgo_mlt_20171205_20230115_v01.bsp
 
      6.  ExoMars-16 TGO FK:
 
             em16_tgo_v07.tf
 
      7.  ExoMars-16 TGO Spacecraft CK, subsetted to cover only the time
          range of interest::
 
             em16_tgo_sc_slt_npo_20171205_20230115_s20160414_v01.bc
 
      8.  Generic PCK:
 
             pck00010.tpc
 
      9.  NOMAD IK:
 
             em16_tgo_nomad_v02.ti
 
   These SPICE kernels are included in the lesson package available from
   the NAIF server at JPL:
 
      ftp://naif.jpl.nasa.gov/pub/naif/toolkit_docs/Lessons/
 
 
SPICE Modules Used
--------------------------------------------------------
 
   This section provides a complete summary of the routines, and the
   kernels 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.)
 
      CHAPTER EXERCISE   ROUTINES   FUNCTIONS  KERNELS
      ------- ---------  ---------  ---------  ---------
        1     convtm     FURNSH                1,2
                         PROMPT
                         STR2ET
                         ETCAL
                         TIMOUT
                         SCE2S
 
        2     getsta     FURNSH     VNORM      1,3-6
                         PROMPT
                         STR2ET
                         SPKEZR
                         SPKPOS
                         CONVRT
 
        3     xform      FURNSH     VSEP       1-8
                         PROMPT
                         STR2ET
                         SPKEZR
                         SXFORM
                         MXVG
                         SPKPOS
                         PXFORM
                         MXV
                         CONVRT
 
        4     subpts     FURNSH                1,3-6,8
                         PROMPT
                         STR2ET
                         SUBPT
                         SUBSOL
 
        5     fovint     FURNSH     DPR        1-9
                         PROMPT
                         STR2ET
                         BODN2C
                         BYEBYE
                         GETFOV
                         SINCPT
                         RECLAT
                         ILUMIN
                         ET2LST
 
   Refer to the headers of the various routines listed above, as detailed
   interface specifications are provided with the source code.
 
 
Time Conversion (convtm)
===========================================================================
 
 
Task Statement
--------------------------------------------------------
 
   Write a program that prompts the user for an input UTC time string,
   converts it to the following time systems and output formats:
 
       1.   Ephemeris Time (ET) in seconds past J2000
 
       2.   Calendar Ephemeris Time
 
       3.   Spacecraft Clock Time
 
   and displays the results. Use the program to convert "2018 jun 11
   19:32:00" UTC into these alternate systems.
 
 
Learning Goals
--------------------------------------------------------
 
   Familiarity with the various time conversion and parsing routines
   available in the Toolkit. Exposure to source code headers and their
   usage in learning to call routines.
 
 
Approach
--------------------------------------------------------
 
   The solution to the problem can be broken down into a series of simple
   steps:
 
       --   Decide which SPICE kernels are necessary. Prepare a meta-kernel
            listing the kernels and load it into the program.
 
       --   Prompt the user for an input UTC time string.
 
       --   Convert the input time string into ephemeris time expressed as
            seconds past J2000 TDB. Display the result.
 
       --   Convert ephemeris time into a calendar format. Display the
            result.
 
       --   Convert ephemeris time into a spacecraft clock string. Display
            the result.
 
   You may find it useful to consult the permuted index, the headers of
   various source modules, and the ``Time Required Reading'' (time.req) and
   ``SCLK Required Reading'' (sclk.req) documents.
 
   When completing the ``calendar format'' step above, consider using one
   of two possible methods: ETCAL or TIMOUT.
 
 
Solution
--------------------------------------------------------
 
 
Solution Meta-Kernel
 
   The meta-kernel we created for the solution to this exercise is named
   'convtm.tm'. Its contents follow:
 
      KPL/MK
 
         This is the meta-kernel used in the solution of the ``Time
         Conversion'' task in the Remote Sensing Hands On Lesson.
 
      \begindata
 
       KERNELS_TO_LOAD = (
 
       'kernels/lsk/naif0012.tls',
       'kernels/sclk/em16_tgo_step_20160414.tsc'
 
                         )
 
      \begintext
 
 
 
Solution Source Code
 
   A sample solution to the problem follows:
 
            PROGRAM CONVTM
 
            IMPLICIT NONE
 
      C
      C     Local Parameters
      C
      C     The name of the meta-kernel that lists the kernels
      C     to load into the program.
      C
            CHARACTER*(*)         METAKR
            PARAMETER           ( METAKR = 'convtm.tm' )
 
      C
      C     The spacecraft clock ID code for ExoMars-16 TGO.
      C
            INTEGER               SCLKID
            PARAMETER           ( SCLKID = -143 )
 
      C
      C     The length of various string variables.
      C
            INTEGER               STRLEN
            PARAMETER           ( STRLEN = 50 )
 
      C
      C     Local Variables
      C
            CHARACTER*(STRLEN)    CALET
            CHARACTER*(STRLEN)    SCLKST
            CHARACTER*(STRLEN)    UTCTIM
 
            DOUBLE PRECISION      ET
 
      C
      C     Load the kernels this program requires.
      C     Both the spacecraft clock kernel and a
      C     leapseconds kernel should be listed
      C     in the meta-kernel.
      C
            CALL FURNSH ( METAKR )
 
      C
      C     Prompt the user for the input time string.
      C
            CALL PROMPT ( 'Input UTC Time: ', UTCTIM )
 
            WRITE (*,*) 'Converting UTC Time: ', UTCTIM
 
      C
      C     Convert UTCTIM to ET.
      C
            CALL STR2ET ( UTCTIM, ET )
 
            WRITE (*,'(A,F16.3)') '   ET Seconds Past J2000: ', ET
 
      C
      C     Now convert ET to a formal calendar time
      C     string.  This can be accomplished in two
      C     ways.
      C
            CALL ETCAL ( ET, CALET )
 
            WRITE (*,*) '   Calendar ET (ETCAL): ', CALET
 
      C
      C     Or use TIMOUT for finer control over the
      C     output format.  The picture below was built
      C     by examining the header of TIMOUT.
      C
            CALL TIMOUT ( ET, 'YYYY-MON-DDTHR:MN:SC ::TDB', CALET )
 
            WRITE (*,*) '   Calendar ET (TIMOUT): ', CALET
 
      C
      C     Convert ET to spacecraft clock time.
      C
            CALL SCE2S ( SCLKID, ET, SCLKST )
 
            WRITE (*,*) '   Spacecraft Clock Time: ', SCLKST
 
            END
 
 
Solution Sample Output
 
   After compiling the program, execute it:
 
      Converting UTC Time: 2018 JUN 11 19:32:00
         ET Seconds Past J2000:    582017589.185
         Calendar ET (ETCAL): 2018 JUN 11 19:33:09.184
         Calendar ET (TIMOUT): 2018-JUN-11T19:33:09
         Spacecraft Clock Time: 1/0070841719.26698
 
 
Extra Credit
--------------------------------------------------------
 
   In this ``extra credit'' section you will be presented with more complex
   tasks, aimed at improving your understanding of time conversions, the
   Toolkit routines that deal with them, and some common errors that may
   happen during the execution of these conversions.
 
   These ``extra credit'' tasks are provided as task statements, and unlike
   the regular tasks, no approach or solution source code is provided. In
   the next section, you will find the numeric solutions (when applicable)
   and answers to the questions asked in these tasks.
 
 
Task statements and questions
 
       1.   Extend your program to convert the input UTC time string to TDB
            Julian Date. Convert "2018 jun 11 19:32:00" UTC.
 
       2.   Remove the LSK from the original meta-kernel and run your
            program again, using the same inputs as before. Has anything
            changed? Why?
 
       3.   Remove the SCLK from the original meta-kernel and run your
            program again, using the same inputs as before. Has anything
            changed? Why?
 
       4.   Modify your program to perform conversion of UTC or ephemeris
            time, to a spacecraft clock string using the NAIF ID for the
            ExoMars-16 TGO NOMAD LNO Nadir aperture. Convert "2018 jun 11
            19:32:00" UTC.
 
       5.   Find the earliest UTC time that can be converted to ExoMars-16
            TGO spacecraft clock.
 
       6.   Extend your program to convert the spacecraft clock time
            obtained in the regular task back to UTC Time and present it in
            ISO calendar date format, with a resolution of milliseconds.
 
       7.   Examine the contents of the generic LSK and the ExoMars-16 TGO
            SCLK kernels. Can you understand and explain what you see?
 
 
Solutions and answers
 
       1.   Two methods exist in order to convert ephemeris time to Julian
            Date: UNITIM and TIMOUT. The difference between them is the
            type of output produced by each method. UNITIM returns the
            double precision value of an input epoch, while TIMOUT returns
            the string representation of the ephemeris time in Julian Date
            format (when picture input is set to 'JULIAND.#########
            ::TDB'). Refer to the routine header for further details. The
            solution for the requested input UTC string is:
 
            Julian Date TDB: 2458281.3146896
 
       2.   When running the original program without the LSK kernel, an
            error is produced: SPICE(NOLEAPSECONDS). This error is
            triggered by STR2ET because the variable that points to the
            leapseconds is not present in the kernel pool and therefore
            there is not enough data to perform the requested UTC to
            ephemeris time conversion.
 
            By default, SPICE will report, as a minimum, a short
            descriptive message -- in this case SPICE(NOLEAPSECONDS) -- and
            a expanded form of this short message where more details about
            the error are provided. If this error message is not sufficient
            for you to understand what has happened, you could go to the
            ``Exceptions'' section in the SPICELIB or CSPICE headers of the
            routine that has triggered the error and find out more
            information about the possible causes.
 
       3.   When running the original program without the SCLK kernel, an
            error is produced by SCE2S: SPICE(KERNELVARNOTFOUND), which in
            this case may not give you enough information to understand
            what has actually happened. Nevertheless, the expanded form of
            this short message clearly indicates that the SCLK kernel for
            the spacecraft ID -143 has not been loaded.
 
            The UTC string to ephemeris time conversion and the conversion
            of ephemeris time into a calendar format worked normally as
            these conversions only require the LSK kernel to be loaded.
 
       4.   The first thing you need to do is to find out what the NAIF ID
            is for the NOMAD LNO Nadir aperture. In order to do so, examine
            the ExoMars-16 TGO frames definitions kernel listed above and
            look for the ``TGO NAIF ID Codes -- Summary Section'' or for
            the ``TGO NAIF ID Codes -- Definitions'' and there, for the
            NAIF ID given to TGO_NOMAD_LNO_NAD (which is -143311). Then
            replace in your code the SCLK ID -143 with -143311. After
            compiling and executing the program using the original
            meta-kernel, you will be getting the same error as in the
            previous task. Despite the error being exactly the same, this
            case is different. Generally, spacecraft clocks are associated
            with the spacecraft ID and not with its payload, sensors or
            structures IDs. Therefore, in order to do conversions from/to
            spacecraft clock for payload, sensors or spacecraft structures,
            the spacecraft ID must be used.
 
            Note that this does not need to be true for all missions or
            payloads, as SPICE does not restrict the SCLKs to spacecraft
            IDs only. Please refer to your mission's SCLK kernels for
            particulars.
 
       5.   Use SCS2E with the input SCLK string set to ``0.0'' and convert
            the resulting ephemeris time to UTC using either TIMOUT or
            ET2UTC. The solution for the requested SCLK string is:
 
            Earliest UTC convertible to SCLK: 2016-03-13T21:34:13.194
 
       6.   Use SCS2E with the SCLK string obtained in the computations
            performed in the regular tasks (1/0070841719.26698) and convert
            the resulting ephemeris time to UTC using either ET2UTC, with
            'ISOC' format and 3 digits precision, or using TIMOUT using the
            time picture 'YYYY-MM-DDTHR:MN:SC.### ::RND'. The solution of
            the requested conversion is:
 
            UTC time from spacecraft clock: 2018-06-11T19:32:00.000
 
 
Obtaining Target States and Positions (getsta)
===========================================================================
 
 
Task Statement
--------------------------------------------------------
 
   Write a program that prompts the user for an input UTC time string,
   computes the following quantities at that epoch:
 
       1.   The apparent state of Mars as seen from ExoMars-16 TGO in the
            J2000 frame, in kilometers and kilometers/second. This vector
            itself is not of any particular interest, but it is a useful
            intermediate quantity in some geometry calculations.
 
       2.   The apparent position of the Earth as seen from ExoMars-16 TGO
            in the J2000 frame, in kilometers.
 
       3.   The one-way light time between ExoMars-16 TGO and the apparent
            position of Earth, in seconds.
 
       4.   The apparent position of the Sun as seen from Mars in the J2000
            frame (J2000), in kilometers.
 
       5.   The actual (geometric) distance between the Sun and Mars, in
            astronomical units.
 
   and displays the results. Use the program to compute these quantities at
   "2018 jun 11 19:32:00" UTC.
 
 
Learning Goals
--------------------------------------------------------
 
   Understand the anatomy of an SPKEZR call. Discover the difference
   between SPKEZR and SPKPOS. Familiarity with the Toolkit utility
   ``brief''. Exposure to unit conversion with SPICE.
 
 
Approach
--------------------------------------------------------
 
   The solution to the problem can be broken down into a series of simple
   steps:
 
       --   Decide which SPICE kernels are necessary. Prepare a meta-kernel
            listing the kernels and load it into the program.
 
       --   Prompt the user for an input time string.
 
       --   Convert the input time string into ephemeris time expressed as
            seconds past J2000 TDB.
 
       --   Compute the state of Mars relative to ExoMars-16 TGO in the
            J2000 reference frame, corrected for aberrations.
 
       --   Compute the position of Earth relative to ExoMars-16 TGO in the
            J2000 reference frame, corrected for aberrations. (The routine
            in the library that computes this also returns the one-way
            light time between ExoMars-16 TGO and Earth.)
 
       --   Compute the position of the Sun relative to Mars in the J2000
            reference frame, corrected for aberrations.
 
       --   Compute the position of the Sun relative to Mars without
            correcting for aberration.
 
       --   Compute the length of this vector. This provides the desired
            distance in kilometers.
 
       --   Convert the distance in kilometers into AU.
 
   You may find it useful to consult the permuted index, the headers of
   various source modules, and the ``SPK Required Reading'' (spk.req)
   document.
 
   When deciding which SPK files to load, the Toolkit utility ``brief'' may
   be of some use.
 
   ``brief'' is located in the ``toolkit/exe'' directory for FORTRAN
   toolkits. Consult its user's guide available in ``toolkit/doc/brief.ug''
   for details.
 
 
Solution
--------------------------------------------------------
 
 
Solution Meta-Kernel
 
   The meta-kernel we created for the solution to this exercise is named
   'getsta.tm'. Its contents follow:
 
      KPL/MK
 
         This is the meta-kernel used in the solution of the
         ``Obtaining Target States and Positions'' task in the
         Remote Sensing Hands On Lesson.
 
      \begindata
 
       KERNELS_TO_LOAD = (
 
       'kernels/lsk/naif0012.tls',
       'kernels/spk/de430.bsp',
       'kernels/spk/mar085.bsp',
       'kernels/spk/em16_tgo_mlt_20171205_20230115_v01.bsp',
       'kernels/fk/em16_tgo_v07.tf'
 
                           )
 
      \begintext
 
 
Solution Source Code
 
   A sample solution to the problem follows:
 
            PROGRAM GETSTA
 
            IMPLICIT NONE
 
      C
      C     SPICELIB Functions
      C
            DOUBLE PRECISION      VNORM
 
      C
      C     Local Parameters
      C
      C
      C     The name of the meta-kernel that lists the kernels
      C     to load into the program.
      C
            CHARACTER*(*)         METAKR
            PARAMETER           ( METAKR = 'getsta.tm' )
 
      C
      C     The length of various string variables.
      C
            INTEGER               STRLEN
            PARAMETER           ( STRLEN = 50 )
 
      C
      C     Local Variables
      C
            CHARACTER*(STRLEN)    UTCTIM
 
            DOUBLE PRECISION      DIST
            DOUBLE PRECISION      ET
            DOUBLE PRECISION      LTIME
            DOUBLE PRECISION      POS   ( 3 )
            DOUBLE PRECISION      STATE ( 6 )
 
      C
      C     Load the kernels that this program requires.  We
      C     will need a leapseconds kernel to convert input
      C     UTC time strings into ET.  We also will need the
      C     necessary SPK files with coverage for the bodies
      C     in which we are interested.
      C
      C     Since the SPICE body/ID mapping for TGO is not
      C     yet included in the standard library, we will
      C     need the frame kernel where the mapping is
      C     defined.
      C
            CALL FURNSH ( METAKR )
 
      C
      C     Prompt the user for the input time string.
      C
            CALL PROMPT ( 'Input UTC Time: ', UTCTIM )
 
            WRITE (*,*) 'Converting UTC Time: ', UTCTIM
 
      C
      C     Convert UTCTIM to ET.
      C
            CALL STR2ET ( UTCTIM, ET )
 
            WRITE (*,'(A,F16.3)') '   ET seconds past J2000: ', ET
 
      C
      C     Compute the apparent state of Mars as seen from
      C     ExoMars-16 TGO in the J2000 frame.  All of the ephemeris
      C     readers return states in units of kilometers and
      C     kilometers per second.
      C
            CALL SPKEZR ( 'MARS', ET,    'J2000', 'LT+S',
           .              'TGO',  STATE, LTIME               )
 
            WRITE (*,*) '   Apparent state of Mars as seen from '
           .//          'ExoMars-16 TGO in the J2000'
            WRITE (*,*) '      frame (km, km/s):'
 
            WRITE (*,'(A,F16.3)') '      X = ', STATE(1)
            WRITE (*,'(A,F16.3)') '      Y = ', STATE(2)
            WRITE (*,'(A,F16.3)') '      Z = ', STATE(3)
            WRITE (*,'(A,F16.3)') '     VX = ', STATE(4)
            WRITE (*,'(A,F16.3)') '     VY = ', STATE(5)
            WRITE (*,'(A,F16.3)') '     VZ = ', STATE(6)
 
      C
      C     Compute the apparent position of Earth as seen from
      C     ExoMars-16 TGO in the J2000 frame.  Note: We could have
      C     continued using SPKEZR and simply ignored the velocity
      C     components.
      C
            CALL SPKPOS ( 'EARTH', ET,  'J2000', 'LT+S',
           .              'TGO',   POS, LTIME               )
 
            WRITE (*,*) '   Apparent position of Earth as seen from '
           .//          'ExoMars-16 TGO in the'
            WRITE (*,*) '      J2000 frame (km):'
 
            WRITE (*,'(A,F16.3)') '      X = ', POS(1)
            WRITE (*,'(A,F16.3)') '      Y = ', POS(2)
            WRITE (*,'(A,F16.3)') '      Z = ', POS(3)
 
      C
      C     We need only display LTIME, as it is precisely the light
      C     time in which we are interested.
      C
            WRITE (*,*) '   One way light time between ExoMars-16 TGO '
           .//          'and the apparent'
            WRITE (*,'(A,F16.3)') '      position of Earth '
           .//          '(seconds): ', LTIME
 
      C
      C     Compute the apparent position of the Sun as seen from
      C     Mars in the J2000 frame.
      C
            CALL SPKPOS ( 'SUN',  ET,  'J2000', 'LT+S',
           .              'MARS', POS, LTIME                    )
 
            WRITE (*,*) '   Apparent position of Sun as seen from '
           .//          'Mars in the'
            WRITE (*,*) '      J2000 frame (km):'
 
            WRITE (*,'(A,F16.3)') '      X = ', POS(1)
            WRITE (*,'(A,F16.3)') '      Y = ', POS(2)
            WRITE (*,'(A,F16.3)') '      Z = ', POS(3)
 
      C
      C     Now we need to compute the actual distance between the Sun
      C     and Mars.  The above SPKPOS call gives us the apparent
      C     distance, so we need to adjust our aberration correction
      C     appropriately.
      C
            CALL SPKPOS ( 'SUN',  ET,  'J2000', 'NONE',
           .              'MARS', POS, LTIME                  )
 
      C
      C     Compute the distance between the body centers in
      C     kilometers.
      C
            DIST = VNORM(POS)
 
      C
      C     Convert this value to AU using CONVRT.
      C
            CALL CONVRT ( DIST, 'KM', 'AU', DIST )
 
            WRITE (*,*) '   Actual distance between Sun and Mars body '
           .//          'centers: '
            WRITE (*,'(A,F16.3)') '      (AU):', DIST
 
            END
 
 
Solution Sample Output
 
   After compiling the program, execute it:
 
      Converting UTC Time: 2018 JUN 11 19:32:00
         ET seconds past J2000:    582017589.185
         Apparent state of Mars as seen from ExoMars-16 TGO in the J2000
            frame (km, km/s):
            X =         2911.822
            Y =        -2033.802
            Z =        -1291.701
           VX =            1.310
           VY =           -0.056
           VZ =            3.104
         Apparent position of Earth as seen from ExoMars-16 TGO in the
            J2000 frame (km):
            X =    -49609884.080
            Y =     57070665.862
            Z =     30304236.930
         One way light time between ExoMars-16 TGO and the apparent
            position of Earth (seconds):          271.738
         Apparent position of Sun as seen from Mars in the
            J2000 frame (km):
            X =    -24712734.289
            Y =    194560532.943
            Z =     89906636.789
         Actual distance between Sun and Mars body centers:
            (AU):           1.442
 
 
Extra Credit
--------------------------------------------------------
 
   In this ``extra credit'' section you will be presented with more complex
   tasks, aimed at improving your understanding of state computations,
   particularly the application of the different light time and stellar
   aberration corrections available in the SPKEZR routine, and some common
   errors that may happen when computing these states.
 
   These ``extra credit'' tasks are provided as task statements, and unlike
   the regular tasks, no approach or solution source code is provided. In
   the next section, you will find the numeric solutions (when applicable)
   and answers to the questions asked in these tasks.
 
 
Task statements and questions
 
       1.   Remove the Martian planetary ephemerides SPK (mar085.bsp) from
            the original meta-kernel and run your program again, using the
            same inputs as before. Has anything changed? Why?
 
       2.   Remove the ExoMars-16 TGO frames definition kernel
            (em16_tgo_v07.tf) from the original meta-kernel and run your
            program again, using the same inputs as before. Has anything
            changed? Why?
 
       3.   Extend your program to compute the geometric position of
            Jupiter as seen from Mars in the J2000 frame (J2000), in
            kilometers.
 
       4.   Extend your program to compute the apparent position of the
            Schiaparelli Entry, Descent and Landing Demonstrator Module
            (EDM) Landing Site as seen from the ExoMars-16 Trace Gas
            Orbiter (TGO) spacecraft in the J2000 frame (J2000), in
            kilometers.
 
       5.   Extend, or modify, your program to compute the position of the
            Sun as seen from Mars in the J2000 frame (J2000), in
            kilometers, using the following light time and aberration
            corrections: NONE, LT and LT+S. Explain the differences.
 
       6.   Examine the ExoMars-16 TGO frames definition kernel to find the
            SPICE ID/name definitions.
 
 
Solutions and answers
 
       1.   When running the original program without the Martian planetary
            ephemerides SPK, an error is produced by SPKEZR:
            SPICE(SPKINSUFFDATA). This error is generated when trying to
            compute the apparent state of Mars as seen from ExoMars-16 TGO
            in the J2000 frame because despite the ExoMars-16 TGO ephemeris
            data being relative to Mars, the state of the spacecraft with
            respect to the solar system barycenter is required to compute
            the effect of the light time and stellar aberrations. The
            loaded SPK data is enough to compute geometric states of
            ExoMars-16 TGO with respect to Mars center, and geometric
            states of Mars barycenter with respect to the Solar System
            Barycenter, but insufficient to compute the state of the
            spacecraft relative to the Solar System Barycenter because the
            SPK data needed to compute geometric states of Mars center
            relative to its barycenter is no longer loaded. Run ``brief''
            on the SPKs used in the original task to find out what
            ephemeris objects are available from that kernel. If you want
            to find out what is the 'center of motion' for the ephemeris
            object(s) included in an SPK, use the -c option when running
            ``brief''.
 
       2.   When running the original program without the ExoMars-16 TGO
            frames definitions kernel, an error is produced by SPKEZR:
            SPICE(IDCODENOTFOUND). This error is generated because the
            observer 'TGO' is not a recognized name for an ephemeris object
            as TGO is not yet included in the official SPICE ID/name
            mappings and the mission specific mapping definitions, included
            in the FK, have not been loaded. In order to resolve this
            issue, two possibilities exist: load the SPICE ID/name mappings
            or use the NAIF IDs instead:
 
            CALL SPKEZR ( 'MARS', ET,    'J2000', 'LT+S',
           .              '-143', STATE, LTIME            )
 
       3.   If you run your extended program, with the original
            meta-kernel, the SPICE(SPKINSUFFDATA) error should be produced
            by the SPKPOS routine because you have not loaded enough
            ephemeris data to compute the position of Jupiter with respect
            to Mars. The loaded SPKs contain data for Mars relative to the
            Solar System Barycenter, and for the Jupiter System Barycenter
            relative to the Solar System Barycenter, but the data for
            Jupiter relative to the Jupiter System Barycenter is missing.
            SPKs with this data are available in the NAIF server at:
 
         http://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/
 
            Download the relevant SPK, add it to the meta-kernel and run
            again your extended program. The solution for the input UTC
            time ``2018 JUN 11 19:32:00'' when using the Jovian Satellite
            Ephemeris SPK jup310.bsp is:
 
            Actual position of Jupiter as seen from Mars in the
               J2000 frame (km):
               X =   -536521483.296
               Y =   -384722940.462
               Z =   -145930841.439
 
       4.   Once you have extended your program, download the required data
            from the official ExoMars-16 SPICE operational FTP site and
            update your meta-kernel. This is the solution for the input UTC
            time ``2018 JUN 11 19:32:00'' when using the following data for
            the EDM lander:
 
 
            Additional kernels used in this task:
 
               a. EDM lander FK:
 
                     em16_emd_v00.tf
 
               b. EDM landing site SPK:
 
                     em16_edm_sot_landing_site_20161020_21000101_v01.bsp
 
               c. Generic PCK, where the Mars orientation constants are
                  provided:
 
                     pck00010.tpc
 
 
            Apparent position of EDM Landing Site (EDM_LANDING_SITE, NAIF
            ID -117900) as seen from ExoMars-16 TGO in the J2000 frame
            (km):
               X =         -131.716
               Y =        -2168.989
               Z =          208.792
 
       5.   When using 'NONE' aberration corrections, SPKPOS returns the
            geometric position of the target body relative to the observer.
            If 'LT' is used, the returned vector corresponds to the
            position of the target at the moment it emitted photons
            arriving at the observer at `et'. If 'LT+S' is used instead,
            the returned vector takes into account the observer's velocity
            relative to the solar system barycenter. The solution for the
            input UTC time ``2018 JUN 11 19:32:00'' is:
 
            Actual (geometric) position of Sun as seen from Mars in the
               J2000 frame (km):
               X =    -24730875.201
               Y =    194558449.560
               Z =     89906170.855
            Light-time corrected position of Sun as seen from Mars in the
               J2000 frame (km):
               X =    -24730866.489
               Y =    194558445.246
               Z =     89906168.754
            Apparent position of Sun as seen from Mars in the
               J2000 frame (km):
               X =    -24712734.289
               Y =    194560532.943
               Z =     89906636.789
 
 
 
Spacecraft Orientation and Reference Frames (xform)
===========================================================================
 
 
Task Statement
--------------------------------------------------------
 
   Write a program that prompts the user for an input time string, and
   computes and displays the following at the epoch of interest:
 
       1.   The apparent state of Mars as seen from ExoMars-16 TGO in the
            IAU_MARS body-fixed frame. This vector itself is not of any
            particular interest, but it is a useful intermediate quantity
            in some geometry calculations.
 
       2.   The angular separation between the apparent position of Mars as
            seen from ExoMars-16 TGO and the nominal instrument view
            direction.
 
            The nominal instrument view direction is not provided by any
            kernel variable, but it is indicated in the ExoMars-16 TGO
            frame kernel cited above in the section ``Kernels Used'' to be
            the -Y axis of the TGO_SPACECRAFT frame.
 
   Use the program to compute these quantities at the epoch "2018 jun 11
   19:32:00" UTC.
 
 
Learning Goals
--------------------------------------------------------
 
   Familiarity with the different types of kernels involved in chaining
   reference frames together, both inertial and non-inertial. Discover some
   of the matrix and vector math routines. Understand the difference
   between PXFORM and SXFORM.
 
 
Approach
--------------------------------------------------------
 
   The solution to the problem can be broken down into a series of simple
   steps:
 
       --   Decide which SPICE kernels are necessary. Prepare a meta-kernel
            listing the kernels and load it into the program.
 
       --   Prompt the user for an input time string.
 
       --   Convert the input time string into ephemeris time expressed as
            seconds past J2000 TDB.
 
       --   Compute the state of Mars relative to ExoMars-16 TGO in the
            J2000 reference frame, corrected for aberrations.
 
       --   Compute the state transformation matrix from J2000 to IAU_MARS
            at the epoch, adjusted for light time.
 
       --   Multiply the state of Mars relative to ExoMars-16 TGO in the
            J2000 reference frame by the state transformation matrix
            computed in the previous step.
 
       --   Compute the position of Mars relative to ExoMars-16 TGO in the
            J2000 reference frame, corrected for aberrations.
 
       --   Determine what the nominal instrument view direction of the
            ExoMars-16 TGO spacecraft is by examining the frame kernel's
            content.
 
       --   Compute the rotation matrix from the ExoMars-16 TGO spacecraft
            frame to J2000.
 
       --   Multiply the nominal instrument view direction expressed in the
            ExoMars-16 TGO spacecraft frame by the rotation matrix from the
            previous step.
 
       --   Compute the separation between the result of the previous step
            and the apparent position of Mars relative to ExoMars-16 TGO in
            the J2000 frame.
 
   HINT: Several of the steps above may be compressed into a single using
   SPICE routines with which you are already familiar. The ``long-way''
   presented above is intended to facilitate the introduction of the
   routines PXFORM and SXFORM.
 
   You may find it useful to consult the permuted index, the headers of
   various source modules, and the following toolkit documentation:
 
       1.   Frames Required Reading (frames.req)
 
       2.   PCK Required Reading (pck.req)
 
       3.   SPK Required Reading (spk.req)
 
       4.   CK Required Reading (ck.req)
 
   This particular example makes use of many of the different types of
   SPICE kernels. You should spend a few moments thinking about which
   kernels you will need and what data they provide.
 
 
Solution
--------------------------------------------------------
 
 
Solution Meta-Kernel
 
   The meta-kernel we created for the solution to this exercise is named
   'xform.tm'. Its contents follow:
 
      KPL/MK
 
         This is the meta-kernel used in the solution of the ``Spacecraft
         Orientation and Reference Frames'' task in the Remote Sensing
         Hands On Lesson.
 
      \begindata
 
       KERNELS_TO_LOAD = (
 
       'kernels/lsk/naif0012.tls',
       'kernels/sclk/em16_tgo_step_20160414.tsc',
       'kernels/spk/de430.bsp',
       'kernels/spk/mar085.bsp',
       'kernels/spk/em16_tgo_mlt_20171205_20230115_v01.bsp',
       'kernels/fk/em16_tgo_v07.tf',
       'kernels/ck/em16_tgo_sc_slt_npo_20171205_20230115_s20160414_v01.bc',
       'kernels/pck/pck00010.tpc'
 
                          )
 
      \begintext
 
 
Solution Source Code
 
   A sample solution to the problem follows:
 
            PROGRAM XFORM
 
            IMPLICIT NONE
 
      C
      C     SPICELIB Functions
      C
            DOUBLE PRECISION      VSEP
 
      C
      C     Local Parameters
      C
      C
      C     The name of the meta-kernel that lists the kernels
      C     to load into the program.
      C
            CHARACTER*(*)         METAKR
            PARAMETER           ( METAKR = 'xform.tm' )
 
      C
      C     The length of various string variables.
      C
            INTEGER               STRLEN
            PARAMETER           ( STRLEN = 50 )
 
      C
      C     Local Variables
      C
            CHARACTER*(STRLEN)    UTCTIM
 
            DOUBLE PRECISION      ET
            DOUBLE PRECISION      LTIME
            DOUBLE PRECISION      STATE  ( 6 )
            DOUBLE PRECISION      BFIXST ( 6 )
            DOUBLE PRECISION      POS    ( 3 )
            DOUBLE PRECISION      SXFMAT ( 6, 6 )
            DOUBLE PRECISION      PFORM  ( 3, 3 )
            DOUBLE PRECISION      BSIGHT ( 3 )
            DOUBLE PRECISION      SEP
 
      C
      C     Load the kernels that this program requires.  We
      C     will need:
      C
      C        A leapseconds kernel
      C        A spacecraft clock kernel for ExoMars-16 TGO
      C        The necessary ephemerides
      C        A planetary constants file (PCK)
      C        A spacecraft orientation kernel for ExoMars-16 TGO (CK)
      C        A frame kernel (TF)
      C
            CALL FURNSH ( METAKR )
 
      C
      C     Prompt the user for the input time string.
      C
            CALL PROMPT ( 'Input UTC Time: ', UTCTIM )
 
            WRITE (*,*) 'Converting UTC Time: ', UTCTIM
 
      C
      C     Convert UTCTIM to ET.
      C
            CALL STR2ET ( UTCTIM, ET )
 
            WRITE (*,'(A,F16.3)') '   ET seconds past J2000: ', ET
 
      C
      C     Compute the apparent state of Mars as seen from ExoMars-16
      C     TGO in the J2000 reference frame.
      C
            CALL SPKEZR ( 'MARS', ET,    'J2000', 'LT+S',
           .              'TGO',  STATE, LTIME           )
 
      C
      C     Now obtain the transformation from the inertial
      C     J2000 frame to the non-inertial, body-fixed IAU_MARS
      C     frame. Since we'll use this transformation to produce
      C     the apparent state in the IAU_MARS reference frame,
      C     we need to correct the orientation of this frame for
      C     one-way light time; hence we subtract LTIME from ET
      C     in the call below.
      C
            CALL SXFORM ( 'J2000', 'IAU_MARS', ET-LTIME, SXFMAT )
 
      C
      C     Now transform the apparent J2000 state into IAU_MARS
      C     with the following matrix multiplication:
      C
            CALL MXVG ( SXFMAT, STATE, 6, 6, BFIXST )
 
      C
      C     Display the results.
      C
            WRITE (*,*) '   Apparent state of Mars as seen from '
           .//          'ExoMars-16 TGO in the IAU_MARS'
            WRITE (*,*) '      body-fixed frame (km, km/s):'
            WRITE (*,'(A,F19.6)') '      X = ', BFIXST(1)
            WRITE (*,'(A,F19.6)') '      Y = ', BFIXST(2)
            WRITE (*,'(A,F19.6)') '      Z = ', BFIXST(3)
            WRITE (*,'(A,F19.6)') '     VX = ', BFIXST(4)
            WRITE (*,'(A,F19.6)') '     VY = ', BFIXST(5)
            WRITE (*,'(A,F19.6)') '     VZ = ', BFIXST(6)
 
      C
      C     It is worth pointing out, all of the above could have
      C     been done with a single call to SPKEZR:
      C
            CALL SPKEZR ( 'MARS', ET,    'IAU_MARS', 'LT+S',
           .              'TGO',  STATE, LTIME               )
 
      C
      C     Display the results.
      C
            WRITE (*,*) '   Apparent state of Mars as seen from '
           .//          'ExoMars-16 TGO in the IAU_MARS'
            WRITE (*,*) '      body-fixed frame (km, km/s) '
           .//          'obtained using SPKEZR directly:'
            WRITE (*,'(A,F19.6)') '      X = ', STATE(1)
            WRITE (*,'(A,F19.6)') '      Y = ', STATE(2)
            WRITE (*,'(A,F19.6)') '      Z = ', STATE(3)
            WRITE (*,'(A,F19.6)') '     VX = ', STATE(4)
            WRITE (*,'(A,F19.6)') '     VY = ', STATE(5)
            WRITE (*,'(A,F19.6)') '     VZ = ', STATE(6)
 
      C
      C     Note that the velocity found by using SPKEZR
      C     to compute the state in the IAU_MARS frame differs
      C     at the few mm/second level from that found previously
      C     by calling SPKEZR and then SXFORM. Computing velocity
      C     via a single call to SPKEZR as we've done immediately
      C     above is slightly more accurate because it accounts for
      C     the effect of the rate of change of light time on the
      C     apparent angular velocity of the target's body-fixed
      C     reference frame.
      C
      C     Now we are to compute the angular separation between
      C     the apparent position of Mars as seen from the orbiter
      C     and the nominal instrument view direction.  First,
      C     compute the apparent position of Mars as seen from
      C     ExoMars-16 TGO in the J2000 frame.
      C
            CALL SPKPOS ( 'MARS', ET,  'J2000', 'LT+S',
           .              'TGO',  POS, LTIME               )
 
      C
      C     Now compute the location of the nominal instrument view
      C     direction.  From reading the frame kernel we know that
      C     the instrument view direction is nominally the -Y axis
      C     of the TGO_SPACECRAFT frame defined there.
      C
            BSIGHT(1) =  0.0D0
            BSIGHT(2) = -1.0D0
            BSIGHT(3) =  0.0D0
 
      C
      C     Now compute the rotation matrix from TGO_SPACECRAFT into
      C     J2000.
      C
            CALL PXFORM ( 'TGO_SPACECRAFT', 'J2000', ET, PFORM )
 
      C
      C     And multiply the result to obtain the nominal instrument
      C     view direction in the J2000 reference frame.
      C
            CALL MXV ( PFORM, BSIGHT, BSIGHT )
 
      C
      C     Lastly compute the angular separation.
      C
            CALL CONVRT ( VSEP(BSIGHT, POS), 'RADIANS',
           .              'DEGREES',         SEP        )
 
            WRITE (*,*) '   Angular separation between the '
           .//          'apparent position of Mars and the'
            WRITE (*,*) '      ExoMars-16 TGO nominal '
           .//          'instrument view direction (degrees):'
            WRITE (*,'(A,F19.3)') '      ', SEP
 
      C
      C     Or, alternately we can work in the spacecraft
      C     frame directly.
      C
            CALL SPKPOS ( 'MARS', ET,  'TGO_SPACECRAFT', 'LT+S',
           .              'TGO',  POS, LTIME                    )
 
      C
      C     The nominal instrument view direction is the -Y-axis
      C     in the TGO_SPACECRAFT frame.
      C
            BSIGHT(1) =  0.0D0
            BSIGHT(2) = -1.0D0
            BSIGHT(3) =  0.0D0
 
      C
      C     Lastly compute the angular separation.
      C
            CALL CONVRT ( VSEP(BSIGHT, POS), 'RADIANS',
           .              'DEGREES',         SEP        )
 
            WRITE (*,*) '   Angular separation between the '
           .//          'apparent position of Mars and the'
            WRITE (*,*) '      ExoMars-16 TGO nominal '
           .//          'instrument view direction at computed'
            WRITE (*,*) '      using vectors in the '
           .//          'TGO_SPACECRAFT frame (degrees): '
            WRITE (*,'(A,F19.3)') '      ', SEP
 
            END
 
 
Solution Sample Output
 
   After compiling the program, execute it:
 
      Converting UTC Time: 2018 JUN 11 19:32:00
         ET seconds past J2000:    582017589.185
         Apparent state of Mars as seen from ExoMars-16 TGO in the IAU_MARS
            body-fixed frame (km, km/s):
            X =        -2843.464125
            Y =         2235.459544
            Z =         1095.894969
           VX =            0.311443
           VY =           -1.151929
           VZ =            3.082123
         Apparent state of Mars as seen from ExoMars-16 TGO in the IAU_MARS
            body-fixed frame (km, km/s) obtained using SPKEZR directly:
            X =        -2843.464125
            Y =         2235.459544
            Z =         1095.894969
           VX =            0.311443
           VY =           -1.151929
           VZ =            3.082123
         Angular separation between the apparent position of Mars and the
            ExoMars-16 TGO nominal instrument view direction (degrees):
                          5.438
         Angular separation between the apparent position of Mars and the
            ExoMars-16 TGO nominal instrument view direction at computed
            using vectors in the TGO_SPACECRAFT frame (degrees):
                          5.438
 
 
Extra Credit
--------------------------------------------------------
 
   In this ``extra credit'' section you will be presented with more complex
   tasks, aimed at improving your understanding of frame transformations,
   and some common errors that may happen when computing them.
 
   These ``extra credit'' tasks are provided as task statements, and unlike
   the regular tasks, no approach or solution source code is provided. In
   the next section, you will find the numeric solutions (when applicable)
   and answers to the questions asked in these tasks.
 
 
Task statements and questions
 
       1.   Run the original program using the input UTC time ``2018 jun 12
            18:25:00''. Explain what happens.
 
       2.   Compute the angular separation between the apparent position of
            the Sun as seen from ExoMars-16 TGO and the nominal instrument
            view direction. Is the science deck illuminated?
 
 
Solutions and answers
 
       1.   When running the original software using as input the UTC time
            string ``2018 jun 12 18:25:00'' PXFORM returns the
            SPICE(NOFRAMECONNECT) error, which indicates that there is not
            sufficient data to perform the transformation from the
            TGO_SPACECRAFT frame to J2000 at the requested epoch. If you
            summarize the ExoMars-16 TGO spacecraft CK using the
            ``ckbrief'' utility program with the -dump option (display
            interpolation intervals boundaries) you will find that the CK
            contains gaps within its segment:
 
               Segment No.: 1
 
               Object:  -143000
                 Interval Begin ET        Interval End ET          AV
                 ------------------------ ------------------------ ---
                 2018-JUN-11 00:01:09.184 2018-JUN-12 06:28:03.102 Y
                 2018-JUN-12 06:58:03.102 2018-JUN-12 18:15:43.102 Y
                 2018-JUN-12 18:45:43.102 2018-JUN-13 04:03:23.102 Y
                 2018-JUN-13 04:33:23.102 2018-JUN-13 07:59:43.102 Y
                 2018-JUN-13 08:29:43.102 2018-JUN-13 12:01:09.184 Y
 
 
            whereas if you had used ckbrief without -dump you would have
            gotten the following information (only CK segment begin/end
            times):
 
               Object:  -143000
                 Interval Begin ET        Interval End ET          AV
                 ------------------------ ------------------------ ---
                 2018-JUN-11 00:01:09.184 2018-JUN-13 12:01:09.184 Y
 
 
            which has insufficient detail to reveal the problem.
 
       2.   By computing the apparent position of the Sun as seen from
            ExoMars-16 TGO in the TGO_SPACECRAFT frame, and the angular
            separation between this vector and the nominal instrument view
            direction (-Y-axis of the TGO_SPACECRAFT frame), you will find
            out that the science deck is NOT illuminated, since the angular
            separation -- 130.543 degrees -- is greater than 90 degrees.
 
 
Computing Sub-spacecraft and Sub-solar Points (subpts)
===========================================================================
 
 
Task Statement
--------------------------------------------------------
 
   Write a program that prompts the user for an input UTC time string,
   computes the following quantities at that epoch:
 
       1.   The apparent sub-observer point of ExoMars-16 TGO on Mars in
            the body fixed frame IAU_MARS in kilometers.
 
       2.   The apparent sub-solar point on Mars as seen from ExoMars-16
            TGO in the body fixed frame IAU_MARS in kilometers.
 
   and displays the results. Use the program to compute these quantities at
   "2018 jun 11 19:32:00" UTC.
 
 
Learning Goals
--------------------------------------------------------
 
   Discover higher level geometry calculation routines in SPICE and their
   usage as it relates to ExoMars-16 TGO.
 
 
Approach
--------------------------------------------------------
 
   This particular problem is more of an exercise in searching the permuted
   index to find the appropriate routines and then reading their headers to
   understand how to call them.
 
   One point worth considering: Which method do you want to use to compute
   the sub-solar (or sub-observer) point?
 
 
Solution
--------------------------------------------------------
 
 
Solution Meta-Kernel
 
   The meta-kernel we created for the solution to this exercise is named
   'subpts.tm'. Its contents follow:
 
      KPL/MK
 
         This is the meta-kernel used in the solution of the
         ``Computing Sub-spacecraft and Sub-solar Points'' task
         in the Remote Sensing Hands On Lesson.
 
      \begindata
 
       KERNELS_TO_LOAD = (
 
       'kernels/lsk/naif0012.tls',
       'kernels/spk/de430.bsp',
       'kernels/spk/mar085.bsp',
       'kernels/spk/em16_tgo_mlt_20171205_20230115_v01.bsp',
       'kernels/fk/em16_tgo_v07.tf',
       'kernels/pck/pck00010.tpc'
 
                         )
 
      \begintext
 
 
Solution Source Code
 
   A sample solution to the problem follows:
 
            PROGRAM SUBPTS
 
            IMPLICIT NONE
      C
      C     SPICELIB functions
      C
            DOUBLE PRECISION      VNORM
 
      C
      C     Local Parameters
      C
      C
      C     The name of the meta-kernel that lists the kernels
      C     to load into the program.
      C
            CHARACTER*(*)         METAKR
            PARAMETER           ( METAKR = 'subpts.tm' )
 
      C
      C     The length of various string variables.
      C
            INTEGER               STRLEN
            PARAMETER           ( STRLEN = 50 )
 
      C
      C     Local Variables
      C
            CHARACTER*(STRLEN)    UTCTIM
 
            DOUBLE PRECISION      ET
            DOUBLE PRECISION      SPOINT ( 3 )
            DOUBLE PRECISION      SRFVEC ( 3 )
            DOUBLE PRECISION      TRGEPC
 
      C
      C     Load the kernels that this program requires.  We
      C     will need:
      C
      C        A leapseconds kernel
      C        The necessary ephemerides
      C        A planetary constants file (PCK)
      C        A frames kernel (TF) with the TGO ID/name mapping
      C
            CALL FURNSH ( METAKR )
 
      C
      C     Prompt the user for the input time string.
      C
            CALL PROMPT ( 'Input UTC Time: ', UTCTIM )
 
            WRITE (*,*) 'Converting UTC Time: ', UTCTIM
 
      C
      C     Convert UTCTIM to ET.
      C
            CALL STR2ET ( UTCTIM, ET )
 
            WRITE (*,'(A,F16.3)') '   ET seconds past J2000: ', ET
 
      C
      C     Compute the apparent sub-observer point of ExoMars-16 TGO
      C     on Mars.
      C
            CALL SUBPNT ( 'NEAR POINT: ELLIPSOID',
           .              'MARS', ET,     'IAU_MARS', 'LT+S',
           .              'TGO',  SPOINT, TRGEPC,     SRFVEC )
 
            WRITE (*,*) '   Apparent sub-observer point of ExoMars-16 TGO '
           .//          'on Mars in the'
            WRITE (*,*) '   IAU_MARS frame (km):'
            WRITE (*,'(A,F16.3)') '      X = ', SPOINT(1)
            WRITE (*,'(A,F16.3)') '      Y = ', SPOINT(2)
            WRITE (*,'(A,F16.3)') '      Z = ', SPOINT(3)
            WRITE (*,'(A,F16.3)') '    ALT = ', VNORM(SRFVEC)
 
      C
      C     Compute the apparent sub-solar point on Mars as seen
      C     from ExoMars-16 TGO.
      C
            CALL SUBSLR ( 'NEAR POINT: ELLIPSOID',
           .              'MARS', ET,     'IAU_MARS', 'LT+S',
           .              'TGO',  SPOINT, TRGEPC,     SRFVEC )
 
            WRITE (*,*) '   Apparent sub-solar point on Mars as '
           .//          'seen from ExoMars-16 TGO in'
            WRITE (*,*) '   the IAU_MARS frame (km):'
            WRITE (*,'(A,F16.3)') '      X = ', SPOINT(1)
            WRITE (*,'(A,F16.3)') '      Y = ', SPOINT(2)
            WRITE (*,'(A,F16.3)') '      Z = ', SPOINT(3)
 
            END
 
 
Solution Sample Output
 
   After compiling the program, execute it:
 
      Converting UTC Time: 2018 JUN 11 19:32:00
         ET seconds past J2000:    582017589.185
         Apparent sub-observer point of ExoMars-16 TGO on Mars in the
         IAU_MARS frame (km):
            X =         2554.165
            Y =        -2008.010
            Z =         -983.240
          ALT =          385.045
         Apparent sub-solar point on Mars as seen from ExoMars-16 TGO in
         the IAU_MARS frame (km):
            X =          487.589
            Y =        -3348.610
            Z =         -286.697
 
 
Extra Credit
--------------------------------------------------------
 
   In this ``extra credit'' section you will be presented with more complex
   tasks, aimed at improving your understanding of SUBPNT and SUBSLR
   routines.
 
   These ``extra credit'' tasks are provided as task statements, and unlike
   the regular tasks, no approach or solution source code is provided. In
   the next section, you will find the numeric solutions (when applicable)
   and answers to the questions asked in these tasks.
 
 
Task statements and questions
 
       1.   Recompute the apparent sub-solar point on Mars as seen from
            ExoMars-16 TGO in the body fixed frame IAU_MARS in kilometers
            using the 'Intercept: ellipsoid' method at ``2018 jun 11
            19:32:00''. Explain the differences.
 
       2.   Compute the apparent sub-spacecraft point of ExoMars-16 TGO on
            Phobos in the body fixed frame IAU_PHOBOS in kilometers using
            the 'Near point: ellipsoid' method at ``2018 jun 11 19:32:00''.
 
       3.   Transform the sub-spacecraft Cartesian coordinates obtained in
            the previous task to planetocentric and planetographic
            coordinates. When computing planetographic coordinates use
            Phobos' radii(1) as its equatorial radius. Explain why
            planetocentric and planetographic latitudes and longitudes are
            different. Explain why the planetographic altitude for a point
            on the surface of Phobos is not zero and whether this is
            correct or not.
 
 
Solutions and answers
 
       1.   The differences observed are due to the computation method. The
            ``Intercept: ellipsoid'' method defines the sub-solar point as
            the target surface intercept of the line containing the Sun and
            the target's center, while the ``Near point: ellipsoid'' method
            defines the sub-solar point as the the nearest point on the
            target relative to the Sun. Since Mars is not spherical, these
            two points are not the same:
 
            Apparent sub-solar point on Mars as seen from ExoMars-16 TGO in
            the IAU_MARS frame using the 'Near Point: ellipsoid' method
            (km):
               X =          487.589
               Y =        -3348.610
               Z =         -286.697
 
            Apparent sub-solar point on Mars as seen from ExoMars-16 TGO in
            the IAU_MARS frame using the 'Intercept: ellipsoid' method
            (km):
               X =          487.547
               Y =        -3348.322
               Z =         -290.077
 
       2.   The apparent sub-spacecraft point of ExoMars-16 TGO on Phobos
            in the body fixed frame IAU_PHOBOS in kilometers at ``2018 jun
            11 19:32:00'' UTC epoch is:
 
            Apparent sub-spacecraft point of ExoMars-16 TGO on Phobos in
            the IAU_PHOBOS frame using the 'Near Point: ellipsoid' method
            (km):
               X =           12.059
               Y =            4.173
               Z =           -0.675
 
       3.   The sub-spacecraft point of ExoMars-16 TGO on Phobos in
            planetocentric and planetographic coordinates at ``2018 jun 11
            19:32:00'' UTC epoch is:
 
            Planetocentric coordinates of the sub-spacecraft point on
            Phobos (degrees, km):
               LAT =           -3.030
               LON =           19.088
               R   =           12.779
 
            Planetographic coordinates of the sub-spacecraft point on
            Phobos (degrees, km):
               LAT =           -6.267
               LON =          340.912
               ALT =           -0.202
 
            The planetocentric and planetographic longitudes are different
            (``graphic'' = 360 - ``centric'') because planetographic
            longitudes on Phobos are measured positive west as defined by
            the Phobos rotation direction.
 
            The planetocentric and planetographic latitudes are different
            because the planetocentric latitude was computed as the angle
            between the direction from the center of the body to the point
            and the equatorial plane, while the planetographic latitude was
            computed as the angle between the surface normal at the point
            and the equatorial plane.
 
            The planetographic altitude is non zero -- -0.202 km -- because
            it was computed using a different and incorrect Phobos surface
            model, a spheroid with equal equatorial radii, for the surface
            point computed by SUBPNT on the Phobos surface modeled as a
            triaxial ellipsoid with different equatorial radii. The
            planetographic latitude is also incorrect because it is based
            on the normal to the surface of the spheroid rather than the
            ellipsoid, In general planetographic coordinates cannot be used
            for bodies with shapes modeled as triaxial ellipsoids.
 
 
Intersecting Vectors with a Triaxial Ellipsoid (fovint)
===========================================================================
 
 
Task Statement
--------------------------------------------------------
 
   Write a program that prompts the user for an input UTC time string and,
   for that time, computes the intersection of the ExoMars-16 TGO NOMAD LNO
   Nadir aperture boresight and field of view (FOV) boundary vectors with
   the surface of Mars. The program presents each point of intersection as
 
       1.   A cartesian vector in the IAU_MARS frame
 
       2.   Planetocentric (latitudinal) coordinates in the IAU_MARS frame.
 
   For each vector, if an intersection is found, the program displays the
   results of the above computations, otherwise it indicates no
   intersection has occurred.
 
   At each point of intersection compute the following:
 
       3.   Phase angle
 
       4.   Solar incidence angle
 
       5.   Emission angle
 
   Additionally compute the local solar time at the intercept of the
   spectrometer aperture boresight with the surface of Mars.
 
   Use this program to compute values at the epoch:
 
            2018 jun 11 19:32:00 UTC
 
 
Learning Goals
--------------------------------------------------------
 
   Understand how field of view parameters are retrieved from instrument
   kernels. Learn how various standard planetary constants are retrieved
   from text PCKs. Discover how to compute the intersection of field of
   view vectors with triaxial ellipsoidal target bodies. Discover another
   high level geometry routine and another time conversion routine in
   SPICE.
 
 
Approach
--------------------------------------------------------
 
   This problem can be broken down into several simple, small steps:
 
       --   Decide which SPICE kernels are necessary. Prepare a meta-kernel
            listing the kernels and load it into the program. Remember, you
            will need to find a kernel with information about the
            ExoMars-16 TGO NOMAD spectrometer.
 
       --   Prompt the user for an input time string.
 
       --   Convert the input time string into ephemeris time expressed as
            seconds past J2000 TDB.
 
       --   Retrieve the FOV (field of view) configuration for the
            ExoMars-16 TGO NOMAD LNO Nadir aperture.
 
   For each vector in the set of boundary corner vectors, and for the
   boresight vector, perform the following operations:
 
       --   Compute the intercept of the vector with Mars.
 
       --   If this intercept is found, convert the position vector of the
            intercept into planetocentric coordinates.
 
            Then compute the phase, solar incidence, and emission angles at
            the intercept. Otherwise indicate to the user no intercept was
            found for this vector.
 
       --   Compute the planetocentric longitude of the boresight
            intercept.
 
   Finally
 
       --   Compute the local solar time at the boresight intercept
            longitude on a 24-hour clock. The input time for this
            computation should be the TDB observation epoch minus one-way
            light time from the boresight intercept to the spacecraft.
 
   It may be useful to consult the ExoMars-16 TGO NOMAD instrument kernel
   to determine the name of the NOMAD LNO Nadir aperture as well as its
   configuration. This exercise may make use of some of the concepts and
   (loosely) code from the ``Spacecraft Orientation and Reference Frames''
   task.
 
 
Solution
--------------------------------------------------------
 
 
Solution Meta-Kernel
 
   The meta-kernel we created for the solution to this exercise is named
   'fovint.tm'. Its contents follow:
 
      KPL/MK
 
         This is the meta-kernel used in the solution of the
         ``Intersecting Vectors with a Triaxial Ellipsoid'' task
         in the Remote Sensing Hands On Lesson.
 
      \begindata
 
       KERNELS_TO_LOAD = (
 
       'kernels/lsk/naif0012.tls',
       'kernels/sclk/em16_tgo_step_20160414.tsc',
       'kernels/spk/de430.bsp',
       'kernels/spk/mar085.bsp',
       'kernels/spk/em16_tgo_mlt_20171205_20230115_v01.bsp',
       'kernels/fk/em16_tgo_v07.tf',
       'kernels/ck/em16_tgo_sc_slt_npo_20171205_20230115_s20160414_v01.bc',
       'kernels/pck/pck00010.tpc',
       'kernels/ik/em16_tgo_nomad_v02.ti'
 
                         )
 
      \begintext
 
 
Solution Source Code
 
   A sample solution to the problem follows:
 
            PROGRAM FOVINT
 
            IMPLICIT NONE
 
      C
      C     SPICELIB functions
      C
            DOUBLE PRECISION      DPR
 
      C
      C     Local Parameters
      C
      C
      C     The name of the meta-kernel that lists the kernels
      C     to load into the program.
      C
            CHARACTER*(*)         METAKR
            PARAMETER           ( METAKR = 'fovint.tm' )
 
      C
      C     The length of various string variables.
      C
            INTEGER               STRLEN
            PARAMETER           ( STRLEN = 50 )
 
      C
      C     The maximum number of boundary corner vectors
      C     we can retrieve.
      C
            INTEGER               BCVLEN
            PARAMETER           ( BCVLEN = 5 )
 
      C
      C     Local Variables
      C
            CHARACTER*(STRLEN)    AMPM
            CHARACTER*(STRLEN)    INSFRM
            CHARACTER*(STRLEN)    SHAPE
            CHARACTER*(STRLEN)    TIME
            CHARACTER*(STRLEN)    UTCTIM
            CHARACTER*(STRLEN)    VECNAM ( BCVLEN )
 
            DOUBLE PRECISION      BOUNDS ( 3, BCVLEN )
            DOUBLE PRECISION      BSIGHT ( 3 )
            DOUBLE PRECISION      EMISSN
            DOUBLE PRECISION      ET
            DOUBLE PRECISION      LAT
            DOUBLE PRECISION      LON
            DOUBLE PRECISION      PHASE
            DOUBLE PRECISION      POINT  ( 3 )
            DOUBLE PRECISION      RADIUS
            DOUBLE PRECISION      SOLAR
            DOUBLE PRECISION      SRFVEC ( 3 )
            DOUBLE PRECISION      TRGEPC
 
            INTEGER               HR
            INTEGER               I
            INTEGER               MN
            INTEGER               N
            INTEGER               LNONID
            INTEGER               MARSID
            INTEGER               SC
 
            LOGICAL               FOUND
 
      C
      C     Load the kernels that this program requires. We
      C     will need:
      C
      C        A leapseconds kernel.
      C        A SCLK kernel for ExoMars-16 TGO.
      C        Any necessary ephemerides.
      C        The ExoMars-16 TGO frame kernel.
      C        An ExoMars-16 TGO C-kernel.
      C        A PCK file with Mars constants.
      C        The ExoMars-16 TGO NOMAD I-kernel.
      C
            CALL FURNSH ( METAKR )
 
      C
      C     Prompt the user for the input time string.
      C
            CALL PROMPT ( 'Input UTC Time: ', UTCTIM )
 
            WRITE (*,*) 'Converting UTC Time: ', UTCTIM
 
      C
      C     Convert UTCTIM to ET.
      C
            CALL STR2ET ( UTCTIM, ET )
 
            WRITE (*,'(A,F16.3)') '   ET seconds past J2000: ', ET
 
      C
      C     Now we need to obtain the FOV configuration of the NOMAD
      C     LNO Nadir aperture. To do this we will need the ID code for
      C     TGO_NOMAD_LNO_NAD.
      C
            CALL BODN2C ( 'TGO_NOMAD_LNO_NAD', LNONID, FOUND )
 
      C
      C     Stop the program if the code was not found.
      C
            IF ( .NOT. FOUND ) THEN
               WRITE (*,*) 'Unable to locate the ID code for '
           .   //          'TGO_NOMAD_LNO_NAD'
               CALL BYEBYE ( 'FAILURE' )
            END IF
 
      C
      C     Now retrieve the field of view parameters.
      C
            CALL GETFOV ( LNONID,  BCVLEN, SHAPE, INSFRM,
           .              BSIGHT, N,      BOUNDS        )
 
      C
      C     Rather than treat BSIGHT as a separate vector,
      C     copy it into the last slot of BOUNDS.
      C
            CALL MOVED ( BSIGHT, 3, BOUNDS(1,5) )
 
      C
      C     Define names for each of the vectors for display
      C     purposes.
      C
            VECNAM (1) = 'Boundary Corner 1'
            VECNAM (2) = 'Boundary Corner 2'
            VECNAM (3) = 'Boundary Corner 3'
            VECNAM (4) = 'Boundary Corner 4'
            VECNAM (5) = 'ExoMars-16 TGO NOMAD LNO Nadir Boresight'
 
      C
      C     Now perform the same set of calculations for each
      C     vector listed in the BOUNDS array.
      C
            DO I = 1, 5
      C
      C        Call SINCPT to determine coordinates of the
      C        intersection of this vector with the surface
      C        of Mars.
      C
               CALL SINCPT ( 'Ellipsoid', 'MARS',      ET,
           .                 'IAU_MARS',  'LT+S',      'TGO',
           .                 INSFRM,      BOUNDS(1,I), POINT,
           .                 TRGEPC,      SRFVEC,      FOUND  )
      C
      C        Check the found flag. Display a message if the point
      C        of intersection was not found, otherwise continue with
      C        the calculations.
      C
               WRITE (*,*) 'Vector: ', VECNAM(I)
 
               IF ( .NOT. FOUND ) THEN
 
                  WRITE (*,*) 'No intersection point found at '
           .      //          'this epoch for this vector.'
 
               ELSE
      C
      C           Now, we have discovered a point of intersection.
      C           Start by displaying the position vector in the
      C           IAU_MARS frame of the intersection.
      C
                  WRITE (*,*) '  Position vector of '
           .      //          'surface intercept in '
           .      //          'the IAU_MARS frame (km):'
                  WRITE (*,'(A,F16.3)') '      X   = ', POINT(1)
                  WRITE (*,'(A,F16.3)') '      Y   = ', POINT(2)
                  WRITE (*,'(A,F16.3)') '      Z   = ', POINT(3)
      C
      C           Display the planetocentric latitude and longitude
      C           of the intercept.
      C
                  CALL RECLAT ( POINT, RADIUS, LON, LAT )
 
                  WRITE (*,*) '  Planetocentric coordinates of the '
           .      //          'intercept (degrees):'
                  WRITE (*,'(A,F16.3)') '      LAT = ', LAT * DPR()
                  WRITE (*,'(A,F16.3)') '      LON = ', LON * DPR()
      C
      C           Compute the illumination angles at this
      C           point.
      C
                  CALL ILUMIN ( 'Ellipsoid', 'MARS',  ET,
           .                    'IAU_MARS',  'LT+S',  'TGO',
           .                    POINT,       TRGEPC,  SRFVEC,
           .                    PHASE,       SOLAR,   EMISSN  )
 
                  WRITE (*,'(A,F16.3)') '   Phase angle (degrees):'
           .      //                    '           ', PHASE * DPR()
                  WRITE (*,'(A,F16.3)') '   Solar incidence angle '
           .      //                    '(degrees): ', SOLAR * DPR()
                  WRITE (*,'(A,F16.3)') '   Emission angle (degree'
           .      //                    's):        ', EMISSN* DPR()
 
               END IF
 
               WRITE (*,*) ' '
 
            END DO
 
      C
      C     Lastly compute the local solar time at the boresight
      C     intersection.
      C
            IF ( FOUND ) THEN
      C
      C        Get Mars ID.
      C
               CALL BODN2C ( 'MARS', MARSID, FOUND )
 
      C
      C        The ID code for MARS is built-in to the library.
      C        However, it is good programming practice to get
      C        in the habit of checking your found-flags.
      C
               IF ( .NOT. FOUND ) THEN
                  WRITE (*,*) 'Unable to locate the ID code for '
           .   //             'MARS'
                  CALL BYEBYE ( 'FAILURE' )
               END IF
      C
      C        Compute local time corresponding to the TDB light time
      C        corrected epoch at the intercept.
      C
               CALL ET2LST ( TRGEPC,
           .                 MARSID,
           .                 LON,
           .                 'PLANETOCENTRIC',
           .                 HR,
           .                 MN,
           .                 SC,
           .                 TIME,
           .                 AMPM              )
 
               WRITE (*,*) '  Local Solar Time at boresight '
           .   //          'intercept (24 Hour Clock): '
               WRITE (*,*) '     ', TIME
 
            ELSE
 
               WRITE (*,*) '   No boresight intercept to compute '
           .   //          'local solar time.'
 
            END IF
 
            END
 
 
Solution Sample Output
 
   After compiling the program, execute it:
 
      Converting UTC Time: 2018 JUN 11 19:32:00
         ET seconds past J2000:    582017589.185
      Vector: Boundary Corner 1
         Position vector of surface intercept in the IAU_MARS frame (km):
            X   =         2535.004
            Y   =        -2028.528
            Z   =         -990.594
         Planetocentric coordinates of the intercept (degrees):
            LAT =          -16.967
            LON =          -38.667
         Phase angle (degrees):                     48.207
         Solar incidence angle (degrees):           43.872
         Emission angle (degrees):                   4.798
 
      Vector: Boundary Corner 2
         Position vector of surface intercept in the IAU_MARS frame (km):
            X   =         2525.056
            Y   =        -2042.075
            Z   =         -988.196
         Planetocentric coordinates of the intercept (degrees):
            LAT =          -16.925
            LON =          -38.963
         Phase angle (degrees):                     50.707
         Solar incidence angle (degrees):           43.586
         Emission angle (degrees):                   7.432
 
      Vector: Boundary Corner 3
         Position vector of surface intercept in the IAU_MARS frame (km):
            X   =         2525.201
            Y   =        -2042.104
            Z   =         -987.770
         Planetocentric coordinates of the intercept (degrees):
            LAT =          -16.917
            LON =          -38.962
         Phase angle (degrees):                     50.708
         Solar incidence angle (degrees):           43.585
         Emission angle (degrees):                   7.413
 
      Vector: Boundary Corner 4
         Position vector of surface intercept in the IAU_MARS frame (km):
            X   =         2535.149
            Y   =        -2028.558
            Z   =         -990.170
         Planetocentric coordinates of the intercept (degrees):
            LAT =          -16.960
            LON =          -38.666
         Phase angle (degrees):                     48.208
         Solar incidence angle (degrees):           43.871
         Emission angle (degrees):                   4.769
 
      Vector: ExoMars-16 NOMAD LNO Nadir Boresight
         Position vector of surface intercept in the IAU_MARS frame (km):
            X   =         2530.122
            Y   =        -2035.307
            Z   =         -989.188
         Planetocentric coordinates of the intercept (degrees):
            LAT =          -16.942
            LON =          -38.814
         Phase angle (degrees):                     49.457
         Solar incidence angle (degrees):           43.729
         Emission angle (degrees):                   6.086
 
         Local Solar Time at boresight intercept (24 Hour Clock):
            14:51:36
 
 
Extra Credit
--------------------------------------------------------
 
   There are no ``extra credit'' tasks for this step of the lesson.
 
