;**********************************************************************
PRO CONT,smooth=smooth,calibration=calibration,swap=swap
;**********************************************************************

;----------------------------------------------------------------------
;	PURPOSE: Draw the contour of Longitudinal Magnetogram
;			of Huairou Solar Observation Station
;----------------------------------------------------------------------
;	KEYWORDS:
;		smooth: mode to smooth the raw data, default=4 pixels
;		calibration: calib. coefficient, default=2000.
;		swap: the high-low 8-bit conversion
;----------------------------------------------------------------------

;----------------------------------------------------------------------
;	Default:
		if n_elements(smooth) eq 0 then smooth=4
		if n_elements(calibration) eq 0 then calibration=2000.
		if n_elements(swap) eq 0 then swap=0	
		calibration=1000./calibration

;----------------------------------------------------------------------
;	Modification:
;		Sep.26, 1997, DASOP, by Deng Y. Y.
;		Nov.14, 1997, DASOP, by DYY
;----------------------------------------------------------------------


;----------------------------------------------------------------------
;	Read Longitudinal Magneogram And Preprocess It
;----------------------------------------------------------------------
filename=pickfile(filter='l*.dat')
if (swap eq 0) then begin
read_hr,filename,dat,hdr
endif else begin
read_hr,filename,dat,hdr,swap=swap
endelse

dat=dat*calibration
limit=2880.
dat=smooth(dat,smooth)
;dat(0:15,*)=0.

factor=5.23/3.63
len=strlen(filename)

print,''
PRINT,'------------------ Useful information ------------------'
PRINT,'	Filename:		'+strmid(filename,len-12,12)
Print,'	Obs. Date:		'+hdr(1)
print,'	     Time:		'+hdr(2)
print,'	Seeing:			'+hdr(3)
print,'	Wavelength:		'+hdr(0)
print,'	Integrated frames:	'+hdr(10)
xpos=strcompress(hdr(4),/remove_all)
if xpos le 0 then begin 
strput,xpos,'S',0
endif else begin
xpos='N'+xpos
endelse
ypos=strcompress(hdr(5),/remove_all)
if ypos le 0 then begin 
strput,ypos,'E',0
endif else begin
ypos='W'+ypos
endelse
print,'	Disk coordinate:	'+xpos+', '+ypos
print,'--------------------------------------------------------'
print,''

;----------------------------------------------------------------------
window,xsize=512*factor,ysize=512

!p.position=[0.,0.,1.,1.]
tvscl,congrid(dat,512*factor,512,/interp)>(-limit)<limit

;----------------------------------------------------------------------
;	Choose Contour Level	
;----------------------------------------------------------------------
;vi=[10.,20.,40.,100.,300.,500.,800.,1200.,1600.,2000.,2400.,2800.]
vi=[10.,20.,40.,80.,160.,320.,640.,960.,1280.,1600.,1920.,2240.,2560.,2880.]
option1=wmenu(['Which Lowest Contour-level Do You Want','10 Gauss ?','20 Gauss ?', 'or 40 Gauss ?'])
	
CASE 1 of
	(option1 eq 1): begin
	vii=vi
	v=[-reverse(vii),vii]
	end

	(option1 eq 2): begin
	vii=vi(1:*)
	v=[-reverse(vii),vii]
	end

	(option1 eq 3): begin
	vii=vi(2:*)
	v=[-reverse(vii),vii]
	end

	else: stop
ENDCASE
;----------------------------------------------------------------------

dat1=congrid(dat,523/3,363/3,/interp)
 	contour,dat1,levels=v,c_linestyle=(v lt 0.),ticklen=0,$
		/noerase,xst=5,yst=5

;----------------------------------------------------------------------
;	Decide if Create Postscript File
;----------------------------------------------------------------------

option3=wmenu(['Do You Want to Create PS File?','Sure','No, Thanks'])


;----------------------------------------------------------------------
;	Create the PS File of Contour
;----------------------------------------------------------------------
if (option3 eq 1) then begin	
nn=strlen(filename)
strput,filename,'ps',nn-3
filename=strmid(filename,nn-12,11)
help,filename

set_plot,'ps'
device,filename=filename,/landscape,xsize=5.23*3.5,ysize=3.63*3.5,$
		xoffset=3.,bits_per_pixel=16

	contour,dat1,levels=v,c_linestyle=(v lt 0.),ticklen=0,$
		/noerase,xst=5,yst=5

x=findgen(174)
y=fltarr(174)+0.
oplot,x,y
oplot,x,y+120.
y=findgen(121)
x=fltarr(121)+0.
oplot,x,y
oplot,x+173.,y


xconst=1./float(174)
yconst=1./float(121)
xyouts,xconst*2.,yconst*160,size=2.6,'!6 HOSO Magnetogram: '+strupcase(filename),/normal
xyouts,xconst*20,yconst*145,size=1.2,'!6 Content: '+'Longitudinal Field',/normal
xyouts,xconst*20,yconst*140,size=1.2,'!6 Date:    '+hdr(1),/normal
xyouts,xconst*20,yconst*135,size=1.2,'!6 Time:    '+hdr(2)+'UT',/normal

xpos=strcompress(hdr(4),/remove_all)
if xpos le 0 then begin 
strput,xpos,'S',0
endif else begin
xpos='N'+xpos
endelse
ypos=strcompress(hdr(5),/remove_all)
if ypos le 0 then begin 
strput,ypos,'E',0
endif else begin
ypos='W'+ypos
endelse
help,xpos,ypos

xyouts,xconst*100,yconst*145,size=1.2,'!6 Disc Coordinate:  '+xpos+', '+ypos,/normal
xyouts,xconst*100,yconst*140,size=1.2,'!6 Integrated Frame: '+hdr(10),/normal
xyouts,xconst*100,yconst*135,size=1.2,'!6 Wave Length:      '+hdr(0),/normal

xyouts,xconst*1,yconst*122,size=1.3,'!6 FOV: 5.23 x 3.63 arcmin.',/normal

xyouts,xconst*185,yconst*100,size=1.2,'!6 N: Solid',/normal
xyouts,xconst*185,yconst*95,size=1.2,'!6 S: Dashed',/normal
xyouts,xconst*185,yconst*80,size=1.2,'!6 Level: Gauss',/normal
xyouts,xconst*190,yconst*70,size=1.,string(fix(vii(0))),/normal
xyouts,xconst*190,yconst*65,size=1.,string(fix(vii(1))),/normal
xyouts,xconst*190,yconst*60,size=1.,string(fix(vii(2))),/normal
xyouts,xconst*190,yconst*55,size=1.,string(fix(vii(3))),/normal
xyouts,xconst*190,yconst*50,size=1.,string(fix(vii(4))),/normal
xyouts,xconst*190,yconst*45,size=1.,string(fix(vii(5))),/normal
xyouts,xconst*190,yconst*40,size=1.,string(fix(vii(6))),/normal
xyouts,xconst*190,yconst*35,size=1.,string(fix(vii(7))),/normal
xyouts,xconst*190,yconst*30,size=1.,string(fix(vii(8))),/normal
xyouts,xconst*190,yconst*25,size=1.,string(fix(vii(9))),/normal

arrow,xconst*185,yconst*120,xconst*195,yconst*120,/normal
arrow,xconst*185,yconst*120,xconst*185,yconst*130,/normal
xyouts,xconst*181.5,yconst*133,size=1.2,'!6 N',/normal
xyouts,xconst*195,yconst*119,size=1.2,'!6 W',/normal


device,/close
set_plot,'x'

!p.position=0

endif
;----------------------------------------------------------------------

end


