;+
; NAME:			bcs_bpcckspec
;
; PURPOSE:		superficial check of bpc spectral data
;
; CALLING SEQUENCE:  	bcs_bpcckspec,data,channel,specrange
;
; INPUTS:		data - bpc_structure
;			channel - 0-3 channel
;			specrange - array of spectra subscripts
;
; OPTIONAL INPUTS:	none
;
; OUTPUTS:		none
;
; OPTIONAL OUTPUTS:	none
;
; RESTRICTIONS:		-
;
; PROCEDURE:		loop through specrange. - depending on channel 
;			check validity of options.
;
; MODIFICATION HISTORY: written atp 1993 
;
;-
pro bcs_bpcckspec,data,chan,spectra
;
; start loop
;
ii = 0; 
nelem = n_elements(spectra);
 c = chan-1;
;
 case (c) of 
  '0': nopt = 0; 
  '1': nopt = 8;
  '2': nopt = 3;
  '3': nopt = 7;
 else: nopt = 0;
 endcase
;
	if nopt eq 0 then return
;
 for ii = 0, nelem -1 do begin
;
   s = spectra(ii);
   
   for jj = 0, nopt-1 do begin
	
	case(jj) of 
	  '0': begin 
;		/* option 1 - w/resonance line */
		if data(c,s).quality(jj,0) eq 0 then data(c,s).quality(jj,0) = 1 
		;/* that should have been picked up already */
		if (data(c,s).intensity(jj,0) le 0) or (data(c,s).intensity(jj,0) ge 9999) then data(c,s).intensity(jj,0) = 1
		;/* if this is gone not much hope for fitting this anyway */
		if (data(c,s).width(jj,0) le 0) then data(c,s).width = ([5,9,3])(c-1)
		;/* use some hard wired defaults */
		;/* leave rest as unguessable */
		data(c,s).nlines(jj) = 1
		end
	   '1':begin
;		/* option 2 - w/resonance line + vw */
		if data(c,s).nlines(jj) eq 2 then begin
		 ;/*else ignored*/
		 toti = data(c,s).intensity(jj-1,0)
		 tots = total([data(c,s).intensity(jj,0),data(c,s).intensity(jj,1)])
		 if tots le 0 then tots = 1 ; (avoid fp overflow)
		;stop
		 rfr = float(data(c,s).intensity(jj,0))/tots
		 mfr = float(data(c,s).intensity(jj,1))/tots
		 data(c,s).intensity(jj,0)=rfr*toti
		 data(c,s).intensity(jj,0)=mfr*toti
		 data(c,s).nlines(jj) = 2
		 ; not going to check widths or velocities yet
		 endif; /*else only have 1 or less lines */
		end
	   '2':  begin 
		  ;/* [x,x,x+y] this is ignored by bsd fit */	
		 end
	   '3':  begin
		  ;/* [y, ,q] this is ignored by bsdfit */
		 end
	   '4':  begin
		  ;/* [z, ,z+j+k] this is important for FeXXV only */ 
		 if c eq 1 then begin
		  refi = data(c,s).intensity(1,0); option 2 I
		  if refi le 0 then refi = 1 ; bounds
		  tint = data(c,s).intensity(jj,0); 
		  data(c,s).quality(jj,0) = 1
		  if abs((tint/refi) - 1) ge 0.2 then data(c,s).intensity(jj,0) = refi
		  endif
		 end
	   '5':  begin
		  ;/* [j, ,y] important for FeXXV only ] */
		  if c eq 1 then begin
		  refi = data(c,s).intensity(1,0); option 2 I
		  tint = data(c,s).intensity(jj,0); 
		  if refi le 0 then refi = 1 ; bounds
		  data(c,s).quality(jj,0) = 1
		  if abs((tint/refi) - 1) ge 0.2 then data(c,s).intensity(jj,0) = refi
		  endif
		 end
	   '6':  begin
		  ;/* [ , ,z] important for sxv only */
		  if c eq 3 then begin
		  refi = data(c,s).intensity(1,0); option 2 I
		  tint = data(c,s).intensity(jj,0); 
		  data(c,s).quality(jj,0) = 1
		  if abs((tint/refi) - 0.6) ge 0.1 then data(c,s).intensity(jj,0) = refi*0.6
		  endif
		 end
	    '7': begin
		  ;/* [j+z, , ] ignored by bsdfit */
		 end
	     else: begin
		   print,'Error in check spec'
		   end
	   endcase
	endfor; /* options */	
      endfor; /* spectra */
end; /*program*/
	
