function recipe_browse_comm(Branch, CurParam)

declare function set_property, fieldcount, get_property, msg, dialog_box
declare function send_message, utility, key_sort, start_window, entid, repository
declare function relational_call, send_event
declare subroutine extract_si_keys,  update_Index, end_dialog, make.list, btree.extract


$insert msg_equates
$insert lsl_users_equ
$insert rds_equ
$insert rds_layer_info_equ
$insert logical
$insert popup_equates
$insert recipe_equ
$insert recipe_layer_info_equ
$insert recipe_info_array_equ
$INSERT RDS_LAYER_EQUATES

equ Hidden$ to 32
equ CrLf$ to char(13):char(10)

RecipeControls = 'EPI_DOPANT/EPI_TIME/EPI_TEMP/EPI_H2_FLOW/EPI_DOPANT_FLOW/EPI_DILUENT/TCS_FLOW/DCS_FLOW/'
RecipeControls:= 'AUX1/AUX2/EPI_GASES/EPI_GAS_RATE/EPI_GASUNITS/BAKE_TIME/ETCH_TIME/HCL_FLOW/ADJ_DILUENT'

equ Dopant$     to 1
equ DepTime$    to 2
equ Temp$       to 3
equ H2Flow$     to 4
equ DopantFlow$ to 5
equ Diluent$    to 6
equ TCS$        to 7
equ DCS$        to 8
equ Aux1$       to 9
equ Aux2$       to 10
equ Gases$      to 11
equ GasRate$    to 12
equ GasUnit$    to 13
equ BakeTime$   to 14
equ EtchTime$   to 15
equ HCLFlow$    to 16
equ AdjDiluent$ to 17

TemperatureControls = 'F_OFFSET/S_OFFSET/R_OFFSET/INJECTORS'
MainControls   = 'REACTOR/RECIPE_NO/RECIPE_NAME/PSN/WO/RDS_NO/RUN_ORDER'
swap '/' with @rm:@window:'.' In TemperatureControls
TemperatureControls = @window:'.':TemperatureControls
swap '/' with @rm:@window:'.' In RecipeControls
RecipeControls = @window:'.':RecipeControls
swap '/' with @rm:@window:'.' In MainControls
MainControls = @window:'.':MainControls
AllControls = MainControls:@rm:RecipeControls:@rm:TemperatureControls
*
open 'DICT.RDS' to DictRDSTable else
   Void = msg( '', 'Unable to open DICT.RDS...' )
   return 0
end
*
ReturnVar = 0
Branches = 'REACT_REC_ON_CHANGE,CLEAR,SEARCH,CHANGE_WO,CHANGE_BOX,CHANGE_LAYER,SET_ADJUST_PARAMS'
convert ',' to @fm in Branches
locate Branch in Branches using @fm setting Bpos then
   on Bpos gosub REACT_REC_ON_CHANGE, CLEAR, SEARCH, CHANGE_WO, CHANGE_BOX, CHANGE_LAYER, SET_ADJUST_PARAMS
end else
   Void = msg( '', 'Invalid Branch ':Bpos:' passed to recipe_browse_comm' )
end
return ReturnVar
*============================================================================*
REACT_REC_ON_CHANGE:
  * CurParam null
  if ( get_property( @window:'.REACTOR', 'TEXT' ) <> '' ) and ( (get_property( @window:'.PSN', 'TEXT') <> '')  OR  (get_property( @window:'.RECIPE_NO', 'TEXT' ) <> '') ) then
     Void = set_property( @window:'.SEARCH', 'VISIBLE', 1 )
  end else
     Void = set_property( @window:'.SEARCH', 'VISIBLE', 0 )
  end
return

*============================================================================*
CLEAR:
   Void = set_property( AllControls, 'TEXT', '' )
   Void = set_property( @window:'.REACTOR', 'ENABLED', 1 )
   Void = set_property( @window:'.RECIPE_NO', 'ENABLED', 1 )
   Void = set_property( @window:'.PSN', 'ENABLED', 1 )             
   Void = send_event( @window:'.REACTOR', 'GOT_FOCUS' )   
   Void = set_property( 'SYSTEM', 'FOCUS', @window:'.REACTOR' )
   Void = set_property( @window:'.WO_BEG', 'ENABLED', 0 )
   Void = set_property( @window:'.WO_PREV', 'ENABLED', 0 )
   Void = set_property( @window:'.WO_NEXT', 'ENABLED', 0 )
   Void = set_property( @window:'.WO_END', 'ENABLED', 0 )
   Void = set_property( @window:'.RO_BEG', 'ENABLED', 0 )
   Void = set_property( @window:'.RO_PREV', 'ENABLED', 0 )
   Void = set_property( @window:'.RO_NEXT', 'ENABLED', 0 )
   Void = set_property( @window:'.RO_END', 'ENABLED', 0 )
   Void = set_property( @window:'.LAY_BEG', 'ENABLED', 0 )   
   Void = set_property( @window:'.LAY_PREV', 'ENABLED', 0 )
   Void = set_property( @window:'.LAY_NEXT', 'ENABLED', 0 )
   Void = set_property( @window:'.LAY_END', 'ENABLED', 0 )            
   Void = set_property( @window:'.GOTO_RDS', 'VISIBLE', 0 )
   Void = set_property( @window:'.PRINT', 'VISIBLE', 0 )
   Void = set_property( @window:'.INST_REC_BUTTON', 'VISIBLE', 0 )      
   Void = set_property( @window:'.WO_BOX_LABEL', 'TEXT', '' )
   Void = set_property( @window:'.BOX_LABEL', 'TEXT', '' )
   Void = set_property( @window:'.WO_LABEL', 'TEXT', '' )
   Void = set_property( @window:'.LAYER_LABEL', 'TEXT', '' )      
	Void = set_property( @window, '@WOCnt', '' )
	Void = set_property( @window, '@WOCurPos', '' )
	Void = set_property( @window, '@WOS', '' )
	Void = set_property( @window, '@RDSCnt', '' )
	Void = set_property( @window, '@RDSCurPos', '' )
	Void = set_property( @window, '@RDSS', '' )
	Void = set_property( @window, '@LayCnt', '' )
	Void = set_property( @window, '@LayCurPos', '' )
	Void = set_property( @window, '@Layers', '' )
   Void = set_property( @window, '@TemperatureData', '' )	
