
	pro pic_plot_load, array, file

common pic_plot,ID,Data,a,d,trace,Datado



	CASE 1 OF

n_tags(Data) le 1: file=pickfile(/read,filt='*.gif')

Data.file eq '': file=pickfile(/read,filt='*.gif')

ELSE:	file=pickfile(/read,filt='*.gif',file=Data.file, path=subdir(Data.file))

	ENDCASE

if file eq '' then return

widget_control,/hour

	read_gif,file,array

array=bytscl(array)

	end



	pro pic_plot_event,ev
common pic_plot,ID,Data,a,d,trace,Datado
	CASE !version.OS OF

'windows':	color=255

'Win32':	color=255

ELSE:		color=127

	ENDCASE


Sz=size(Data.array)

	CASE ev.id OF

ID.Draw(0):	begin
wset,ID.Win(0)

if n_elements(Data.array) lt 1000 then return
widget_control,ID.Label(0),set_val=string(ev.x,ev.y,format="(i4,',  ',i4)")

device,/cursor_cross

	if ev.press then Data.press=1
	if ev.release then Data.press=0

	IF Data.press THEN BEGIN
device,set_gr=6

	if Data.New eq 0 then begin

plots, [0,Sz(1)-1],[1,1]*Data.xy(1),/dev, col=color
plots, [1,1]*Data.xy(0),[0,Sz(2)-1],/dev, col=color

	endif

Data.New=0

Data.xy=[ev.x, ev.y]

plots, [0,Sz(1)-1],[1,1]*Data.xy(1),/dev, col=color
plots, [1,1]*Data.xy(0),[0,Sz(2)-1],/dev, col=color

device,set_gr=3
	ENDIF

return
		end


ID.Draw(1):	begin
wset,ID.Win(1)


if id.Mode eq 'Mark' then begin

	CASE ID.Select_Mode OF

'Box':	begin

	tmp=a.a
w_box_cursor,ev,xy,init=a.init,cur=tmp
	a.a=tmp

a.init=0
a.xy=xy
	end

'Trace':	begin

if ev.press then ID.press=1
if ev.release then ID.press=0

if ID.press eq 0 then return

if n_elements(trace) eq 1 then trace=[ev.x, ev.y] else begin

trace=[[trace], [ev.x, ev.y]]

Sz_tr=size(trace)

plots,trace(0,Sz_tr(2)-[1,2]), trace(1,Sz_tr(2)-[1,2]), /dev,col=100

empty

endelse

		end
ELSE: begin
tmp=a.a
w_box_cursor,ev,xy,init=a.init,cur=tmp
a.a=tmp
a.init=0
a.xy=xy
end
ENDCASE
eNDIF

if n_elements(Data.array) lt 1000 then return
widget_control,ID.Label(1),set_val=string(ev.x,ev.y,format="(i4,',  ',i4)")

return
		end


ID.Draw(2):	begin

window_set,ID.Win(2),sc=Data.Sc

device,/cursor_cross

xy=convert_coord(ev.x, ev.y, /dev, /to_data)

if n_elements(Data.array) lt 1000 then return

if Data.Calibrated ne 0 and Data.type eq 'UT' then $

widget_control,ID.Label(2),set_val=	$
	smh(xy(0), ms=1)+',  '+	string(xy(1), format="(g10.4)") $

	else widget_control,ID.Label(2),set_val=string(xy(0),xy(1),	$
		format="(g10.4,',  ',g10.4)")

device,/cursor_cross

return
		end

ELSE:
	ENDCASE


widget_control,ev.id,get_uval=uv

	CASE uv OF
"Box":		begin
	ID.Mode='Mark'
	ID.Select_Mode='Box'
		end

"Trace":	begin

	ID.Mode='Mark'
	ID.Select_Mode='Trace'
	trace=0

		end

"DONE":	begin

device,/cursor_cross
widget_control,ev.top,/destroy
	end
"Help":begin

	CASE !version.OS OF

'windows':	Delim='\'

'Win32':	Delim='\'

ELSE:		Delim='/'

	ENDCASE

s=findfile(getenv('help_dir')+Delim+'fpicplot.hlp')
IF (s(0) EQ '') then return else xtext,file=getenv('help_dir')+Delim+'fpicplot.hlp',group=ev.top

		end

