disp('eval_mean')
fclose('all');
clear jad_mean;
%g=0.0098;						%adiabatic lapse rate
%eps_w=0.97;						%emissivity of water
sig_sb=5.67e-8;				%Stefan Boltzmann constant
jax=1;

if hhh<10,
   e=['D:\hp_data\day',num2str(ddd),'\P2_',num2str(ddd),'0',num2str(hhh)];
else
   e=['D:\hp_data\day',num2str(ddd),'\P2_',num2str(ddd),num2str(hhh)];
end;

flist=fopen(e,'r');
   
dmp=fgets(flist);		%read header lines and skip blanks
clear dmp e
   

while feof(flist)==0,
   clear st1;clear stz;
   st0=fscanf(flist,'%g%*c%g%*c%g',[3,1]);
   [n0 m0]=size(st0);if n0==0;break;end;
   clear n0 m0
   if st0(3)==1
      stx=fscanf(flist,'%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g',[127,1]);
		stz(1:3)=st0;stz(4:length(stx)+3)=stx;st1=stz';
   else
     	sty=fscanf(flist,'%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%g%*c%g%*c%g%g',[130,1]);
      if length(sty)>3
         st1=sty;sty(1:3);
      else
         break
      end;
   end;
   [nr1,nl1]=size(st1);
	if nr1==130
      st2(:,jax)=st1; 
      jax=jax+1;
	else
   	break
	end; 
end;
%clear flist nl1 nr1 st0 st1 stx stz

psp1=st2(62,:);
psp2=st2(64,:);
org=st2(66,:);                    
Tvais=st2(52,:);
Rhvais=st2(54,:);
Tsea=st2(50,:);
Tc1=st2(42,:);
Td1=st2(44,:);
Tc2=st2(46,:);
Td2=st2(48,:);
therm1=st2(58,:);
therm2=st2(60,:);
pir1=therm1+sig_sb*(Tc1+273.16).^4-4*sig_sb*((Td1+273.16).^4-(Tc1+273.16).^4);
pir2=therm2+sig_sb*(Tc2+273.16).^4-4*sig_sb*((Td2+273.16).^4-(Tc2+273.16).^4);
jad_mean=str2num(num2str(ddd))+((st2(1,:)-st2(1,1))/60/60)/24;

clear jax st2 

if length(therm1)<60,
   therm1=[therm1 therm1(length(therm1))];
   therm2=[therm2 therm2(length(therm2))];
   Tvais=[Tvais Tvais(length(Tvais))];
   Tsea=[Tsea Tsea(length(Tsea))];
   Td1=[Td1 Td1(length(Td1))];
   Td2=[Td2 Td2(length(Td2))];
   Tc1=[Tc1 Tc1(length(Tc1))];
   Tc2=[Tc2 Tc2(length(Tc2))];
   psp1=[psp1 psp1(length(psp1))];
   psp2=[psp2 psp2(length(psp2))];
   jad_mean=[jad_mean jad_mean(length(jad_mean))];
   pir1=[pir1 pir1(length(pir1))];
   pir2=[pir2 pir2(length(pir2))];
   org=[org org(length(org))];
   Rhvais=[Rhvais Rhvais(length(Rhvais))];
end;

%figure;plot(jad,Tvais,jad,Tsea);xlabel('Jday (1999)');ylabel('Temperature (C)');Title('Tair_v=blu; Tsea_s_n_a_k_e=grn;  Tc1=red;  Td1=cyn;  Tc2=mag;  Td2=yel'); 
%figure;plot(jad,pir1,jad,pir2);xlabel('Jday (1999)');ylabel('Pir_1 & Pir_2 (W/m^2)');Title('Downward IR Flux: unit1=blu; unit2=grn'); 
%figure;plot(jad,psp1,jad,psp2);xlabel('Jday (1999)');ylabel('Psp_1 & Psp_2 (W/m^2)');Title('Downward Solar Flux: unit1=blu; unit2=grn'); 
%figure;plot(jad,org);xlabel('Jday (1999)');ylabel('ORG Precipitation Rate (mm/hr)');Title('STI Optical Rain Gauge');

clear Tc1 Td1 Tc2 Td2 ans flist jad_mean nl1 nr1 org pir1 pir2 psp1 psp2 sig_sb  st0 st1 stx stz therm1 therm2 sty