return

*============================================================================*
SEARCH:
*CurParam is null
Reactor  = get_property( @window:'.REACTOR', 'TEXT' )
RecipeNo = get_property( @window:'.RECIPE_NO', 'TEXT' )
PSN      = get_property( @window:'.PSN', 'TEXT' )
SearchStr = ''
if Reactor <> '' then
   SearchStr<-1> = 'REACTOR':@vm:Reactor
end
if RecipeNo <> '' then
   SearchStr<-1> = 'RECIPE_NO':@vm:RecipeNo
end
if PSN <> '' then
   SearchStr<-1> = 'PROD_SPEC_ID':@vm:PSN
end
SearchStr := @fm
Void = utility( 'CURSOR', 'H' )
* do a btree.extract
* POSSIBLY ONLY EXTRACT RECORDS WITH DATE OUT
btree.extract( SearchStr, 'RDS', DictRDSTable, Keys, '', Flag )
if Flag <> 0 then
   Void = msg( '', 'Error while extracting RDS records...' )
   return 0
end
if Keys then
   convert @vm to @fm in Keys
   Keys = key_sort( Keys, 'RDS', 'WO':@fm:'RUN_ORDER_NUM', 0 )
   TWos = xlate( 'RDS', Keys, rds_wo$, 'X' )
   Kcnt = fieldcount( Keys, @fm )
   Wos = ''
   for i = 1 to Kcnt
      WoToFind = TWos<i>
      locate WoToFind in Wos using @fm setting Fpos else
         Wos := WoToFind:@fm
      end
   next i
   Wos[-1,1] = ''
   NWos = fieldcount( Wos, @fm )
   Void = set_property( @window, '@Wos', Wos )
   Void = set_property( @window, '@WoCnt', NWos )
   Void = set_property( @window, '@WOCurPos', '' )
   CurParam = NWos   ;* set it to the last work order (last one used)
   gosub CHANGE_WO 
   Void = set_property( @window:'.SEARCH', 'VISIBLE', 0 )
   Void = set_property( @window:'.WO_BEG', 'ENABLED', 1 )
   Void = set_property( @window:'.WO_PREV', 'ENABLED', 1 )
   Void = set_property( @window:'.WO_NEXT', 'ENABLED', 1 )
   Void = set_property( @window:'.WO_END', 'ENABLED', 1 )
   Void = set_property( @window:'.RO_BEG', 'ENABLED', 1 )
   Void = set_property( @window:'.RO_PREV', 'ENABLED', 1 )
   Void = set_property( @window:'.RO_NEXT', 'ENABLED', 1 )
   Void = set_property( @window:'.RO_END', 'ENABLED', 1 )
   Void = set_property( @window:'.LAY_BEG', 'ENABLED', 1 )      
   Void = set_property( @window:'.LAY_PREV', 'ENABLED', 1 )
   Void = set_property( @window:'.LAY_NEXT', 'ENABLED', 1 )
   Void = set_property( @window:'.LAY_END', 'ENABLED', 1 )            
   Void = set_property( @window:'.GOTO_RDS', 'VISIBLE', 1 )
   Void = set_property( @window:'.PRINT', 'VISIBLE', 1 )
   Void = set_property( @window:'.INST_REC_BUTTON', 'VISIBLE', 1 )   
   Void = set_property( @window:'.REACTOR', 'ENABLED', 0 )
   Void = set_property( @window:'.RECIPE_NO', 'ENABLED', 0 )
   Void = set_property( @window:'.PSN', 'ENABLED', 0 )                
end else
   MsgInfo = ''
   MsgInfo<mtext$> = 'No records found meeting your criteria...' 
   MsgInfo<micon$> = '!'
   Void = msg( '', MsgInfo )
end
Void = utility( 'CURSOR', 'A' )
return 0

*============================================================================*
CHANGE_WO:
* CurParam will be an integer representing the first or the last work order
* or it will either be PREVIOUS or NEXT
ProcessWo = true$
if num(CurParam) then ;* called from search will have the last wo
   * no need to check to see if in range
   if CurParam = 1 and get_property( @window, '@WoCurPos' ) = 1 then
      MsgInfo = ''
      MsgInfo<mtext$> = 'You are on the first Work Order...'
      MsgInfo<micon$> = 'H'
      ProcessWo = false$
      Void = msg( '', MsgInfo )
   end else
      if CurParam = get_property( @window, '@WoCurPos' ) then
         MsgInfo = ''
         MsgInfo<mtext$> = 'You are on the last Work Order...'
         MsgInfo<micon$> = 'H'
         ProcessWo = false$
         Void = msg( '', MsgInfo )
      end else
         Void = set_property( @window, '@WoCurPos', CurParam )
         WoToUse = get_property( @window, '@Wos' )<CurParam>
      end
   end 
