pro rd_gen,filename,data,header=header,text=text
;
;+
; NAME:
; 	RD_GEN
;
; PURPOSE:
;	Read SXT generic file and return contents in appropriate data
;	structure.  
;
; CALLING SEQUENCE:
;	RD_GEN, filename, data [,TEXT=TEXT, HEADER=HEADER]
;
; INPUTS:
;	FILENAME - string containing generic file name
;
; OUTPUTS:
;	DATA - structure containing contents of file
;	       (one tag field per stored data structure)
;
; OPTIONAL KEYWORD PARAMETERS:
; 	TEXT - Generic file text description
;	HEADER - System imposed header (version/creattion date)
;
; COMMON BLOCKS;
;	NONE
;
; MODIFICATION HISTORY:
;	Version 1 - SLF, 3/5/91
;			 21-dec-92 	; restore text as array if it
;					; is delimited by wrt_gen del= '\\'
;	
;-		
;
openr,unit,/get_lun,filename 		; needs check for file exist
; 
; create file header structure and read it
header='{dummy, version:0L, creation:string(replicate(32b,24))}'
header=make_str(header)
readu,unit,header
;
; read optional text section
text_len=0L
readu,unit,text_len			
if text_len gt 0 then begin
   text=string(replicate(32b,text_len))
   readu,unit,text
   text=str2arr(text,'\\')		; slf 21-dec-92
   if n_elements(text) eq 1 then $
	text=text(0)			; force scaler
endif
;
n_sstags=0L			; number tags in superstructure
readu,unit,n_sstags
;
tag=0				; loop counter (tag pointer)
n_dimensions=0L			; #tag dimensions
structure='{dummy'		; open structure string
; 
; loop for each tag field 
;
while not eof(unit) and tag lt n_sstags do begin
   readu,unit,n_dimensions			; #tag dimensions
   arr_size=make_array(n_dimensions+2,/long)	; to recieve size vect
   readu,unit,arr_size				; read size vect
   structure = structure + ',Tag' + 	  $	; concat [struct,tag]
      string(tag,format='(i2.2)') + ':' + $
      fmt_tag([n_dimensions,arr_size])
   tag=tag+1					; next tag
endwhile			; all tags processed
;
structure=structure + '}'	; close structure string
;
data=make_str(structure)	; define the super structure
readu,unit,data			; and read the file contents into it
;
free_lun,unit
end
