; $Id: printfits.pro,v 1.2 2002/01/14 20:59:26 amunter Exp $
PRO printfits, fits, name, col=col
;+
; NAME: printfits
;
; PURPOSE: To print the results of SIGAVE to a file
;
; CATEGORY: TASCOM data analysis
;
; CALLING SEQUENCE: fits = sigave(list,'fina','extension',interval)
;		    printfits, fits, 'fitresults.dat'
;
; INPUTS: 
;		fits = the fitresults of sigave. See sigave for details
;		'fitresults.dat' = the output file
;
; OPTIONAL INPUT PARAMETERS: none
; KEYWORD PARAMETERS: COL = number of columns you actually want.
;		if COL is an array of zeros and ones, then these will be used to
;		print the stuff. 
;
;		eg. printfits, fits, 'fitresults.dat', COL=2
;		     will only print the x-axis and y-axis data, nothing else
;		eq. printfits, fits, 'fitresults.dat', COL=[1,1,0,1,0]
;		     will only print the x-axis, y-axis and y-errorbar	
; OUTPUTS:
;	Five columns of data:
;		x-axis y-axis x-errorbar y-errorbar fwhm-of-the-fit
;
; OPTIONAL OUTPUT PARAMETERS: none
; COMMON BLOCKS: none
; SIDE EFFECTS:

; MODIFICATION HISTORY:
;	Paul Schleger, Riso National Laboratory, March 1994
;-
f=fits & size = n_elements(f.x)
IF keyword_set(col) THEN BEGIN
	IF NOT isarray(col) THEN BEGIN
		colly = INDGEN(N_TAGS(fits))+1
		index = WHERE(colly LE col, count)
		col = INTARR(N_TAGS(fits))
		IF count NE 0 THEN col(index) = 1
	END	
END ELSE col = intarr(N_TAGS(fits))+1
get_lun, lun
openw, lun, name
FOR I=0,n_elements(f.x)-1 DO BEGIN
  str = ''
  FOR J=0,N_ELEMENTS(col)-1 DO IF col(J) NE 0 THEN str = str+STRING(fits.(J)(I))+' '
  printf, lun, str
END
close, lun
END
