FUNCTION_BLOCK GetScalingParameters
lowHeightScalingParam := 0.0;
highHeightScalingParam := 0.0;
lowVolumeScalingParam := 0.0;
highVolumeScalingParam := 0.0;
success := FALSE;

IF linpPondNumber = 1 THEN
	maxCalIndex := FindNumberOfCalPoints(1);
	
	IF maxCalIndex = 0 THEN
		success := FALSE;
	ELSIF maxCalIndex = 1 THEN
		lowHeightScalingParam := 0.0;
		highHeightScalingParam := pond1CalibrationHeight[1];
		lowVolumeScalingParam := 0.0;
		highVolumeScalingParam := pond1CalibrationVolume[1];
		success := TRUE;
	ELSE
		IF linpPondHeight <= pond1CalibrationHeight[1] THEN
			lowHeightScalingParam := 0.0;
			highHeightScalingParam := pond1CalibrationHeight[1];
			lowVolumeScalingParam := 0.0;
			highVolumeScalingParam := pond1CalibrationVolume[1];
			success := TRUE;
		ELSIF linpPondHeight >= pond1CalibrationHeight[maxCalIndex] THEN
			lowHeightScalingParam := pond1CalibrationHeight[maxCalIndex - 1];
			highHeightScalingParam := pond1CalibrationHeight[maxCalIndex];
			lowVolumeScalingParam := pond1CalibrationVolume[maxCalIndex - 1];
			highVolumeScalingParam := pond1CalibrationVolume[maxCalIndex];
			success := TRUE;
		ELSE
			FOR calIndex := 1 TO maxCalIndex - 1 DO
				IF linpPondHeight >= pond1CalibrationHeight[calIndex] AND linpPondHeight < pond1CalibrationHeight[calIndex + 1] THEN
					lowHeightScalingParam := pond1CalibrationHeight[calIndex];
					highHeightScalingParam := pond1CalibrationHeight[calIndex + 1];
					lowVolumeScalingParam := pond1CalibrationVolume[calIndex];
					highVolumeScalingParam := pond1CalibrationVolume[calIndex + 1];
					success := TRUE;
				END_IF;
			END_FOR;
		END_IF;
	END_IF;
	
ELSIF linpPondNumber = 2 THEN
	maxCalIndex := FindNumberOfCalPoints(2);
	
	IF maxCalIndex = 0 THEN
		success := FALSE;
	ELSIF maxCalIndex = 1 THEN
		lowHeightScalingParam := 0.0;
		highHeightScalingParam := pond2CalibrationHeight[1];
		lowVolumeScalingParam := 0.0;
		highVolumeScalingParam := pond2CalibrationVolume[1];
		success := TRUE;
	ELSE
		IF linpPondHeight <= pond2CalibrationHeight[1] THEN
			lowHeightScalingParam := 0.0;
			highHeightScalingParam := pond2CalibrationHeight[1];
			lowVolumeScalingParam := 0.0;
			highVolumeScalingParam := pond2CalibrationVolume[1];
			success := TRUE;
		ELSIF linpPondHeight >= pond2CalibrationHeight[maxCalIndex] THEN
			lowHeightScalingParam := pond2CalibrationHeight[maxCalIndex - 1];
			highHeightScalingParam := pond2CalibrationHeight[maxCalIndex];
			lowVolumeScalingParam := pond2CalibrationVolume[maxCalIndex - 1];
			highVolumeScalingParam := pond2CalibrationVolume[maxCalIndex];
			success := TRUE;
		ELSE
			FOR calIndex := 1 TO maxCalIndex - 1 DO
				IF linpPondHeight >= pond2CalibrationHeight[calIndex] AND linpPondHeight < pond2CalibrationHeight[calIndex + 1] THEN
					lowHeightScalingParam := pond2CalibrationHeight[calIndex];
					highHeightScalingParam := pond2CalibrationHeight[calIndex + 1];
					lowVolumeScalingParam := pond2CalibrationVolume[calIndex];
					highVolumeScalingParam := pond2CalibrationVolume[calIndex + 1];
					success := TRUE;
				END_IF;
			END_FOR;
		END_IF;
	END_IF;

