COMPILE FUNCTION obj_Clean_Insp(Method,Parms)

/*
	Methods for CLEAN_INSP table
    
	08/5/2009 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Create(DataStruct)		;* Create new record
	
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey,  obj_Prod_Spec, Send_Dyn
DECLARE FUNCTION obj_RDS_Test, Environment_Services, Error_Services
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, obj_WO_Step, obj_RDS_Layer, obj_RDS_Test, obj_WM_In,obj_WO_Mat
DECLARE SUBROUTINE ErrMsg

$INSERT MSG_EQUATES
$INSERT DICT_EQUATES

$INSERT CLEAN_INSP_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT PROD_SPEC_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT SURFACE_SCAN_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT EPI_PART_EQUATES

EQU CRLF$	TO \0D0A\
EQU TAB$	TO CHAR(9)

EQU ACTION$ACTIONS				TO 1	;* Data structures for each action
EQU ACTION$SIGS					TO 2
EQU ACTION$SIG_DTMS				TO 3
EQU ACTION$TOOLS				TO 4
EQU ACTION$SPEC_CLEAN_TOOL		TO 5
EQU ACTION$SPEC_MICROSCOPE		TO 6
EQU ACTION$SPEC_BRIGHTLIGHT		TO 7
EQU ACTION$SPEC_SURFSCAN_RECIPE	TO 8
EQU ACTION$SPEC_EDGE            TO 9


$INSERT PRS_LAYER_EQU	;* Used to return obj_Prod_Spec_CI values

ErrTitle = 'Error in Stored Procedure "obj_Clean_Insp"'
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 = 'Create'			; GOSUB Create
    CASE Method = 'Desc'			; GOSUB Desc
    CASE Method = 'Delete'			; GOSUB Delete
    CASE Method = 'CurrStatus'		; GOSUB CurrStatus
    CASE Method = 'SigComp'			; GOSUB SigComp
    CASE Method = 'SetClean'		; GOSUB SetClean
    CASE Method = 'SetInsp'			; GOSUB SetInsp
    CASE Method = 'SetScan'			; GOSUB SetScan
    CASE Method = 'SendToSPC'		; GOSUB SendToSPC
    CASE Method = 'WMOConv'			; GOSUB WMOConv
    CASE Method = 'GetActions'		; GOSUB GetActions
    CASE Method = 'SpecDelta'		; GOSUB SpecDelta	
        
    CASE 1
        
        
END CASE

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

RETURN Result




* * * * * * *
Create:
* * * * * * *
    
    WONo	= Parms[1,@RM]
    WOStep	= Parms[COL2()+1,@RM]
    CassNo	= Parms[COL2()+1,@RM]
    Stages	= Parms[COL2()+1,@RM]	;* pass as a @VM'd list of stages
    RDSNo	= Parms[COL2()+1,@RM]
    PSNo	= Parms[COL2()+1,@RM]
    PSRec	= Parms[COL2()+1,@RM]
    
    IF WONo = ''	THEN ErrorMsg = 'Null Parameter "WONo" passed to routine. (':Method:')'
    IF WOStep  = ''	THEN ErrorMsg = 'Null Parameter "WOStep" passed to routine. (':Method:')'
    IF Stages  = ''	THEN ErrorMsg = 'Null Parameter "Stages" passed to routine. (':Method:')'
    IF PSNo  = ''	THEN ErrorMsg = 'Null Parameter "PSNo" passed to routine. (':Method:')'
    
    IF ErrorMsg NE '' THEN RETURN
    
    IF PSRec = '' THEN
        PSRec = XLATE('PROD_SPEC',PSNo,'','X')
    END
    
    IF PSRec = '' THEN
        ErrorMsg = 'Invalid Parameter "PSNo" passed to routine. (':Method:')'
        RETURN
    END
    
    StageCnt = COUNT(Stages,@VM) + (Stages NE '')
    
    FOR N = 1 TO StageCnt
        Stage = Stages<1,N>
        
        PRSStageRec = XLATE('PRS_STAGE',PSNo:'*':Stage,'','X')
        
        CIRec = ''
        
        CIRec<CLEAN_INSP_SPEC_INSP_REQ$>          = PRSStageRec<PRS_STAGE_INSP_SIG_REQ$>
        CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>       = PRSStageRec<PRS_STAGE_BRIGHTLIGHT$>		    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>        = PRSStageRec<PRS_STAGE_MICROSCOPE$>		    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_EDGE$>              = PRSStageRec<PRS_STAGE_EDGE$>                ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_PITS$>              = PRSStageRec<PRS_STAGE_PITS$>			    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_MOUNDS$>            = PRSStageRec<PRS_STAGE_MOUNDS$>			    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_BL_DEFECTS$>        = PRSStageRec<PRS_STAGE_BL_DEFECTS$>		    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_SPOTS$>             = PRSStageRec<PRS_STAGE_SPOTS$>			    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_FOV$>               = PRSStageRec<PRS_STAGE_FOV$>				    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_SCRATCHES$>         = PRSStageRec<PRS_STAGE_SCRATCHES$>		    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_SCRATCH_LEN$>       = PRSStageRec<PRS_STAGE_SCRATCH_LEN$>		    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_LPD$>               = PRSStageRec<PRS_STAGE_LPD$>				    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_STACK_FAULTS$>      = PRSStageRec<PRS_STAGE_STACK_FAULTS$>	    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_SPIKES$>            = PRSStageRec<PRS_STAGE_SPIKES$>			    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_BSIDE_SCRATCHES$>   = PRSStageRec<PRS_STAGE_BSIDE_SCRATCHES$>	    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_BSIDE_SCRATCH_LEN$> = PRSStageRec<PRS_STAGE_BSIDE_SCRATCH_LEN$>   ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_BSIDE_NODULES$>     = PRSStageRec<PRS_STAGE_BSIDE_NODULES$>	    ;* Visual Inspection
        CIRec<CLEAN_INSP_SPEC_BSIDE_SPIKES$>      = PRSStageRec<PRS_STAGE_BSIDE_SPIKES$>	    ;* Visual Inspection
        
        IF Stage = 'PRE' THEN
            EpiPartNo = XLATE('WO_LOG',WONo,WO_LOG_EPI_PART_NO$,'X')
            EpiPartRec = XLATE('EPI_PART',EpiPartNo,'','X')
            
            CIRec<CLEAN_INSP_SPEC_CLEAN_SUBOXIDE$>			= EpiPartRec<EPI_PART_SUB_OXIDE$>	
            CIRec<CLEAN_INSP_SPEC_CLEAN_OXIDE_ANGSTROMS$>	= EpiPartRec<EPI_PART_SUB_OXIDE_ANGSTROMS$>
        END
        
        CIRec<CLEAN_INSP_SPEC_SURFSCAN_REQ$>			= PRSStageRec<PRS_STAGE_SURFSCAN_SIG_REQ$>
        CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>			= PRSStageRec<PRS_STAGE_SURFSCAN_RECIPE$>	;* Surface Scan
        CIRec<CLEAN_INSP_SPEC_SURF_HAZE$>				= PRSStageRec<PRS_STAGE_SURF_HAZE$>			;* Surface Scan
        CIRec<CLEAN_INSP_SPEC_SURF_DEFECTS$>			= PRSStageRec<PRS_STAGE_SURF_DEFECTS$>		;* Surface Scan
        CIRec<CLEAN_INSP_SPEC_SS_SAMP_QTY$>				= PRSStageRec<PRS_STAGE_SS_SAMP_QTY$>		;* Surface Scan
        
        CIRec<CLEAN_INSP_SPEC_CLEAN_REQ$>				= PRSStageRec<PRS_STAGE_CLEAN_SIG_REQ$>
        CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>				= PRSStageRec<PRS_STAGE_CLEAN_TOOL$>		;* Cleans
        CIRec<CLEAN_INSP_SPEC_CLEAN_RECIPE$>			= PRSStageRec<PRS_STAGE_CLEAN_RECIPE$>		;* Cleans
        
        IF CIRec NE '' THEN
            
            CINo = NextKey('CLEAN_INSP')
            
            If Error_Services('NoError') then
                
                CIRec<CLEAN_INSP_WO_NO$>		= WONo
                CIRec<CLEAN_INSP_WO_STEP$>		= WOStep
                CIRec<CLEAN_INSP_CASS_NO$>		= CassNo
                CIRec<CLEAN_INSP_STAGE$>		= Stage
                CIRec<CLEAN_INSP_RDS_NO$>		= RDSNo
                
                obj_Tables('WriteRec','CLEAN_INSP':@RM:CINo:@RM:@RM:CIRec)
                
                Result<1,N> = CINo
            END ELSE
                // Failed to get next key ID from sequential counter record (%SK%)
                Result = 0
                RETURN Result
            END
        END
        
    NEXT N
    
RETURN Result




* * * * * * *
Desc:
* * * * * * *
    
    CINo = Parms[1,@RM]
    CIRec = Parms[COL2()+1,@RM]
    
    IF CINo		= '' THEN RETURN
    IF CIRec	= '' THEN CIRec = XLATE('CLEAN_INSP',CINo,'','X')
    
    Stage		= CIRec<CLEAN_INSP_STAGE$>
    SpecFwiLwi	= CIRec<CLEAN_INSP_SPEC_FWI_LWI$>
    
    
    CTool		= CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>
    CRecipe		= CIRec<CLEAN_INSP_SPEC_CLEAN_RECIPE$>
    
    IF CTool = 'No' THEN CTool = ''
    
    IBrightlight	= CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>
    IMicroscope		= CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>
    
    SurfscanRecipe	= CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>
    
    BEGIN CASE
        CASE Stage = 'PRE'							; LabelText = 'Pre Epi '
        CASE Stage = 'POST'							; LabelText = 'Post Epi '
        CASE Stage = 'FWI'							; LabelText = 'First Wafer'
        CASE Stage = 'LWI'							; LabelText = 'Last Wafer '
        CASE Stage = 'WFR' AND SpecFwiLwi = 'FWI'	; LabelText = 'First Wafer '
        CASE Stage = 'WFR' AND SpecFwiLwi = 'LWI'	; LabelText = 'Last Wafer '
        CASE Stage[1,3] = 'WFR'	AND LEN(Stage) > 3	; LabelText = 'Wafer ':Stage[4,99]:' Extra '
        CASE Stage[1,3] = 'WFR'						; LabelText = 'Wafer '
        CASE 1										; LabelText = 'Cleaning & Inspection '
    END CASE
    
    IF Ctool OR CRecipe				THEN CleanText = 'Cleaning'		ELSE CleanText = ''
    IF IBrightLight OR IMicroscope	THEN InspText = 'Inspection'	ELSE InspText = ''
    IF SurfscanRecipe	THEN ScanText = 'Surfscan'					ELSE ScanText = ''
    
    IF CleanText NE '' THEN
        LabelText := CleanText
        IF InspText NE '' THEN LabelText := ' & ':InspText
        IF ScanText NE '' THEN LabelText := ' & ':ScanText
    END ELSE
        IF InspText NE '' THEN
            LabelText := InspText
            IF ScanText NE '' THEN LabelText := ' & ':ScanText
        END ELSE
            IF ScanText NE '' THEN LabelText := ScanText
        END
    END
    
    Result = LabelText
    
RETURN


* * * * * * *
CurrStatus:
* * * * * * *

    CINo = Parms[1,@RM]
    CIRec = Parms[COL2()+1,@RM]
    
    IF CINo = '' THEN RETURN	;* Called from the dictionary
    
    IF CIRec = ''	THEN CIRec = XLATE('CLEAN_INSP',CINo,'','X')
    
    IF CIRec = ''	THEN RETURN		;* ErrorMsg = 'Null Parameter "CIRec" passed to routine. (':Method:')'
    
    IF ErrorMsg NE '' THEN RETURN
    
    SCSubOxide		= CIRec<CLEAN_INSP_SPEC_CLEAN_SUBOXIDE$>
    SCTool			= CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>
    SCAkrionRecipe	= CIRec<CLEAN_INSP_SPEC_CLEAN_AKRION_RECIPE$>
    
    SBrightLight	= CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>
    SMicroscope		= CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>
    
    SSurfscanRecipe	= CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>
    
    IF SCTool = 'No' THEN SCTool = ''
    
    IF SCSubOxide OR SCTool OR SCAkrionRecipe	THEN
        IF CIRec<CLEAN_INSP_CLEAN_SIG$,1> = ''	THEN
            Result = 'RTC'
        END
    END
    
    
    IF SBrightLight OR SMicroscope THEN
        
        
        
        * Visual Inspection
        
        IF CIRec<CLEAN_INSP_INSP_SIG$,1> = '' THEN
            Result = 'RTI'
        END ELSE
            
            SurfaceComp = 1
            IF CIRec<CLEAN_INSP_SPEC_LPD$> NE '' 			AND CIRec<CLEAN_INSP_INSP_LPD_IN$>  = '' 		THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_PITS$> NE ''			AND CIRec<CLEAN_INSP_INSP_PITS$> = ''			THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_MOUNDS$> NE ''			AND CIRec<CLEAN_INSP_INSP_MOUNDS$> = ''			THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_BL_DEFECTS$> NE ''		AND CIRec<CLEAN_INSP_INSP_BL_DEFECTS$> = ''		THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_STACK_FAULTS$> NE ''	AND CIRec<CLEAN_INSP_INSP_STACK_FAULTS$> = ''	THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_SPIKES$> NE ''			AND CIRec<CLEAN_INSP_INSP_SPIKES$> = ''			THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_SPOTS$> NE ''			AND CIRec<CLEAN_INSP_INSP_SPOTS$> = ''			THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_FOV$> NE ''			AND CIRec<CLEAN_INSP_INSP_FOV$> = ''			THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_SCRATCHES$> NE ''		AND CIRec<CLEAN_INSP_INSP_SCRATCHES$> = ''		THEN SurfaceComp = 0
            IF CIRec<CLEAN_INSP_SPEC_SCRATCH_LEN$> NE ''	AND CIRec<CLEAN_INSP_INSP_SCRATCH_LEN$> = ''	THEN SurfaceComp = 0
            
            IF SurfaceComp = 0 THEN
                Result = 'RTI'
                RETURN
            END
            
        END ;* End of check for Inspection signature
        
        
    END
    
    IF SSurfscanRecipe	THEN
        
        * Surfscan 
        
        SpecSurfDef	= OCONV(CIRec<CLEAN_INSP_SPEC_SURF_DEFECTS$, 1>,'MD0')
        
        SurfDefMax	= OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$, 1>,'MD0')
        SurfDefAvg	= OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$, 1>,'MD3')
        
        SpecSurfHaze	= OCONV(CIRec<CLEAN_INSP_SPEC_SURF_HAZE$, 1>,'MD2')
        SurfHazeAvgAvg	= OCONV( CIRec<CLEAN_INSP_SCAN_HAZE_AVG_AVG$, 1>,'MD3')
        
        IF SpecSurfDef NE '' THEN
            IF SurfDefMax NE '' THEN
                IF SurfDefMax GE SpecSurfDef THEN
                    Result = 'OUT'
                    RETURN
                END
            END
            IF SurfDefAvg NE '' THEN
                IF SurfDefAvg GE SpecSurfDef THEN
                    Result = 'OUT'
                    RETURN
                END
            END
        END
        
        IF SpecSurfHaze NE '' THEN
            IF SurfHazeAvgAvg NE '' THEN
                IF SurfHazeAvgAvg GE SpecSurfHaze THEN
                    Result = 'OUT'
                    RETURN
                END
            END
        END
        
        IF CIRec<CLEAN_INSP_SCAN_SIG$,1> = '' THEN
            IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$, 1> = '' THEN
                IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$, 1> = '' THEN
                    IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$, 1> = '' THEN
                        IF CIRec<CLEAN_INSP_SCAN_TOOL$, 1> NE '' THEN
                            Result = 'RTS'
                            RETURN
                        END
                    END
                END
            END
        END
        
    END
    
RETURN


* * * * * * *
SigComp:
* * * * * * *
    
    /*
    	This returns a set of 3 tri-state boolean values, one for each section Cleans/Insp/Surfscan
    	Null	= Nothing specifed
    	0		= Specified - no signature
    	1		= Specified and at least one signature complete
    */
    
    
    CINo = Parms[1,@RM]
    CIRec = Parms[COL2()+1,@RM]
    
    IF CINo = '' THEN RETURN	;* Called from the dictionary
    
    IF CIRec = ''	THEN CIRec = XLATE('CLEAN_INSP',CINo,'','X')
    
    IF CIRec = ''	THEN RETURN		;* ErrorMsg = 'Null Parameter "CIRec" passed to routine. (':Method:')'
    
    IF ErrorMsg NE '' THEN RETURN
    
    SCSubOxide		= CIRec<CLEAN_INSP_SPEC_CLEAN_SUBOXIDE$>
    SCTool			= CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>
    SCAkrionRecipe	= CIRec<CLEAN_INSP_SPEC_CLEAN_AKRION_RECIPE$>
    
    SBrightLight = CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>
    SMicroscope  = CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>
    SEdge        = CIRec<CLEAN_INSP_SPEC_EDGE$>
    
    SSurfscanRecipe	= CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>
    
    IF SCTool = 'No' THEN SCTool = ''
    
    * Cleans
    
    IF SCSubOxide OR SCTool OR SCAkrionRecipe	THEN
        IF CIRec<CLEAN_INSP_CLEAN_SIG$,1> = ''	THEN
            Result<1,1> = 0
        END Else
            Result<1,1> = 1
        END
    END ELSE
        Result<1,1> = ''	;* No Cleans specified
    END
    
    * Inspection
    
    IF SBrightLight OR SMicroscope OR SEdge THEN
        IF CIRec<CLEAN_INSP_INSP_SIG$,1> = '' THEN
            Result<1,2> = 0
        END ELSE
            Result<1,2> = 1
        END
    END ELSE
        Result<1,2> = ''
    END
    
    * SurfaceScan
    
    IF SSurfscanRecipe	THEN
        IF CIRec<CLEAN_INSP_SCAN_SIG_DTM$,1> = '' THEN
            Result<1,3> = 0
        END ELSE
            Result<1,3> = 1
        END
    END ELSE
        Result<1,3> = ''
    END
    
