[go: up one dir, main page]

Menu

[73c35b]: / anal / mat2hdf5.m  Maximize  Restore  History

Download this file

636 lines (584 with data), 27.9 kB

  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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
% Generate an EISCAT HDF5-file from mat-files generated in a Guisdap analysis
function [storepath,EISCAThdf5file] = mat2hdf5(matpath, datapath,addfigs,addnotes)
global path_GUP result_path name_ant
name_ant = [];
if nargin<4, addnotes = []; else addnotes = 1; end
if nargin<3, addfigs = []; else addfigs = 1; end
if nargin==1, error('Not enough input parameters, path to matfiles folder and path to datastore folder needed'); end
if nargin<1
matpath = result_path;
datapath = result_path;
end
if isstring(datapath)
datapath = char(datapath); % need to be char class
end
filelist = dir(fullfile(matpath,'*.mat'));
rec = length(filelist);
gupfile = fullfile(matpath,'.gup');
gupfilecheck = dir(gupfile);
matfile_1 = fullfile(matpath,filelist(1).name);
load(matfile_1);
% store the gfd content
s = [];
if exist('r_gfd','var')
%matfile.metadata.gfd = r_gfd;
gfd_Fields = fieldnames(r_gfd);
for gf = gfd_Fields.'
if strcmp(gf,'extra')
extra=r_gfd.extra;
for r = 1:size(extra,1)
if contains(extra(r,:),'%')
s = [s r];
end
end
extra(s,:)=[];
if ~isempty(extra)
matfile.metadata.gfd.extra = {row([extra ones(size(extra,1))*'#']')};
else
matfile.metadata.gfd.extra = {'None'};
end
elseif ~ischar(r_gfd.(char(gf)))
matfile.metadata.gfd.(char(gf)) = {num2str(r_gfd.(char(gf)))};
else
matfile.metadata.gfd.(char(gf)) = {r_gfd.(char(gf))};
end
end
intper_med = median(r_gfd.intper);
matfile.metadata.gfd.intper_median = {num2str(intper_med)};
elseif ~isempty(gupfilecheck)
load('-mat',gupfile);
if exist('name_expr','var'), matfile.metadata.gfd.name_expr = {name_expr}; end
if exist('expver','var'), matfile.metadata.gfd.expver = {num2str(expver)}; end
if exist('siteid','var'), matfile.metadata.gfd.siteid = {num2str(siteid)}; end
if exist('data_path','var'), matfile.metadata.gfd.data_path = {data_path}; end
if exist('result_path','var'), matfile.metadata.gfd.result_path = {result_path}; end
if exist('intper','var'), matfile.metadata.gfd.intper = {num2str(intper)};
intper_med = median(intper); matfile.metadata.gfd.intper_median = {num2str(intper_med)}; end
if exist('t1','var'), matfile.metadata.gfd.t1 = {num2str(t1)}; end
if exist('t2','var'), matfile.metadata.gfd.t2 = {num2str(t2)}; end
if exist('rt','var'), matfile.metadata.gfd.rt = {num2str(rt)}; end
if exist('figs','var'), matfile.metadata.gfd.figs = {num2str(figs)}; end
if exist('path_exps','var'), matfile.metadata.gfd.path_exps = {path_exps}; end
if exist('extra','var')
for r = 1:size(extra,1)
if contains(extra(r,:),'%')
s = [s r];
end
end
extra(s,:)=[];
if ~isempty(extra)
matfile.metadata.gfd.extra = {row([extra ones(size(extra,1))*'#']')};
else
matfile.metadata.gfd.extra = {'None'};
end
end
else
intper_vec = zeros(rec,1);
for tt = 1:rec
matfile_tmp = fullfile(matpath,filelist(tt).name);
load(matfile_tmp)
intper_vec(tt) = posixtime(datetime(r_time(2,1:6)))-posixtime(datetime(r_time(1,1:6)));
intper_med = median(intper_vec);
end
end
software = 'https://git.eiscat.se/cvs/guisdap9';
level2_link = '';
matfile.metadata.software_link = {software};
if ~isempty(level2_link)
matfile.metadata.level2_links = {level2_link};
end
year = num2str(r_time(1,1));
month = sprintf('%02d',r_time(1,2));
day = sprintf('%02d',r_time(1,3));
hour = sprintf('%02d',r_time(1,4));
minute = sprintf('%02d',r_time(1,5));
second = sprintf('%02.f',r_time(1,6));
if strcmp(matpath(end),'/')
matpath = matpath(1:end-1);
end
[~,matfolder] = fileparts(matpath);
dd_ = strfind(matfolder,'_');
ddat = strfind(matfolder,'@');
dd = sort([dd_ ddat]);
if length(dd)==4
name_expr_more = [matfolder(dd(2)+1:dd(3)-1) '_'];
else
name_expr_more = [];
end
ant = matfolder(dd(end)+1:end);
if isempty(name_ant)
switch name_site
case 'L', if isempty(str2num(ant)), name_ant = ant; else name_ant = 'esr'; end
case 'K', name_ant = 'kir';
case 'T', name_ant = 'uhf';
case 'S', name_ant = 'sod';
case 'V', name_ant = 'vhf';
case 'Q', name_ant = 'quj';
end
end
datafolder = ['EISCAT_' year '-' month '-' day '_' name_expr '_' name_expr_more num2str(intper_med) '@' name_ant];
%display(datafolder)
storepath = fullfile(datapath,datafolder);
if exist(storepath)
rmdir(storepath,'s');
end
mkdir(storepath);
Hdf5File = sprintf('%s%s',datafolder,'.hdf5');
MatFile = sprintf('%s%s',datafolder,'.mat');
hdffilename = fullfile(storepath,Hdf5File);
matfilename = fullfile(storepath,MatFile);
EISCAThdf5file = hdffilename;
GuisdapParFile = fullfile(path_GUP,'matfiles','Guisdap_Parameters.xlsx'); % path to the .xlsx file
if exist(hdffilename)==2, delete(hdffilename); end
% 0d and 1d parameters
parameters_1d = {'h_time' 'h_ver' 'h_Magic_const' 'h_az' 'h_el' 'h_Pt' 'h_SCangle'...
'h_XMITloc' 'h_RECloc' 'h_Tsys' 'h_code' 'h_om0' 'h_m0' 'h_phasepush'...
'h_Offsetppd' 'h_gain' 'h_fradar'};
% 2d parameters
parameters_2d = {'h_h' 'h_range' 'h_param' 'h_error' 'h_apriori'...
'h_apriorierror' 'h_status' 'h_dp' 'h_res' 'h_w'};
% 2d_pp parameters
parameters_2dpp = {'h_pprange' 'h_pp' 'h_pperr' 'h_ppw'};
[~,text] = xlsread(GuisdapParFile);
parameters_list = text(:,1); % list that includes all Guisdap parameters and keep their positions from the excel arc
matfile.metadata.header= text(1,1:7)';
nn1 = 0;
[uniom0,unigain,unifradar] = deal(0);
for ii = 1:length(parameters_1d)
h_name1 = char(parameters_1d(ii));
if ~exist(['r_' h_name1(3:end)],'var')
continue
elseif strcmp(h_name1,'h_time')
a = find(strcmp(h_name1,parameters_list)==1);
for jj = 1:2; nn1 = nn1+1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(1) = {[h_name1(3:end) num2str(jj)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par1d(:,nn1) = info';
end
elseif strcmp(h_name1,'h_XMITloc')
a = find(strcmp(h_name1,parameters_list)==1);
for jj = 1:3; nn1 = nn1+1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(1) = {[h_name1(3:end) num2str(jj)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par1d(:,nn1) = info';
end
elseif strcmp(h_name1,'h_RECloc')
a = find(strcmp(h_name1,parameters_list)==1);
for jj = 1:3; nn1 = nn1+1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(1) = {[h_name1(3:end) num2str(jj)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par1d(:,nn1) = info';
end
elseif strcmp(h_name1,'h_om0') && length(unique(eval(['r_om0']))) == 1
nn1 = nn1+1;
uniom0 = 1;
a = find(strcmp(h_name1,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {[h_name1(3:end)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
elseif strcmp(h_name1,'h_gain') && length(unique(eval(['r_gain']))) == 1
nn1 = nn1+1;
unigain = 1;
a = find(strcmp(h_name1,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {[h_name1(3:end)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
elseif strcmp(h_name1,'h_fradar') && length(unique(eval(['r_fradar']))) == 1
nn1 = nn1+1;
unifradar = 1;
a = find(strcmp(h_name1,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {[h_name1(3:end)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
elseif length(eval(['r_' h_name1(3:end)]))==1
nn1 = nn1+1;
a = find(strcmp(h_name1,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {h_name1(3:end)};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
else
num = length(eval(['r_' h_name1(3:end)]));
a = find(strcmp(h_name1,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
for jj = 1:num; nn1 = nn1+1;
info(1) = {[h_name1(3:end) num2str(jj)]};
matfile.metadata.par1d(:,nn1) = info';
end
end
end
% adding record lengths
nn1 = nn1 + 1;
a = find(strcmp('nrec',parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
nn1 = nn1 + 1;
a = find(strcmp('nrec_pp',parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par1d(:,nn1) = info';
nn2 = 0;
for ii = 1:length(parameters_2d)
h_name2 = char(parameters_2d(ii));
if ~exist(['r_' h_name2(3:end)],'var')
continue
end
dim=size(eval(['r_' h_name2(3:end)]));
if dim(2)==1
nn2 = nn2 + 1;
a = find(strcmp(h_name2,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {h_name2(3:end)};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par2d(:,nn2) = info';
elseif strcmp(h_name2,'h_param') || strcmp(h_name2,'h_error') || strcmp(h_name2,'h_apriori') || strcmp(h_name2,'h_apriorierror')
a = find(strcmp(h_name2,parameters_list)==1);
if strcmp(h_name2,'h_apriori') || strcmp(h_name2,'h_apriorierror')
nump = length(r_apriori(1,:));
else
nump = length(r_param(1,:));
end
for jj = 1:5; nn2 = nn2 + 1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par2d(:,nn2) = info';
end
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj+1) ':E' num2str(a+jj+1)]); info_tmp = info;
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj+1)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj+1)])) };
if ge(nump,6)
for kk=1:length(r_m0)-1; nn2 = nn2 + 1;
if (length(r_m0)-1)>1
info(1) = {[char(info_tmp(1)) num2str(kk)]};
end
if r_m0(kk)==30.5
if strcmp(h_name2,'h_param'), info(2)={'ion mix content: [O2+,NO+]/N'}; info(5)={'pm'}; info(6)={'690'};
elseif strcmp(h_name2,'h_error'), info(2)={'error ion mix content: [O2+,NO+]/N'}; info(5)={'dpm'}; info(6)={'-690'};
elseif strcmp(h_name2,'h_apriori'), info(2)={'a priori ion mix content: [O2+,NO+]/N'}; info(5)={'N/A'}; info(6)={'0'};
elseif strcmp(h_name2,'h_apriorierror'), info(2)={'a priori error ion mix content: [O2+,NO+]/N'}; info(5)={'N/A'}; info(6)={'0'};
end
elseif r_m0(kk)==16
if strcmp(h_name2,'h_param'), info(2)={'O+ content: [O+]/N'}; info(5)={'po+'}; info(6)={'620'};
elseif strcmp(h_name2,'h_error'), info(2)={'error O+ content: [O+]/N'}; info(5)={'dpo+'}; info(6)={'-620'};
elseif strcmp(h_name2,'h_apriori'), info(2)={'a priori O+ content: [O+]/N'}; info(5)={'N/A'}; info(6)={'0'};
elseif strcmp(h_name2,'h_apriorierror'), info(2)={'a priori error O+ content: [O+]/N'}; info(5)={'N/A'}; info(6)={'0'};
end
end
matfile.metadata.par2d(:,nn2) = info';
end
if isempty(kk); kk=0; end
for ll = (jj + 2):nump; nn2 = nn2 + 1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+ll) ':E' num2str(a+ll)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+ll)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+ll)]))};
matfile.metadata.par2d(:,nn2) = info';
end
end
if strcmp(h_name2,'h_error')
a = find(strcmp('crossvar',parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
for jj = 1:nump-1
for kk = 1:nump-jj; nn2 = nn2 + 1;
info(1) = {['crossvar_' num2str(kk) num2str(kk+jj)]};
info(2) = {['cross variance (p' num2str(kk) ',p' num2str(kk+jj) ')']};
matfile.metadata.par2d(:,nn2) = info';
end
end
end
elseif strcmp(h_name2,'h_res')
a = find(strcmp(h_name2,parameters_list)==1);
for jj = 1:2; nn2 = nn2+1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(1) = {[h_name2(3:end) num2str(jj)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par2d(:,nn2) = info';
end
elseif strcmp(h_name2,'h_w')
a = find(strcmp(h_name2,parameters_list)==1);
for jj = 1:3; nn2 = nn2+1;
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a+jj) ':E' num2str(a+jj)]);
info(1) = {[h_name2(3:end) num2str(jj)]};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a+jj)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a+jj)]))};
matfile.metadata.par2d(:,nn2) = info';
end
else
a = find(strcmp(parameters_2d(ii),parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
for jj = 1:dim(2); nn2 = nn2 + 1;
info(1) = {[h_name2(3:end) num2str(jj)]};
matfile.metadata.par2d(:,nn2) = info';
end
end
end
nn3 = 0;
for ii = 1:length(parameters_2dpp)
h_name2pp = char(parameters_2dpp(ii));
if ~exist(['r_' h_name2pp(3:end)],'var')
continue
end
nn3 = nn3 + 1;
a = find(strcmp(h_name2pp,parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(1) = {h_name2pp(3:end)};
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
matfile.metadata.par2d_pp(:,nn3) = info';
end
parameters = [parameters_1d parameters_2d parameters_2dpp];
nh = [];
npprange = [];
for ii = 1:length(parameters)
h_name = char(parameters(ii));
if ~exist(['r_' h_name(3:end)],'var')
evalc([h_name '=[]']); continue
else
par = [];
for jj = 1:rec
matfile_tmp = fullfile(matpath,filelist(jj).name);
load(matfile_tmp)
if strcmp(h_name,'h_time')
par = [par; posixtime(datetime(r_time(1,:))) posixtime(datetime(r_time(2,:)))]; % unix time
elseif strcmp(h_name,'h_Tsys')
par = [par; eval(['r_' h_name(3:end)])'];
elseif strcmp(h_name,'h_h')
nh = [nh; length(r_h)];
par = [par; eval(['r_' h_name(3:end)])];
elseif strcmp(h_name,'h_pprange')
npprange = [npprange; length(r_pprange)];
par = [par; eval(['r_' h_name(3:end)])];
elseif strcmp(h_name,'h_om0') && uniom0 == 1
r_om0 = r_om0(1);
par = [par; eval(['r_' h_name(3:end)])];
elseif strcmp(h_name,'h_gain') && unigain == 1
r_gain = r_gain(1);
par = [par; eval(['r_' h_name(3:end)])];
elseif strcmp(h_name,'h_fradar') && unifradar == 1
r_fradar = r_fradar(1);
par = [par; eval(['r_' h_name(3:end)])];
else
par = [par; eval(['r_' h_name(3:end)])];
end
end
evalc([char(parameters(ii)) '=par']);
end
end
%keyboard
matfile.data.par1d = [h_time h_ver h_Magic_const h_az h_el h_Pt...
h_SCangle h_XMITloc h_RECloc h_Tsys h_code h_om0 h_m0...
h_phasepush h_Offsetppd h_gain h_fradar nh npprange];
matfile.data.par2d = [h_h h_range h_param h_error h_apriori...
h_apriorierror h_status h_dp h_res h_w];
matfile.data.par2d_pp = [h_pprange h_pp h_pperr h_ppw];
parameters_special = {'h_om' 'h_lag' 'h_spec' 'h_freq' 'h_acf' 'h_ace'};
for ii = 1:length(parameters_special)
h_name = parameters_special{ii};
name = h_name(3:end);
if exist(['r_' name],'var')
a = find(strcmp(parameters_special{ii},parameters_list)==1);
[~,~,info] = xlsread(GuisdapParFile,1,['A' num2str(a) ':E' num2str(a)]);
info(6:7) = {num2str(xlsread(GuisdapParFile,1,['F' num2str(a)])) num2str(xlsread(GuisdapParFile,1,['G' num2str(a)]))};
if isempty(info{6}), info{6} = '0'; end
if isempty(info{7}), info{7} = '0'; end
matfile.metadata.(name) = info';
par = [];
for jj = 1:rec
matfile_tmp = fullfile(matpath,filesep,filelist(jj).name);
load(matfile_tmp)
par = [par; eval(['r_' name])'];
end
matfile.data.(name) = par;
end
end
k = length(matfile.data.par2d(1,:));
n = length(matfile.data.par1d(1,:));
index = [];
pp = 0;
for ii = 1:k
if length(matfile.data.par2d(:,ii))==length(filelist)
pp = pp +1;
matfile.data.par1d(:,n+pp) = matfile.data.par2d(:,ii);
matfile.metadata.par1d(:,n+pp) = matfile.metadata.par2d(:,ii);
index = [index ii];
end
end
matfile.data.par2d(:,index) = [];
matfile.metadata.par2d(:,index) = [];
n = length(matfile.data.par1d(1,:)); % now possibly a new length
mm=0;
index = [];
for ii = 1:n
if length(unique(round(matfile.data.par1d(:,ii),4)))==1 || sum(isfinite(matfile.data.par1d(:,ii))) == 0
mm = mm + 1;
value = matfile.data.par1d(1,ii);
matfile.data.par0d(mm) = value;
matfile.metadata.par0d(:,mm) = matfile.metadata.par1d(:,ii);
index = [index ii];
end
end
matfile.data.par1d(:,index) = [];
matfile.metadata.par1d(:,index) = [];
nn = 0;
if exist('name_expr','var'); nn = nn + 1;
infoname(1) = {'name_expr'};
infoname(2) = {name_expr};
a = find(strcmp('name_expr',parameters_list)==1);
[~,~,infodesc] = xlsread(GuisdapParFile,1,['B' num2str(a)]);
infoname(3) = infodesc;
matfile.metadata.names(:,nn) = infoname';
end
if exist('name_site','var'); nn = nn + 1;
infoname(1) = {'name_site'};
infoname(2) = {name_site};
a = find(strcmp('name_site',parameters_list)==1);
[~,~,infodesc] = xlsread(GuisdapParFile,1,['B' num2str(a)]);
infoname(3) = infodesc;
matfile.metadata.names(:,nn) = infoname';
end
if exist('name_ant','var'); nn = nn + 1;
infoname(1) = {'name_ant'};
infoname(2) = {name_ant};
a = find(strcmp('name_ant',parameters_list)==1);
[~,~,infodesc] = xlsread(GuisdapParFile,1,['B' num2str(a)]);
infoname(3) = infodesc;
matfile.metadata.names(:,nn) = infoname';
end
if exist('name_sig','var'); nn = nn + 1;
infoname(1) = {'name_sig'};
infoname(2) = {name_sig};
a = find(strcmp('name_sig',parameters_list)==1);
[~,~,infodesc] = xlsread(GuisdapParFile,1,['B' num2str(a)]);
infoname(3) = infodesc;
matfile.metadata.names(:,nn) = infoname';
end
aa = find(cellfun('isempty',matfile.metadata.par0d(6,:))); matfile.metadata.par0d(6,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par0d(7,:))); matfile.metadata.par0d(7,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par1d(6,:))); matfile.metadata.par1d(6,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par1d(7,:))); matfile.metadata.par1d(7,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par2d(6,:))); matfile.metadata.par2d(6,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par2d(7,:))); matfile.metadata.par2d(7,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par2d_pp(6,:))); matfile.metadata.par2d_pp(6,aa)= {'0'};
aa = find(cellfun('isempty',matfile.metadata.par2d_pp(7,:))); matfile.metadata.par2d_pp(7,aa)= {'0'};
symbols = ['a':'z' 'A':'Z' '0':'9'];
strLength = 10;
nums = randi(numel(symbols),[1 strLength]);
randstr = symbols(nums);
PID = ['doi://eiscat.se/3a/' year month day hour minute second '/' randstr];
matfile.metadata.schemes.DataCite.Identifier = {PID};
matfile.metadata.schemes.DataCite.Creator = {'Ingemar Häggström'};
matfile.metadata.schemes.DataCite.Title = {datafolder};
matfile.metadata.schemes.DataCite.Publisher = {'EISCAT Scientific Association'};
matfile.metadata.schemes.DataCite.ResourceType = {'dataset/Level 3 Ionosphere'};
if exist('name_sig')
dd = strfind(name_sig,' ');
publdate = name_sig(dd(1)+1:dd(2)-1);
publdate = datestr(datenum(publdate,'dd-mmm-yyyy'),'yyyy-mm-dd'); % date on the form YYYY-MM-DD
publyear = publdate(1:4);
matfile.metadata.schemes.DataCite.Date = {['Created/' publdate]};
matfile.metadata.schemes.DataCite.PublicationYear = {publyear};
end
% Delete any empty fields from the structure
sFields = fieldnames(matfile);
for sf = sFields.'
tFields = fieldnames(matfile.(char(sf)));
for tf = tFields.'
if isempty(matfile.(char(sf)).(char(tf)))
matfile.(char(sf)) = rmfield(matfile.(char(sf)),char(tf));
end
end
end
% change Vi and Vobi sign
if isfield(matfile.metadata,'par2d')
parnames = matfile.metadata.par2d(1,:);
a = find(strcmp('Vi',parnames));
b = find(strcmp('Vobi',parnames));
if a, matfile.data.par2d(:,a) = -matfile.data.par2d(:,a); end
if b, matfile.data.par2d(:,b) = -matfile.data.par2d(:,b); end
end
if isfield(matfile.metadata,'par1d')
parnames = matfile.metadata.par1d(1,:);
a = find(strcmp('Vi',parnames));
b = find(strcmp('Vobi',parnames));
if a, matfile.data.par1d(:,a) = -matfile.data.par1d(:,a); end % change sign
if b, matfile.data.par1d(:,b) = -matfile.data.par1d(:,b); end % change sign
end
save(matfilename,'matfile')
% Generate an HDF5-file from the MAT-file
chunklim = 10;
sFields = fieldnames(matfile);
for sf = sFields.'
group1 = ['/' char(sf)];
tFields = fieldnames(matfile.(char(sf)));
for tf = tFields.'
if strcmp('data',char(sf)) && (strcmp('par0d',char(tf)) || strcmp('par1d',char(tf)) || strcmp('par2d',char(tf)) || strcmp('par2d_pp',char(tf)) || strcmp('acf',char(tf)) || strcmp('ace',char(tf)) || strcmp('lag',char(tf)) || strcmp('freq',char(tf)) || strcmp('spec',char(tf)) || strcmp('om',char(tf)))
npar = length(matfile.data.(char(tf))(1,:));
ndata = length(matfile.data.(char(tf))(:,1));
if ge(ndata,chunklim) && ge(npar,chunklim), csize = [chunklim chunklim];
elseif ge(ndata,chunklim), csize = [chunklim npar];
elseif ge(npar,chunklim), csize = [ndata chunklim];
else csize = [ndata npar]; end
h5create(hdffilename,['/' char(sf) '/' char(tf)],size([matfile.(char(sf)).(char(tf))]),'ChunkSize',csize,'Deflate',9,'Datatype','single');
h5write(hdffilename,['/' char(sf) '/' char(tf)],[matfile.(char(sf)).(char(tf))]);
elseif strcmp('metadata',char(sf))
if isstruct(matfile.(char(sf)).(char(tf)))
group2 = [group1 '/' char(tf)];
uFields = fieldnames(matfile.(char(sf)).(char(tf)));
for uf = uFields.'
if isstruct(matfile.(char(sf)).(char(tf)).(char(uf)))
group3 = [group2 '/' char(uf)];
vFields = fieldnames(matfile.(char(sf)).(char(tf)).(char(uf)));
for vf = vFields.'
strdata = matfile.(char(sf)).(char(tf)).(char(uf)).(char(vf));
dsname = char(vf);
strds2hdf5(hdffilename,group3,dsname,strdata)
end
else
strdata = matfile.(char(sf)).(char(tf)).(char(uf));
dsname = char(uf);
strds2hdf5(hdffilename,group2,dsname,strdata)
end
end
else
strdata = matfile.(char(sf)).(char(tf));
dsname = char(tf);
strds2hdf5(hdffilename,group1,dsname,strdata)
end
else
h5create(hdffilename,['/' char(sf) '/' char(tf)],size([matfile.(char(sf)).(char(tf))]));
h5write(hdffilename,['/' char(sf) '/' char(tf)],[matfile.(char(sf)).(char(tf))]);
end
end
end
if addfigs
image_filelist = [dir(fullfile(matpath,'*.png'));dir(fullfile(matpath,'*.pdf'))];
npdf = 0;
%if ~isempty(image_filelist)
for ii = 1:length(image_filelist)
figurefile = fullfile(matpath,image_filelist(ii).name);
[~,filename,ext] = fileparts(figurefile);
if strcmp(ext,'.png')
store_image2Hdf5(figurefile,hdffilename)
elseif strcmp(ext,'.pdf')
npdf = npdf + 1;
pdf_forHDF5(npdf) = {[filename ext]};
end
end
if npdf>0
strds2hdf5(hdffilename,'/metadata','figure_links',pdf_forHDF5');
end
%end
end
if addnotes
notesfiles = dir(fullfile(matpath,'notes*txt'));
for nn = 1:length(notesfiles)
notesfile = fullfile(matpath,notesfiles(nn).name);
addNote2Hdf5(notesfile,EISCAThdf5file,nn)
end
end
end