pro calcspec,fluxarray,spectra,duration,period,sph,nfft,start,missing
;routine to calculate spectra

;determine nchannels, ncols and nrows
arrsize   = size(spectra)
ncols     = arrsize(1)
nrows     = arrsize(2)

fluxpts   = size(fluxarray)
fluxpts   = fluxpts(2)

;generate fft times (still using decimal hours):
times = findgen(ncols)
;times = start + (duration/ncols)/2 + times*(duration/ncols)
times = (duration/ncols)/2 + times*(duration/ncols); MWC 20180102

   for j=0,ncols-1 do begin

      ;make sure the data is contained in fluxarray (away from end of file):
      first_time = times(j) - (nfft/2.0)*period/sph
      last_time  = times(j) + (nfft/2.0)*period/sph
      check      = first_time gt fluxarray(0,0) and last_time lt $
         fluxarray(0,fluxpts-1)

      if check then begin ;go ahead and grab the data
         first_data = where(fluxarray(0,*) gt times(j))
         grab = [fluxarray(1,first_data(0)-nfft/2:first_data(0)-1+nfft/2)]
         grab = reform(grab)

         if n_elements(grab ne nfft) then begin
            print,'BIG ERROR!! (in getspec)'
            STOP
         endif
         spectrum       = alog10(abs(fft(hanning(nfft)*(grab),-1)))  ;deriv(grab)
         spectrum(0)    = missing
         spectrum(1)    = missing
         spectra(j,*) = spectrum(0:nrows-1)
      endif else begin
         spectra(j,*) = missing ;make this white in color
      endelse
;if j eq 0 and start gt 36. then stop
   endfor


return
end