function GetNewScanData(CINo, CurrentMax, NCRNo)
/*
This function will return the defect data while excluding data for wafers that were NCR'ed out.
*/
*#pragma precomp SRP_PreCompiler
#pragma precomp SRP_PreCompiler
$INSERT REACT_RUN_EQUATES


Declare function DCount

*/
*Some wafers must get a reclean and thus they're read twice. We'll take the last number and assign it as the max.
CurrentMax = CurrentMax<1,1>
OldMax = CurrentMax

*Pulls in the values of all slots read
Reads =  XLATE('CLEAN_INSP',CINo,86,'X')

slots = 25

*Pulls up the NCR Records and looks for what failed wafers exist in each NCR

    FailedSlots = XLATE('NCR', NCRNo, 57, 'X')


failedCount = Count(FailedSlots, @VM)


swap @SVM with @VM in Reads
ReadsCount = DCOUNT(Reads,@VM)
NewMax = 0
DefSpecs = XLATE('CLEAN_INSP',CINo, 15, 'X')
DefSpec = DefSpecs<1,1>


NewReads = 0
if FailedCount GT 0 Then
        For slot = 1 to slots
                
                IF Reads<1,slot> NE '' then
                        If Reads<1,slot> LE DefSpec then
                        	NewReads += Reads<1,slot>
                        	
                        	If Reads<1,slot> GE NewMax then
                        		NewMax = Reads<1,slot>
                        	end
                        end
                        /**
                            failed = 0
                            Loop
                                For failedWafers = 0 to failedCount
                                    if FailedSlots<1, failedWafers> EQ slot then
					                    failed = 1
					                end else
					                     failed = failed + 0
					                end
					                
					            Next failedWafers
                            Until failed = 1 OR failedWafers GE failedCount
                            Repeat
                            
                            if failed = 0 then
                                IF Reads<1,slot> GE NewMax AND Reads<1,slot> NE OldMax then
					                NewMax = Reads<1,slot>
                                end
                                NewReads += Reads<1,slot>
					        end
*/
                        
                end

        Next slot

    @Ans = NewMax
end else
	@Ans = OldMax
	
END
Return @Ans

