pro jitter_html, outfil, q_debug=q_debug

;+
;NAME
;       JITTER_HTML
;PURPOSE:
;       To create a html file with links to the x and y error plots, full spectrum images,
;       peaks, and tab files.
;SAMPLE CALLING SEQUENCE:
;       jitter_html
;       jitter_html, 'outfil'
;OPTIONAL INPUT:
;       outfil  -The path and name where the file will be written to.
;OPTIONAL KEYWORDS:
;	q_debug
;HISTORY:
;       Written 4-Mar-97 by S.Qwan
;	12-Dec-97 J.Abrehamson (Eliminated reliance on ordered data in jitter_data.tab)
;	24-Nov-98 TDT  Datasets not in $MDI_CAL_INFO/jitter_data.tab are ignored
;-      


if (n_elements(outfil) eq 0) then outfil='$path_http/cal/jitter.html'
if (n_elements(title) eq 0) then title='MDI Jitter Calibration Results'

get_lun, lun
openw, lun, outfil

; writing html headers

printf, lun, '<html>'
printf, lun, '<head>'
printf, lun, '<base HREF=http://www.lmsal.com>'
printf, lun, '<title>', title,'</title>'
printf, lun, '</head>'
printf, lun, '<hr>'
printf, lun, '<pre>'
printf, lun,'<b>			   		  X&Y Error     X	       Y            X       Y'
printf, lun, 'Date	  Time	  	Comments   	   Plots   Img & Peaks     Img & Peaks    Table   Table</b>'



ff=file_list('/data14/jitter','*.genx', file=file)
outdir='/MDI/cal/jitter'

ff_com= rd_tfile('$MDI_CAL_INFO/jitter_data.tab', 5)
For n=0, n_elements(ff)-1 do begin
	break_file, ff(n),dks_log, dir,filnam,ext 
	xy_plots=concat_dir(outdir, filnam + '_xyplot.gif')		; finding all the needed paths and names
	x_plot=concat_dir(outdir, filnam + '_ximg.gif')			; for each file
	y_plot=concat_dir(outdir, filnam + '_yimg.gif')
	x_tab=concat_dir(outdir, filnam + '.tab_x')
	y_tab=concat_dir(outdir, filnam + '.tab_y')
	place = where(ff_com(0,*) EQ (filnam + ext))
	place = place(0)
	if (place ge 0) then begin
	print, place
	comm= ff_com(1,place) + ' ' + ff_com(2,place) + ' '+ff_com(3, place) +' '+ff_com(4, place)	;getting descriptions from tab file
							; max number of columns from tab file = 4, delineated by spaces

	print, ff_com(0,place),'  ',comm
tarr = fid2ex(strmid(filnam, 0, 13))
ff_sub_x=file_list('/data14/http/cal/jitter', filnam + '_x_pksub*')
ff_sub_y=file_list('/data14/http/cal/jitter', filnam + '_y_pksub*')
	allpks_x= concat_dir(outdir, filnam + '_x_allpks.html')
	allpks_y= concat_dir(outdir, filnam + '_y_allpks.html')


w= ff_com(2, place)			; number of characters in each coloum will determine the spacing in the html
z= ff_com(3, place)			
y= ff_com(4, place)

if (keyword_set(q_debug)) then print, strlen(w)+strlen(z)+strlen(y)

;------for total number of characters eq 4 -------------------;
if strlen(w)+strlen(z)+strlen(y) eq 4 then begin
    if (ff_sub_x(0) eq 4 and ff_sub_y(0) eq '') then begin	;protect against files without peaks, or only x or only y peaks
 	  if (keyword_set(q_debug)) then print, 'nothing here'
	  printf,lun, fmt_tim(tarr),'  ',comm,'   	<a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	     <a HREF ="',y_plot,'">y_img</a>
    end

    if (ff_sub_x(0) ne '' and ff_sub_y(0) ne '') then begin
	printf, lun, fmt_tim(tarr),'  ',comm,'  	  <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a> <a HREF'
	printf, lun, '="',allpks_y,'">peaks</a>    <a HREF'
	printf, lun, '="',x_tab,'">x_tab</a>   <a HREF="',y_tab,'">y_tab</a>'
	end
    if (ff_sub_x(0) ne '' and ff_sub_y(0) eq '') then begin
	printf, lun,  fmt_tim(tarr),'  ',comm,'  	  <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a>		<a HREF="',x_tab,'">x_tab</a>'
	end
    if (ff_sub_x(0) eq '' and ff_sub_y(0) ne '') then begin
	printf,lun, fmt_tim(tarr),'  ',comm,'  		  <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	     <a HREF ="'
	printf, lun, y_plot,'">y_img</a>  <a HREF="',allpks_y,'">peaks</a>    		<a HREF="',y_tab,'">y_tab</a>'
	end
