home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / astrnomy / ephem421.zip / MAINMENU.C < prev    next >
C/C++ Source or Header  |  1990-09-13  |  7KB  |  280 lines

  1. /* printing routines for the main (upper) screen.
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include "astro.h"
  7. #include "circum.h"
  8. #include "screen.h"
  9.  
  10. /* #define PC_GRAPHICS */
  11. #ifdef PC_GRAPHICS
  12. #define    JOINT    207
  13. #define    VERT    179
  14. #define    HORIZ    205
  15. #else
  16. #define    JOINT    '-'
  17. #define    VERT    '|'
  18. #define    HORIZ    '-'
  19. #endif
  20.  
  21. mm_borders()
  22. {
  23.     char line[NC+1], *lp;
  24.     register i;
  25.  
  26.     lp = line;
  27.     for (i = 0; i < NC; i++)
  28.         *lp++ = HORIZ;
  29.     *lp = '\0';
  30.     f_string (R_PLANTAB-1, 1, line);
  31.     for (i = R_TOP; i < R_PLANTAB-1; i++)
  32.         f_char (i, COL2-2, VERT);
  33.     f_char (R_PLANTAB-1, COL2-2, JOINT);
  34.     for (i = R_TOP; i < R_PLANTAB-1; i++)
  35.         f_char (i, COL3-2, VERT);
  36.     f_char (R_PLANTAB-1, COL3-2, JOINT);
  37.     for (i = R_LST; i < R_PLANTAB-1; i++)
  38.         f_char (i, COL4-2, VERT);
  39.     f_char (R_PLANTAB-1, COL4-2, JOINT);
  40. }
  41.  
  42. /* print the permanent labels, on the top menu and the planet names
  43.  * in the bottom section.
  44.  */
  45. mm_labels()
  46. {
  47.     f_string (R_TZN,    C_TZN,        "LT");
  48.     f_string (R_UT,        C_UT,        "UTC");
  49.     f_string (R_JD,        C_JD,        "JulianDate");
  50.     f_string (R_LISTING,    C_LISTING,    "Listing");
  51.     f_string (R_WATCH,    C_WATCH,    "Watch");
  52.     f_string (R_SRCH,    C_SRCH,        "Search");
  53.     f_string (R_PLOT,    C_PLOT,        "Plot");
  54.     f_string (R_ALTM,    C_ALTM,        "Menu");
  55.  
  56.     f_string (R_LST,    C_LST,        "LST");
  57.     f_string (R_DAWN,    C_DAWN,        "Dawn");
  58.     f_string (R_DUSK,    C_DUSK,        "Dusk");
  59.     f_string (R_LON,    C_LON,        "NiteLn");
  60.     f_string (R_PAUSE,    C_PAUSE,    "Pause");
  61.     f_string (R_NSTEP,    C_NSTEP,    "NStep");
  62.     f_string (R_STPSZ,    C_STPSZ,    "StpSz");
  63.  
  64.     f_string (R_LAT,    C_LAT,        "Lat");
  65.     f_string (R_LONG,    C_LONG,        "Long");
  66.     f_string (R_HEIGHT,    C_HEIGHT,    "Elev");
  67.     f_string (R_TEMP,    C_TEMP,        "Temp");
  68.     f_string (R_PRES,    C_PRES,        "AtmPr");
  69.     f_string (R_TZONE,    C_TZONE,    "TZ");
  70.     f_string (R_EPOCH,    C_EPOCH,    "Epoch");
  71.  
  72.     f_string (R_PLANTAB,    C_OBJ,    "Ob");
  73.     f_string (R_SUN,    C_OBJ,    "Su");
  74.     f_string (R_MOON,    C_OBJ,    "Mo");
  75.     f_string (R_MERCURY,    C_OBJ,    "Me");
  76.     f_string (R_VENUS,    C_OBJ,    "Ve");
  77.     f_string (R_MARS,    C_OBJ,    "Ma");
  78.     f_string (R_JUPITER,    C_OBJ,    "Ju");
  79.     f_string (R_SATURN,    C_OBJ,    "Sa");
  80.     f_string (R_URANUS,    C_OBJ,    "Ur");
  81.     f_string (R_NEPTUNE,    C_OBJ,    "Ne");
  82.     f_string (R_PLUTO,    C_OBJ,    "Pl");
  83.     f_string (R_OBJX,    C_OBJ,    "X");
  84.     f_string (R_OBJY,    C_OBJ,    "Y");
  85. }
  86.  
  87. /* print all the time/date/where related stuff: the Now structure.
  88.  * print in a nice order, based on the field locations, as much as possible.
  89.  */
  90. mm_now (np, all)
  91. Now *np;
  92. int all;
  93. {
  94.     char buf[32];
  95.     double lmjd = mjd - tz/24.0;
  96.     double jd = mjd + 2415020L;
  97.     double tmp;
  98.  
  99.     (void) sprintf (buf, "%-3.3s", tznm);
  100.     f_string (R_TZN, C_TZN, buf);
  101.     f_time (R_LT, C_LT, mjd_hr(lmjd));
  102.     f_date (R_LD, C_LD, mjd_day(lmjd));
  103.  
  104.     f_time (R_UT, C_UTV, mjd_hr(mjd));
  105.     f_date (R_UD, C_UD, mjd_day(mjd));
  106.  
  107.     (void) sprintf (buf, "%14.5f", jd);
  108.     (void) flog_log (R_JD, C_JDV, jd, buf);
  109.     f_string (R_JD, C_JDV, buf);
  110.  
  111.     now_lst (np, &tmp);
  112.     f_time (R_LST, C_LSTV, tmp);
  113.  
  114.     if (all) {
  115.         f_gangle (R_LAT, C_LATV, lat);
  116.         f_gangle (R_LONG, C_LONGV, -lng);    /* + west */
  117.  
  118.         tmp = height * 2.093e7;    /* want to see ft, not earth radii */
  119.         (void) sprintf (buf, "%5g ft", tmp);
  120.         (void) flog_log (R_HEIGHT, C_HEIGHTV, tmp, buf);
  121.         f_string (R_HEIGHT, C_HEIGHTV, buf);
  122.  
  123.         tmp = 9./5.*temp + 32.0;     /* want to see degrees F, not C */
  124.         (void) sprintf (buf, "%6g F", tmp);
  125.         (void) flog_log (R_TEMP, C_TEMPV, tmp, buf);
  126.         f_string (R_TEMP, C_TEMPV, buf);
  127.  
  128.         tmp = pressure / 33.86;    /* want to see in. Hg, not mBar */
  129.         (void) sprintf (buf, "%5.2f in", tmp);
  130.         (void) flog_log (R_PRES, C_PRESV, tmp, buf);
  131.         f_string (R_PRES, C_PRESV, buf);
  132.  
  133.         f_signtime (R_TZONE, C_TZONEV, tz);
  134.  
  135.         if (epoch == EOD)
  136.         f_string (R_EPOCH, C_EPOCHV, "(OfDate)");
  137.         else {
  138.         mjd_year (epoch, &tmp);
  139.         f_double (R_EPOCH, C_EPOCHV, "%8.1f", tmp);
  140.         }
  141.     }
  142.  
  143.     /* print the calendar for local day, if new month/year.  */
  144.     mm_calendar (np, all > 1);
  145. }
  146.  
  147. /* display dawn/dusk/length-of-night times.
  148.  */
  149. mm_twilight (np, force)
  150. Now *np;
  151. int force;
  152. {
  153.     double dusk, dawn;
  154.     double tmp;
  155.     int status;
  156.  
  157.     if (!twilight_cir (np, &dawn, &dusk, &status) && !force)
  158.         return;
  159.  
  160.     if (status != 0) {
  161.         f_blanks (R_DAWN, C_DAWNV, 5);
  162.         f_blanks (R_DUSK, C_DUSKV, 5);
  163.         f_string (R_LON, C_LONV, "-----");
  164.         return;
  165.     }
  166.  
  167.     f_mtime (R_DAWN, C_DAWNV, dawn);
  168.     f_mtime (R_DUSK, C_DUSKV, dusk);
  169.     tmp = dawn - dusk; range (&tmp, 24.0);
  170.     f_mtime (R_LON, C_LONV, tmp);
  171. }
  172.  
  173. mm_newcir (y)
  174. int y;
  175. {
  176.     static char ncmsg[] = "NEW CIRCUMSTANCES";
  177.     static char nomsg[] = "                 ";
  178.     static int last_y = -1;
  179.  
  180.     if (y != last_y) {
  181.         f_string (R_NEWCIR, C_NEWCIR, y ? ncmsg : nomsg);
  182.         last_y = y;
  183.     }
  184. }
  185.  
  186. static
  187. mm_calendar (np, force)
  188. Now *np;
  189. int force;
  190. {
  191.     static char *mnames[] = {
  192.         "January", "February", "March", "April", "May", "June",
  193.         "July", "August", "September", "October", "November", "December"
  194.     };
  195.     static int last_m, last_y;
  196.     static double last_tz = -100;
  197.     char str[64];
  198.     int m, y;
  199.     double d;
  200.     int f, nd;
  201.     int r;
  202.     double jd0;
  203.  
  204.     /* get local m/d/y. do nothing if still same month and not forced. */
  205.     mjd_cal (mjd_day(mjd-tz/24.0), &m, &d, &y);
  206.     if (m == last_m && y == last_y && tz == last_tz && !force)
  207.         return;
  208.     last_m = m;
  209.     last_y = y;
  210.     last_tz = tz;
  211.  
  212.     /* find day of week of first day of month */
  213.     cal_mjd (m, 1.0, y, &jd0);
  214.     mjd_dow (jd0, &f);
  215.     if (f < 0) {
  216.         /* can't figure it out - too hard before Gregorian */
  217.         int i;
  218.         for (i = 8; --i >= 0; )
  219.         f_string (R_CAL+i, C_CAL, "                    ");
  220.         return;
  221.     }
  222.  
  223.     /* print header */
  224.     f_blanks (R_CAL, C_CAL, 20);
  225.     (void) sprintf (str, "%s %4d", mnames[m-1], y);
  226.     f_string (R_CAL, C_CAL + (20 - (strlen(mnames[m-1]) + 5))/2, str);
  227.     f_string (R_CAL+1, C_CAL, "Su Mo Tu We Th Fr Sa");
  228.  
  229.     /* find number of days in this month */
  230.     mjd_dpm (jd0, &nd);
  231.  
  232.     /* print the calendar */
  233.     for (r = 0; r < 6; r++) {
  234.         char row[7*3+1], *rp = row;
  235.         int c;
  236.         for (c = 0; c < 7; c++) {
  237.         int i = r*7+c;
  238.         if (i < f || i >= f + nd)
  239.             (void) sprintf (rp, "   ");
  240.         else
  241.             (void) sprintf (rp, "%2d ", i-f+1);
  242.         rp += 3;
  243.         }
  244.         row[sizeof(row)-2] = '\0';    /* don't print last blank; causes wrap*/
  245.         f_string (R_CAL+2+r, C_CAL, row);
  246.     }
  247.  
  248.     /* over print the new and full moons for this month.
  249.      * TODO: don't really know which dates to use here (see moonnf())
  250.      *   so try several to be fairly safe. have to go back to 4/29/1988
  251.      *   to find the full moon on 5/1 for example.
  252.      */
  253.     mm_nfmoon (jd0-3, tz, m, f);
  254.     mm_nfmoon (jd0+15, tz, m, f);
  255. }
  256.  
  257. static
  258. mm_nfmoon (jd, tzone, m, f)
  259. double jd, tzone;
  260. int m, f;
  261. {
  262.     static char nm[] = "NM", fm[] = "FM";
  263.     double dm;
  264.     int mm, ym;
  265.     double jdn, jdf;
  266.     int di;
  267.  
  268.     moonnf (jd, &jdn, &jdf);
  269.     mjd_cal (jdn-tzone/24.0, &mm, &dm, &ym);
  270.     if (m == mm) {
  271.         di = dm + f - 1;
  272.         f_string (R_CAL+2+di/7, C_CAL+3*(di%7), nm);
  273.     }
  274.     mjd_cal (jdf-tzone/24.0, &mm, &dm, &ym);
  275.     if (m == mm) {
  276.         di = dm + f - 1;
  277.         f_string (R_CAL+2+di/7, C_CAL+3*(di%7), fm);
  278.     }
  279. }
  280.