File : taylors-io.adb



package body Taylors.IO is

  package Txt_Int_IO is new Ada.Text_IO.Integer_IO(Integer);
  use Txt_Int_IO;

  procedure Show(P: in Taylor; Cut: in Rep := Zero) is
    C: Scalar;
  begin
    for K in 0 .. Deg(P) loop
      C := Component(K,P);
      if SupAbs(C)>Cut then
        Put(Current_Output,K,2,10);
        Put(Current_Output,"   ");
        Show(C);
      end if;
    end loop;
    C := ErrComp(P);
    if SupAbs(C)>Cut then
      Put(Current_Output," E   ");
      Show(C);
    end if;
    New_Line;
  end Show;

  procedure Get(R: in Radius; F: in File_Type; P: out Taylor; IsPoly: in out Boolean; GetPoly: in Boolean; Decimal: in Boolean := True) is
    D: Integer;
    C,E: Scalar := ScalZero;
    B: Scalar := Ball(R);
  begin
    SetZero(P);
    Get(File=>F, Item=>D);
    if D<0 then return; end if;
    if not GetPoly then
      Get(F,C,Decimal);
    end if;
    SetErrComp(C,P);                           -- general error
    IsPoly := IsPoly and C=ScalZero;
    for K in 0 .. D loop
      Get(F,C,Decimal);
      if K <= Size then
        SetComponent(K,C,P);
      else
        E := E+B*C;
        B := R*B;
      end if;
    end loop;
    SetComponent(Size,Component(Size,P)+E,P);  -- add higher order error
    IsPoly := IsPoly and E=ScalZero;
  end Get;

  procedure Put(F: in File_Type; P: in Taylor; PutPoly: in Boolean; Decimal: in Boolean := True) is
    Pt: Taylor;
  begin
    Copy(P,Pt);
    Cleanup(Pt);
    Put(File=>F, Item=>Deg(Pt), Width=>3);
    New_Line(F);
    if Deg(Pt)<0 then return; end if;
    if not PutPoly then
      Put(F,ErrComp(Pt),Decimal);
      New_Line(F);
    end if;
    for K in 0 .. Deg(Pt) loop
      Put(F,Component(K,Pt),Decimal);
      New_Line(F);
    end loop;
  end Put;

end Taylors.IO;