"Load": begin

pic_plot_load, array, file
if file eq '' then return
widget_control,/hour

	for j=0,2 do begin
widget_control,ID.Draw_base(j),map=([1,0,0])(j)
wset,ID.Win(j)
erase
	endfor

wset,ID.Win(0)
erase
tvscl,array

Sz=size(array)

wset,ID.Win(1)
erase
device,copy=[0,0,Sz(1),Sz(2),0,0,ID.Win(0)]


Data={file:file, array_e:array, array:array, calibrated:0,	$
	Sc:Data.Sc, Undo:'', type:data.type, xy:Data.xy, press:Data.press, $
	x0:Data.x0, x1:Data.x1, x0_d:Data.x0_d, x1_d:Data.x1_d, New:1, Counter:Data.Counter }

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
;--
empty
	end

"Loade": begin

arrayn=Data.array
CASE 1 OF

n_tags(Data) le 1: file=pickfile(/read,filt='*.sav')

Data.file eq '': file=pickfile(/read,filt='*.sav')

ELSE:	file=pickfile(/read,filt='*.sav', path=subdir(Data.file))

	ENDCASE

if file eq '' then return

widget_control,/hour

Restore,file
Data={file:Data.file, array_e:Data.array_e, array:arrayn, calibrated:Data.calibrated,	$
	Sc:Data.Sc, Undo:Data.Undo, type:data.type, xy:Data.xy, press:Data.press, $
	x0:Data.x0, x1:Data.x1, x0_d:Data.x0_d, x1_d:Data.x1_d, New:Data.New, Counter:Data.Counter }

array = arrayn
array_e=Data.array_e

widget_control,/hour

	for j=0,2 do begin
widget_control,ID.Draw_base(j),map=([1,0,0])(j)
wset,ID.Win(j)
erase
	endfor

wset,ID.Win(0)
erase
tvscl,Data.array

wset,ID.Win(1)
erase
tvscl,Data.array_e

Sz=size(array)

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)

empty

	end


"Save":		begin

	CASE !version.OS OF

'windows':	Delim='\'

'Win32':	Delim='\'

ELSE:		Delim='/'

	ENDCASE

path=subdir(Data.file)

New_file=path+Delim+	$
	newfilename(model=(name_extract(Data.file))(1),filt='*.dig')

	file=pickfile(/read,filt='*.dig',file=New_file, path=path)

if file eq '' then return
widget_control,/hour

	openw,lun,file,/get_lun
writeu,lun,Data.x, Data.y
	free_lun,lun

		end

"SaveE":		begin

	CASE !version.OS OF

'windows':	Delim='\'

'Win32':	Delim='\'

ELSE:		Delim='/'

	ENDCASE

path=subdir(Data.file)

New_file=path+Delim+	$
	newfilename(model=(name_extract(Data.file))(1),filt='*.sav')

	file=pickfile(/read,filt='*.sav',file=New_file, path=path)

if file eq '' then return
widget_control,/hour

save,Data,a,filename=new_file
		end


"Initial":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([1,0,0])(j)
wset,ID.Win(0)
widget_control,ID.InputX0,/input_focus

		end

"Edited":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
		end

"Converted":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)
wset,ID.Win(2)
		end

"Outside":	begin

	CASE ID.Select_Mode OF

'Trace': begin
SzT=size(TRACE)
V_x=[transpose(trace(0,*)), trace(0,0)]
V_y=[transpose(trace(1,*)), trace(1,0)]

;V_x=[transpose(trace(0,*) < (SzT(1)-1)>0 ), trace(0,0)]
;V_y=[transpose(trace(1,*) < (SzT(1)-1)>0 ), trace(1,0)]

trace=0

Szx=size(Data.array)
factor=float(!d.x_size)/Szx(1)
Dataf=Data.array_e

AP=polyfillv(V_x/factor, V_y/factor, !d.x_size/factor, !d.y_size/factor)
SzAp=size(AP)
IF SzAP(0) eq 0 then return

Dataf(polyfillv(V_x/factor, V_y/factor, !d.x_size/factor, !d.y_size/factor))=255b
indd=where(Dataf ne 255b)

