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

st1=[];st2=[];

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

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;

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

dfl=[way_rawdata,'\GOMECC\day',jd,'\P2_' jd hr];
disp(dfl)


flist=fopen(dfl,'r');
if flist>0,   					%if the file exists, 
   dmp=fgets(flist);
   %while feof(flist)==0,
     st1=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,inf]);
     [nr1,nl1]=size(st1);
      if nr1==77
  	      st2(:,jax:jax+nl1-1)=st1;
      	jax=jax+nl1;
	   else
   	   x=fgets(flist);
	   end;
  % end;
end;

psp1=st2(28,:);
psp2=st2(29,:);
org=st2(30,:);
Tvais=st2(24,:);
Rhvais=st2(25,:);
Tsea=st2(23,:);
Tc1=st2(19,:);
Td1=st2(20,:);
Tc2=st2(21,:);
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);

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

if length(Rhvais)<60,
   Rhvais=[Rhvais (1:(60-length(Rhvais))).*0+Rhvais(length(Rhvais))];
end;
if length(pir)<60,
   pir=[pir (1:(60-length(pir))).*0+pir(length(pir))];
end;
if length(psp)<60,
   psp=[psp (1:(60-length(psp))).*0+psp(length(psp))];
end;
if length(org)<60,
   org=[org (1:(60-length(org))).*0+org(length(org))];
end;
if length(Tvais)<60,
   Tvais=[Tvais (1:(60-length(Tvais))).*0+Tvais(length(Tvais))];
end;
if length(Tsea)<60,
   Tsea=[Tsea (1:(60-length(Tsea))).*0+Tsea(length(Tsea))];
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;

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

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 ', way_data, '\procturb\ss_',jd,hr,'.prn A -ascii'];
% save  (['C:\Program Files\MATLAB71\work\GOMECC\flux_data\procturb\ss_',jd,hr,'.prn'], 'A', '-ascii');
% %sdg='C:\Program Files\MATLAB71\work\GOMECC\flux_data\procturb\ss_',jd,hr,'.prn'
% disp(sdg)
% eval(sdg)
   
%disp('pause');pause