; $Id: colwr.pro,v 1.2 2002/01/14 20:59:26 amunter Exp $
pro colwr,d,filename,index
;+
; NAME:         COLWR
; PURPOSE:
;               Write a COLUMN *.COL file
; CATEGORY:
; CALLING SEQUENCE:
;               taswr,d,'filename',index
; INPUTS:
;               d= TASCOM data structure
;               filename= eg. ora059.dat
; OPTIONAL INPUT PARAMETERS:
;               index=array of field defintions for output
; KEYWORD PARAMETERS:
; OUPUTS:
;               a COLUMN format *.col ascii 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 filename=pickfile(filter='*.col',title=$
 'Select an output file')
on_ioerror,bad
if (n_params() eq 2) then begin
 index=[tasid('h',d),tasid('k',d),tasid('l',d),tasid('em',d),tasid('ea',d),$
   tasid('ef',d),tasid('i',d),tasid('sigi',d)]
 index=index(where(index ge 0))
 endif              
ncol=size(index)
openw,unit,filename,/get_lun
for i=0,d.points-1 do begin
  printf,unit,format='(11(1x,g12.6))',d.data(index,i)
  endfor
goto,done
                                              
bad:print,!err_string

done: free_lun,unit
end
