COMPILE ROUTINE LOAD_NCR_IN_WO_MAT(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Info, obj_WO_Log, Set_Status, obj_WO_Step
DECLARE FUNCTION Get_Status, Set_Printer, obj_WO_Step

$INSERT NCR_EQU
$INSERT WO_MAT_EQUATES

OPEN 'NCR' TO FileIn ELSE
	DEBUG 
	GOTO Bail
END

OPEN 'WO_MAT' TO WOMatFile ELSE
	DEBUG
	GOTO Bail
END

debug

SELECT FileIn
Done = 0
RecCnt = 0 
FixCnt = 0
LOOP
	READNEXT NCRNo ELSE Done = 1
UNTIL Done
	READ NCRRec FROM FileIn,NCRNo THEN
		RecCnt += 1
		WONo	= NCRRec<NCR_WO_NO$>
		StepNo	= NCRRec<NCR_WO_STEP$>
		IF WONo NE '' AND StepNo NE '' THEN
			PSNo = XLATE('WO_STEP',WONo:'*':StepNo,1,'X')
			ReactorType = XLATE('PROD_SPEC',PSNo,80,'X')
				
			IF ReactorType NE 'P' AND NCRRec<NCR_SLOT_NO$> = '' THEN
			
				RejCnt = SUM(XLATE('NCR',NCRNo,'REJ_CNT','X'))
				IF RecCnt > 0 THEN
					FOR I = 1 TO RejCnt
				 		NCRRec<NCR_SLOT_NO$,I> = 1
					NEXT I
				END
				
				* Skip EpiPRO stuff
				
				RejWaferIDs = NCRRec<NCR_REJ_WAFER_ID$>
				WONo		= NCRRec<NCR_WO_NO$>
				CassNo		= NCRRec<NCR_WO_MAT_CASS_NO$>
				
				IF RejWaferIDs = '' THEN
					SlotFlags = NCRRec<NCR_SLOT_NO$>
					SlotNos = ''
					FOR I = 1 TO COUNT(SlotFlags,@VM) + (SlotFlags NE '')
						IF SlotFlags<1,I> = 1 THEN
							SlotNos<1,-1> = I
						END
					NEXT I
					
					IF SlotNos NE '' THEN
						READ WOMatRec FROM WOMatFile,WONo:'*':CassNo THEN
							NCRRec<NCR_SLOT_NO$> = SlotNos
							FOR I = 1 TO COUNT(SlotNos,@VM ) + (SlotNos NE '')
								SlotNo = SlotNos<1,I>
								WOMatRec<WO_MAT_SLOT_NCR$,SlotNo> = NCRNo
								NCRRec<NCR_REJ_WAFER_ID$,I> = WONo:'.':CassNo:'.':SlotNo
							NEXT I
							WRITE WOMatRec ON WOMatFile,WONo:'*':CassNo THEN
								FixCnt += 1
								Send_Info(RecCnt:' ':FixCnt:' -> ':WONo:'*':CassNo)
							END
							*WRITE NCRRec ON FileIn,NCRNo THEN
								* Save this till we're live
							*END
						END
					END	;* End of Check for empty SlotNos
				END
			END	;* End of check for WONo and StepNo
		END	;* End of check for 
	END	;* End of NCR Record Read
REPEAT
	




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

END