end else begin
;-------for total number of characters eq 10 -------------------;
if strlen(w)+strlen(z)+strlen(y) eq 10 then begin
    if (ff_sub_x(0) ne '' and ff_sub_y(0) ne '') then begin
	printf, lun, fmt_tim(tarr),'  ',comm,'   <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a> <a HREF'
	printf, lun, '="',allpks_y,'">peaks</a>    <a HREF'
	printf, lun, '="',x_tab,'">x_tab</a>   <a HREF="',y_tab,'">y_tab</a>'
	end
    if (ff_sub_x(0) ne '' and ff_sub_y(0) eq '') then begin
	printf, lun,  fmt_tim(tarr),'  ',comm,'   <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a>		<a HREF="',x_tab,'">x_tab</a>'
	end
    if (ff_sub_x(0) eq '' and ff_sub_y(0) ne '') then begin
	printf,lun, fmt_tim(tarr),'  ',comm,' 	 <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	     <a HREF ="'
	printf, lun, y_plot,'">y_img</a>  <a HREF="',allpks_y,'">peaks</a>    		<a HREF="',y_tab,'">y_tab</a>'
	end

end else begin
;-------for total number of characters eq 6 -------------------;
if strlen(w) eq 6 then begin
   if (ff_sub_x(0) eq '' and ff_sub_y(0) eq '') then begin
 	  if (keyword_set(q_debug)) then print, 'nothing here'
	  printf,lun, fmt_tim(tarr),'  ',comm,'    <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>		<a HREF ="',y_plot,'">y_img</a>
    end

    if (ff_sub_x(0) ne '' and ff_sub_y(0) ne '') then begin
	printf, lun, fmt_tim(tarr),'  ',comm,'       <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a> <a HREF'
	printf, lun, '="',allpks_y,'">peaks</a>    <a HREF'
	printf, lun, '="',x_tab,'">x_tab</a>   <a HREF="',y_tab,'">y_tab</a>'
	end
    if (ff_sub_x(0) ne '' and ff_sub_y(0) eq '') then begin
	printf, lun,  fmt_tim(tarr),'  ',comm,'      <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>  <a HREF="',y_plot,'">y_img</a>		<a HREF="',x_tab,'">x_tab</a>'
	end
    if (ff_sub_x(0) eq '' and ff_sub_y(0) ne '') then begin
	printf,lun, fmt_tim(tarr),'  ',comm,'       <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	   <a HREF ="'
	printf, lun, y_plot,'">y_img</a> <a HREF="',allpks_y,'">peaks</a>    	  <a HREF="',y_tab,'">y_tab</a>'
	end
end else begin
;--------for all other circumstances ------------------------;
   if (ff_sub_x(0) eq '' and ff_sub_y(0) eq '') then begin
 	  if (keyword_set(q_debug)) then print, 'nothing here'
	  printf,lun, fmt_tim(tarr),'  ',comm,'   <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	     <a HREF ="',y_plot,'">y_img</a>
    end

    if (ff_sub_x(0) ne '' and ff_sub_y(0) ne '') then begin
	printf, lun, fmt_tim(tarr),'  ',comm,'  <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a> <a HREF'
	printf, lun, '="',allpks_y,'">peaks</a>    <a HREF'
	printf, lun, '="',x_tab,'">x_tab</a>   <a HREF="',y_tab,'">y_tab</a>'
	end
    if (ff_sub_x(0) ne '' and ff_sub_y(0) eq '') then begin
	printf, lun,  fmt_tim(tarr),'  ',comm,'  <a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a>  <a HREF'
	printf, lun, '="',allpks_x,'">peaks</a>    <a HREF="',y_plot,'">y_img</a>		<a HREF="',x_tab,'">x_tab</a>'
	end
    if (ff_sub_x(0) eq '' and ff_sub_y(0) ne '') then begin
	printf,lun, fmt_tim(tarr),'  ',comm,'  	<a HREF="', xy_plots, '">xyplots</a>  <a HREF="',x_plot,'">x_img</a> 	     <a HREF ="'
	printf, lun, y_plot,'">y_img</a>  <a HREF="',allpks_y,'">peaks</a>    		<a HREF="',y_tab,'">y_tab</a>'
	end
   end
end
end
end
end
printf, lun, '</pre>'
close, lun
free_lun, lun
end




