-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPTRwid.pro
More file actions
9180 lines (7577 loc) · 426 KB
/
Copy pathPTRwid.pro
File metadata and controls
9180 lines (7577 loc) · 426 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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;
;;;;;;;
;;;;;;; PTRWID routines
;;;;;;;
;;;;;;; .FULL_RESET_SESSION
;;;;;;; RESOLVE_ALL
;;;;;;; SAVE, /ROUTINES, FILENAME = 'C:/PTRwid/PTRwid.sav'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PRO ____________PTRwid
end
PRO PTRwid
compile_opt idl2
version='v002'
date='Oct_14_2015'
parfile='C:/PTRwid/'+version+'_'+date+'_par.txt'
codefile='C:/PTRwid/PTRwid_'+version+'_'+date+'.pro'
help,/source_files, output=mis
source=strtrim(string(strmid(mis[where(strpos(mis,'PTRWID_EVENT') eq 0)],12,1111)),2)
inf=file_info('C:/PTRwid/')
if (inf.directory eq 0) then FILE_MKDIR, 'C:/PTRwid/'
makecsv,'C:/PTRwid/parfile.txt',parfile
inf=file_info(parfile)
info='> processing info '
if (inf.exists eq 0) then begin
log=['PTRwid_'+version+' released '+date,'Default parfile has been created:', parfile, '','Values can be adjusted (advanced users only).' ]
;create default PTRwid_parameter.txt
PTRwidpar=transpose([$
'PTR DEFAULT VALUES',$
'',$
'_p_drift_default=2.4',$ ; hPa
'_u_drift_default=600',$ ;volt
'_udx_default=35',$ ;volt
'_t_drift_default=50',$ ; celcius
'_reactionlength=9.6',$ ;reactionlength in cm
'_reduced_mobility=2.8',$ ;reduced mobility of H3O+ in N2
'',$
'CRUDE CALIBRATION',$
'',$
'_PeaksToConsider=24',$
'',$
'UNIFIED MASS LIST',$
'',$
'_PeakAnalysis=1',$
'_DefaultRes=4500',$
'_Desired_Min_Signal=1.0E6',$ ;counts
'_Max_Time_Gap=10',$ ;minutes
'',$
'PS1 _ peak search',$
'',$
'_Min_Mass=10',$ ;Da
'',$
'COMPOUND CLASS',$
'',$
'_N_ox_st=-1',$ ;Nitrogen oxidation state
'',$
'MassScsale Calibration Parameter Boundaries',$
'',$
'_default_a_1000=7800', '_default_a_8000=17300',$
'_default_t0_1000=-28500', '_default_t0_8000=750',$
'_exMin=0.49', '_exMax=0.500000015','_monitorMass=371.10123',$
'',$
'3-POINT MASS-SCALE-CALIBRATION ',$
'',$
'_M1a=21.0221', '_M1b=42.034',$
'_M2a=59.0491', '_M2b=116.906',$
'_M3a=205.195', '_M3b=355.0731',$
'_tol_ppm=300',$ ;acceptable tollerance to find peak
'',$
'OPTIONAL: CALIBRATION TO FIT MASSLIST',$
'',$
'_HardCal=0',$
;CH4O H+ ;CH2O2 H+ ;C3H6O H+ ;C2H4O2 H+ ;C3H6O2 H+ ;C4H8O2 H+ ;C5H10O2 H+ ;C6H12O2 H+ ;C7H14O2 H+ ;C8H16O2 H+
'_M1=33.0335','_M2=47.0128','_M3=59.0491','_M4=61.0284','_M5=75.0441','_M6=89.0597','_M7=103.0754','_M8=117.0910','_M9=131.1067','_M10=145.1223',$
;C9H18O2 H+ ;C10H20O2 H+ ;C11H22O2 H+ ;C12H24O2 H+ ;C13H26O2 H+ ;C14H28O2 H+ ;C15H30O2 H+ ;C16H32O2 H+ ;C17H34O2 H+ ;C18H36O2 H+
'_M11=159.1380','_M12=173.1536','_M13=187.1693','_M14=201.1849','_M15=215.2006','_M16=229.2162','_M17=243.2319','_M18=257.2475','_M19=271.2632','_M20=285.2788',$
;C13H14O8 H+ ;C9H11O13N H+ ;C8H18O15 H+ ;C11H16O13 H+ ;C16H18O10 H+ ;C12H20O13 H+ ;C16H14O13 H+
'_M21=299.0761','_M22=342.0303','_M23=355.0719','_M24=357.0664','_M25=371.0973','_M26=373.0977','_M27=415.0507','_M28=0','_M29=0','_M30=0',$
'',$
'PEAK SHAPE',$
'',$
'_MinSig=800',$
'',$
'MIXING RATIO:',$
'',$
'_k19=3',$
'_k37=3',$
'_m38=1',$
'',$
'Transmission Fit:',$
'',$
' _P0=9.1323863212E-02',$
' _P1=4.2137768341E-03',$
' _P2=-1.3332441405E-5',$
' _P3=2.9151001160E-8',$
' _P4=-3.4829484108E-11',$
' _P5=2.0979046465E-14',$
' _P6=-4.9852341527E-18',$
'',$
'EXPORT OPTIONS:',$
'',$
'_ExportOne=0',$
'_CorrectOverlap=1',$
'_SaveCsv=1',$
'_JunkSize=1.0E8',$
'',$
'CORRECTIONS:',$
'',$
'_CorrectionON=1',$
'_NonExtendingDeadTime=15',$
'_ExtendingDeadTime=1.3',$
'',$
'WIDGET ELEMENTS & SIZE',$
'',$
'_base_1x=450', '_base_1y=700',$
'_base_2x=230', '_base_2y=700',$;left column
'_base_4x=200', '_base_4y=220',$;engineering data, masslist
'_base_5x=110', '_base_5y=220',$
'_base_6x=110', '_base_6y=220',$
'_base_7x=200', '_base_7y=28',$; label
'_base_8x=200', '_base_8y=45', $
'_base_9x=200', '_base_9y=30',$
'_base_10x=200', '_base_10y=24', $
'_base_11x=200', '_base_11y=30',$
'_base_12x=210', '_base_12y=700', $; right column
'_Text_DataDiry=2', '_Text_DestDiry=2', '_List_Filesy=8', '_List_EngDaty=15',$
'_Text_Ind1x=40', '_Text_Ind1x2=40', '_Text_Ind2x=40', '_Text_Ind2x2=40', '_Text_logy=30','_Text_infoy=17',$
'',$
'End of file'])
File_copy,source[0],codefile
makecsv,parfile,PTRwidpar
endif else begin
PTRwidpar=readcsvstr(parfile)
log=['PTRwid_'+version+' released '+date,'Parfile loaded']
endelse
base_1 = WIDGET_BASE(/Row ,uname='base_1', XSIZE = getpar('base_1x'), YSIZE = getpar('base_1y'))
base_2=widget_base(base_1,/column,uname='base_2',xsize=getpar('base_2x'),ysize=getpar('base_2y'))
Label_1=Widget_label(base_2,/Align_left,uname='label_1', value="Data directory (HDF5 data):")
Text_DataDir = WIDGET_TEXT(base_2, uname="Text_DataDir", VALUE="click the right mouse button to select a TOF DATA directory (HDF5 data)", /EDITABLE,/ALL_EVENTS, /NO_NEWLINE,/wrap , /CONTEXT_EVENTS, YSIZE = getpar('Text_DataDiry'),uvalue=-9999)
base_3= WIDGET_BASE(Text_DataDir, /CONTEXT_MENU, UNAME="base_3")
But_1 = WIDGET_BUTTON(base_3, uname='But_1', VALUE = 'browse', EVENT_PRO = 'getDataDir')
But_111 = WIDGET_BUTTON(base_3, uname='But_111', VALUE = 'last settings', EVENT_PRO = 'LoadSet')
Label_2=Widget_label(base_2,/Align_left,uname='label_2',value="Destination directory:")
Text_DestDir = WIDGET_TEXT(base_2, uname="Text_DestDir", VALUE=" ",/ALL_EVENTS, /NO_NEWLINE,/wrap , YSIZE = getpar('Text_DestDiry'))
Label_3=Widget_label(base_2,/Align_left,uname='Label_3', value="File Creation times:",uvalue=CREATE_STRUCT('name1',['']))
List_Files=WIDGET_LIST(base_2,UNAME = 'List_Files',event_pro="SingleFile",ysize=getpar('List_Filesy'))
base_4=widget_base(base_2,/row,uname='base_4',xsize=getpar('base_4x'),ysize=getpar('base_4y'))
base_5=widget_base(base_4,/column,uname='base_5',xsize=getpar('base_5x'),ysize=getpar('base_5y'))
Label_4=Widget_label(base_5,/Align_left,uname='Label_4', value="Engineering:")
List_EngDat=WIDGET_LIST(base_5,UNAME = 'List_EngDat',event_pro="plot1", ysize=getpar('List_EngDaty'))
base_6=widget_base(base_4,/column,uname='base_6',xsize=getpar('base_6x'),ysize=getpar('base_6y'))
Label_5=Widget_label(base_6,/Align_left,uname='Label_5', value="Mass peaks:",uvalue=CREATE_STRUCT('masslist',[-9999],'MaxMass',[5]))
Drop_1=widget_droplist(base_6,uname='Drop_1',event_pro='setdrop1',value=['no timeline','time vs cps', 'time vs ppb'])
List_Masses=WIDGET_LIST(base_6,UNAME = 'List_Masses',event_pro="plot2", ysize=13,xsize=11)
Label_6=Widget_label(base_2,/Align_left,uname='Label_6', value="Unified Mass List:")
But_2 = WIDGET_BUTTON(base_2, uname='But_2',event_pro='UniMassList',value='Unified Mass List',uvalue=CREATE_STRUCT('PeakLoc',[-9999]))
base_8=widget_base(base_2,/row,uname='base_8',xsize=getpar('base_8x'),ysize=getpar('base_8y'))
Label_7=Widget_label(base_8,/Align_left,uname='Label_7', value="Data Export:")
But_4 = CW_PDMENU(base_8, uname='But_4', ['1\X\selList','0\unified mass list','2\file mass list'], /RETURN_FULL_NAME)
Label_8=Widget_label(base_8, uname='Label_8', value=" unified mass list ", uvalue='unified mass list')
But_6 = WIDGET_BUTTON(base_2, uname='But_6', event_pro='export', value=' Export ')
base_10=widget_base(base_2,/row,uname='base_10',xsize=getpar('base_10x'),ysize=getpar('base_10y'))
Label_9=Widget_label(base_10,/Align_left, uname='Label_9', value="File number (first - last):")
Text_Ind1 = WIDGET_TEXT(base_10, uname='Text_Ind1', VALUE='0',/EDITABLE,xsize=getpar('Text_Ind1x'), scr_xsize=getpar('Text_Ind1x2'))
Text_Ind2 = WIDGET_TEXT(base_10, uname='Text_Ind2', VALUE='0',/EDITABLE,xsize=getpar('Text_Ind2x'), scr_xsize=getpar('Text_Ind2x2'))
But_MB1 = WIDGET_BUTTON(base_2, uname='But_MB1',event_pro='createAvgSpectra', value='Mass calibration + avgerage Spectra')
But_9 = WIDGET_BUTTON(base_2, uname='But_9',event_pro='ExtendedProc', value=' Extended processing ')
base_MB_10=widget_base(base_2,/row,uname='base_MB_10',xsize=getpar('base_10x'),ysize=getpar('base_10y'))
Label_9=Widget_label(base_MB_10,/Align_left, uname='Label_MB_1', value="average time [s]:")
Text_Ind_MB1 = WIDGET_TEXT(base_MB_10, uname='averageTime', VALUE='60',/EDITABLE,xsize=getpar('Text_Ind1x'), scr_xsize=getpar('Text_Ind1x2'))
But_MB2 = WIDGET_BUTTON(base_2, uname='But_MB2',event_pro='calculateStickdata', value='calculate stick Spectra')
base_12=widget_base(base_1,/column,uname='base_12',xsize=getpar('base_12x'),ysize=getpar('base_12y'))
Text_log = WIDGET_TEXT(base_12, uname="Text_log", VALUE=[log],/ALL_EVENTS, /wrap ,/scroll, YSIZE = getpar('Text_logy'))
Text_info = WIDGET_TEXT(base_12, uname="Text_info", VALUE=[info],/ALL_EVENTS, /wrap ,/scroll, YSIZE = getpar('Text_infoy'))
WIDGET_CONTROL, base_1, /REALIZE
XMANAGER, 'PTRwid', base_1, /NO_BLOCK
END
pro export, event
; called by button 'export'
;this routine retrieves and exports cps and ppb from the specified files (adjust index i in the main loop)
;UNIFIED MASS LIST MUST BE AVAILABLE
; if you want to re-calculate a file, remove the corresponding ppb-file from the destination folder
compile_opt idl2
WIDGET_CONTROL, /HOURGLASS
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Label_8'), get_uVALUE= MassListType
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_DestDir'), GET_VALUE=DestFolder
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_Ind1'), get_VALUE=iFile1
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_Ind2'), get_VALUE=iFile2
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'List_Files'), GET_uVALUE=Files
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'List_Masses'), get_uVALUE= msss
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Label_5'), get_uVALUE= Filepar
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'label_2'), gET_uVALUE= Names
mist=systime(1)
; if export is called from "export one" pics of the mass spectrum are produced
iFile1=max(long(iFile1))
iFile2=max(long(iFile2))
length=max(size(files,/dimensions))
if(iFile2 gt length-1) then iFile2=length-1
if(iFile2 lt iFile1) then iFile2=iFile1
if(getpar('ExportOne') eq 1) then begin
jpeg=1
iFile2=iFile1
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_Ind2'), SET_VALUE=string(iFile2, format='(I5)')
endif else jpeg=0
ID=''
if (MassListType eq 'unified mass list') then ID='UL'
if (MassListType eq 'file mass list') then ID='FL'
; clear lost memory
help,/memory
print, 'heap_gc'
heap_gc
help,/memory
if (ID eq 'UL') then begin
massesUL=readcsv(strjoin([DestFolder,'unifiedmasslist.csv']))
if(massesUL[0] eq -9999) then begin
UniMassList, event
massesUL=readcsv(strjoin([DestFolder,'unifiedmasslist.csv']))
endif
endif
;set tol parameter
tol=0.05
if(iFile2-iFile1 gt 0) then files=files[iFile1+indgen(iFile2-iFile1+1)] else files=files[iFile1]
if(iFile2-iFile1 gt 0) then names=names[iFile1+indgen(iFile2-iFile1+1)] else names=names[iFile1]
for i=0,iFile2-iFile1 do begin
; missttii=0
; delvar, Sumspec
; print, [var_exists(sumspec),123]
help,/memory
;check if file exits already
Name1=names[i]
exists=file_info(strjoin([DestFolder,'Export/',ID,'/ppb/','ppb',Name1,ID,'.fdt'],'')) & exists=exists.exists
if (jpeg eq 1) then exists=0 ;i.e. if exportOne is selected the files will be overwritten anyway
if (exists eq 1)then begin
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
log=[strjoin(['FILE: ', Name1,'',ID]),'File index: '+strtrim(string(i+iFile1,Format='(I4)'),2), 'Export data exist already','------------','',log]
if(max(size(log,/dimensions)) gt 100) then log=log[0:99]
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), sET_VALUE= log
endif
if (exists ne 1) then begin
NamePar=''
NameBaseline=''
exists2=file_info(destfolder+'FileInfo/Time2MassPAR/'+name1+'PAR2.fdt') & exists2=exists2.exists
if (exists2 eq 1)then NamePar=destfolder+'FileInfo/Time2MassPAR/'+name1+'PAR2.fdt'
if (exists2 eq 1)then NameBaseline=destfolder+'FileInfo/Baseline/'+name1+'Baseline.fdt'
if (NamePar ne '') then if (max(readfloat(NamePar)) eq -9999) then NamePar=''
if (NameBaseline ne '') then baseline=readfloat(NameBaseline)
if (NamePar ne '') then begin
par=readfloat(NamePar)
a=par[0]
t0=par[1]
ex=par[2]
maxmass=par[3]
res=par[8]
mode=par[9]
endif else begin
Sumspec=getsumspec(files[i])
if(max(sumspec.duration) ne -9999) then begin
Filepar=PS1(event,sumspec.sumspec, sumspec.SampInt, sumspec.duration, sumspec.cycles, sumspec.extractions,destfolder,names[i],sumspec.instrument)
if(max(Filepar.counts) ne -9999)then Filepar.counts[where(Filepar.counts gt 0)]=Filepar.counts[where(Filepar.counts gt 0)]/sumspec.duration
a=Filepar.a
t0=Filepar.t0
ex=Filepar.ex
maxmass=Filepar.maxmass
res=Filepar.resolution
mode=strpos('H3O+ NO+ O2+',filepar.mode)
baseline=Filepar.baseline
makefloat, destfolder+'FileInfo/IonList/'+names[i]+'FL2.fdt', Filepar.masslist
makefloat, destfolder+'FileInfo/Time2MassPAR/'+names[i]+'PAR2.fdt', [Filepar.a,Filepar.t0,Filepar.ex,Filepar.maxmass,sumspec.SampInt,Filepar.a3,Filepar.t03,Filepar.ex3,Filepar.resolution,strpos('H3O+ NO+ O2+',filepar.mode)]
makefloat, destfolder+'FileInfo/PeakShape/'+names[i]+'PeakShape.fdt', Filepar.PeakShape
makefloat, destfolder+'FileInfo/Baseline/'+names[i]+'Baseline.fdt', baseline
endif
endelse
if (ID eq 'UL' and var_exists(a) eq 1) then begin
massessUL=massesUL[*,0]
exists2=file_info(destfolder+'FileInfo/IonList/'+name1+'FL2.fdt') & exists2=exists2.exists
if (exists2 eq 1)then NameMsss=destfolder+'FileInfo/IonList/'+name1+'FL2.fdt' else NameMsss='jjj'
if (NameMsss ne '') then msss=readfloat(NameMsss)
massessFL=msss[*,0]
if (mode eq 0) then begin
iUL=where(abs(massessUL-21.0221 ) eq min(abs(massessUL-21.0221 )))
iFL=where(abs(massessFL-21.0221 ) eq min(abs(massessFL-21.0221 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
if(getpar('m38') eq 1) then begin
iUL=where(abs(massessUL-38.0326 ) eq min(abs(massessUL-38.0326 )))
iFL=where(abs(massessFL-38.0326 ) eq min(abs(massessFL-38.0326 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
endif else begin
iUL=where(abs(massessUL-39.0327 ) eq min(abs(massessUL-39.0327 )))
iFL=where(abs(massessFL-39.0327 ) eq min(abs(massessFL-39.0327 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
endelse
endif
if (mode eq 5) then begin
iUL=where(abs(massessUL-30.994 ) eq min(abs(massessUL-30.994 )))
iFL=where(abs(massessFL-30.994 ) eq min(abs(massessFL-30.994 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
iUL=where(abs(massessUL-47.9966) eq min(abs(massessUL-47.9966 )))
iFL=where(abs(massessFL-47.9966 ) eq min(abs(massessFL-47.9966 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
endif
if (mode eq 9) then begin
iUL=where(abs(massessUL-33.9935 ) eq min(abs(massessUL-33.9935 )))
iFL=where(abs(massessFL-33.9935 ) eq min(abs(massessFL-33.9935 )))
massessUL[iUL[0]]=massessFL[iFL[0]]
endif
peakTable=peaktable(massessUL,res)
endif
if (ID eq 'FL' and var_exists(a) eq 1) then begin
NameMsss=''
exists2=file_info(destfolder+'FileInfo/IonList/'+name1+'FL2.fdt') & exists2=exists2.exists
if (exists2 eq 1)then NameMsss=destfolder+'FileInfo/IonList/'+name1+'FL2.fdt'
if (NameMsss ne '') then msss=readfloat(NameMsss)
peakTable=peaktable(msss[*,0],res)
endif
if(var_exists(a) eq 1) then if(var_exists(maxmass) eq 1) then m_max=min([maxmass-0.3,max(PeakTable[*,0])-0.1]) else m_max=max(PeakTable[*,0])-0.1
m_min=10.5
if(NamePar eq '') then missttii=sumspec.duration else missttii=111
if (missttii eq -9999)then begin
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
log=[strjoin(['FILE: ', Name1,'',ID]),'File index: '+strtrim(string(i+iFile1,Format='(I4)'),2), 'Problem reading SumSpec','------------','',log]
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), sET_VALUE= log
endif
if(var_exists(a) eq 1) then if (a eq -9999)then begin
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
log=[strjoin(['FILE: ', Name1,'',ID]),'File index: '+strtrim(string(i+iFile1,Format='(I4)'),2), 'Crude cal FAILED','------------','',log]
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), sET_VALUE= log
endif
if(var_exists(a) eq 1) then if (missttii ne -9999 and a ne -9999)then begin
info=['Start data export:','']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
EngData=GetEngData(event,files[i])
misst=LoadMassRange(Files[i],20.5,20.7,a,t0,ex, SampInt)
if ( mean(*misst[0]) eq -9999 or max(engdata.duration) eq -9999)then begin
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
log=[strjoin(['FILE: ', Name1,'',ID]),'File index: '+strtrim(string(i+iFile1,Format='(I4)'),2), 'NOT EXPORTED:','HD5 READ PROBLEM','',log]
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), sET_VALUE= log
endif
if(max(engdata.duration) gt 0 and mean(*misst[0]) ne -9999) then begin
cycles=size(*misst,/dimensions)
cycles=min(cycles[1])
cycles2=cycles
sig=total(*misst,1)
while(sig[cycles-1] eq 0) do cycles=cycles-1
cyc=indgen(cycles)
*misst=0
SampInt=EngData.SampInt
Extractions=EngData.extractions
poiscor=EngData.poiscor
engdati=engdata.data
engdati=engdati[cyc,*]
udrift= engdati[*,min(where(strmatch(engdata.names,'Udrift*') eq 1)) ]
pdrift= engdati[*,where(strmatch(engdata.names,'p_drift*') eq 1 or strmatch(engdata.names,'p-Drift*') eq 1)]
tdrift= 273.15 +engdati[*,WHERE(strmatch(engdata.names,'Drift_Temp*') eq 1 or strmatch(engdata.names,'T-Drift*') eq 1)]
pdrift=pdrift[*,0]
udrift=udrift[*,0]
tdrift=tdrift[*,0]
makeFloat, strjoin([DestFolder,'Export/EngData/','EngData',Name1,'.fdt'],''), engdati
if(getpar('SaveCsv') eq 1) then MakeCsv,strjoin([DestFolder,'Export/EngData/','EngData',Name1,'.csv'],''),engdati
makeCsv, strjoin([DestFolder,'Export/EngData/','EngDataNames',Name1,'.csv'],''), transpose(EngData.names)
print, 'engineering data loaded and saved; time = ', systime(1)-mist
info=[info,'Engineering data loaded and saved']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
;create a list of 'masses'and 'deltas'which defines the integration boundaries for each mass peak; save a list with mass names
PeakTable2= PeakTable[where(PeakTable[*,0] gt m_min),*] & PeakTable2=PeakTable2[where(PeakTable2[*,0] lt m_max),*]
masses=(PeakTable2[*,2]+PeakTable2[*,1])/2
deltas=PeakTable2[*,2]-PeakTable2[*,1]
makeCsv,strjoin([DestFolder,'Export/',ID,'/IonList/','MassIDs_',Name1,ID,'.csv'],''),transpose(PeakTable2[*,0])
;prepare parameters for reading HDF5
Start =floor(m2t(m_min, a, t0, ex,SampInt))
if(Start lt 0) then Start=0
Width = ceil(m2t(m_max, a, t0, ex,SampInt)- Start)
timerow=LINDGEN(Width)+Start
split=max(ceil(float(Width)*engdata.cycles/getpar('JunkSize')) )
print, split
info=[info,'Importing Raw Data in'+string(split,format='(I3)')+' junk(s)']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
leng=floor(float(Width)/(split))
;read junks of the HDF5 raw data, perform integration of peaks and create a cps-file
cps=fltarr(1,cycles)
for k=0,split-1 do begin
if(k gt 0) then mmi=mma else mmi=m2t(timerow[0], a, t0, ex,SampInt,/time)
if(timerow[0] eq 0) then mmi=mmi+2*tol
mma=m2t(timerow[leng*(k+1)-1], a, t0, ex,SampInt,/time)
if (max(where(masses gt mmi and masses le mma)) gt -0.5) then begin
mistm=masses[where(masses gt mmi)]
mistd=deltas[where(masses gt mmi)]
msses=mistm[where(mistm le mma)]
dltas=mistd[where(mistm le mma)]
if(min(msses-dltas/2) gt mmi) then tollow=2*tol else tollow=2*tol+mmi-min(msses-dltas/2)
if(max(msses+dltas/2) lt mma) then tolhig=2*tol else tolhig=2*tol+max(msses+dltas/2)-mma
Start =floor(m2t(mmi-tollow, a, t0, ex,SampInt))
Width = ceil(m2t(mma+tolhig, a, t0, ex,SampInt)- Start)
tmrow=LINDGEN(Width)+Start
data=LoadMassRange(Files[i],mmi-tollow,mma+tolhig,a,t0,ex,SampInt)
if(max(baseline) eq -9999) then baseline1=-9999 else baseline1=baseline[Start+lindgen(Width)]
rsch=string(indgen(split))
ccc=integrate(*data,baseline1, tmrow,msses,dltas,tol,a,t0,ex,fltarr(cycles2)+a,fltarr(cycles2)+t0,fltarr(cycles2)+ex,strjoin([DestFolder,'Export/',ID,'/cps/',Name1,rsch[k]],''),jpeg,SampInt,extractions,poiscor)
ccc=ccc[*,cyc]
cps=[(cps),ccc]
*data=0
info=[info,'Junk'+string(k+1,format='(I3)')+' imported']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
endif
endfor
print,'data',i+iFile1,' integrated',' time', systime(1)-mist
info=[info,'Data integrated']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
cps=cps[1:max(size(masses,/dimensions)),*]
cps=cps*engdata.cycles/engdata.duration
MakeFloat,strjoin([DestFolder,'Export/',ID,'/cps/','cps',Name1,ID,'.fdt'],''),cps
print,'cps.fdt',i+iFile1,' saved',' time', systime(1)-mist
if(getpar('SaveCsv') eq 1) then begin
lis=['',string(PeakTable2[*,0],format='(F9.3)')]
hed=strarr(max(d(lis)))
hed[0]='Integrated signal [counts ner second; cps]; 2nd row: m/z; 1st column: timerow [days since 1.1.2009]'
timrow=string(engdati[*,0],format='(D14.8)')
str=[transpose(timrow),string(cps)]
str=[[hed],[lis],[str]]
MakeCsv,strjoin([DestFolder,'Export/',ID,'/cps/','cps',Name1,ID,'.csv'],''),str
endif
print,'cps.csv',i+iFile1,' saved',' time', systime(1)-mist
info=[info,'File saved: cps']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
if(getpar('CorrectOverlap') eq 1) then begin
misss=name1
corrcps=overlap(masses,cps,misss,destfolder)
MakeFloat,strjoin([DestFolder,'Export/',ID,'/cps/OCorr/','corrcps',Name1,ID,'.fdt'],''),corrcps
if(getpar('SaveCsv') eq 1) then begin
lis=['',string(PeakTable2[*,0],format='(F9.3)')]
hed=strarr(max(d(lis)))
hed[0]='Integrated signal corrected for overlapping peaks [counts ner second; cps]; 2nd row: m/z; 1st column: timerow [days since 1.1.2009]'
timrow=string(engdati[*,0],format='(D14.8)')
str=[transpose(timrow),string(corrcps)]
str=[[hed],[lis],[str]]
MakeCsv,strjoin([DestFolder,'Export/',ID,'/cps/OCorr/','corrcps',Name1,ID,'.csv'],''),str
endif
print,'corrcps',i+iFile1,' saved',' time', systime(1)-mist
info=[info,'File saved: corrcps']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
endif
; fix if engineering data and raw TOF data do not contain the same number of cycles
l2= max(size(pdrift,/dimensions))
if(cycles ne l2) then begin
print, 'WARNING: mismatch length engineering and tof data', l2,cycles
if(cycles gt l2) then begin
for kkk=1,cycles-l2 do begin
udrift=[udrift,mean(udrift)]
pdrift=[pdrift,mean(pdrift)]
tdrift=[tdrift,mean(tdrift)]
endfor
endif else begin
udrift=udrift[0,cycles-1]
pdrift=pdrift[0,cycles-1]
tdrift=tdrift[0,cycles-1]
endelse
endif
; compute and save ppb data
Prim=getPrimIons(masses,cps,mode)
ppb=calcppb( cps, masses,Prim.A, Prim.B,pdrift,udrift,tdrift)
MakeFloat,strjoin([DestFolder,'Export/',ID,'/ppb/','ppb',Name1,ID,'.fdt'],''),ppb
if(getpar('SaveCsv') eq 1) then begin
lis=['',string(PeakTable2[*,0],format='(F9.3)')]
hed=strarr(max(d(lis)))
hed[0]='Volume mixing ratio [nmol/mol; ppb]; 2nd row: m/z; 1st column: timerow [days since 1.1.2009]'
timrow=string(engdati[*,0],format='(D14.8)')
str=[transpose(timrow),string(ppb)]
str=[[hed],[lis],[str]]
MakeCsv,strjoin([DestFolder,'Export/',ID,'/ppb/','ppb',Name1,ID,'.csv'],''),str
endif
info=[info,'File saved: ppb']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
if(getpar('CorrectOverlap') eq 1) then begin
corrppb=calcppb( corrcps, masses,Prim.A, Prim.B,pdrift,udrift,tdrift)
MakeFloat,strjoin([DestFolder,'Export/',ID,'/ppb/OCorr/','corrppb',Name1,ID,'.fdt'],''),corrppb
if(getpar('SaveCsv') eq 1) then begin
lis=['',string(PeakTable2[*,0],format='(F9.3)')]
hed=strarr(max(d(lis)))
hed[0]='Volume mixing ratio corrected for overlapping peaks [nmol/mol; ppb]; 2nd row: m/z; 1st column: timerow [days since 1.1.2009]'
timrow=string(engdati[*,0],format='(D14.8)')
str=[transpose(timrow),string(corrppb)]
str=[[hed],[lis],[str]]
MakeCsv,strjoin([DestFolder,'Export/',ID,'/ppb/OCorr/','corrppb',Name1,ID,'.csv'],''),str
endif
info=[info,'File saved: corrppb']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
endif
print,'ppb',i+iFile1,' calculated & saved',' time', systime(1)-mist
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
log=[strjoin(['FILE: ', Name1,'',ID]),'File index: '+strtrim(string(i+iFile1,Format='(I4)'),2), 'EXPORT successful', 'processing time: '+strtrim(string( systime(1)-mist,Format='(I6)'),2)+'s','------------','',log]
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), sET_VALUE= log
info=[info,'','Export complete']
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), sET_VALUE= info
endif
endif
endif
;print, missttii
;print, var_exists(sumspec)
endfor
print, 'fertig'
end
PRO ExtendedProc, event
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_DestDir'), GET_VALUE=path
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_DataDir'), GET_uVALUE=lib
if(strpos(path,'w_data') lt -0.5) then path='click the right mouse button to select "w_data" directory'
base = WIDGET_BASE(/column, XSIZE = 210, YSIZE = 96, RESOURCE_NAME = 'Extended Processing')
buti1 = WIDGET_BUTTON(base,event_pro='ProcPTR', value='Average and Merge Data',uname='Buti1',uvalue=path)
buti2 = WIDGET_BUTTON(base,event_pro='IdentPTR', value='Attribute Formulas',uname='Buti2',uvalue=lib)
buti3 = WIDGET_BUTTON(base,event_pro='FiltPTR', value='Filter samples',uname='Buti3')
WIDGET_CONTROL, base, /REALIZE
XMANAGER, 'ExtendedProc', base, /NO_BLOCK
print, buti1
print, buti2
END
PRO calculateStickdata, event
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'List_Files'), GET_uVALUE=Files
; check, if all Files are there, we need them:
n=size(Files,/DIMENSIONS)
c=0
for i=0,n[0]-1 do begin
tmp = file_info(Files[i]) & tmp=tmp.exists
if (tmp eq 1) then c=c+1
endfor
if (c lt n[0]) then begin
print, 'some raw data files are missing...'
return
endif
;check if ResultSpectra.hdf is present
path = FILE_DIRNAME(Files[0])
ResultFilePath = FILEPATH('ResultSpectra.hdf5',ROOT_DIR=path, SUBDIRECTORY='w_data')
tmp = file_info(ResultFilePath) & tmp=tmp.exists
if (tmp lt 1) then begin
print, 'resultspectra.hdf5 is missing...'
return
endif
;retrieve integration time:
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'averageTime'), GET_VALUE=tmp
averageTime = (double(tmp))[0]
; loop through Files to retrieve dataspace required:
n=size(Files,/DIMENSIONS)
counter=0
for file=0,n[0]-1 do begin
fileId = H5F_OPEN(Files[file])
;retrieve max of BufTimes:
dataset_id2 = H5D_OPEN(fileId, '/TimingData/BufTimes')
BufTimes= H5D_READ(dataset_id2)
Dims3 = size(BufTimes,/DIMENSIONS)
actualBufTime=0.0
dt = BufTimes[1,0]
while ((actualBufTime+averageTime-dt/2.0) LT max(BufTimes)+dt) do begin
times = make_array(Dims3[0])
maxBufTime = 0.0
for i=0,Dims3[0]-1 do begin
indizes = WHERE(BufTimes[i,*] GE actualBufTime-dt/2.0 and BufTimes[i,*] LE (actualBufTime+averageTime)-dt/2.0)
times[i] = mean(BufTimes[i,indizes])
if maxBufTime LT max(BufTimes[i,indizes]) then maxBufTime=max(BufTimes[i,indizes])
endfor
time = mean(times)+dt/2.0
counter=counter+1
actualBufTime=maxBufTime+dt
;if (counter GT 1.5) then begin
; y=fehler
;endif
endwhile
;print, counter
;retrieve Info to convert to cps:
FileStruct=H5_parse(Files[file])
SingleIonSignal=Filestruct.FullSpectra.Single_Ion_Signal._data; ---MB
Extractions=Filestruct.NbrWaveforms._DATA
TofPeriod = Filestruct.TimingData.TofPeriod._DATA
TofPeriod = TofPeriod[0]
Extractions = Extractions[0]
SingleIonSignal = SingleIonSignal[0]
inttime = Extractions*(TofPeriod*1E-9)
H5F_CLOSE, fileId
endfor
print, counter
;load the total result file with all the information in it:
fileId = H5F_OPEN(ResultFilePath)
dataset_id1 = H5D_OPEN(fileId, '/MassList')
MassList = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/A')
tofA = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/T0')
tofT0 = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/Ex')
tofEx = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/Peakshape')
PeakShape = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/PeakshapeX')
PeakShapeX = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/Resolution')
Resolution = H5D_read(dataset_id1)
dataset_id1 = H5D_OPEN(fileId, '/MassAxis')
MassAxisBaseline = H5D_read(dataset_id1)
id = H5D_OPEN(fileId, '/SumSpecs')
aid = H5A_OPEN_NAME(id,'SampleInterval')
tmp = H5A_READ(aid)
SampleInterval = float(tmp)
H5F_CLOSE, fileId
m = size(MassList,/Dimensions)
Cps = make_array(counter,m[0],/FLOAT,value=-1.0)
StickTimes = make_array(counter,/DOUBLE,value=-1.0) ; MATLAB timestamp
WIDGET_CONTROL, /HOURGLASS
runtimeStart=systime(1)
;----------- start main loop
counter=0
n=size(Files,/DIMENSIONS)
numberOfFiles = n[0]
;numberOfFiles=1
for file=0,numberOfFiles-1 do begin
filetimeStart = systime(i)
actualBufTime=0.0
fileId = H5F_OPEN(Files[file])
dataset_id1 = H5D_OPEN(fileId, '/FullSpectra/TofData')
dataspace_id1 = H5D_GET_SPACE(dataset_id1)
Dims=H5S_GET_SIMPLE_EXTENT_DIMS(Dataspace_id1)
TofData = Reform(H5D_READ(dataset_id1))
dataset_id2 = H5G_OPEN(fileId, '/TimingData')
aid = H5A_OPEN_NAME(dataset_id2,'AcquisitionTimeZero')
TimeStamp = double(H5A_READ(aid));
TimeStamp = TimeStamp[0]
unix_timestamp = (double(timestamp)-130893181529880000.0)/1.0e7+1444844552.0
MATLAB_timestamp = double(unix_timestamp)/86400.0 + 719529.0
;y=fehler
;retrieve BufTimes:
dataset_id2 = H5D_OPEN(fileId, '/TimingData/BufTimes')
BufTimes= H5D_READ(dataset_id2)
H5F_CLOSE, fileId
;load actual BaseLine
fileId = H5F_OPEN(ResultFilePath)
dataset_id1 = H5D_OPEN(fileId, '/BaseLines')
dataspace_id1 = H5D_GET_SPACE(dataset_id1)
Dims2=H5S_GET_SIMPLE_EXTENT_DIMS(Dataspace_id1)
H5S_SELECT_HYPERSLAB, dataspace_id1, [0,file], [Dims2[0],1], /RESET
memory_space_id1 = H5S_CREATE_SIMPLE([Dims2[0],1])
actualBaseline = H5D_READ(dataset_id1, FILE_SPACE=dataspace_id1, MEMORY_SPACE=memory_space_id1)
H5F_CLOSE, fileId
;average TofData for the averageTime [s]:
Dims3 = size(BufTimes,/DIMENSIONS)
avgTofData = make_array(Dims[0],/FLOAT,value=0.0)
TofDatablocks = make_array(Dims[0],Dims[2])
times = make_array(Dims[2])
actualBufTime = 0.0
dt = BufTimes[1,0]
while ((actualBufTime+averageTime-dt/2.0) LT max(BufTimes)+dt) do begin
times = make_array(Dims3[0])
maxBufTime = 0.0
for i=0,Dims3[0]-1 do begin
indizes = WHERE(BufTimes[i,*] GE actualBufTime-dt/2.0 and BufTimes[i,*] LE (actualBufTime+averageTime)-dt/2.0)
TofDataBlocks[i] = mean(TofData[*,i,indizes],DIMENSION=3)
times[i] = mean(BufTimes[i,indizes])
if maxBufTime LT max(BufTimes[i,indizes]) then maxBufTime=max(BufTimes[i,indizes])
endfor
actualTofData = mean(TofDataBlocks,DIMENSION=2)
actualTime = mean(times)+dt/2.0
; ----------------------------------------------------------------------------------------
if actualBufTime eq 0.0 then begin ;do this preparation step only in the first iteration:
;define the mass-axis for this file:
;sampInt = 2E-10
timeAxis = findgen(Dims[0])
actualMassAxis = m2t(timeAxis,tofA[file],tofT0[file],tofEx[file],sampleInterval, /time)
didAllMasses = 0
outerSize=2.0
leftOuterMass = MassList[0]-outersize/2.0
;leftOuterMass = 19.5; -----------------TESTDATA
;create and store normalized Peaks:
tmp = size(MassList, /DIMENSIONS)
numberInvolved = tmp[0]
tmp = size(actualMassAxis,/DIMENSIONS)
bins=tmp[0]
peaks = make_array(numberInvolved,bins,/FLOAT, Value=0)
A = make_array(numberInvolved,numberInvolved,/FLOAT, Value=0.0)
S = make_array(numberInvolved,/FLOAT, Value=0.0)
Faktor = make_array(numberInvolved,/FLOAT, Value=0.8); defines the ratio of counted area vs. total peak area
bin1 = make_array(numberInvolved,/long,value=0)
bin2=bin1
lower=0.1; defines the region in the normalized cumulated Peak to count
higher=0.9
for i=0,numberInvolved-1 do begin
mass = MassList[i]
indizes = where(PeakShape gt 1e-6)
masses = PeakShapeX[indizes]/Resolution[round(mass)]*mass
massIndizes = where(actualMassAxis gt mass+min(masses) and actualMassAxis lt mass+max(masses))
for k=min(massIndizes),max(massIndizes) do begin
dx=(actualMassAxis[k]-mass)*Resolution[round(mass)]/mass
;if (dx gt min(peakShapeX)) and (dx lt max(peakShapeX)) then begin
indx = value_locate(PeakShapeX,dx)
peaks[i,k]=PeakShape[indx]
;endif
endfor
peaksum=total(peaks[i,min(massIndizes):max(massIndizes)])
for jj=min(massIndizes),max(massIndizes) do begin
peaks[i,jj]=peaks[i,jj]/peaksum
endfor
c = total(peaks[i,min(massIndizes):max(massIndizes)], /CUMULATIVE)
c=c/max(c)
bins2 = where(c gt lower and c lt higher)
bin1[i] = min(bins2)+min(massIndizes)
bin2[i] = max(bins2)+min(massIndizes)
for j=0,numberInvolved-1 do begin
A[i,j]=total(peaks[j,bin1[i]:bin2[i]])
endfor
endfor
Ai = invert(A)
print, FORMAT='(%" %d of %d peaks created...")',$
numberInvolved, numberinvolved
endif
; create and invert Matrix
for i=0,numberInvolved-1 do begin
; Signal in bins of Average Spectrum:
S[i] = total(actualTofData[bin1[i]:bin2[i]])*(SampleInterval*1e9/SingleIonSignal)/inttime;-total(AvgBaseline[bin1[i]:bin2[i]])
endfor
coeffs = Ai#S
; convert to cps:
for i=0,numberInvolved-1 do begin
Cps[counter,i]=coeffs[i]/Faktor[i]
endfor
actualTime = double(actualBufTime)+double(averageTime)/2.0
StickTimes[counter]=MATLAB_timestamp+double(actualTime)/(24.0*3600.0)
counter=counter+1
actualBufTime=maxBufTime+dt
endwhile
print, 'calculating sticks...'
;counter=counter+1
totalElapsedTime = systime(1)-RunTimeStart
fileElapsedTime = systime(1)-FileTimeStart
estimatedTimeRemaining = (NumberOfFiles-(file+1))*fileElapsedTime/60; min
print, FORMAT='(%" %d s for this file, %d files remaining, %d minutes to go...")',$
fileElapsedTime, NumberOfFiles-(file+1),estimatedTimeRemaining
endfor
;-------------- end main loop
;create Fit_width data:
Dims = size(CPS,/DIMENSIONS)
FitWidth = make_array(Dims[0],Dims[1],/FLOAT,value=0.0)
uniVector = make_array(Dims[0],/FLOAT,value=1.0)
for i=0,Dims[1]-1 do begin
FitWidth[*,i]=uniVector/Resolution[round(MassList[i])]
endfor
;create duty area:
DutyArea = make_array(Dims[0],Dims[1],/FLOAT,value=0.0)
uniVector = make_array(Dims[0],/FLOAT,value=1.0)
for i=0,Dims[1]-1 do begin
for j=0,Dims[0]-1 do begin
DutyArea[j,i]=Cps[j,i]*sqrt(100.0/MassList[i])
endfor
endfor
;create nominal area:
maxMass = floor(max(actualMassAxis))
NominalArea = make_array(maxmass,Dims[0],/FLOAT,value=1.0)
;save Result:
;--------------------------------------------------------------------------------
folder = FILE_DIRNAME(Files[0])
file = FILEPATH('_result.hfd5',ROOT_DIR=folder)
fid = H5F_CREATE(file)
gid = H5G_CREATE(fid,'Fitted_MS_Data')
data = DutyArea
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'duty_corrected_area',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = MassList
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'exact_mass',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = MassList
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'fit_acquisition_bin_center',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = Cps
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'fit_area',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = MassList
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'fit_mass_center',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = FitWidth
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'fit_width',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = Cps*0.0+1.0
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'goodness_of_fit',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = MassList
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'mass_list',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = Cps
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'ncps',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
data = NominalArea
datatype_id = H5T_IDL_CREATE(float(data))
dataspace_id = H5S_CREATE_SIMPLE(size(data,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'nominal_area',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,data
datatype_id = H5T_IDL_CREATE(double(StickTimes))
dataspace_id = H5S_CREATE_SIMPLE(size(StickTimes,/DIMENSIONS))
dataset_id = H5D_CREATE(gid,'time_fit',datatype_id,dataspace_id)
H5D_WRITE,dataset_id,StickTimes
H5G_CLOSE, gid
H5F_CLOSE, fid
end
PRO createAvgSpectra, event
WIDGET_CONTROL, /HOURGLASS
runtime_strt=systime(1)
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_DestDir'), GET_VALUE=DestFolder
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'List_Files'), GET_uVALUE=Files
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'label_2'), gET_uVALUE= Names
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_log'), gET_VALUE= log
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_info'), gET_VALUE= info
Names=Files
n = size(Names,/DIMENSIONS)
for i=0,n[0]-1 do begin
Names[i]=FILE_BASENAME(Files[i])
endfor
i=0
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_Ind1'), SET_VALUE=string(i, format='(I5)')
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Text_Ind2'), SET_VALUE=string(i, format='(I5)')
;delete data from previous file
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Label_6'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'Label_7'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_1'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_2'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_3'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_4'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_5'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_6'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_10'), set_uVALUE= -9999
WIDGET_CONTROL, WIDGET_INFO(event.TOP, FIND_BY_UNAME = 'base_12'), set_uVALUE= -9999
numberOfFiles=(size(Files,/DIMENSIONS))[0]-1
; read ToF-parameters a, t0, ex from the first file, do mass correction and baseline for every "new" file not already processed:
for i=0,numberOfFiles do begin