MODULE WBDiffModelPascal%s; 

	IMPORT 
		WBDiffODEMath,
		Math,
		MathFunc; 
	TYPE 
		 Equations = POINTER TO RECORD (WBDiffODEMath.Equations) END; 
		 Factory = POINTER TO RECORD (WBDiffODEMath.Factory) END; 
	CONST 
		nEq = %s; 
	VAR 
		fact-: WBDiffODEMath.Factory;

	PROCEDURE InterpMoreCov3*(IN parameters: ARRAY OF REAL; t: REAL; OUT p_cont: ARRAY OF REAL); 
	VAR 
		n_cov_cont, i, flag, index, acc, endm, max_m, m, j: INTEGER; 
		gradient: REAL; 
	BEGIN 
		n_cov_cont:=MathFunc.Round(parameters[0]); 
		FOR i:=1 TO n_cov_cont DO 
			max_m:=MathFunc.Round(parameters[i]); 
			m:= MathFunc.Round(parameters[n_cov_cont+i]); 
			acc:=1+2*n_cov_cont; 
			IF (i#1) THEN 
				FOR j:=1 TO (i-1) DO 
					acc:=acc+MathFunc.Round(parameters[i-j])*2; 
				END; 
			END; 
			index:=acc; 
			flag:=0; 
			WHILE (flag=0) & (index<m+acc-1) DO 
				IF (t >= parameters[index]) & (t <= parameters[index+1])THEN 
					endm:=index+1; 
					flag:=1; 
				ELSE 
					index:=index+1; 
				END; 
			END; 

			gradient:= (t- parameters[endm-1])/(parameters[endm]- parameters[endm-1]); 
			p_cont[i-1]:= parameters[max_m+endm-1]+ gradient*(parameters[max_m+endm] - parameters[max_m+endm-1]); 
		END; 
	END InterpMoreCov3; 

		
	PROCEDURE (e: Equations) Derivatives (IN %s, %s: ARRAY OF REAL; n: INTEGER; t: REAL; OUT d%sdt: ARRAY OF REAL); 
	VAR 
		n_cov_cont,lastindex, i: INTEGER; 
		%s 
		p_cont: ARRAY %s OF REAL; 
	BEGIN 
		n_cov_cont:=MathFunc.Round(theta[0]); 
		lastindex:=1+n_cov_cont*2; 
		FOR i:=1 TO n_cov_cont DO 
			lastindex:=lastindex+2*MathFunc.Round(theta[i]); 
		END; 

		InterpMoreCov3(theta,t,p_cont); 
		%s
		%s
		%s 
	END Derivatives;

	PROCEDURE (equations: Equations) SecondDerivatives (IN theta, x: ARRAY OF REAL; numEq: INTEGER; t: REAL;OUT d2xdt2: ARRAY OF REAL);
	BEGIN 
		  HALT(126)
	END SecondDerivatives; 
	
	PROCEDURE (equations: Equations) Jacobian (IN theta, x: ARRAY OF REAL; numEq: INTEGER; t: REAL; OUT jacob: ARRAY OF ARRAY OF REAL); 
	BEGIN
	 HALT(126)
	END Jacobian; 
	
	PROCEDURE (f: Factory) New (option: INTEGER): WBDiffODEMath.GraphNode;
	VAR 
		equations: Equations; 
		node: WBDiffODEMath.GraphNode; 
	BEGIN
		 NEW(equations);
		 node := WBDiffODEMath.New(equations, nEq); 
		 RETURN node
	END New;
   
   
	PROCEDURE Install*; 
	BEGIN 
		  WBDiffODEMath.Install(fact) 
	END Install; 
	
	PROCEDURE Init; 
	VAR 
		f: Factory; 
	BEGIN 
		  NEW(f); fact := f 
	END Init; 
		
	BEGIN 
		  Init
END WBDiffModelPascal%s.