-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMossA.m
executable file
·3224 lines (2705 loc) · 118 KB
/
MossA.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
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
function MossA(varargin)
version='1.01g';
% Initialization tasks
width=1024;
height=600;
setappdata(0,'old_height',600); %is needed for the resize function
%always storing the height befor the resize
%event occurs
if ismac
setappdata(0, 'old_height', 620);
height=620;
end
fh=figure('Visible','off','Name', ['MossA ',version],...
'resize','on','position',[200 200 width height],'MenuBar', 'none',...
'ToolBar','none','WindowButtonMotionFcn',@fh_WindowButtonMotionFcn,...
'NumberTitle', 'off','WindowButtonDownFcn', @fh_WindowButtonDownFcn,...
'ResizeFcn', @fh_ResizeFcn, 'KeyPressFcn',@fh_KeyPressFcn);
% Construct the components
handles=guidata(fh);
%defining panels
%variables defining right panels:
panel_width=230;
setappdata(0,'panel_width', panel_width);
fitting.state = 'normal';
setappdata(0,'fitting_data',fitting);
%content of left panel:
lpanh = uipanel('Parent',fh,'units','pixel','Position',[0 0.2*height panel_width 0.8*height]);
%central panel containing the graphs
cpanh = uipanel('Parent', fh, 'units', 'pixel','Position',[panel_width 0.2*height width-2*panel_width 0.8*height]);
%right panel for options
rpanh = uipanel('Parent',fh,'units', 'pixel','Position',[width-panel_width 0.2*height panel_width 0.8*height]);
%panel for the results, containing a table
bpanh = uipanel('Parent', fh, 'units', 'pixel' ,'Position', [0 20 width (0.2*height-20)]);
footer=uipanel('Parent', fh, 'units', 'pixel', 'Position', [0 0 width 20]);
%graphs:
dataAxes= axes('Parent', cpanh,'units','pixel', 'outerposition', [0 0.2*0.8*height width-2*panel_width 0.8*0.8*height]);
resAxes= axes('Parent', cpanh,'units','pixel', 'outerposition', [0 0 width-2*panel_width 0.2*0.8*height]);
%set handles for graphs:
setappdata(0,'dataAxes', dataAxes);
setappdata(0,'resAxes', resAxes);
%tabs for right panel:
hTabGroup = uitabgroup('parent',rpanh);
%**********************************************************************
%************************content of leftpan ***************************
%**********************************************************************
site_num_txt=uicontrol(lpanh, 'Style', 'edit','Horizontalalignment','right',...
'backgroundcolor', [1 1 1], 'string','1', 'Position', [10 453 20 19],...
'callback', @site_num_txt_edit,'enable','inactive');
site_num_cnt=uicontrol(lpanh, 'style','slider', 'Max', 10, 'Min',1,...
'value', 1,'SliderStep',[0.05 0.2],'position',[33 453 13 19],...
'callback', @site_num_cnt_click, 'enable', 'inactive');
func_type=uicontrol(lpanh, 'style', 'popupmenu',...
'String', {'Lorentzian', 'Gaussian', 'PseudoVoigt', 'LorSquared'},...
'Position', [55 455 0.45*panel_width 19], 'backgroundcolor', [1 1 1]);
site_type =uicontrol(lpanh, 'style', 'popupmenu',...
'String', {'Singlet', 'Doublet', 'Sextet'},...
'Position', [55 428 0.45*panel_width 19], 'backgroundcolor', [1 1 1]);
add_btn=uicontrol(lpanh, 'style', 'Pushbutton', 'String', '+',...
'Position', [0.75*panel_width 450 40 25], 'callback', @add_btn_click);
delete_btn=uicontrol(lpanh,'style', 'pushbutton', 'string', '-',...
'Position', [0.75*panel_width 425 40 25], 'callback', @delete_btn_click);
%********************bbdefinine site_param panel**************************
site_pan=uipanel('Parent',lpanh,'units', 'pixel','Position',...
[05 240 panel_width-10 180],'Title', 'Site params');
uicontrol(site_pan, 'Style', 'text', 'String', 'CS:',...
'Position', [30 145 35 15],'horizontalalignment', 'right');
cs_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 145 panel_width-130 19], 'callback', @value_cb,...
'UserData', 'cs');
cs_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 1, 'Position',[panel_width-40 147 15 15],...
'callback', @cb_click,'UserData', 'fit(1)');
uicontrol(site_pan, 'Style', 'text', 'String', 'FWHM:',...
'Position', [30 125 35 15],'horizontalalignment', 'right');
fwhm_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 125 panel_width-130 19], 'callback', @value_cb,...
'UserData', 'fwhm');
fwhm_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 1, 'Position',[panel_width-40 127 15 15],...
'callback', @cb_click,'UserData', 'fit(2)');
uicontrol(site_pan, 'Style', 'text', 'String', 'Int:',...
'Position', [30 105 35 15],'horizontalalignment', 'right');
intensity_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 105 panel_width-130 19], 'callback', @value_cb,...
'UserData', 'intensity');
intensity_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 1, 'Position',[panel_width-40 107 15 15],...
'callback', @cb_click, 'UserData', 'fit(3)');
uicontrol(site_pan, 'Style', 'text', 'String', 'QS:',...
'Position', [30 85 35 15],'horizontalalignment', 'right');
qs_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 85 panel_width-130 19], 'callback', @value_cb,...
'enable','off','UserData', 'qs');
qs_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 0, 'Position',[panel_width-40 87 15 15],...
'callback', @cb_click,'enable','off', 'UserData', 'fit(4)');
uicontrol(site_pan, 'Style', 'text', 'String', 'BHF:',...
'Position', [30 65 35 15],'horizontalalignment', 'right');
bhf_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 65 panel_width-130 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'bhf');
bhf_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 0, 'Position',[panel_width-40 67 15 15],...
'callback', @cb_click,'enable','off', 'UserData', 'fit(6)');
uicontrol(site_pan, 'Style', 'text', 'String', 'A12:',...
'Position', [30 45 35 15],'horizontalalignment', 'right');
A12_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 45 panel_width-130 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'a12');
A12_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 0, 'Position',[panel_width-40 47 15 15],...
'callback', @cb_click, 'enable','off', 'UserData', 'fit(5)');
uicontrol(site_pan, 'Style', 'text', 'String', 'A13:',...
'Position', [30 25 35 15],'horizontalalignment', 'right');
A13_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 25 panel_width-130 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'a13');
A13_cb=uicontrol(site_pan,'style', 'checkbox', 'String','',...
'Value', 0, 'Position',[panel_width-40 27 15 15],...
'callback', @cb_click, 'enable','off', 'UserData', 'fit(7)');
uicontrol(site_pan, 'Style', 'text', 'String', 'Ratio:',...
'Position', [30 05 35 15],'horizontalalignment', 'right');
pv_n_txt=uicontrol(site_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [80 05 panel_width-130 19], 'callback', @pv_n_txt_callback,...
'enable','off');
%*********************background pan
bkg_pan=uipanel('Parent',lpanh,'units', 'pixel','Position',...
[05 190 panel_width-10 45],'Title', 'Background');
uicontrol(bkg_pan, 'Style', 'text', 'String', 'Polynom:',...
'Position', [30 10 60 15],'horizontalalignment', 'right');
polynom_type=uicontrol(bkg_pan, 'style', 'popupmenu',...
'String', {'0th order', '1st order', '2nd order', '3rd order'},...
'Position', [95 14 panel_width-130 15], 'backgroundcolor', [1 1 1]);
%********************status pan:
status_pan=uipanel('Parent',lpanh,'units', 'pixel','Position',...
[05 05 panel_width-10 150],'Title', 'Status');
status_txt=uicontrol(status_pan, 'Style', 'text', 'String', '',...
'Position', [10 10 panel_width-35 120],'horizontalalignment', 'left',...
'backgroundcolor', [1 1 1]);
fit_btn=uicontrol(lpanh, 'style', 'pushbutton',...
'string', 'Fit', 'Position', [75 155 0.6*panel_width 30],...
'callback', @fit_btn_click);
stop_btn=uicontrol(lpanh, 'style', 'pushbutton',...
'string', 'STOP', 'Position', [75 155 120 30],...
'callback', @stop_btn_click,'visible','off');
ft_cb=uicontrol(lpanh,'style', 'checkbox', 'String','FT',...
'Value', 0, 'Position',[30 162 40 15],...
'callback', @ft_cb_click);
%**************************************************************************
%*************************** bpanh*****************************************
%**************************************************************************
datatable=uitable(bpanh, 'ColumnName', {'CS', 'error', 'FWHM', 'error', ...
'Int', 'error', 'QS', 'error', 'BHF', 'error', 'type', 'n', 'error',...
'a12','error', 'a13', 'error'},...
'Position', [0 0 width (0.2*height-20)], 'Columnwidth', {44},...
'RowName',[]);
%**************************************************************************
%***************************footer*****************************************
%*************************************************************************
reference_lbl=uicontrol(footer, 'Style', 'text', 'String', 'written by C. Prescher',...
'Position', [width/2 0 width/2-10 15],'horizontalalignment', 'right');
output_lbl=uicontrol(footer, 'Style', 'text', 'String', '',...
'Position', [10 0 width/2-10 15],'horizontalalignment', 'left');
%**************************************************************************
%*************************** rpanh*****************************************
%**************************************************************************
tab1 = uitab('parent',hTabGroup, 'title','Gen');
button_width = 100;
mid_spacing = 10;
if ismac
panel_width = panel_width-30;
elseif isunix
panel_width = panel_width-20;
end
load_btn=uicontrol(tab1, 'style', 'pushbutton',...
'string', 'Load data', 'Position', [05 410 button_width 30],...
'callback', @load_btn_click);
fold_cb=uicontrol(tab1,'style', 'checkbox', 'String','autofold',...
'Value', 1, 'Position',[panel_width-(button_width-mid_spacing) ...
420 90 15]);
cal_cb=uicontrol(tab1,'style', 'checkbox', 'String','calibrated',...
'Value', 0, 'Position',[panel_width-(button_width-mid_spacing) ...
390 90 15], 'callback', @cal_cb_click);
cal_btn=uicontrol(tab1, 'style', 'pushbutton',...
'string', 'Calibrate', 'Position', [05 380 button_width 30],...
'callback', @cal_btn_click);
%*********calibration panel
std_pan=uipanel('Parent',tab1,'units', 'pixel','Position',...
[05 287 panel_width 90],'Title', 'Calibration');
uicontrol(std_pan, 'Style', 'text', 'String', 'Max_vel:',...
'Position', [panel_width-160 53 60 15],'horizontalalignment', 'right');
maxv_txt=uicontrol(std_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [panel_width-85 53 60 19], 'callback', @maxv_txt_cb);
uicontrol(std_pan, 'Style', 'text', 'String', 'Std. CS:',...
'Position', [panel_width-160 33 60 15],'horizontalalignment', 'right');
stdcs_txt=uicontrol(std_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [panel_width-85 33 60 19], 'callback', @stdcs_txt_cb);
sin_cb=uicontrol(std_pan,'style', 'checkbox', 'String','sinusoidal',...
'Value', 0, 'Position',[panel_width-90 10 90 15], 'callback', @sin_cb_click);
flip_btn=uicontrol(std_pan, 'style', 'pushbutton',...
'string', 'Flip Signs', 'Position', [05 5 panel_width-140 27],...
'callback', @flip_btn_click);
%***********save panel*************************
save_pan=uipanel('Parent',tab1,'units', 'pixel','Position',...
[05 200 panel_width 80]);
save_graph_btn=uicontrol(save_pan, 'style', 'pushbutton',...
'string', 'Save Graph', 'Position', [05 40 0.4*panel_width 30],...
'callback', @save_graph_btn_click);
save_data_btn=uicontrol(save_pan, 'style', 'pushbutton',...
'string', 'Save Data', 'Position', [0.5*panel_width 40 0.4*panel_width 30],...
'callback', @save_data_btn_click);
save_sites_btn=uicontrol(save_pan, 'style', 'pushbutton',...
'string', 'Save Sites', 'Position', [05 05 0.4*panel_width 30],...
'callback', @save_sites_btn_click);
load_sites_btn=uicontrol(save_pan, 'style', 'pushbutton',...
'string', 'Load Sites', 'Position', [0.5*panel_width 05 0.4*panel_width 30],...
'callback', @load_sites_btn_click);
%***********FT options**************************************
ft_pan=uipanel('Parent',tab1,'units', 'pixel','Position',...
[05 110 panel_width 80], 'Title', 'Full Transmission Int');
uicontrol(ft_pan, 'Style', 'text', 'String', 'FWHM src:',...
'Position', [panel_width-160 45 60 15],'horizontalalignment', 'right');
fwhm_s_txt=uicontrol(ft_pan,'style','edit', 'string','0.097',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [panel_width-85 45 60 19], 'callback', @fwhm_s_txt_cb);
uicontrol(ft_pan, 'Style', 'text', 'String', 'FT factor:',...
'Position', [panel_width-160 25 60 15],'horizontalalignment', 'right');
ft_factor_txt=uicontrol(ft_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [panel_width-85 25 60 19], 'callback', @ft_factor_txt_cb);
lor2_cb=uicontrol(ft_pan,'style', 'checkbox', 'String','Lor2 SrcFunc',...
'Value', 0, 'Position',[panel_width-120 5 130 15],...
'callback', @lor2_cb_click);
%calibration of source profile:
src_cal_pan=uipanel('Parent',tab1,'units', 'pixel','Position',...
[05 40 panel_width 70], 'Title', 'Source Calibration');
uicontrol(src_cal_pan, 'Style', 'text', 'String', 'Calib. FWHM:',...
'Position', [panel_width-200 35 100 15],'horizontalalignment', 'right');
src_calib_txt=uicontrol(src_cal_pan,'style','edit', 'string','0.097',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [panel_width-85 35 60 19], 'callback', @src_calib_txt_cb);
src_calib_btn=uicontrol(src_cal_pan, 'style', 'pushbutton',...
'string', 'Calibrate', 'Position', [0.5*panel_width 05 0.4*panel_width 27],...
'callback', @src_calib_btn_click);
%make report btn...
report_btn=uicontrol(tab1, 'style', 'Pushbutton',...
'string', 'Create report', 'Position', [05 05 panel_width-15 30],...
'callback', @report_btn_click);
%*********************bounds tab***************************
%*************************************************************
tab2 = uitab('parent',hTabGroup, 'title','Bnds');
txt_width = 50;
bounds_pan=uipanel('Parent',tab2,'units', 'pixel','Position',...
[10 270 panel_width-15 170]);
uicontrol(bounds_pan, 'Style', 'text', 'String', 'Min',...
'Position', [45 155 panel_width-160 15],'horizontalalignment', 'center');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'Max',...
'Position', [65+txt_width 155 panel_width-160 15],'horizontalalignment', 'center');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'CS:',...
'Position', [05 135 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 135 20 15],'horizontalalignment', 'center');
cs_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 135 txt_width 19], 'callback', @value_cb,...
'UserData', 'cs_min');
cs_max_txt=uicontrol(bounds_pan,'style','edit', 'string','2',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 135 txt_width 19], 'callback', @value_cb,...
'UserData', 'cs_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'FWHM:',...
'Position', [05 115 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 115 20 15],'horizontalalignment', 'center');
fwhm_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 115 txt_width 19], 'callback', @value_cb,...
'UserData', 'fwhm_min');
fwhm_max_txt=uicontrol(bounds_pan,'style','edit', 'string','2',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 115 txt_width 19], 'callback', @value_cb,...
'UserData', 'fwhm_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'Int:',...
'Position', [05 95 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 95 20 15],'horizontalalignment', 'center');
intensity_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 95 txt_width 19], 'callback', @value_cb,...
'UserData', 'intensity_min');
intensity_max_txt=uicontrol(bounds_pan,'style','edit', 'string','0',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 95 txt_width 19], 'callback', @value_cb,...
'UserData', 'intensity_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'QS:',...
'Position', [05 75 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 75 20 15],'horizontalalignment', 'center');
qs_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 75 txt_width 19], 'callback', @value_cb,...
'enable','off','UserData', 'qs_min');
qs_max_txt=uicontrol(bounds_pan,'style','edit', 'string','0',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 75 txt_width 19], 'callback', @value_cb,...
'enable','off','UserData', 'qs_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'BHF:',...
'Position', [05 55 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 55 20 15],'horizontalalignment', 'center');
bhf_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 55 txt_width 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'bhf_min');
bhf_max_txt=uicontrol(bounds_pan,'style','edit', 'string','0',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 55 txt_width 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'bhf_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'A12:',...
'Position', [05 35 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 35 20 15],'horizontalalignment', 'center');
A12_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 35 txt_width 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'a12_min');
A12_max_txt=uicontrol(bounds_pan,'style','edit', 'string','0',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 35 txt_width 19], 'callback', @value_cb,...
'enable','off','UserData', 'a12_max');
uicontrol(bounds_pan, 'Style', 'text', 'String', 'A13:',...
'Position', [05 15 35 15],'horizontalalignment', 'right');
uicontrol(bounds_pan, 'Style', 'text', 'String', '-',...
'Position', [45+txt_width 15 20 15],'horizontalalignment', 'center');
A13_min_txt=uicontrol(bounds_pan,'style','edit', 'string','',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [45 15 txt_width 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'a13_min');
A13_max_txt=uicontrol(bounds_pan,'style','edit', 'string','0',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [65+txt_width 15 txt_width 19], 'callback', @value_cb,...
'enable','off', 'UserData', 'a13_max');
%**************constraints panel:
constraints_pan=uipanel('Parent',tab2,'units', 'pixel','Position',...
[10 105 panel_width-15 160], 'title', 'Constraints');
cb_width = 70;
if isunix
cb_width=57;
end
con_num_txt=uicontrol(constraints_pan, 'Style', 'edit','Horizontalalignment','right',...
'backgroundcolor', [1 1 1], 'string','0', 'Position', [50 120 20 19],...
'enable','inactive');
con_num_cnt=uicontrol(constraints_pan, 'style','slider', 'Max', 10, 'Min',1,...
'value', 1,'SliderStep',[0.05 0.2],'position',[73 120 13 19],...
'callback', @con_num_cnt_click, 'enable', 'inactive');
add_con_btn=uicontrol(constraints_pan, 'style', 'pushbutton',...
'string', 'add', 'Position', [90 115 panel_width-120 25],...
'callback', @add_con_btn_click);
uicontrol(constraints_pan, 'Style', 'text', 'String', 'Var1:',...
'Position', [05 92 35 15],'horizontalalignment', 'right');
site1_number_pop=uicontrol(constraints_pan, 'style', 'popupmenu',...
'String', {' '},...
'Position', [50 92 cb_width 19], 'backgroundcolor', [1 1 1],...
'callback', @site1_number_pop_cb);
site1_var_pop=uicontrol(constraints_pan, 'style', 'popupmenu',...
'String', {' '},...
'Position', [110 92 cb_width 19], 'backgroundcolor', [1 1 1]);
uicontrol(constraints_pan, 'Style', 'text', 'String', 'Var2:',...
'Position', [05 67 35 15],'horizontalalignment', 'right');
site2_number_pop=uicontrol(constraints_pan, 'style', 'popupmenu',...
'String', {' '},...
'Position', [50 67 cb_width 19], 'backgroundcolor', [1 1 1],...
'callback',@site2_number_pop_cb);
site2_var_pop=uicontrol(constraints_pan, 'style', 'popupmenu',...
'String', {' '},...
'Position', [110 67 cb_width 19], 'backgroundcolor', [1 1 1]);
uicontrol(constraints_pan, 'Style', 'text', 'String', 'Factor:',...
'Position', [05 37 35 15],'horizontalalignment', 'right');
con_factor_txt=uicontrol(constraints_pan,'style','edit', 'string','1',...
'backgroundcolor', [1 1 1], 'horizontalalignment', 'right',...
'Position', [50 37 35 19], 'callback', @con_factor_txt_cb);
save_con_btn=uicontrol(constraints_pan, 'style', 'pushbutton',...
'string', 'save', 'Position', [90 32 panel_width-120 25],...
'callback', @save_con_btn_click);
del_con_btn=uicontrol(constraints_pan, 'style', 'pushbutton',...
'string', 'delete', 'Position', [90 5 panel_width-120 25],...
'callback', @del_con_btn_click);
%*********************************xVBF tab********************************
%***********************************************************************
tab3 = uitab('parent',hTabGroup, 'title','xVBF');
tab3_c=cxVBF(tab3);
set(tab3_c.qsd_axes,'nextplot','add');
set(tab3_c.csd_axes,'nextplot','add');
%*********************************options tab*****************************
%*************************************************************************
tab5=uitab('parent', hTabGroup,'title','opt');
tab5_content=coptions(tab5);
%**************************************************************************
%***********************Initialize Variables*******************************
%**************************************************************************
data.x=linspace(-10,10,512);
%data.y=1e5-doublet(0.2,0.4,500,0.7,0.5,data.x)-doublet(1.1,0.4,800,2.1,0.5,data.x);
data.y=1e5-sextet(0 ,0.4,800,0,1.5, 33, 3, data.x);
noise=0.2*randn(1,length(data.y))*sqrt(max(data.y)-min(data.y));
data.y=data.y+noise;
%normalize to 100!
setappdata(0,'data',data);
setappdata(0,'I0',max(data.y));
%initiate variables
site_y(1:length(data.x))=NaN;
site_h=plot(data.x,site_y,'g-');
site(1)=csite(1,2,3,site_h);
setappdata(0,'residual', site_y);
setappdata(0,'site_data',site);
setappdata(0,'site_cur',1);
setappdata(0,'site_num',0);
setappdata(0,'fwhm_s', 0.097);
setappdata(0,'ft_fit', 0);
setappdata(0,'ft_scale',1);
setappdata(0,'ft_factor',1);
setappdata(0,'ft_y',[]); %fitted y for the full transmission integral
setappdata(0,'ft_lor2',0); %variable if Lorentzian squared should be used as srce funcion
setappdata(0,'src_calib_fwhm', 0.097); %variable for calibration of the src
setappdata(0,'sinusoidal',0)
%constraints stuff_
setappdata(0, 'con_num',0);
setappdata(0, 'con_cur',0);
setappdata(0, 'con_matrix', [0 0 0 0 0]); %saving the data for the constraints
%as [site1 var site2 var factor]
%background stuff:
setappdata(0, 'bkg_param', [0 0 0 0]);
setappdata(0, 'bkg_order', 1);
function createHandles()
data=getappdata(0,'data');
site=getappdata(0,'site_data');
bkgOrder=getappdata(0,'bkg_order');
bkgParam=getappdata(0,'bkg_param');
I0=getappdata(0,'I0');
siteNum=getappdata(0,'site_num');
siteCur=getappdata(0,'site_cur');
axes(dataAxes);
%%first find opimal x and y range:
%set axis properly
%y Axis
data_ymax=max(data.y);
data_ymin=min(data.y);
yrange=data_ymax-data_ymin;
YLim(1)=data_ymin-yrange*0.1;
YLim(2)=data_ymax+yrange*0.1;
%x Axis
data_xmax=max(data.x);
data_xmin=min(data.x);
xrange=data_xmax-data_xmin;
XLim(1)=data_xmin-xrange*0.05;
XLim(2)=data_xmax+xrange*0.05;
xlim(XLim);
ylim(YLim);
%create data handle and background handle:
data.h=plot(data.x,data.y,'k.');
hold on;
%bkg:
y=ones(1,length(data.x))*I0;
for k=2:bkgOrder
y=y-bkgParam(k)*data.x.^(k-1);
end
bkg_h=plot(data.x,y,'b-');
%site spectra
for k=1:siteNum
site_y=y-site(k).calc(data.x);
site(k).line_h=plot(data.x,site_y,'-b');
if k==siteCur
set(site(k).line_h,'color','r');
end
end
%sum spectra:
if ~getappdata(0,'ft_fit')
for k=1:siteNum
y=y-site(k).calc(data.x);
end
sum_h=plot(data.x,y,'g-','linewidth',2);
else
sum_h=plot(data.x, getappdata(0,'ft_y'),'g-','linewidth',2);
end
hold off;
%initiate the residual
res_h=plot(resAxes,data.x,getappdata(0,'residual'),'b.');
set(resAxes,'xlim',XLim);
data.XLim=XLim;
data.YLim=YLim;
set(dataAxes,'ylim',YLim);
set(dataAxes,'xlim',XLim);
%save all the handles:
setappdata(0,'site_data',site);
setappdata(0,'data',data);
setappdata(0,'res_h',res_h);
setappdata(0,'sum_h',sum_h);
setappdata(0,'bkg_h',bkg_h);
resize_graphs();
%now the xVBF plots:
if site(siteCur).fit_method==2
tab3_c.delete_graph_handles();
tab3_c.create_graph_handles();
end
end
setappdata(0,'createHandles',@createHandles);
createHandles();
%if we wish to stop the fitting
setappdata(0, 'stop_fitting',0);
%set(hTabGroup,'selectedindex',1);
%load calibration data, if it was determined before:
if ismac
if exist('~/.MossA/calibration.txt')
calibration_filename = '~/.MossA/calibration.txt';
else
calibration_filename = '';
end
else
%windows or unix, saves the calibration in the same folder as the
%program
if exist('calibration.txt')
calibration_filename = 'calibration.txt';
else
calibration_filename = '';
end
end
if ~strcmp(calibration_filename,'')
calibration=dlmread(calibration_filename);
set(maxv_txt,'String', calibration(1));
set(stdcs_txt,'String', calibration(2));
setappdata(0,'maxv', calibration(1));
setappdata(0,'stdcs', calibration(2));
else
set(maxv_txt,'String', 5);
set(stdcs_txt,'String', 0);
setappdata(0,'maxv', 5);
setappdata(0,'stdcs', 0);
end
resize_graphs();
guidata(fh,handles);
setappdata(0, 'state', 'normal');
set(fh,'visible', 'on');
movegui(fh,'onscreen');
%**************************************************************************
%**************functionality for lpanh*************************************
%**************************************************************************
function add_btn_click(~, ~)
fitting = getappdata(0,'fitting_data');
if strcmp(fitting.state,'normal')
fitting.state='define1';
setappdata(0,'fitting_data',fitting);
site_num=getappdata(0,'site_num')+1;
setappdata(0,'site_num',site_num);
setappdata(0,'site_cur',site_num);
%define initial values
site=getappdata(0,'site_data');
data=getappdata(0,'data');
clear site_y;
site_y(1:length(data.x))=NaN;
axes(dataAxes);
hold on;
length(data.x);
length(site_y);
line_h=plot(data.x,site_y,'r-');
%vertical line
line_ver_h=plot([0 0], [NaN NaN],'r--');
line_hor_h=plot([min(data.x) max(data.x)], [NaN NaN],'r--');
hold off;
setappdata(0,'line_ver_h',line_ver_h);
setappdata(0,'line_hor_h',line_hor_h);
site(site_num)=csite(0,0.2,min(data.y),line_h);
site(site_num).intensity_max=inf;
type=get(site_type,'String');
site(site_num).type=type(get(site_type,'Value'));
type=get(func_type,'String');
site(site_num).func_type=type(get(func_type, 'Value'));
if strcmp(site(site_num).func_type, 'PseudoVoigt')
site(site_num).n=0.5;
end
if strcmp(site(site_num).func_type, 'FT_Lor2')
site(site_num).ta=2;
end
setappdata(0,'site_data', site);
update_txt();
%define the slider things
set(site_num_txt, 'String', site_num);
if site_num>=2
set(site_num_cnt, 'Enable','on');
set(site_num_cnt, 'Max', site_num);
set(site_num_cnt, 'Min', 1);
set(site_num_cnt, 'Value' , site_num);
set(site_num_cnt, 'SliderStep', [1/(site_num-1) 5]);
for k=1:site_num-1
set(site(k).line_h,'color','b');
end
end
%delete the possible graph handles in xVBF
tab3_c.delete_graph_handles();
tab3_c.update();
end
end
function delete_btn_click(~, ~)
site=getappdata(0,'site_data');
site_cur=getappdata(0,'site_cur');
site_old=getappdata(0,'site_data');
site_num=getappdata(0,'site_num');
counter=0;
if site_num>0
site(site_cur).delete_h();
end
%saving the con matrix of the deleted site:
if site_num>1
for k=1:site_num
if k~=site_cur
counter=counter+1;
site_new(counter)=site_old(k);
end
end
setappdata(0,'site_data', site_new);
site=site_new;
site_num=site_num-1;
else
site_num=0;
end
setappdata(0,'site_num', site_num);
%slider mist:
if site_cur>1
site_cur=site_cur-1;
else
site_cur=1;
%reset the textboxes
if site_num>=1
else
set(cs_txt,'String','');
set(fwhm_txt,'String',0.19);
set(intensity_txt,'String','');
end
end
set(site_num_txt, 'String', site_cur);
set(site_num_cnt, 'Value', site_cur);
setappdata(0,'site_cur', site_cur);
if site_num>1
set(site_num_cnt, 'Enable','on');
if site_num>=2
set(site_num_cnt, 'SliderStep', [1/(site_num-1) 5]);
set(site_num_cnt, 'Max', site_num);
end
else
set(site_num_cnt, 'Enable', 'off');
set(site_num_txt, 'String', 1);
end
if site_num>0
set(site_new(site_cur).line_h,'color','r');
end
update_sum();
update_txt();
%managing the graph handles in
tab3_c.delete_graph_handles();
if site_num>0
tab3_c.create_graph_handles();
else
tab3_c.xVBF_off;
set(tab3_c.convert_cb,'enable', 'off');
end
%now the constraints accompanied with the site should be
%deleted...
%sort the absolute values and now delete the constraints from
%above....
end
function site_num_cnt_click(hObject, ~)
set(site_num_txt,'String', get(hObject, 'Value'));
site_cur=get(hObject, 'Value');
site_num=getappdata(0,'site_num');
site=getappdata(0,'site_data');
setappdata(0,'site_cur', site_cur);
for k=1:site_num
if k==site_cur
set(site(k).line_h,'color','r');
else
set(site(k).line_h,'color','b');
end
end
update_txt();
end
function value_cb(hObject, ~)
str=get(hObject,'string');
str=strrep(str,',','.');
var=str2double(str);
if isnan(var)
beep;
set(hObject,'String', '');
else
set(hObject,'String',var);
site=getappdata(0,'site_data');
site_cur=getappdata(0,'site_cur');
str=['site(site_cur).',get(hObject, 'UserData'),'=str2double(get(hObject,''String''))'];
eval(str);
setappdata(0,'site_data',site);
site(site_cur).update_h();
update_sum();
end
end
function cb_click(hObject, ~)
old_value=get(hObject, 'Value');
site=getappdata(0,'site_data');
site_cur=getappdata(0,'site_cur');
str=['site(site_cur).',get(hObject, 'UserData'),'=old_value;'];
eval(str);
setappdata(0,'site_data', site);
update_txt();
end
%function um intensities zu �ndern wenn man in den FT_modus wechselt
function y=ft_calib_func(x,xdata)
if getappdata(0, 'ft_lor2')
y1=lorentz_squared(0,0.097,1,xdata);
else
y1=lorentz_curve(0,0.097,1,xdata);
end
y2=exp(-lorentz_curve(0,0.097,x,xdata));
y_model=conv(y1,y2,'same');
I0=getappdata(0,'I0');
y=I0/100*y_model;
end
function ft_cb_click(hObject,~)
value=get(hObject,'Value');
setappdata(0,'ft_fit', value);
site=getappdata(0,'site_data');
site_num=getappdata(0,'site_num');
data=getappdata(0,'data');
I0=getappdata(0,'I0');
%changing intensities of sites, to be more in the range
if value
%if FT is selected
ival=1;
%wir definieren eine Lorentzcurve mit der range vom spektrum
%und fitten dann das FT_integral dazu um eine ungef�hre
%approximation zu haben
xdata=-5:0.01:5;
ydata=I0-lorentz_curve(0,0.194,(I0-min(data.y))*pi*0.097,xdata);
param=lsqcurvefit(@ft_calib_func,ival,xdata,ydata);
height=param/(pi*0.0485);
%the approximate height of the highes peak with full
%transmission integral
%changing all intensities of the sites
for k=1:site_num
site_height=site(k).intensity/(pi*site(k).hwhm);
site(k).intensity=site_height/(I0-min(data.y))*height;
end
%calculating new ft_factor
ft_factor=(I0-min(data.y))/height;
setappdata(0,'ft_factor',ft_factor);
set(ft_factor_txt,'String', ft_factor);
else
%change intensities
for k=1:site_num
height=max(site(k).calc(data.x));
new_height=height*getappdata(0, 'ft_factor');
site(k).intensity=new_height*pi*site(k).hwhm;
end
end
%changing FWHM minimum value to an the real or double FWHM
for k=1:site_num
if get(hObject, 'Value')
if site(k).fwhm_min==0.194
site(k).fwhm_min=0.097;
end
else
if site(k).fwhm_min==0.097
site(k).fwhm_min=0.194;
end
end
end
setappdata(0,'site_data',site);
if site_num>0
update_txt();
end
%saving the new data
if value
y=get(getappdata(0,'sum_h'),'ydata');
setappdata(0,'ft_y', y);
end
%changing the plots
for k=1:site_num
site(k).update_h();
end
update_sum();
end
function fit_btn_click(hObject, ~)
site_num=getappdata(0,'site_num');
if site_num>0
site=getappdata(0,'site_data');
set(hObject, 'visible' , 'off');
set(stop_btn,'visible' , 'on');
setappdata(0,'stop_fitting',0);
%fitting procedure
ft_fit=getappdata(0,'ft_fit');
if ft_fit
fwhm_s=getappdata(0,'fwhm_s');
fitting=cft_fit(status_txt,dataAxes, site, get(polynom_type,'Value'), fwhm_s);
[site, table,residual, y]=fitting.process();
if ~getappdata(0,'stop_fitting')
setappdata(0,'ft_y',y);
set(ft_factor_txt,'String', getappdata(0,'ft_factor'));
end
else
fitting=cta_fit(status_txt,dataAxes, site, get(polynom_type,'Value'));
[site, table,residual, y]=fitting.process();
end
clear fitting;
setappdata(0,'site_data',site);
setappdata(0,'residual',residual);
set(datatable, 'Data', table);
%update all the sites and sum
site_num=getappdata(0,'site_num');
for k=1:site_num
site(k).update_h();
end
update_sum();
update_txt();
resize_graphs();
%update residual
set(getappdata(0,'res_h'),'ydata',residual);
%some other tasks
set(hObject,'enable','on');
set(hObject, 'visible','on');
set(stop_btn,'visible','off');
setappdata(0,'stop_fitting',0);