unit LIBEP02;



interface

uses xMatDefs, variable, Lib_basi;

procedure ll2trans(k,j:integer;r1,r2:NReal; pos:boolean);
procedure d2(k,j:integer;rd:NReal);
procedure Th2(k,j:integer;rd:NReal;gate:boolean);
procedure Th2hold(k,j:integer;rd, IHold, vgama: NReal;gate:boolean);

implementation

procedure ll2trans(k,j:integer;r1,r2:NReal; pos:boolean);
begin
nd:=nd+2;
if chek then
	if dx[nd] then
		if dx[nd-1] then  { r2 }
			begin
			dx[nd-1]:=false;
			if pos then dx[nd]:=false
			end
		else
			if pos then dx[nd-1]:=true  {comienza a cerrarse}
			else {queda abierta}
	else
		if dx[nd-1] then  {llave cerrada}
			if pos then {sigue cerrada}
			else dx[nd-1]:=false {comienza a abrir la llave}
		else  { r1 }
			if pos then
				dx[nd-1]:=true
			else
				begin
				dx[nd-1]:=true;
				dx[nd]:=true
				end
else
	 if dx[nd] then
		if dx[nd-1] then r(k,j,r2)
		else { circuito abierto }
	 else
		if dx[nd-1] then vg(0,k,j,0)
		else r(k,j,r1)
end;

procedure d2(k,j:integer;rd:NReal);
const
	vgama=0.5;

var
	r1,r2:NReal;
	pos:boolean;

begin
	r1:=rd*1000;r2:=r1*1000;
	nd:=nd+2;
	if chek then
	begin
		pos:=v[k]>=v[j]+vgama;
		if dx[nd] then
			if dx[nd-1] then  { r2 }
			begin
				dx[nd-1]:=false;
				if pos then dx[nd]:=false
			end
			else
				if pos then dx[nd-1]:=true  {comienza a cerrarse}
				else {queda abierta}
		else
			if dx[nd-1] then  {llave cerrada}
				if pos then {sigue cerrada}
				else dx[nd-1]:=false {comienza a abrir la llave}
			else  { r1 }
				if pos then
					dx[nd-1]:=true
				else
				begin
					dx[nd-1]:=true;
					dx[nd]:=true
				end
	end
	else
	 if dx[nd] then
		if dx[nd-1] then rvg(k,j,r2,-vgama)
		else { circuito abierto }
	 else
		if dx[nd-1] then rvg(k,j,rd,-vgama)
		else rvg(k,j,r1,-vgama)
end;


procedure Th2(k,j:integer;rd:NReal;gate:boolean);
const
	vgama=1;

var
	r1,r2:NReal;
	pg,p:boolean;

begin
	r1:=rd*1000;r2:=r1*1000;
	nd:=nd+2;
	if chek then
	begin
		p:=(v[k]>=v[j]+vgama/1.1);
		pg:= p and gate;
		if dx[nd] then
			if dx[nd-1] then  { r2 est=3}
			begin
				dx[nd-1]:=false;
				if pg then dx[nd]:=false
			end
			else
				if pg then dx[nd-1]:=true  {comienza a cerrarse}
				else {queda abierta}
		else
		if dx[nd-1] then  {llave cerrada}
			if p then {sigue cerrada}
			else dx[nd-1]:=false {comienza a abrir la llave}
		else  { r1 est=0 }
			if pg then
				dx[nd-1]:=true
			else
			begin
				dx[nd-1]:=true;
				dx[nd]:=true
			end
	end
else
	 if dx[nd] then
		if dx[nd-1] then rvg(k,j,r2,-vgama)
		else { circuito abierto }
	 else
		if dx[nd-1] then rvg(k,j,rd,-vgama)
		else rvg(k,j,r1,-vgama)
end;

procedure Th2hold(k,j:integer;rd, IHold, vgama: NReal;gate:boolean);

var
	it, r1,r2:NReal;
	pg,p_v, p_i:boolean;

begin
	r1:=rd*10;r2:=r1*100;

	nd:=nd+2;

	if chek then
	begin
		p_v:=v[k]>=v[j]+vgama;
		it:= (v[k]-v[j]-vgama)/rd;

		if it > 0 then
			if it>IHold then p_i:= true
			else p_i:= gate
		else p_i:= false;

		pg:= p_v and gate;

		if dx[nd] then
			if dx[nd-1] then  { r2 est=3}
			begin
				dx[nd-1]:=false;
				if pg then dx[nd]:=false
			end
			else
				if pg then dx[nd-1]:=true  {comienza a cerrarse}
				else {queda abierta}
		else
			if dx[nd-1] then  {llave cerrada}
				if p_i then {sigue cerrada}
				else dx[nd-1]:=false {comienza a abrir la llave}
			else  { r1 est=0 }
				if pg then
					dx[nd-1]:=true
				else
				begin
					dx[nd-1]:=true;
					dx[nd]:=true
				end
	end
	else
		 if dx[nd] then
			if dx[nd-1] then rvg(k,j,r2,-vgama)
			else { circuito abierto }
		 else
			if dx[nd-1] then rvg(k,j,rd,-vgama)
			else rvg(k,j,r1,-vgama)
	end;

begin
end.
