MODULE WBDevFunctionPiecewise3;

	IMPORT
		WBDevScalar,
		Math,
		MathFunc;
		
	TYPE
		Function = POINTER TO RECORD (WBDevScalar.Node) END;
		Factory = POINTER TO RECORD (WBDevScalar.Factory) END;
		
	VAR
		fact-: WBDevScalar.Factory;
		
	PROCEDURE (func: Function) DeclareArgTypes (OUT args: ARRAY OF CHAR);
	BEGIN
		args := "v";
	END DeclareArgTypes;
	
	PROCEDURE (func: Function) Evaluate (OUT value: REAL);
	CONST
		 
	VAR
		aVm: REAL;
		bVm: REAL;
		BSA_UNIPV: REAL;
		FEMALE: REAL;
		aVf: REAL;
		bVf: REAL;
		WEIGHT: REAL;
		HEIGHT: REAL;
		
	BEGIN
		bVf := func.arguments[0][0].Value();
		HEIGHT := func.arguments[0][1].Value();
		aVf := func.arguments[0][2].Value();
		aVm := func.arguments[0][3].Value();
		bVm := func.arguments[0][4].Value();
		FEMALE := func.arguments[0][5].Value();
		WEIGHT := func.arguments[0][6].Value();
		

		IF FEMALE = 0  THEN;
			value := (aVm + (bVm * BSA_UNIPV)); 
		ELSE;
			value := (aVf + (bVf * BSA_UNIPV));
		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
		WBDevScalar.Install(fact);
	END Install;
	
	PROCEDURE Init;
	VAR
		f: Factory;
	BEGIN
		NEW(f); fact := f;
	END Init;
	
BEGIN
	Init;
END WBDevFunctionPiecewise3.