end else
	if CurParam = 'NEXT' then
	   if get_property( @window, '@WoCurPos' ) = get_property( @window, '@WoCnt' ) then
	      MsgInfo = ''
	      MsgInfo<mtext$> = 'You are on the last Work Order...'
	      MsgInfo<micon$> = 'H'
	      ProcessWo = false$
	      Void = msg( '', MsgInfo )
	   end else
	      Void = set_property( @window, '@WoCurPos', get_property( @window, '@WoCurPos' ) + 1 )
	      WoToUse = get_property( @window, '@Wos' )<get_property( @window, '@WoCurPos' )>
	   end
	end else
	   if CurParam = 'PREVIOUS' then
		   if get_property( @window, '@WoCurPos' ) = 1 then
		      MsgInfo = ''
		      MsgInfo<mtext$> = 'You are on the first Work Order...'
		      MsgInfo<micon$> = 'H'
		      ProcessWo = false$
		      Void = msg( '', MsgInfo )
		   end else
		      Void = set_property( @window, '@WoCurPos', get_property( @window, '@WoCurPos' ) - 1 )
		      WoToUse = get_property( @window, '@Wos' )<get_property( @window, '@WoCurPos' )>      
		   end
		end
	end
end
if ProcessWo then
	SearchStr = ''
	SearchStr<-1> = 'WO':@vm:WoToUse
	SearchStr := @fm
	Void = utility( 'CURSOR', 'H' )
	* do a btree.extract
	btree.extract( SearchStr, 'RDS', DictRDSTable, Keys, '', Flag )
	if Flag <> 0 then
	   Void = msg( '', 'Error while extracting RDS records...' )
	   return 0
	end
	if Keys then
	   convert @vm to @fm in Keys
	   Keys = key_sort( Keys, 'RDS', 'RUN_ORDER_NUM', 0 )
	   for i = 2 to 999
	      Found = index( Keys, '.':i, 1 )
	     until Found = 0 
	   next i
	   i - = 1 
	   Tcnt = fieldcount( Keys, @fm )
	   *TLabel = get_property( @window:'.WO_BOX_LABEL', 'TEXT' )
	   *convert 1234567890 to '' in TLabel
	   *convert ' ' to '' in TLabel
	   TLabel = Tcnt/i:' Boxes'
	   Void = set_property( @window:'.WO_BOX_LABEL', 'TEXT', TLabel )
	   Void = set_property( @window:'.WO', 'TEXT', WoToUse )
	   WoBoxLabel = get_property( @window, '@WoCurPos' ):' of ':get_property( @window, '@WoCnt' )
	   Void = set_property( @window:'.WO_LABEL', 'TEXT', WoBoxLabel )
	   * now setup rds common var - meaning choose boxes that actually ran
	   * on that reactor and that recipe; cause the work order may have been 
	   * split
		SearchStr = ''
		SearchStr<-1> = 'WO':@vm:WoToUse
		SearchStr<-1> = 'REACTOR':@vm:get_property( @window:'.REACTOR', 'TEXT' )
		RecipeNo = get_property( @window:'.RECIPE_NO', 'TEXT' )
		PSN      = get_property( @window:'.PSN', 'TEXT' )
		if RecipeNo <> '' then
		   SearchStr<-1> = 'RECIPE_NO':@vm:RecipeNo
		end
		if PSN <> '' then
		   SearchStr<-1> = 'PROD_SPEC_ID':@vm:PSN
		end
		SearchStr := @fm
		* do a btree.extract
		btree.extract( SearchStr, 'RDS', DictRDSTable, Keys, '', Flag )
		if Flag <> 0 then
			Void = msg( '', 'Error while extracting RDS records...' )
			return 0
		end
	   convert @vm to @fm in Keys
	   Keys = key_sort( Keys, 'RDS', 'RUN_ORDER_NUM', 0 )
		NRdss = fieldcount( Keys, @fm )
		Void = set_property( @window, '@RDSS', Keys )
		Void = set_property( @window, '@RDSCnt', NRdss )
		Void = set_property( @window, '@RDSCurPos', '' )
		CurParam = 1      ;* set it to the first run order that was run on
		                  ;* that reactor and recipe
		gosub CHANGE_BOX
	end
	Void = utility( 'CURSOR', 'A' )   
end
return

*============================================================================*
CHANGE_BOX:
* CurParam will be an integer representing the first or the last BOX RUN
* or it will either be PREVIOUS or NEXT
ProcessBox = true$
if num(CurParam) then
   * no need to check to see if in range
   if CurParam = 1 and get_property( @window, '@RDSCurPos' ) = 1 then
      MsgInfo = ''
      MsgInfo<mtext$> = 'You are on the first first box that was run...'
      MsgInfo<micon$> = 'H'
      ProcessBox = false$
      Void = msg( '', MsgInfo )
   end else
      if CurParam = get_property( @window, '@RDSCurPos' ) then
         MsgInfo = ''
         MsgInfo<mtext$> = 'You are on the last box that was run...'
         MsgInfo<micon$> = 'H'
         ProcessBox = false$
         Void = msg( '', MsgInfo )
      end else
         Void = set_property( @window, '@RDSCurPos', CurParam )
         RdsToUse = get_property( @window, '@RDSS' )<CurParam>
      end
   end 
