Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/display_options.pro'
pro display_options, mosaic_specs, caller, changes

;Frank Varosi NASA/GSFC 1990.

   common menus, menu_window
   common contour_options, TickLen, bitspix
   common display_options, Magf_min, Magf_max
   common color_scale, csxpos, csypos, scale_window, colorbar, region

	BELL = string(7b)

	if N_struct( mosaic_specs ) LT 1 then begin

		message,"specification structure not initialized"+BELL,/INFO
		wait,1
		return

	  endif else if N_struct( mosaic_specs ) GT 1 then begin

	     wm = where( mosaic_specs.size_image(0) GT 0, Nmos )

	     if (Nmos GT 0) then begin

			w = where( [mosaic_specs(wm).display] NE "CONTOUR", nw )

			if (nw LE 0) then begin
				print," all mosaics in Contour mode..."
				print," alter display while in Contour..."
				return
			  endif else if (nw LT Nmos) then begin
				wm = wm(w)
				specs = mosaic_specs(wm)
				display_options, specs, caller, changes
				mosaic_specs(wm) = specs
				return
			   endif else begin
				print," setting display specifications for:"
				for i=0,nw-1 do print,$
				    strmid( mosaic_specs(wm(i)).winame, 0,10 ),$
						mosaic_specs(wm(i)).name
				wait,1
			    endelse

		  endif else begin

			message,"first restore a mosaic"+BELL,/INFO
			wait,1
			return
		   endelse
	   endif

	select = 4
	changes = ""
	if N_elements( bitspix ) NE 1 then bitspix = 5

	menu_options = ["Options for Display/Contour of Mosaics:",$
			" "					,$
			"return to main menu"			,$
			" "					,$
			"filter type"				,$
			"filter width"				,$
			"scaling options for image display"	,$
			"magnification for image display"	,$
			"color scale display (Yes/No) ?"	,$
			" "					]

	if N_elements( caller ) EQ 1 then begin

		menu_options(2) = "return to " + caller

		CASE strupcase( caller ) OF

		  "CONTOUR": BEGIN

			menu_options = [ menu_options(0:2)		      ,$
					" "				      ,$
					"Labeling of contour Levels"	      ,$
					"fraction of Levels to Reverse"	      ,$
					"smoother (spline) contour Lines ?"   ,$
					"contour Line thickness (on hardcopy)",$
					" "				      ,$
					"Rotation (orientation) of image"     ,$
					" "				      ,$
					"show contour Level info?"	      ,$
					"tick marks pointing in/out ?"	      ,$
					"number of grey Levels for hardcopy"   ]
			END

		  "PROFILE":	menu_options = menu_options(0:5)

		     else:
		  ENDCASE
	   endif

	wset, menu_window
	wshow, menu_window

