disp('eval_pc_day_sjohnson_05')
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;
N15=[];N16=[];N17=[];N18=[];N19=[];N20=[];N21=[];N22=[];N41=[];
n15=[];n16=[];n17=[];n18=[];n19=[];n20=[];n21=[];n22=[];n41=[];

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=['d:\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 line
        while feof(flist)==0,
           stx=fgetl(flist);
           if length(stx)>15,
              if stx(15:17)==',09',
                  n15=str2num(stx(78:84));
                  n16=str2num(stx(88:94));
                  N15=[N15 n15];
                  N16=[N16 n16];
              end;
              if stx(15:17)==',17'
                  n17=str2num(stx(18:24));
                  n18=str2num(stx(28:34));
                  n19=str2num(stx(38:44));
                  n20=str2num(stx(48:54));
                  n21=str2num(stx(58:64));
                  n22=str2num(stx(68:74));
                  N17=[N17 n17];N18=[N18 n18];N19=[N19 n19];
                  N20=[N20 n20];N21=[N21 n21];N22=[N22 n22];
              end;
              if stx(15:17)==',41'
                  n41=str2num(stx(18:24));
                  N41=[N41 n41];
              end;
          end;       
        end;                        %end while feof
    end;                            %end if flist
end;                                %end for jam

Tc=N15-0.45;  %correct for bias, day 321
Td=N16-.1;    %correct for bias
Tsea=N17+0.06;   %correct for lead resistance 20C
Tvais=N18;
Rhvais=N19;
therm=N20;
psp=N21;
org=N22;
aspir_on=N41;                 %aspirator swich -5 means back flow

avgpsp=mean(psp)
avgrain=mean(org);
avgTvais=mean(Tvais)
avgRHvais=mean(Rhvais);
avgQvais=avgRHvais/100*qsea(avgTvais)
qvais=Rhvais./100.*qsea(Tvais);

pir=therm+sig_sb*(Tc+273.16).^4-4*sig_sb*((Td+273.16).^4-(Tc+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 Tc(iii)==0,
        Tc(iii)=Tc(iii-1);
    end;
    if Td(iii)==0,
        Td(iii)=Td(iii-1);
    end;
    if pir(iii)==0,
        pir(iii)=pir(iii-1);
    end;
    if psp(iii)==0,
        psp(iii)=psp(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 & length(Tvais)>0,
    Tvais=[Tvais Tvais(length(Tvais))+0.*(1:60-length(Tvais))];
end;
if length(Rhvais)<60 & length(Rhvais)>0,
    Rhvais=[Rhvais Rhvais(length(Rhvais))+0.*(1:60-length(Rhvais))];
end;
if length(Tsea)<60 & length(Tsea)>0,
    Tsea=[Tsea Tsea(length(Tsea))+0.*(1:60-length(Tsea))];
end;
if length(psp)<60 & length(psp)>0,
    psp=[psp psp(length(psp))+0.*(1:60-length(psp))];
end;
if length(pir)<60 & length(pir)>0,
    pir=[pir pir(length(pir))+0.*(1:60-length(pir))];
end;
if length(org)<60 & length(org)>0,
    org=[org org(length(org))+0.*(1:60-length(org))];
end;
if length(qvais)<60 & length(qvais)>0,
    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(psp)>60,
    psp=psp(1:60);
end;
if length(pir)>60,
    pir=pir(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;

%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