end else
	if CurParam = 'NEXT' then
	   if get_property( @window, '@RDSCurPos' ) = get_property( @window, '@RDSCnt' ) then
	      MsgInfo = ''
	      MsgInfo<mtext$> = 'You are on the last box that was run...'
	      MsgInfo<micon$> = 'H'
	      ProcessBox = false$
	      Void = msg( '', MsgInfo )
	   end else
	      Void = set_property( @window, '@RDSCurPos', get_property( @window, '@RDSCurPos' ) + 1 )
	      RDSToUse = get_property( @window, '@RDSS' )<get_property( @window, '@RDSCurPos' )>
	   end
	end else
	   if CurParam = 'PREVIOUS' then
		   if get_property( @window, '@RDSCurPos' ) = 1 then
		      MsgInfo = ''
		      MsgInfo<mtext$> = 'You are on the first box that was run...'
		      MsgInfo<micon$> = 'H'
		      ProcessBox = false$
		      Void = msg( '', MsgInfo )
		   end else
		      Void = set_property( @window, '@RDSCurPos', get_property( @window, '@RDSCurPos' ) - 1 )
		      RDSToUse = get_property( @window, '@RDSS' )<get_property( @window, '@RDSCurPos' )>      
		   end
		end
	end
end
if ProcessBox then
   Void = set_property( @window:'.RDS_NO', 'TEXT', RDSToUse )
   RunOrderNo = xlate( 'RDS', RDSToUse, 'RUN_ORDER_NUM', 'X' )
   Void = set_property( @window:'.RUN_ORDER', 'TEXT', RunOrderNo )
   TLabel = 'Box ':get_property( @window, '@RDSCurPos' ):' of ':get_property( @window, '@RDSCnt' )  
   Void = set_property( @window:'.BOX_LABEL', 'TEXT', TLabel )
   ThisRdsRec = xlate( 'RDS', RDSToUse, '', 'X' )
   
   
	RDSLayerKeys = XLATE('RDS',RDSToUse,'RDS_LS_SORTED','X')		;* Sorted Layer Set Keys
	
	LayerCnt = COUNT(RDSLayerKeys,@VM) + (RDSLayerKeys NE '')
	
	TData = ''
	Layers = ''
	
	FOR L = 1 TO LayerCnt
		RDSLayerKey = RDSLayerKeys<1,L>
		
		RDSLayerRec = XLATE('RDS_LAYER',RDSLayerKey,'','X')
		
		Layers<L,Dopant$>		= RDSLayerRec<RDS_LAYER_DOPANT$>
		Layers<L,DepTime$>		= RDSLayerRec<RDS_LAYER_EPI_TIME$>
		Layers<L,Temp$>			= XLATE('RECIPE',RDSLayerRec<RDS_LAYER_RECIPE_NO$>,'EPI_TEMP','X')
		Layers<L,H2Flow$>		= RDSLayerRec<RDS_LAYER_EPI_H2_FLOW$>
		Layers<L,DopantFlow$>	= RDSLayerRec<RDS_LAYER_DOPANT_FLOW$>
		Layers<L,Diluent$>		= RDSLayerRec<RDS_LAYER_EPI_DILUENT$>
		Layers<L,TCS$>			= RDSLayerRec<RDS_LAYER_TCS_FLOW$>
		Layers<L,DCS$>			= RDSLayerRec<RDS_LAYER_DCS_FLOW$>
		Layers<L,Aux1$>			= RDSLayerRec<RDS_LAYER_AUX1$>
		Layers<L,Aux2$>			= RDSLayerRec<RDS_LAYER_AUX2$>
		Layers<L,Gases$>		= XLATE('RECIPE',RDSLayerRec<RDS_LAYER_RECIPE_NO$>,'EPI_GASES','X')
		Layers<L,GasRate$>		= XLATE('RECIPE',RDSLayerRec<RDS_LAYER_RECIPE_NO$>,'EPI_GAS_RATE', 'X' )
		Layers<L,GasUnit$>		= XLATE('RECIPE',RDSLayerRec<RDS_LAYER_RECIPE_NO$>,'EPI_GASES_UNIT', 'X' )
		Layers<L,BakeTime$>		= RDSLayerRec<RDS_LAYER_BAKE_TIME$>
		Layers<L,EtchTime$>		= XLATE('RECIPE',RDSLayerRec<RDS_LAYER_RECIPE_NO$>,'ETCH_TIME', 'X' )
		Layers<L,HCLFlow$>		= RDSLayerRec<RDS_LAYER_HCL_FLOW$>
		Layers<L,AdjDiluent$>	= RDSLayerRec<RDS_LAYER_DILUENT_ADJ_PARAM$>
	
		IF L = 1 THEN
			TData  = RDSLayerRec<RDS_LAYER_F_OFFSET$>:@RM
			TData := RDSLayerRec<RDS_LAYER_S_OFFSET$>:@RM
			TData := RDSLayerRec<RDS_LAYER_R_OFFSET$>:@RM
			TData := ThisRdsRec<RDS_INJECTORS$>
		END
	NEXT L
	/*
   * now get layer information...start with base layer and then
   * on layers 2-nnn only put in the DEPOSIT_TIME AND THE DOPANT_FLOW, DOPANT, DILUENT
   Layers = ''
   Layers<1,Dopant$>        = xlate('RDS',RDSToUse,'DOPANT_L1', 'X' )
   Layers<1,DepTime$>       = XLATE('RDS',RDSToUse,'EPI_TIME','X')				;* ThisRdsRec<rds_epi_time$> 
   Layers<1,Temp$>          = xlate('RDS',RDSToUse,'TEMP', 'X' )
   Layers<1,H2Flow$>        = XLATE('RDS',RDSToUse,'EPI_H2_FLOW','X')			;* ThisRdsRec<rds_epi_h2_flow$>
   Layers<1,DopantFlow$>    = XLATE('RDS',RDSToUse,'DOPANT_FLOW','X')			;* ThisRdsRec<rds_dopant_flow$> 
   Layers<1,Diluent$>       = xlate('RDS',RDSToUse,'DILUENT_L1', 'X' )
   Layers<1,TCS$>           = XLATE('RDS',RDSToUse,'TCS_FLOW','X')				;* ThisRDSREc<rds_tcs_flow$>
   Layers<1,DCS$>           = XLATE('RDS',RDSToUse,'DCS_FLOW','X')				;* ThisRDSRec<rds_dcs_flow$>
   Layers<1,Aux1$>          = XLATE('RDS',RDSToUse,'AUX1','X')					;* ThisRDSRec<rds_aux1$>
   Layers<1,Aux2$>          = XLATE('RDS',RDSToUse,'AUX2','X')					;* ThisRDSRec<rds_aux2$>
   Layers<1,Gases$>			= xlate('RDS',RDSToUse,'GASES', 'X' )
   Layers<1,GasRate$>		= xlate('RDS',RDSToUse,'GAS_RATE', 'X' )
   Layers<1,GasUnit$>		= xlate('RDS',RDSToUse,'GAS_UNIT', 'X' )
   Layers<1,BakeTime$>		= XLATE('RDS',RDSToUse,'BAKE_TIME','X')				;* ThisRdsRec<rds_bake_time$> 
   Layers<1,EtchTime$>		= xlate('RDS',RDSToUse,'ETCH_TIME', 'X' )
   Layers<1,HCLFlow$>		= XLATE('RDS',RDSToUse,'HCL_FLOW','X')				;* ThisRDSRec<rds_hcl_flow$>
   Layers<1,AdjDiluent$>	= XLATE('RDS',RDSToUse,'DILUENT_ADJ_PARAM','X')		;* ThisRDSRec<rds_diluent_adj_param$>
   
   * THIS IS LAYER ONE SO DISPLAY TEMPERATURE OFFSETS AND INJECTORS
   
   
	FOffset = XLATE('RDS',RDSToUse,'F_OFFSET','X')
	SOffset = XLATE('RDS',RDSToUse,'S_OFFSET','X')
	ROffset = XLATE('RDS',RDSToUse,'R_OFFSET','X')
	
   
   TData = FOffset:@fm:SOffset:@fm:ROffset:@fm:ThisRdsRec<rds_injectors$>
   convert @fm to @rm in TData
   */
   
   
   Void = set_property( TemperatureControls, 'TEXT', TData )
   Void = set_property( @window, '@TemperatureData', TData )
   
   /*
   *
   LayerInfo = ThisRdsRec<rds_layer_info$>
   convert char(248) to @fm in LayerInfo
   Lcnt = fieldcount( LayerInfo, @fm )
   
   DopantAll  = xlate( 'RDS', RDSToUse, 'DOPANT_ALL', 'X' )
   DiluentAll = xlate( 'RDS', RDSToUse, 'DILUENT_ALL', 'X' )
   
   * DELETE LAYER ONE CAUSE IT HAS ALREDY BEEN USED ABOVE
   DopantAll  = delete( DopantAll, 1, 1, 0 )
   DiluentAll = delete( DiluentAll, 1, 1, 0 )
   for i = 1 to Lcnt
		*Layers := char(248):ThisRdsRec<rds_layer_info$,>
		ThisLayer = LayerInfo<i>
		TLayer    = ''
		*
	   TLayer<1,Dopant$>        = DopantAll<1,i>
	   TLayer<1,DepTime$>       = ThisLayer<1,RLEpiTime$> 
	   TLayer<1,Temp$>          = ''
	   TLayer<1,H2Flow$>        = ''
	   TLayer<1,DopantFlow$>    = ThisLayer<1,RLDopantFlow$> 
	   TLayer<1,Diluent$>       = DiluentAll<1,i>
	   TLayer<1,TCS$>           = ''
	   TLayer<1,DCS$>           = ''
	   TLayer<1,Aux1$>          = ''
	   TLayer<1,Aux2$>          = ''
	   TLayer<1,Gases$>    = ''
	   TLayer<1,GasRate$>  = ''
	   TLayer<1,GasUnit$>  = ''
	   TLayer<1,BakeTime$>    = ''
	   TLayer<1,EtchTime$>    = ''
		Layers := char(248):TLayer 	
   next i
   
   */
   
	CONVERT @FM TO CHAR(248) IN Layers
	Void = set_property( @window, '@Layers', Layers )
	Void = set_property( @window, '@LayCnt', LayerCnt )
	Void = set_property( @window, '@LayCurPos', '' )
	CurParam = 1      ;* set it to the first layer
	GOSUB CHANGE_LAYER