RETURN



* * * * * * *
SpecDelta:
* * * * * * *
    
    CINo		= Parms[1,@RM]
    PSStageKey	= Parms[COL2()+1,@RM]
    
    IF CINo			= '' THEN ErrorMsg = 'Null parameter "CINo" passed to routine  . (':Method:')'
    IF PSStageKey	= '' THEN ErrorMsg = 'Null parameter "PSStageKey" passed to routine  . (':Method:')'
    
    PRSStageRec = XLATE('PRS_STAGE',PSStageKey,'','X')
    
    IF PRSStageRec = '' THEN
        otParms = 'CLEAN_INSP':@RM:CINo
        obj_Tables('DeleteRec',otParms)
        RETURN
    END
    
    IF ErrorMsg NE '' THEN RETURN
    
    otParms = 'CLEAN_INSP':@RM:CINo
    CIRec = obj_Tables('ReadRec',otParms)
    
    IF Get_Status(errCode) THEN RETURN
    
    WONo	= CIRec<CLEAN_INSP_WO_NO$>
    WOStep	= CIRec<CLEAN_INSP_WO_STEP$>
    CassNo	= CIRec<CLEAN_INSP_CASS_NO$>
    Stage	= CIRec<CLEAN_INSP_STAGE$>
    RDSNo	= CIRec<CLEAN_INSP_RDS_NO$>
    
    CIRec<CLEAN_INSP_SPEC_INSP_REQ$>				= PRSStageRec<PRS_STAGE_INSP_SIG_REQ$>
    CIRec<CLEAN_INSP_SPEC_SURFSCAN_REQ$>			= PRSStageRec<PRS_STAGE_SURFSCAN_SIG_REQ$>
    CIRec<CLEAN_INSP_SPEC_CLEAN_REQ$>				= PRSStageRec<PRS_STAGE_CLEAN_SIG_REQ$>
    
    CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>  = PRSStageRec<PRS_STAGE_BRIGHTLIGHT$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>   = PRSStageRec<PRS_STAGE_MICROSCOPE$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_EDGE$>         = PRSStageRec<PRS_STAGE_EDGE$>		        ;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_PITS$>         = PRSStageRec<PRS_STAGE_PITS$>				;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_MOUNDS$>       = PRSStageRec<PRS_STAGE_MOUNDS$>			;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_BL_DEFECTS$>   = PRSStageRec<PRS_STAGE_BL_DEFECTS$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_SPOTS$>        = PRSStageRec<PRS_STAGE_SPOTS$>			;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_FOV$>          = PRSStageRec<PRS_STAGE_FOV$>				;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_SCRATCHES$>    = PRSStageRec<PRS_STAGE_SCRATCHES$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_SCRATCH_LEN$>  = PRSStageRec<PRS_STAGE_SCRATCH_LEN$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_LPD$>          = PRSStageRec<PRS_STAGE_LPD$>				;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_STACK_FAULTS$> = PRSStageRec<PRS_STAGE_STACK_FAULTS$>		;* Visual Inspection
    CIRec<CLEAN_INSP_SPEC_SPIKES$>       = PRSStageRec<PRS_STAGE_SPIKES$>			;* Visual Inspection
    CIRec<CLEAN_INSP_INSP_INTERVAL$>     = PRSStageRec<PRS_STAGE_INSP_INTERVAL$>    ;* Visual Inspection
    
    CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>			= PRSStageRec<PRS_STAGE_SURFSCAN_RECIPE$>	;* Surface Scan
    CIRec<CLEAN_INSP_SPEC_SURF_HAZE$>				= PRSStageRec<PRS_STAGE_SURF_HAZE$>			;* Surface Scan
    CIRec<CLEAN_INSP_SPEC_SURF_DEFECTS$>			= PRSStageRec<PRS_STAGE_SURF_DEFECTS$>		;* Surface Scan
    CIRec<CLEAN_INSP_SPEC_SS_SAMP_QTY$>				= PRSStageRec<PRS_STAGE_SS_SAMP_QTY$>		;* Surface Scan
    
    CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>				= PRSStageRec<PRS_STAGE_CLEAN_TOOL$>		;* Cleans
    CIRec<CLEAN_INSP_SPEC_CLEAN_RECIPE$>			= PRSStageRec<PRS_STAGE_CLEAN_RECIPE$>		;* Cleans
    
    otParms = FieldStore(otParms,@RM,4,0,CIRec)
    obj_Tables('WriteRec',otParms)
    
    IF WONo NE '' AND CassNo NE '' THEN
        obj_WO_Mat('RefreshSigProfile',WONo:'*':CassNo)
    END
    
    
