disp('read_hp_AMMA08_2008.m')
fclose('all');

if ddd>99,
   jd=num2str(ddd);
else   
   jd=['0',num2str(ddd)];
end;

g=0.0098;						%adiabatic lapse rate
sig_sb=5.67e-8;				%Stefan Boltzmann constant
jax=1;

jam=hhh;
if jam<10,
   hr=['0',num2str(jam)];
else
   hr=num2str(jam);
end;

dfl=['C:\Data\AMMA\day',jd,'\met008',jd ,hr ,'_raw.txt'];
disp(dfl)
st2=[];
flist=fopen(dfl,'r');
if flist>0,   					%if the file exists, 
%    while feof(flist)==0,
         stx =textscan(flist,'%2f%2f%3f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %*[^\n]', 'delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN,'treatAsEmpty', 'Radiometers & Mean Met');
%        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

       stx=cell2mat(stx)';
       [nr1,nl1]=size(stx);
       if nr1==79
           st2(:,jax:jax+nl1-1)=stx;
           jax=jax+nl1;
       else
   	   x=fgets(flist);
	   end;
%    end;
end;

press=st2(36,:);    %pressure (mbar)
psp1=st2(30,:);
psp2=st2(31,:);
org=st2(32,:);
Tvais=st2(26,:);
Rhvais=st2(27,:);
Tsea=st2(25,:);
Tc1=st2(21,:);
Td1=st2(22,:);
Tc2=st2(23,:);
Td2=st2(24,:);
therm1=st2(28,:);
therm2=st2(29,:);
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);

pir=(pir1+pir2)/2;
psp=(psp1+psp2)/2;
clear psp1 psp2 pir2 pir1

if length(Rhvais)<60,
   Rhvais=[Rhvais (1:(60-length(Rhvais))).*0+NaN];
end;
if length(pir)<60,
   pir=[pir (1:(60-length(pir))).*0+NaN];
end;
if length(psp)<60,
   psp=[psp (1:(60-length(psp))).*0+NaN];
end;
if length(org)<60,
   org=[org (1:(60-length(org))).*0+NaN];
end;
if length(Tvais)<60,
   Tvais=[Tvais (1:(60-length(Tvais))).*0+NaN];
end;
if length(Tsea)<60,
   Tsea=[Tsea (1:(60-length(Tsea))).*0+NaN];
end;
if length(press)<60,
   press=[press (1:(60-length(press))).*0+NaN];
end;

if length(Rhvais)>60,
   Rhvais=Rhvais(1:60);
end;
if length(pir)>60,
   pir=pir(1:60);
end;
if length(psp)>60,
   psp=psp(1:60);
end;
if length(org)>60,
   org=org(1:60);
end;
if length(Tvais)>60,
   Tvais=Tvais(1:60);
end;
if length(Tsea)>60,
   Tsea=Tsea(1:60);
end;
if length(press)>60,
   press=press(1:60);
end;

if clearit
clear jax jam jad j_st j_en hul hll g flist f eps_w dfl dmp blk backchk ans
clear vul uul tzilch therm1 therm2 sul stz sty stx st2 st1 st0 sig_sb prtit prt_it plotit
clear Tc1 Tc2 Td1 Td2 Tll Tul jazz m0 n0 nl1 np npz nr1 Rlll Rlul Rsll Rsul Rtll Rtul
end;
Rs_1=mean(psp(1:10));
Rs_2=mean(psp(11:20));
Rs_3=mean(psp(21:30));
Rs_4=mean(psp(31:40));
Rs_5=mean(psp(41:50));
Rs_6=mean(psp(51:60));
stdRs_1=std(psp(1:10));
stdRs_2=std(psp(11:20));
stdRs_3=std(psp(21:30));
stdRs_4=std(psp(31:40));
stdRs_5=std(psp(41:50));
stdRs_6=std(psp(51:60));

A=[Rs_1 stdRs_1
   Rs_2 stdRs_2
   Rs_3 stdRs_3
   Rs_4 stdRs_4
   Rs_5 stdRs_5
   Rs_6 stdRs_6];
   
sdg=['save ', drive_w, '\procturb\ss_',jd,hr,'.prn A -ascii'];

disp(sdg)
eval(sdg)