Annotation of OpenXM_contrib/PHC/Ada/Homotopy/grepsols.adb, Revision 1.1.1.1
1.1 maekawa 1: with text_io,integer_io; use text_io,integer_io;
2: with Communications_with_User; use Communications_with_User;
3: with Standard_Natural_Vectors; use Standard_Natural_Vectors;
4: with Standard_Natural_Vectors_io; use Standard_Natural_Vectors_io;
5: with Symbol_Table; use Symbol_Table;
6: with Symbol_Table_io;
7: with Standard_Complex_Solutions; use Standard_Complex_Solutions;
8: with Standard_Complex_Solutions_io; use Standard_Complex_Solutions_io;
9:
10: procedure grepsols is
11:
12: -- DESCRIPTION :
13: -- Reads a solution list from file.
14: -- Writes a selection of a solution list to file.
15:
16: function Select_Solutions
17: ( sols : Solution_List; nb : Vector ) return Solution_List is
18:
19: -- DESCRIPTION :
20: -- Selects the solutions according to the numbers in the vector nb.
21:
22: -- REQUIRED : the entries in nb are sorted in increasing order.
23:
24: res,res_last,tmp : Solution_List;
25: ind : natural := nb'first;
26:
27: begin
28: tmp := sols;
29: for i in 1..Length_Of(sols) loop
30: if i = nb(ind)
31: then Append(res,res_last,Head_Of(tmp).all);
32: ind := ind+1;
33: end if;
34: exit when (ind > nb'last);
35: tmp := Tail_Of(tmp);
36: end loop;
37: return res;
38: end Select_Solutions;
39:
40: procedure Initialize_Symbol_Table ( n : in natural ) is
41: begin
42: put("Give "); put(n,1); put_line(" symbols to initialize symbol table :");
43: Symbol_Table.Init(n);
44: for i in 1..n loop
45: declare
46: sb : Symbol;
47: begin
48: Symbol_Table_io.get(sb);
49: Symbol_Table.Add(sb);
50: end;
51: end loop;
52: end Initialize_Symbol_Table;
53:
54: function Read_Selection return Vector is
55:
56: -- DESCRIPTION :
57: -- Returns a vector of natural numbers.
58:
59: n : natural;
60:
61: begin
62: put("Give the number of solutions to select : "); get(n);
63: declare
64: v : Vector(1..n);
65: begin
66: put("Give "); put(n,1); put(" natural increasing numbers : ");
67: get(v);
68: return v;
69: end;
70: end Read_Selection;
71:
72: procedure Main is
73:
74: infile,outfile : file_type;
75: sols : Solution_List;
76:
77: begin
78: new_line;
79: put_line("Selecting elements from a list of solutions.");
80: new_line;
81: put_line("Reading the name of the file with the solutions.");
82: Read_Name_and_Open_File(infile);
83: get(infile,sols);
84: Close(infile);
85: new_line;
86: put_line("Reading the name of the output file.");
87: Read_Name_and_Create_File(outfile);
88: new_line;
89: put("There are "); put(Length_Of(sols),1); put_line(" solutions given.");
90: declare
91: sel : constant Vector := Read_Selection;
92: selsols : Solution_List := Select_Solutions(sols,sel);
93: begin
94: Initialize_Symbol_Table(Head_Of(sols).n);
95: put_line("The selected solutions : "); put(selsols);
96: put(outfile,Length_Of(selsols),Head_Of(selsols).n,selsols);
97: end;
98: Close(outfile);
99: end Main;
100:
101: begin
102: Main;
103: end grepsols;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>