RETURN


********************************************************************************************************************************

* * * * * * *
WMOConv:
* * * * * * * 
    
    * appears dead (not called anywhere 1/24/2013 JCH)
    
    WONo	= Parms[1,@RM]
    StepNo	= Parms[COL2()+1,@RM]
    CassNo	= Parms[COL2()+1,@RM]
    
    Stage = 'POST'
    RDSNo = ''
    
    WMORec = XLATE('WM_OUT',WONo:'*':StepNo:'*':CassNo,'','X')
    
    * Build Specification driven fields
    
    PostStageRec = ''
    
    PostStageRec<CLEAN_INSP_WO_NO$>		= WONo
    PostStageRec<CLEAN_INSP_WO_STEP$>	= StepNo
    PostStageRec<CLEAN_INSP_CASS_NO$>	= CassNo
    PostStageRec<CLEAN_INSP_STAGE$>		= Stage
    PostStageRec<CLEAN_INSP_RDS_NO$>	= RDSNo
    
    SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
    SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostAkrionRecipe$>
    
    IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
    IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
    
    IF SCTool NE '' OR SCToolRecipe NE '' THEN
        PostStageRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>			= SCTool 
        PostStageRec<CLEAN_INSP_SPEC_CLEAN_AKRION_RECIPE$>	= SCToolRecipe
    END
    
    PostStageRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>			= PSRec<PROD_SPEC_POST_CLEAN_BRIGHTLIGHT$>
    PostStageRec<CLEAN_INSP_SPEC_SURFSCAN_REQ$>				= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN$>
    PostStageRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>		= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN_RECIPE$>
    
    IF PostStageRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$> = 1 THEN
        PostStageRec<CLEAN_INSP_SPEC_PITS$>				= PSRec<PROD_SPEC_POST_PITS$>
        PostStageRec<CLEAN_INSP_SPEC_MOUNDS$>			= PSRec<PROD_SPEC_POST_MOUNDS$>
        PostStageRec<CLEAN_INSP_SPEC_BL_DEFECTS$>		= PSRec<PROD_SPEC_POST_BL_DEFECTS$>
        PostStageRec<CLEAN_INSP_SPEC_SPOTS$>			= PSRec<PROD_SPEC_POST_SPOTS$>
        PostStageRec<CLEAN_INSP_SPEC_FOV$>				= PSRec<PROD_SPEC_POST_FOV$>
        PostStageRec<CLEAN_INSP_SPEC_SCRATCHES$>		= PSRec<PROD_SPEC_POST_SCRATCHES$>
        PostStageRec<CLEAN_INSP_SPEC_SCRATCH_LEN$>		= PSRec<PROD_SPEC_POST_SCRATCH_LEN$>
        PostStageRec<CLEAN_INSP_SPEC_LPD$>				= PSRec<PROD_SPEC_POST_LPD$>
        PostStageRec<CLEAN_INSP_SPEC_STACK_FAULTS$>		= PSRec<PROD_SPEC_POST_STACK_FAULTS$>
        PostStageRec<CLEAN_INSP_SPEC_SPIKES$>			= PSRec<PROD_SPEC_POST_SPIKES$>
    END
    
    PostStageRec<CLEAN_INSP_SPEC_SURF_HAZE$>			= PSRec<PROD_SPEC_POST_CLEAN_SURF_HAZE$>
    PostStageRec<CLEAN_INSP_SPEC_SURF_DEFECTS$>			= PSRec<PROD_SPEC_POST_CLEAN_SURF_DEFECTS$>
    PostStageRec<CLEAN_INSP_SPEC_SS_SAMP_QTY$>			= PSRec<PROD_SPEC_POST_CLEAN_SS_SAMP_QTY$>
    
    
    PostStageRec<CLEAN_INSP_RDS_NO$>					= RDSNo
    PostStageRec<CLEAN_INSP_CLEAN_TOOL$>				= WMORec<WM_OUT_POST_CODE$>
    PostStageRec<CLEAN_INSP_CLEAN_BOAT_ID$>				= WMORec<WM_OUT_POST_BOAT_ID$>
    PostStageRec<CLEAN_INSP_CLEAN_SRD_NO$>				= WMORec<WM_OUT_POST_SRD_NO$>
    
    IF WMORec<WM_OUT_POST_CODE$> NE '' OR WMORec<WM_OUT_POST_BOAT_ID$> NE '' OR WMORec<WM_OUT_POST_SRD_NO$> NE '' THEN
        PostStageRec<CLEAN_INSP_CLEAN_SIG$>				= WMORec<WM_OUT_POST_EPI_SIG$>
        PostStageRec<CLEAN_INSP_CLEAN_SIG_DTM$>			= WMORec<WM_OUT_POST_EPI_SIG_DTM$>
    END
    
    PostStageRec<CLEAN_INSP_SHIFT$>						= WMORec<WM_OUT_SHIFT$>
    
    SurfaceScanRec = XLATE('SURFACE_SCAN',WONO:'*':StepNo:'*':CassNo:'*':'PC','','X')
    
    PostStageRec<CLEAN_INSP_SCAN_TOOL$>					= SurfaceScanRec<SURFACE_SCAN_SCAN_TOOL$> 
    PostStageRec<CLEAN_INSP_SCAN_SIG_DTM$>				= SurfaceScanRec<SURFACE_SCAN_SCAN_DTM$> 
    PostStageRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$>		= SurfaceScanRec<SURFACE_SCAN_SUM_OF_DEF_MIN$>
    PostStageRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$>		= SurfaceScanRec<SURFACE_SCAN_SUM_OF_DEF_MAX$>
    PostStageRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$>		= SurfaceScanRec<SURFACE_SCAN_SUM_OF_DEF_AVG$>
    PostStageRec<CLEAN_INSP_SCAN_HAZE_AVG_MIN$>			= SurfaceScanRec<SURFACE_SCAN_HAZE_AVG_MIN$>
    PostStageRec<CLEAN_INSP_SCAN_HAZE_AVG_MAX$>			= SurfaceScanRec<SURFACE_SCAN_HAZE_AVG_MAX$>
    PostStageRec<CLEAN_INSP_SCAN_HAZE_AVG_AVG$>			= SurfaceScanRec<SURFACE_SCAN_HAZE_AVG_AVG$>
    
    
    IF PostStageRec NE '' THEN
        
        RETURN
        
        
    END
    
    
