Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/export_import.pro'
;+
; NAME:
;	export_import
; PURPOSE:
;	Transfer (add/replace) images from PREProcess inventory structures
;	to TOFU image_List (TUT_images) structures.
; CALLING:
;	export_import, image_List, image_inven
;
; INPUTS & OUTPUTS:
;	image_List =
;	image_inven =
; EXTERNAL CALLS:
;	function check_struct
;	function N_struct
;	function merge_images
;	pro organize_images
;	pro Tofu_Task
; COMMON BLOCKS:
;	common control, cur_pro, win_mos, win_prep
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1989.
;	Mod for TOFU: F.V.1996.
;-

pro export_import, image_List, image_inven

  common control, cur_pro, win_mos, win_prep

	Nim_inv = check_struct( image_inven, Magf_inv )
	Nim_iml = N_struct( image_List )

	CASE cur_pro OF
		"PREProcess":	trade = "export"
		"TOFU": 	trade = "import"
		else:		trade = "export/import"
	 ENDCASE

	if (Nim_iml GT 0) then begin

		menu =[ " "				,$
			"Add to current images"		,$
			"Replace current images"	,$
			"Abort this "+trade+" operation"]

		sel = wmenu( menu, TIT=0, INIT=1 )
		task = next_word( menu(sel) )
		if (task EQ "Abort") then return

	  endif else task = "Replace"

	if (Nim_inv GT 0) then begin

			menu = [trade+" from inventory by:"	,$
				"select images individually"	,$
				"Lasso images with rubber-box"	,$
				"All images"			]

			sel = wmenu( menu, INIT=2, TIT=0 )
			if (sel LT 1) then return
			how = next_word( menu(sel) )

			CASE how OF
			"select": inums = select_images( image_inven,/MARK )
			"Lasso":  inums = Lasso_images( image_inven, /MARK )
			"All":	  inums = indgen( N_elements( image_inven ) )
			ENDCASE

			if (inums(0) LT 0) then return

			iml = image_inven(inums)
			iml(*).windo = win_mos
			name = strmid( iml(0).winame, 11,99 )

	 endif else BEGIN
			print," nothing to " + trade
			return
	  endelse

	CASE task OF

	    "Add": BEGIN
			iml(*).winame = name
			image_List = merge_images( image_List, iml, /NEW )
			if N_struct(image_List) EQ $
			  (Nim_iml + N_struct(iml)) then success=1
			iml=0
		     END

	    "Replace": BEGIN
				iml(*).winame = "TUT images: " + name
				image_List = iml
				success=1
				iml=0
			 END
	ENDCASE

	if (cur_pro EQ "PREProcess") AND keyword_set( success ) then begin
		print," exported images from inventory to Analysis"
		print,"	goto Analysis to work with exported images"
	   endif

	if keyword_set( success ) then Tofu_Task, "resize","", image_List $
				else message,"failed",/INFO
end