COMPILE SUBROUTINE Print_RDS_Instruction(RDSNo)

DECLARE FUNCTION Set_Printer, Get_Printer, Printer_Select, obj_Prod_Spec


$INSERT OIPRINT_EQUATES
$INSERT MSG_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT PROD_SPEC_EQUATES
$INSERT RDS_EQU
$INSERT RECIPE_EQU
$INSERT RDS_LAYER_EQUATES
$INSERT RDS_TEST_EQUATES
$INSERT PRS_LAYER_EQU
$INSERT APPCOLORS


EQU FONT_NAME$		TO 1
EQU FONT_SIZE$		TO 2
EQU FONT_JUST$		TO 3
EQU FONT_BOLD$		TO 4
EQU FONT_ITALIC$	TO 5
EQU FONT_UNDERLINE$	TO 6


IF RDSNo = '' THEN RETURN
RDSRec = XLATE('RDS',RDSNo,'','X')

PSNo = RDSRec<RDS_PROD_SPEC_ID$>
WONo = RDSRec<RDS_WO$>

PSNRec = XLATE( 'PROD_SPEC', PSNo, '', 'X' )

SpecSubInfo = PSNRec<prod_spec_spec_substrate$>
SpecialInst = SpecSubInfo<1,QSSubInstructions$>
Orientation = SpecSubInfo<1,QSSubOrientation$>
ProdType	= SpecSubInfo<1,QSSubType$>

SpecAddtl   = PSNRec<prod_spec_spec_addtl$>
ProveinInst = SpecAddtl<1,QSAddProveInInst$>

SWAP @TM WITH CRLF$ IN SpecialInst
SWAP @TM WITH CRLF$ IN ProveInInst


PSNLayerProps = obj_Prod_Spec('GetLayerProp',PSNo)


LSIDs = ''
Dopants = ''
colData = ''

FOR I = 1 TO COUNT(PSNLayerProps,@RM) + (PSNLayerProps NE '')
	LayerSet = FIELD(PSNLayerProps,@RM,I)
	LSIDs<I> = LayerSet<1>
	LayerSet = FIELD(LayerSet,@FM,2,99)
	
	
	
	Dopants<1,I> = LayerSet<PRS_LAYER_DOPANT$>
	
	IF I = 1 THEN
	
		RecipeNo = LayerSet<PRS_LAYER_RECIPE$>
		RecipeRec	= XLATE('RECIPE',RecipeNo,'','X')
		RecipeName	= RecipeRec<RECIPE_RECIPE_NAME$>
		CapGas		= RecipeRec<RECIPE_CAP_BURST_GASES$>
		EpiGas		= RecipeRec<RECIPE_EPI_GASES$>

		BEGIN CASE
			CASE EpiGas = 'SiH4'		; EpiGasName = 'Silane'
			CASE EpiGas = 'SiH2CL2'		; EpiGasName = 'DiChloroSilane (DCS)'
			CASE EpiGas = 'SiH1HCL3'	; EpiGasName = 'TriChloroSilane (TCS)'
			CASE 1	; EpiGasName = ''
		END CASE

		BEGIN CASE
			CASE CapGas = 'SiH4'		; CapGasName = 'Silane'
			CASE CapGas = 'SiH2CL2'		; CapGasName = 'DiChloroSilane (DCS)'
			CASE CapGas = 'SiH1HCL3'	; CapGasName = 'TriChloroSilane (TCS)'
			CASE 1	; CapGasName = ''
		END CASE
			
		colData<I,1> = PSNo
		colData<I,2> = Recipename
		colData<I,3> = EpiGas
		colData<I,4> = CapGas
		colData<I,5> = Orientation
		colData<I,6> = ProdType
	END
	
	LSIDs<I> = RDSNo:'*':LSIDs<I>
	
NEXT I


PrinterID	= ''
PrintPath	= Printer_Select(PrinterID,1)	;* Get Default printer path
Stat = Set_Printer( 'INIT', '', '', .25:@FM:.75:@FM:.25:@FM:.75, 0 ,'' ,PrintPath)		;* No Preview

