COMPILE ROUTINE Import_PM_Data(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE RList,Send_Dyn
DECLARE FUNCTION Get_Status, NextKey

$INSERT PM_SCHED_EQUATES
$INSERT TOOL_EQUATES

EQU COL_PRE_AKRION_RECIPE$			TO 1
EQU COL_POST_AKRION_RECIPE$			TO 2
EQU COL_POST_CLEAN_SURFSCAN_RECIPE$	TO 3
EQU COL_SRP_RECIPE$					TO 4
EQU COL_CRES_MEASURE_ALL$			TO 5
EQU COL_4PP_RECIPE$					TO 6
EQU COL_4PP_PATTERN$				TO 7
EQU COL_FTIR_RECIPE$				TO 8
EQU COL_FTIR_PATTERN$				TO 9
EQU COL_TW_MEAS_TYPE_ALL$			TO 10


EQU COL$PM_ID				TO 1
EQU COL$PM_TASKNAME			TO 2	;*
EQU COL$PM_ITEM_ID			TO 3	;*
EQU COL$CHANGESTATUS		TO 4	;*
EQU COL$PM_SCHED_METHOD		TO 5	;*
EQU COL$NEXTSCHCALCTYPE		TO 6	;*
EQU COL$TIMEINTERVAL		TO 7	;*
EQU COL$PM_UOM				TO 8	;*
EQU COL$PM_DAY_INTERVAL		TO 9	;*
EQU COL$PM_QTY_INTERVAL		TO 10	;*
EQU COL$PM_QTY_UNITS		TO 11	;*
EQU COL$PM_EARLY_DATE		TO 12	;*
EQU COL$PM_EARLY_TARG		TO 13	;*
EQU COL$PM_DUE_DATE			TO 14	;*
EQU COL$PM_LATE_TARG		TO 15	;*
EQU COL$LEVEL				TO 16	;*
EQU COL$CLASS				TO 17	;*
EQU COL$GAGE_RR_DTM			TO 18
EQU COL$GAGE_RR_NEXT_DTM	TO 19

OPEN 'PM_SCHED' TO PMSchedTable ELSE
	DEBUG
END


DosFile = 'R:\Temp\GaN_PMSeed.txt'
FileSize = Dir(DosFile)<1>

OSOPEN DosFile TO FileIn ELSE
	debug
	GOTO Bail
END

OffSet = 0

OSClose FileIn

OSBRead RawData FROM FileIn AT OffSet LENGTH FileSize

SWAP CHAR(13):CHAR(10) WITH @FM IN RawData
SWAP CHAR(09) WITH @VM IN RawData

DEBUG

Result = ''

LineCnt = COUNT(RawData,@FM) + (RawData NE '')

FOR L = 2 TO LineCnt

	LineIn = RawData<L>
	
	PMSchedRec = ''
	
	ToolID = RawData<L,COL$PM_ITEM_ID>
	
	IF ToolID = 'R71' THEN ToolID = 'R69'
	
	IF ToolID = 'BOX01' THEN
		ToolID = 'N2BOX1'
	END
	
	IF ToolID = 'CAN01A' THEN
		ToolIDs = 'CAN01':@VM:'CAN02'
		* Make 2 PMS for this one
	END
	
	ToolDesc = XLATE('TOOL',ToolID,TOOL_TOOL_DESC$,'X')
	
	IF ToolID NE '' AND ToolDesc = '' THEN
	
		Send_Dyn(ToolID:' not found ':RawData<L,COL$PM_TASKNAME>)
		
	END ELSE
		PMSchedRec<PM_SCHED_TOOL_ID$>			= ToolID
		PMSchedRec<PM_SCHED_DESC$>				= LineIn<1,COL$PM_TASKNAME>
		PMSchedRec<PM_SCHED_CHANGE_STAT$>		= LineIn<1,COL$CHANGESTATUS>
		PMSchedRec<PM_SCHED_UNITS$>				= 'D'
		
		
		
		TimeInterval = LineIn<1,COL$TIMEINTERVAL>
		
		IF TimeInterval = '1' OR TimeInterval = '-1' THEN
			DayInterval = LineIn<1,COL$PM_DAY_INTERVAL>
			IF NUM(DayInterval) THEN
				TimeInterval = Dayinterval
			END
		END ELSE
			TimeInterval = INT(TimeInterval/86400)
		END
		
		
		PMSchedRec<PM_SCHED_INTERVAL$>		= TimeInterval
		
		
		
		PMSchedRec<PM_SCHED_EARLY_START_DELTA$>	= LineIn<1,COL$PM_EARLY_TARG>
		PMSchedRec<PM_SCHED_LATE_START_DELTA$>	= LineIn<1,COL$PM_LATE_TARG>		;* May not be a late start delta
		
	
		
		PMId = NextKey('PM_SCHED')
		
		*WRITE PMSchedRec ON PMSchedTable,PMId THEN
			Send_Dyn(PMId)
		*END
	END
	
	
	
NEXT L	

GOTO Bail


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


END
