disp('eval_ophir')
% Inputs data from ASCII data files
%  Note:  hhh=hour
fclose('all'); 
if hhh<10,
   dfx2=['0',num2str(hhh)];
else,
   dfx2=num2str(hhh);
end;

if ddd<10,
   dfx1=['00',num2str(ddd)];
elseif ddd<100,
   dfx1=['0',num2str(ddd)];
else,
   dfx1=num2str(ddd);
end;

dfx=[dfx1 dfx2];

%   Open OPHIR file
dfl=['D:\hp_data\day',num2str(ddd),'\P4_',dfx];       

flist=fopen(dfl,'r');
headr=fgetl(flist);
headr1=fgetl(flist);
%disp('     ###############     Ophir Evaluation     ###############     ')
z=fscanf(flist,'%g,%g,%g%g%g',[5,inf]);
if ~isempty(z);
   z=z(:,1:length(z)-1);
   t1=z(1,:)-z(1,1);t2=z(2,:)/10000-z(2,1)/10000;
   Oclear=z(4,:);Oabsorb=z(3,:);
%   ophx=input('Ophir number?  [89111 = 1;   89113 = 2;   andreas = 3]   ');
   ophx=3;
   tophir=t1+t2;clear t1 t2;
   if ophx==1,
      a0=1.039;
      a1=-.001364;
      ki=1/0.05215;
      bi=1/0.7288;
      disp('ophir 89111');%installed 126 1212
   elseif ophx==2,
      a0=.7643;
      a1=-.001664;
      ki=1/0.05161;
      bi=1/0.74;
      disp('ophir 89113');%installed 119, taken down 126 1212
   elseif ophx==3,
      a0=0.8095;
      a1=-.00051;
      ki=1/0.047;
      bi=1/0.7543;
%      disp('ophir andreas');%installed for nauru........unit # 93149
   end;
   a=a0*(1+a1*45);%45=Tcan+15
   x=(302.15/273.15)^1.54*(ki)^bi;%3012.15=Ta+273.15
   if Oclear(1)<=0,
      Oclear(1)=10;
   end;
   if Oabsorb(1)<=0,
      Oabsorb(1)=10;
   end;
   for ii=2:length(Oclear);
      if Oclear(ii)<=0,
         Oclear(ii)=Oclear(ii-1);
      end
      if Oabsorb(ii)<=0,
         Oabsorb(ii)=Oabsorb(ii-1);
      end
   end
   rc=Oabsorb./Oclear;
   abshum=x*(-log(rc/a)).^bi;
   abshum_mean=mean(abshum);

end;

if isreal(abshum)==0,
   abshum=real(abshum);
end;

[Oph,F]=psd2(detrend(abshum),length(abshum),20);
[Ophs,Fso]=specsmoo(Oph,20);
   
figure;loglog(Fso,Ophs.*Fso,Fso(length(Fso)-31:length(Fso)),((Fso(length(Fso)-31:length(Fso))).^(-2/3))./(Fso(length(Fso)-18).^(-2/3)).*Ophs(length(Fso)-18).*Fso(length(Fso)-18));
title(['Hygrometer Spectrum:   Day ',num2str(ddd),'   Hour ',num2str(hhh)]);
xlabel('Frequency in Hz');
ylabel('Spectrum * Frequency');
   
clear Oph F Ophs Fso abshum

clear Oabsorb Oclear a a0 a1 abshum abshum_mean ans bi dfl dfx dfx1 dfx2 flist
clear headr headr1 ii ki ophx rc tophir x z Oph F Fso Ophs
