disp('openradi.m')
% Opens Channel #2 Radiometers and Mean Tair, Tsea, and RH sensors

norman=1;
R1Pg1=[];R2Pg1=[];THPg1=[];R1Pg2=[];R2Pg2=[];THPg2=[];THPr1=[];THPr2=[];
RS=[];TA=[];RHa=[];

while norman==1,
   headr=fgetl(flist);
   if headr==-1,norman=0;break;end;
   for qq=1:length(headr)-9;
      if headr(qq:qq+2)==' 03',
         R1_pyrg1=str2num(headr(qq+3:qq+9));
         if R1_pyrg1 > 1000,                     %conditional to bypass the once per hour status output by Campbell
            R1Pg1=[R1Pg1 R1_pyrg1];
         end;   
      end;   
      if headr(qq:qq+2)==' 04',
         R2_pyrg1=str2num(headr(qq+3:qq+9));
         R2Pg1=[R2Pg1 R2_pyrg1];
      end;
      if headr(qq:qq+2)==' 05',
         Th_pyrg1=str2num(headr(qq+3:qq+9));
         THPg1=[THPg1 Th_pyrg1];
      end;
      if headr(qq:qq+2)==' 06',
         R1_pyrg2=str2num(headr(qq+3:qq+9));
         R1Pg2=[R1Pg2 R1_pyrg2];
      end;   
      if headr(qq:qq+2)==' 07',
         R2_pyrg2=str2num(headr(qq+3:qq+9));
         R2Pg2=[R2Pg2 R2_pyrg2];
      end;
      if headr(qq:qq+2)==' 08',
         Th_pyrg2=str2num(headr(qq+3:qq+9));
         THPg2=[THPg2 Th_pyrg2];
      end;
      if headr(qq:qq+2)==',09',
         Th_pyra1=str2num(headr(qq+3:qq+9));
         THPr1=[THPr1 Th_pyra1];
      end;   
      if headr(qq:qq+2)==' 10',
         Th_pyra2=str2num(headr(qq+3:qq+9));
         THPr2=[THPr2 Th_pyra2];
      end;
      if headr(qq:qq+2)==' 11',
         Rsea=str2num(headr(qq+3:qq+9));
         RS=[RS Rsea];
      end;   
      if headr(qq:qq+2)==' 12',
         Tairv=str2num(headr(qq+3:qq+9));
         TA=[TA Tairv];
      end;
      if headr(qq:qq+2)==' 13',
         RHv=str2num(headr(qq+3:qq+9));
         RHa=[RHa RHv];
      end;
   end;
end;


Td1(1:length(R1Pg1))=3563./(2.74+log(R1Pg1));
Td2(1:length(R1Pg2))=3563./(2.74+log(R1Pg2));
Tc1(1:length(R2Pg1))=3563./(2.74+log(R2Pg1));
Tc2(1:length(R2Pg2))=3563./(2.74+log(R2Pg2));

if length(Tc1)>length(Td1),
   Tc1=Tc1(1:length(Td1));
end;   
if length(Tc2)>length(Td2),
   Tc2=Tc2(1:length(Td2));
end;   
if length(Td1)>length(Tc1),
   Td1=Td1(1:length(Tc1));
end;   
if length(Td2)>length(Tc2),
   Td2=Td2(1:length(Tc2));
end;   
if length(THPg1)>length(Tc1),
   THPg1=THPg1(1:length(Tc1));
end;   
if length(THPg2)>length(Tc2),
   THPg2=THPg2(1:length(Tc2));
end;   

sigma=5.67e-8;
clear Tairv RHv
Tairv=TA;
RHv=RHa;

%Esv=6.112.*exp((17.67.*Tairv)./(Tairv+243.5));
%Qv=0.622.*RHv./100.*Esv./1010.*1.3.*1000;

%[Cqv,Fqv]=psd(Qv,32,1./60);
%[Cqv2,Fqv2]=specsmoo(Cqv,1/60);
%Cqv=Cqv*2*60;Cqv2=Cqv2*2*60;

Tsea_snake=3915.9./(5.127+log(RS-10))-273.15;

disp([num2str(ddd),'   ',num2str(hhh),'   Tv = ',num2str(mean(Tairv)),'   RHv = ',num2str(mean(RHv)),'   Tss = ',num2str(mean(Tsea_snake))])

Solar1=THPr1./(9.03e-3);
Solar2=THPr2./(9.13e-3);
LongIR1=THPg1./(4.20e-3)+(sigma*(Tc1.^4))+2.5*sigma*((Tc1.^4)-(Td1.^4));
LongIR2=THPg2./(3.57e-3)+(sigma*(Tc2.^4))+2.5*sigma*((Tc2.^4)-(Td2.^4));

