disp('read_hp_day')
fclose('all');
clear all;
jd=input('julian day, ddd','s');
plotit=input('plot plots? 0=n, 1=y');
clear jad;
%plotit=0;
prtit=input('append master data file? 0=n, 1=y');
%prtit=1;
%yd=date;
%jif=datevec(yd);
%xx=[jif(1) jif(2) jif(3) 0 0 0];
%jd=num2str(julday(xx)-1);
hr='00';%input('gmt hr','s');
g=0.0098;%adiabatic lapse rate
eps_w=0.97;%emissivity of water
sig_sb=5.67e-8;%Stefan Boltzmann constant
blk=1;%10-min index 
jax=1;
backchk=0;
for jam=0:0,%cycle thru 24 hourly stats files
   if jam<10,
      hr=['0'num2str(jam)];
   else
      hr=num2str(jam);
   end;
   e=['D:\hp_data\P6_' jd hr];
	flist=fopen(e,'r');
   if flist>0,   %if the file exists, 
      if backchk==0,
         tzilch=jam;
         backchk=1;
      end;%end if
      
      dmp=fgets(flist);%read header lines and skip blanks
      dmp1=fgets(flist);dmp2=fgets(flist);dmp3=fgets(flist);dmp4=fgets(flist);dmp5=fgets(flist);dmp6=fgets(flist);dmp7=fgets(flist);dmp8=fgets(flist);dmp9=fgets(flist);
      
		
      while feof(flist)==0,%go until you run out of 10-min sections
         clear st1;clear stz;
         st0=fscanf(flist,'%g%*c%g%*c%g',[3,1]);
         [n0 m0]=size(st0);if n0==0;break;end;
         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]);
                  %1     2   3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1    2    3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1     2   3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8  1    2   3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1     2    3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1    2   3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8  1    2   3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1    2    3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 1    2    3 4   
             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 if             
      end;%end while
   end;%end flist
end;%end jam
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=str2num(num2str(jd))+(tzilch+(st2(1,:)-st2(1,1))/60/60)/24;
np=jax-1;


if prtit==1;
  prt_jas_means;
end;

if plotit==1;
%  set some plot limits
Tll=-25;
hll=70;
uul=10;
vul=10;
Tul=-0;
hul=100;
sul=12;
Rlul=30;
Rlll=-100;
Rtul=300;
Rtll=125;
Rsul=1000;
Rsll=0;

%plot T profiles
j_st=jad(1);
j_en=jad(np);
figure;
plot(jad(1:np),Tvais(1:np),jad(1:np),Tsea(1:np),jad(1:np),Tc1(1:np),jad(1:np),Td1(1:np),jad(1:np),Tc2(1:np),jad(1:np),Td2(1:np));
xlabel('Jday (1999)');
ylabel('Temperature (C)');
%axis([j_st j_en Rtll Rtul]);
Title('Tair=blu; Tsea=grn'); 
figure;
plot(jad(1:np),pir1(1:np),jad(1:np),pir2(1:np));
xlabel('Jday (1999)');
ylabel('Pir_1 & Pir_2 (W/m^2)');
%axis([j_st j_en Rtll Rtul]);
Title('Downward IR Flux: unit1=blu; unit2=grn'); 
figure;
plot(jad(1:np),psp1(1:np),jad(1:np),psp2(1:np));
xlabel('Jday (1999)');
ylabel('Psp_1 & Psp_2 (W/m^2)');
axis([j_st j_en Rsll Rsul]);
Title('Downward Solar Flux: unit1=blu; unit2=grn'); 
figure;
plot(jad(1:np),org(1:np));
xlabel('Jday (1999)');
ylabel('ORG Precipitation Rate (mm/hr)');
axis([j_st j_en 0 50]);
Title('STI Optical Rain Gauge');
end; 
