% a diagnostic tool to plot scattering of shear vs/ AGC



% Jules 2000/11/27




colors = jet(length(speeds) -1);
coefs = zeros(length(bins),length(speeds), 2);
means = zeros(length(bins),length(speeds));
hM = zeros(length(bins),length(speeds));


clf
plotnum = 1;
for bini = 1:length(bins)
   for speedi = 1:length(speeds)-1
      hM(bini, speedi) = subplot(length(bins),length(speeds) -1,plotnum);

      ii=find( (data.clmps >= speeds(speedi)) & ...
               (data.clmps <= speeds(speedi+1)) );
      binnum = bins(bini);
   
      h=plot(amprange', [0 0]','k');hold on
      
      x = dtfm(binnum,ii).*data.amp(binnum,ii);
      y = data.fabs_sm(binnum,ii) - data.fabs_sm(refbin,ii);
      
      goodi = find(~isnan(x.*y)); %NO nans
      goodx = dtfm(binnum,ii(goodi)).*data.amp(binnum,ii(goodi));
      goody = ...
          data.fabs_sm(binnum,ii(goodi)) - data.fabs_sm(refbin, ii(goodi));
      coef = polyfit(goodx, goody, 1);
      newx = [min(goodx) max(goodx)];
      newy = polyval(coef, newx);
      coefs(bini, speedi, :) = coef;
      meany = mean(goody);
      means(bini, speedi) = meany;

      h=plot(amprange', [meany meany]','k');
      set(h,'color',.8*[1 1 1], 'linewidth',3)
      hold on    
      h=plot([100 100]',[shearrange]','k');lw(h,.1)
      h=plot(x, y, 'o');
      set(h, 'markersize', 2, 'color', 'b');
      plot(newx, newy, 'r','linewidth',2)
      

      xl(amprange)
      yl(shearrange)
      
      if (speedi == 1)
         ylabel(sprintf('a(%d)', binnum))
      else
         set(gca,'ytick', [])
      end
      
      if (bini == length(bins))
         xlabel(sprintf('%2.1f-%2.1f',speeds(speedi), speeds(speedi + 1)));
      else
         set(gca, 'xtick', [])
      end
     
      plotnum = plotnum + 1;

      hh = hM(bini, speedi);
     pos = get(hh, 'pos');
     %[left, bottom, width, height]
     set(hh, 'pos', pos +.01*[-1 -1 1 1]);
      
   end
end

date_it


subtitle_comment = sprintf('%s forward shear rel to bin %d', config.comment, refbin);
subtitle_comment = sprintf('%s (dday %3.1f - %3.1f)',...
                           subtitle_comment, min(data.dday), max(data.dday));

subtitle(subtitle_comment);
