adagsl_335d13f0/examples/clarks/src/clarks.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
with Ada.Text_IO;            use Ada.Text_IO;
with Ada.Text_IO.C_Streams;
with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO;
with Ada.Integer_Text_IO;    use Ada.Integer_Text_IO;
with Interfaces.C;           use Interfaces.C;
with Interfaces.C.Strings;   use Interfaces.C.Strings;
with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Command_Line;       use Ada.Command_Line;
with Ada.Numerics.Elementary_Functions ; use Ada.Numerics.Elementary_Functions ;

with GNAT.Source_Info; use GNAT.Source_Info;

with Angles ;

procedure Clarks is
   Verbose : boolean := True ;
   myname : String := gnat.Source_Info.enclosing_entity ;

   procedure T1 is
      myname : String := gnat.Source_Info.enclosing_entity ;
      logfile : File_Type ;
      procedure show_radians( d : angles.degrees ) is
      begin
         Put(Integer(d)) ; Put(" ; "); 
         Put(Long_Float(angles.R(d)));
         New_Line;
      end show_radians ;
   begin
      if Verbose
      then
         Put_Line(myname);
      end if ;
      Show_Radians(1);
      Show_Radians(90);
      show_radians(180);
      Show_Radians(360);
      --Create(logfile,Out_File,myname & ".csv");
      --Set_Output(logfile);
      --Set_Output(Standard_Output);
      --Close(logfile);
   end T1 ;

   procedure T2 is
      myname : String := gnat.Source_Info.enclosing_entity ;
      logfile : File_Type ;
      procedure show_sine( d : angles.degrees ) is
      begin
         Put(Integer(d)) ; Put(" ; "); 
         Put(Long_Float(angles.R(d))); Put(" ; ");
         Put(Long_Float(Ada.Numerics.Elementary_Functions.Sin(Float(angles.R(d)))));
         New_Line;
      end show_sine ;
   begin
      if Verbose
      then
         Put_Line(myname);
      end if ;
      Create(logfile,Out_File,myname & ".csv");
      Set_Output(logfile);
      for d in angles.degrees'Range
      loop
         Show_Sine(d);
      end loop ;
      Set_Output(Standard_Output);
      Close(logfile);
   end T2 ;

   procedure T3 is
      myname : String := gnat.Source_Info.enclosing_entity ;
      logfile : File_Type ;
      procedure Show_Sine_Line( d : angles.degrees ) is
         values : array (angles.minutes'Range) of Long_Float ;
         meandiff : array (1..5) of Long_Float := (others => 0.0);
         varg : float ;
         ptr : angles.minutes;
      begin
         for v in values'Range
         loop
            varg := Float( angles.R(d,v)) ;
            values(v) := Long_Float(Sin(varg)) ;
         end loop ;
         Put( Long_Float(d) , exp => 0 , aft => 0 ); 
         Set_Col(8) ; Put(" | ") ;
         for v in values'Range
         loop
            if v mod 6 = 0
            then
               if v /= values'Last
               then 
                  ptr := v ;
                  Put(values(v) , aft => 4 , exp => 0); Put( " ");
               end if ;
            else
               meandiff( v mod 6 ) :=
                  meandiff(v mod 6) + (values(v) - values(ptr)) ;
            end if ;
         end loop ;
         Put( " | ");
         for md in meandiff'Range
         loop
            Put(Integer(10000.0*meandiff(md)/10.0), width => 2); Put(" ");
         end loop ;
         New_Line ;
      end Show_Sine_Line; 
   begin
      if Verbose
      then
         Put_Line(myname);
      end if ;
      Create(logfile,Out_File,myname & ".txt");
      Set_Output(logfile);
      for d in angles.degrees'Range
      loop
         Show_Sine_Line( d );
      end loop ;
      Set_Output(Standard_Output);
      Close(logfile);
   end T3 ;

   procedure T4 is
      myname : String := gnat.Source_Info.enclosing_entity ;
      logfile : File_Type ;
      procedure Show_Degrees( r : angles.Radians ) is
          dd : aliased angles.degrees ;
          mm : aliased angles.minutes ;
          ss : aliased angles.seconds ;
      begin
          angles.D( r , dd'access , mm'access, ss'access);
          Put( Long_Float(r) , aft => 4 , exp => 0) ; Put(" ; ");
          Put( Integer(dd) , width => 3 ) ; Put(" ; ");
          Put( Integer(mm) , width => 3 ) ; Put(" ; ");
          Put( Integer(ss) , width => 3 ) ; Put(" ; ");
          New_Line ;
      end Show_Degrees;
   begin
      if Verbose
      then
         Put_Line(myname);
      end if ;
      Create(logfile,Out_File,myname & ".csv");
      Set_Output(logfile);
      Show_Degrees( angles.R(10,10,10) );
      Show_Degrees( angles.R(20,20,20) );
      Show_Degrees( angles.R(90,0,0) );
      Show_Degrees( angles.R(180,0,0) );
      Show_Degrees( angles.R(270,0,0) );
      Show_Degrees( angles.R(45,0,0) );
      Set_Output(Standard_Output);
      Close(logfile);
   end T4 ;

begin
   if Verbose
   then
      Put_Line(myname);
   end if ;
   T1 ;
   T2 ;
   T3 ;
   T4 ;
end Clarks;