font = 'Arial'		;* Font basics
font<2> = 10
font<4> = 0

stat = Set_Printer('FONTHEADFOOT', font)
stat = Set_Printer('FOOTER',"Page 'P'":@VM:'Instructions for WO No. ':WONo:@VM:"'T' 'D'")

Font = 'Arial'
Font<FONT_SIZE$>		= 18
Font<FONT_JUST$>		= 'C'
Font<FONT_BOLD$>		= 1		;* Bold
Font<FONT_UNDERLINE$>	= 1		;* Underlline

Stat = set_printer( 'FONT', Font )
Void = set_printer( 'TEXT', 'Instructions for WO No. ':WONo )
stat = Set_Printer('TEXT')		;* blank line


Font<FONT_JUST$>		= 'L'
Font<FONT_SIZE$>		= 10
Font<FONT_UNDERLINE$>	= 0


colHeader = 'Prod Spec No'				; colFormat = '^2520'
colHeader<1,2> = 'Recipe'				; colFormat<1,2> = '^1800'
colHeader<1,3> = 'Epi Gas'				; colFormat<1,3> = '^1800'
colHeader<1,4> = 'Cap Gas'				; colFormat<1,4> = '^1800'
colHeader<1,5> = 'Prod Orientation'		; colFormat<1,5> = '^1800'
colHeader<1,6> = 'Prod Type'			; colFormat<1,6> = '^1800'


font<FONT_SIZE$> = 10		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)
stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

Font<FONT_SIZE$> = 9
Font<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', Font )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)
stat = Set_Printer('TEXT')

colHeader = 'LS':CRLF$:'Id':@VM				; colFormat = '^540':@VM
colHeader<1,2> = 'Dopant':@VM				; colFormat<1,2> = '^1260':@VM
colHeader<1,3> = 'Measure':@VM				; colFormat<1,3> = '<1440':@VM
colHeader<1,4> = 'Minimum':@VM				; colFormat<1,4> = '^1260':@VM
colHeader<1,5> = 'Target':@VM				; colFormat<1,5> = '^1260':@VM
colHeader<1,6> = 'Maximum':@VM				; colFormat<1,6> = '^1260':@VM
colHeader<1,7> = 'Tool':@VM					; colFormat<1,7> = '<720':@VM
colHeader<1,8> = 'Monitor Type':@VM			; colFormat<1,8> = '<990':@VM
colHeader<1,9> = 'Recipe':@VM				; colFormat<1,9> = '<1260':@VM
colHeader<1,10> = 'Frq':@VM					; colFormat<1,10> = '^540':@VM
colHeader<1,11> = 'ProveIn Type'			; colFormat<1,11> = '<990'

LayerCnt = COUNT(LSIDs,@FM) + (LSIDs NE '')