RETURN



*****************

Stage = CIRec<CLEAN_INSP_STAGE$>

COxide		= CIRec<CLEAN_INSP_SPEC_CLEAN_SUBOXIDE$>
CAngstroms	= CIRec<CLEAN_INSP_SPEC_CLEAN_OXIDE_ANGSTROMS$>
CTool		= CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>
COxide		= CIRec<CLEAN_INSP_SPEC_CLEAN_AKRION_RECIPE$>	;********************* fix this !!!!!!!!!!!!!!!!!!!!

IF CTool[1,2] = 'No' OR CTool[1,2] = 'If' THEN CTool = ''

IBrightlight	= CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>
IMicroscope		= CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>

Surfscan		= CIRec<CLEAN_INSP_SPEC_SURFSCAN_REQ$>
SurfscanRecipe	= CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>

IF COxide OR CAngstroms OR CTool OR COxide	THEN
    
    IF CIRec<CLEAN_INSP_CLEAN_SIG$> = '' AND CTool NE '' THEN
        Result = 'RTC'
        RETURN
    END 
END

Stage = CIRec<CLEAN_INSP_STAGE$>

IF (IBrightLight OR IMicroscope) THEN
    
    IF CIRec<CLEAN_INSP_INSP_SIG$,1> = '' THEN
        
        NoSpec = 1
        
        IF CIRec<CLEAN_INSP_SPEC_LPD$> NE '' 			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_PITS$> NE ''			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_MOUNDS$> NE ''			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_BL_DEFECTS$> NE ''		THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_STACK_FAULTS$> NE ''	THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_SPIKES$> NE ''			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_SPOTS$> NE ''			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_FOV$> NE ''			THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_SCRATCHES$> NE ''		THEN NoSpec = 0
        IF CIRec<CLEAN_INSP_SPEC_SCRATCH_LEN$> NE ''	THEN NoSpec = 0
        
        IF NoSpec THEN
            Result = 'RTI'
            RETURN
        END
        
        SurfaceComp = 1
        IF CIRec<CLEAN_INSP_SPEC_LPD$> NE '' 			AND CIRec<CLEAN_INSP_INSP_LPD_IN$>  = '' 		THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_PITS$> NE ''			AND CIRec<CLEAN_INSP_INSP_PITS$> = ''			THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_MOUNDS$> NE ''			AND CIRec<CLEAN_INSP_INSP_MOUNDS$> = ''			THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_BL_DEFECTS$> NE ''		AND CIRec<CLEAN_INSP_INSP_BL_DEFECTS$> = ''		THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_STACK_FAULTS$> NE ''	AND CIRec<CLEAN_INSP_INSP_STACK_FAULTS$> = ''	THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_SPIKES$> NE ''			AND CIRec<CLEAN_INSP_INSP_SPIKES$> = ''			THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_SPOTS$> NE ''			AND CIRec<CLEAN_INSP_INSP_SPOTS$> = ''			THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_FOV$> NE ''			AND CIRec<CLEAN_INSP_INSP_FOV$> = ''			THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_SCRATCHES$> NE ''		AND CIRec<CLEAN_INSP_INSP_SCRATCHES$> = ''		THEN SurfaceComp = 0
        IF CIRec<CLEAN_INSP_SPEC_SCRATCH_LEN$> NE ''	AND CIRec<CLEAN_INSP_INSP_SCRATCH_LEN$> = ''	THEN SurfaceComp = 0
        
        IF SurfaceComp = 0 THEN
            Result = 'RTI'
            RETURN
        END
        
    END ;* End of check for Inspection signature
