home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / math / daylite / globals.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-20  |  2.0 KB  |  96 lines

  1. unit Globals;
  2.  
  3. interface
  4.  
  5.   const pi    = 3.1415926535897932385;
  6.  
  7. {$IFOPT N+}
  8.   type  Float = Extended;
  9. {$ELSE}
  10.   type  Float = Real;
  11. {$ENDIF}
  12.  
  13.   function Tan(x:float):float;
  14.  
  15.   function Radians(degrees:Float):Float;
  16.  
  17.   function Sex2Dec(hh:longint;mm,ss:integer):Float;
  18.  
  19.   procedure Dec2Sex(dec:float; var hh:longint; var mm,ss:integer);
  20.  
  21.  
  22.   function LeapYear(y:longint):Boolean;
  23.  
  24.   function DaysIn(y:longint;m:integer):Integer;
  25.  
  26.   function ValidDate(y:LongInt;m,d:integer):boolean;
  27.  
  28.   function DayOfYear(y:longint;m,d:integer):integer;
  29.  
  30.  
  31. implementation
  32.  
  33.  
  34.   function Tan(x:float):float;
  35.     begin
  36.       Tan := sin(x) / cos(x);
  37.     end;
  38.  
  39.   function Radians(degrees:Float):Float;
  40.     begin
  41.       Radians := degrees * 2*pi / 360.0;
  42.     end;
  43.  
  44.   function Sex2Dec(hh:longint;mm,ss:integer):Float;
  45.     var dec : Float;
  46.     begin
  47.       dec := abs(hh)+(abs(mm)+(abs(ss)/60.0))/60.0;
  48.       if hh<0 then dec := -dec;
  49.       Sex2Dec := dec;
  50.     end;
  51.  
  52.   procedure Dec2Sex(dec:float; var hh:longint; var mm,ss:integer);
  53.     begin
  54.       hh := trunc(dec);
  55.       mm := trunc((dec - hh) * 60);
  56.       ss := trunc(((dec - hh) * 60 - mm) * 60 + 0.5);
  57.     end;
  58.  
  59.  
  60.   function LeapYear(y:longint):Boolean;
  61.     begin
  62.       LeapYear := (y div 4 = 0) and not(y div 100 = 0) or (y div 400 = 0);
  63.     end;
  64.  
  65.   function DaysIn(y:longint;m:integer):Integer;
  66.     begin
  67.       if (m<1) or (m>12) then
  68.         DaysIn := 0
  69.       else if m IN [4,6,9,11] then
  70.         DaysIn := 30
  71.       else if m=2 then begin
  72.         if LeapYear(y) then
  73.           DaysIn := 29
  74.         else
  75.           DaysIn := 28
  76.        end
  77.       else
  78.         DaysIn := 31;
  79.     end;
  80.  
  81.   function ValidDate(y:LongInt;m,d:integer):boolean;
  82.     var days : integer;
  83.     begin
  84.       days := DaysIn(y,m);
  85.       ValidDate := (days>=d) and (days>0);
  86.     end;
  87.  
  88.   function DayOfYear(y:longint;m,d:integer):integer;
  89.     var i: integer;
  90.     begin
  91.       for i := 1 to m-1 do
  92.         d := d + DaysIn(y,i);
  93.       DayOfYear := d;
  94.     end;
  95.  
  96. end.