disp('camp_yes.m')
disp('YES RAIN')

rain=(1:60).*0;

% Opens Channel #1 Oak Ridge, K-Gill, Lyman-alpha, Psychrometric sensors
% Inputs data from ASCII data files

%  Note:  hhh=hour

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];

%dfl=['/cdrom/DAY',dfx(1:3),'/P1_',dfx,';1'];       %H2O and CO2 channel

dfl=[drive,'\DAY',dfx(1:3),'\P1_',dfx];       %H2O and CO2 channel

flist=fopen(dfl,'r');
headr=fgetl(flist);%disp(headr)
headr=fgetl(flist);                    % get rid of first line of data .... 

z=fscanf(flist,'%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g',[13,inf]);

z=z(:,1:length(z)-1);
t1=z(1,:)-z(1,1);t2=z(2,:)/10000-z(2,1)/10000;
tcamp=t1+t2;clear t1 t2;

H2O=1.145.*(z(3,:).^2)+1.888.*z(3,:)+0.43;    %  [g/m3]
CO2=96.9.*z(4,:)+441;                         % [mg/m3]
%Tt=z(5,:).*28.1-8;
CO2=CO2(1:length(tcamp));
H2O=H2O(1:length(tcamp));
%Tt=Tt(1:length(tcamp));
%KGillTop=z(6,:)*13;
%KGillBot=z(7,:)*13;                   %Wind speed = (sqrt (KGillBot.^2 + KGillTop.^2) ) / 0.83
%KGillAzu=(z(8,:)-2.5)*71;         %0 deg is from bow ... 90 deg is from starboard 
%lyman=z(9,:);
Tdry=z(10,:)*10+15.5;              %ORIGINAL ELECTRONICS REPLACED JD006
Twet=z(11,:)*10+9.5;

% NEW CALIBRATION  01-08-97

if ddd>7,
  Tdry=z(10,:).*9.8371+14.9147;
  Twet=z(11,:).*9.4295+11.3186;
end; 

Rain=z(13,:);Rain=100.*(Rain.^2);   %before xxxxxx
for yy=1:length(Rain),if Rain(yy)<0.07, Rain(yy)=0;end;end;    %before xxxxxx

if length(Rain) < 71000,                                       %before xxxxxx
   Rain=[Rain (1:71000-length(Rain)).*0+Rain(length(Rain))];   %before xxxxxx
   plot(Rain);                                                 %before xxxxxx
end;                                                           %before xxxxxx

if length(Rain) >= 71000,                                      %before xxxxxx
   rain=(1:60).*0;                                             %before xxxxxx
   mm=1:1200;                                                  %before xxxxxx
   for pp=1:60;                                                %before xxxxxx
      ii=mm+1200*(pp-1);                                       %before xxxxxx
      if pp==60;                                               %before xxxxxx
         ii=length(Rain)-1200+1:length(Rain);                  %before xxxxxx
      end;                                                     %before xxxxxx
      rain(pp)=median(Rain(ii));                               %before xxxxxx
   end;                                                        %before xxxxxx
 rain=rain';                                                   %before xxxxxx
end;                                                           %before xxxxxx

%ss=['save /home/user1/hare/rain/r',dfx,'.dat rain -ascii'];%disp(ss);
%eval(ss);clear ss mm ii;

[Quw,Qsuw,RHuw]=q_gkg(Tdry,Twet);      %Tdry and Twet can be corrected for response
                                  % time with the speed_T function (Serhad Atakturk)
%Tref=z(12,:)/0.0021-273.15;

clear Qsuw RHuw

%if abs(Quw(1))>99,
%   Quw(1)=0;
%end;
%if abs(CO2(1))>999,
%   CO2(1)=0;
%end;
%if abs(H2O(1))>99,
%   H2O(1)=0;
%end;

%for jj=2:length(tcamp);
%   if abs(Quw(jj))>999,
%      Quw(jj)=Quw(jj-1);
%   end;
%   if abs(CO2(jj))>999,
%      CO2(jj)=CO2(jj-1);
%   end;
%   if abs(H2O(jj))>999,
%      H2O(jj)=H2O(jj-1);
%  end;
%end;

H2O=medfilt1(H2O);
CO2=medfilt1(CO2);
Quw=medfilt1(Quw);


%Fc=1;bc=Fc/10;[bf af]=butter(2,bc);

%Qs=filtfilt(bf,af,Q);

