MODULE WBDevFunctionPiecewise2;

	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
		mFn: REAL;
		HSTATUS: REAL;
		mFo: REAL;
		mFd: REAL;
		
	BEGIN
		mFn := func.arguments[0][0].Value();
		mFd := func.arguments[0][1].Value();
		HSTATUS := func.arguments[0][2].Value();
		mFo := func.arguments[0][3].Value();
		

		IF HSTATUS = 1  THEN;
			value := mFn; 
		ELSIF  (HSTATUS = 2 ) THEN; 
			value := mFo; 
		ELSIF  (HSTATUS = 3 ) THEN; 
			value := mFd; 
		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 WBDevFunctionPiecewise2.