END

IF Surfscan OR SurfscanRecipe THEN
    SpecSurfDef	= OCONV(CIRec<CLEAN_INSP_SPEC_SURF_DEFECTS$, 1>,'MD0')
    
    SurfDefMax	= OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$, 1>,'MD0')
    SurfDefAvg	= OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$, 1>,'MD3')
    
    SpecSurfHaze	= OCONV(CIRec<CLEAN_INSP_SPEC_SURF_HAZE$, 1>,'MD2')
    SurfHazeAvgAvg	= OCONV( CIRec<CLEAN_INSP_SCAN_HAZE_AVG_AVG$, 1>,'MD3')
    
    IF SpecSurfDef NE '' THEN
        IF SurfDefMax NE '' THEN
            IF SurfDefMax GE SpecSurfDef THEN
                Result = 'OUT'
                RETURN
            END
        END
        IF SurfDefAvg NE '' THEN
            IF SurfDefAvg GE SpecSurfDef THEN
                Result = 'OUT'
                RETURN
            END
        END
    END
    
    IF SpecSurfHaze NE '' THEN
        IF SurfHazeAvgAvg NE '' THEN
            IF SurfHazeAvgAvg GE SpecSurfHaze THEN
                Result = 'OUT'
                RETURN
            END
        END
    END
    
    IF CIRec<CLEAN_INSP_SCAN_SIG$, 1> = '' THEN
        IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$, 1> = '' THEN
            IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$, 1> = '' THEN
                IF CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$, 1> = '' THEN
                    IF CIRec<CLEAN_INSP_SCAN_TOOL$, 1> NE '' THEN
                        Result = 'RTS'
                        RETURN
                    END
                END
            END
        END
    END
    