END
RETURN
*============================================================================*
CHANGE_LAYER:
* CurParam will be an integer representing the first or the last SAME
* REACTOR LAYER...first layer will be the recipe specific fields in RDS and
* layer 2-999 will come out of the rds_layer_info field with each layer
* delimited by char(248) or it will either be PREVIOUS or NEXT
ProcessLayer = true$
if num(CurParam) then
   * no need to check to see if in range
   if CurParam = 1 and get_property( @window, '@LayCurPos' ) = 1 then
      MsgInfo = ''
      MsgInfo<mtext$> = 'You are on the first layer...'
      MsgInfo<micon$> = 'H'
      ProcessLayer = false$
      Void = msg( '', MsgInfo )
   end else
      if CurParam = get_property( @window, '@LayCurPos' ) then
         MsgInfo = ''
         MsgInfo<mtext$> = 'You are on the last layer...'
         MsgInfo<micon$> = 'H'
         ProcessLayer = false$
         Void = msg( '', MsgInfo )
      end else
         Void = set_property( @window, '@LayCurPos', CurParam )
         LayToUse = get_property( @window, '@Layers' )<CurParam>
      end
   end 
end else
	if CurParam = 'NEXT' then
	   if get_property( @window, '@LayCurPos' ) = get_property( @window, '@LayCnt' ) then
	      MsgInfo = ''
	      MsgInfo<mtext$> = 'You are on the last layer...'
	      MsgInfo<micon$> = 'H'
	      ProcessLayer = false$
	      Void = msg( '', MsgInfo )
	   end else
	      Void = set_property( @window, '@LayCurPos', get_property( @window, '@LayCurPos' ) + 1 )
	      LayToUse = get_property( @window, '@Layers' )<get_property( @window, '@LayCurPos' )>
	   end
	end else
	   if CurParam = 'PREVIOUS' then
		   if get_property( @window, '@LayCurPos' ) = 1 then
		      MsgInfo = ''
		      MsgInfo<mtext$> = 'You are on the first layer...'
		      MsgInfo<micon$> = 'H'
		      ProcessLayer = false$
		      Void = msg( '', MsgInfo )
		   end else
		      Void = set_property( @window, '@LayCurPos', get_property( @window, '@LayCurPos' ) - 1 )
		      LayToUse = get_property( @window, '@Layers' )<get_property( @window, '@LayCurPos' )>      
		   end
		end
	end