widget_control,/hour

Data.array_e(indd)=255b
;-----

a.init=1

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross

Data.Undo=uv

end

'Box':	begin

Data.array=Data.array_e

widget_control,/hour

Sz=size(Data.array)

Data.array_e(0:a.xy(0,0) < (Sz(1)-1) > 0,*)=255b
Data.array_e(a.xy(1,0) < (Sz(1)-1) > 0:*,*)=255b
Data.array_e(*,0:a.xy(0,1) < (Sz(2)-1) > 0)=255b
Data.array_e(*,a.xy(1,1) < (Sz(2)-1) > 0:*)=255b

a.init=1

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross
Data.Undo=uv
		end

endcase
end

"Cut":	begin

	CASE ID.Select_Mode OF

'Trace': begin

Datado=Data.array_e

V_x=[transpose(trace(0,*)), trace(0,0)]
V_y=[transpose(trace(1,*)), trace(1,0)]
trace=0

Szx=size(Data.array)
factor=float(!d.x_size)/Szx(1)

AP=polyfillv(V_x/factor, V_y/factor, !d.x_size/factor, !d.y_size/factor)
SzAp=size(AP)
IF SzAP(0) eq 0 then return

Data.array_e(polyfillv(V_x/factor, V_y/factor, !d.x_size/factor, !d.y_size/factor))=255b

wset,ID.Win(1)

empty
;-----
a.init=1

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross

Data.Undo=uv

end

'Box':	begin
Data.array=Data.array_e

widget_control,/hour
Sz=size(Data.array)

Data.array_e(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)=255b

a.init=1

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross

Data.Undo=uv
end
ELSE: RETURN
ENDCASE
		end

"Invert":	begin

Data.array=Data.array_e

widget_control,/hour
Sz=size(Data.array)

Data.array_e(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)=		$
255b-Data.array_e(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)
a.init=1

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross

Data.Undo=uv

		end

"Invert_all":	begin

Data.array=Data.array_e

widget_control,/hour

Data.array_e=255b-Data.array_e

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)

wset,ID.Win(1)
tvscl,Data.array_e
empty

device,/cursor_cross

Data.Undo=uv

		end


"Convert":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)

widget_control,/hour
;mode 0-low,1-mean,2- high
mode=1.0
pic_dig,Data.array_e,x,y,mode

wset,ID.Win(2)
plot, x, y, col=0, back=!d.n_colors-1,/yno, /xst
scale,temp,/mem

Data={file:Data.file, calibrated:Data.calibrated,			$
	array_e:Data.array_e, array:Data.array,				$
	Sc:Data.Sc, Undo:Data.Undo, type:Data.type, xy:Data.xy, 	$
	press:Data.press, x0:Data.x0, x1:Data.x1, x:x, y:y, 		$
	x0_d:Data.x0_d, x1_d:Data.x1_d, New:Data.New, Counter:Data.Counter}

array=0


Data.Sc=temp
empty
device,/cursor_cross

widget_control, ID.InputX0, sens=1
widget_control, ID.InputX1, sens=1
widget_control, ID.InputY0, sens=1
widget_control, ID.InputY1, sens=1

widget_control,Id.info,set_val='Move to mode "Initial Image" and input coordinates x,y'
		end


"Convertl":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)

widget_control,/hour
;mode 0-low,1-mean,2- high
mode=0.0
pic_dig,Data.array_e,x,y,mode

wset,ID.Win(2)

plot, x, y, col=0, back=!d.n_colors-1,/yno, /xst
scale,temp,/mem

Data={file:Data.file, calibrated:Data.calibrated,			$
	array_e:Data.array_e, array:Data.array,				$
	Sc:Data.Sc, Undo:Data.Undo, type:Data.type, xy:Data.xy, 	$
	press:Data.press, x0:Data.x0, x1:Data.x1, x:x, y:y, 		$
	x0_d:Data.x0_d, x1_d:Data.x1_d, New:Data.New, Counter:Data.Counter}

array=0


Data.Sc=temp
empty
device,/cursor_cross

widget_control, ID.InputX0, sens=1
widget_control, ID.InputX1, sens=1
widget_control, ID.InputY0, sens=1
widget_control, ID.InputY1, sens=1

