     with FloaAKD; use FloaAKD;
     with MathAKD; use MathAKD;
     with TextAKD; use TextAKD;
     with TTY;


     procedure HH_Alpha is
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
       V, V1, V2, dV1_dt, dV2_dt : float := 0.0;
       Decay_1 : float := 2.0;
       Decay_2 : float := 1.0;
       Stim     : float := 1.0;
       Stimulus : float := 0.0;
       Time : float := 0.0;
       dt   : constant float := 0.001;
       Key  : character;
       A : float := 2.0;
       dV_dt : float;

     procedure Alpha (
       V        : in out float;
       dV_dt    : in out float;
       Stimulus : in     float := 0.0;
       Decay    : in     float := 1.0;
       dt       : in     float := 0.001 ) is
     ----------------------------------------------------------------------
     -- V(t) = time * exp ( -Decay * time )
     ----------------------------------------------------------------------
       dV_dt_2 : float;
     begin
       dV_dt_2 := Stimulus - 2.0 * Decay * dV_dt - ( Decay ** 2 ) * V;
       dV_dt := dV_dt + dt * dV_dt_2;
       V := V + dt * dV_dt;
     end Alpha;

     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     begin
       Stim := Ask ( "Stimulus ", Stim );
       Decay_1 := Ask ( "Decay_1 ", Decay_1 );
       Decay_2 := Ask ( "Decay_2 ", Decay_2 );
       loop
	 if TTY.Char_Ready then
	   Get ( Key );
	   Stimulus := Stim;
	 end if;
--       if V > 0.0 then
	   Alpha ( V1, dV1_dt, V, Decay_1, dt );
	   Alpha ( V2, dV2_dt, V, Decay_2, dt );
--       else
--         Alpha ( V1, dV1_dt, Stimulus, Decay_1, dt );
--         Alpha ( V2, dV2_dt, Stimulus, Decay_2, dt );
--       end if;
	 if V1 > 1.0 then
	   V1 := 1.0;
	 end if;
	 if V2 > 1.0 then
	   V2 := 1.0;
	 end if;
	 Put ( Time    ); Put ( ":  " );
	 Put ( V1 ); Put ( " - " );
	 Put ( V2 ); Put ( " = " );
	 V := V + Stimulus + dt * ( V1 - V2 );
	 Put ( V ); New_Line;
	 Stimulus := 0.0;
	 Time := Time + dt;
       end loop;
     end HH_Alpha;