colData = ''
FOR I = 1 TO LayerCnt
	LSKey 			= LSIDs<I>
	LayerRec		= XLATE('RDS_LAYER',LSKey,'','X')
	FirstTestKey	= LayerRec<RDS_LAYER_RDS_TEST_KEYS$,1>
	TestRec			= XLATE('RDS_TEST',FirstTestKey,'','X')
	ThickMin		= TestRec<RDS_TEST_SPEC_THICK_MIN$>
	ThickTarget 	= TestRec<RDS_TEST_SPEC_THICK_TARGET$>
	ThickMax		= TestRec<RDS_TEST_SPEC_THICK_MAX$>
	ThickUnits		= TestRec<RDS_TEST_SPEC_THICK_UNITS$>
	ThickMTool		= TestRec<RDS_TEST_SPEC_THICK_MTOOL$>
	ThickMType		= TestRec<RDS_TEST_SPEC_THICK_MTYPE$>
	ThickMPIType	= TestRec<RDS_TEST_SPEC_THICK_MPROVEIN$>
	ThickMRecipe	= TestRec<RDS_TEST_SPEC_THICK_MRECIPE$>
	ThickMFreq		= TestRec<RDS_TEST_SPEC_THICK_MFREQ$>
	
	
	ResMin			= TestRec<RDS_TEST_SPEC_RES_MIN$>
	ResTarget		= TestRec<RDS_TEST_SPEC_RES_TARGET$>
	ResMax			= TestRec<RDS_TEST_SPEC_RES_MAX$>
	ResUnits		= TestRec<RDS_TEST_SPEC_RES_UNITS$>
	ResMTool		= TestRec<RDS_TEST_SPEC_RES_MTOOL$>
	ResMType		= TestRec<RDS_TEST_SPEC_RES_MTYPE$>
	ResMPIType		= TestRec<RDS_TEST_SPEC_RES_MPROVEIN$>
	ResMRecipe		= TestRec<RDS_TEST_SPEC_RES_MRECIPE$>
	ResMFreq		= TestRec<RDS_TEST_SPEC_RES_MFREQ$>
	
	IF I = 1 THEN FirstResUnits = ResUnits
	
	ConMin			= TestRec<RDS_TEST_SPEC_CON_MIN$>
	ConTarget		= TestRec<RDS_TEST_SPEC_CON_TARGET$>
	ConMax			= TestRec<RDS_TEST_SPEC_CON_MAX$>
	ConUnits		= TestRec<RDS_TEST_SPEC_CON_UNITS$>
	ConMTool		= TestRec<RDS_TEST_SPEC_CON_MTOOL$>
	ConMType		= TestRec<RDS_TEST_SPEC_CON_MTYPE$>
	ConMPIType		= TestRec<RDS_TEST_SPEC_CON_MPROVEIN$>
	ConMRecipe		= TestRec<RDS_TEST_SPEC_CON_MRECIPE$>
	ConMFreq		= TestRec<RDS_TEST_SPEC_CON_MFREQ$>
	
	colData<I,1> = FIELD(LSKey,'*',2):CRLF$
	colData<I,2> = Dopants<1,I>:CRLF$
	colData<I,3> = 'Thickness':CRLF$:'Resistivity'
	colData<I,4> = OCONV(ThickMin,'MD2'):ThickUnits:CRLF$:OCONV(ResMin,'MD3'):ResUnits
	colData<I,5> = OCONV(ThickTarget,'MD2'):ThickUnits:CRLF$:OCONV(ResTarget,'MD3'):ResUnits
	colData<I,6> = OCONV(ThickMax,'MD2'):ThickUnits:CRLF$:OCONV(ResMax,'MD3'):ResUnits
	colData<I,7> = ThickMTool:CRLF$:ResMTool
	colData<I,8> = ThickMType:CRLF$:ResMType
	colData<I,9> = ThickMRecipe:CRLF$:ResMRecipe
	colData<I,10> = ThickMFreq:CRLF$:ResMFreq
	colData<I,11> = ThickMPIType:CRLF$:ResMPIType
	
	IF ConTarget NE '' THEN
		colData<I,1> = colData<I,1>:CRLF$
		colData<I,2> = colData<I,2>:CRLF$
		colData<I,3> = colData<I,3>:CRLF$:'Concentration'
		colData<I,4> = colData<I,4>:CRLF$:OCONV(ConMin,'MS21'):ConUnits
		colData<I,5> = colData<I,5>:CRLF$:OCONV(ConTarget,'MS21'):ConUnits
		colData<I,6> = colData<I,6>:CRLF$:OCONV(ConMax,'MS21'):ConUnits
		colData<I,7> = colData<I,7>:CRLF$:ConMTool
		colData<I,8> = colData<I,8>:CRLF$:ConMType
		colData<I,9> = colData<I,9>:CRLF$:ConMRecipe
		colData<I,10> = colData<I,10>:CRLF$:ConMFreq
		colData<I,11> = colData<I,11>:CRLF$:ConMPIType
	END ELSE
		colData<I,1> = colData<I,1>:CRLF$
		colData<I,2> = colData<I,2>:CRLF$
		colData<I,3> = colData<I,3>:CRLF$
		colData<I,4> = colData<I,4>:CRLF$
		colData<I,5> = colData<I,5>:CRLF$
		colData<I,6> = colData<I,6>:CRLF$
		colData<I,7> = colData<I,7>:CRLF$
		colData<I,8> = colData<I,8>:CRLF$
		colData<I,9> = colData<I,9>:CRLF$
		colData<I,10> = colData<I,10>:CRLF$
		colData<I,11> = colData<I,11>:CRLF$
	END