widget_control,Id.info,set_val='Move to mode "Initial Image" and input coordinates x,y'
		end

"Converth":	begin

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)

widget_control,/hour
;mode 0-low,1-mean,2- high
mode=2.0
pic_dig,Data.array_e,x,y,mode

wset,ID.Win(2)

plot, x, y, col=0, back=!d.n_colors-1,/yno, /xst
scale,temp,/mem

Data={file:Data.file, calibrated:Data.calibrated,			$
	array_e:Data.array_e, array:Data.array,				$
	Sc:Data.Sc, Undo:Data.Undo, type:Data.type, xy:Data.xy, 	$
	press:Data.press, x0:Data.x0, x1:Data.x1, x:x, y:y, 		$
	x0_d:Data.x0_d, x1_d:Data.x1_d, New:Data.New, Counter:Data.Counter}

array=0


Data.Sc=temp
empty
device,/cursor_cross

widget_control, ID.InputX0, sens=1
widget_control, ID.InputX1, sens=1
widget_control, ID.InputY0, sens=1
widget_control, ID.InputY1, sens=1

widget_control,Id.info,set_val='Move to mode "Initial Image" and input coordinates x,y'
		end




"x0":		begin
widget_control,ID.InputX0,get_val=tmp
Data.x0(0)=strtrim(tmp(0),2)
Data.x0_d=Data.xy
widget_control,ID.InputY0,/input_focus
Data.Counter=Data.Counter+1

	if Data.Counter eq 4 then begin
widget_control, ID.Calibrate, sens=1
widget_control, ID.Calibratex, sens=1
widget_control, ID.Calibratey, sens=1
widget_control, ID.Calibratexy, sens=1
widget_control,Id.info,set_val='Choose sort of calibration and move to corresponding mode'
Data.Counter=0
	endif
		end


"y0":		begin
widget_control,ID.InputY0,get_val=tmp
Data.x0(1)=strtrim(tmp(0),2)
Data.x0_d=Data.xy
widget_control,ID.InputX1,/input_focus
Data.Counter=Data.Counter+1
	if Data.Counter eq 4 then begin
widget_control, ID.Calibrate, sens=1
widget_control, ID.Calibratex, sens=1
widget_control, ID.Calibratey, sens=1
widget_control, ID.Calibratexy, sens=1
widget_control,Id.info,set_val='Choose sort of calibration and move to corresponding mode'
Data.Counter=0
	endif
		end


"x1":		begin
widget_control,ID.InputX1,get_val=tmp
Data.x1(0)=strtrim(tmp(0),2)
Data.x1_d=Data.xy
widget_control,ID.InputY1,/input_focus
Data.Counter=Data.Counter+1
	if Data.Counter eq 4 then begin
widget_control, ID.Calibrate, sens=1
widget_control, ID.Calibratex, sens=1
widget_control, ID.Calibratey, sens=1
widget_control, ID.Calibratexy, sens=1
widget_control,Id.info,set_val='Choose sort of calibration and move to corresponding mode'
Data.Counter=0
	endif
		end

"y1":		begin
widget_control,ID.InputY1,get_val=tmp
Data.x1(1)=strtrim(tmp(0),2)
Data.x1_d=Data.xy
Data.Counter=Data.Counter+1
	if Data.Counter eq 4 then begin
widget_control, ID.Calibrate, sens=1
widget_control, ID.Calibratex, sens=1
widget_control, ID.Calibratey, sens=1
widget_control, ID.Calibratexy, sens=1
widget_control,Id.info,set_val='Choose sort of calibration and move to corresponding mode'
Data.Counter=0
	endif
		end

"Calibrate":	begin

