	MODULE WBDevModelPascal%s;

		IMPORT
			StdLog,
			WBDevVector,
			Math,
			PmetricsPKModels,
			PmetricsFunctionModel%s;
			
		TYPE
			Function = POINTER TO RECORD (WBDevVector.Node) END;
			Factory = POINTER TO RECORD (WBDevVector.Factory) END;
			
		VAR
			fact-: WBDevVector.Factory;
			
		PROCEDURE (func: Function) DeclareArgTypes (OUT args: ARRAY OF CHAR);
		BEGIN
			args := "vvvvvvvvv";
		END DeclareArgTypes;

		PROCEDURE GetRealWBDevVector(vectorIndex: INTEGER; func: Function): POINTER TO 
			ARRAY OF REAL;
		VAR
			i, np: INTEGER;
			p: POINTER TO ARRAY OF REAL;
		BEGIN
			np := LEN(func.arguments[vectorIndex]);
			NEW(p, np);
			FOR i := 0 TO np-1 DO
				p[i] := func.arguments[vectorIndex][i].Value()
			END;
			RETURN p;
		END GetRealWBDevVector;

		PROCEDURE GetIntWBDevVector(vectorIndex: INTEGER; func: Function): POINTER TO 
			ARRAY OF INTEGER;
		VAR
			i, np: INTEGER;
			p: POINTER TO ARRAY OF INTEGER;
		BEGIN
			np := LEN(func.arguments[vectorIndex]);
			NEW(p, np);
			FOR i := 0 TO np-1 DO
				p[i] := SHORT(ENTIER(func.arguments[vectorIndex][i].Value() + 0.5))
			END;
			RETURN p;
		END GetIntWBDevVector;

		PROCEDURE (func: Function) Evaluate (OUT pred: ARRAY OF REAL);
		CONST
			time = 0; amt = 1; rate = 2; ii = 3; evid = 4; cmt = 5; addl = 6; ss = 7;
			pArray = 8;
		VAR
			i: INTEGER;
			m: PmetricsFunctionModel%s.ODEModel;
		BEGIN

			NEW(m);
			m.Pred(
				GetRealWBDevVector(pArray, func),
				GetRealWBDevVector(time, func),
				GetRealWBDevVector(amt, func),
				GetRealWBDevVector(rate, func),
				GetRealWBDevVector(ii, func),
				GetIntWBDevVector(evid, func),
				GetIntWBDevVector(cmt, func),
				GetIntWBDevVector(addl, func),
				GetIntWBDevVector(ss, func),
				pred);
(*			FOR i := 0 TO LEN(pred)-1 DO
				StdLog.Real(pred[i]); StdLog.Ln;
			END;
*)		
		END Evaluate;
		
		PROCEDURE (f: Factory) New (option: INTEGER): Function;
		VAR
			func: Function;
		BEGIN
			NEW(func); func.Initialize; RETURN func;
		END New;
		
		PROCEDURE Install*;
		BEGIN
			WBDevVector.Install(fact);
		END Install;
		
		PROCEDURE Init;
		VAR
			f: Factory;
		BEGIN
			NEW(f); fact := f;
		END Init;
		
	BEGIN
		Init;
	END WBDevModelPascal%s.
