-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad3.m
executable file
·178 lines (128 loc) · 3.46 KB
/
ad3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
flag=0;
dp=-10; %pressure step
pend=20000;
clear p T th thcs r theta
A=2.53e11;
epsilon=0.622;
B=5.42e3;
k=0.286;
L=2.5e6;
cp=1005;
%read in sounding
FileName='c:/documents and settings/user/my documents/cprogs/0302052040UTC.TXT';
fid=fopen(FileName,'rb');
txt=fscanf(fid,'%s',71);
dat=fscanf(fid,'%g',[12,108]);
Tdat=dat(6,:);
Pdat=dat(5,:);
THdat=(Tdat+273.13).*(1e3./Pdat).^k;
pstart=Pdat(1)*100;
tstart=Tdat(1)+273.13;
rhstart=dat(7,1); %relative humidity at ground (%)
T(1)=tstart;
p(1)=pstart;
thstart=T(1)*(1e5/p(1))^k;
iend=-fix( (pstart-pend)/dp )
esg=A*exp(-B/T(1)); %es at ground
wg=rhstart/100*esg*epsilon/p(1); %mixing ratio at ground=constant
for i=1:iend
dwsdp=-epsilon*A*exp(-B/T(i))/p(i)/p(i);
dwsdt=B*epsilon*A*exp(-B/T(i))/T(i)/T(i)/p(i);
es=A*exp(-B/T(i)); %saturation vapour pressure at T
e=p(i)*wg/epsilon; %vapour pressure at T
psc=0;
if e>es
psc=psc+1;
if psc==1
psati=i;
end
dTdp=( (k/p(i)) - (0.35*L*dwsdp/T(i)/cp) ) / ( (1/T(i)) + (0.35*L*dwsdt/T(i)/cp) );
T(i+1)=T(i)+dTdp*dp;
else
i
T(i+1)=thstart*(p(i)/1e5)^k;
end
p(i+1)=p(i)+dp;
end
th=T.*(1e5./p).^k;
%figure;
%plot(T,log(th));
hold on;
figure;
pcs=[1000 900 800 700 600 500 400 300 200]; %mb
ths=260:40:600;
thsfine=260:0.1:600;
ts=30:-10:-50;
size(pcs)
for i=1:ans(2)
thcs(i,:)=T.*(1e3./pcs(i)).^k;
%plot(T,log(thcs(i,:)));
hold on;
size(thcs);
siz=ans(2);
thi=atan( (thcs(1,siz) - thcs(1,1)) / ( log(T(siz))/log(10) - log(T(1))/log(10) ) );
%thi=0;
%thi= atan( log(thcs(1,siz)) / T(siz) ) - atan(log(thcs(1,1)) / T(1) );
[xx,yy]=rotatedan(log(T)/log(10),th,thi);
h=plot(xx,(yy),'r'); %pseudo-adiabat
[x,y]=rotatedan(log(T)/log(10),thcs(i,:),thi);
%r(i,:)=( (T.^2)+(log(thcs(i,:)).^2) ).^0.5;
%theta(i,:)=atan( log(thcs(i,:))./T );
h=plot( x,(y) );
%rotate(h,[0 0 1],a*180/pi);
h=text(x(fix(siz*19/20)),y(fix(siz*19/20)),num2str(pcs(i)));
%rotate(h,[0 0 1],a*180/pi);
%plot( r(i,:).*cos(theta(i,:)-thi) , log(r(i,:).*sin(theta(i,:)-thi)) );
end
clear x y
size(ths);
for i=1:ans(2)
[x,y]=rotatedan(log(T)/log(10),(ths(i)),thi);
h=plot( x,(y) );
%rotate(h,[0 0 1],a*180/pi);
h=text(x(fix(siz*8/20)),y(fix(siz*8/20)),num2str(ths(i)),'rotation',-19);
%rotate(h,[0 0 1],a*180/pi);
end
clear x y
size(thsfine);
siz=ans(2);
size(ts);
for i=1:ans(2)
[x,y]=rotatedan(log(273.13+ts(i))/log(10),thsfine,thi);
h=plot( x,(y) );
%rotate(h,[0 0 1],a*10*180/pi);
h=text(x(fix(siz*3/20)),y(fix(siz*3/20)),num2str(ts(i)));
%rotate(h,[0 0 1],a*180/pi);
end
thi
%rotate(h,[0 0 1],a*180/pi)
size(T);
%axis( [xx(ans(2)) xx(1) yy(1) yy(ans(2)) ] );
%set(gca,'XTicklabel','');
%set(gca,'YTicklabel','');
[x,y]=rotatedan(log(273.13+Tdat)/log(10),THdat,thi);
h=plot( x,(y),'kx'); %plot sounding
[a b]=size(th);
[a c]=size(THdat);
sati=find(abs(Pdat-850)<2);
clear tdiff;
for i=100:b
[a2 ay]=min(abs(th(i)-THdat));
tdiff(i-99)=abs(T(i)-273-Tdat(ay));
% if abs(tdiff(i)-0)<1e-10
% tdiff(i)=NaN;
% end
end
[a b]=min(tdiff);
b=b+99;
fprintf(1,'Cross-over pressure = %g\n',p(b)/100);
[c d]=min(abs(Pdat.*100-p(b)));
fprintf(1,'Cross-over height = %g',dat(4,d));
break;
rr=( (T.^2)+(log(th).^2) ).^0.5;
angle=atan( log(th)./T );
xx=rr.*cos(angle-thi);
yy=log(rr.*sin(angle-thi));
plot(xx,yy,'--','r');
size(T);
axis( [xx(ans(2)) xx(1) yy(1) yy(ans(2)) ] );