if strpos(Data.X0(0),':') lt 0 and strpos(Data.X0(0),' ') lt 0 then	$
	x0=float(Data.X0(0)) else begin
	x0=hms(Data.X0(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X0(1),':') lt 0 and strpos(Data.X0(1),' ') lt 0 then	$
	y0=float(Data.X0(1)) else begin
	y0=hms(Data.X0(1))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(0),':') lt 0 and strpos(Data.X1(0),' ') lt 0 then	$
	x1=float(Data.X1(0)) else begin
	x1=hms(Data.X1(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(1),':') lt 0 and strpos(Data.X1(1),' ') lt 0 then	$
	y1=float(Data.X1(1)) else y1=hms(Data.X1(1))*3600d0


Data.x=(Data.x-Data.x0_d(0))/(Data.x1_d(0)-Data.x0_d(0))*(x1-x0)+x0
Data.y=(Data.y-Data.x0_d(1))/(Data.x1_d(1)-Data.x0_d(1))*(y1-y0)+y0


for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)

widget_control,/hour
wset,ID.Win(2)

if Data.type eq 'UT' then xtickform='t_ticks0' else xtickform=''

plot, Data.x, Data.y, col=0, back=!d.n_colors-1, /yno, xtickf=xtickform, /xst

Data.calibrated=1

scale,temp,/mem

Data.Sc=temp
empty
device,/cursor_cross

		end
"Calibratexy":	begin

if strpos(Data.X0(0),':') lt 0 and strpos(Data.X0(0),' ') lt 0 then	$
	x0=float(Data.X0(0)) else begin
	x0=hms(Data.X0(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X0(1),':') lt 0 and strpos(Data.X0(1),' ') lt 0 then	$
	y0=float(Data.X0(1)) else begin
	y0=hms(Data.X0(1))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(0),':') lt 0 and strpos(Data.X1(0),' ') lt 0 then	$
	x1=float(Data.X1(0)) else begin
	x1=hms(Data.X1(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(1),':') lt 0 and strpos(Data.X1(1),' ') lt 0 then	$
	y1=float(Data.X1(1)) else y1=hms(Data.X1(1))*3600d0

	if x0 le 0 or x1 le 0 or y0 le 0 or y1 le 0 then begin

 widget_control,Id.info,set_val='x,y must be greater 0,input x and y again'

return
	endif

x1=alog10(x1)
x0=alog10(x0)

y1=alog10(y1)
y0=alog10(y0)

	  if (Data.x1_d(0) eq Data.x0_d(0))$
	             or (Data.x1_d(1) eq Data.x0_d(1))$
	             or (x1 eq x0) or (y1 eq y0) then begin

 widget_control,Id.info,set_val='x,y must be greater 0,input x and y again'


return
end
Data.x=10^((Data.x-Data.x0_d(0))/(Data.x1_d(0)-Data.x0_d(0))*(x1-x0)+x0)
Data.y=10^((Data.y-Data.x0_d(1))/(Data.x1_d(1)-Data.x0_d(1))*(y1-y0)+y0)

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)
widget_control,Id.info,set_val=''
widget_control,/hour
wset,ID.Win(2)

plot, Data.x, Data.y, col=0, back=!d.n_colors-1, /yno,  /xst,yty=1,xty=1
Data.calibrated=1

scale,temp,/mem

Data.Sc=temp
empty
device,/cursor_cross

		end

"Calibratey":	begin

if strpos(Data.X0(0),':') lt 0 and strpos(Data.X0(0),' ') lt 0 then	$
	x0=float(Data.X0(0)) else begin
	x0=hms(Data.X0(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X0(1),':') lt 0 and strpos(Data.X0(1),' ') lt 0 then	$
	y0=float(Data.X0(1)) else begin
	y0=hms(Data.X0(1))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(0),':') lt 0 and strpos(Data.X1(0),' ') lt 0 then	$
	x1=float(Data.X1(0)) else begin
	x1=hms(Data.X1(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(1),':') lt 0 and strpos(Data.X1(1),' ') lt 0 then	$
	y1=float(Data.X1(1)) else y1=hms(Data.X1(1))*3600d0

	if y0 le 0 or y1 le 0 then begin

 widget_control,Id.info,set_val='y must be greater 0,input y again'
return
	endif

y1=alog10(y1)
y0=alog10(y0)

	  if (Data.x1_d(0) eq Data.x0_d(0))$
	             or (Data.x1_d(1) eq Data.x0_d(1))$
	             or (x1 eq x0) or (y1 eq y0) then begin

 widget_control,Id.info,set_val='x,y is incorrect,input x and y again'


return
end
Data.x=(Data.x-Data.x0_d(0))/(Data.x1_d(0)-Data.x0_d(0))*(x1-x0)+x0
Data.y=10^((Data.y-Data.x0_d(1))/(Data.x1_d(1)-Data.x0_d(1))*(y1-y0)+y0)


for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)
widget_control,Id.info,set_val=''
widget_control,/hour
wset,ID.Win(2)

