home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / ephem2 / part05 < prev    next >
Text File  |  1989-11-27  |  47KB  |  1,595 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v09i042: ephem, v4.8, 5 of 5
  4. Reply-To: ecd@umn-cs.cs.umn.edu@ncs-med.UUCP (Elwood C. Downey)
  5.  
  6. Posting-number: Volume 9, Issue 42
  7. Submitted-by: ecd@umn-cs.cs.umn.edu@ncs-med.UUCP (Elwood C. Downey)
  8. Archive-name: ephem2/part05
  9.  
  10. # This is a "shell archive" file; run it with sh.
  11. # This is file 5.
  12. echo x sel_fld.c
  13. cat > sel_fld.c << 'xXx'
  14. #include <stdio.h>
  15. #include "screen.h"
  16.  
  17. /* table of the fields, with flags indicating which menu(s) they are on and
  18.  * whether pickable for changing or plotting.
  19.  * N.B. type must be long enough to hold 16 bits.
  20.  */
  21. static int fields[] = {
  22.     rcfpack (R_ALTM,    C_ALTM,        F_MMNU|F_CHG),
  23.     rcfpack (R_DAWN,    C_DAWN,        F_MMNU|F_CHG),
  24.     rcfpack (R_DAWN,    C_DAWNV,    F_MMNU|F_PLT),
  25.     rcfpack (R_DUSK,    C_DUSK,        F_MMNU|F_CHG),
  26.     rcfpack (R_DUSK,    C_DUSKV,    F_MMNU|F_PLT),
  27.     rcfpack (R_EPOCH,    C_EPOCHV,    F_MMNU|F_CHG),
  28.     rcfpack (R_HEIGHT,    C_HEIGHTV,    F_MMNU|F_CHG|F_PLT),
  29.     rcfpack (R_JD,    C_JDV,        F_MMNU|F_CHG|F_PLT),
  30.     rcfpack (R_JUPITER,    C_ALT,        F_MNU1|F_PLT),
  31.     rcfpack (R_JUPITER,    C_AZ,        F_MNU1|F_PLT),
  32.     rcfpack (R_JUPITER,    C_DEC,        F_MNU1|F_PLT),
  33.     rcfpack (R_JUPITER,    C_EDIST,    F_MNU1|F_PLT),
  34.     rcfpack (R_JUPITER,    C_ELONG,    F_MNU1|F_PLT),
  35.     rcfpack (R_JUPITER,    C_HLAT,        F_MNU1|F_PLT),
  36.     rcfpack (R_JUPITER,    C_HLONG,    F_MNU1|F_PLT),
  37.     rcfpack (R_JUPITER,    C_MAG,        F_MNU1|F_PLT),
  38.     rcfpack (R_JUPITER,    C_MARS,        F_MNU3|F_PLT),
  39.     rcfpack (R_JUPITER,    C_MERCURY,    F_MNU3|F_PLT),
  40.     rcfpack (R_JUPITER,    C_MOON,        F_MNU3|F_PLT),
  41.     rcfpack (R_JUPITER,    C_NEPTUNE,    F_MNU3|F_PLT),
  42.     rcfpack (R_JUPITER,    C_OBJ,        F_MMNU|F_CHG),
  43.     rcfpack (R_JUPITER,    C_OBJX,        F_MNU3|F_PLT),
  44.     rcfpack (R_JUPITER,    C_PHASE,    F_MNU1|F_PLT),
  45.     rcfpack (R_JUPITER,    C_PLUTO,    F_MNU3|F_PLT),
  46.     rcfpack (R_JUPITER,    C_RA,        F_MNU1|F_PLT),
  47.     rcfpack (R_JUPITER,    C_RISEAZ,    F_MNU2|F_PLT),
  48.     rcfpack (R_JUPITER,    C_RISETM,    F_MNU2|F_PLT),
  49.     rcfpack (R_JUPITER,    C_SATURN,    F_MNU3|F_PLT),
  50.     rcfpack (R_JUPITER,    C_SDIST,    F_MNU1|F_PLT),
  51.     rcfpack (R_JUPITER,    C_SETAZ,    F_MNU2|F_PLT),
  52.     rcfpack (R_JUPITER,    C_SETTM,    F_MNU2|F_PLT),
  53.     rcfpack (R_JUPITER,    C_SIZE,        F_MNU1|F_PLT),
  54.     rcfpack (R_JUPITER,    C_SUN,        F_MNU3|F_PLT),
  55.     rcfpack (R_JUPITER,    C_TRANSALT,    F_MNU2|F_PLT),
  56.     rcfpack (R_JUPITER,    C_TRANSTM,    F_MNU2|F_PLT),
  57.     rcfpack (R_JUPITER,    C_TUP,        F_MNU2|F_PLT),
  58.     rcfpack (R_JUPITER,    C_URANUS,    F_MNU3|F_PLT),
  59.     rcfpack (R_JUPITER,    C_VENUS,    F_MNU3|F_PLT),
  60.     rcfpack (R_LAT,    C_LATV,        F_MMNU|F_CHG|F_PLT),
  61.     rcfpack (R_LD,    C_LD,        F_MMNU|F_PLT|F_CHG),
  62.     rcfpack (R_LON,    C_LON,        F_MMNU|F_CHG),
  63.     rcfpack (R_LON,    C_LONV,        F_MMNU|F_PLT),
  64.     rcfpack (R_LONG,    C_LONGV,    F_MMNU|F_CHG|F_PLT),
  65.     rcfpack (R_LST,    C_LSTV,        F_MMNU|F_CHG|F_PLT),
  66.     rcfpack (R_LT,    C_LT,        F_MMNU|F_CHG|F_PLT),
  67.     rcfpack (R_MARS,    C_ALT,        F_MNU1|F_PLT),
  68.     rcfpack (R_MARS,    C_AZ,        F_MNU1|F_PLT),
  69.     rcfpack (R_MARS,    C_DEC,        F_MNU1|F_PLT),
  70.     rcfpack (R_MARS,    C_EDIST,    F_MNU1|F_PLT),
  71.     rcfpack (R_MARS,    C_ELONG,    F_MNU1|F_PLT),
  72.     rcfpack (R_MARS,    C_HLAT,        F_MNU1|F_PLT),
  73.     rcfpack (R_MARS,    C_HLONG,    F_MNU1|F_PLT),
  74.     rcfpack (R_MARS,    C_JUPITER,    F_MNU3|F_PLT),
  75.     rcfpack (R_MARS,    C_MAG,        F_MNU1|F_PLT),
  76.     rcfpack (R_MARS,    C_MERCURY,    F_MNU3|F_PLT),
  77.     rcfpack (R_MARS,    C_MOON,        F_MNU3|F_PLT),
  78.     rcfpack (R_MARS,    C_NEPTUNE,    F_MNU3|F_PLT),
  79.     rcfpack (R_MARS,    C_OBJ,        F_MMNU|F_CHG),
  80.     rcfpack (R_MARS,    C_OBJX,        F_MNU3|F_PLT),
  81.     rcfpack (R_MARS,    C_PHASE,    F_MNU1|F_PLT),
  82.     rcfpack (R_MARS,    C_PLUTO,    F_MNU3|F_PLT),
  83.     rcfpack (R_MARS,    C_RA,        F_MNU1|F_PLT),
  84.     rcfpack (R_MARS,    C_RISEAZ,    F_MNU2|F_PLT),
  85.     rcfpack (R_MARS,    C_RISETM,    F_MNU2|F_PLT),
  86.     rcfpack (R_MARS,    C_SATURN,    F_MNU3|F_PLT),
  87.     rcfpack (R_MARS,    C_SDIST,    F_MNU1|F_PLT),
  88.     rcfpack (R_MARS,    C_SETAZ,    F_MNU2|F_PLT),
  89.     rcfpack (R_MARS,    C_SETTM,    F_MNU2|F_PLT),
  90.     rcfpack (R_MARS,    C_SIZE,        F_MNU1|F_PLT),
  91.     rcfpack (R_MARS,    C_SUN,        F_MNU3|F_PLT),
  92.     rcfpack (R_MARS,    C_TRANSALT,    F_MNU2|F_PLT),
  93.     rcfpack (R_MARS,    C_TRANSTM,    F_MNU2|F_PLT),
  94.     rcfpack (R_MARS,    C_TUP,        F_MNU2|F_PLT),
  95.     rcfpack (R_MARS,    C_URANUS,    F_MNU3|F_PLT),
  96.     rcfpack (R_MARS,    C_VENUS,    F_MNU3|F_PLT),
  97.     rcfpack (R_MERCURY,    C_ALT,        F_MNU1|F_PLT),
  98.     rcfpack (R_MERCURY,    C_AZ,        F_MNU1|F_PLT),
  99.     rcfpack (R_MERCURY,    C_DEC,        F_MNU1|F_PLT),
  100.     rcfpack (R_MERCURY,    C_EDIST,    F_MNU1|F_PLT),
  101.     rcfpack (R_MERCURY,    C_ELONG,    F_MNU1|F_PLT),
  102.     rcfpack (R_MERCURY,    C_HLAT,        F_MNU1|F_PLT),
  103.     rcfpack (R_MERCURY,    C_HLONG,    F_MNU1|F_PLT),
  104.     rcfpack (R_MERCURY,    C_JUPITER,    F_MNU3|F_PLT),
  105.     rcfpack (R_MERCURY,    C_MAG,        F_MNU1|F_PLT),
  106.     rcfpack (R_MERCURY,    C_MARS,        F_MNU3|F_PLT),
  107.     rcfpack (R_MERCURY,    C_MOON,        F_MNU3|F_PLT),
  108.     rcfpack (R_MERCURY,    C_NEPTUNE,    F_MNU3|F_PLT),
  109.     rcfpack (R_MERCURY,    C_OBJ,        F_MMNU|F_CHG),
  110.     rcfpack (R_MERCURY,    C_OBJX,        F_MNU3|F_PLT),
  111.     rcfpack (R_MERCURY,    C_PHASE,    F_MNU1|F_PLT),
  112.     rcfpack (R_MERCURY,    C_PLUTO,    F_MNU3|F_PLT),
  113.     rcfpack (R_MERCURY,    C_RA,        F_MNU1|F_PLT),
  114.     rcfpack (R_MERCURY,    C_RISEAZ,    F_MNU2|F_PLT),
  115.     rcfpack (R_MERCURY,    C_RISETM,    F_MNU2|F_PLT),
  116.     rcfpack (R_MERCURY,    C_SATURN,    F_MNU3|F_PLT),
  117.     rcfpack (R_MERCURY,    C_SDIST,    F_MNU1|F_PLT),
  118.     rcfpack (R_MERCURY,    C_SETAZ,    F_MNU2|F_PLT),
  119.     rcfpack (R_MERCURY,    C_SETTM,    F_MNU2|F_PLT),
  120.     rcfpack (R_MERCURY,    C_SIZE,        F_MNU1|F_PLT),
  121.     rcfpack (R_MERCURY,    C_SUN,        F_MNU3|F_PLT),
  122.     rcfpack (R_MERCURY,    C_TRANSALT,    F_MNU2|F_PLT),
  123.     rcfpack (R_MERCURY,    C_TRANSTM,    F_MNU2|F_PLT),
  124.     rcfpack (R_MERCURY,    C_TUP,        F_MNU2|F_PLT),
  125.     rcfpack (R_MERCURY,    C_URANUS,    F_MNU3|F_PLT),
  126.     rcfpack (R_MERCURY,    C_VENUS,    F_MNU3|F_PLT),
  127.     rcfpack (R_MOON,    C_ALT,        F_MNU1|F_PLT),
  128.     rcfpack (R_MOON,    C_AZ,        F_MNU1|F_PLT),
  129.     rcfpack (R_MOON,    C_DEC,        F_MNU1|F_PLT),
  130.     rcfpack (R_MOON,    C_EDIST,    F_MNU1|F_PLT),
  131.     rcfpack (R_MOON,    C_ELONG,    F_MNU1|F_PLT),
  132.     rcfpack (R_MOON,    C_JUPITER,    F_MNU3|F_PLT),
  133.     rcfpack (R_MOON,    C_MAG,        F_MNU1|F_PLT),
  134.     rcfpack (R_MOON,    C_MARS,        F_MNU3|F_PLT),
  135.     rcfpack (R_MOON,    C_MERCURY,    F_MNU3|F_PLT),
  136.     rcfpack (R_MOON,    C_NEPTUNE,    F_MNU3|F_PLT),
  137.     rcfpack (R_MOON,    C_OBJ,        F_MMNU|F_CHG),
  138.     rcfpack (R_MOON,    C_OBJX,        F_MNU3|F_PLT),
  139.     rcfpack (R_MOON,    C_PHASE,    F_MNU1|F_PLT),
  140.     rcfpack (R_MOON,    C_PLUTO,    F_MNU3|F_PLT),
  141.     rcfpack (R_MOON,    C_RA,        F_MNU1|F_PLT),
  142.     rcfpack (R_MOON,    C_RISEAZ,    F_MNU2|F_PLT),
  143.     rcfpack (R_MOON,    C_RISETM,    F_MNU2|F_PLT),
  144.     rcfpack (R_MOON,    C_SATURN,    F_MNU3|F_PLT),
  145.     rcfpack (R_MOON,    C_SDIST,    F_MNU1|F_PLT),
  146.     rcfpack (R_MOON,    C_SETAZ,    F_MNU2|F_PLT),
  147.     rcfpack (R_MOON,    C_SETTM,    F_MNU2|F_PLT),
  148.     rcfpack (R_MOON,    C_SIZE,        F_MNU1|F_PLT),
  149.     rcfpack (R_MOON,    C_SUN,        F_MNU3|F_PLT),
  150.     rcfpack (R_MOON,    C_TRANSALT,    F_MNU2|F_PLT),
  151.     rcfpack (R_MOON,    C_TRANSTM,    F_MNU2|F_PLT),
  152.     rcfpack (R_MOON,    C_TUP,        F_MNU2|F_PLT),
  153.     rcfpack (R_MOON,    C_URANUS,    F_MNU3|F_PLT),
  154.     rcfpack (R_MOON,    C_VENUS,    F_MNU3|F_PLT),
  155.     rcfpack (R_NEPTUNE,    C_ALT,        F_MNU1|F_PLT),
  156.     rcfpack (R_NEPTUNE,    C_AZ,        F_MNU1|F_PLT),
  157.     rcfpack (R_NEPTUNE,    C_DEC,        F_MNU1|F_PLT),
  158.     rcfpack (R_NEPTUNE,    C_EDIST,    F_MNU1|F_PLT),
  159.     rcfpack (R_NEPTUNE,    C_ELONG,    F_MNU1|F_PLT),
  160.     rcfpack (R_NEPTUNE,    C_HLAT,        F_MNU1|F_PLT),
  161.     rcfpack (R_NEPTUNE,    C_HLONG,    F_MNU1|F_PLT),
  162.     rcfpack (R_NEPTUNE,    C_JUPITER,    F_MNU3|F_PLT),
  163.     rcfpack (R_NEPTUNE,    C_MAG,        F_MNU1|F_PLT),
  164.     rcfpack (R_NEPTUNE,    C_MARS,        F_MNU3|F_PLT),
  165.     rcfpack (R_NEPTUNE,    C_MERCURY,    F_MNU3|F_PLT),
  166.     rcfpack (R_NEPTUNE,    C_MOON,        F_MNU3|F_PLT),
  167.     rcfpack (R_NEPTUNE,    C_OBJ,        F_MMNU|F_CHG),
  168.     rcfpack (R_NEPTUNE,    C_OBJX,        F_MNU3|F_PLT),
  169.     rcfpack (R_NEPTUNE,    C_PHASE,    F_MNU1|F_PLT),
  170.     rcfpack (R_NEPTUNE,    C_PLUTO,    F_MNU3|F_PLT),
  171.     rcfpack (R_NEPTUNE,    C_RA,        F_MNU1|F_PLT),
  172.     rcfpack (R_NEPTUNE,    C_RISEAZ,    F_MNU2|F_PLT),
  173.     rcfpack (R_NEPTUNE,    C_RISETM,    F_MNU2|F_PLT),
  174.     rcfpack (R_NEPTUNE,    C_SATURN,    F_MNU3|F_PLT),
  175.     rcfpack (R_NEPTUNE,    C_SDIST,    F_MNU1|F_PLT),
  176.     rcfpack (R_NEPTUNE,    C_SETAZ,    F_MNU2|F_PLT),
  177.     rcfpack (R_NEPTUNE,    C_SETTM,    F_MNU2|F_PLT),
  178.     rcfpack (R_NEPTUNE,    C_SIZE,        F_MNU1|F_PLT),
  179.     rcfpack (R_NEPTUNE,    C_SUN,        F_MNU3|F_PLT),
  180.     rcfpack (R_NEPTUNE,    C_TRANSALT,    F_MNU2|F_PLT),
  181.     rcfpack (R_NEPTUNE,    C_TRANSTM,    F_MNU2|F_PLT),
  182.     rcfpack (R_NEPTUNE,    C_TUP,        F_MNU2|F_PLT),
  183.     rcfpack (R_NEPTUNE,    C_URANUS,    F_MNU3|F_PLT),
  184.     rcfpack (R_NEPTUNE,    C_VENUS,    F_MNU3|F_PLT),
  185.     rcfpack (R_NSTEP,    C_NSTEPV,    F_MMNU|F_CHG),
  186.     rcfpack (R_OBJX,    C_ALT,        F_MNU1|F_PLT),
  187.     rcfpack (R_OBJX,    C_AZ,        F_MNU1|F_PLT),
  188.     rcfpack (R_OBJX,    C_DEC,        F_MNU1|F_CHG|F_PLT),
  189.     rcfpack (R_OBJX,    C_ELONG,    F_MNU1|F_PLT),
  190.     rcfpack (R_OBJX,    C_JUPITER,    F_MNU3|F_PLT),
  191.     rcfpack (R_OBJX,    C_MARS,        F_MNU3|F_PLT),
  192.     rcfpack (R_OBJX,    C_MERCURY,    F_MNU3|F_PLT),
  193.     rcfpack (R_OBJX,    C_MOON,        F_MNU3|F_PLT),
  194.     rcfpack (R_OBJX,    C_NEPTUNE,    F_MNU3|F_PLT),
  195.     rcfpack (R_OBJX,    C_OBJ,        F_MMNU|F_CHG),
  196.     rcfpack (R_OBJX,    C_PLUTO,    F_MNU3|F_PLT),
  197.     rcfpack (R_OBJX,    C_RA,        F_MNU1|F_CHG|F_PLT),
  198.     rcfpack (R_OBJX,    C_RISEAZ,    F_MNU2|F_PLT),
  199.     rcfpack (R_OBJX,    C_RISETM,    F_MNU2|F_PLT),
  200.     rcfpack (R_OBJX,    C_SATURN,    F_MNU3|F_PLT),
  201.     rcfpack (R_OBJX,    C_SETAZ,    F_MNU2|F_PLT),
  202.     rcfpack (R_OBJX,    C_SETTM,    F_MNU2|F_PLT),
  203.     rcfpack (R_OBJX,    C_SUN,        F_MNU3|F_PLT),
  204.     rcfpack (R_OBJX,    C_TRANSALT,    F_MNU2|F_PLT),
  205.     rcfpack (R_OBJX,    C_TRANSTM,    F_MNU2|F_PLT),
  206.     rcfpack (R_OBJX,    C_TUP,        F_MNU2|F_PLT),
  207.     rcfpack (R_OBJX,    C_URANUS,    F_MNU3|F_PLT),
  208.     rcfpack (R_OBJX,    C_VENUS,    F_MNU3|F_PLT),
  209.     rcfpack (R_PLOT,    C_PLOT,        F_MMNU|F_CHG),
  210.     rcfpack (R_PLUTO,    C_ALT,        F_MNU1|F_PLT),
  211.     rcfpack (R_PLUTO,    C_AZ,        F_MNU1|F_PLT),
  212.     rcfpack (R_PLUTO,    C_DEC,        F_MNU1|F_PLT),
  213.     rcfpack (R_PLUTO,    C_EDIST,    F_MNU1|F_PLT),
  214.     rcfpack (R_PLUTO,    C_ELONG,    F_MNU1|F_PLT),
  215.     rcfpack (R_PLUTO,    C_HLAT,        F_MNU1|F_PLT),
  216.     rcfpack (R_PLUTO,    C_HLONG,    F_MNU1|F_PLT),
  217.     rcfpack (R_PLUTO,    C_JUPITER,    F_MNU3|F_PLT),
  218.     rcfpack (R_PLUTO,    C_MAG,        F_MNU1|F_PLT),
  219.     rcfpack (R_PLUTO,    C_MARS,        F_MNU3|F_PLT),
  220.     rcfpack (R_PLUTO,    C_MERCURY,    F_MNU3|F_PLT),
  221.     rcfpack (R_PLUTO,    C_MOON,        F_MNU3|F_PLT),
  222.     rcfpack (R_PLUTO,    C_NEPTUNE,    F_MNU3|F_PLT),
  223.     rcfpack (R_PLUTO,    C_OBJ,        F_MMNU|F_CHG),
  224.     rcfpack (R_PLUTO,    C_OBJX,        F_MNU3|F_PLT),
  225.     rcfpack (R_PLUTO,    C_PHASE,    F_MNU1|F_PLT),
  226.     rcfpack (R_PLUTO,    C_RA,        F_MNU1|F_PLT),
  227.     rcfpack (R_PLUTO,    C_RISEAZ,    F_MNU2|F_PLT),
  228.     rcfpack (R_PLUTO,    C_RISETM,    F_MNU2|F_PLT),
  229.     rcfpack (R_PLUTO,    C_SATURN,    F_MNU3|F_PLT),
  230.     rcfpack (R_PLUTO,    C_SDIST,    F_MNU1|F_PLT),
  231.     rcfpack (R_PLUTO,    C_SETAZ,    F_MNU2|F_PLT),
  232.     rcfpack (R_PLUTO,    C_SETTM,    F_MNU2|F_PLT),
  233.     rcfpack (R_PLUTO,    C_SIZE,        F_MNU1|F_PLT),
  234.     rcfpack (R_PLUTO,    C_SUN,        F_MNU3|F_PLT),
  235.     rcfpack (R_PLUTO,    C_TRANSALT,    F_MNU2|F_PLT),
  236.     rcfpack (R_PLUTO,    C_TRANSTM,    F_MNU2|F_PLT),
  237.     rcfpack (R_PLUTO,    C_TUP,        F_MNU2|F_PLT),
  238.     rcfpack (R_PLUTO,    C_URANUS,    F_MNU3|F_PLT),
  239.     rcfpack (R_PLUTO,    C_VENUS,    F_MNU3|F_PLT),
  240.     rcfpack (R_PRES,    C_PRESV,    F_MMNU|F_CHG|F_PLT),
  241.     rcfpack (R_SATURN,    C_ALT,        F_MNU1|F_PLT),
  242.     rcfpack (R_SATURN,    C_AZ,        F_MNU1|F_PLT),
  243.     rcfpack (R_SATURN,    C_DEC,        F_MNU1|F_PLT),
  244.     rcfpack (R_SATURN,    C_EDIST,    F_MNU1|F_PLT),
  245.     rcfpack (R_SATURN,    C_ELONG,    F_MNU1|F_PLT),
  246.     rcfpack (R_SATURN,    C_HLAT,        F_MNU1|F_PLT),
  247.     rcfpack (R_SATURN,    C_HLONG,    F_MNU1|F_PLT),
  248.     rcfpack (R_SATURN,    C_JUPITER,    F_MNU3|F_PLT),
  249.     rcfpack (R_SATURN,    C_MAG,        F_MNU1|F_PLT),
  250.     rcfpack (R_SATURN,    C_MARS,        F_MNU3|F_PLT),
  251.     rcfpack (R_SATURN,    C_MERCURY,    F_MNU3|F_PLT),
  252.     rcfpack (R_SATURN,    C_MOON,        F_MNU3|F_PLT),
  253.     rcfpack (R_SATURN,    C_NEPTUNE,    F_MNU3|F_PLT),
  254.     rcfpack (R_SATURN,    C_OBJ,        F_MMNU|F_CHG),
  255.     rcfpack (R_SATURN,    C_OBJX,        F_MNU3|F_PLT),
  256.     rcfpack (R_SATURN,    C_PHASE,    F_MNU1|F_PLT),
  257.     rcfpack (R_SATURN,    C_PLUTO,    F_MNU3|F_PLT),
  258.     rcfpack (R_SATURN,    C_RA,        F_MNU1|F_PLT),
  259.     rcfpack (R_SATURN,    C_RISEAZ,    F_MNU2|F_PLT),
  260.     rcfpack (R_SATURN,    C_RISETM,    F_MNU2|F_PLT),
  261.     rcfpack (R_SATURN,    C_SDIST,    F_MNU1|F_PLT),
  262.     rcfpack (R_SATURN,    C_SETAZ,    F_MNU2|F_PLT),
  263.     rcfpack (R_SATURN,    C_SETTM,    F_MNU2|F_PLT),
  264.     rcfpack (R_SATURN,    C_SIZE,        F_MNU1|F_PLT),
  265.     rcfpack (R_SATURN,    C_SUN,        F_MNU3|F_PLT),
  266.     rcfpack (R_SATURN,    C_TRANSALT,    F_MNU2|F_PLT),
  267.     rcfpack (R_SATURN,    C_TRANSTM,    F_MNU2|F_PLT),
  268.     rcfpack (R_SATURN,    C_TUP,        F_MNU2|F_PLT),
  269.     rcfpack (R_SATURN,    C_URANUS,    F_MNU3|F_PLT),
  270.     rcfpack (R_SATURN,    C_VENUS,    F_MNU3|F_PLT),
  271.     rcfpack (R_SRCH,    C_SRCH,        F_MMNU|F_CHG|F_PLT),
  272.     rcfpack (R_STPSZ,    C_STPSZV,    F_MMNU|F_CHG),
  273.     rcfpack (R_SUN,    C_ALT,        F_MNU1|F_PLT),
  274.     rcfpack (R_SUN,    C_AZ,        F_MNU1|F_PLT),
  275.     rcfpack (R_SUN,    C_DEC,        F_MNU1|F_PLT),
  276.     rcfpack (R_SUN,    C_EDIST,    F_MNU1|F_PLT),
  277.     rcfpack (R_SUN,    C_HLAT,        F_MNU1|F_PLT),
  278.     rcfpack (R_SUN,    C_HLONG,    F_MNU1|F_PLT),
  279.     rcfpack (R_SUN,    C_JUPITER,    F_MNU3|F_PLT),
  280.     rcfpack (R_SUN,    C_MAG,        F_MNU1|F_PLT),
  281.     rcfpack (R_SUN,    C_MARS,        F_MNU3|F_PLT),
  282.     rcfpack (R_SUN,    C_MERCURY,    F_MNU3|F_PLT),
  283.     rcfpack (R_SUN,    C_MOON,        F_MNU3|F_PLT),
  284.     rcfpack (R_SUN,    C_NEPTUNE,    F_MNU3|F_PLT),
  285.     rcfpack (R_SUN,    C_OBJ,        F_MMNU|F_CHG),
  286.     rcfpack (R_SUN,    C_OBJX,        F_MNU3|F_PLT),
  287.     rcfpack (R_SUN,    C_PLUTO,    F_MNU3|F_PLT),
  288.     rcfpack (R_SUN,    C_RA,        F_MNU1|F_PLT),
  289.     rcfpack (R_SUN,    C_RISEAZ,    F_MNU2|F_PLT),
  290.     rcfpack (R_SUN,    C_RISETM,    F_MNU2|F_PLT),
  291.     rcfpack (R_SUN,    C_SATURN,    F_MNU3|F_PLT),
  292.     rcfpack (R_SUN,    C_SETAZ,    F_MNU2|F_PLT),
  293.     rcfpack (R_SUN,    C_SETTM,    F_MNU2|F_PLT),
  294.     rcfpack (R_SUN,    C_SIZE,        F_MNU1|F_PLT),
  295.     rcfpack (R_SUN,    C_TRANSALT,    F_MNU2|F_PLT),
  296.     rcfpack (R_SUN,    C_TRANSTM,    F_MNU2|F_PLT),
  297.     rcfpack (R_SUN,    C_TUP,        F_MNU2|F_PLT),
  298.     rcfpack (R_SUN,    C_URANUS,    F_MNU3|F_PLT),
  299.     rcfpack (R_SUN,    C_VENUS,    F_MNU3|F_PLT),
  300.     rcfpack (R_TEMP,    C_TEMPV,    F_MMNU|F_CHG|F_PLT),
  301.     rcfpack (R_TZN,    C_TZN,        F_MMNU|F_CHG),
  302.     rcfpack (R_TZONE,    C_TZONEV,    F_MMNU|F_CHG),
  303.     rcfpack (R_UD,    C_UD,        F_MMNU|F_PLT|F_CHG),
  304.     rcfpack (R_URANUS,    C_ALT,        F_MNU1|F_PLT),
  305.     rcfpack (R_URANUS,    C_AZ,        F_MNU1|F_PLT),
  306.     rcfpack (R_URANUS,    C_DEC,        F_MNU1|F_PLT),
  307.     rcfpack (R_URANUS,    C_EDIST,    F_MNU1|F_PLT),
  308.     rcfpack (R_URANUS,    C_ELONG,    F_MNU1|F_PLT),
  309.     rcfpack (R_URANUS,    C_HLAT,        F_MNU1|F_PLT),
  310.     rcfpack (R_URANUS,    C_HLONG,    F_MNU1|F_PLT),
  311.     rcfpack (R_URANUS,    C_JUPITER,    F_MNU3|F_PLT),
  312.     rcfpack (R_URANUS,    C_MAG,        F_MNU1|F_PLT),
  313.     rcfpack (R_URANUS,    C_MARS,        F_MNU3|F_PLT),
  314.     rcfpack (R_URANUS,    C_MERCURY,    F_MNU3|F_PLT),
  315.     rcfpack (R_URANUS,    C_MOON,        F_MNU3|F_PLT),
  316.     rcfpack (R_URANUS,    C_NEPTUNE,    F_MNU3|F_PLT),
  317.     rcfpack (R_URANUS,    C_OBJ,        F_MMNU|F_CHG),
  318.     rcfpack (R_URANUS,    C_OBJX,        F_MNU3|F_PLT),
  319.     rcfpack (R_URANUS,    C_PHASE,    F_MNU1|F_PLT),
  320.     rcfpack (R_URANUS,    C_PLUTO,    F_MNU3|F_PLT),
  321.     rcfpack (R_URANUS,    C_RA,        F_MNU1|F_PLT),
  322.     rcfpack (R_URANUS,    C_RISEAZ,    F_MNU2|F_PLT),
  323.     rcfpack (R_URANUS,    C_RISETM,    F_MNU2|F_PLT),
  324.     rcfpack (R_URANUS,    C_SATURN,    F_MNU3|F_PLT),
  325.     rcfpack (R_URANUS,    C_SDIST,    F_MNU1|F_PLT),
  326.     rcfpack (R_URANUS,    C_SETAZ,    F_MNU2|F_PLT),
  327.     rcfpack (R_URANUS,    C_SETTM,    F_MNU2|F_PLT),
  328.     rcfpack (R_URANUS,    C_SIZE,        F_MNU1|F_PLT),
  329.     rcfpack (R_URANUS,    C_SUN,        F_MNU3|F_PLT),
  330.     rcfpack (R_URANUS,    C_TRANSALT,    F_MNU2|F_PLT),
  331.     rcfpack (R_URANUS,    C_TRANSTM,    F_MNU2|F_PLT),
  332.     rcfpack (R_URANUS,    C_TUP,        F_MNU2|F_PLT),
  333.     rcfpack (R_URANUS,    C_VENUS,    F_MNU3|F_PLT),
  334.     rcfpack (R_UT,    C_UTV,        F_MMNU|F_PLT|F_CHG),
  335.     rcfpack (R_VENUS,    C_ALT,        F_MNU1|F_PLT),
  336.     rcfpack (R_VENUS,    C_AZ,        F_MNU1|F_PLT),
  337.     rcfpack (R_VENUS,    C_DEC,        F_MNU1|F_PLT),
  338.     rcfpack (R_VENUS,    C_EDIST,    F_MNU1|F_PLT),
  339.     rcfpack (R_VENUS,    C_ELONG,    F_MNU1|F_PLT),
  340.     rcfpack (R_VENUS,    C_HLAT,        F_MNU1|F_PLT),
  341.     rcfpack (R_VENUS,    C_HLONG,    F_MNU1|F_PLT),
  342.     rcfpack (R_VENUS,    C_JUPITER,    F_MNU3|F_PLT),
  343.     rcfpack (R_VENUS,    C_MAG,        F_MNU1|F_PLT),
  344.     rcfpack (R_VENUS,    C_MARS,        F_MNU3|F_PLT),
  345.     rcfpack (R_VENUS,    C_MERCURY,    F_MNU3|F_PLT),
  346.     rcfpack (R_VENUS,    C_MOON,        F_MNU3|F_PLT),
  347.     rcfpack (R_VENUS,    C_NEPTUNE,    F_MNU3|F_PLT),
  348.     rcfpack (R_VENUS,    C_OBJ,        F_MMNU|F_CHG),
  349.     rcfpack (R_VENUS,    C_OBJX,        F_MNU3|F_PLT),
  350.     rcfpack (R_VENUS,    C_PHASE,    F_MNU1|F_PLT),
  351.     rcfpack (R_VENUS,    C_PLUTO,    F_MNU3|F_PLT),
  352.     rcfpack (R_VENUS,    C_RA,        F_MNU1|F_PLT),
  353.     rcfpack (R_VENUS,    C_RISEAZ,    F_MNU2|F_PLT),
  354.     rcfpack (R_VENUS,    C_RISETM,    F_MNU2|F_PLT),
  355.     rcfpack (R_VENUS,    C_SATURN,    F_MNU3|F_PLT),
  356.     rcfpack (R_VENUS,    C_SDIST,    F_MNU1|F_PLT),
  357.     rcfpack (R_VENUS,    C_SETAZ,    F_MNU2|F_PLT),
  358.     rcfpack (R_VENUS,    C_SETTM,    F_MNU2|F_PLT),
  359.     rcfpack (R_VENUS,    C_SIZE,        F_MNU1|F_PLT),
  360.     rcfpack (R_VENUS,    C_SUN,        F_MNU3|F_PLT),
  361.     rcfpack (R_VENUS,    C_TRANSALT,    F_MNU2|F_PLT),
  362.     rcfpack (R_VENUS,    C_TRANSTM,    F_MNU2|F_PLT),
  363.     rcfpack (R_VENUS,    C_TUP,        F_MNU2|F_PLT),
  364.     rcfpack (R_VENUS,    C_URANUS,    F_MNU3|F_PLT),
  365.     rcfpack (R_WATCH,    C_WATCH,    F_MMNU|F_CHG),
  366. };
  367. #define    NFIELDS (sizeof(fields)/sizeof(fields[0]))
  368.  
  369. /* let op select a field by moving around and hitting RETURN, or until see END.
  370.  * also allow moving directly to a planet row using its name.
  371.  * only allow fields with the given flag mask.
  372.  * return the rcfpack()'d field, or 0 if typed END.
  373.  * N.B. we might also exit() entirely by calling bye() if op types QUIT.
  374.  */
  375. sel_fld (r, c, flag, prmpt, help)
  376. int r, c;    /* inial row, col */
  377. int flag;
  378. char *prmpt, *help;
  379. {
  380.     extern void bye();
  381.     char *lastp;
  382.     int ch;
  383.  
  384.     lastp = 0;
  385.     while (1) {
  386.         if (lastp != prmpt) {
  387.         lastp = prmpt;
  388.         f_prompt (lastp);
  389.         }
  390.         c_pos (r, c);
  391.         switch (ch = read_char()) {
  392.         case REDRAW:
  393.         redraw_screen(2);    /* redraw all from scratch */
  394.         lastp = 0;
  395.         break;
  396.         case VERSION:
  397.         version();
  398.         lastp = 0;
  399.         break;
  400.         case HELP:
  401.         f_prompt (help);
  402.         (void) read_char();
  403.         lastp = 0;
  404.         break;
  405.         case QUIT:
  406.         bye();    /* probably never returns */
  407.         break;
  408.         case END:
  409.         return (0);
  410.         case '\r':
  411.         return (rcfpack (r, c, 0));
  412.         default:
  413.         move_cur (ch, flag, &r, &c);
  414.         break;
  415.         }
  416.     }
  417. }
  418.  
  419. /* move cursor to next field in given direction: hjkl, or directly to a
  420.  * planet row, and set *rp and *cp.
  421.  * limit eligible fields to those with given flag mask.
  422.  */
  423. static
  424. move_cur (dirchar, flag, rp, cp)
  425. char dirchar;
  426. int flag;
  427. int *rp, *cp;
  428. {
  429.     int curr = *rp, curc = *cp;
  430.     int f, newf, *fp;
  431.     int d, newd;
  432.  
  433.     wrapped:
  434.     newf = 0;
  435.     newd = 1000;
  436.  
  437.     switch (dirchar) {
  438.     case 'h': /* left */
  439.         /* go to next field to the left, or wrap.  */
  440.         for (fp = fields+NFIELDS; --fp >= fields; ) {
  441.         f = *fp;
  442.         if (tstpackf(f,flag) && unpackr(f) == curr) {
  443.             d = curc - unpackc(f);
  444.             if (d > 0 && d < newd) {
  445.             newf = f;
  446.             newd = d;
  447.             }
  448.         }
  449.         }
  450.         if (!newf) {
  451.         curc = NC;
  452.         goto wrapped;
  453.         }
  454.         break;
  455.  
  456.     case 'j': /* down */
  457.         /* go to closest field on next row down with anything on it,
  458.          * or wrap.
  459.          */
  460.         for (fp = fields+NFIELDS; --fp >= fields; ) {
  461.         f = *fp;
  462.         if (tstpackf(f,flag)) {
  463.             d = unpackr(f) - curr;
  464.             if (d > 0 && d < newd) {
  465.             newf = f;
  466.             newd = d;
  467.             }
  468.         }
  469.         }
  470.         if (newf) {
  471.         /* now find the field closest to current col on that row */
  472.         newf = nearestfld (unpackr(newf), curc, flag);
  473.         } else {
  474.         curr = 0;
  475.         goto wrapped;
  476.         }
  477.         break;
  478.  
  479.     case 'k': /* up */
  480.         /* go to closest field on next row up with anything on it, 
  481.          * or wrap.
  482.          */
  483.         for (fp = fields+NFIELDS; --fp >= fields; ) {
  484.         f = *fp;
  485.         if (tstpackf(f,flag)) {
  486.             d = curr - unpackr(f);
  487.             if (d > 0 && d < newd) {
  488.             newf = f;
  489.             newd = d;
  490.             }
  491.         }
  492.         }
  493.         if (newf) {
  494.         /* now find the field closest to current col on that row */
  495.         newf = nearestfld (unpackr(newf), curc, flag);
  496.         } else {
  497.         curr = NR+1;
  498.         goto wrapped;
  499.         }
  500.         break;
  501.  
  502.     case 'l': /* right */
  503.         /* go to next field to the right, or wrap.  */
  504.         for (fp = fields+NFIELDS; --fp >= fields; ) {
  505.         f = *fp;
  506.         if (tstpackf(f,flag) && unpackr(f) == curr) {
  507.             d = unpackc(f) - curc;
  508.             if (d > 0 && d < newd) {
  509.             newf = f;
  510.             newd = d;
  511.             }
  512.         }
  513.         }
  514.         if (!newf) {
  515.         curc = 0;
  516.         goto wrapped;
  517.         }
  518.         break;
  519.  
  520.     /* shorthands directly to a given planet row */
  521.     case 'S': newf = nearestfld (R_SUN, 1, flag); break;
  522.     case 'M': newf = nearestfld (R_MOON, 1, flag); break;
  523.     case 'e': newf = nearestfld (R_MERCURY, 1, flag); break;
  524.     case 'v': newf = nearestfld (R_VENUS, 1, flag); break;
  525.     case 'm': newf = nearestfld (R_MARS, 1, flag); break;
  526.     case cntrl('j'): newf = nearestfld (R_JUPITER, 1, flag); break;
  527.     case 's': newf = nearestfld (R_SATURN, 1, flag); break;
  528.     case 'u': newf = nearestfld (R_URANUS, 1, flag); break;
  529.     case 'n': newf = nearestfld (R_NEPTUNE, 1, flag); break;
  530.     case 'p': newf = nearestfld (R_PLUTO, 1, flag); break;
  531.     }
  532.  
  533.     *rp = unpackr(newf);
  534.     *cp = unpackc(newf);
  535. }
  536.  
  537. /* return the nearest field with given flag mask, either way, on this row,
  538.  * else -1 if none.
  539.  */
  540. static int
  541. nearestfld (r, c, flag)
  542. int r, c, flag;
  543. {
  544.     int nf, f, *fp;
  545.     int d, d0;
  546.  
  547.     nf = 0;
  548.     d0 = 1000;
  549.  
  550.     for (fp = fields+NFIELDS; --fp >= fields; ) {
  551.         f = *fp;
  552.         if (tstpackf(f,flag) && unpackr(f) == r) {
  553.         d = abs(c - unpackc(f));
  554.         if (d < d0) {
  555.             nf = f;
  556.             d0 = d;
  557.         }
  558.         }
  559.     }
  560.     return (nf ? nf : -1);
  561. }
  562. xXx
  563. echo x sex_dec.c
  564. cat > sex_dec.c << 'xXx'
  565. /* given hours (or degrees), hd, minutes, m, and seconds, s, 
  566.  * return decimal hours (or degrees), *d.
  567.  * in the case of hours (angles) < 0, only the first non-zero element should
  568.  *   be negative.
  569.  */
  570. sex_dec (hd, m, s, d)
  571. int hd, m, s;
  572. double *d;
  573. {
  574.     int sign = 1;
  575.  
  576.     if (hd < 0) {
  577.         sign = -1;
  578.         hd = -hd;
  579.     } else if (m < 0) {
  580.         sign = -1;
  581.         m = -m;
  582.     } else if (s < 0) {
  583.         sign = -1;
  584.         s = -s;
  585.     }
  586.  
  587.     *d = ((s/60.0 + m)/60.0 + hd) * sign;
  588. }
  589.  
  590. /* given decimal hours (or degrees), d.
  591.  * return nearest hours (or degrees), *hd, minutes, *m, and seconds, *s, 
  592.  * each always non-negative; *isneg is set to 1 if d is < 0, else to 0.
  593.  */
  594. dec_sex (d, hd, m, s, isneg)
  595. double d;
  596. int *hd, *m, *s, *isneg;
  597. {
  598.     double min;
  599.  
  600.     if (d < 0) {
  601.         *isneg = 1;
  602.         d = -d;
  603.     } else
  604.         *isneg = 0;
  605.  
  606.     *hd = (int)d;
  607.     min = (d - *hd)*60.;
  608.     *m = (int)min;
  609.     *s = (int)((min - *m)*60. + 0.5);
  610.  
  611.     if (*s == 60) {
  612.         if ((*m += 1) == 60) {
  613.         *hd += 1;
  614.         *m = 0;
  615.         }
  616.         *s = 0;
  617.     }
  618.     /* no  negative 0's */
  619.     if (*hd == 0 && *m == 0 && *s == 0)
  620.         *isneg = 0;
  621. }
  622.  
  623. /* insure 0 <= *v < r.
  624.  */
  625. range (v, r)
  626. double *v, r;
  627. {
  628.     while (*v <  0) *v += r;
  629.     while (*v >= r) *v -= r;
  630. }
  631. xXx
  632. echo x srch.c
  633. cat > srch.c << 'xXx'
  634. /* this file contains functions to support iterative ephem searches.
  635.  * we support several kinds of searching and solving algorithms.
  636.  * values used in the evaluations come from the field logging flog.c system.
  637.  * the expressions being evaluated are compiled and executed from compiler.c.
  638.  */
  639.  
  640. #include <stdio.h>
  641. #include <math.h>
  642. #include "screen.h"
  643.  
  644. static int (*srch_f)();
  645. static int srch_tmscalled;
  646. static char expbuf[NC];        /* [0] == '\0' when expression is invalid */
  647. static double tmlimit = 1./60.;    /* search accuracy, in hrs; def is one minute */
  648.  
  649.  
  650. srch_setup()
  651. {
  652.     int srch_minmax(), srch_solve0(), srch_binary();
  653.     static char *chcs[] = {
  654.         "Find extreme", "Find 0", "Binary", "New function", "Accuracy",
  655.         "Stop"
  656.     };
  657.     int fn;
  658.  
  659.     /* let op select algorithm, edit, set accuracy
  660.      * or stop if currently searching
  661.      * algorithms require a function.
  662.      */
  663.     fn = 0;
  664.     ask:
  665.     switch (popup(chcs, fn, srch_f ? 6 : 5)) {
  666.     case 0: if (expbuf[0] == '\0')
  667.             set_function();
  668.         srch_f = expbuf[0] ? srch_minmax : 0;
  669.         break;
  670.     case 1: if (expbuf[0] == '\0')
  671.             set_function();
  672.         srch_f = expbuf[0] ? srch_solve0 : 0;
  673.         break;
  674.     case 2: if (expbuf[0] == '\0')
  675.             set_function();
  676.         srch_f = expbuf[0] ? srch_binary : 0;
  677.         break;
  678.     case 3: srch_f = 0; set_function(); fn = 3; goto ask;
  679.     case 4: srch_f = 0; set_accuracy(); fn = 4; goto ask;
  680.     case 5: srch_f = 0; srch_prstate(0); return;
  681.     default: return;
  682.     }
  683.  
  684.     /* new search */
  685.     srch_tmscalled = 0;
  686.     srch_prstate (0);
  687. }
  688.  
  689. /* if searching is in effect call the search type function.
  690.  * it might modify *tmincp according to where it next wants to eval.
  691.  * (remember tminc is in hours, not days).
  692.  * if searching ends for any reason it is also turned off.
  693.  * also, flog the new value.
  694.  * return 0 if caller can continue or -1 if it is time to stop.
  695.  */
  696. srch_eval(mjd, tmincp)
  697. double mjd;
  698. double *tmincp;
  699. {
  700.     char errbuf[128];
  701.     int s;
  702.     double v;
  703.  
  704.     if (!srch_f)
  705.         return (0);
  706.  
  707.     if (execute_expr (&v, errbuf) < 0) {
  708.         srch_f = 0;
  709.         f_msg (errbuf);
  710.     } else {
  711.         s = (*srch_f)(mjd, v, tmincp);
  712.         if (s < 0)
  713.         srch_f = 0;
  714.         (void) flog_log (R_SRCH, C_SRCH, v);
  715.         srch_tmscalled++;
  716.     }
  717.  
  718.     srch_prstate (0);
  719.     return (s);
  720. }
  721.  
  722. /* print state of searching. */
  723. srch_prstate (force)
  724. int force;
  725. {
  726.     int srch_minmax(), srch_solve0(), srch_binary();
  727.     static (*last)();
  728.  
  729.     if (force || srch_f != last) {
  730.         f_string (R_SRCH, C_SRCHV,
  731.             srch_f == srch_minmax   ? "Extrema" :
  732.             srch_f == srch_solve0   ? " Find 0" :
  733.             srch_f == srch_binary ?   " Binary" :
  734.                           "    off");
  735.         last = srch_f;
  736.     }
  737. }
  738.  
  739. srch_ison()
  740. {
  741.     return (srch_f != 0);
  742. }
  743.  
  744. /* display current expression. then if type in at least one char make it the
  745.  * current expression IF it compiles ok.
  746.  * TODO: editing?
  747.  */
  748. static
  749. set_function()
  750. {
  751.     static char prompt[] = "Function: ";
  752.     char newexp[NC];
  753.     int s;
  754.  
  755.     f_prompt (prompt);
  756.     fputs (expbuf, stdout);
  757.     c_pos (R_PROMPT, sizeof(prompt));
  758.  
  759.     s = read_line (newexp, PW-sizeof(prompt));
  760.     if (s >= 0) {
  761.         char errbuf[NC];
  762.         if (s > 0 && compile_expr (newexp, errbuf) < 0)
  763.         f_msg (errbuf);
  764.         else
  765.         strcpy (expbuf, newexp);
  766.     }
  767. }
  768.  
  769. static
  770. set_accuracy()
  771. {
  772.     static char p[] = "Desired accuracy (         hrs): ";
  773.     int hrs, mins, secs;
  774.     char buf[NC];
  775.  
  776.     f_prompt (p);
  777.     f_time (R_PROMPT, C_PROMPT+18, tmlimit); /* place in blank spot */
  778.     c_pos (R_PROMPT, sizeof(p));
  779.     if (read_line (buf, PW-sizeof(p)) > 0) {
  780.         f_dec_sexsign (tmlimit, &hrs, &mins, &secs);
  781.         f_sscansex (buf, &hrs, &mins, &secs);
  782.         sex_dec (hrs, mins, secs, &tmlimit);
  783.     }
  784. }
  785.  
  786. /* use successive paraboloidal fits to find when expression is at a
  787.  * local minimum or maximum.
  788.  */
  789. static
  790. srch_minmax(mjd, v, tmincp)
  791. double mjd;
  792. double v;
  793. double *tmincp;
  794. {
  795.     static double base;
  796.     static double x1, x2, x3; /* keep in increasing order */
  797.     static double y1, y2, y3;
  798.     double xm, a, b;
  799.  
  800.     if (srch_tmscalled == 0) {
  801.         base = mjd;
  802.         x1 = 0.0;
  803.         y1 = v;
  804.         return (0);
  805.     }
  806.     mjd -= base;
  807.     if (srch_tmscalled == 1) {
  808.         /* put in one of first two slots */
  809.         if (mjd < x1) {
  810.             x2 = x1;  y2 = y1;
  811.         x1 = mjd; y1 = v;
  812.         } else {
  813.         x2 = mjd; y2 = v;
  814.         }
  815.         return (0);
  816.     }
  817.     if (srch_tmscalled == 2 || fabs(mjd - x1) < fabs(mjd - x3)) {
  818.         /* closer to x1 so discard x3.
  819.          * or if it's our third value we know to "discard" x3.
  820.          */
  821.         if (mjd > x2) {
  822.         x3 = mjd; y3 = v;
  823.         } else {
  824.         x3 = x2;  y3 = y2;
  825.         if (mjd > x1) {
  826.             x2 = mjd; y2 = v;
  827.         } else {
  828.             x2 = x1;  y2 = y1;
  829.             x1 = mjd; y1 = v;
  830.         }
  831.         }
  832.         if (srch_tmscalled == 2)
  833.         return (0);
  834.     } else {
  835.         /* closer to x3 so discard x1 */
  836.         if (mjd < x2) {
  837.         x1 = mjd;  y1 = v;
  838.         } else {
  839.         x1 =  x2;  y1 = y2;
  840.         if (mjd < x3) {
  841.             x2 = mjd; y2 = v;
  842.         } else {
  843.             x2 =  x3; y2 = y3;
  844.             x3 = mjd; y3 = v;
  845.         }
  846.         }
  847.     }
  848.  
  849. #ifdef TRACEMM
  850.     { char buf[NC];
  851.       sprintf (buf, "x1=%g y1=%g x2=%g y2=%g x3=%g y3=%g",
  852.                         x1, y1, x2, y2, x3, y3);
  853.       f_msg (buf);
  854.     }
  855. #endif
  856.     a = y1*(x2-x3) - y2*(x1-x3) + y3*(x1-x2);
  857.     if (fabs(a) < 1e-10) {
  858.         /* near-0 zero denominator, ie, curve is pretty flat here,
  859.          * so assume we are done enough.
  860.          * signal this by forcing a 0 tminc.
  861.          */
  862.         *tmincp = 0.0;
  863.         return (-1);
  864.     }
  865.     b = (x1*x1)*(y2-y3) - (x2*x2)*(y1-y3) + (x3*x3)*(y1-y2);
  866.     xm = -b/(2.0*a);
  867.     *tmincp = (xm - mjd)*24.0;
  868.     return (fabs (*tmincp) < tmlimit ? -1 : 0);
  869. }
  870.  
  871. /* use secant method to solve for time when expression passes through 0.
  872.  */
  873. static
  874. srch_solve0(mjd, v, tmincp)
  875. double mjd;
  876. double v;
  877. double *tmincp;
  878. {
  879.     static double x0, x1;    /* x(n-1) and x(n) */
  880.     static double y0, y1;    /* y(n-1) and y(n) */
  881.     double x2;        /* x(n+1) */
  882.     double df;        /* y(n) - y(n-1) */
  883.  
  884.     switch (srch_tmscalled) {
  885.     case 0: x0 = mjd; y0 = v; return(0);
  886.     case 1: x1 = mjd; y1 = v; break;
  887.     default: x0 = x1; y0 = y1; x1 = mjd; y1 = v; break;
  888.     }
  889.  
  890.     df = y1 - y0;
  891.     if (fabs(df) < 1e-10) {
  892.         /* near-0 zero denominator, ie, curve is pretty flat here,
  893.          * so assume we are done enough.
  894.          * signal this by forcing a 0 tminc.
  895.          */
  896.         *tmincp = 0.0;
  897.         return (-1);
  898.     }
  899.     x2 = x1 - y1*(x1-x0)/df;
  900.     *tmincp = (x2 - mjd)*24.0;
  901.     return (fabs (*tmincp) < tmlimit ? -1 : 0);
  902. }
  903.  
  904. /* binary search for time when expression changes from its initial state.
  905.  * if the change is outside the initial tminc range, then keep searching in that
  906.  *    direction by tminc first before starting to divide down.
  907.  */
  908. static
  909. srch_binary(mjd, v, tmincp)
  910. double mjd;
  911. double v;
  912. double *tmincp;
  913. {
  914.     static double lb, ub;        /* lower and upper bound */
  915.     static int initial_state;
  916.     int this_state = v >= 0.5;
  917.  
  918. #define    FLUNDEF    -9e10
  919.  
  920.     if (srch_tmscalled == 0) {
  921.         if (*tmincp >= 0.0) {
  922.         /* going forwards in time so first mjd is lb and no ub yet */
  923.         lb = mjd;
  924.         ub = FLUNDEF;
  925.         } else {
  926.         /* going backwards in time so first mjd is ub and no lb yet */
  927.         ub = mjd;
  928.         lb = FLUNDEF;
  929.         }
  930.         initial_state = this_state;
  931.         return (0);
  932.     }
  933.  
  934.     if (ub != FLUNDEF && lb != FLUNDEF) {
  935.         if (this_state == initial_state)
  936.         lb = mjd;
  937.         else
  938.         ub = mjd;
  939.         *tmincp = ((lb + ub)/2.0 - mjd)*24.0;
  940. #ifdef TRACEBIN
  941.         { char buf[NC];
  942.           sprintf (buf, "lb=%g ub=%g tminc=%g mjd=%g is=%d ts=%d",
  943.                 lb, ub, *tmincp, mjd, initial_state, this_state);
  944.           f_msg (buf);
  945.         }
  946. #endif
  947.         /* signal to stop if asking for time change less than TMLIMIT */
  948.         return (fabs (*tmincp) < tmlimit ? -1 : 0);
  949.     } else if (this_state != initial_state) {
  950.         /* gone past; turn around half way */
  951.         if (*tmincp >= 0.0)
  952.         ub = mjd;
  953.         else
  954.         lb = mjd;
  955.         *tmincp /= -2.0;
  956.         return (0);
  957.     } else {
  958.         /* just keep going, looking for first state change but we keep
  959.          * learning the lower (or upper, if going backwards) bound.
  960.          */
  961.         if (*tmincp >= 0.0)
  962.         lb = mjd;
  963.         else
  964.         ub = mjd;
  965.         return (0);
  966.     }
  967. }
  968. xXx
  969. echo x sun.c
  970. cat > sun.c << 'xXx'
  971. #include <stdio.h>
  972. #include <math.h>
  973. #include "astro.h"
  974.  
  975. /* given the modified JD, mjd, return the true geocentric ecliptic longitude
  976.  *   of the sun for the mean equinox of the date, *lsn, in radians, and the
  977.  *   sun-earth distance, *rsn, in AU. (the true ecliptic latitude is never more
  978.  *   than 1.2 arc seconds and so may be taken to be a constant 0.)
  979.  * if the APPARENT ecliptic longitude is required, correct the longitude for
  980.  *   nutation to the true equinox of date and for aberration (light travel time,
  981.  *   approximately  -9.27e7/186000/(3600*24*365)*2*pi = -9.93e-5 radians).
  982.  */
  983. sunpos (mjd, lsn, rsn)
  984. double mjd;
  985. double *lsn, *rsn;
  986. {
  987.     double t, t2;
  988.     double ls, ms;    /* mean longitude and mean anomoay */
  989.     double s, nu, ea; /* eccentricity, true anomaly, eccentric anomaly */
  990.     double a, b, a1, b1, c1, d1, e1, h1, dl, dr;
  991.  
  992.     t = mjd/36525.;
  993.     t2 = t*t;
  994.     a = 100.0021359*t;
  995.     b = 360.*(a-(int)a);
  996.     ls = 279.69668+.0003025*t2+b;
  997.     a = 99.99736042000039*t;
  998.     b = 360*(a-(int)a);
  999.     ms = 358.47583-(.00015+.0000033*t)*t2+b;
  1000.     s = .016751-.0000418*t-1.26e-07*t2;
  1001.     anomaly (degrad(ms), s, &nu, &ea);
  1002.     a = 62.55209472000015*t;
  1003.     b = 360*(a-(int)a);
  1004.     a1 = degrad(153.23+b);
  1005.     a = 125.1041894*t;
  1006.     b = 360*(a-(int)a);
  1007.     b1 = degrad(216.57+b);
  1008.     a = 91.56766028*t;
  1009.     b = 360*(a-(int)a);
  1010.     c1 = degrad(312.69+b);
  1011.     a = 1236.853095*t;
  1012.     b = 360*(a-(int)a);
  1013.     d1 = degrad(350.74-.00144*t2+b);
  1014.     e1 = degrad(231.19+20.2*t);
  1015.     a = 183.1353208*t;
  1016.     b = 360*(a-(int)a);
  1017.     h1 = degrad(353.4+b);
  1018.     dl = .00134*cos(a1)+.00154*cos(b1)+.002*cos(c1)+.00179*sin(d1)+
  1019.                                 .00178*sin(e1);
  1020.     dr = 5.43e-06*sin(a1)+1.575e-05*sin(b1)+1.627e-05*sin(c1)+
  1021.                         3.076e-05*cos(d1)+9.27e-06*sin(h1);
  1022.     *lsn = nu+degrad(ls-ms+dl);
  1023.     *rsn = 1.0000002*(1-s*cos(ea))+dr;
  1024.     range (lsn, 2*PI);
  1025. }
  1026. xXx
  1027. echo x time.c
  1028. cat > time.c << 'xXx'
  1029. /* I have tried to provide two ways to set the time, timezone etc.
  1030.  * one works on our ibm-pc and at&t systems, one works on our BSD 4.2 vax.
  1031.  * I hope at least one works for you!
  1032.  * #define TZA    for the at&t method
  1033.  * #define TZB    for the BSD method
  1034.  */
  1035. #define    TZB
  1036.  
  1037. #include <stdio.h>
  1038. #include <time.h>
  1039. #include "astro.h"
  1040. #include "circum.h"
  1041.  
  1042. static long c0;
  1043. static double mjd0;
  1044.  
  1045. /* save current mjd and corresponding system clock for use by inc_mjd().
  1046.  * this establishes the base correspondence between the mjd and system clock.
  1047.  */
  1048. set_t0 (np)
  1049. Now *np;
  1050. {
  1051.     mjd0 = mjd;
  1052.     time (&c0);
  1053. }
  1054.  
  1055. /* fill in n_mjd/tz/tznm from system clock.
  1056.  */
  1057. time_fromsys (np)
  1058. Now *np;
  1059. {
  1060.     extern struct tm *gmtime();
  1061.     struct tm *gmt;
  1062.     long c;
  1063.     double day, hr;
  1064.  
  1065. #ifdef TZA
  1066.     extern long timezone;
  1067.     extern int daylight;
  1068.     extern char *tzname[2];
  1069.  
  1070.     tzset();
  1071.     tz = timezone/3600;
  1072.     strncpy (tznm, tzname[daylight?1:0], sizeof(tznm)-1);
  1073. #endif
  1074. #ifdef TZB
  1075.     extern char *timezone();
  1076.     struct timeval timev;
  1077.     struct timezone timez;
  1078.  
  1079.     gettimeofday (&timev, &timez);
  1080.     tz = timez.tz_minuteswest/60;
  1081.     if (timez.tz_dsttime)
  1082.         tz -= 1.0;
  1083.     strncpy (tznm, timezone(timez.tz_minuteswest, timez.tz_dsttime),
  1084.                                 sizeof(tznm)-1);
  1085. #endif
  1086.     tznm[sizeof(tznm)-1] = '\0';    /* insure string is terminated */
  1087.  
  1088.     time (&c);
  1089.     gmt = gmtime (&c);
  1090.  
  1091.     cal_mjd (gmt->tm_mon+1, (double)gmt->tm_mday, gmt->tm_year+1900, &day);
  1092.     sex_dec (gmt->tm_hour, gmt->tm_min, gmt->tm_sec, &hr);
  1093.     mjd = day + hr/24.0;
  1094. }
  1095.  
  1096. inc_mjd (np, inc)
  1097. Now *np;
  1098. double inc;
  1099. {
  1100.     if (inc == RTC) {
  1101.         long c;
  1102.         time (&c);
  1103.         mjd = mjd0 + (c - c0)/SPD;
  1104.     } else
  1105.         mjd += inc/24.0;
  1106.  
  1107.     /* round to nearest whole second.
  1108.      * without this, you can get fractional days so close to .5 but
  1109.      * not quite there that mjd_hr() can return 24.0
  1110.      */
  1111.     rnd_second (&mjd);
  1112. }
  1113. xXx
  1114. echo x utc_gst.c
  1115. cat > utc_gst.c << 'xXx'
  1116. #include "astro.h"
  1117.  
  1118. /* given a modified julian date, mjd, and a universally coordinated time, utc,
  1119.  * return greenwich mean siderial time, *gst.
  1120.  */
  1121. utc_gst (mjd, utc, gst)
  1122. double mjd;
  1123. double utc;
  1124. double *gst;
  1125. {
  1126.     double tnaught();
  1127.     static double lastmjd;
  1128.     static double t0;
  1129.  
  1130.     if (mjd != lastmjd) {
  1131.         t0 = tnaught (mjd);
  1132.         lastmjd = mjd;
  1133.     }
  1134.     *gst = (1.0/SIDRATE)*utc + t0;
  1135.     range (gst, 24.0);
  1136. }
  1137.  
  1138. /* given a modified julian date, mjd, and a greenwich mean siderial time, gst,
  1139.  * return universally coordinated time, *utc.
  1140.  */
  1141. gst_utc (mjd, gst, utc)
  1142. double mjd;
  1143. double gst;
  1144. double *utc;
  1145. {
  1146.     double tnaught();
  1147.     static double lastmjd;
  1148.     static double t0;
  1149.  
  1150.     if (mjd != lastmjd) {
  1151.         t0 = tnaught (mjd);
  1152.         range (&t0, 24.0);
  1153.         lastmjd = mjd;
  1154.     }
  1155.     *utc = gst - t0;
  1156.     range (utc, 24.0);
  1157.     *utc *= SIDRATE;
  1158. }
  1159.  
  1160. static double
  1161. tnaught (mjd)
  1162. double mjd;    /* julian days since 1900 jan 0.5 */
  1163. {
  1164.     double dmjd;
  1165.     int m, y;
  1166.     double d;
  1167.     double t, t0;
  1168.  
  1169.     mjd_cal (mjd, &m, &d, &y);
  1170.     cal_mjd (1, 0., y, &dmjd);
  1171.     t = dmjd/36525;
  1172.     t0 = 6.57098e-2 * (mjd - dmjd) - 
  1173.          (24 - (6.6460656 + (5.1262e-2 + (t * 2.581e-5))*t) -
  1174.            (2400 * (t - (((double)y - 1900)/100))));
  1175.     return (t0);
  1176. }
  1177. xXx
  1178. echo x version.c
  1179. cat > version.c << 'xXx'
  1180. /* N.B. please increment version and date and note each change. */
  1181.  
  1182. #include "screen.h"
  1183.  
  1184. static char vmsg[] = "Version 4.8  November 22, 1989";
  1185.  
  1186. /*
  1187.  * 4.8 10/28/89 use doubles everywhere
  1188.  *     10/31/89    add direct planet row selection codes.
  1189.  *     11/2/89  improve compiler's fieldname parser.
  1190.  *     11/3/89    switch from ESC to q for "go on" (CBREAK ESC not very portable)
  1191.  *     11/6/89    allow plotting the search function too.
  1192.  *     11/8/89  suppress screen updates while plotting and nstep > 1.
  1193.  *     11/9/89    fix bug prohibiting plotting venus' sdist and objx's transit.
  1194.  *     11/9/89    add option to plot in polar coords.
  1195.  *     11/12/89    fix bug related to updating timezone name when it is changed.
  1196.  *     11/21/89 fix bug in when to print info about object-x
  1197.  *     11/21/89    increase MAXPLTLINES to 10 (to ease plotting all planet seps)
  1198.  *     11/22/89 allow setting fields from command line too.
  1199.  * 4.7 10/13/89 start adding general searching feature. start with flogging.
  1200.  *     10/17/89 add compiler, first menu ideas, get binary srch working.
  1201.  *     10/18/89 add parabolic-extrema and secant-0 solvers.
  1202.  *     10/23/89 finish up new idea of one-line control and set-up "popup" menus.
  1203.  * 4.6 10/29/89 improve transit circumstances by iterating as with rise/set.
  1204.  *        allow changing lst.
  1205.  *        show Updating message at better times.
  1206.  *        avoid overstrikes while watching and add trails option.
  1207.  *        allow for Turbo-C 2.0 printf bug using %?.0f".
  1208.  * 4.5  9/24/89 add third table of all mutual planet angular distances.
  1209.  * 4.4  9/21/89 add second planet table with rise/set times.
  1210.  *        all rise/set times may now use standard or adaptive horizons.
  1211.  * 4.3   9/6/89 NM/FM calendar overstikes now use local time (was ut).
  1212.  *        display elongation of object x.
  1213.  *        better handling of typo when asking for refraction model.
  1214.  * 4.2    7/24/89    specify 7 digits to plot file (not just default to 6)
  1215.  * 4.1  7/18/89 use buffered output and fflush in read_char().
  1216.  * 4.0   7/8/89    add simple sky and solarsystem plotting (and rearrange fields)
  1217.  *        change mars' .cfg mnemonic from a to m.
  1218.  *        clean up nstep/NEW CIR handling
  1219.  *        quit adding our own .cfg suffixes, but...
  1220.  *        add looking for $HOME/.ephemrc (Ronald Florence)
  1221.  *        drop -b
  1222.  *        no longer support SITE
  1223.  * 3.17 6/15/89 misspelt temperature prompt; sun -/= bug. (Mike McCants)
  1224.  *        change sun() to sunpos() for sake of Sun Microsystems.
  1225.  * 3.16  6/9/89 allow JD to be set and plotted.
  1226.  *        c_clear (LATTIC_C) should use J not j (Alex Pruss)
  1227.  *        support SIGINT (Ronald Florence)
  1228.  * 3.15  6/8/89 forget SIMPLETZ: now TZA and TZB.
  1229.  * 3.14  6/6/89 add back borders but allow turning off via -b
  1230.  * 3.13 5/26/89 fix Day/Nite picking loc bug.
  1231.  * 3.12 5/25/89 add SIMPLETZ option to time.c for systems w/o tzset()
  1232.  *        files; couldn't plot dayln or niteln.
  1233.  * 3.11 5/16/89 local time prompt said utc; add NiteLn; check for bad plot
  1234.  * 3.10 4/27/89 allow caps for moving cursor around too
  1235.  * 3.9   4/5/89 discard leading termcap delay digits, for now
  1236.  * 3.8   3/2/89 shorten displayed precision, add heliocentric lat/long
  1237.  * 3.7  2/13/89 change to ^d to quit program.
  1238.  * 3.6   2/7/89 try adding .cfg suffix if can't find config file
  1239.  * 3.5   2/2/89 sunrise/set times based on actual sun size and pressure/temp
  1240.  * 3.4  1/22/89 calendar and all rise/set times based on local date, not utc
  1241.  * 3.3   1/6/89 add z to plot files (still don't plot it however)
  1242.  * 3.2   1/3/89 if set date/time then time does not inc first step
  1243.  * 3.1   1/1/89 user def. graph labels; nstep/stpsz control; genuine c_eol
  1244.  * 3.0 12/31/88 add graphing; add version to credits.
  1245.  * 2.7 12/30/88 add version to credits.
  1246.  * 2.6 12/28/88 twilight defined as 18 rather than 15 degrees below horizon
  1247.  * 2.5 12/26/88 remove trace capability; add screen shadowing: ^l.
  1248.  * 2.4 10/31/88 add credits banner, -s turns it off; savings time fix.
  1249.  * 2.3  9/23/88 exchange Altitude/Elevation titles (no code changes)
  1250.  * 2.2  9/20/88 more caution in aaha_aux() guarding acos() arg range
  1251.  * 2.1  9/14/88 moon phase always >= 0 to match planets convention
  1252.  * 2.0  9/13/88 add version ^v option
  1253.  */
  1254.  
  1255. version()
  1256. {
  1257.     f_msg (vmsg);
  1258. }
  1259.  
  1260. static char *cre[] = {
  1261. "Ephem - computerized ephemeris",
  1262. vmsg,
  1263. "by Elwood Downey",
  1264. "",
  1265. "Many formulas and tables are based, with permission, on material found in",
  1266. "\"Astronomy with your Personal Computer\"",
  1267. "by Dr. Peter Duffett-Smith, Cambridge University Press, (c) 1985",
  1268. "",
  1269. "type any key to continue..."
  1270. };
  1271. credits()
  1272. {
  1273.     int r = 10;    /* first row of credits message */
  1274.     int l;
  1275.  
  1276.     c_erase();
  1277.     for (l = 0; l < sizeof(cre)/sizeof(cre[0]); l++)
  1278.         f_string (r++, (NC - strlen(cre[l]))/2, cre[l]);
  1279.     (void) read_char();    /* wait for any char to continue */
  1280. }
  1281. xXx
  1282. echo x watch.c
  1283. cat > watch.c << 'xXx'
  1284. /* these functions allow you to watch the sky or the solar system via a
  1285.  * simple character-graphics representation on the screen. 
  1286.  * the interaction starts by using the current time. then control with
  1287.  *    END returns to table form; or
  1288.  *    RETURN advances time by one StpSz; or
  1289.  *    d|D advances once by 24 hours (1 day); or
  1290.  *    h|H advances once by 1 hour; or
  1291.  *    any other key keeps advancing by StpSz until any key.
  1292.  */
  1293.  
  1294. #include <stdio.h>
  1295. #include <math.h>
  1296. #include "astro.h"
  1297. #include "circum.h"
  1298. #include "screen.h"
  1299.  
  1300. #define    TROW    (R_PROMPT+1)    /* time/date row */
  1301. #define    TCOL    C_PROMPT
  1302. #define    TGAP    (C_UD-C_UTV)
  1303.  
  1304. #define    SKYACC    3600.    /* desired sky plot accuracy, in arc seconds */
  1305. #define    SSACC    3600.    /* desired solar system plot accuracy, in arc secs */
  1306.  
  1307. /* single-character tag for each body.
  1308.  * order must match the #defines in astro.h and screen.h additions.
  1309.  */
  1310. static char body_tags[] = "evmjsunpSM?";
  1311.  
  1312. /* multiple and single loop prompts */
  1313. static char frprompt[] = "Running... press any key to stop.";
  1314. static char qprompt[]  =
  1315. "q to quit, RETURN/h/d to step by StpSz/hour/day, or any other to freerun";
  1316.  
  1317. /* used to record and then erase last plotted chars */
  1318. typedef struct {
  1319.     int l_r, l_c;
  1320. } LastDraw;
  1321.  
  1322. static int trails;    /* !0 if want to leave trails */
  1323.  
  1324. watch (np, tminc, wbodies)
  1325. Now *np;    /* time now and on each step */
  1326. double tminc;    /* hrs to increment time by each step */
  1327. int wbodies;    /* each bit is !=0 if want that body */
  1328. {
  1329.     static char *flds[3] = {
  1330.         "Night sky", "Solar system"
  1331.     };
  1332.     int fn = 0;
  1333.  
  1334.     ask:
  1335.     flds[2] = trails ? "Leave trails" : "No trails";
  1336.     switch (popup (flds, fn, 3)) {
  1337.     case 0: watch_sky (np, tminc, wbodies); break;
  1338.     case 1: watch_solarsystem (np, tminc, wbodies); break;
  1339.     case 2: trails ^= 1; fn = 2; goto ask;    /* toggle trails and repeat */
  1340.     default: break;
  1341.     }
  1342. }
  1343.  
  1344. /* full night sky view.
  1345.  * north is at left and right of screen south at center.
  1346.  * 0 elevation is at bottom of screen, zenith at the top.
  1347.  */
  1348. static
  1349. watch_sky (np, tminc, wbodies)
  1350. Now *np;    /* time now and on each step */
  1351. double tminc;    /* hrs to increment time by each step */
  1352. int wbodies;    /* each bit is !=0 if want */
  1353. {
  1354.     static char title[] = "Sky at ";
  1355.     int tcol = sizeof(title)+1;
  1356.     double tminc0 = tminc;    /* remember the original */
  1357.     LastDraw last[20], *lp;
  1358.     int nlast = 0;
  1359.     int once = 1;
  1360.     double lmjd;
  1361.     Sky s;
  1362.     int p;
  1363.  
  1364.     set_objx_tag();
  1365.     c_erase();
  1366.     f_string (TROW, TCOL, title);
  1367.  
  1368.     while (1) {
  1369.         if (once)
  1370.         print_updating();
  1371.  
  1372.         /* unless we want trails,
  1373.          * erase any previous tags (in same order as written)
  1374.          */
  1375.         if (!trails)
  1376.         for (lp = last; --nlast >= 0; lp++)
  1377.             f_char (lp->l_r, lp->l_c, ' ');
  1378.         nlast = 0;
  1379.  
  1380.         /* print LOCAL time and date we will be using */
  1381.         lmjd = np->n_mjd - np->n_tz/24.0;
  1382.         f_time (TROW, tcol, mjd_hr(lmjd));
  1383.         f_date (TROW, tcol+TGAP, mjd_day(lmjd));
  1384.  
  1385.         /* print desired stuff */
  1386.         for (p = nxtbody(-1); p != -1; p = nxtbody(p))
  1387.         if (wbodies & (1<<p)) {
  1388.             (void) body_cir (p, SKYACC, np, &s);
  1389.             if (s.s_alt >= 0) {
  1390.             draw_sky (s.s_alt, s.s_az, body_tags[p], last, nlast);
  1391.             nlast++;
  1392.             }
  1393.         }
  1394.  
  1395.         if (once || (chk_char()==0 && read_char()!=0)) {
  1396.         if (readwcmd (tminc0, &tminc, &once) < 0)
  1397.             break;
  1398.         }
  1399.  
  1400.         /* advance time */
  1401.         inc_mjd (np, tminc);
  1402.     }
  1403.  
  1404.     redraw_screen(2);
  1405. }
  1406.  
  1407. /* solar system view, "down from the top", first point of aries to the right.
  1408.  * always include earth.
  1409.  */
  1410. static
  1411. watch_solarsystem (np, tminc, wbodies)
  1412. Now *np;    /* time now and on each step */
  1413. double tminc;    /* hrs to increment time by each step */
  1414. int wbodies;
  1415. {
  1416.     /* max au of each planet from sun; in astro.h #defines order */
  1417.     static double auscale[] = {.38, .75, 1.7, 5.2, 11., 20., 31., 39.};
  1418.     static char title[] = "Solar System at ";
  1419.     int tcol = sizeof(title)+1;
  1420.     double tminc0 = tminc;    /* remember the original */
  1421.     LastDraw last[20], *lp;
  1422.     int nlast = 0;
  1423.     int once = 1;
  1424.     double lmjd;
  1425.     double scale;
  1426.     Sky s;
  1427.     int p;
  1428.  
  1429.     /* set screen scale: largest au we will have to plot */
  1430.     scale = 0.;
  1431.     for (p = MERCURY; p <= PLUTO; p++)
  1432.         if (wbodies & (1<<p))
  1433.         scale = auscale[p];
  1434.     if (scale < 1.)
  1435.         scale = 1.;
  1436.  
  1437.     c_erase();
  1438.     f_string (TROW, TCOL, title);
  1439.  
  1440.     while (1) {
  1441.         if (once)
  1442.         print_updating();
  1443.  
  1444.         /* unless we want trails,
  1445.          * erase any previous tags (in same order as written).
  1446.          */
  1447.         if (!trails)
  1448.         for (lp = last; --nlast >= 0; lp++)
  1449.             f_char (lp->l_r, lp->l_c, ' ');
  1450.         nlast = 0;
  1451.  
  1452.         /* print LOCAL time and date we will be using */
  1453.         lmjd = np->n_mjd - np->n_tz/24.0;
  1454.         f_time (TROW, tcol, mjd_hr(lmjd));
  1455.         f_date (TROW, tcol+TGAP, mjd_day(lmjd));
  1456.  
  1457.         /* print desired stuff */
  1458.         for (p = MERCURY; p <= PLUTO; p++)
  1459.         if (wbodies & (1<<p)) {
  1460.             (void) body_cir (p, SSACC, np, &s);
  1461.             draw_ss (s.s_sdist, s.s_hlong, body_tags[p], scale,
  1462.                                 last, nlast);
  1463.             nlast++;
  1464.         }
  1465.         /* fake a sun at center and add earth */
  1466.         draw_ss (0., 0., 'S', scale, last, nlast);
  1467.         nlast++;
  1468.         (void) body_cir (SUN, SSACC, np, &s);
  1469.         draw_ss (s.s_edist, s.s_hlong, 'E', scale, last, nlast);
  1470.         nlast++;
  1471.  
  1472.         if (once || (chk_char()==0 && read_char()!=0)) {
  1473.         if (readwcmd (tminc0, &tminc, &once) < 0)
  1474.             break;
  1475.         }
  1476.  
  1477.         /* advance time */
  1478.         inc_mjd (np, tminc);
  1479.     }
  1480.  
  1481.     redraw_screen(2);
  1482. }
  1483.  
  1484. static
  1485. set_objx_tag()
  1486. {
  1487.     char n[MAXOBJXNM+1];
  1488.  
  1489.     objx_get ((double *)0, (double *)0, (double *)0, n);
  1490.     body_tags[OBJX] = n[0] > ' ' ? n[0] : '?';
  1491. }
  1492.  
  1493. static
  1494. draw_sky (alt, az, tag, last, nlast)
  1495. double alt, az;
  1496. char tag;
  1497. LastDraw last[];
  1498. int nlast;
  1499. {
  1500.     int r, c;
  1501.  
  1502.     r = NR - (int)(alt*2/PI*(NR-1) + 0.5);
  1503.     c = (int)(az/2.0/PI*(NC-1) + 0.5) + 1;
  1504.     addlast (last, nlast, r, c);
  1505.     f_char (last[nlast].l_r, last[nlast].l_c, tag);
  1506. }
  1507.  
  1508. static
  1509. draw_ss (dist, angle, tag, scale, last, nlast)
  1510. double dist, angle;
  1511. char tag;
  1512. double scale;
  1513. LastDraw last[];
  1514. int nlast;
  1515. {
  1516.     double rad = dist / scale;
  1517.     int r, c;
  1518.  
  1519.     r = NR - (int)((NR-1)/2*(1.0+rad*sin(angle)) + 0.5);
  1520.     c = 1 + (int)((NC-1)/2*(1.0+rad*cos(angle)/ASPECT) + 0.5);
  1521.     addlast (last, nlast, r, c);
  1522.     f_char (last[nlast].l_r, last[nlast].l_c, tag);
  1523. }
  1524.  
  1525. /* add r,c to last[nlast] but possibly move column to avoid overlapps */
  1526. static
  1527. addlast (last, nlast, r, c)
  1528. LastDraw last[];
  1529. int nlast;
  1530. int r, c;
  1531. {
  1532.     LastDraw *lp;
  1533.  
  1534.     search:
  1535.     for (lp = last + nlast; --lp >= last; )
  1536.         if (lp->l_r == r && lp->l_c == c) {
  1537.         if (++c > NC)
  1538.             c = 1;
  1539.         goto search;
  1540.         }
  1541.  
  1542.     last[nlast].l_r = r;
  1543.     last[nlast].l_c = c;
  1544. }
  1545.  
  1546. /* see what the op wants to do now and update prompt/times accordingly.
  1547.  * return -1 if we are finished, else 0.
  1548.  */
  1549. static int
  1550. readwcmd (tminc0, tminc, once)
  1551. double tminc0;
  1552. double *tminc;
  1553. int *once;
  1554. {
  1555.     f_prompt (qprompt);
  1556.  
  1557.     switch (read_char()) {
  1558.     case END:     /* back to table */
  1559.         return (-1);
  1560.     case '\r':    /* one StpSz step */
  1561.         *tminc = tminc0;
  1562.         *once = 1;
  1563.         break;
  1564.     case 'd':    /* one 24-hr step */
  1565.         *tminc = 24.0;
  1566.         *once = 1;
  1567.         break;
  1568.     case 'h':    /* one 1-hour step */
  1569.         *tminc = 1.0;
  1570.         *once = 1;
  1571.         break;
  1572.     default:        /* free-run */
  1573.         *once = 0;
  1574.         f_prompt (frprompt);
  1575.     }
  1576.     return (0);
  1577. }
  1578. xXx
  1579. echo x ephem.cfg
  1580. cat > ephem.cfg << 'xXx'
  1581. UT NOW
  1582. LONG 93:42:8
  1583. LAT 44:50:37
  1584. HEIGHT 800
  1585. TEMP 40
  1586. PRES 29.5
  1587. STPSZ RTC
  1588. PROPTS TSMevmjsunp
  1589. EPOCH EOD
  1590. NSTEP 1
  1591. OBJN Or
  1592. OBJRA 6:0:0
  1593. OBJDEC 0:0:0
  1594. xXx
  1595.