end
if ProcessLayer then
   CurLayer = field( get_property( @window, '@Layers' ), char(248), get_property( @window, '@LayCurPos' ) )
   CurLayer<1,DepTime$>      = oconv( CurLayer<1,DepTime$>, 'MD1' )   
	CurLayer<1,DopantFlow$>   = oconv( CurLayer<1,DopantFlow$>, 'MD2' )
	CurLayer<1,Diluent$>      = oconv( CurLayer<1,Diluent$>, 'MD2' )
	CurLayer<1,TCS$>          = oconv( CurLayer<1,TCS$>, 'MD1' )
	CurLayer<1,Aux1$>         = oconv( CurLayer<1,Aux1$>, 'MD2' )
	CurLayer<1,Aux2$>         = oconv( CurLayer<1,Aux2$>, 'MD2' )	
	CurLayer<1,GasRate$>      = oconv( CurLayer<1,GasRate$>, 'MD2' )
	CurLayer<1,BakeTime$>     = oconv( CurLayer<1,BakeTime$>, '[SECONDS_CONV]' )
	CurLayer<1,EtchTime$>     = oconv( CurLayer<1,EtchTime$>, '[SECONDS_CONV]' )
	CurLayer<1,HCLFlow$>      = oconv( CurLayer<1,HCLFlow$>, 'MD2' )
	CurLayer<1,AdjDiluent$>   = oconv( CurLayer<1,AdjDiluent$>, 'MD2' )
	DataToLoad = field( CurLayer, @vm, 1, fieldcount( RecipeControls, @rm ) )
	convert @vm to @rm in DataToLoad
	Void = set_property( RecipeControls, 'TEXT', DataToLoad )
   TLabel = 'Layer ':get_property( @window, '@LayCurPos' ):' of ':get_property( @window, '@LayCnt' )  
   Void = set_property( @window:'.LAYER_LABEL', 'TEXT', TLabel )
   if get_property( @window, '@LayCurPos' ) > 1 then
      * IF WE ARE NOT ON THE FIRST LAYER THEN SHOW NOTHIN IN THE TEMPERATURE AND INJECTOR SETTINGS
      Void = set_property( TemperatureControls, 'TEXT', '' )
   end else
      TempData = get_property( @window, '@TemperatureData' )   
	   Void = set_property( TemperatureControls, 'TEXT', TempData )
   end   
