PROGRAM Scaling
pond1Height := LinearScale(pond1Scaling.rawMin,
	pond1Scaling.rawMax,
	pond1Scaling.euMin,
	pond1Scaling.euMax,
	ANY_TO_REAL(_IO_P1_AI_00)) + pond1Offset;

pond2Height := LinearScale(pond2Scaling.rawMin,
	pond2Scaling.rawMax,
	pond2Scaling.euMin,
	pond2Scaling.euMax,
	ANY_TO_REAL(_IO_P1_AI_01)) + pond2Offset;
	
pond3Height := LinearScale(pond3Scaling.rawMin,
	pond3Scaling.rawMax,
	pond3Scaling.euMin,
	pond3Scaling.euMax,
	ANY_TO_REAL(_IO_P1_AI_02)) + pond3Offset;
	
pond4Height := LinearScale(pond4Scaling.rawMin,
	pond4Scaling.rawMax,
	pond4Scaling.euMin,
	pond4Scaling.euMax,
	ANY_TO_REAL(_IO_P1_AI_03)) + pond4Offset;

GetPond1ScalingParams(pond1Height, 1);
GetPond2ScalingParams(pond2Height, 2);
GetPond3ScalingParams(pond3Height, 3);
GetPond4ScalingParams(pond4Height, 4);

IF GetPond1ScalingParams.success THEN
	pond1Volume := LinearScale(GetPond1ScalingParams.lowHeightScalingParam, 
		GetPond1ScalingParams.highHeightScalingParam, 
		GetPond1ScalingParams.lowVolumeScalingParam,
		GetPond1ScalingParams.highVolumeScalingParam,
		pond1Height);
END_IF;

IF GetPond2ScalingParams.success THEN
	pond2Volume := LinearScale(GetPond2ScalingParams.lowHeightScalingParam, 
		GetPond2ScalingParams.highHeightScalingParam, 
		GetPond2ScalingParams.lowVolumeScalingParam,
		GetPond2ScalingParams.highVolumeScalingParam,
		pond2Height);
END_IF;

IF GetPond3ScalingParams.success THEN
	pond3Volume := LinearScale(GetPond3ScalingParams.lowHeightScalingParam, 
		GetPond3ScalingParams.highHeightScalingParam, 
		GetPond3ScalingParams.lowVolumeScalingParam,
		GetPond3ScalingParams.highVolumeScalingParam,
		pond3Height);
END_IF;

IF GetPond4ScalingParams.success THEN
	pond4Volume := LinearScale(GetPond4ScalingParams.lowHeightScalingParam, 
		GetPond4ScalingParams.highHeightScalingParam, 
		GetPond4ScalingParams.lowVolumeScalingParam,
		GetPond4ScalingParams.highVolumeScalingParam,
		pond4Height);
END_IF;

IF cfgNumberOfPonds = 1 THEN
	pondVolumeTotal := pond1Volume;
	pond2Height := 0.0;
	pond2Volume := 0.0;
	pond3Height := 0.0;
	pond3Volume := 0.0;
	pond4Height := 0.0;
	pond4Volume := 0.0;
ELSIF cfgNumberOfPonds = 2 THEN
	pondVolumeTotal := pond1Volume + pond2Volume;
	pond3Height := 0.0;
	pond3Volume := 0.0;
	pond4Height := 0.0;
	pond4Volume := 0.0;
ELSIF cfgNumberOfPonds = 3 THEN
	pondVolumeTotal := pond1Volume + pond2Volume + pond3Volume;
	pond4Height := 0.0;
	pond4Volume := 0.0;
ELSIF cfgNumberOfPonds = 4 THEN 
	pondVolumeTotal := pond1Volume + pond2Volume + pond3Volume + pond4Volume;
END_IF;

		
	

END_PROGRAM