;+
; NAME:
;	HIST_FIND
;
;
; PURPOSE:
;	Find whether an operation has been applied from the history
;	records. 
;
;
; CATEGORY:
;	UTILS
;
;
; CALLING SEQUENCE:
;	version = hist_find(process, history)
;
;
; INPUTS:
;	process	string	The process to look for (e.g. 'Large-scale
;			flatfields')
;	history	string	The history fields from the fits file
;			(extracted as found in the structure format).
;
; KEYWORD PARAMETERS:
;	boolean		If set, then only return a -1/0/1 code rather
;			than the version number.
;	line_break	If set, then the value lies on the next line,
;			rather than on the end of the keyword line		
;
;
; OUTPUTS:
;	version	int/float/bool	The version number of presence flag
;				for the process requested. Note: -1
;				indicates the process was not found at all.
;
;
; MODIFICATION HISTORY:
;	Original: 24/3/03; SJT
;	Added line_break key and allow "none" as a synonym for "not
;	applied": 20/10/03; SJT
;	Better type checking: 21/10/03; SJT
;-


function hist_find, process, history, boolean = boolean, line_break = line_break

aninteger = '^[+-]?[0-9]+$'
anumber = '^[+-]?[0-9]*\.?[0-9]*([eEdD][+-]?[0-9]+)?$'

locs = where(strpos(strlowcase(history), strlowcase(process)) eq 0, $
             nm)
if nm eq 0 then return, -1

if keyword_set(line_break) then fline = history[locs[0]+1] $
else fline = history[locs[0]]
not_applied = strpos(fline, 'not applied') ne -1
if not_applied then return, 0

if keyword_set(boolean) then return, 1

lsp = strpos(fline, ' ', /reverse_search)
vs = strmid(fline, lsp+1, strlen(fline)-lsp)
if stregex(vs, aninteger, /bool) then return, fix(vs) $
else if stregex(vs, anumber, /bool) then return, float(vs) $
else return, vs


end
