disp('jes_ts1')

djay=10/60/24;

ijsb=1;
ijsi=1;
iy=1;

ny=1076;				%# of lines of data  

for ibg = 170:ny 			%major read loop
   jdx=dtc(1,ibg)+djay;
   jsb_n=0;
   jsi_n=0;
   tsb=0;
   tsi=0;
   while happ(ijsb,1)<jdx;
      ijsb=ijsb+1;
      jsb_n=jsb_n+1;
      tsb=tsb+happ(ijsb,3);
   end;
   
   while hapx(ijsi,1)<jdx;
      ijsi=ijsi+1;
      jsi_n=jsi_n+1;
      tsi=tsi+hapx(ijsi,2);
   end;
   if jsi_n>0;
      if jsb_n>0;
         tst=tsb/jsb_n;
         if abs(tst-tsx(ibg))<0.5;
            tsbar(iy)=tsb/jsb_n;
         	tibar(iy)=tsi/jsi_n;
         	jd(iy)=dtc(1,ibg);
         	ts_cf(iy)=tsx(ibg);
         	dter(iy)=dtl(ibg);
            qx(iy)=qtot(ibg);
            tgx(iy)=(tsx(ibg)+tst)/2;
            iy=iy+1;
         end;
       end;
   end;   
   nq=iy-1;
end; %  data line loop
	figure;	
	plot(jd(1,1:nq), dter(1:nq), jd(1,1:nq), tsbar(1:nq)-tibar(1:nq));
   axis([261 270 -.2 .5]);
   xlabel('Julian Day');
   ylabel('Dt(C)');
   figure;
   plot(jd(1:nq), qx(1:nq));
   axis([261 270 0 200]);
   xlabel('Julian Day');
   ylabel('Q_{tot} (W/m^2)');
   %figure;	
	%plot(dtc(1,1:ny), hl(1,1:ny), dtc(1,1:ny), hl(2,1:ny));
   %axis([260 272 -10 100]);
   %xlabel('Julian Day');
   %ylabel('Hl (W/m^2)');
   %figure;
   %plot(hl(1,1:ny), hl(2,1:ny), 'o');
   %axis([-10 100 -10 100]);
   %xlabel('Hl_{old} (W/m^2)');
   %ylabel('Hl_{new} (W/m^2)');
	 %figure;	
	%plot(dtc(1,1:ny), tu(1,1:ny), dtc(1,1:ny), tu(2,1:ny));
   %axis([260 272 -0 .6]);
   %xlabel('Julian Day');
   %ylabel('Tau (N/m^2)');
   %figure;
   %plot(tu(1,1:ny), tu(2,1:ny), 'o');
   %axis([-0 .6 -0 .6]);
   %xlabel('Tau_{cov} (W/m^2)');
   %ylabel('Tau_{new} (W/m^2)');

   
fclose('all');
%flist=fopen('c:\matlab5\cwf\progs\tact.txt','w');
%flist=1;
%for ibg = 1:ny 			%major write loop
%fprintf(flist,'%9.5f %6.2f\n',dtc);
%fclose('all');
	
	
	
	
	
