display(['pwv_sonde_07'])
% DEW 5/12/2007
% DEW 3/22/2008

clear all;
close all;

way_raw_sonde = 'c:\data\icealot\data\sonde\';
fname=['*.txt'];

s1=[way_raw_sonde fname];
s='m:\';
%s1=['c:\data\icealot\data\Mailbox\' fname];
dr=dir(s1);
[n m]=size(dr);
mx=n;

for i=1:mx  %loop through temp profile text files
    clear balt
   flnm=dr(i).name
%c:\data\icealot\data\sonde\ICEALOT_sonde_08_03_19_1831.txt
f=['c:\data\icealot\data\sonde\' flnm];
ss = [f];
balt = load(ss);

year = str2num(f(42:43)) + 2000;
month = str2num(f(45:46));
day = str2num(f(48:49));
hour = str2num(f(51:52));
minutes = str2num(f(53:54));
jd=datenum(year,month,day,hour,minutes,0)-datenum(year-1,12,31);

clear year month day hour minute

h=balt(:,2);
press=balt(:,3);
t=balt(:,4);
rh=balt(:,5);



e=6.112.*exp(17.67.*t./(t+243.5)).*rh./100; %vapor pressure pa
w=e.*622./(press-0.378*e); %mixing ratio g/kg
es=6.112.*exp(17.67.*t./(t+243.5));%pa


%now, adjust for vapor pressure over ice to determine where get ice clouds.
ice=find(t<=0);
es(ice)=(1.0003+4.18e-6*press(ice)).*6.1115.*exp(22.452.*t(ice)./(t(ice)+272.55));


wm=0.5*(w(1:end-1,:)+w(2:end,:));%take each layer and avg mixing ratio

wm=0.001*wm;%convert from g/kg to g/g to be dimensionless

ql=wm./(wm+1);% change to specific humidity

dpp=1000.*(press(1:end-1,:)-press(2:end,:));
%find pressure difference for each layer in dynes/cm^2, starting from mb

g=980.616;%accln due to gravity cm/s2

pw=(ql./g).*dpp; %% Precipitable water cm

tpw(i,1) = jd;
tpw(i,2) = nansum(pw); %cm

RHcorr=rh;
RHcorr(ice)=e(ice)./es(ice).*100;

end

figure(1)
clf
set(gcf,'defaultaxesfonts',18)
set(gca,'fontname','time','fontsize',18);
plot(tpw(:,1),tpw(:,2),'r')
hold
plot(tpw(:,1),tpw(:,2),'r*')
ylim([0 8])
xmin = fix(tpw(1,1));
xmax = fix(tpw(length(tpw),1)+1);
xlim([xmin xmax])
xlabel('Year Day (UTC)')
ylabel('Sonde PWV (cm)')
title('ICEALOT 2008')

if 0
print_buffer=['-djpeg90 f:/ICEALOT_2008/RHB/balloon/Processed_images/ICEALOT07_PWV_sonde.jpg']
eval(['print ' print_buffer])
end
save c:/data/icealot/data/sonde/ICEALOT_PWV_sonde tpw