COMPILE FUNCTION obj_Test_Point_Map(Method,Parms)

/*
	Methods for Test_Point_Map object
    
	05/17/2006 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    PointToResult(MapID,PointIDs,Thick,SheetRho,HgCV1,HgCV2)		;* Sort readings by ResultNos - This is the raw readings sort
	ResultToPoint(MapID,ResultNos,Thick,SheetRho,HgCV1,HgCV2)		;* Sort readings by PointIDs - This is the format in the RDS_TEST (Metrology) window.
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, obj_Notes, ErrMsg

$INSERT TEST_POINT_MAP_EQUATES
$INSERT MSG_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_Test_Point_Map"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'PointToResult'			; GOSUB PointToResult
	CASE Method = 'ResultToPoint'			; GOSUB ResultToPoint
	CASE 1

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result


* * * * * * *
PointToResult:
* * * * * * *

MapID			= Parms[1,@RM]
PointIDs		= Parms[COL2()+1,@RM]
ThickReadsIn	= Parms[COL2()+1,@RM]
SheetRhoReadsIn	= Parms[COL2()+1,@RM]
HgCV1ReadsIn	= Parms[COL2()+1,@RM]
HgCV2ReadsIn	= Parms[COL2()+1,@RM]

IF MapID = ''		THEN ErrorMsg = 'Null Parameter "MapID" passed to routine. (':Method:')'
IF PointIDs = ''	THEN ErrorMsg = 'Null Parameter "PointIDs" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN
MapRec = XLATE('TEST_POINT_MAP',MapID,'','X')

IF MapRec = '' THEN
	ErrorMsg = 'Invalid TestPointMap "MapID" passed to routine. (':Method:')'
	RETURN
END

ResultNosOut		= ''
ThickReadsOut		= ''
SheetRhoReadsOut	= ''
HgCV1ReadsOut		= ''
HgCV2ReadsOut		= ''

FOR I = 1 TO COUNT(PointIDs,@VM) + (PointIDs NE '')
	PointID = PointIDs<1,I>
	LOCATE PointID IN MapRec<TEST_POINT_MAP_POINT_ID$> USING @VM SETTING Pos THEN
		ReadNo = MapRec<TEST_POINT_MAP_RESULT_NO$,Pos>
		ResultNosOut<1,ReadNo>	= MapRec<TEST_POINT_MAP_RESULT_NO$,Pos>
		ThickReadsOut<1,ReadNo>	= ThickReadsIn<1,I>
	END
NEXT I

* Sheet Row uses map "4PP"

IF MapID = 'HTR5' THEN
	NULL
END ELSE
	MapRec = XLATE('TEST_POINT_MAP','4PP','','X')
END

FOR I = 1 TO COUNT(PointIDs,@VM) + (PointIDs NE '')
	PointID = PointIDs<1,I>
	
	LOCATE PointID IN MapRec<TEST_POINT_MAP_POINT_ID$> USING @VM SETTING Pos THEN
		ReadNo = MapRec<TEST_POINT_MAP_RESULT_NO$,Pos>
		SheetRhoReadsOut<1,ReadNo>	= SheetRhoReadsIn<1,I>
	END
NEXT I


* Resistivity uses map "HGCV"

MapRec = XLATE('TEST_POINT_MAP','HGCV','','X')

FOR I = 1 TO COUNT(PointIDs,@VM) + (PointIDs NE '')
	PointID = PointIDs<1,I>
	
	LOCATE PointID IN MapRec<TEST_POINT_MAP_POINT_ID$> USING @VM SETTING Pos THEN
		ReadNo = MapRec<TEST_POINT_MAP_RESULT_NO$,Pos>
		HgCV1ReadsOut<1,ReadNo> = HgCV1ReadsIn<1,I>
		HgCv2ReadsOut<1,ReadNo>	= HgCV2ReadsIn<1,I>
	END
NEXT I

Result = ResultNosOut:@FM:ThickReadsOut:@FM:SheetRhoReadsOut:@FM:HgCV1ReadsOut:@FM:HgCV2ReadsOut

RETURN


* * * * * * *
ResultToPoint:
* * * * * * *

MapID			= Parms[1,@RM]
ResultNos		= Parms[COL2()+1,@RM]
ThickReadsIn	= Parms[COL2()+1,@RM]
SheetRhoReadsIn	= Parms[COL2()+1,@RM]
HgCV1ReadsIn	= Parms[COL2()+1,@RM]
HgCV2ReadsIn	= Parms[COL2()+1,@RM]

IF MapID = ''		THEN ErrorMsg = 'Null Parameter "MapID" passed to routine. (':Method:')'
IF ResultNos = ''	THEN ErrorMsg = 'Null Parameter "ResultNos" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN
MapRec = XLATE('TEST_POINT_MAP',MapID,'','X')

IF MapRec = '' THEN
	ErrorMsg = 'Invalid TestPointMap "MapID" passed to routine. (':Method:')'
	RETURN
END

MapResultNos = MapRec<TEST_POINT_MAP_RESULT_NO$>
MapPointIDs  = MapRec<TEST_POINT_MAP_POINT_ID$>

PointIDsOut			= ''
ThickReadsOut		= ''
SheetRhoReadsOut	= ''
HgCV1ReadsOut		= ''
HgCV2ReadsOut		= ''

FOR I = 1 TO COUNT(ResultNos,@VM) + (ResultNos NE '')
	ResultNo = ResultNos<1,I>
	LOCATE ResultNo IN MapResultNos USING @VM SETTING Pos THEN
		PointIDsOut<1,Pos>		= MapPointIDs<1,Pos>
		ThickReadsOut<1,Pos>	= ThickReadsIn<1,I>
	END
NEXT I


* Sheet Row uses map "4PP"

IF MapID = 'HTR5' THEN
	NULL
END ELSE
	MapRec = XLATE('TEST_POINT_MAP','4PP','','X')
END

FOR I = 1 TO COUNT(ResultNos,@VM) + (ResultNos NE '')
	ResultNo = ResultNos<1,I>
	LOCATE ResultNo IN MapRec<TEST_POINT_MAP_RESULT_NO$> USING @VM SETTING Pos THEN
		SheetRhoReadsOut<1,Pos>	= SheetRhoReadsIn<1,I>
	END
NEXT I

MapRec = XLATE('TEST_POINT_MAP','HGCV','','X')

FOR I = 1 TO COUNT(ResultNos,@VM) + (ResultNos NE '')
	ResultNo = ResultNos<1,I>
	LOCATE ResultNo IN MapRec<TEST_POINT_MAP_RESULT_NO$> USING @VM SETTING Pos THEN
		MapPointID = MapRec<TEST_POINT_MAP_POINT_ID$,Pos>
		LOCATE MapPointID IN PointIDsOut USING @VM SETTING PointPos THEN
			HgCV1ReadsOut<1,PointPos> = HgCV1ReadsIn<1,I>
			HgCV2ReadsOut<1,PointPos> = HgCV2ReadsIn<1,I>
		END
	END
NEXT I
		

Result = PointIDsOut:@FM:ThickReadsOut:@FM:SheetRhoReadsOut:@FM:HgCV1ReadsOut:@FM:HgCv2ReadsOut

RETURN
