COMPILE ROUTINE MOVE_PROD_SPEC(Dummy)
ROWDEF (CHARSTR)

DECLARE SUBROUTINE SEND_INFO, SEND_DYN, Utility, msg

$INSERT PR_SPEC_EQU
$INSERT PRS_LAYER_EQU
$INSERT PRS_SURFACE_EQU
$INSERT PRS_SUBSTRATE_EQU

OPEN 'PROD_SPEC' TO FileIn ELSE
	DEBUG
	GOTO Bail
END

OPEN 'PR_SPEC' TO PRSpec ELSE
	DEBUG
	GOTO Bail
END

OPEN 'PRS_LAYER' TO PRSLayer ELSE
	debug
	GOTO Bail
END

OPEN 'PRS_SURFACE' TO PRSSurface ELSE
	debug
	GOTO Bail
END

OPEN 'PRS_SUBSTRATE' TO PRSSubstrate ELSE
	debug
	GOTO Bail
END

SELECT FileIn

RecCnt = 0
Done = 0
LOOP
	ReadNext PS_No ELSE Done = 1
UNTIL Done
	READ ProdSpecRec FROM FileIn,PS_No THEN
		PRSpecRec = ''
		PRSpecRec<PR_SPEC_ENTER_BY$>			= ProdSpecRec<1>
		PRSpecRec<PR_SPEC_ENTER_DT$>			= ProdSpecRec<2>
		PRSpecRec<PR_SPEC_ACT_STATUS$>			= ProdSpecRec<9>
		PRSpecRec<PR_SPEC_CUST_NO$>				= ProdSpecRec<8>
		PRSpecRec<PR_SPEC_CUST_SPEC$>			= ProdSpecRec<3>
		PRSpecRec<PR_SPEC_CUST_SPEC_HARDCOPY$>	= ProdSpecRec<49>
		PRSpecRec<PR_SPEC_CUST_SPEC_REV$>		= ProdSpecRec<4>
		PRSpecRec<PR_SPEC_CUST_SPEC_REV_DT$>	= ProdSpecRec<6>
		PRSpecRec<PR_SPEC_CUST_PART_NO$>		= ProdSpecRec<5>
		PRSpecRec<PR_SPEC_MOD_DESC$>			= ProdSpecRec<7>
		PRSpecRec<PR_SPEC_MOD_BY$>				= ProdSpecRec<47>
		PRSpecRec<PR_SPEC_MOD_DTM$>				= ProdSpecRec<48>
		PRSpecRec<PR_SPEC_LAYER_TYPE$>			= ProdSpecRec<93>
		PRSpecRec<PR_SPEC_SUPPLIER_CD$>			= ProdSpecRec<85>
		PRSpecRec<PR_SPEC_GENERIC_RECIPE$>		= ProdSpecRec<17>
		PRSpecRec<PR_SPEC_CUST_SVC_NOTES$>		= ProdSpecRec<22>
		PRSpecRec<PR_SPEC_SCHED_NOTES$>			= ProdSpecRec<20>
		PRSpecRec<PR_SPEC_WAFER_PART_NO$>		= ProdSpecRec<97>
		PRSpecRec<PR_SPEC_WAFER_MFG$>			= ProdSpecRec<98>
		PRSpecRec<PR_SPEC_SCANNED_IMG_PATH$>	= ProdSpecRec<88>
		PRSpecRec<PR_SPEC_SURF_SPEC_NOTES$>		= ProdSpecRec<68>
		
		PRSpecRec<PR_SPEC_LAYER_KEYS$>			= ''
		PRSpecRec<PR_SPEC_SURFACE_KEYS$>		= ''
		
		SpecAddtl = ProdSpecRec<25>
		
		
		PRSpecRec<PR_SPEC_PREQUAL_SIG$>	= SpecAddtl<1,10>
		
		IF SpecAddtl<1,10> = '' THEN
			PRSpecRec<PR_SPEC_PREQUAL_DTM$> = ''
		END ELSE	
			PRSpecRec<PR_SPEC_PREQUAL_DTM$>	= ICONV(OCONV(SpecAddtl<1,17>,'D'):' ':OCONV(SpecAddtl<1,18>,'MTS'),'DT')
		END
		
		PRSpecRec<PR_SPEC_QUAL_SIG$> = SpecAddtl<1,2>
		
		IF SpecAddtl<1,2> = '' THEN
			PRSpecRec<PR_SPEC_QUAL_DTM$> = ''
		END ELSE	
			PRSpecRec<PR_SPEC_QUAL_DTM$> = ICONV(OCONV(SpecAddtl<1,13>,'D'):' ':OCONV(SpecAddtl<1,14>,'MTS'),'DT')
		END
		
		PRSpecRec<PR_SPEC_PREPROD_SIG$>	= SpecAddtl<1,9>
		
		IF SpecAddtl<1,9> = '' THEN
			PRSpecRec<PR_SPEC_PREPROD_DTM$>	= ''
		END ELSE
			PRSpecRec<PR_SPEC_PREPROD_DTM$>	= ICONV(OCONV(SpecAddtl<1,15>,'D'):' ':OCONV(SpecAddtl<1,16>,'MTS'),'DT')
		END
		
		PRSpecRec<PR_SPEC_PROD_SIG$>	= SpecAddtl<1,1>
		
		IF SpecAddtl<1,1> = '' THEN
			PRSpecRec<PR_SPEC_PROD_DTM$> = ''
		END ELSE
			PRSpecRec<PR_SPEC_PROD_DTM$> = ICONV(OCONV(SpecAddtl<1,11>,'D'):' ':OCONV(SpecAddtl<1,12>,'MTS'),'DT')
		END		
		
		WRITE PRSpecRec ON PRSpec,PS_No THEN
			RecCnt += 1
			Send_Info(RecCnt)
		END
		
		EpiLayers = ProdSpecRec<15>
		CONVERT CHAR(248) TO @RM IN EpiLayers
		CONVERT @VM TO @FM IN EpiLayers
		CONVERT @SVM TO @VM IN EpiLayers
		CONVERT '~' TO @VM IN EpiLayers
		FOR I = 1 TO COUNT(EpiLayers,@RM) + (EpiLayers NE '')
			EpiLayer = FIELD(EpiLayers,@RM,I,1)
			PRSLayerRec = ''
			BEGIN CASE
				CASE I = 1
					Layer = 'L1'
					
					PRSLayerRec<PRS_LAYER_STRESS_MIN$>			= SpecAddtl<1,6>
					PRSLayerRec<PRS_LAYER_STRESS_MAX$>			= SpecAddtl<1,7>
					PRSLayerRec<PRS_LAYER_STRESS_MEASUREMENT$>	= SpecAddtl<1,4>
					PRSLayerRec<PRS_LAYER_TRANS_SPEC$>			= SpecAddtl<1,8>
					PRSLayerRec<PRS_LAYER_TRANS_MEASUREMENT$>	= SpecAddtl<1,5>
				
				CASE I = 2 ; Layer = 'L2'
				CASE I = 3 ; Layer = '2'
				CASE 1 ; Layer = I-1
			END CASE
			
			
			PRSLayerRec<1> = EpiLayer<10>
			PRSLayerRec<2> = EpiLayer<11>
			PRSLayerRec<3> = EpiLayer<12>
			PRSLayerRec<4> = EpiLayer<1>
			PRSLayerRec<5> = EpiLayer<2>
			PRSLayerRec<6> = EpiLayer<3>
			PRSLayerRec<7> = EpiLayer<15>
			PRSLayerRec<8> = ICONV(OCONV(EpiLayer<4>,'MD3'),'MD5')
			PRSLayerRec<9> = ICONV(OCONV(EpiLayer<5>,'MD3'),'MD5')
			PRSLayerRec<10> = EpiLayer<6>
			PRSLayerRec<11> = EpiLayer<14>
			PRSLayerRec<12> = ICONV(OCONV(EpiLayer<7>,'MD2'),'MD3')
			PRSLayerRec<13> = ICONV(OCONV(EpiLayer<8>,'MD2'),'MD3')
			PRSLayerRec<14> = EpiLayer<9>
			PRSLayerRec<15> = EpiLayer<13>
			
			PRSLayerKey = PS_No:'*':Layer
			WRITE PRSLayerRec ON PRSLayer,PRSLayerKey THEN
				Send_Info(RecCnt:' - ':PRSLayerKey)
			END
		NEXT I
		
		
		* PreEpi surface 
		
		Stage = 'PE'		;* Pre EPI
		SurfRec = ''
		SurfRec<PRS_SURFACE_PITS$>				= ProdSpecRec<50>
		SurfRec<PRS_SURFACE_MOUNDS$>			= ProdSpecRec<51>
		SurfRec<PRS_SURFACE_BL_DEFECTS$>		= ProdSpecRec<52>
		SurfRec<PRS_SURFACE_SPOTS$>				= ProdSpecRec<53>
		SurfRec<PRS_SURFACE_FOV$>				= ProdSpecRec<54>
		SurfRec<PRS_SURFACE_SCRATCHES$>			= ProdSpecRec<55>
		SurfRec<PRS_SURFACE_SCRATCH_LEN$>		= ProdSpecRec<56>
		SurfRec<PRS_SURFACE_LPD$>				= ProdSpecRec<57>
		*SurfRec<PRS_SURFACE_STACK_FAULTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SPIKES$>			= ProdSpecRec<
		SurfRec<PRS_SURFACE_BRIGHTLIGHT$>		= ProdSpecRec<69>
		SurfRec<PRS_SURFACE_SURFSCAN$>			= ProdSpecRec<70>
		SurfRec<PRS_SURFACE_MICROSCOPE$>		= ProdSpecRec<71>
		SurfRec<PRS_SURFACE_SURFSCAN_RECIPE$>	= ProdSpecRec<77>
		SurfRec<PRS_SURFACE_SURF_DEFECTS$>		= ProdSpecRec<100>
		SurfRec<PRS_SURFACE_SURF_HAZE$>			= ProdSpecRec<101>
		
		StageKey = PS_No:'*':Stage
		WRITE SurfRec ON PRSSurface,StageKey THEN
			NULL
		END ELSE
			debug
		END

		Stage = 'PSE'		;* Post EPI
		SurfRec = ''
		SurfRec<PRS_SURFACE_PITS$>				= ProdSpecRec<58>
		SurfRec<PRS_SURFACE_MOUNDS$>			= ProdSpecRec<59>
		SurfRec<PRS_SURFACE_BL_DEFECTS$>		= ProdSpecRec<60>
		SurfRec<PRS_SURFACE_SPOTS$>				= ProdSpecRec<62>
		SurfRec<PRS_SURFACE_FOV$>				= ProdSpecRec<63>
		SurfRec<PRS_SURFACE_SCRATCHES$>			= ProdSpecRec<65>
		SurfRec<PRS_SURFACE_SCRATCH_LEN$>		= ProdSpecRec<66>
		SurfRec<PRS_SURFACE_LPD$>				= ProdSpecRec<67>
		SurfRec<PRS_SURFACE_STACK_FAULTS$>		= ProdSpecRec<61>
		*SurfRec<PRS_SURFACE_SPIKES$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_BRIGHTLIGHT$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SURFSCAN$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_MICROSCOPE$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SURFSCAN_RECIPE$>	= ProdSpecRec<
		SurfRec<PRS_SURFACE_SURF_DEFECTS$>		= ProdSpecRec<102>
		SurfRec<PRS_SURFACE_SURF_HAZE$>			= ProdSpecRec<103>
		
		StageKey = PS_No:'*':Stage
		WRITE SurfRec ON PRSSurface,StageKey THEN
			NULL
		END ELSE
			debug
		END
		
		Stage = 'FW'		;* First Wafer
		SurfRec = ''
		*SurfRec<PRS_SURFACE_PITS$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_MOUNDS$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_BL_DEFECTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SPOTS$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_FOV$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SCRATCHES$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SCRATCH_LEN$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_LPD$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_STACK_FAULTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SPIKES$>			= ProdSpecRec<
		SurfRec<PRS_SURFACE_BRIGHTLIGHT$>		= ProdSpecRec<72>
		SurfRec<PRS_SURFACE_SURFSCAN$>			= ProdSpecRec<73>
		SurfRec<PRS_SURFACE_MICROSCOPE$>		= ProdSpecRec<74>
		SurfRec<PRS_SURFACE_SURFSCAN_RECIPE$>	= ProdSpecRec<78>
		*SurfRec<PRS_SURFACE_SURF_DEFECTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SURF_HAZE$>		= ProdSpecRec<		
		
		StageKey = PS_No:'*':Stage
		WRITE SurfRec ON PRSSurface,StageKey THEN
			NULL
		END ELSE
			debug
		END
		
		Stage = 'PC'		;* Post Clean
		SurfRec = ''
		*SurfRec<PRS_SURFACE_PITS$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_MOUNDS$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_BL_DEFECTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SPOTS$>			= ProdSpecRec<
		*SurfRec<PRS_SURFACE_FOV$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SCRATCHES$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SCRATCH_LEN$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_LPD$>				= ProdSpecRec<
		*SurfRec<PRS_SURFACE_STACK_FAULTS$>		= ProdSpecRec<
		*SurfRec<PRS_SURFACE_SPIKES$>			= ProdSpecRec<
		SurfRec<PRS_SURFACE_BRIGHTLIGHT$>		= ProdSpecRec<75>
		SurfRec<PRS_SURFACE_SURFSCAN$>			= ProdSpecRec<76>
		*SurfRec<PRS_SURFACE_MICROSCOPE$>		= ProdSpecRec<
		SurfRec<PRS_SURFACE_SURFSCAN_RECIPE$>	= ProdSpecRec<79>
		SurfRec<PRS_SURFACE_SURF_DEFECTS$>		= ProdSpecRec<104>
		SurfRec<PRS_SURFACE_SURF_HAZE$>			= ProdSpecRec<105>			
		
		StageKey = PS_No:'*':Stage
		WRITE SurfRec ON PRSSurface,StageKey THEN
			NULL
		END ELSE
			debug
		END
		
		SubStrate = ProdSpecRec<14>

		SubRec = ''
		SubRec<PRS_SUBSTRATE_WAFER_TYPE$>			= SubStrate<1,2>
		SubRec<PRS_SUBSTRATE_WAFER_SIZE$>			= SubStrate<1,3>

		SubRec<PRS_SUBSTRATE_WAFER_SUP_BY$>			= SubStrate<1,17>
		SubRec<PRS_SUBSTRATE_ORIENTATION$>			= SubStrate<1,1>
		
		SubRec<PRS_SUBSTRATE_RESISTIVITY$>			= ICONV(OCONV(SubStrate<1,4>,'MD2'),'MD5')
		
		SubRec<PRS_SUBSTRATE_RES_UNITS$>			= SubStrate<1,5>
		SubRec<PRS_SUBSTRATE_DOPANT$>				= SubStrate<1,6>
		SubRec<PRS_SUBSTRATE_PRE_CLEAN$>			= SubStrate<1,7>
		SubRec<PRS_SUBSTRATE_POST_CLEAN$>			= SubStrate<1,11>
		SubRec<PRS_SUBSTRATE_OXIDE_STRIP$>			= SubStrate<1,10>
		SubRec<PRS_SUBSTRATE_OXIDE_ANGSTROMS$>		= SubStrate<1,22>
		SubRec<PRS_SUBSTRATE_SUBSTRATE$>			= SubStrate<1,14>
		SubRec<PRS_SUBSTRATE_BACK_SEAL$>			= SubStrate<1,12>
		
		SubRec<PRS_SUBSTRATE_BL_DOPANT$>			= SubStrate<1,8>:@VM:Substrate<1,9>:@VM:Substrate<1,21>
		
		*SubRec<PRS_SUBSTRATE_INSTRUCTIONS$>			= SubStrate<1,15>  ;**** This is the missing processing instructions
		
		SubRec<PRS_SUBSTRATE_SPEC_TYPE$>			= SubStrate<1,18>
		SubRec<PRS_SUBSTRATE_POLISH$>				= SubStrate<1,19>
		SubRec<PRS_SUBSTRATE_PRODUCT$>				= SubStrate<1,20>
		SubRec<PRS_SUBSTRATE_PRE_AKRION_RECIPE$>	= SubStrate<1,23>
		SubRec<PRS_SUBSTRATE_POST_AKRION_RECIPE$>	= SubStrate<1,24>
		
		WRITE SubRec ON PRSSubstrate,PS_No THEN
			NULL
		END ELSE
			debug
		END
		
	END

REPEAT



*UNLOCK All

* * * * * * *
Bail:
* * * * * * *

END