NEXT I

font<FONT_NAME$> = 'MS LineDraw'
font<FONT_SIZE$> = 8		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

Font<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', Font )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

stat = Set_Printer('TEXT')

font<FONT_BOLD$> = 0		;* Bold off
stat = Set_Printer('FONT',font)

Dopant = XLATE('PROD_SPEC',PSNo,'DOPANT_ALL','X')

Font<FONT_NAME$> = 'Arial'
Font<FONT_SIZE$> = 14
Font<FONT_JUST$> = 'L'
Font<FONT_UNDERLINE$> = 0

Void = set_printer( 'TEXT', '' )
Void = set_printer( 'FONT', Font )
Void = set_printer( 'TEXT', 'Special Instructions:' )
Table = ''
Table<-1> = SpecialInst
TableColInfo = '<+11520'

Font<2> = 12   
Font<4> = 0
Void = set_printer( 'FONT', Font )   
x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 0, TB_ALL)

Void = set_printer( 'TEXT', '' )
Font<2> = 14
Font<3> = 'L'
Font<4> = 1
Font<6> = 0
Void = set_printer( 'TEXT', '' )
Void = set_printer( 'FONT', Font )
Void = set_printer( 'TEXT', 'Prove-In Instructions:' )
Table = ''
Table<-1> = ProveinInst
TableColInfo = '<+11520'

Font<2> = 12   
Font<4> = 0
Void = set_printer( 'FONT', Font )   
x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 0, TB_ALL)

Void = set_printer( 'TEXT', '' )
Font<2> = 14
Font<3> = 'L'
Font<4> = 1
Void = set_printer( 'FONT', Font )
Void = set_printer( 'TEXT', 'Recipe Limits' )

Font<2> = 12   
Font<4> = 0
Void = set_printer( 'FONT', Font )


colHeader = 'LS Id'				; colFormat = '^1080'
colHeader<1,2> = 'Deposit'		; colFormat<1,2> = '^+1440'
colHeader<1,3> = 'Diluent'		; colFormat<1,3> = '^+1440'
colHeader<1,4> = 'Dopant Flow'	; colFormat<1,4> = '^+1440'
colHeader<1,5> = 'HCL Flow'		; colFormat<1,5> = '^+1440'
colHeader<1,6> = 'Bake Time'	; colFormat<1,6> = '^+1440'

colData = ''

LayerCnt = COUNT(LSIDs,@FM) + (LSIDs NE '')

FOR I = 1 TO LayerCnt
	LSKey = LSIDs<I>
	colData<I,1> = FIELD(LSKey,'*',2)
	colData<I,2> = XLATE('RDS_LAYER',LSKey,'EPI_TIME_LIMITS','X')
	colData<I,3> = XLATE('RDS_LAYER',LSKey,'DILUENT_LIMITS','X')
	colData<I,4> = XLATE('RDS_LAYER',LSKey,'DOPANT_FLOW_LIMITS','X')
	colData<I,5> = XLATE('RDS_LAYER',LSKey,'HCL_FLOW_LIMITS','X')
	colData<I,6> = XLATE('RDS_LAYER',LSKey,'BAKE_TIME_LIMITS','X')
	
NEXT I

font<FONT_SIZE$> = 8		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('CALCTABLE',colFormat:@FM:colData)
TableSize = Get_Printer('CALCTABLE')
TableHeight = TableSize<2>
Test = Get_Printer('POS')<2>

