-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNM_FitTab.ipf
More file actions
5796 lines (4305 loc) · 153 KB
/
NM_FitTab.ipf
File metadata and controls
5796 lines (4305 loc) · 153 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
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma hide = 1
//****************************************************************
//****************************************************************
//
// NeuroMatic: data aquisition, analyses and simulation software that runs with the Igor Pro environment
// Copyright (C) 2024 The Silver Lab, UCL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// Contact Jason@ThinkRandom.com
// www.NeuroMatic.ThinkRandom.com
//
//****************************************************************
//****************************************************************
//
// Fit Tab
//
// Set and Get functions:
//
// NMFitSet( [ fxn, numTerms, xoffset, pntsPerCycle, synExpSign, xbgn, xend, cursors, weighting, fitFullWidth, fitSave, fitPoints, fitResiduals, autoFit, printResults, update, history ] )
// NMConfigVarSet( "Fit" , varName, value )
// NMConfigStrSet( "Fit" , strVarName, strValue )
// NMFitVarGet( varName )
// NMFitStrGet( strVarName )
//
// Useful functions:
//
// NMFitUserFxnAdd( fxn, numParams [ history ] )
// NMFitFxnListRemove( fxn [ history ] )
// NMFitAll( [ chanSelectList, waveSelectList, pause, history ] )
// NMFitWave( [ history ] )
// NMFitWaveCompute( guessORfit [ history ] )
// NMFitSaveCurrent( [ history ] )
// NMFitClearCurrent( [ history ] )
// NMFitClearAll( [ history ] )
// NMFitPlotAll( plotData [ history ] )
// NMFitSubfolderTable( subfolder [ history ] )
//
//****************************************************************
//****************************************************************
Static Constant OverwriteMode = 1 // ( 0 ) no ( 1 ) yes
Static Constant UserSubfolders = 1 // ( 0 ) no ( 1 ) yes
Static Constant FitAuto = 0 // compute fit when incrementing thru waves ( 0 ) no ( 1 ) yes
Static Constant AutoTable = 1 // create table of fit results ( 0 ) no ( 1 ) yes
Static Constant AutoGraph = 1 // create graph of fit results ( 0 ) no ( 1 ) yes
Static Constant SaveFitWaves = 1 // ( 0 ) no ( 1 ) yes
Static Constant FullGraphWidth = 0 // ( 0 ) no ( 1 ) yes
Static Constant Residuals = 0 // ( 0 ) no ( 1 ) yes
Static Constant PrintResults = 0 // ( 0 ) no ( 1 ) yes
Static Constant Weighting = 0 // ( 0 ) no ( 1 ) yes
Static Constant SynExpSign = 1 // ( -1 ) negative events ( 1 ) positive events
Static Constant printCurveFitCommand = 0 // print CurveFit command to history ( 0 ) no ( 1 )
Static Constant MaxIterations = 40
Static Constant Tolerance = 0.001
Static Constant MultiThreads = 1 // ( 0 ) no ( 1 ) yes
Static Constant FitMethod = 0 // 0, 1, 2, 3 ( see Igor CurveFit /ODR )
Static Constant KeidingGuessAuto = 1 // ( 0 ) no ( 1 ) yes
//Static Constant KeidingConstraints = 0 // ( 0 ) no ( 1 ) yes
Static StrConstant WeightingPrefix = "Stdv_" // weighting wave name prefix
Static StrConstant GHK_Xunits = "mV" // "V" or "mV"
StrConstant NMFitDF = "root:Packages:NeuroMatic:Fit:"
Static StrConstant IgorFitFxnList = "f:Line,n:2;f:Poly,n:3;f:Poly_XOffset,n:3;f:Gauss,n:4;f:Lor,n:4;f:Exp,n:3;f:Exp_XOffset,n:3;f:DblExp,n:5;f:DblExp_XOffset,n:5;f:Sin,n:4;f:HillEquation,n:4;f:Sigmoid,n:4;f:Power,n:3;f:LogNormal,n:4;"
Static StrConstant NMFitFxnList = "f:NMExp3,n:8;f:NMAlpha,n:4;f:NMGamma,n:3;f:NMGauss,n:2;f:NMGauss1,n:4;f:NMSynExp3,n:7;f:NMSynExp4,n:9;f:NM_IV,n:2;f:NM_IV_Boltzmann,n:5;f:NM_IV_GHK,n:4;f:NM_IV_GHK_Boltzmann,n:7;f:NM_MPFA1,n:4;f:NM_MPFA2,n:5;f:NM_RCvstep,n:6;f:NMCircle,n:3;f:NMEllipse,n:4;f:NMKeidingGauss,n:6;f:NMKeidingChi,n:4;f:NMKeidingGamma,n:5;"
//****************************************************************
//****************************************************************
Menu "NeuroMatic"
Submenu StrVarOrDefault( NMDF + "NMMenuShortcuts" , "\\M1(Keyboard Shortcuts" )
StrVarOrDefault( NMDF + "NMMenuShortcutFit0" , "" )
StrVarOrDefault( NMDF + "NMMenuShortcutFit1" , "" ), /Q, NMFitCall( "Fit", "" )
StrVarOrDefault( NMDF + "NMMenuShortcutFit2" , "" ), /Q, NMFitCall( "Save", "" )
StrVarOrDefault( NMDF + "NMMenuShortcutFit3" , "" ), /Q, NMFitCall( "Clear", "" )
End
End // NeuroMatic menu
//****************************************************************
//****************************************************************
Function NMMenuBuildFit()
if ( NMVarGet( "NMOn" ) && StringMatch( CurrentNMTabName(), "Fit" ) )
SetNMstr( NMDF + "NMMenuShortcutFit0", "-" )
SetNMstr( NMDF + "NMMenuShortcutFit1", "Fit Wave/4" )
SetNMstr( NMDF + "NMMenuShortcutFit2", "Save Fit/5" )
SetNMstr( NMDF + "NMMenuShortcutFit3", "Clear Fit/6" )
else
SetNMstr( NMDF + "NMMenuShortcutFit0", "" )
SetNMstr( NMDF + "NMMenuShortcutFit1", "" )
SetNMstr( NMDF + "NMMenuShortcutFit2", "" )
SetNMstr( NMDF + "NMMenuShortcutFit3", "" )
endif
End // NMMenuBuildFit
//****************************************************************
//****************************************************************
Function /S NMTabPrefix_Fit()
return "FT_"
End // NMTabPrefix_Fit
//****************************************************************
//****************************************************************
//****************************************************************
Function FitTab( enable )
Variable enable // ( 0 ) disable ( 1 ) enable tab
if ( enable )
CheckNMPackage( "Fit", 1 ) // declare globals if necessary
NMChannelGraphDisable( channel = CurrentNMChannel(), all = 0 )
NMFitMake() // create tab controls if necessary
NMFitUpdate()
endif
NMFitDisplay( -1, enable )
if ( enable )
NMFitAuto()
endif
End // FitTab
//****************************************************************
//****************************************************************
//****************************************************************
Function FitTabKill( what )
String what
strswitch( what )
case "waves":
// kill any other waves here
break
case "folder":
if ( DataFolderExists( NMFitDF ) )
KillDataFolder $NMFitDF
endif
break
endswitch
End // FitTabKill
//****************************************************************
//****************************************************************
//****************************************************************
//
// Channel Graph Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitDisplay( chan, appnd )
Variable chan // channel number ( -1 ) for current channel
Variable appnd // 1 - append wave; 0 - remove wave
Variable ccnt, drag = appnd
String gName
if ( !DataFolderExists( NMFitDF ) )
return 0
endif
if ( !NMVarGet( "DragOn" ) || !StringMatch( CurrentNMTabName(), "Fit" ) )
drag = 0
endif
for ( ccnt = 0 ; ccnt < NMNumChannels() ; ccnt += 1 )
gName = ChanGraphName( ccnt )
if ( Wintype( gName ) == 0 )
continue // window does not exist
endif
RemoveFromGraph /Z/W=$gName DragBgnY, DragEndY
endfor
gName = ChanGraphName( chan )
NMDragEnable( drag, "DragBgn", "", NMFitDF+"Xbgn", "", gName, "bottom", "min", 65535, 0, 0 )
NMDragEnable( drag, "DragEnd", "", NMFitDF+"Xend", "", gName, "bottom", "max", 65535, 0, 0 )
if ( !appnd )
NMFitRemoveDisplayWaves()
endif
KillWaves /Z $NMDF + "DragTbgnX" // old waves
KillWaves /Z $NMDF + "DragTbgnY"
End // NMFitDisplay
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitDisplayClear()
String dwave = NMFitDisplayWaveName()
String df = NMFitWaveDF()
String wName = df + "W_sigma"
if ( WaveExists( $dwave ) )
Wave wtemp = $dwave
wtemp = Nan
endif
if ( WaveExists( $wName ) )
Wave wtemp = $wName
wtemp = Nan
endif
NMFitRemoveDisplayWaves()
NMDragClear( "DragBgn" )
NMDragClear( "DragEnd" )
End // NMFitDisplayClear
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitRemoveDisplayWaves()
Variable ccnt, wcnt
String gName, wName
for ( ccnt = 0 ; ccnt < NMNumChannels() ; ccnt += 1 )
gName = ChanGraphName( ccnt )
if ( Wintype( gName ) == 0 )
continue
endif
GetWindow $gName wavelist
if ( !WaveExists( $"W_WaveList" ) )
continue
endif
Wave /T W_WaveList // 3 column text wave
if ( DimSize( W_WaveList, 1 ) != 3 )
continue
endif
for ( wcnt = 0 ; wcnt < DimSize( W_WaveList, 0 ) ; wcnt += 1 )
wName = W_WaveList[ wcnt ][ 0 ]
if ( ( StrSearch( wName, "Fit_", 0, 2 ) >= 0 ) || ( StrSearch( wName, "Res_", 0, 2 ) >= 0 ) )
RemoveFromGraph /W=$gName /Z $wName
endif
endfor
endfor
KillWaves /Z W_WaveList
return 0
End // NMFitRemoveDisplayWaves
//****************************************************************
//****************************************************************
//****************************************************************
//
// Global Variables, Strings and Waves
//
//****************************************************************
//****************************************************************
//****************************************************************
Function CheckNMFitVar( varName )
String varName
return CheckNMvar( NMFitDF+varName, NMFitVarGet( varName ) )
End // CheckNMFitVar
//****************************************************************
//****************************************************************
//****************************************************************
Function CheckNMFitStr( strVarName )
String strVarName
return CheckNMstr( NMFitDF+strVarName, NMFitStrGet( strVarName ) )
End // CheckNMFitStr
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitConfigs()
NMConfigVar( "Fit", "UseSubfolders", UserSubfolders, "use subfolders when creating Fit result waves ( uncheck for previous NM formatting )", "boolean" )
NMConfigVar( "Fit", "MaxIterations", MaxIterations, "maximum number of passes before stopping fit", "" )
NMConfigVar( "Fit", "Tolerance", Tolerance, "fit termination tolerance", "" )
NMConfigVar( "Fit", "MultiThreads", MultiThreads, "use multiple processors", "boolean" )
NMConfigVar( "Fit", "FitMethod", FitMethod, "fitting method as defined by Igor CurveFit ODR", "0;1;2;3;" )
NMConfigVar( "Fit", "Weighting", Weighting, "use STDV or SEM values to compute weighted fit", "boolean" )
NMConfigStr( "Fit", "WeightingWavePrefix", WeightingPrefix, "weighting wave name prefix", "" )
NMConfigVar( "Fit", "FullGraphWidth", FullGraphWidth, "compute fits for entire x-axis", "boolean" )
NMConfigVar( "Fit", "SaveFitWaves", SaveFitWaves, "save fits to current data folder", "boolean" )
NMConfigVar( "Fit", "Residuals", Residuals, "compute residuals", "boolean" )
NMConfigVar( "Fit", "FitAuto", FitAuto, "auto fit when changing wave number", "boolean" )
NMConfigVar( "Fit", "AutoTable", AutoTable, "create table of fit results", "boolean" )
NMConfigVar( "Fit", "AutoGraph", AutoGraph, "create graph of fit results", "boolean" )
NMConfigVar( "Fit", "PrintResults", PrintResults, "print fit results to Igor Command Window", "boolean" )
NMConfigVar( "Fit", "KeidingGuessAuto", KeidingGuessAuto, "auto compute initial guesses for Keiding function", "boolean" )
//NMConfigVar( "Fit", "KeidingConstraints", KeidingConstraints, "set parameter constraints for Keiding function", "boolean" )
NMConfigStr( "Fit", "GHK_Xunits", GHK_Xunits, "x-scale units for GHK fit fxn", "V;mV;" )
End // NMFitConfigs
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitVarGet( varName )
String varName
Variable defaultVal = Nan
strswitch( varName )
case "UseSubfolders":
defaultVal = UserSubfolders
break
case "Coefficients":
defaultVal = 0
break
case "XOffset":
defaultVal = NaN
break
case "SinPointsPerCycle":
defaultVal = 0
break
case "Xbgn":
defaultVal = -inf
break
case "Xend":
defaultVal = inf
break
case "Cursors":
defaultVal = 0
break
case "FitAuto":
defaultVal = FitAuto
break
case "AutoTable":
defaultVal = AutoTable
break
case "AutoGraph":
defaultVal = AutoGraph
break
case "SaveFitWaves":
defaultVal = SaveFitWaves
break
case "FullGraphWidth":
defaultVal = FullGraphWidth
break
case "Residuals":
defaultVal = Residuals
break
case "PrintResults":
defaultVal = PrintResults
break
case "Weighting":
defaultVal = Weighting
break
case "MultiThreads":
defaultVal = MultiThreads
break
case "FitMethod":
defaultVal = FitMethod
break
case "MaxIterations":
defaultVal = MaxIterations
break
case "Tolerance":
defaultVal = Tolerance
break
case "FitAllWavesPause":
defaultVal = 0
break
case "ClearWavesSelect":
defaultVal = 1
break
case "SynExpSign":
defaultVal = SynExpSign // ( -1 ) negative events ( 1 ) positive events
break
case "KeidingGuessAuto":
defaultVal = KeidingGuessAuto
break
//case "KeidingConstraints":
//defaultVal = KeidingConstraints
//break
case "V_FitQuitReason":
defaultVal = 0
break
case "V_chisq":
defaultVal = Nan
break
case "V_npnts":
defaultVal = Nan
break
case "V_numNaNs":
defaultVal = Nan
break
case "V_numINFs":
defaultVal = Nan
break
case "V_startRow":
defaultVal = Nan
break
case "V_endRow":
defaultVal = Nan
break
default:
NMDoAlert( "NMFitVar Error: no variable called " + NMQuotes( varName ) )
return Nan
endswitch
return NumVarOrDefault( NMFitDF+varName, defaultVal )
End // NMFitVarGet
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitStrGet( strVarName )
String strVarName
String defaultStr = ""
strswitch( strVarName )
case "Equation":
defaultStr = ""
break
case "Function":
defaultStr = ""
break
case "WeightingWavePrefix":
defaultStr = "Stdv_"
break
case "FxnShort":
defaultStr = StrVarOrDefault( NMFitDF+"Function", "" )
break
case "FxnList":
defaultStr = IgorFitFxnList
break
case "UserFxnList":
defaultStr = ""
break
case "S_Info":
defaultStr = ""
break
case "S_FitNumPnts":
defaultStr= "auto"
break
case "S_XOffset":
defaultStr= "auto"
break
case "S_UserInput":
defaultStr= ""
break
case "GHK_Xunits":
defaultStr = GHK_Xunits
break
default:
NMDoAlert( "NMFitStr Error: no variable called " + NMQuotes( strVarName ) )
return ""
endswitch
return StrVarOrDefault( NMFitDF+strVarName, defaultStr )
End // NMFitStrGet
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitWavePath( wName )
String wName
return NMFitDF + "FT_" + wName
End // NMFitWavePath
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitNumParams()
return NMFitFxnListNumParams( "" )
End // NMFitNumParams
//****************************************************************
//****************************************************************
//****************************************************************
//
// Fit Function Lists
//
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitFxnListAll()
Variable icnt
String item, fname, userList = ""
String flist = NMFitStrGet( "FxnList" )
String user = NMFitFxnList + NMFitStrGet( "UserFxnList" )
if ( ItemsInList( flist ) == 0 )
flist = IgorFitFxnList
endif
for ( icnt = 0 ; icnt < ItemsInList( user ) ; icnt += 1 )
item = StringFromList( icnt, user )
fname = StringByKey( "f", item, ":", "," )
if ( exists( fname ) == 6 )
userList = AddListItem( item, userList, ";", inf )
endif
endfor
return flist + userList
End // NMFitFxnListAll
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitFxnListShort()
return NMFitFxnListByKey( NMFitFxnListAll(), "f" )
End // NMFitFxnListShort
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitFxnListByKey( fList, key )
String fList
String key
Variable icnt
String istr, kList = ""
for ( icnt = 0 ; icnt < ItemsInList( fList ) ; icnt += 1 )
istr = StringFromList( icnt, fList, ";" )
istr = StringByKey( key, istr, ":", "," )
kList = AddListItem( istr, kList, ";", inf )
endfor
return kList
End // NMFitFxnListByKey
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitFxnListNumParams( fxn )
String fxn
if ( strlen( fxn ) == 0 )
fxn = NMFitStrGet( "Function" )
endif
Variable item = WhichListItem( fxn, NMFitFxnListShort(), ";", 0, 0 )
if ( item < 0 )
return 0
endif
String f = StringFromList( item, NMFitFxnListAll(), ";" )
f = StringByKey( "n", f, ":", "," )
return str2num( f )
End // NMFitFxnListNumParams
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitFxnListNumParamsSet( fxn, numParams )
String fxn
Variable numParams
Variable oldNum = NMFitFxnListNumParams( fxn )
if ( numParams == oldNum )
return 0
endif
String fList = NMFitStrGet( "FxnList" )
String fold = "f:" + fxn + ",n:" + num2istr( oldNum )
String fnew = "f:" + fxn + ",n:" + num2istr( numParams )
fList = ReplaceString( fold, fList, fnew )
SetNMstr( NMFitDF + "FxnList", fList )
End // NMFitFxnListNumParamsSet
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitIgorListShort()
return NMFitFxnListByKey( IgorFitFxnList, "f" )
End // NMFitIgorListShort
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitFuncListShort()
return NMFitFxnListByKey( NMFitFxnList, "f" )
End // NMFitFuncListShort
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitUserFxnListShort()
return NMFitFxnListByKey( NMFitStrGet( "UserFxnList" ), "f" )
End // NMFitUserFxnListShort
//****************************************************************
//****************************************************************
//****************************************************************
//
// Tab Panel Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitMake() // create controls that will begin with appropriate prefix
Variable x0 = 40, y0 = 205, xinc, yinc = 25, fs = NMPanelFsize
y0 = NMPanelTabY + 55
CheckNMFitVar( "Coefficients" )
CheckNMFitVar( "Xbgn" )
CheckNMFitVar( "Xend" )
CheckNMFitVar( "V_FitQuitReason" )
CheckNMFitStr( "Equation" )
CheckNMFitStr( "S_FitNumPnts" )
CheckNMFitStr( "S_UserInput" )
ControlInfo /W=$NMPanelName FT_FxnGroup // check first in a list of controls
if ( V_Flag != 0 )
return 0 // tab controls exist, return here
endif
DoWindow /F $NMPanelName
GroupBox FT_FxnGroup, title = "Function", pos={x0-20,y0-23}, size={260,85}, win=$NMPanelName, fsize=fs
PopupMenu FT_FxnMenu, pos={x0+225,y0+0*yinc}, size={0,0}, bodyWidth=230, fsize=14, proc=NMFitFxnPopup, win=$NMPanelName
PopupMenu FT_FxnMenu, value=NMFitPopupList(), win=$NMPanelName, fsize=fs
SetVariable FT_UserInput, title="", pos={x0+5,y0+1*yinc+10}, size={100,50}, limits={0,inf,0}, frame=1, win=$NMPanelName
SetVariable FT_UserInput, value=$( NMFitDF+"S_UserInput" ), proc=SetNMFitUserValue, win=$NMPanelName, fsize=fs
Checkbox FT_SynExpSign, title="positive peaks", pos={x0+5,y0+1*yinc+10}, size={200,50}, value=1, proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
SetVariable FT_Coefficients, title="coefficients:", pos={x0+120,y0+1*yinc+10}, size={100,50}, limits={0,inf,0}, frame=1, win=$NMPanelName
SetVariable FT_Coefficients, value=$( NMFitDF+"Coefficients" ), proc=SetNMFitUserValue, win=$NMPanelName, fsize=fs, format="%.0f"
y0 += 95
GroupBox FT_RangeGroup, title = "Data Options", pos={x0-20,y0-23}, size={260,75}, win=$NMPanelName, fsize=fs
SetVariable FT_Xbgn, title="xbgn", pos={x0-5,y0+0*yinc+2}, size={80,50}, limits={-inf,inf,0}, win=$NMPanelName
SetVariable FT_Xbgn, value=$( NMFitDF+"Xbgn" ), proc=SetNMFitVariable, win=$NMPanelName, fsize=fs, format="%.3f"
SetVariable FT_Xend, title="xend", pos={x0+85,y0+0*yinc+2}, size={80,50}, limits={-inf,inf,0}, win=$NMPanelName
SetVariable FT_Xend, value=$( NMFitDF+"Xend" ), proc=SetNMFitVariable, win=$NMPanelName, fsize=fs, format="%.3f"
Button FT_ClearRange, pos={x0+175,y0+0*yinc}, title="Clear", size={50,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
Checkbox FT_Cursors, title="cursors", pos={x0+40,y0+1*yinc+2}, size={200,50}, value=NMFitVarGet( "Cursors" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
Checkbox FT_Weighting, title="weighting", pos={x0+125,y0+1*yinc+2}, size={200,50}, value=NMFitVarGet( "Weighting" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
y0 += 85
GroupBox FT_FitWaveGroup, title = "Output Options", pos={x0-20,y0-23}, size={260,77}, win=$NMPanelName, fsize=fs
Checkbox FT_FullGraphWidth, title="full graph width", pos={x0-5,y0+0*yinc}, size={200,50}, value=NMFitVarGet( "SaveFitWaves" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
Checkbox FT_SaveFits, title="save", pos={x0-5,y0+1*yinc+2}, size={200,50}, value=NMFitVarGet( "SaveFitWaves" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
Checkbox FT_Residuals, title="residuals", pos={x0+60,y0+1*yinc+2}, size={200,50}, value=NMFitVarGet( "Residuals" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
SetVariable FT_FitNumPnts, title="points", pos={x0+130,y0+0*yinc}, size={95,50}, limits={0,inf,0}, win=$NMPanelName
SetVariable FT_FitNumPnts, value=$( NMFitDF+"S_FitNumPnts" ), proc=SetNMFitVariable, win=$NMPanelName, fsize=fs, format="%.0f"
Button FT_Compute, pos={x0+145,y0+1*yinc}, title="Graph Now", size={80,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
y0 += 87
GroupBox FT_FitExecuteGroup, title = "Execute", pos={x0-20,y0-23}, size={260,130}, win=$NMPanelName, fsize=fs
Button FT_Fit, pos={x0-5,y0+0*yinc}, title="Fit", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
Button FT_Save, pos={x0+75,y0+0*yinc}, title="Save", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
Button FT_Clear, pos={x0+155,y0+0*yinc}, title="Clear", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
Button FT_FitAll, pos={x0-5+40,y0+1*yinc}, title="Fit All", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
//Button FT_PlotAll, pos={x0+75,y0+1*yinc}, title="Plot All", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
Button FT_Table, pos={x0+155-40,y0+1*yinc}, title="Table", size={70,20}, proc=NMFitButton, win=$NMPanelName, fsize=fs
y0 += 30
Checkbox FT_FitAuto, title="auto fit", pos={x0+25,y0+1*yinc}, size={100,50}, value=NMFitVarGet( "FitAuto" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
Checkbox FT_Print, title="print results", pos={x0+120,y0+1*yinc}, size={100,50}, value=NMFitVarGet( "PrintResults" ), proc=NMFitCheckBox, win=$NMPanelName, fsize=fs
SetVariable FT_Error, title="error #", pos={x0+70,y0+2*yinc}, size={80,50}, limits={5,500,0}, win=$NMPanelName
SetVariable FT_Error, value=$( NMFitDF+"V_FitQuitReason" ), win=$NMPanelName, fsize=fs, noedit=1
End // NMFitMake
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitUpdate()
Variable igorFxn
String ttl, userInput = ""
if ( NMVarGet( "ConfigsDisplay" ) > 0 )
return 0
endif
String fxn = NMFitStrGet( "Function" )
String eq = NMFitStrGet( "Equation" )
String flist = NMFitPopupList()
Variable fmode = WhichListItem( fxn, flist, ";", 0, 0 )
if ( ( strlen( fxn ) > 0 ) && ( WhichListItem( fxn, NMFitIgorListShort(), ";", 0, 0 ) >= 0 ) )
igorFxn = 1
endif
ttl = "Function"
if ( strlen( eq ) > 0 )
ttl = "F=" + eq
endif
//GroupBox FT_FxnGroup, win=$NMPanelName, title=ttl
if ( fmode < 0 )
fmode = 0
endif
fmode += 1
PopupMenu FT_FxnMenu, win=$NMPanelName, mode=( fmode ), value =NMFitPopupList()
strswitch( fxn )
case "Poly":
SetVariable FT_UserInput, title="", disable=1, win=$NMPanelName
Checkbox FT_SynExpSign, title = "", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=1, noedit=0, pos={100, 260}, win=$NMPanelName
break
case "Poly_XOffset":
SetVariable FT_UserInput, title="offset:", disable=0, win=$NMPanelName
Checkbox FT_SynExpSign, title = "", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=1, noedit=0, pos={160, 260}, win=$NMPanelName
userInput = NMFitStrGet( "S_XOffset" )
break
case "Exp_XOffset":
case "DblExp_XOffset":
SetVariable FT_UserInput, title="offset:", disable=0, win=$NMPanelName
Checkbox FT_SynExpSign, title = "", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=0, noedit=1, pos={160, 260}, win=$NMPanelName
userInput = NMFitStrGet( "S_XOffset" )
break
case "Sin":
SetVariable FT_UserInput, title="pnts/cycle:", disable=0, win=$NMPanelName
Checkbox FT_SynExpSign, title = "", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=0, noedit=1, pos={160, 260}, win=$NMPanelName
userInput = num2str( NMFitVarGet( "SinPointsPerCycle" ) )
break
case "NMSynExp3":
case "NMSynExp4":
SetVariable FT_UserInput, title="", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=0, noedit=1, pos={160, 260}, win=$NMPanelName
if ( NMFitVarGet( "SynExpSign" ) == 1 )
Checkbox FT_SynExpSign, title = "positive peak", disable=0, value=1, win=$NMPanelName
else
Checkbox FT_SynExpSign, title = "negative peak", disable=0, value=1, win=$NMPanelName
endif
break
default:
SetVariable FT_UserInput, title="", disable=1, win=$NMPanelName
Checkbox FT_SynExpSign, title = "", disable=1, win=$NMPanelName
SetVariable FT_Coefficients, frame=0, noedit=1, pos={100, 260}, win=$NMPanelName
endswitch
if ( ( strlen( fxn ) > 0 ) && !igorFxn )
//SetVariable FT_UserInput, title="", disable=1, win=$NMPanelName
//SetVariable FT_Coefficients, frame=0, noedit=1, pos={100, 260}, win=$NMPanelName
endif
SetNMstr( NMFitDF + "S_UserInput", userInput )
Checkbox FT_Cursors, value=NMFitVarGet( "Cursors" ), win=$NMPanelName
Checkbox FT_Weighting, value=NMFitVarGet( "Weighting" ), win=$NMPanelName
Checkbox FT_FullGraphWidth, value=NMFitVarGet( "FullGraphWidth" ), win=$NMPanelName
Checkbox FT_SaveFits, value=NMFitVarGet( "SaveFitWaves" ), win=$NMPanelName
Checkbox FT_Residuals, value=NMFitVarGet( "Residuals" ), win=$NMPanelName
Checkbox FT_FitAuto, value=NMFitVarGet( "FitAuto" ), win=$NMPanelName
Checkbox FT_Print, value=NMFitVarGet( "PrintResults" ), win=$NMPanelName
NMFitCursorsSetTimes()
End // NMFitUpdate
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMFitPopupList()
return " ;" + NMFitFxnListShort() + "---;Other;Remove from List;Print Equation;"
End // NMFitPopupList
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitPopup( ctrlName, popNum, popStr ) : PopupMenuControl
String ctrlName; Variable popNum; String popStr
String callFxn = ReplaceString( "FT_", ctrlName, "" )
NMFitCall( callFxn, popStr )
End // NMFitPopup
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitFxnPopup( ctrlName, popNum, popStr ) : PopupMenuControl
String ctrlName; Variable popNum; String popStr
strswitch( popStr )
case "---":
NMFitUpdate()
break
default:
NMFitFxnCall( popStr )
endswitch
End // NMFitFxnPopup
//****************************************************************
//****************************************************************
//****************************************************************
Function NMFitButton( ctrlName ) : ButtonControl
String ctrlName
String callFxn = ReplaceString( "FT_", ctrlName, "" )
NMFitCall( callFxn, "" )
End // NMFitButton
//****************************************************************
//****************************************************************
//****************************************************************
Function SetNMFitVariable( ctrlName, varNum, varStr, varName ) : SetVariableControl
String ctrlName; Variable varNum; String varStr; String varName
String callFxn = ReplaceString( "FT_", ctrlName, "" )