plot, Data.x, Data.y, col=0, back=!d.n_colors-1, /yno,  /xst,yty=1;,xty=1
Data.calibrated=1

scale,temp,/mem

Data.Sc=temp
empty
device,/cursor_cross

		end

"Calibratex":	begin

if strpos(Data.X0(0),':') lt 0 and strpos(Data.X0(0),' ') lt 0 then	$
	x0=float(Data.X0(0)) else begin
	x0=hms(Data.X0(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X0(1),':') lt 0 and strpos(Data.X0(1),' ') lt 0 then	$
	y0=float(Data.X0(1)) else begin
	y0=hms(Data.X0(1))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(0),':') lt 0 and strpos(Data.X1(0),' ') lt 0 then	$
	x1=float(Data.X1(0)) else begin
	x1=hms(Data.X1(0))*3600d0
	Data.type='UT'
	endelse

if strpos(Data.X1(1),':') lt 0 and strpos(Data.X1(1),' ') lt 0 then	$
	y1=float(Data.X1(1)) else y1=hms(Data.X1(1))*3600d0

	if x0 le 0 or x1 le 0 then begin

 widget_control,Id.info,set_val='x must be greater 0,input x again'
return
	endif

x1=alog10(x1)
x0=alog10(x0)


	  if (Data.x1_d(0) eq Data.x0_d(0))$
	             or (Data.x1_d(1) eq Data.x0_d(1))$
	             or (x1 eq x0) or (y1 eq y0) then begin

 widget_control,Id.info,set_val='x,y incorrect,input x and y again'

return
end
Data.x=10^((Data.x-Data.x0_d(0))/(Data.x1_d(0)-Data.x0_d(0))*(x1-x0)+x0)
Data.y=(Data.y-Data.x0_d(1))/(Data.x1_d(1)-Data.x0_d(1))*(y1-y0)+y0


for j=0,2 do widget_control,ID.Draw_base(j),map=([0,0,1])(j)
widget_control,Id.info,set_val=''
widget_control,/hour
wset,ID.Win(2)

plot, Data.x, Data.y, col=0, back=!d.n_colors-1, /yno,  /xst,xty=1
Data.calibrated=1

scale,temp,/mem

Data.Sc=temp
empty
device,/cursor_cross

		end


"Undo":	begin

widget_control,/hour
Sz=size(Data.array)

	CASE Data.Undo OF

"Invert":	begin

tmp=Data.array_e
Data.array_e(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)=		$
255b-Data.array(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)

		end

"Cut":	begin;***

	CASE ID.Select_Mode OF

'Box': begin

tmp=Data.array_e

Data.array_e(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)=		$
Data.array(a.xy(0,0) < (Sz(1)-1) > 0:a.xy(1,0) < (Sz(1)-1) > 0,	$
	a.xy(0,1) < (Sz(2)-1) > 0:a.xy(1,1) < (Sz(2)-1) > 0)

		end
'Trace': begin
tmp=Data.array_e
Data.array_e=Datado


		end

endcase
end
"Outside":	begin

tmp=Data.array_e

Data.array_e(0:a.xy(0,0) < (Sz(1)-1) > 0,*)=		$
	Data.array(0:a.xy(0,0) < (Sz(1)-1) > 0,*)
Data.array_e(a.xy(1,0) < (Sz(1)-1) > 0:*,*)=		$
	Data.array(a.xy(1,0) < (Sz(1)-1) > 0:*,*)
Data.array_e(*,0:a.xy(0,1) < (Sz(2)-1) > 0)=		$
	Data.array(*,0:a.xy(0,1) < (Sz(2)-1) > 0)
Data.array_e(*,a.xy(1,1) < (Sz(2)-1) > 0:*)=		$
	Data.array(*,a.xy(1,1) < (Sz(2)-1) > 0:*)

		end

"Invert_all":	begin

