; $Id: taswr.pro,v 1.2 2002/01/14 20:59:27 amunter Exp $
pro taswr,d,filen
;+
; NAME:         TASWR
; PURPOSE:
;               Write a TASCOM *.DAT file
; CATEGORY:
; CALLING SEQUENCE:
;               taswr,d,'filename'
; INPUTS:                         
;               d= TASCOM data structure
;               filename= eg. ora059.dat
; OPTIONAL INPUT PARAMETERS:
; KEYWORD PARAMETERS:
; OUPUTS:
;               a TASCOM format *.dat file
; OPTIONAL OUTPUT PARAMETERS: 
; COMMON BLOCKS:
; SIDE EFFECTS: 
;               overwrites an existing file if one of the same name exists
; RESTRICTIONS:
; PROCEDURE:
; MODIFICATION HISTORY:
;               Thom Mason, Riso National Laboratory, 1993
;-
if (n_params() eq 1) then filen=pickfile(filter='*.dat*',title=$
 'Select an output file')
on_ioerror,bad
tmp0=string(' ',format='(a79)')
tmp1=string(' ',format='(a79)')
strput,tmp0,d.text(0)
strput,tmp1,d.text(1)
openw,unit,filen,/get_lun
printf,unit,format='(1x,i3,i3,2(/,a79))',d.pars+d.heads+2,d.pars,tmp0,tmp1
IF (d.heads GT 1) THEN $
for i=0,d.heads-1 do $
 printf,unit,format='(1x,a4,a3,g13.6)',d.hdef(i),' = ',d.hnum(i) $
ELSE printf,unit,format='(1x,a4,a3,g13.6)',d.hdef,' = ',d.hnum
for i=0,d.pars-1 do printf,unit,format='(1x,a4)',d.prp(i)
for i=0,d.points-1 do begin
  for j=0,d.pars-1 do printf,unit,format='(g13.6)',d.data(j,i)
  endfor
goto,done
    
bad:print,!err_string

done: free_lun,unit
end