END



RETURN


* * * * * * *
Delete:
* * * * * * *
    
    CINos = Parms[1,@RM]
    
    IF CINos = '' THEN RETURN
    
    CONVERT @VM:@SVM TO @FM:@FM IN CINos
    
    OPEN 'CLEAN_INSP' TO CIFile THEN
        KeyCnt = COUNT(CINos,@FM) + (CINos NE '')
        FOR I = 1 TO KeyCnt
            DELETE CIFile,CINos<I> ELSE NULL
        NEXT I
    END
    
RETURN


* * * * * * *
SetClean:
* * * * * * *
    
    CINo		= Parms[1,@RM]
    CleanTool	= Parms[COL2()+1,@RM]
    CleanBoatID	= Parms[COL2()+1,@RM]
    CleanSRDNo	= Parms[COL2()+1,@RM]
    CleanSig	= Parms[COL2()+1,@RM]
    CleanSigDt	= Parms[COL2()+1,@RM]
    CleanSigTm	= Parms[COL2()+1,@RM]
    
    
    IF CINo = ''		THEN ErrorMsg = 'Null Parameter "CINo" passed to routine. (':Method:')'
    IF CleanSig = ''	THEN ErrorMsg = 'Null Parameter "CleanSig" passed to routine. (':Method:')'
    IF CleanSigDt = ''	THEN ErrorMsg = 'Null Parameter "CleanSigDt" passed to routine. (':Method:')'
    IF CleanSigTm = ''	THEN ErrorMsg = 'Null Parameter "CleanSigTm" passed to routine. (':Method:')'
    
    IF CleanTool = '' THEN RETURN	;* Bogus data
    
    IF ErrorMsg NE '' THEN RETURN
    
    thisCleanSigDt = ICONV(CleanSigDt,'D')
    IF thisCleanSigDt = '' THEN
        ErrorMsg = 'Invalid Parameter ':CleanSigDt:' passed to routine. (':Method:')'
        RETURN
    END
    
    thisCleanSigTm = ICONV(CleanSigTm,'MT')
    IF thisCleanSigTm = '' THEN
        ErrorMsg = 'Invalid Parameter ':CleanSigTm:' passed to routine. (':Method:')'
        RETURN
    END
    
    thisSigDTM = ICONV(OCONV(thisCleanSigDt,'D4/'):' ':OCONV(thisCleanSigTm,'MTHS'),'DT')
    
    CIParms = 'CLEAN_INSP':@RM:CINo
    CIRec = obj_Tables('ReadRec',CIParms)
    
    IF Get_Status(errCode) THEN RETURN
    
    LOCATE thisSigDTM IN CIRec<CLEAN_INSP_CLEAN_SIG_DTM$> BY 'DR' USING @VM SETTING Pos THEN
        CIRec<CLEAN_INSP_CLEAN_TOOL$,Pos>		= CleanTool
        CIRec<CLEAN_INSP_CLEAN_BOAT_ID$,Pos>	= CleanBoatID
        CIRec<CLEAN_INSP_CLEAN_SRD_NO$,Pos>		= CleanSRDNo
        CIRec<CLEAN_INSP_CLEAN_SIG$,Pos>		= CleanSig
    END ELSE
        CIRec = INSERT(CIRec,CLEAN_INSP_CLEAN_TOOL$,Pos,0,CleanTool)
        CIRec = INSERT(CIRec,CLEAN_INSP_CLEAN_BOAT_ID$,Pos,0,CleanBoatID)
        CIRec = INSERT(CIRec,CLEAN_INSP_CLEAN_SRD_NO$,Pos,0,CleanSRDNo)
        CIRec = INSERT(CIRec,CLEAN_INSP_CLEAN_SIG$,Pos,0,CleanSig)
        CIRec = INSERT(CIRec,CLEAN_INSP_CLEAN_SIG_DTM$,Pos,0,thisSigDTM)
    END
    
    
    CIParms = FieldStore(CIParms,@RM,4,1,CIRec)
    obj_Tables('WriteRec',CIParms)
    
