Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/check_subimage.pro'
;+
; NAME:
;	Check_Subimage
; PURPOSE:
;	Check for existence, save-status, or display of subimage.
;	If needed, force appropriate event to occur.
;	Called by Analyze_Event if EFFICIENCY/SCATTER measurement was selected.
; CALLING:
;	status = Check_Subimage( uval )
; INPUT:
;	uval = string, the task to be performed on subimage.
; OUTPUT:
;	Function returns subimage status: 1 = OK to proceed, 0 = do not proceed.
; EXTERNAL CALLS:
;	pro Force_Events
; HISTORY:
;	written: Frank Varosi HSTX/NASA/GSFC 1994.
;-

function Check_Subimage, uval

   common Analyze_Image, analyze_widget
   common opticon1, subimage, subhead, subhist

	if N_struct( subhead ) NE 1 then begin
		message,"first EXTRACT subregion" + string(7b),/INFO
		Force_Events, analyze_widget.wmap, "EXTRACT sub-image"
		return,0
	   endif

	if (uval EQ "FLAT") then return,1

	if ( strlen( subhead.filename ) LE 0 ) OR $
	   ( ( strpos( subhead.filename, "(" ) EQ 0 ) AND $
	     ( strpos( subhead.filename, ")" ) GT 0 ) ) then begin
		message,"first STORE the new subimage" + string(7b),/INFO
		Force_Events, analyze_widget.wmap, "STORE sub-image"
		return,0
	   endif

	if (uval EQ "EFFIC") AND (analyze_widget.imspec(1).rescale) then begin
		Force_Events, analyze_widget.wmap, $
				["DISPLAY sub-image", "EFFICIENCY" ]
		return,0
	   endif

	if (uval EQ "SCATTER") AND (analyze_widget.imspec(1).rescale) then begin
		Force_Events, analyze_widget.wmap, $
				["DISPLAY sub-image", "SCATTER" ]
		return,0
	   endif

return,1
end