ELSIF linpPondNumber = 3 THEN
	maxCalIndex := FindNumberOfCalPoints(3);
	
	IF maxCalIndex = 0 THEN
		success := FALSE;
	ELSIF maxCalIndex = 1 THEN
		lowHeightScalingParam := 0.0;
		highHeightScalingParam := pond3CalibrationHeight[1];
		lowVolumeScalingParam := 0.0;
		highVolumeScalingParam := pond3CalibrationVolume[1];
		success := TRUE;
	ELSE
		IF linpPondHeight <= pond3CalibrationHeight[1] THEN
			lowHeightScalingParam := 0.0;
			highHeightScalingParam := pond3CalibrationHeight[1];
			lowVolumeScalingParam := 0.0;
			highVolumeScalingParam := pond3CalibrationVolume[1];
			success := TRUE;
		ELSIF linpPondHeight >= pond3CalibrationHeight[maxCalIndex] THEN
			lowHeightScalingParam := pond3CalibrationHeight[maxCalIndex - 1];
			highHeightScalingParam := pond3CalibrationHeight[maxCalIndex];
			lowVolumeScalingParam := pond3CalibrationVolume[maxCalIndex - 1];
			highVolumeScalingParam := pond3CalibrationVolume[maxCalIndex];
			success := TRUE;
		ELSE
			FOR calIndex := 1 TO maxCalIndex - 1 DO
				IF linpPondHeight >= pond3CalibrationHeight[calIndex] AND linpPondHeight < pond3CalibrationHeight[calIndex + 1] THEN
					lowHeightScalingParam := pond3CalibrationHeight[calIndex];
					highHeightScalingParam := pond3CalibrationHeight[calIndex + 1];
					lowVolumeScalingParam := pond3CalibrationVolume[calIndex];
					highVolumeScalingParam := pond3CalibrationVolume[calIndex + 1];
					success := TRUE;
				END_IF;
			END_FOR;
		END_IF;
	END_IF;
	
ELSIF linpPondNumber = 4 THEN
	maxCalIndex := FindNumberOfCalPoints(4);
	
	IF maxCalIndex = 0 THEN
		success := FALSE;
	ELSIF maxCalIndex = 1 THEN
		lowHeightScalingParam := 0.0;
		highHeightScalingParam := pond4CalibrationHeight[1];
		lowVolumeScalingParam := 0.0;
		highVolumeScalingParam := pond4CalibrationVolume[1];
		success := TRUE;
	ELSE
		IF linpPondHeight <= pond4CalibrationHeight[1] THEN
			lowHeightScalingParam := 0.0;
			highHeightScalingParam := pond4CalibrationHeight[1];
			lowVolumeScalingParam := 0.0;
			highVolumeScalingParam := pond4CalibrationVolume[1];
			success := TRUE;
		ELSIF linpPondHeight >= pond4CalibrationHeight[maxCalIndex] THEN
			lowHeightScalingParam := pond4CalibrationHeight[maxCalIndex - 1];
			highHeightScalingParam := pond4CalibrationHeight[maxCalIndex];
			lowVolumeScalingParam := pond4CalibrationVolume[maxCalIndex - 1];
			highVolumeScalingParam := pond4CalibrationVolume[maxCalIndex];
			success := TRUE;
		ELSE
			FOR calIndex := 1 TO maxCalIndex - 1 DO
				IF linpPondHeight >= pond4CalibrationHeight[calIndex] AND linpPondHeight < pond4CalibrationHeight[calIndex + 1] THEN
					lowHeightScalingParam := pond4CalibrationHeight[calIndex];
					highHeightScalingParam := pond4CalibrationHeight[calIndex + 1];
					lowVolumeScalingParam := pond4CalibrationVolume[calIndex];
					highVolumeScalingParam := pond4CalibrationVolume[calIndex + 1];
					success := TRUE;
				END_IF;
			END_FOR;
		END_IF;
	END_IF;
	
END_IF;
END_FUNCTION_BLOCK