disp('red_ts2')

stux=zeros(8,1);
stuy=zeros(29,1);
dtc=zeros(2,1380);
hs=zeros(2,1380);
hl=zeros(2,1380);
tu=zeros(2,1380);

fclose('all');
flisx=fopen('c:\matlab\toolbox\local\flip_me3.txt','r');
%stuff=fgetl(flisx);
%stufg=fgetl(flisx);%******************  setup read data loop  **********
ny=1380;				%# of lines of data     
for ibg = 1:ny 			%major read loop
	stuy=fscanf(flisx,'%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g',[29,1]);
	%*********************************************
		%*******   decode date  ************
	
	harp(ibg,1:29)=stuy(1:29)';
	%stuy(1:29)'
	u=stuy(13);
	t=stuy(3)-.6;
	ts=stuy(5);
	qs=stuy(11);
	rs=stuy(8);
	q=stuy(12);
	rl=stuy(6);
	if rs==-9999;
		rs=0;
	end;
	if rl==-9999;
		rl=390;
	end;
	x=[u,0,ts,t,qs,q,rs,rl,0,600,1010,17,11,11];
	y=cool_lkb(x);
	L=real(y(7));
	dtc(2,ibg)=y(9)/.4*(log(10/1.5)-psit(10/L)+psit(1.5/L));
	dtc(1,ibg)=stuy(1);
	hs(1,ibg)=stuy(27);
   hs(2,ibg)=y(1);
	hl(1,ibg)=stuy(28);
   hl(2,ibg)=y(2);
	tu(1,ibg)=stuy(22);
   tu(2,ibg)=y(3);
   tsx(ibg)=ts;
   tax(ibg)=t;
 %  tir(ibg)=stuy(10)+.275*(stuy(10)-t);
	  tir(ibg)=stuy(10)+.2*(ts-t);
 	dtl(ibg)=y(11);
   qtot(ibg)=.97*(5.67e-8*(ts+273.16)^4-stuy(6))+y(1)+y(2);
   
end; %  data line loop
	figure;	
	plot(dtc(1,1:ny), dtl(1:ny), dtc(1,1:ny), tsx(1:ny)-tir(1:ny));
   axis([260 272 -.5 1]);
   xlabel('Julian Day');
   ylabel('Dt(C)');
   figure;
   plot(dtc(1,1:ny), qtot(1:ny), 'o');
   axis([260 272 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');
	
	
	
	
	
