; This procedure is used for read HSOS data file in DAD mode  
; 	
;	Synopsis:	read_hr_dad,filename,ldata,rdata,info
;	      or:	read_hr_dad,filename,ldata,rdata,info,/swap
;	parameter: filename,data,info
;	keyword:   swap  
;       filename: name of data file  
;       data: raw data will be store in this variable  
;       info: observing information 
;	swap: option for high-low 8-bits conversion 
;       0       spectral line  
;       1       date  
;       2       time  
;       3       seeing  
;       4       sun disc coordinate x  
;       5       sun disc coordinate y  
;       6       orthogonal coordinate x  
;       7       orthogonal coordinate y  
;       8       carrington coordinate x  
;       9       carrington coordinate y  
;       10      frame  
;       11      huirou number  
;
;	Modification History:
;		Sep. 28, 1997, for different Device Environment
;			By Deng Y. Y.
;	Option: Swap---- Judge if the data need swap
;		Default: swap=0

pro read_hr_dad,filename,ldata,rdata,info,swap=swap  


filename=strlowcase(filename)   
length=strlen(filename)
  
if length lt 1 then begin
  	print,'Haven"t selected a file'
  	ldata=0
	rdata=0
	info=0
	goto,end_lab
endif
first_char=strmid(filename,length-12,1)  
          
	ldata=intarr(512,512)   
        rdata=intarr(512,512)  
	tmp=intarr(512,8)
;-----------------------------------------------------
;	Set the value of swap
;-----------------------------------------------------
	if (n_elements(swap) eq 0) then begin
		swap=0
  	endif else begin
		swap=1
	endelse
;-----------------------------------------------------

tail=bytarr(65)  
xy=intarr(7)  
info=strarr(12)  
openr,unit,filename,/get_lun
	for ii=0,63 do begin  
	readu,unit,tmp
	ldata(*,ii*8:(ii+1)*8-1)=tmp
	readu,unit,tmp
	rdata(*,ii*8:(ii+1)*8-1)=tmp
	endfor
readu,unit,tail,xy
free_lun,unit  

if (swap eq 1) then xy=swap_endian(xy)/10.0  
xy=xy/10.
xy=string(format='(f7.1)',xy)  
xy(6)=string(format='(i4)',xy(6))  

if (swap eq 1) then begin
	ldata=swap_endian(ldata)  
	rdata=swap_endian(rdata)
endif  

info(1)=string(tail(2:12))  
info(2)=string(tail(15:22))  
info(3)=string(tail(62))  
info(4:10)=xy(0:6)  
info(11)=strmid(filename,length-8,3) 

end_lab:
ldata=rotate(ldata,7)
rdata=rotate(rdata,7)

end