RETURN



* * * * * * *
GetActions:
* * * * * * * 
    
    CINo = Parms[1,@RM]
    CIRec = Parms[COL2()+1,@RM]
    
    IF CINo = '' THEN RETURN	;* Called from the dictionary
    
    IF CIRec = ''	THEN CIRec = XLATE('CLEAN_INSP',CINo,'','X')
    
    IF CIRec = ''	THEN RETURN		;* ErrorMsg = 'Null Parameter "CIRec" passed to routine. (':Method:')'
    
    IF ErrorMsg NE '' THEN RETURN
    
    
    SCTool			= CIRec<CLEAN_INSP_SPEC_CLEAN_TOOL$>
    
    SWAP @VM WITH ', ' IN SCTool
    
    SCAkrionRecipe	= CIRec<CLEAN_INSP_SPEC_CLEAN_RECIPE$>
    
    SBrightLight = CIRec<CLEAN_INSP_SPEC_BRIGHTLIGHT$>
    SMicroscope  = CIRec<CLEAN_INSP_SPEC_MICROSCOPE$>
    SEdge        = CIRec<CLEAN_INSP_SPEC_EDGE$>
    
    SSurfscanRecipe	= CIRec<CLEAN_INSP_SPEC_SURFSCAN_RECIPE$>
    //
    Convert @VM to @SVM in SSurfscanRecipe
    //
    IF SCTool = 'No' THEN SCTool = ''
    
    Actions             = ''
    Sigs                = ''
    SigDTMs             = ''
    Tools               = ''
    SpecCleanTools      = ''
    SpecMicroscopes     = ''
    SpecBrightlights    = ''
    SpecEdges           = ''
    SpecSurfscanRecipes = ''
    
    Line = 0
    
    IF  SCTool OR SCAkrionRecipe OR	CIRec<CLEAN_INSP_CLEAN_SIG$> NE '' THEN
        Line += 1
        Actions<1,Line> 		= 'Clean'
        Sigs<1,Line> 			= CIRec<CLEAN_INSP_CLEAN_SIG$>[-1,'B':@VM]
        SigDTMS<1,Line> 		= CIRec<CLEAN_INSP_CLEAN_SIG_DTM$>[-1,'B':@VM]
        Tools<1,Line>			= CIRec<CLEAN_INSP_CLEAN_TOOL$>[-1,'B':@VM]
        SpecCleanTools<1,Line>	= SCTool
    END
    
    InspReq = Xlate('CLEAN_INSP', CINo, 'INSP_REQ', 'X')
    IF ( ( (SBrightLight OR SMicroscope OR SEdge) AND InspReq) OR (CIRec<CLEAN_INSP_INSP_SIG$> NE '') ) THEN
        Line += 1
        Actions<1,Line>	= 'Inspection'
        Sigs<1,Line>	= CIRec<CLEAN_INSP_INSP_SIG$>[-1,'B':@VM]
        SigDTMS<1,Line> = CIRec<CLEAN_INSP_INSP_SIG_DTM$>[-1,'B':@VM]
        
        LastTool                 = CIRec<CLEAN_INSP_INSP_TOOL$>[-1,'B':@VM]
        IF LastTool	= '' THEN LastTool = ''
        Tools<1,Line>            = LastTool
        SpecMicroscopes<1,Line>  = SMicroscope
        SpecBrightlights<1,Line> = SBrightLight
        SpecEdges<1,Line>        = SEdge
    END
    
    IF SSurfscanRecipe OR CIRec<CLEAN_INSP_SCAN_SIG$> THEN
        Line += 1
        Actions<1,Line>				= 'SurfScan'
        Sigs<1,Line>				= CIRec<CLEAN_INSP_SCAN_SIG$>[-1,'B':@VM]
        SigDTMS<1,Line>				= CIRec<CLEAN_INSP_SCAN_SIG_DTM$>[-1,'B':@VM]
        Tools<1,Line>				= CIRec<CLEAN_INSP_SCAN_TOOL$>[-1,'B':@VM]
        SpecSurfscanRecipes<1,Line> = SSurfscanRecipe
    END
    
    Result<ACTION$ACTIONS>				= Actions
    Result<ACTION$SIGS>					= Sigs
    Result<ACTION$SIG_DTMS>				= SigDTMs
    Result<ACTION$TOOLS>				= Tools
    Result<ACTION$SPEC_CLEAN_TOOL>		= SpecCleanTools
    Result<ACTION$SPEC_MICROSCOPE>		= SpecMicroscopes
    Result<ACTION$SPEC_BRIGHTLIGHT>		= SpecBrightlights
    Result<ACTION$SPEC_SURFSCAN_RECIPE>	= SpecSurfscanRecipes
    Result<ACTION$SPEC_EDGE>            = SpecEdges
    
