PRO hr_all_gif6701,filename,smooth=smooth,limit=limit,swap=swap

;---------------------------------------------------------------------
; PURPOSE:
;	create GIF files from raw data
;
;INPUT:
;	filename: FITS file of Huairou data
;
;OUTPUT:
;	GIF file (the same with filename with 'fit' replaced by'gif')
;
;KEYWORDS:
;	smooth: factor used to smooth the raw	data. DEFAULT=3
;	swap:	sawp the high-low 8bit data,
;	limit:	used to BYTSCL the magnetograms and Dopplergrams,
;		DEFAULT=600
;
;HISTORY:
;	July-07,2000, DENG Y. Y., in HSOS for OLD system
;       May-21, 2001, DYY in HSOS for OLD system
;	Oct-13, 2001, DYY in HSOS for PULNIX 6701AN CCD Camera


	if n_elements(limit) eq 0 then limit=600

dat=readfits(filename,header)
xdim=sxpar(header,'NAXIS1')
ydim=sxpar(header,'NAXIS2')

if n_elements(swap) then dat=swap_endian(dat)
;dat=rotate(dat,7)
if n_elements(smooth) ne 0 then dat=smooth(dat,smooth)

fc=sxpar(header,'content')
if (fc eq 'D') or (fc eq 'S') or (fc eq 'T') or (fc eq 'R') then begin
;	option=wmenu(['Do you want correct the flatfield?','Yes','No'])
;	if option ne 2 then begin
;		dadfile='cccc'
;		print,''
;		print,'---- Please input the filename of flatfield 1 -----'
;		print,''
;		read,dadfile
;		ldad=readfits(dadfile)
;		print,''
;		print,'---- Please input the filename of flatfield 2 -----'
;		print,''
;		read,dadfile
;		rdad=readfits(dadfile)
;		if n_elements(swap) ne 0 then  begin
;			ldad=swap_endian(ldad)
;			rdad=swap_endian(rdad)
;		endif
;		dad=float(ldad)+rdad

;		if n_elements(smooth) ne 0 then dad=smooth(dad,smooth)
;		dad=dad/mean(dad)
;		dat=dat/dad
;	endif

	vmin=dat(100:400,50:310)
	vmax=max(vmin)
	vmin=min(vmin)
endif else begin
	vmax=limit
	vmin=-limit
	dat=dat*10000./sxpar(header,'CALIBRAT')
endelse

content='Filtergram'
  if (fc eq 'L') or (fc eq 'Q') or (fc eq 'U') $
	then content='Magnetogram'
  if (fc eq 'V') then content='Dopplergram'
  if (fc eq 'D') or (fc eq 'S') or (fc eq 'T') or (fc eq 'R') then content='Filtergram'

window,xs=xdim,ys=ydim

tvscl,dat>vmin<vmax
tt=tvrd()
tt(0:400,ydim-44:*)=min(tt)/2+max(tt)/2
tvscl,tt

	obs_date=sxpar(header,'T_START')
	obs_time=strlen(obs_date)
	obs_time=strmid(obs_date,10,obs_time-10+1)
	obs_time=strcompress(obs_time,/remove_all)
	if strlen(obs_time) eq 7 then obs_time='0'+obs_time
	obs_date=strmid(obs_date,0,10)
	xpos=sxpar(header,'LONGITUD')
	if xpos le 0 then begin
	strput,xpos,'E',0
	endif else begin
	xpos='W'+xpos
	endelse
	ypos=sxpar(header,'LATITUDE')
	if ypos le 0 then begin
	strput,ypos,'S',0
	endif else begin
	ypos='N'+ypos
	endelse

filename=strsplit(filename,'/',/extract)
filename=filename(n_elements(filename)-1)
filename=strsplit(filename,'\',/extract)
filename=filename(n_elements(filename)-1)
giffile=strsplit(filename,'.',/extract)
giffile=giffile(0)+'.gif'

xyouts,5,ydim-14,size=1.2,'!6 Content:  '+content,/device
xyouts,5,ydim-28,size=1.2,'!6 HSOS No.: '+sxpar(header,'HSOS_NO'),/device
xyouts,5,ydim-42,size=1.2,'!6 Date:      '+obs_date,/device
xyouts,185,ydim-14,size=1.2,'!6 Wavelegnth:  '+sxpar(header,'WAVELENG'),/device
xyouts,185,ydim-28,size=1.2,'!6 Coordinate:  '+xpos+' '+ypos,/device
xyouts,185,ydim-42,size=1.2,'!6 Time:         '+obs_time+'UT',/device

tt=tvrd()
write_gif,giffile,tt
$xv giffile

print,''
print,'Your figure is put into:  ',giffile
print,''
;----------------------------------------------------------------------

end




















