-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetwind.asv
executable file
·467 lines (336 loc) · 10.7 KB
/
getwind.asv
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
function getwind(year,doybeg,doyend,write_file)
% READ WIND DATA for gui
%from NSSDC: 1-min MAG ASCII and 92-sec SWE ASCII
% Christian Möstl IWF March 2008
%makes a .MAT File in Folder GS-code\DATA
close all;
%clear
format compact;
format short;
disp('*********************** START ************************')
%%use to get DOY from date
%DOY=datenum(year,1,21,0,0,0)-datenum(year,0,0,0,0,0)
%%%%%%%%%%%%%%
%year=1996;
%doybeg=272; %73,74
%doyend=273;
%eg. DOY 140-144 covers 140,141,142,143
secres=120; %Common time resolution for the finally interpolated data
%write_file=0; % =1 if data is to be saved
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DOYbeg=datenum(year,0,doybeg,0,0,0);
datestr(DOYbeg)
datebeg=datevec(DOYbeg);
DOYend=datenum(year,0,doyend-1,23,59,0);
datestr(DOYend)
dateend=datevec(DOYend);
%%%%%%%%%%%%%%%%%%%%%%%%%%% MAG %%%%%%%%%%%%%%%%%%%%%%%%%%%%
scstring='win';
a=datenum(year, 0, doybeg, 0, 0, 0);
b=datevec(a);
if b(2) < 10
monthstr=['0',num2str(b(2))];
else
monthstr=num2str(b(2));
end
ndays=doyend-doybeg+1;
yearstr=num2str(year);
if doybeg < 100
doybegstr=['0',num2str(doybeg)];
else
doybegstr=num2str(doybeg);
end
if doyend < 100
doyendstr=['0',num2str(doyend)];
else
doyendstr=num2str(doyend);
end
%monthly mag files 1-min
strwin1=strcat(yearstr,monthstr,'_wind_mag_1min.asc')
%yearly swe files key parameters 2-min
strwin2=strcat('wind_kp_unspike',yearstr,'.txt')
time=clock;
time(4:6)
%%%load mag from the days of interest
cd('C:\chris\Data\WIND\NSSDC\mag\1min_ascii')
mfidata = load(strwin1);
sm=length(mfidata);
mday=mfidata(:,3);
indm1=find(mday ==datebeg(3));
indm2=find(mday ==dateend(3));
anfang=min(indm1);
ende=max(indm2);
myear=mfidata(anfang:ende,1);
mmonth=mfidata(anfang:ende,2);
mday=mfidata(anfang:ende,3);
mhour=mfidata(anfang:ende,4);
mmin=mfidata(anfang:ende,5);
msec=mfidata(anfang:ende,6);
mdata=mfidata(anfang:ende,:); %%%%%%%%%!!!!!!!!!!!!!!!!!!!!
%%%%%%%%%%%%%%%%%%%%%
%%%load swe from the days of interest
cd('C:\chris\Data\WIND\NSSDC\swe_kp_unspike')
swedata = load(strwin2);
sp=length(swedata);
pDOY=swedata(:,2);
%%% DOYs auslesen
indp1=find(pDOY > doybeg);
indp2=find(pDOY < doyend);
pdata=swedata(min(indp1):max(indp2),:); %%%%%%%%%!!!!!!!!!!!!!!!!!!!!
pDOY=swedata(min(indp1):max(indp2),2);
disp('Einlesen der Dateien fertig!')
time=clock;
time(4:6)
%%%%%%%%%%%%%%%%%%
cd('C:\chris\Matlab\GS-code')
disp('********************************************************')
%%%%%%%%%%%%%%% Physical constants [SI] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=1.38066*1e-23;
Mp=1.672623*1e-27;
mu0=4*pi*1e-7;
TtoeV=1.29*1e-4; % aus kT=E, umrechnen T[k] -> E in [eV]
Re=6378;
%%%%%%%%%%%%%%%%%%%% Bad data values %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%badmag=1000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mag
%1 Year I4
% 2 Month I3 01-12
% 3 Day I3 01-31
% 4 Hour I3 00-23
% 5 Min I3 00-59
% 6 Sec I3 at midpoint of average; typically 30
% 7 Bx,GSE F10.3 nT (same as Bx,GSM)
% 8 By,GSE F10.3 nT
% 9 Bz,GSE F10.3 nT
%fill values E10.2 and have the value -1.00E+31
%18 Rx,GSE F9.3 Re, GSE X component of Wind position vector
%19 Ry,GSE F9.3 Re, Re = Earth radii
%20 Rz,GSE F9.3 Re
%fill values E9.1 and have the value -1.0E+31
Bdata(:,1)=mdata(:,7);%Bx usw. nT
Bdata(:,2)=mdata(:,8);%Bx usw. nT
Bdata(:,3)=mdata(:,9);%Bx usw. nT
pos(:,1)=mdata(:,18);%Re GSE
pos(:,2)=mdata(:,19);
pos(:,3)=mdata(:,20);
%swe
%Wd Format Fill values Parameters
% 1 I5 9999 Year
% 2 F12.6 99999.9999999 Decimal Day (day.fractionofday)
% 3 F8.1 99999.9 Flow Speed, km/s
% 4 F8.1 99999.9 Vx, GSE, km/s, flow velocity component
% 5 F8.1 99999.9 Vy, GSE, km/s
% 6 F8.1 99999.9 Vz, GSE, km/s
% 7 F9.0 9999999. Proton Temperature, K.
% 8 F7.2 999.99 Proton Density, n/cc
vdata(:,1)=pdata(:,4); %vx km/s
vdata(:,2)=pdata(:,5); %vy km/s
vdata(:,3)=pdata(:,6); %vz km/s
%protons
T=pdata(:,7); %K
N=pdata(:,8); % 1/ccm
T=T/1e6; %T in 10^6 K;
%convert to Matlab datenumber
mDOY=datenum(myear,mmonth,mday,mhour,mmin,msec);
pDOY=pDOY+datenum(year,0,0,0,0,0);
badmag=-1.00E+31; %mag and pos from mag
badvel=99999.9; %swe
badT=9999999;
badN=999.99;
% interpolate fill values
Bmag=sqrt(Bdata(:,1).^2+Bdata(:,2).^2+Bdata(:,3).^2);% nT, GSE
[Ib,Jb]=find(Bdata(:,3)~=badmag & Bdata(:,2)~=badmag & Bdata(:,1)~=badmag & abs(Bmag) < 100);
if length(Ib) < length(mDOY) %Wenn Fehler drinnen -> interpolieren
Bdata=interp1(mDOY(Ib),Bdata(Ib,:),mDOY,'linear');
else Ib=0;
end
%disp(['bad mag data ',num2str(Ib)])
[Ip,Jp]=find(pdata(:,3)~=badvel);
if length(Ip) < length(pDOY)
vdata=interp1(pDOY(Ip),vdata(Ip,:),pDOY,'linear');
else Ip=0;
end
[Ip,Jp]=find(T~=badT & N~=badN);
if length(Ip) < length(pDOY)
N=interp1(pDOY(Ip),N(Ip),pDOY,'linear');
T=interp1(pDOY(Ip),T(Ip),pDOY,'linear');
else Ip=0;
end
%disp(['bad swe data ',num2str(Ip)])
%disp('1st')
%size(T)
%size(N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% linear interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%e - 92 sec.
%p, B - 3 sec
%1 DOY Vektor mit gewünschtem Abstand -> darauf alles interpolieren!!
DOYvec=[DOYbeg:(secres/(60*60*24)):DOYend]';
disp('stop')
Bdata=interp1(mDOY,Bdata,DOYvec,'linear');
vdata=interp1(pDOY,vdata,DOYvec,'linear');
N=interp1(pDOY,N,DOYvec,'linear');
T=interp1(pDOY,T,DOYvec,'linear');
disp('Interpolieren fertig!')
time=clock;
time(4:6)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vx=vdata(:,1); % km/s GSE
vy=vdata(:,2); % km/s GSE
vz=vdata(:,3); % km/s GSE
V=sqrt(vx.^2+vy.^2+vz.^2); % km/s GSE
bx=Bdata(:,1); % nT, GSE
by=Bdata(:,2); % nT, GSE
bz=Bdata(:,3); % nT, GSE
Bmag=sqrt(bx.^2+by.^2+bz.^2);% nT, GSE
Dt=[1:length(Bmag)]';
Dt(:)=secres;
[YY,MM,DD,hh,mm,sec]=datevec(DOYvec);
%zu Testzwecken
%clouddata=[round(MM) round(DD) round(YY) round(hh) round(mm) round(sec) Dt bx by bz Nnew Tnew vx vy vz Nenew Tenew];
clouddata=[double(MM) double(DD) double(YY) double(hh) double(mm) double(sec) double(Dt) double(bx) double(by) double(bz) double(N) double(T) double(vx) double(vy) double(vz)];% double(Ne) double(Te)];
% 1. und letzter Datenpunkt ist NaN (durch Interpolieren)
%clouddata=clouddata(2:1440,:);
if year > 1999
yearstr=num2str(year-2000);
yearstrout=['0',yearstr];
else
yearstrout=num2str(year-1900);
end
%e.g. winall291_95.mat
filestr=strcat(scstring,'all',doybegstr,'_',yearstrout);
%%%%%%%%%%%%%%%%%%%% DATEN RAUSSCHREIBEN %%%%%%%%%%%%%%%%%%
if write_file == 1
%outstr=strcat('c:\chris\Matlab\GS-code\DATA\winall', str(5:7),str(12:14),'_',num2str(secres),'.mat')
outstr=strcat('c:\chris\Matlab\GS-code\DATA\',filestr,'.mat')
save(outstr, 'clouddata');
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%T in [K] and N in [m-3]
N1=N*1e6; %[SI]
T1=T*1e6;
pressure=N1*k.*T1;%+Ne1*k.*Te1; %[Pa]
%N [cm-3] T [K]
%pressure2=N*1.381.*T*1e-8+Ne*1.381.*Te*1e-8;
Bpre=(Bmag*1e-9).^(2)/(2*mu0);
beta=pressure./Bpre;
Bmax=ceil(max(Bmag)/10)*10; %Plot-Obergrenzen für B,N,T,V
Nmax=ceil(max(N)/10)*10;
Tmax=ceil(max(T)/.1)*.1;
Vmax=ceil(max(V)/100)*100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DATEN DARSTELLEN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%
day1=DOYvec(1);
day2=DOYvec(length(DOYvec));
datestyle=1;
%%%%%%%%%%%%%%%%%%% B, T, N, V
figure;
subplot(311)
d=DOYvec;
plot(d,Bmag,d,clouddata(:,8:10));
title(['WIND MAG/SWE ',num2str(year)]);
set(gca, 'XTickLabel', []);
axis([day1 day2 -Bmax Bmax]);
grid on;
%datetick('x', 13);
legend('|B| [nT]', 'B_X', 'B_Y', 'B_Z');
subplot(312)
[ax,h1,h2]=plotyy(d, N, d, T*1e6, @semilogy);
axis(ax(1), [day1 day2 10^(-2) Nmax]);
set(ax(1), 'XTickLabel', []);
axis(ax(2), [day1 day2 10^(-3) Tmax]);
set(ax(2), 'XTickLabel', []);
legend([h1 h2], 'proton density [1/ccm]','proton Temp. [10^6 K]');
xlabel('Np & Tp')
%legend('Tp');
subplot(313)
plot(d, V,d, clouddata(:,13:15));
%datetick('x', datestyle,'keeplimits','keepticks');
axis([day1 day2 -Vmax Vmax]);
legend('V [km/s]', 'v_x', 'v_y', 'v_z');
grid on;
datetick('x', 6,'keeplimits','keepticks');
%%%%%%%%%%%%%%%%%%%%5
%figure;
%subplot(211)
%[ax,h1,h2]=plotyy(d, N, d, T, @semilogy);
%axis(ax(1), [day1 day2 10^(-2) Nmax]);
%axis(ax(2), [day1 day2 10^(-3) Tmax]);
%legend([h1 h2], 'proton density [1/ccm]','proton Temp. [10^6 K]');
%xlabel('Np & Tp')
%set(gca, 'XTickLabel', []);
%subplot(212)
%[ax,h1,h2]=plotyy(d, Na, d, Ta, @semilogy);
%axis(ax(1), [day1 day2 10^(-2) Nmax]);
%axis(ax(2), [day1 day2 10^(-3) Tmax]);
%legend([h1 h2], 'alpha density [1/ccm]','alpha Temp. [10^6 K]');
%xlabel('Na & Ta')
%%%%%%%%%%%%%%%%%%%%%%
figure;
subplot(211)
plot(d,Bmag,d,clouddata(:,8:10));
title(['WIND MAG/SWE ',num2str(year)]);
axis([day1 day2 -Bmax Bmax]);
grid on;
xlabel('B [nT] GSE');
legend('|B| [nT]', 'B_X', 'B_Y', 'B_Z');
datetick('x', 13,'keeplimits','keepticks');
subplot(212)
semilogy(d, beta)
axis([day1 day2 0 3]);
xlabel('proton beta');
grid on;
datetick('x', 6,'keeplimits','keepticks');
%semilogy(beta); axis([1 length(beta) 10^(-3) 10^2]);
%subplot(313)
%plot(V);axis([1 length(V) 0 Vmax]);
%plot(pressure*1e9);
%axis([1 length(pressure) 0 max(pressure)]);
%xlabel('plasma pressure [nPa]');
%datetick('x', datestyle);
%axis3=subplot(513);
%plot(Lambda); axis([1 length(Lambda) 0 360]);
%subplot(512)
%plot(Delta); axis([1 length(Delta) -90 90]);
adjp=0;
%Grenzen einlesen, stehen dann in CASE1.par
if write_file==1
[X,Y]=ginput(2);
%axes(axis3); Y=[1400; -980];
hbound=line([X'; X'], [Y Y]); set(hbound, 'Clipping', 'off','color',[0 0 0]);
i1=min(find(DOYvec>X(1)));
i2=max(find(DOYvec<X(2)));
X=[i1 i2 adjp] %adjp = 0 initially
cd('c:\chris\Matlab\GS-code')
%%% Directory für das Event erstellen
dirstr=strcat(scstring,'_',doybegstr,'_',doyendstr,'_',yearstrout);
if exist(dirstr, 'dir') == 0
[suc, mess, messid]=mkdir(dirstr);
suc
mess
end
cd(dirstr);
if exist('CASE1.par', 'file') == 0
parid=fopen('CASE1.par', 'wt');
fprintf(parid, '%s\n', [outstr]);
fclose(parid);
end
parid=fopen('CASE1.par', 'at');
fprintf(parid, '%i %i %i\n', X);
fclose(parid);
disp('mean position of WIND in the chosen interval (Re GSE):')
meanposx=mean(pos(X(1):X(2),1))
meanposy=mean(pos(X(1):X(2),2))
meanposz=mean(pos(X(1):X(2),3))
parid=fopen('winpos.txt', 'wt');
fprintf(parid, '%f %f %f\n', meanposx,meanposy,meanposz);
fclose(parid);
cd('..');
end
disp('mean position of WIND in Re GSE:')
meanposx=mean(pos(:,1))
meanposy=mean(pos(:,2))
meanposz=mean(pos(:,3))
pwd