    function SSRT_file_struc,lun,Fileformat=Fileformat, $
   Offset=Offset, Blocklength=Blocklength, Length=Length, $
	Num_blocks=Num_blocks, Dt=Dt, Date=Date, I_file=I_file


Descr_file = FSTAT(lun)


	if keyword_set(I_file) then begin
Block={T_F_Block_1,Time:intarr(2),data:intarr(254,/Nozero)}
Offset=512L
FileFormat=['rout','1']
rec_length = Descr_file.size-Offset
N_scans=256
goto, Label
	endif

;	The SSRT data files structure.

Sum_chan=[180,192]

file_date=strmid((name_lun(lun))(1),2,6)
file_ext=strlowcase((name_lun(lun))(2))
Fyear  = strmid(file_date,4,2)
Fmonth = strmid(file_date,2,2)
Fday   = strmid(file_date,0,2)
Date=string(Fday,Fmonth,Fyear,	format="(2(I2.2,' '),I2)")

     IF file_ext eq 'bst' or file_ext eq 'bso' or	$
	file_ext eq 'spk' or file_ext eq 'spo' THEN	$
			       Fileformat=['aor','0']	$
ELSE IF file_ext eq 'dat' THEN Fileformat=['fdas','0']	$
ELSE IF file_ext eq 'fds' THEN Fileformat=['fdas','1']	$
ELSE IF file_ext eq 'clm' THEN Fileformat=['aor','clm']	$
ELSE IF file_ext eq 'ccd' THEN Fileformat=['aor','cor0'] $

ELSE Fileformat=['rout','1']


	IF Fileformat(0) eq 'aor' THEN BEGIN
		Rec_Type=1
	if (Fyear gt 93) or (Fyear eq 93 and Fmonth gt 6) or $
	(Fyear eq 93 and Fmonth eq 6 and Fday ge 7) then $
	if  Fileformat(1) ne 'clm' then Fileformat(1)='1'

	if (Fyear gt 96) or (Fyear eq 96 and Fmonth gt 4) or $
	(Fyear eq 96 and Fmonth eq 4 and Fday ge 1) then $
	if  Fileformat(1) ne 'clm' then Fileformat(1)='cor1'


	ENDIF ELSE Rec_Type=0


if (Fileformat(1) eq 'cor0') then rec_type=1


;*****************************************************

Num_pat = 2L*Sum_chan(1)
Offset=(4L+2*Num_pat*equiv(Fileformat, ['aor','1']))* $
	(Fileformat(0) eq 'aor')
rec_length = Descr_file.size-Offset
N_scans=32L

;*****************************************************
		CASE 1 OF

	equiv(Fileformat, ['aor','0']): begin

ScansetAOR0={ScansetAOR0,Attr:0B, I:bytarr(192),V:bytarr(192)}

Block={BlockAOR0,time:0L, Set32:replicate(ScansetAOR0,32)}

Blocklength = n_tags(Block,/length)
Num_blocks = rec_length/Blocklength
Length=32L*Num_blocks

IF (double(rec_length)/Blocklength ne double(Num_blocks)) $
	AND (Fyear eq '92') THEN BEGIN

Offset=0L
rec_length = Descr_file.size-Offset
Num_blocks = rec_length/Blocklength
Length=32L*Num_blocks
Fileformat=['aor','-1']

if double(rec_length)/Blocklength ne double(Num_blocks) $
		then begin
print,'ERROR of file length'
print,'Cannot recognize format'
		endif
	ENDIF

Dt=0.056D
					end


	equiv(Fileformat, ['aor','1']):	begin

ScansetAOR1={ScansetAOR1, AttrEW:0B, LEW:bytarr(192), $
REW:bytarr(192), AttrSN:0B, LSN:bytarr(192), RSN:bytarr(192)}

Block={BlockAOR1,time:0L, Set32:replicate(ScansetAOR1,32)}

Dt=0.056D
					end

	equiv(Fileformat, ['aor','cor0']):	begin
ScansetAORcor0={ScansetAORcor0, AttrEW:0B, LEW:bytarr(192), $
REW:bytarr(192), AttrSN:0B, LSN:bytarr(192), RSN:bytarr(192), $
AttrSUM:0B, LSUM:bytarr(192), RSUM:bytarr(192)}

Block={BlockAORcor0,time:0L, Set32:replicate(ScansetAORcor0,32)}

Dt=0.056D

						end

	equiv(Fileformat, ['aor','cor1']):	begin
ScansetAORcor1={ScansetAORcor1, Attr:0, $
LSUM:intarr(384), $
LEW:intarr(384), $
LSN:intarr(384),  $
RSUM:intarr(384), $
REW:intarr(384),  $
RSN:intarr(384)}

Block={BlockAORcor1,time:0L, Set32:replicate(ScansetAORcor1,16)}

Dt=0.056D

						end


	equiv(Fileformat, ['aor','clm']): begin

Block=fltarr(Descr_file.size/4)
Length=(Num_blocks=1L)
Offset=0L
Dt=0.56D
Blocklength=Descr_file.size/4

					  end


	equiv(Fileformat, ['fdas','0']) or $
	equiv(Fileformat, ['fdas','1']):  begin

Dt=0.014d0
Offset=0L
N_scans=1L

N_channels_total = 180
N_channels_actual = 176

Dummy_channels = intarr(N_channels_total-N_channels_actual)

Block={FDAS_Block, Time_in_R:intarr(4),	$
	Descriptor_R:0L,		$
	Right:intarr(N_channels_actual),$
	Dummy_channels_R:Dummy_channels,$
	Time_in_L:intarr(4),		$
	Descriptor_L:0L,		$
	Left:intarr(N_channels_actual),	$
	Dummy_channels_L:Dummy_channels}

					end



	ENDCASE

;*****************************************************

Label:

	IF not equiv(Fileformat, ['aor','clm']) THEN BEGIN

Blocklength = n_tags(Block,/length)
Num_blocks = rec_length/Blocklength
Length=N_scans*Num_blocks

IF double(rec_length)/Blocklength ne double(Num_blocks) $
		then print,'ERROR of file length'

	ENDIF


	    RETURN,Block
end