MENU:	select = wmenu( menu_options, INIT=select, TITLE=0 )
	if (select LT 0) then return

	request = menu_options(select)
	task = next_word( request )
	changes = [changes,task]

	CASE task OF

	"filter": BEGIN

		what = next_word( request )

		CASE what OF

		"type": BEGIN
			menu = ["select filter for image display:"	,$
				"smooth"				,$
				"iterate smooth(3)"			,$
				"median filter"				,$
				"none"					]
			sel = wmenu( menu, INIT=1, TIT=0 ) > 1
			mosaic_specs.filter = next_word( menu(sel) )
		     END

		"width": BEGIN
			filter = mosaic_specs(0).filter
			fw = mosaic_specs(0).filt_width
			filt_width = select_number( filter+" Filter Width?", $
						    3,19,SKIP=1,/ZERO,INIT=fw )
			mosaic_specs.filt_width = filt_width
		     END
		ENDCASE
	     END

	"scaling": BEGIN
			menu = ["Select image scaling for display:"	,$
				"Linear scale from min to max"		,$
				"Log10 scale from min>0 to max"		,$
				"Histogram Equalization"		]

			sel = wmenu( menu, INIT=1, TITLE=0 ) > 1
			mosaic_specs.scaling = next_word( menu(sel) )

			if (mosaic_specs(0).scaling EQ "Log10") then begin
				if N_elements( minLog ) NE 1 then minLog = .1
				print," current default MIN for Logs =",minLog
				input = ""
				read," enter MINIMUM value >0 for Logs: ",input
				if (input NE "") then minLog = float( input )
				minLog = minLog > 1.e-3
				mosaic_specs.minLog = minLog
				print," will take Log of image values >",minLog
			   endif
		     END

	"magnification": BEGIN
			if N_elements( Magf_min ) NE 1 then Magf_min=1
			if N_elements( Magf_max ) NE 1 then Magf_max=9
			Magf = mosaic_specs(0).Magf
			mosaic_specs.Magf = $
				select_number( "Magnification ?", $
						Magf_min, Magf_max, INIT=Magf )
			END

	"Rotation": BEGIN
			Rin = mosaic_specs(0).Rotation
			Rotation = select_number( "Rotation ?", 0,3, INIT=Rin )
			Rdiff = Rotation - mosaic_specs.Rotation
			wd = where( [Rdiff MOD 2], ndiff )
			if (ndiff GT 0) then begin
				Arcs_Pix_RA = mosaic_specs(wd).RA_pix
				Arcs_Pix_DEC = mosaic_specs(wd).DEC_pix
				mosaic_specs(wd).RA_pix = Arcs_Pix_DEC
				mosaic_specs(wd).DEC_pix = Arcs_Pix_RA
			  endif
			mosaic_specs.Rotation = Rotation
		      END

	  "color": BEGIN
			answer = yes_no_menu( "display color scales" )

			if (answer EQ "NO") then begin

				csxpos = -1
				csypos = -1

				if N_elements( scale_window ) EQ 1 then begin
					if (scale_window GE 0) then begin
						wdelete, scale_window
						scale_window = -1
					   endif
				   endif

			  endif else begin
				csxpos = 600
				csypos = 90
			   endelse
		     END

	"contour":	mosaic_specs.contour.Cthick = $
				  select_number( "contour Line thickness",$
							2, 9, FACTOR=0.5, $
					INIT=2*mosaic_specs(0).contour.Cthick )

	"smoother":	mosaic_specs.contour.spline = $
				yes_no_menu( "use splines for contours",/BIN,$
					NO_DEF=mosaic_specs(0).contour.spline )

	"Labeling": BEGIN
			menu = ["consecutive contours"	,$
				"every other contour"	,$
				"No Labels"		]
			sel = ( wmenu( menu ) > 0 ) + 1

			if (sel LT 3) then begin

				w = where( mosaic_specs.contour.CLabels, NL )
				NL = select_number( "# contour Labels ?",$
								0,20, INIT=NL )
				if (NL GT 0) then begin
					NL = (NL*sel) < 30
			  		mosaic_specs.contour.CLabels(*)=0
					mosaic_specs.contour.CLabels = $
					    abs( ( indgen( NL ) MOD sel )-1 )
				   endif

			  endif else mosaic_specs.contour.CLabels(*)=0
		     END

	"fraction": BEGIN
			f = findgen(11)/10
			menu  = ["fraction to reverse color:", strtrim( f, 2 )]
			sel = wmenu( menu, TITLE=0, $
				     INIT=10*mosaic_specs.contour.Levfracrev+1 )
			if (sel LE 0) then goto,MENU
			Levfracrev = f(sel-1)
			menu =["reverse from...","Top (max) ?","Bottom (min) ?"]
			sel = wmenu( menu, INIT=1, TITLE=0 )
			if (sel EQ 2) then $
				mosaic_specs.contour.Levfracrev=-Levfracrev $
			   else mosaic_specs.contour.Levfracrev= Levfracrev
		     END

	   "show":	mosaic_specs.options.Levprint = $
				yes_no_menu( "show contour Level info",/BIN,$
				       NO_DEF=mosaic_specs(0).options.Levprint )

	   "tick": BEGIN
			menu  = ["direction of tick marks ?","INTO plot","OUT"]
			sel = wmenu( menu, INIT=1, TITLE=0 )
			if (sel LE 0) then goto,MENU
			tickdir = next_word( menu(sel) )
			CASE tickdir OF
			"INTO":		TickLen = .02
			"OUT":		TickLen = -.02
			ENDCASE
		     END

	 "number": BEGIN
			menu = [ "Hardcopy Grey Levels?"	,$
				strtrim( 2^(indgen(5)+1), 2 )	]
			sel = wmenu( menu, INIT=bitspix, TIT=0 )
			if (sel GT 0) then bitspix = sel
			print," bits per pixel = " + strtrim( bitspix, 2 )
		     END

	  "return":	return

	   else:

	ENDCASE

   goto,MENU
end