RETURN





* * * * * * *
SetInsp:
* * * * * * *
    
RETURN


* * * * * * *
SetScan:
* * * * * * *
    
    
    
RETURN



* * * * * * *
SendToSPC:
* * * * * * *
    
    CINo = Parms[1,@RM]
    
    CIRec = XLATE('CLEAN_INSP',CINo,'','X')
    
    CIParms = 'CLEAN_INSP':@RM:CINo
    CIRec = obj_Tables('ReadRec',CIParms)
    
    IF Get_Status(errCode) THEN RETURN
    
    DictInfo = XLATE('DICT.RDS_LAYER','%FIELDS%','','X')
    
    
    RDSNo			= CIRec<CLEAN_INSP_RDS_NO$>
    Stage			= CIRec<CLEAN_INSP_STAGE$>			;* Last part of the four part key
    ScanTool		= CIRec<CLEAN_INSP_SCAN_TOOL$>
    
    ReactNo			= XLATE('CLEAN_INSP',CINo,'REACT_NO','X')
    WaferSize		= XLATE('CLEAN_INSP',CINo,'WAFER_SIZE','X')
    
    WaferSize = WaferSize[1,' ']		;* Data looks like "125 mm 6 in"
    UserName = OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]')
    
    
    LOCATE CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        SumOfDefMin	= OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$,1>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        SumOfDefMin = CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MIN$,1>
    END
    
    LOCATE CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        SumOfDefMax = OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$,1>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        SumOfDefMax = CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_MAX$,1>
    END
    
    LOCATE CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        SumOfDefAvg = OCONV(CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$,1>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        SumOfDefAvg = CIRec<CLEAN_INSP_SCAN_SUM_OF_DEF_AVG$,1>
    END
    
    LOCATE CLEAN_INSP_SCAN_HAZE_AVG_AVG$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        HazeAvgAvg = OCONV(CIRec<CLEAN_INSP_SCAN_HAZE_AVG_AVG$,1>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        HazeAvgAvg = CIRec<CLEAN_INSP_SCAN_HAZE_AVG_AVG$,1>
    END
    
    LOCATE CLEAN_INSP_INSP_SPOTS$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        Spots = OCONV(CIRec<CLEAN_INSP_INSP_SPOTS$>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        Spots = CIRec<CLEAN_INSP_INSP_SPOTS$>
    END
    
    LOCATE CLEAN_INSP_INSP_FOV$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        FOV	= OCONV(CIRec<CLEAN_INSP_INSP_FOV$>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        FOV = CIRec<CLEAN_INSP_INSP_FOV$>
    END
    
    LOCATE CLEAN_INSP_INSP_SCRATCHES$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        Scratches = OCONV(CIRec<CLEAN_INSP_INSP_SCRATCHES$>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        Scratches = CIRec<CLEAN_INSP_INSP_SCRATCHES$>
    END
    
    LOCATE CLEAN_INSP_INSP_SCRATCH_LEN$ IN DictInfo<FIELDS_FIELD_NO$> SETTING Pos THEN
        ScratchLen = OCONV(CIRec<CLEAN_INSP_INSP_SCRATCH_LEN$>,DictInfo<FIELDS_CONV$,Pos>)
    END ELSE
        ScratchLen = CIRec<CLEAN_INSP_INSP_SCRATCH_LEN$>
    END
    
    
    SSScratchAvg = ''	;* No data in these fields 5/29/2012 jch - deprecated
    SSScratchMax = ''	;* No data in these fields 5/29/2012 jch - deprecated
    
    
    DataLine  = QUOTE(ReactNo):TAB$
    DataLine := QUOTE(RDSNo):TAB$
    DataLine := QUOTE(Stage):TAB$
    DataLine := QUOTE(ScanTool):TAB$
    DataLine := QUOTE(SumOfDefMin):TAB$
    DataLine := QUOTE(SumOfDefMax):TAB$
    DataLine := QUOTE(SumOfDefAvg):TAB$
    DataLine := QUOTE(HazeAvgAvg):TAB$
    DataLine := QUOTE(Spots):TAB$
    DataLine := QUOTE(FOV):TAB$
    DataLine := QUOTE(Scratches):TAB$
    DataLine := QUOTE(ScratchLen):TAB$
    DataLine := QUOTE(UserName):TAB$
    DataLine := QUOTE(SSScratchAvg):TAB$
    DataLine := QUOTE(SSScratchMax):TAB$
    DataLine := QUOTE(WaferSize)
    
    DOSFile = Environment_Services('GetSPCDataPath') : '\SPC_Surf.txt'
    
RETURN

* * * * *
DosRead:
* * * * *
    
    Set_Status(0)
    
    OSRead DOSRecord FROM DOSFile ELSE
        ErrCode = Status()
        IF ErrCode = 4 THEN
            DOSRecord = ''	;* File doesn't exist
        END ELSE
            ErrMsg('Unable to read DOS file "SPC_Data.TXT" for update. ':ErrCode:' Please try again.')
            RETURN
        END
    END
    
    DOSRecord := DataLine:CRLF$
    
    OSWrite DOSRecord ON DOSFile
    
    CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
    
    CIRec<CLEAN_INSP_SPC_DTM$> = ICONV(CurrDTM,'DT')
    
    CIParms = FieldStore(CIParms,@RM,4,1,CIRec)
    obj_Tables('WriteRec',CIParms)
    
RETURN 

