adagsl_335d13f0/examples/vector/src/vector.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
with Ada.Text_Io; use Ada.Text_IO ;
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.Text_Io.C_Streams;

with gnat.source_info ;

with gsl ;
with gsl.rng ;
with gsl.randist ;
with gsl.statistics ;
with gsl.rstat ;
with gsl.vector_double ;
with gsl.sort_double ;

procedure Vector is
   vec : access gsl.vector_double.gsl_vector := gsl.vector_double.alloc(5);
   procedure Setup is
   begin
      for vi in 1..5
      loop
         gsl.vector_double.set(vec,size_t(vi-1),double(vi)+0.5);
      end loop ;
   end Setup ;

   procedure Test0 is
      outfile : File_Type ;
      Status : Int ;
   begin
      Put_Line(gnat.source_info.enclosing_entity);
      Create(outfile,Out_File,"vector.txt");
      Status := gsl.vector_double.fprintf(Ada.Text_Io.C_Streams.C_Stream(outfile),
                                vec,
                                New_String("%.5g"));
      Close(outfile);
   end Test0;

   procedure Test1 is
      vin : access gsl.vector_double.gsl_vector := gsl.vector_double.alloc(5);
      infile : File_Type;
      Status : Int ;
   begin
      Put_Line(gnat.source_info.enclosing_entity);
      Open(infile,In_File,"vector.txt");
      Status := gsl.vector_double.fscanf(Ada.Text_Io.C_Streams.C_Stream(infile),vin);
      Close(infile);
      for i in 1..Integer(vin.size)
      loop
         Put(i); Put(" => "); Put(Long_float(gsl.vector_double.get(vin,size_t(i-1)))); New_Line;
         Flush ;
      end loop ;
   end Test1 ;

   procedure Test2 is
   begin
      Put_Line(gnat.source_info.enclosing_entity);
      for vi in 1..10
      loop
         Put(vi); Put(" => "); Put(Long_float(gsl.vector_double.get(vec,size_t(vi-1)))); New_Line;
         Flush ;
      end loop ;
   end Test2 ;
begin
   Setup;
   Test0;
   Test1;
   Test2;
end Vector;