tmp=Data.array_e
Data.array_e=255b-Data.array_e

		end


	ELSE:
	ENDCASE

Data.array=tmp

	for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)
wset,ID.Win(1)
tvscl,Data.array_e

empty
device,/cursor_cross

a.init=1

	end


ELSE:

	ENDCASE

	end


	pro pic_plot,group_leader=group_leader

common pic_plot,ID,Data,a,d,trace,Datado

if n_elements(group_leader) le 0 then group_leader=0L


ID={Draw:[0L,0L,0L], Win:[0L,0L,0L], draw_base:[0L,0L,0L],	$
 Mode:'Init',Mark:0L, Select_Mode:'Box',$
	g_leader:group_leader, Label:[0L,0L,0L], 		$
	Load:0L,Loade:0L, Convert:0L,Convertl:0L,Converth:0L,Calibrate:0L, Save:0L,Savee:0L,press:0,	$
	Cut:0L,	Invert_all:0L, Invert:0L, Outside:0L,		$
	Initial:0L, Edited:0L, Converted:0L,Calibratexy:0L,Calibratey:0L,Calibratex:0L,	$
	InputX0:0L, InputY0:0L, InputX1:0L, InputY1:0L,Info:0L}

pic_plot_load, array, file

if file eq '' then return

Data={file:file, array_e:array, 	$
	array:array, xy:fltarr(2),			$
	Sc:{Axes, x:!x, y:!y, z:!z, map:!map}, 			$
	Undo:'', type:'', press:0, calibrated:0,		$
	x0:strarr(2), x1:strarr(2),				$
	x0_d:fltarr(2), x1_d:fltarr(2), New:1, Counter:0,$
        factor:1., Triangle:fltarr(2,4), $;
	Attempt:0, Max:0., Scaling:0, $;
	Plot_Mean:0., Plot_Min:0., Plot_Max:0., Plot_factor:1.}

bm_box= [		$
	[000B, 000B],	$
	[000B, 000B],	$
	[000B, 000B],	$
	[248B, 031B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[008B, 016B],	$
	[248B, 031B],	$
	[000B, 000B],	$
	[000B, 000B],	$
	[000B, 000B]	$
			]


bm_trace=	[	     	$
	[000B, 000B],	$
	[192B, 001B],	$
	[032B, 002B],	$
	[016B, 004B],	$
	[008B, 008B],	$
	[008B, 016B],	$
	[008B, 032B],	$
	[004B, 032B],	$
	[004B, 032B],	$
	[004B, 032B],	$
	[004B, 016B],	$
	[004B, 008B],	$
	[008B, 008B],	$
	[112B, 008B],	$
	[128B, 007B],	$
	[000B, 000B]	$
	]

init_structure={w_b_state,	$
	x:0, y:0, press:0, first:1, Xc:[0.,0.], Yc:[0.,0.],	$
	Output:intarr(2,2), stretch:0., move:0.}

a={init:1, xy:intarr(2,2), a:init_structure}

Sz=size(temporary(array))
base=widget_base(/colu,group=group_leader,	$
	tit='Converter of an image into array')

Menu_base=widget_base(base,/row)
Emptystring='                     '
Em=Emptystring+Emptystring+Emptystring

label_size=Em+Em
;if font ne '' then if fontsize le 16 then
label_size=label_size+Emptystring



junk=widget_button(Menu_base, val="DONE", uv="DONE")
junk=widget_button(Menu_base, val="File", /menu)
	ID.Load=widget_button(junk, val="Load", uv="Load")
	ID.Loade=widget_button(junk, val="Load Interim Image", uv="Loade")
	ID.Convert=widget_button(junk, val="Convert mean", uv="Convert")
ID.Convertl=widget_button(junk, val="Convert low", uv="Convertl")
ID.Converth=widget_button(junk, val="Convert high", uv="Converth")
	ID.Calibrate=widget_button(junk, val="Calibrate linear", uv="Calibrate")
	ID.Calibratexy=widget_button(junk, val="Calibrate Logarithmic (xy)", uv="Calibratexy")
	ID.Calibratex=widget_button(junk, val="Calibrate Logarithmic (x)", uv="Calibratex")
	ID.Calibratey=widget_button(junk, val="Calibrate Logarithmic (y)", uv="Calibratey")
	ID.Save=widget_button(junk, val="Save", uv="Save")
	ID.Savee=widget_button(junk, val="Save Interim Image", uv="SaveE")
junk=widget_button(Menu_base, val="Edit", /menu)
	ID.Cut=widget_button(junk, val="UNDO", uv="Undo")
	ID.Cut=widget_button(junk, val="Cut", uv="Cut")
	ID.Invert_all=widget_button(junk, val="Invert all", uv="Invert_all")
	ID.Invert=widget_button(junk, val="Invert", uv="Invert")
	ID.Outside=widget_button(junk, val="Erase outside", uv="Outside")
junk=widget_button(Menu_base,val="Window", /menu)
	junk1=widget_button(junk, val="Initial Image", uv='Initial')
	junk1=widget_button(junk, val="Edited Image", uv='Edited')
	junk1=widget_button(junk, val="Converted", uv="Converted")
junk=widget_button(Menu_base,val="Help", uv='Help')
Id.info=widget_label(Menu_base,val=label_size,/fra) ;!,font=font)
input_base=widget_base(base,/row)


