home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 223.dms / 223.adf / Source / starglb.c < prev    next >
C/C++ Source or Header  |  1988-07-25  |  24KB  |  825 lines

  1. /*=========================================================================
  2.   Starglb.c -- This module handles initialization and global functions
  3.   for the StarChart program.
  4.  
  5.   Credits for Star Chart:
  6.        Robert L. Hill of the Orange County, CA. Amiga Friends User Group
  7.                       wrote the original version of StarChart in AmigaBasic
  8.                       The star data and many of the main functions of this
  9.                       version are derived from that program.
  10.  
  11.        Ray R. Larson  wrote the c version 1.0 of StarChart, 'intuitionizing'
  12.                       and enhancing the speed and functions of the original.
  13.  
  14.   Copyright (c) 1986 by Ray R. Larson
  15.   
  16.   This program may be freely distributed and copied, but may not be sold
  17.   without the permission of the author. If you modify or enhance it, 
  18.   please include the above credits (and please send me a copy!).
  19.  
  20. Ray R. Larson
  21. 6425 Central Ave. #304
  22. El Cerrito, CA 94530
  23.  
  24. BitNet  LARSON@UCBCMSA
  25. =========================================================================*/
  26. /*------------Header file for all of the standard stuff----*/ 
  27. /*-------------plus definitions of global structures-------*/
  28. #include "star.h" 
  29. #include <graphics/gfxmacros.h>
  30. #include <time.h>
  31.  
  32. /*------------------ extern vars ------------------*/
  33.  
  34. extern LONG MathTransBase;
  35. extern LONG MathBase; 
  36. extern struct star_rec StarTable[];
  37. extern char *Greek[]; 
  38. extern struct cons_rec Constel[];
  39. extern struct RastPort *rp;
  40. extern struct Window *w;
  41. extern struct Screen *scr;      /* pointer to the custom screen    - RRL */
  42. extern struct ViewPort *vport;
  43. extern struct FileHandle *Open();
  44. extern FLOAT cos(), sin(), tan();
  45. extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
  46.        TxtAt_IU,TxtAt_I,TxtAt_U;
  47. BOOL CalcParm = FALSE;
  48. extern UWORD defaultCT[32], CTable[32], *ctabptr;
  49. extern UBYTE DefaultStartFile[];
  50.  
  51. /*------------------ global vars ------------------*/
  52.  
  53. struct ParamStruct DefaultParms, Parms;  /* parameter structures */
  54. extern struct ParamStruct workParms;
  55.  
  56. /* Days per month - used in date calculations */
  57. SHORT Dd[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  58. SHORT DSum[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334};
  59.  
  60. /* values based on pi, used in angular calculations - PI defined in mathffp.h*/
  61. FLOAT P1, P12 , P15;
  62.  
  63. /* values used in determining the type of display for an object */
  64. FLOAT MaxPlus = 2.0, MaxWhite = 11.1;
  65.  
  66. SHORT TimeDelay = 1;  /* time delay is 1 for real time. Max is 1800 */
  67.                       /* for one hour per second of program time    */
  68. SHORT SecondsCount = 0;
  69.  
  70. struct Coord coords[MAXSTARS]; /* x and y screen coordinates for stars */
  71.  
  72.  
  73. /**********************************************************************
  74.  *  IntuiTexts for the horizon labels.
  75.  **********************************************************************/
  76.  
  77. struct IntuiText LeftLabel = {
  78.    15, 0,     /* FrontPen, BackPen */
  79.    JAM2,       /* DrawMode */
  80.    30, 85,     /* LeftEdge, TopEdge */
  81.    &TxtAt_Plain, /* ITextFont Pointer */ 
  82.    /* The IText */
  83.    (UBYTE *)"  ",
  84.    NULL
  85.  };
  86.  
  87. struct IntuiText RightLabel = {
  88.    15, 0,     /* FrontPen, BackPen */
  89.    JAM2,       /* DrawMode */
  90.    601, 85,     /* LeftEdge, TopEdge */
  91.    &TxtAt_Plain, /* ITextFont Pointer */ 
  92.    /* The IText */
  93.    (UBYTE *)"  ",
  94.    &LeftLabel
  95.  };
  96.  
  97. struct IntuiText BotLabel = {
  98.    15, 0,     /* FrontPen, BackPen */
  99.    JAM2,       /* DrawMode */
  100.    315, 171,     /* LeftEdge, TopEdge */
  101.    &TxtAt_Plain, /* ITextFont Pointer */ 
  102.    /* The IText */
  103.    (UBYTE *)"  ",
  104.    &RightLabel
  105.  };
  106.  
  107.  
  108.  
  109. /**********************************************************************
  110.  *  IntuiTexts for the parameter display area
  111.  **********************************************************************/
  112. UBYTE STBuf[10];
  113. struct IntuiText SidTimeText = {
  114.    1, 0,     /* FrontPen, BackPen */
  115.    JAM2,       /* DrawMode */
  116.    450, 177,     /* LeftEdge, TopEdge */
  117.    &TxtAt_Plain, /* ITextFont Pointer */ 
  118.    /* The IText */
  119.    (UBYTE *)&STBuf[0],
  120.    NULL
  121.  };
  122.  
  123. UBYTE DateBuf[12];
  124. struct IntuiText DateText = {
  125.    1, 0,     /* FrontPen, BackPen */
  126.    JAM2,       /* DrawMode */
  127.    243, 177,     /* LeftEdge, TopEdge */
  128.    &TxtAt_Plain, /* ITextFont Pointer */ 
  129.    /* The IText */
  130.    (UBYTE *)&DateBuf[0],
  131.    &SidTimeText    /* NextText */
  132.  };
  133.  
  134. UBYTE LatBuf[4];
  135. struct IntuiText LatText = {
  136.    1, 0,     /* FrontPen, BackPen */
  137.    JAM2,       /* DrawMode */
  138.    483, 167,     /* LeftEdge, TopEdge */
  139.    &TxtAt_Plain, /* ITextFont Pointer */ 
  140.    /* The IText */
  141.    (UBYTE *)&LatBuf[0],
  142.    &DateText    /* NextText */
  143.  };
  144.  
  145. UBYTE LnMinBuf[4];
  146. struct IntuiText LongMinText = {
  147.    1, 0,     /* FrontPen, BackPen */
  148.    JAM2,       /* DrawMode */
  149.    305, 167,     /* LeftEdge, TopEdge */
  150.    &TxtAt_Plain, /* ITextFont Pointer */ 
  151.    /* The IText */
  152.    (UBYTE *)&LnMinBuf[0],
  153.    &LatText    /* NextText */
  154.  };
  155.  
  156. UBYTE LnDegBuf[6];
  157. struct IntuiText LongDegText = {
  158.    1, 0,     /* FrontPen, BackPen */
  159.    JAM2,       /* DrawMode */
  160.    230, 167,     /* LeftEdge, TopEdge */
  161.    &TxtAt_Plain, /* ITextFont Pointer */ 
  162.    /* The IText */
  163.    (UBYTE *)&LnDegBuf[0],
  164.    &LongMinText    /* NextText */
  165.  };
  166.  
  167.  
  168. struct IntuiText DispText_5 = {
  169.    1, 0,     /* FrontPen, BackPen */
  170.    JAM2,       /* DrawMode */
  171.    333, 177,     /* LeftEdge, TopEdge */
  172.    &TxtAt_B, /* ITextFont Pointer */ 
  173.    /* The IText */
  174.    (UBYTE *)"Sidereal Time:",
  175.    &LongDegText    /* NextText */
  176.  };
  177.  
  178.  
  179. struct IntuiText DispText_4 = {
  180.    1, 0,     /* FrontPen, BackPen */
  181.    JAM2,       /* DrawMode */
  182.    200, 177,     /* LeftEdge, TopEdge */
  183.    &TxtAt_B, /* ITextFont Pointer */ 
  184.    /* The IText */
  185.    (UBYTE *)"Date:",
  186.    &DispText_5    /* NextText */
  187.  };
  188.  
  189.  
  190. struct IntuiText DispText_3 = {
  191.    1, 0,     /* FrontPen, BackPen */
  192.    JAM2,       /* DrawMode */
  193.    508, 167,     /* LeftEdge, TopEdge */
  194.    &TxtAt_I, /* ITextFont Pointer */ 
  195.    /* The IText */
  196.    (UBYTE *)"Deg.",
  197.    &DispText_4    /* NextText */
  198.  };
  199.  
  200.  
  201. struct IntuiText DispText_2 = {
  202.    1, 0,     /* FrontPen, BackPen */
  203.    JAM2,       /* DrawMode */
  204.    398, 167,     /* LeftEdge, TopEdge */
  205.    &TxtAt_B, /* ITextFont Pointer */ 
  206.    /* The IText */
  207.    (UBYTE *)"Latitude:",
  208.    &DispText_3    /* NextText */
  209.  };
  210.  
  211.  
  212. struct IntuiText DispText_1 = {
  213.    1, 0,     /* FrontPen, BackPen */
  214.    JAM2,       /* DrawMode */
  215.    223, 167,     /* LeftEdge, TopEdge */
  216.    &TxtAt_I, /* ITextFont Pointer */ 
  217.    /* The IText */
  218.    (UBYTE *)"     Deg.     Min.",
  219.    &DispText_2    /* NextText */
  220.  };
  221.  
  222.  
  223. struct IntuiText DispText_0 = {
  224.    1, 0,     /* FrontPen, BackPen */
  225.    JAM2,       /* DrawMode */
  226.    137, 167,     /* LeftEdge, TopEdge */
  227.    &TxtAt_B, /* ITextFont Pointer */ 
  228.    /* The IText */
  229.    (UBYTE *)"Longitude:",
  230.    &DispText_1    /* NextText */
  231.  };
  232.  
  233.  
  234.  
  235.  
  236. /**********************************************************************
  237.  perform initialization of the screen and data structures (as needed) 
  238. **********************************************************************/
  239. initialize()
  240. {
  241.   struct FileHandle *filedes;
  242.   LONG timestamp;
  243.   struct tm *timedat;
  244.  
  245.  
  246.   if((filedes = Open(&DefaultStartFile[0],MODE_OLDFILE))==NULL)
  247.     { /* set defaults to local stuff (for me) */
  248.       DefaultParms.LongitudeDeg =118;
  249.        DefaultParms.LongitudeMin = 10;
  250.        DefaultParms.Latitude = 34;
  251.        
  252.        /* read the system clock */
  253.        timestamp = time(NULL);
  254.        timedat = localtime(×tamp);
  255.  
  256.        DefaultParms.Month = timedat->tm_mon + 1;
  257.        DefaultParms.Day = timedat->tm_mday;
  258.        DefaultParms.Year= timedat->tm_year + 1900;
  259.        DefaultParms.Hour = timedat->tm_hour;
  260.        DefaultParms.Minute = timedat->tm_min;
  261.        DefaultParms.Horizon = 0;/* zero for North, one for South */
  262.        CalcParams(&DefaultParms); /* calculate sidereal time, GST, etc. from work */
  263.      }
  264.   else { /* read the default parameters from the file */
  265.          Read(filedes,&DefaultParms,(LONG)sizeof(struct ParamStruct));
  266.          Read(filedes,&CTable[0],(LONG)(32*sizeof(UWORD)));
  267.          /* change the registers to the new  colors */
  268.          LoadRGB4(vport,&CTable,32L);
  269.  
  270.          Close(filedes);
  271.        }
  272.        
  273.   /* global PI based values for calculations */
  274.   P1 = PI/180.0;
  275.   P12 = PI/12.0;
  276.   P15 = P1 * 15.0;
  277.  
  278.   Parms = DefaultParms; /* set the current parms to the default */
  279.   
  280.   DisplayStars();
  281.   DisplayAllText();
  282. }
  283. /***************************************************************************
  284.  * SetEW - set labels for the east and west sides of the display 
  285.  ***************************************************************************/
  286. SetEW(horiz)
  287. SHORT horiz;
  288. {  
  289.    if (horiz) {
  290.       RightLabel.IText = (UBYTE *)"W";
  291.       LeftLabel.IText = (UBYTE *)"E";
  292.       BotLabel.IText = (UBYTE *)"S";
  293.       } 
  294.    else {
  295.       RightLabel.IText = (UBYTE *)"E";
  296.       LeftLabel.IText = (UBYTE *)"W";
  297.       BotLabel.IText = (UBYTE *)"N";
  298.       } 
  299.    PrintIText(rp,&BotLabel,0L,0L);
  300.    
  301. }
  302.  
  303. /***************************************************************************
  304.  * PlotStar - draw a star into the display area. - must provide coords 
  305.  ***************************************************************************/
  306. PlotStar(magnitude,chartx,charty,highlight)
  307. FLOAT magnitude;
  308. LONG chartx, charty;
  309. SHORT highlight;
  310.   LONG starcolor;
  311.   SetDrMd(rp,JAM1);
  312.   if (highlight) SetAPen(rp,(LONG)(highlight + 10)); /* output star in color */
  313.   else if (magnitude > MaxWhite) SetAPen(rp,12L); /* output in alternate blue */
  314.   else 
  315.      {
  316.        starcolor = (LONG) magnitude + 3.5; /* round up */
  317.        if (starcolor > 10L) starcolor = 12L;
  318.        SetAPen(rp,starcolor);
  319.      }
  320.  
  321.   if (magnitude > MaxPlus) /* magnitude is an inverse measure */
  322.      WritePixel(rp,chartx,charty);
  323.   else   
  324.      { Move(rp,chartx-1L,charty);
  325.        Draw(rp,chartx+1L,charty);
  326.        Move(rp,chartx,charty-1L);
  327.        Draw(rp,chartx,charty+1L);
  328.      }
  329. } /* end of PlotStar */
  330.  
  331. /***************************************************************************
  332.  * BlinkStar - blink the star indicated by the table index number in red
  333.  ***************************************************************************/
  334. BlinkStar (index,count,highlight,circle)
  335. SHORT index,count,highlight,circle;
  336. {
  337.   SHORT i;
  338.   FLOAT mag;
  339.   LONG x, y;
  340.  
  341.   mag = StarTable[index].Mag;
  342.   x = coords[index].x;
  343.   y = coords[index].y;
  344.   
  345.   if (x == 0L) return;
  346.  
  347.   if (circle > 0) 
  348.      { SetDrMd(rp,COMPLEMENT);
  349.        DrawEllipse(rp,x,y,(LONG)circle,(LONG)(circle / 2));
  350.      }
  351.        
  352.   for (i=0; i < count; i++)
  353.     {
  354.       PlotStar(mag,x,y,highlight);
  355.       Delay(25L);
  356.       PlotStar(mag,x,y,0);
  357.       Delay(10L);
  358.     }
  359.  
  360.   if (circle > 0) 
  361.      { SetDrMd(rp,COMPLEMENT);
  362.        DrawEllipse(rp,x,y,(LONG)circle,(LONG)(circle /2));
  363.        
  364.      }
  365.   SetDrMd(rp,JAM1);
  366.  
  367. } /* end of BlinkStar */
  368.  
  369. /***************************************************************************
  370.  * HighLightStar - Plot the star indicated by the table index number.
  371.  ***************************************************************************/
  372. HighLightStar (index,highlight,circle)
  373. SHORT index,highlight,circle;
  374. {
  375.   SHORT i;
  376.   FLOAT mag;
  377.   LONG x, y;
  378.  
  379.   mag = StarTable[index].Mag;
  380.   x = coords[index].x;
  381.   y = coords[index].y;
  382.  
  383.   if (x == 0L) return;
  384.   
  385.   PlotStar(mag,x,y,highlight);
  386.   if (circle > 0) 
  387.      { SetDrMd(rp,COMPLEMENT);
  388.        DrawEllipse(rp,x,y,(LONG)circle,(LONG)(circle /2));
  389.        SetDrMd(rp,JAM1);
  390.      }
  391.  
  392. } /* end of HighLightStar */
  393.  
  394. /***************************************************************************
  395.  * PlotConst - Plot a constellation from a list of startable indexes.
  396.  *             If highlight is 1, the stars are output in red. If
  397.  *             highlight is 0, they are output in normal colors.
  398.  ***************************************************************************/
  399. BOOL PlotConst(list,highlight,dispflag)
  400. SHORT list[], highlight, dispflag;
  401.  
  402. {
  403.   SHORT i, nstars, index;
  404.   FLOAT mag;
  405.   LONG x, y;
  406.   BOOL visible, major;
  407.  
  408.   nstars = list[0];
  409.   visible = FALSE;
  410.   if (dispflag & 4) major = TRUE;
  411.   else major = FALSE;
  412.  
  413.   /* highlight all the visible stars in the constellation list */
  414.   for(i=1; i <= nstars; i++)
  415.      {  index = list[i];
  416.         if (major && StarTable[index].GreekNum == 0) continue;
  417.           
  418.         mag = StarTable[index].Mag;
  419.         x = coords[index].x;
  420.         y = coords[index].y;
  421.         if (x != 0L)
  422.           { visible = TRUE;
  423.             PlotStar(mag,x,y,highlight);
  424.           }
  425.          
  426.      }
  427.   /* if none of the stars were visible - return now */
  428.   return(visible);
  429.   
  430. } /* end of PlotConst */
  431.  
  432. /***************************************************************************
  433.  * PlotObjects - Plot Messier or NGC objects.
  434.  ***************************************************************************/
  435. PlotObjects(type,highlight)
  436. char type;
  437. SHORT highlight;
  438.  
  439. {
  440.   SHORT i;
  441.  
  442.   for (i=1; i <= NumStars; i++)
  443.      { if (coords[i].x != 0L) /* is it visible ? */
  444.          { if (StarTable[i].GreekNum == 0)
  445.              { /* not a major star */
  446.               if (*(StarTable[i].StarName) == type)
  447.                  PlotStar(StarTable[i].Mag,
  448.               coords[i].x,coords[i].y,highlight);
  449.          }
  450.          }
  451.      }
  452.  
  453. } /* end of PlotObjects */
  454.  
  455. /***************************************************************************
  456.  * CalcGst - calculate Greenwich time
  457.  ***************************************************************************/
  458. FLOAT CalcGst(day,month)
  459. SHORT day, month;
  460. {
  461.    FLOAT df,Gst;
  462.     
  463.    df = (FLOAT) day + DSum[month];
  464.    Gst = 6.68 + (df * 4.0) / 60.0;
  465.    if (Gst > 24.0) return(Gst - 24.0);
  466.    else return(Gst);
  467.  
  468. }
  469.  
  470. /***************************************************************************
  471.  * ClearChart - clear the star display area to black.
  472.  ***************************************************************************/
  473. ClearChart()
  474. {
  475.   SetAPen(rp,2L);
  476.   RectFill(rp,CHARTLEFT,CHARTTOP,CHARTRIGHT,CHARTBOT);
  477. }
  478.  
  479. /***************************************************************************
  480.  * DisplayStars - Calculate the positions of the visible stars given the
  481.  *  current parms and plot them on the screen. Save positions in coords.
  482.  ***************************************************************************/
  483. DisplayStars()
  484. {
  485.   extern UBYTE WTMessage[];
  486.   extern UBYTE WinTitle[]; /* default window title */
  487.   
  488.   sprintf(WTMessage,"Calculating Star Positions for Current Date and Time");
  489.   SetWindowTitles(w,WTMessage,(UBYTE *)-1);
  490.   CalcStars();
  491.   SetWindowTitles(w,WinTitle,(UBYTE *)-1);
  492.   ReDisplay();
  493.   SetEW(Parms.Horizon);
  494.  
  495. } /* end of DisplayStars */
  496.  
  497. /***************************************************************************
  498.  * CalcStars - Calculate the positions of the visible stars given the
  499.  *  current parms and plot them on the screen. Save positions in coords.
  500.  ***************************************************************************/
  501. CalcStars()
  502. {
  503.   FLOAT Xpos,Ypos, LatRad, LatPos, LatCOS, LatSIN, F;
  504.   SHORT i;
  505.   register FLOAT yeardif, RA, DC, xRad, yRad;
  506.   BOOL visible;
  507.   struct star_rec *ST;
  508.   struct Coord *c;
  509.  
  510.   /* set some (variable) constants */
  511.   yeardif = (FLOAT)(Parms.Year - 1950);
  512.   LatRad = Parms.Latitude * P1;
  513.   LatPos = 160.0 - (1.78 * Parms.Latitude);
  514.   LatCOS = cos(LatRad);
  515.   LatSIN =  -sin(LatRad);
  516.   F = 140.0 / 1.5708;
  517.  
  518.   /* for a little extra speed we will use pointers rather than array indexes */
  519.   ST = &StarTable[1];
  520.   c = &coords[1];
  521.  
  522.   for (i = 1; i <= NumStars; i++)
  523.     { 
  524.      RA = ST->Ra;
  525.      DC = ST->Dc;
  526.  
  527.      if (((Parms.Horizon == 0)&&(DC < 0.0)) || /* north view */
  528.          ((Parms.Horizon == 1)&&
  529.           ((DC > (FLOAT)Parms.Latitude)|| 
  530.            (DC < (FLOAT)(Parms.Latitude - 90))) /* south view */
  531.           ))
  532.         { /* don't bother calculating if it will never be visible given the */
  533.           /* current position and orientation.                    */
  534.           c->x = 0L;
  535.           c->y = 0L;
  536.           ST++;
  537.           c++;  
  538.           continue;
  539.          }
  540.          
  541.      if (yeardif) {
  542.        /* convert right Asc. and declination of star to radians */
  543.        xRad = RA * P12;
  544.        yRad = DC * P1;
  545.        
  546.      
  547.        /* correct for year - uses mathffp routines*/
  548.        Xpos = RA + 
  549.              (3.07 + 1.34 * sin(xRad) * tan(xRad))
  550.           * yeardif / 3600.0;
  551.  
  552.       
  553.        Ypos = DC + 20.0 * cos(yRad) * yeardif / 3600.0;
  554.       }
  555.    else { /* year is 1950 - basis for the star table */
  556.          Xpos = RA;
  557.          Ypos = DC;
  558.         }
  559.   
  560.    /* modify the Xpos and Ypos for the date, time, location and horizon */   
  561.    if(Parms.Horizon == 0) 
  562.      visible = NorthView(&Xpos,&Ypos,LatRad,LatPos,LatCOS,LatSIN,F);
  563.    else 
  564.      visible = SouthView(&Xpos,&Ypos,LatCOS,LatSIN);
  565.   
  566.    /* if the star is visible from the current location - save coords and   */
  567.    /* plot it on the display (not any more - actual plot is done in redisp */
  568.    if(visible)
  569.      { /* set the display coordinates */
  570.        c->x = CHARTLEFT + (LONG)((2.0 * Xpos) + 0.5);
  571.        c->y = (CHARTTOP+1L) + (LONG)(Ypos + 0.5);
  572.      }
  573.    else 
  574.      { c->x = 0L;
  575.        c->y = 0L;
  576.      }
  577.      
  578.    /* increment the pointers */
  579.    ST++;
  580.    c++;  
  581.    } /* end of for loop */
  582. } /* end of DisplayStars */
  583.  
  584.  
  585. /***************************************************************************
  586.  * NorthView - calculate star position for Northern Sky
  587.  *  returns 1 if star is visible, zero if not visible from current location
  588.  ***************************************************************************/
  589. BOOL NorthView (xposit,yposit,lat,LatPos,latcos,latsin,F)
  590. FLOAT *xposit, *yposit,lat,LatPos,latcos,latsin,F;
  591. {
  592.   FLOAT DecRad,HourRad, Temp1, TempX, TempY;
  593.   register FLOAT xpos, ypos;
  594.  
  595.   xpos = *xposit;
  596.   ypos = *yposit;
  597.  
  598.   if (ypos < 0.0) return(0);
  599.   
  600.   /* convert declination, latitude, and local sidereal time to radians */
  601.   DecRad = ypos * P1;
  602.   HourRad = P12 * (Parms.Lst - xpos);
  603.   
  604.   /* eliminate stars below the horizon line */
  605.   if(( latcos * cos(DecRad) * cos(HourRad))
  606.      <( latsin * sin(DecRad))) return(0);
  607.  
  608.   xpos = xpos - Parms.Lst;
  609.   ypos = ypos * P1;
  610.   
  611.   /* Map to scale for the display */
  612.   xpos = (xpos * P15) - 1.5708;
  613.  
  614.   Temp1 =  F * (1.5708 -  abs(ypos));
  615.   TempX = Temp1 * cos(xpos) + 140.0;
  616.   
  617.   TempY = Temp1 * sin(xpos) + LatPos;
  618.   
  619.   xpos = TempX;
  620.   ypos = TempY;
  621.  
  622.   if((xpos > 279.0) || (xpos < 0.0)) return(0);
  623.   if((ypos > 159.0) || (ypos < 0.0)) return(0);
  624.   
  625.   /* if we got to here it must be visible */
  626.   *xposit = xpos;
  627.   *yposit = ypos;
  628.   return(1);
  629. } /* end of NorthView */
  630.  
  631. /***************************************************************************
  632.  * SouthView - calculate star position for Southern Sky
  633.  *  returns 1 if star is visible, zero if not visible from current location
  634.  ***************************************************************************/
  635. BOOL SouthView (xposit,yposit,latcos,latsin)
  636. FLOAT *xposit, *yposit,latcos,latsin;
  637. {
  638.   FLOAT DecRad,LatRad,HourRad, LatPos, Temp1;
  639.   register FLOAT xpos, ypos;
  640.  
  641.   xpos = *xposit;
  642.   ypos = *yposit;
  643.  
  644.   if (ypos > (FLOAT)Parms.Latitude) return(0);
  645.  
  646.   if (ypos < (FLOAT)(Parms.Latitude - 90)) return(0);
  647.  
  648.   
  649.   /* convert declination, latitude, and local sidereal time to radians */
  650.   DecRad = ypos * P1;
  651.   HourRad = P12 * (Parms.Lst - xpos);
  652.   
  653.   /* eliminate stars below the horizon line */
  654.   if(( latcos * cos(DecRad) * cos(HourRad))
  655.      <( latsin * sin(DecRad))) return(0);
  656.  
  657.   xpos =  Parms.Lst - xpos;
  658.   if(xpos < -12.0) xpos += 24.0;
  659.   if(xpos > 12.0) xpos -= 24.0;
  660.   xpos = 140.0 + (23.33 * xpos);
  661.   
  662.   if((xpos > 279) || (xpos < 0)) return(0);
  663.  
  664.   ypos = 1.78 * (Parms.Latitude - ypos);
  665.   
  666.   if((ypos > 159.0) || (ypos < 0.0)) return(0);
  667.   
  668.   /* if we got to here it must be visible */
  669.   *xposit = xpos;
  670.   *yposit = ypos;
  671.   return(1);
  672. } /* end of SouthView */
  673.  
  674. /***************************************************************************
  675.  * ReDisplay - Plots the stars currently in the coords table.
  676.  ***************************************************************************/
  677. ReDisplay()
  678.   SHORT i;
  679.   struct star_rec *S;
  680.   struct Coord *c;
  681.  
  682.   ClearChart();
  683.   S = &StarTable[1];
  684.   c = &coords[1];
  685.  
  686.   for(i=1; i <= NumStars; i++) 
  687.      {if (c->x) /* if the coord is not 0 */
  688.         PlotStar(S->Mag,c->x,c->y,0);
  689.       S++;
  690.       c++;
  691.      }
  692. }
  693.  
  694. /***************************************************************************
  695.  * DisplayAllText - Print out the parameters and their labels in the
  696.  *               text display area;
  697.  ***************************************************************************/
  698. DisplayAllText()
  699. {
  700.   setlatdisp();
  701.   setlndisp();
  702.   setdatedisp();
  703.   settimedisp();
  704.   PrintIText(w->RPort,&DispText_0,-20L,13L);
  705. }  
  706.  
  707. /***************************************************************************
  708.  * DispDateText - Format and print out the current date
  709.  ***************************************************************************/
  710. DispDateText()
  711. {
  712.   setdatedisp();
  713.   PrintIText(w->RPort,&DateText,-20L,13L);
  714. }  
  715.  
  716. /***************************************************************************
  717.  * DispTimeText - Format and print out the current time.
  718.  ***************************************************************************/
  719. DispTimeText()
  720. {
  721.   settimedisp();
  722.   PrintIText(w->RPort,&SidTimeText,-20L,13L);
  723. }  
  724.  
  725. /***************************************************************************
  726.  * DispDateTimeText - Format and print out both the date and time
  727.  ***************************************************************************/
  728. DispDateTimeText()
  729. {
  730.   setdatedisp();
  731.   settimedisp();
  732.   PrintIText(w->RPort,&DateText,-20L,13L);
  733. }  
  734.  
  735.  
  736. /***************************************************************************
  737.  * setlatdisp - Put current latitude into display buffer.
  738.  ***************************************************************************/
  739. setlatdisp()
  740. {     
  741.    sprintf(&LatBuf[0],"%2d",Parms.Latitude);
  742. }
  743.  
  744. /***************************************************************************
  745.  * setlndisp - Put current longitude into display buffer.
  746.  ***************************************************************************/
  747. setlndisp()
  748. {     
  749.     sprintf(&LnDegBuf[0], "%3d",Parms.LongitudeDeg);
  750.     sprintf(&LnMinBuf[0], "%2d",Parms.LongitudeMin);
  751. }
  752.  
  753. /***************************************************************************
  754.  * setdatedisp - Put current date into display buffer.
  755.  ***************************************************************************/
  756. setdatedisp()
  757. {    
  758.     sprintf(&DateBuf[0],"%2d/%2d/%4d",Parms.Month,Parms.Day,Parms.Year);
  759. }
  760.  
  761. /***************************************************************************
  762.  * settimedisp - Put current time into display buffer.
  763.  ***************************************************************************/
  764. settimedisp()
  765. {
  766.    sprintf(&STBuf[0],"%2d:%02d:%02d",Parms.Hr,Parms.Mn,SecondsCount);
  767. }
  768. /***************************************************************************
  769.  * UpdateTime - increment the current time and date by the TimeDelay value
  770.  ***************************************************************************/
  771. BOOL UpdateTime()
  772. {
  773.   SHORT worksecs, workmins, workhours;
  774.   BOOL datechange = FALSE;
  775.   BOOL hourchange; /* display is updated each hour */
  776.   
  777.   hourchange = FALSE;
  778.   SecondsCount += TimeDelay;
  779.   if (SecondsCount < 60) DispTimeText();
  780.   else
  781.    {  workhours = SecondsCount / 3600;  
  782.       workmins = SecondsCount % 3600;
  783.       worksecs = workmins % 60;
  784.       workmins = workmins / 60;
  785.       SecondsCount = worksecs;
  786.  
  787.       workmins += Parms.Mn;
  788.       workhours += Parms.Hr;
  789.  
  790.       if (workmins > 59)
  791.        { workhours++;
  792.          hourchange = TRUE;
  793.          workmins -= 60;
  794.        }
  795.       Parms.Mn = workmins;
  796.  
  797.       if (workhours > 23)
  798.        { Parms.Day++;
  799.          workhours -= 24;
  800.          datechange = TRUE;
  801.        }
  802.       Parms.Hr = workhours;
  803.  
  804.       if (datechange)
  805.        { if (Parms.Day > Dd[Parms.Month])
  806.             {  Parms.Day -= Dd[Parms.Month];
  807.                Parms.Month++;
  808.              }
  809.          if (Parms.Month > 12)
  810.             { Parms.Year++;
  811.           Parms.Month -= 12;
  812.             }
  813.          DispDateTimeText();
  814.        }
  815.       else DispTimeText();
  816.    }
  817.   Parms.Lst = (FLOAT)Parms.Hr
  818.               + ((FLOAT)Parms.Mn / 60.0) + ((FLOAT)SecondsCount / 3600.0); 
  819.               
  820.   return(hourchange);
  821. }
  822.  
  823.