%figure;plot(tcamp,H2O);title(['JD',dfx1,' Hr',dfx2,' UTC  Oak Ridge H2O']);ylabel('g/m^3');xlabel('time in sec')
%figure;plot(tcamp,CO2);title(['JD',dfx1,' Hr',dfx2,' UTC  Oak Ridge CO2']);ylabel('mg/m^3');xlabel('time in sec')
%figure;plot(tcamp,Tt);title(['JD',dfx1,' Hr',dfx2,' UTC  Oak Ridge T']);ylabel('degrees');xlabel('time in sec')
%figure;plot(tcamp,KGillTop,tcamp,KGillBot);title(['JD',dfx1,' Hr',dfx2,' UTC  K-Gill']);ylabel('wind speed in m/s');xlabel('time in sec')
%figure;plot(tcamp,KGillAzu);title(['JD',dfx1,' Hr',dfx2,' UTC  K-Gill Azimuth']);ylabel('degrees');xlabel('time in sec')
%figure;plot(tcamp,lyman);title(['JD',dfx1,' Hr',dfx2,' UTC  Lyman-alpha']);ylabel('lyman-alpha Volts');xlabel('time in sec')
%figure;plot(tcamp,Tdry,tcamp,Twet);title(['JD',dfx1,' Hr',dfx2,' UTC  Tdry/Twet']);ylabel('degrees');xlabel('time in sec')
%figure;plot(1:length(rain),rain);title(['JD',dfx1,' Hr',dfx2,' UTC  Rainfall in mm/hr']);ylabel('millimeters per hour');xlabel('time in min')

%ts=(0:specsize/2-1);ts=1/((specsize/2-1)./10)+ts*(10-1/((specsize/2-1)./10));ts=ts';
%Ch2=psd(detrend(H2O),specsize);[Ch1,FF]=specsmoo(Ch2,20);
%Cco=psd(detrend(CO2),specsize);[Cc1,FF]=specsmoo(Cco,20);
%Ctt=psd(detrend(Tt),specsize);[Ct1,FF]=specsmoo(Ctt,20);
%Ckt=psd(detrend(KGillTop),specsize);[Ckt1,FF]=specsmoo(Ckt,20);
%Ckb=psd(detrend(KGillBot),specsize);[Ckb1,FF]=specsmoo(Ckb,20);
%Cly=psd(detrend(lyman),specsize);[Cly1,FF]=specsmoo(Cly,20);
%Ctd=psd(detrend(Tdry),specsize);[Ctd1,FF]=specsmoo(Ctd,20);
%Ctw=psd(detrend(Twet),specsize);[Ctw1,FF]=specsmoo(Ctw,20);
%Ctr=psd(detrend(Tref),specsize);[Ctr1,FF]=specsmoo(Ctr,20);
%figure;loglog(FF,Cc1.*FF);title(['JD',dfx1,' Hr',dfx2,' UTC  Spectrum Oak Ridge CO2']);ylabel('F*S(co2)');xlabel('freq in Hz')
%figure;loglog(FF,Ch1.*FF);title(['JD',dfx1,' Hr',dfx2,' UTC  Spectrum Oak Ridge H2O']);ylabel('F*S(h2o)');xlabel('freq in Hz')
%figure;loglog(FF,Ct1.*FF);title(['JD',dfx1,' Hr',dfx2,' UTC  Spectrum Oak Ridge T']);ylabel('F*S(tt)');xlabel('freq in Hz')
%figure;loglog(FF,Ckt1.*FF,FF,Ckb1.*FF);title(['JD',dfx1,' Hr',dfx2,' UTC  Spectra KGill Top(yel) & Bot(mag)']);ylabel('F*S(kg)');xlabel('freq in Hz')
%figure;loglog(FF,Ctd1.*FF,FF,Ctw1.*FF);title(['JD',dfx1,' Hr',dfx2,' UTC  Spectra Tdry(yel) & Twet(mag)']);ylabel('F*S(t)');xlabel('freq in Hz')
clear Cc Cc1 Ct Ct1 Tt Ch Ch1 Ckt Ckt1 Ckb Ckb1 Cly Cly1 Ctd Ctd1 Ctw Ctw1 Ctr Ctr1
clear Cco Ch2 Ctt FF ans dfx dfx2 headr jj specsize ts z dfx1
clear KGillAzu KGillBot KGillTop Twet lyman tcamp
clear Rain ii mm pp yy ans

%figure;plot(rain)
%sfl=['save d:\labsea\r_',dfl(14:18),'.prn rain -ascii'];
%eval(sfl)
fclose(flist);