;edit_base=widget_base(menu_base,/row)


junk=widget_label(input_base,val='x0')
ID.inputX0=widget_text(input_base,val=' ', xs=10, /edit, uval='x0', /frame)
junk=widget_label(input_base,val='y0')
ID.inputY0=widget_text(input_base,val=' ', xs=10, /edit, uval='y0', /frame)
junk=widget_label(input_base,val='x1')
ID.inputX1=widget_text(input_base,val=' ', xs=10, /edit, uval='x1', /frame)
junk=widget_label(input_base,val='y1')
ID.inputY1=widget_text(input_base,val=' ', xs=10, /edit, uval='y1', /frame)

button=widget_button(input_base, val=bm_box, uval='Box')
button=widget_button(input_base, val=bm_trace, uval='Trace')

widget_control, ID.InputX0, sens=0
widget_control, ID.InputX1, sens=0
widget_control, ID.InputY0, sens=0
widget_control, ID.InputY1, sens=0


device,get_scr=scr

Draw_size=[scr(0)*0.96,scr(1)*0.75]

Scroll=(Draw_size(0) le Sz(1)) or (Draw_size(1) le Sz(2))

Plain_base=widget_base(base)

	for j=0,2 do begin

ID.Draw_base(j)=widget_base(Plain_base,/colu)

if scroll then $

ID.draw(j)=widget_draw(ID.Draw_base(j), xs=Sz(1), ys=Sz(2), $
	uv='Window'+strtrim(j,2), /motion, /button, /fra, /scroll, $
	x_scroll=Draw_size(0), y_scroll=Draw_size(1)) else $

ID.draw(j)=widget_draw(ID.Draw_base(j), xs=Draw_size(0),ys=Draw_size(1), $
	uv='Window'+strtrim(j,2), /motion, /button, /fra)

junk=widget_base(ID.Draw_base(j),/row)

Label=widget_label(junk, val=(['Initial','Edited','Converted'])(j)+'  ')
ID.Label(j)=widget_label(junk, /fra, val=' ',xs=Draw_size(0)-100)
	endfor

for j=0,2 do widget_control,ID.Draw_base(j),map=([1,0,0])(j)

widget_control, ID.Calibrate, sens=0
widget_control, ID.Calibratex, sens=0
widget_control, ID.Calibratey, sens=0
widget_control, ID.Calibratexy, sens=0


widget_control,base,/real,/hour

widget_control, Id.info, set_val='Choose mode drawing and take away spare lines and do "File"-"Convert"'

	for j=0,2 do begin

widget_control,ID.draw(j),get_val=tmp
ID.Win(j)=tmp
wset, tmp
tvscl,data.array

	endfor
wset,ID.Win(2)
plot,indgen(10),/nod,xst=4,yst=4, /noer
scale,temp,/mem
Data.Sc=temp

wset,ID.Win(1)

for j=0,2 do widget_control,ID.Draw_base(j),map=([0,1,0])(j)

empty


xmanager,'pic_plot',base,group=group_leader
	end