; This procedure is used for read HSOS data file  
; 	
;	Synopsis:	read_hr,filename,data,info
;	      or:	read_hr,filename,data,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  
;                               by X.Z. Hu  
;       last change date        May 11, 1995  

;	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,filename,data,info,swap=swap  


filename=strlowcase(filename)   
length=strlen(filename)
  
if length lt 1 then begin
  	print,'Haven"t selected a file'
  	data=0
	info=0
	goto,end_lab
end
first_char=strmid(filename,length-12,1)  
          
case first_char of  
        "s":data=bytarr(512,512)   
        "t":data=bytarr(512,512) 
        "d":data=bytarr(512,512)
        "l":data=intarr(512,512)
 	"q":data=intarr(512,512)
        "u":data=intarr(512,512)  
        "v":data=intarr(512,512)
	"h":data=bytarr(512,512)  
 	"c":data=bytarr(512,512)  
       else:message,'not a HSOS format data file!'  
endcase  

;-----------------------------------------------------
;	Set the value of swap
;-----------------------------------------------------
	if (n_elements(swap) eq 0) then begin
		swap=0
  	endif else begin
		if (swap ne 0) then swap=1
	endelse
;-----------------------------------------------------

tail=bytarr(65)  
xy=intarr(7)  
info=strarr(12)  
openr,unit,filename,/get_lun  
readu,unit,data,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 (first_char ne 's') and (first_char ne 't') and $
	(first_char ne 'h') and (first_char ne 'c') and $
	(swap eq 1) then data=swap_endian(data)  
line=strmid(filename,length-11,1) 

case line of
'5':info(0)='5324A'
'4':info(0)='4861A'
'a':info(0)='6563A'
endcase 
if (first_char eq 'c') then info(0)='3933A'

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:
data=rotate(data,7)
end  