end
return
*============================================================================*
SET_ADJUST_PARAMS:
   * THIS SUBROUTINE IS CALLED FROM THE RECIPE_BROWSE2 WINDOW ONLY
   PSNId = CurParam
   RDSId = get_property( 'RECIPE_BROWSE.RDS_NO', 'TEXT' )
   IdToUse = xlate( 'RDS', RDSId, 'RECIPE_NO', 'X' )						;* 4/14/2006 JCH
   RecipeRec = xlate( 'RECIPE', IdToUse, '', 'X' )
   PSNs = RecipeRec<recipe_prod_spec_ids$>   
   locate PSNId in PSNs using @vm setting Rpos else
      * THE PSN IS NOT FOUND IN THE RECIPE SO USE THE TOP ROW LIMITS
      Rpos = 1
   end
   DepMin         = RecipeRec<recipe_dep_time_min$,Rpos>
   DepMax         = RecipeRec<recipe_dep_time_max$,Rpos>
   DiluentFlowMin = RecipeRec<recipe_diluent_min$,Rpos>
   DiluentFlowMax = RecipeRec<recipe_diluent_max$,Rpos>	   
   DopantFlowMin  = RecipeRec<recipe_dopant_flow_min$,Rpos>
   DopantFlowMax  = RecipeRec<recipe_dopant_flow_max$,Rpos>
   HCLFlowMin     = RecipeRec<recipe_hcl_flow_min$,Rpos>
   HCLFlowMax     = RecipeRec<recipe_hcl_flow_max$,Rpos>
   BakeMin        = RecipeRec<recipe_bake_time_min$,Rpos>
   BakeMax        = RecipeRec<recipe_bake_time_max$,Rpos>
   H2Min          = RecipeRec<recipe_h2_flow_min$,Rpos>
   H2Max          = RecipeRec<recipe_h2_flow_max$,Rpos>
   TCSMin         = RecipeRec<recipe_tcs_flow_min$,Rpos>
   TCSMax         = RecipeRec<recipe_tcs_flow_max$,Rpos>
   DCSMin         = RecipeRec<recipe_dcs_flow_min$,Rpos>
   DCSMax         = RecipeRec<recipe_dcs_flow_max$,Rpos>
   Aux1Min        = RecipeRec<recipe_aux1_min$,Rpos>
   Aux1Max        = RecipeRec<recipe_aux1_max$,Rpos>
   Aux2Min        = RecipeRec<recipe_aux2_min$,Rpos>
   Aux2Max        = RecipeRec<recipe_aux2_max$,Rpos>
   FOffsetMin     = RecipeRec<recipe_f_offset_min$,Rpos>
   FOffsetMax     = RecipeRec<recipe_f_offset_max$,Rpos>
   SOffsetMin     = RecipeRec<recipe_s_offset_min$,Rpos>
   SOffsetMax     = RecipeRec<recipe_s_offset_max$,Rpos>
   ROffsetMin     = RecipeRec<recipe_r_offset_min$,Rpos>
   ROffsetMax     = RecipeRec<recipe_r_offset_max$,Rpos>
   LayerInfo      = RecipeRec<recipe_layer_info$>
   LimitStyles    = send_message( @window:'.RECIPE_LIMITS', "COLSTYLE", 0, '' )
   CurArray       = get_property( @window:'.RECIPE_LIMITS', 'ARRAY' )
   CurLArray      = get_property( @window:'.RECIPE_LAYER_LIMTS', 'ARRAY' )

   convert char(248) to @fm in LayerInfo
   LACnt = fieldcount( LayerInfo, @fm )
   for i = 1 to LACnt
      CurLArray<1,i> = i+1
   	CurLArray<2,i> = oconv( LayerInfo<i,RecLEpiDepTimeMin$>, 'MD1' ):'~':oconv( LayerInfo<i,RecLEpiDepTimeMax$>, 'MD1' )
   	CurLArray<3,i> = oconv( LayerInfo<i,RecLEpiDopantFlowMin$>, 'MD2' ):'~':oconv( LayerInfo<i,RecLEpiDopantFlowMax$>, 'MD2' )
   next i

   Void = set_property( 'RECIPE_BROWSE2.RECIPE_LAYER_LIMITS', 'ARRAY', CurLArray )     
   
   if ( DepMin = '' ) and ( DepMax = '' ) then
      LimitStyles<RecInfoDepTime$> = bitor( LimitStyles<RecInfoDepTime$>, Hidden$ )	      
   end else
      CurArray<RecInfoDepTime$,1> = oconv( DepMin, 'MD1' ):'~':oconv( DepMax, 'MD1' )
      LimitStyles<RecInfoDepTime$> = bitand( LimitStyles<RecInfoDepTime$>, bitnot(Hidden$) )	      
   end
   if ( DiluentFlowMin = '' ) and ( DiluentFlowMax = '' ) then
      LimitStyles<RecInfoDiluentFlow$> = bitor( LimitStyles<RecInfoDiluentFlow$>, Hidden$ )	      
   end else
      CurArray<RecInfoDiluentFlow$,1> = oconv( DiluentFlowMin, 'MD2' ):'~':oconv( DiluentFlowMax, 'MD2' )
      LimitStyles<RecInfoDiluentFlow$> = bitand( LimitStyles<RecInfoDiluentFlow$>, bitnot(Hidden$) )	      
   end
   if ( DopantFlowMin = '' ) and ( DopantFlowMax = '' ) then
      LimitStyles<RecInfoDopantFlow$> = bitor( LimitStyles<RecInfoDopantFlow$>, Hidden$ )	      
   end else
      CurArray<RecInfoDopantFlow$,1> = oconv( DopantFlowMin, 'MD2' ):'~':oconv( DopantFlowMax, 'MD2' )
      LimitStyles<RecInfoDopantFlow$> = bitand( LimitStyles<RecInfoDopantFlow$>, bitnot(Hidden$) )	      
   end
   if ( HCLFlowMin = '' ) and ( HCLFlowMax = '' ) then
      LimitStyles<RecInfoHCLFlow$> = bitor( LimitStyles<RecInfoHCLFlow$>, Hidden$ )	      
   end else
      CurArray<RecInfoHCLFlow$,1> = oconv( HCLFlowMin, 'MD2' ):'~':oconv( HCLFlowMax, 'MD2' )
      LimitStyles<RecInfoHCLFlow$> = bitand( LimitStyles<RecInfoHCLFlow$>, bitnot(Hidden$) )	      
   end
   if ( BakeMin = '' ) and ( BakeMax = '' ) then
      LimitStyles<RecInfoBake$> = bitor( LimitStyles<RecInfoBake$>, Hidden$ )	      
   end else
      CurArray<RecInfoBake$,1> = oconv( BakeMin, '[SECONDS_CONV]' ):'~':oconv( BakeMax, '[SECONDS_CONV]' )
      LimitStyles<RecInfoBake$> = bitand( LimitStyles<RecInfoBake$>, bitnot(Hidden$) )	      
   end
   if ( H2Min = '' ) and ( H2Max = '' ) then
      LimitStyles<RecInfoH2$> = bitor( LimitStyles<RecInfoH2$>, Hidden$ )	      
   end else
      CurArray<RecInfoH2$,1> = oconv( H2Min, 'MD0' ):'~':oconv( H2Max, 'MD0' )
      LimitStyles<RecInfoH2$> = bitand( LimitStyles<RecInfoH2$>, bitnot(Hidden$) )	      
   end
   if ( TCSMin = '' ) and ( TCSMax = '' ) then
      LimitStyles<RecInfoTCS$> = bitor( LimitStyles<RecInfoTCS$>, Hidden$ )	      
   end else
      CurArray<RecInfoTCS$,1> = oconv( TCSMin, 'MD1' ):'~':oconv( TCSMax, 'MD1' )
      LimitStyles<RecInfoTCS$> = bitand( LimitStyles<RecInfoTCS$>, bitnot(Hidden$) )	      
   end
   if ( DCSMin = '' ) and ( DCSMax = '' ) then
      LimitStyles<RecInfoDCS$> = bitor( LimitStyles<RecInfoDCS$>, Hidden$ )	      
   end else
      CurArray<RecInfoDCS$,1> = oconv( DCSMin, 'MD0' ):'~':oconv( DCSMax, 'MD0' )
      LimitStyles<RecInfoDCS$> = bitand( LimitStyles<RecInfoDCS$>, bitnot(Hidden$) )	      
   end
   if ( Aux1Min = '' ) and ( Aux1Max = '' ) then
      LimitStyles<RecInfoAux1$> = bitor( LimitStyles<RecInfoAux1$>, Hidden$ )	      
   end else
      CurArray<RecInfoAux1$,1> = oconv( Aux1Min, 'MD2' ):'~':oconv( Aux1Max, 'MD2' )
      LimitStyles<RecInfoAux1$> = bitand( LimitStyles<RecInfoAux1$>, bitnot(Hidden$) )	      
   end
   if ( Aux2Min = '' ) and ( Aux2Max = '' ) then
      LimitStyles<RecInfoAux2$> = bitor( LimitStyles<RecInfoAux2$>, Hidden$ )	      
   end else
      CurArray<RecInfoAux2$,1> = oconv( Aux2Min, 'MD2' ):'~':oconv( Aux2Max, 'MD2' )
      LimitStyles<RecInfoAux2$> = bitand( LimitStyles<RecInfoAux2$>, bitnot(Hidden$) )	      
   end
   if ( FOffsetMin = '' ) and ( FOffsetMax = '' ) then
      LimitStyles<RecInfoFOffset$> = bitor( LimitStyles<RecInfoFOffset$>, Hidden$ )	      
   end else
      CurArray<RecInfoFOffset$,1> = iconv( FOffsetMin, 'MD0' ):'~':iconv( FOffsetMax, 'MD0' )
      LimitStyles<RecInfoFOffset$> = bitand( LimitStyles<RecInfoFOffset$>, bitnot(Hidden$) )	      
   end
   if ( SOffsetMin = '' ) and ( SOffsetMax = '' ) then
      LimitStyles<RecInfoSOffset$> = bitor( LimitStyles<RecInfoSOffset$>, Hidden$ )	      
   end else
      CurArray<RecInfoSOffset$,1> = iconv( SOffsetMin, 'MD0' ):'~':iconv( SOffsetMax, 'MD0' )
      LimitStyles<RecInfoSOffset$> = bitand( LimitStyles<RecInfoSOffset$>, bitnot(Hidden$) )	      
   end
   if ( ROffsetMin = '' ) and ( ROffsetMax = '' ) then
      LimitStyles<RecInfoROffset$> = bitor( LimitStyles<RecInfoROffset$>, Hidden$ )	      
   end else
      CurArray<RecInfoROffset$,1> = iconv( ROffsetMin, 'MD0' ):'~':iconv( ROffsetMax, 'MD0' )
      LimitStyles<RecInfoROffset$> = bitand( LimitStyles<RecInfoROffset$>, bitnot(Hidden$) )	      
   end
   LimitStyles = send_message( @window:'.RECIPE_LIMITS', "COLSTYLE", 0, LimitStyles  )	   
   Void = set_property( @window:'.RECIPE_LIMITS', "AUTOSIZECOL", 14 )	   
   Void = set_property( @window:'.RECIPE_LIMITS', 'ARRAY', CurArray )
return
*============================================================================*