IF Get_Printer('POS')<2> + TableHeight > 7.0 THEN
	stat = Set_Printer('PAGEBREAK')
END

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

Font<FONT_SIZE$> = 8
Font<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', Font )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

colHeader = 'LS Id'		; colFormat = '^1080'
colHeader<1,2> = 'H2 Flow'		; colFormat<1,2> = '^+1440'
colHeader<1,3> = 'TCS Flow'		; colFormat<1,3> = '^+1440'
colHeader<1,4> = 'DCS Flow'		; colFormat<1,4> = '^+1440'
colHeader<1,5> =  'Aux 1 Flow'	; colFormat<1,5> = '^+1440'
colHeader<1,6> = 'Aux 2 Flow'	; colFormat<1,6> = '^+1440'

colData = ''

LayerCnt = COUNT(LSIDs,@FM) + (LSIDs NE '')

FOR I = 1 TO LayerCnt
	LSKey = LSIDs<I>
	colData<I,1> = FIELD(LSKey,'*',2)
	colData<I,2> = XLATE('RDS_LAYER',LSKey,'EPI_H2_FLOW_LIMITS','X')
	colData<I,3> = XLATE('RDS_LAYER',LSKey,'TCS_FLOW_LIMITS','X')
	colData<I,4> = XLATE('RDS_LAYER',LSKey,'DCS_FLOW_LIMITS','X')
	colData<I,5> = XLATE('RDSLayer',LSKey,'AUX1_LIMITS','X')
	colData<I,6> = XLATE('RDSLayer',LSKey,'AUX2_LIMITS','X')
NEXT I

font<FONT_SIZE$> = 8		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('CALCTABLE',colFormat:@FM:colData)
TableSize = Get_Printer('CALCTABLE')
TableHeight = TableSize<2>
Test = Get_Printer('POS')<2>

IF Get_Printer('POS')<2> + TableHeight > 7.0 THEN
	stat = Set_Printer('PAGEBREAK')
END


stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

Font<FONT_SIZE$> = 8
Font<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', Font )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

colHeader = 'LS Id'		; colFormat = '^1080'
colHeader<1,2> = 'F Offset'		; colFormat<1,2> = '^+1440'
colHeader<1,3> = 'S Offset'		; colFormat<1,3> = '^+1440'
colHeader<1,4> = 'R Offset'		; colFormat<1,4> = '^+1440'
colHeader<1,5> = 'Etch 1'		; colFormat<1,5> = '^+1440'
colHeader<1,6> = 'Etch 2'		; colFormat<1,6> = '^+1440'
colHeader<1,7> = 'Etch 3'		; colFormat<1,7> = '^+1440'

colData = ''

LayerCnt = COUNT(LSIDs,@FM) + (LSIDs NE '')

FOR I = 1 TO LayerCnt
	LSKey = LSIDs<I>
	colData<I,1> = FIELD(LSKey,'*',2)
	
	colData<I,2> = XLATE('RDSLayer',LSKey,'F_OFFSET_LIMITS','X')
	colData<I,3> = XLATE('RDSLayer',LSKey,'S_OFFSET_LIMITS','X')
	colData<I,4> = XLATE('RDSLayer',LSKey,'R_OFFSET_LIMITS','X')
	colData<I,5> = XLATE('RDSLayer',LSKey,'ETCH1_LIMITS','X')
	colData<I,6> = XLATE('RDSLayer',LSKey,'ETCH2_LIMITS','X')
	colData<I,7> = XLATE('RDSLayer',LSKey,'ETCH3_LIMITS','X')

NEXT I

font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('CALCTABLE',colFormat:@FM:colData)
TableSize = Get_Printer('CALCTABLE')
TableHeight = TableSize<2>
Test = Get_Printer('POS')<2>

IF Get_Printer('POS')<2> + TableHeight > 7.0 THEN
	stat = Set_Printer('PAGEBREAK')
END

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

Font<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', Font )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)
stat = set_printer( 'TERM' )       

RETURN 0
