disp('eval_pc_day_rhb_07')
fclose('all');
% modified on 30-mar-01 by D.E.Lane for Kai 2001 cruise
% modified 10 nov 03 by cfairall for the weller 2003 cruise

jd=num2str(ddd);
if ddd<100
   jd=['0' num2str(ddd)];
end;
if ddd<10
   jd=['00' num2str(ddd)];
end;

plotit=0;
prtit=0;
clear jad;
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;
st2=[];
Tvais=[];psp1=[];pir1=[];qvais=[];Rhvais=[];Tsea=[];

total_num_fields=68;

for jam=hhh:hhh,					%cycle thru 24 hourly stats files
    if jam<10,
        hr=['0' num2str(jam)];
    else
        hr=num2str(jam);
    end;                       %end if jam
   
    e=[way_raw_data 'day',jd,'\P2_' jd hr];
    disp(['Reading means file from hour ',num2str(jam)]);
    flist=fopen(e,'r');
   
    if flist>0,					%if the file exists, 
              
        dmp=fgets(flist);		%read header lines and skip blanks
		
        while feof(flist)==0,
            if backchk==0,
            tzilch=jam;
            backchk=1;
            end;						%end if
            clear st1 stz;
            if isfinite(flist),
                stx=fscanf(flist,'%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,%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,%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,%g,%g',[77,1]);
                %                          1                           2                          3                          4                         5
                [nr1,nl1]=size(stx);
                if nr1==77
                    st2(:,jax:jax+nl1-1)=stx;
      	            jax=jax+nl1;
	            else
   		            x=fgets(flist);clear x
                end;                %end nr1
            dmp4=fgets(flist);  %read time from blank line
            end;                    %end if st0
        end;                        %end while feof
    end;                            %end if flist
end;                                %end for jam

% if isempty(st2)
%     st2=ones(72,60)*NaN;
% end;

if ~isempty(st2)
chnx=17;
org_carrier=st2(15,:);         %sti carrier voltage
aspir_on=st2(32,:);                 %aspirator swich -5 means back flow

psp1=st2(28,:);
psp2=st2(29,:);
org=st2(30,:);
Tvais=st2(24,:);
Rhvais=st2(25,:);

avgpsp=mean(psp1);
avgrain=mean(org);
avgTvais=mean(Tvais);
avgRHvais=mean(Rhvais);
avgQvais=avgRHvais/100*qsea(avgTvais);
qvais=Rhvais./100.*qsea(Tvais);
Tsea=st2(23,:)+0.01;   %correct for lead resistance 20C

Tc1=st2(19,:);%-.35;  %correct for bias, day 321
Td1=st2(20,:);%-.35;    %correct for bias
Tc2=st2(21,:);%-0.1;
Td2=st2(22,:);
therm1=st2(26,:);
therm2=st2(27,:);
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);
pp=ones(length(Tvais),1)*1009;

for iii=2:length(org);
    if org(iii)==0,
        org(iii)=org(iii-1);
    end;
    if org_carrier(iii)==0,
        org_carrier(iii)=org_carrier(iii-1);
    end;
    if Tc1(iii)==0,
        Tc1(iii)=Tc1(iii-1);
    end;
    if Tc2(iii)==0,
        Tc2(iii)=Tc2(iii-1);
    end;
    if Td1(iii)==0,
        Td1(iii)=Td1(iii-1);
    end;
    if Td2(iii)==0,
        Td2(iii)=Td2(iii-1);
    end;
    if pir1(iii)==0,
        pir1(iii)=pir1(iii-1);
    end;
    if pir2(iii)==0,
        pir2(iii)=pir2(iii-1);
    end;
    if psp1(iii)==0,
        psp1(iii)=psp1(iii-1);
    end;
    if psp2(iii)==0,
        psp2(iii)=psp2(iii-1);
    end;
    if Tvais(iii)==0,
        Tvais(iii)=Tvais(iii-1);
    end;
    if Rhvais(iii)==0,
        Rhvais(iii)=Rhvais(iii-1);
    end;
    if Tsea(iii)==0,
        Tsea(iii)=Tsea(iii-1);
    end;
end;

if length(Tvais)<60,
    Tvais=[Tvais Tvais(length(Tvais))+0.*(1:60-length(Tvais))];
end;
if length(Rhvais)<60,
    Rhvais=[Rhvais Rhvais(length(Rhvais))+0.*(1:60-length(Rhvais))];
end;
if length(Tsea)<60,
    Tsea=[Tsea Tsea(length(Tsea))+0.*(1:60-length(Tsea))];
end;
if length(psp1)<60,
    psp1=[psp1 psp1(length(psp1))+0.*(1:60-length(psp1))];
end;
if length(psp2)<60,
    psp2=[psp2 psp2(length(psp2))+0.*(1:60-length(psp2))];
end;
if length(pir1)<60,
    pir1=[pir1 pir1(length(pir1))+0.*(1:60-length(pir1))];
end;
if length(pir2)<60,
    pir2=[pir2 pir2(length(pir2))+0.*(1:60-length(pir2))];
end;
if length(org)<60,
    org=[org org(length(org))+0.*(1:60-length(org))];
end;
if length(qvais)<60,
    qvais=[qvais qvais(length(qvais))+0.*(1:60-length(qvais))];
end;
if length(Tvais)>60,
    Tvais=Tvais(1:60);
end;
if length(Rhvais)>60,
    Rhvais=Rhvais(1:60);
end;
if length(Tsea)>60,
    Tsea=Tsea(1:60);
end;
if length(psp1)>60,
    psp1=psp1(1:60);
end;
if length(pir1)>60,
    pir1=pir1(1:60);
end;
if length(psp2)>60,
    psp2=psp2(1:60);
end;
if length(pir2)>60,
    pir2=pir2(1:60);
end;
if length(org)>60,
    org=org(1:60);
end;
if length(qvais)>60,
    qvais=qvais(1:60);
end;
if length(Tvais)>60,
    Tvais=Tvais(1:60);
end;

end;
%clear jd jax jam jad j_st j_en hul hr hll g flist f eps_w e dmp blk backchk ans
%clear vul uul tzilch therm1 therm2 sul stz sty stx st2 st1 st0 sig_sb psp1 psp2 prtit prt_it plotit
%clear Tc1 Tc2 Td1 Td2 Tll Tsea Tul Tvais jazz m0 n0 nl1 np npz nr1 org pir1 pir2
%clear Rhvais Rlll Rlul Rsll Rsul Rtll Rtul
