function get_op_rules, filein
;+
;  Name:
;    get_op_rules
;
;  Purpose:
;    Read a table of "rules" by which to run op_first_guess
;
;  Inputs:
;    filein	Name of the ascii file containing rules.
;
;  Outputs:
;    Returns a structure containing a lookup table of rules.
;
;  Proceedure:
;    Opens an ascii file and reads it.
;    Lines beginning with ";" are ignored.
;    Format is op_first_guess index, value, "Comment"
;
;    Example:
;    0     -.5   "AOS            offset (min)"
;
;  Modification History:
;    5-oct-91, Written, JRL.
;   12-nov-91, Updated, JRL, Added more rules for DSN, Night aos
;   10-dec-91, Updated, JRL, Added min_sun rule
;   13-jan-92, Updated, JRL, Added dsn_los_n/dsn_los_d
;   23-jan-92, Updated, JRL, Added dsn_switch
;   14-jun-94, JRL, Added saa_med_rate, saa_min_time
;    3-feb-96, JRL, Added aaos_ant_ab
;-

a = {op_rules_d, a: 0., b: ' '}
op_rules = {op_rules, 	AOS_d: {op_rules_d},		$ ;0
			AOS_n:  {op_rules_d},  		$ ;1
			LOS:    {op_rules_d},  		$ ;2
                      	RB_ON: {op_rules_d},		$ ;3
			RB_OFF: {op_rules_d},  		$ ;4
			DAY:   {op_rules_d},		$ ;5
			NIGHT:  {op_rules_d},  		$ ;6
			AN_EL: {op_rules_d},		$ ;7
			NOP_bef:   {op_rules_d},	$ ;8
			NOP_after: {op_rules_d}, 	$ ;9
			VALID:     {op_rules_d}, 	$ ;10
			AN_EL_DSN:{op_rules_d},		$ ;11
			VALID_DSN: {op_rules_d}, 	$ ;12
			dsn_rep_d: {op_rules_d}, 	$ ;13
			dsn_rep_n: {op_rules_d}, 	$ ;14
			dsn_los_d: {op_rules_d}, 	$ ;15
			dsn_los_n: {op_rules_d}, 	$ ;16
			dsn_switch: {op_rules_d}, 	$ ;17
			dsn_time: {op_rules_d},		$ ;18
			min_sun:   {op_rules_d},	$ ;19
			saa_med_rate: {op_rules_d},	$ ;20
			saa_min_time: {op_rules_d},	$ ;21
			aos_ant_ab: {op_rules_d} }	  ;22

openr,lun,filein,/get_lun
while not eof(lun) do begin
   str = '' & readf,lun,str,format='(a)'
   str = strtrim(str,2)
   if strmid(str,0,1) ne ';' then begin		; Ignore if preceeded by ';'

;  Convert single quotes to "
     while strpos(str,"'") ne -1 do strput,str,'"',strpos(str,"'")

;  Parse the comment (should appear between " ")
     str_comment = strmid(str,strpos(str,'"')+1,strlen(str))
     str_comment = strmid(str_comment,0,strpos(str_comment,'"'))		
     str = strtrim(strmid(str,0,strpos(str,'"')),2)	; Remove the comment

;  Get the lookup index and corresponding value and comment 
     a_ind = fix(str) 					; op_first_guess index
     val   = float(strmid(str,strpos(str,' '),strlen(str)))

;  Equate to structure variable
     op_rules.(a_ind).a = val
     op_rules.(a_ind).b = str_comment
   endif
endwhile

free_lun,lun
return,op_rules
end
