[BACK]Return to grepsols.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Homotopy

File: [local] / OpenXM_contrib / PHC / Ada / Homotopy / grepsols.adb (download)

Revision 1.1.1.1 (vendor branch), Sun Oct 29 17:45:23 2000 UTC (23 years, 6 months ago) by maekawa
Branch: PHC, MAIN
CVS Tags: v2, maekawa-ipv6, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, HEAD
Changes since 1.1: +0 -0 lines

Import the second public release of PHCpack.

OKed by Jan Verschelde.

with text_io,integer_io;                 use text_io,integer_io;
with Communications_with_User;           use Communications_with_User;
with Standard_Natural_Vectors;           use Standard_Natural_Vectors;
with Standard_Natural_Vectors_io;        use Standard_Natural_Vectors_io;
with Symbol_Table;                       use Symbol_Table;
with Symbol_Table_io;
with Standard_Complex_Solutions;         use Standard_Complex_Solutions;
with Standard_Complex_Solutions_io;      use Standard_Complex_Solutions_io;

procedure grepsols is

-- DESCRIPTION :
--   Reads a solution list from file.
--   Writes a selection of a solution list to file.

  function Select_Solutions
              ( sols : Solution_List; nb : Vector ) return Solution_List is

  -- DESCRIPTION :
  --   Selects the solutions according to the numbers in the vector nb.

  -- REQUIRED : the entries in nb are sorted in increasing order.

    res,res_last,tmp : Solution_List;
    ind : natural := nb'first;

  begin
    tmp := sols;
    for i in 1..Length_Of(sols) loop
      if i = nb(ind)
       then Append(res,res_last,Head_Of(tmp).all);
            ind := ind+1;
      end if;
      exit when (ind > nb'last);
      tmp := Tail_Of(tmp);
    end loop;
    return res;
  end Select_Solutions;

  procedure Initialize_Symbol_Table ( n : in natural ) is
  begin
    put("Give "); put(n,1); put_line(" symbols to initialize symbol table :");
    Symbol_Table.Init(n);
    for i in 1..n loop
      declare
		sb : Symbol;
      begin
        Symbol_Table_io.get(sb);
        Symbol_Table.Add(sb);
      end;
    end loop;
  end Initialize_Symbol_Table;

  function Read_Selection return Vector is

  -- DESCRIPTION :
  --   Returns a vector of natural numbers.

    n : natural;

  begin
    put("Give the number of solutions to select : "); get(n);
    declare
      v : Vector(1..n);
    begin
      put("Give "); put(n,1); put(" natural increasing numbers : ");
      get(v);
      return v;
    end;
  end Read_Selection;

  procedure Main is

    infile,outfile : file_type;
    sols : Solution_List;

  begin
    new_line;
    put_line("Selecting elements from a list of solutions.");
    new_line;
    put_line("Reading the name of the file with the solutions.");
    Read_Name_and_Open_File(infile);
    get(infile,sols);
    Close(infile);
    new_line;
    put_line("Reading the name of the output file.");
    Read_Name_and_Create_File(outfile);
    new_line;
    put("There are "); put(Length_Of(sols),1); put_line(" solutions given.");
    declare
      sel : constant Vector := Read_Selection;
	  selsols : Solution_List := Select_Solutions(sols,sel);
    begin
      Initialize_Symbol_Table(Head_Of(sols).n);
	  put_line("The selected solutions : "); put(selsols);
      put(outfile,Length_Of(selsols),Head_Of(selsols).n,selsols);
    end;
    Close(outfile);
  end Main;

begin
  Main;
end grepsols;