COMPILE SUBROUTINE WM_OUT_CLEAN_INSP(WMOutKey)

DECLARE FUNCTION NextKey


$INSERT WM_OUT_EQUATES
$INSERT CLEAN_INSP_EQUATES
$INSERT REACT_RUN_EQUATES



* * * * * * *
CleanInsp:
* * * * * * *




IF Stage = 'POST' THEN

	* Post Clean
			
	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$>				= 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_CODE$>				= RDSRec<RDS_POST_CODE$>
	PostStageRec<CLEAN_INSP_CLEAN_BOAT_ID$>				= RDSRec<RDS_POST_BOAT_ID$>
	PostStageRec<CLEAN_INSP_CLEAN_SRD_NO$>				= RDSRec<RDS_POST_SRD_NUM$>
	
	IF RDSRec<RDS_POST_CODE$> NE '' OR RDSRec<RDS_POST_BOAT_ID$> NE '' OR RDSRec<RDS_POST_SRD_NUM$> NE '' THEN
		PostStageRec<CLEAN_INSP_CLEAN_SIG$>				= RDSRec<RDS_POST_EPI_SIG$>
		PostStageRec<CLEAN_INSP_CLEAN_SIG_DTM$>			= ICONV(OCONV(RDSRec<RDS_POST_EPI_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_POST_EPI_SIG_TIME$>,'MTS'),'DT')
	END
		
	PostStageRec<CLEAN_INSP_COMMENTS$>					= RDSRec<RDS_POST_EPI_COMMENTS$>
	
	SurfaceScanRec = XLATE('SURFACE_SCAN',WOStepKey:'*':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
	
		IF RunRec<REACT_RUN_POST_CI_NO$> = '' THEN
			CINo = NextKey('CLEAN_INSP')			;* This is a new CLEAN_INSP record
			RunRec<REACT_RUN_POST_CI_NO$> = CINo
		END ELSE
			CINo = RunRec<REACT_RUN_POST_CI_NO$>
		END
		
		WRITE PostStageRec ON CITable,CINo ELSE NULL
		
	END
	
END		;* End of POST stage logic

RETURN









