-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathNM_Utility.ipf
More file actions
4810 lines (3341 loc) · 109 KB
/
NM_Utility.ipf
File metadata and controls
4810 lines (3341 loc) · 109 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
// SetIgorOption IndependentModuleDev=1 (unhide)
//****************************************************************
//****************************************************************
//
// 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
//
//****************************************************************
//****************************************************************
//
// String folder // data folder where waves in wList exist
// String wList // list of wave names with ";" seperator
// String xWave // x-axis wave name
// Variable xbgn, xend // x-axis window begin and end
// Variable deprecation
//
//****************************************************************
//****************************************************************
StrConstant NMPlotColorList = "black;gray;red;yellow;green;blue;purple;white;"
StrConstant NMCancel = "CANCEL"
StrConstant NMCR = "\r" // carriage return
Constant NMBoltzmannConstant = 1.38064852e-23 // K // m2·kg·s-2·K-1
Constant NMFaradayConstant = 96485.33212331 // F // C·mol−1 // equal to elementary charge e
Constant NMGasConstant = 8.31446261815324 // R // kg⋅m2·K−1⋅mol−1⋅s−2
//****************************************************************
//****************************************************************
Function NMTestVarEqual( var1, var2 )
Variable var1, var2
String flist
switch( numtype( var1 ) )
case 0:
if ( ( numtype( var2 ) == 0 ) && ( var1 == var2 ) )
return 1 // var1 = var2
endif
break
case 1: // INF
if ( numtype( var2 ) == 1 )
if ( ( var1 < 0 ) && ( var2 < 0 ) )
return 1 // -INF = -INF
elseif ( ( var1 > 0 ) && ( var2 > 0 ) )
return 1 // +INF = +INF
endif
endif
break
case 2: // NaN
if ( numtype( var2 ) == 2 )
return 1 // NaN = NaN
endif
break
endswitch
flist = GetRTStackInfo( 3 )
flist = StringFromList( 0, flist )
Print "NM test failure: unequal numbers: " + num2str( var1 ) + " ≠ " + num2str( var2 ) + ": " + flist
Abort
End // NMTestVarEqual
//****************************************************************
//****************************************************************
Function NMTestVarNotEqual( var1, var2 )
Variable var1, var2
Variable equal
String flist
switch( numtype( var1 ) )
case 0:
if ( ( numtype( var2 ) == 0 ) && ( var1 == var2 ) )
equal = 1 // var1 = var2
endif
break
case 1: // INF
if ( numtype( var2 ) == 1 )
if ( ( var1 < 0 ) && ( var2 < 0 ) )
equal = 1 // -INF = -INF
elseif ( ( var1 > 0 ) && ( var2 > 0 ) )
equal = 1 // +INF = +INF
endif
endif
break
case 2: // NaN
if ( numtype( var2 ) == 2 )
equal = 1 // NaN = NaN
endif
break
endswitch
if ( !equal )
return 1
endif
flist = GetRTStackInfo( 3 )
flist = StringFromList( 0, flist )
Print "NM test failure: equal numbers: " + num2str( var1 ) + " = " + num2str( var2 ) + ": " + flist
Abort
End // NMTestVarNotEqual
//****************************************************************
//****************************************************************
Function NMTestStrEqual( str1, str2 [ casesensitive ] )
String str1, str2
Variable casesensitive // ( 0 ) no ( 1 ) yes
String flist
if ( ParamIsDefault( casesensitive ) )
casesensitive = 1
else
casesensitive = BinaryCheck( casesensitive )
endif
if ( CmpStr( str1, str2, casesensitive ) == 0 )
return 1
endif
flist = GetRTStackInfo( 3 )
flist = StringFromList( 0, flist )
Print "NM test failure: unequal strings: " + NMQuotes( str1 ) + " ≠ " + NMQuotes( str2 ) + ": " + flist
Abort
End // NMTestStrEqual
//****************************************************************
//****************************************************************
Function NMTestStrNotEqual( str1, str2 [ casesensitive ] )
String str1, str2
Variable casesensitive // ( 0 ) no ( 1 ) yes
String flist
if ( ParamIsDefault( casesensitive ) )
casesensitive = 1
else
casesensitive = BinaryCheck( casesensitive )
endif
if ( CmpStr( str1, str2, casesensitive ) != 0 )
return 1
endif
flist = GetRTStackInfo( 3 )
flist = StringFromList( 0, flist )
Print "NM test failure: equal strings: " + NMQuotes( str1 ) + " = " + NMQuotes( str2 ) + ": " + flist
Abort
End // NMTestStrNotEqual
//****************************************************************
//****************************************************************
Function BinaryCheck( num )
Variable num
if ( num == 0 )
return 0
else
return 1
endif
End // BinaryCheck
//****************************************************************
//****************************************************************
Function BinaryInvert( num )
Variable num
if ( num == 0 )
return 1
else
return 0
endif
End // BinaryInvert
//****************************************************************
//****************************************************************
Function Zero2Nan( num )
Variable num
if ( num == 0 )
return NaN
else
return num
endif
End // Zero2Nan
//****************************************************************
//****************************************************************
Function Nan2Zero( num )
Variable num
if ( numtype( num ) == 2 )
return 0
else
return num
endif
End // Nan2Zero
//****************************************************************
//****************************************************************
Function NMInequality( testValue [ greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, equal, notEqual, logic, binaryOutput, deprecation ] )
Variable testValue
Variable greaterThan // testvalue > greaterThan
Variable greaterThanOrEqual // testvalue ≥ greaterThanOrEqual
Variable lessThan // testvalue < lessThan
Variable lessThanOrEqual // testvalue ≤ lessThanOrEqual
Variable equal // testvalue == equal
Variable notEqual // testvalue != notEqual
String logic // sequence logic, "AND" or "OR"
Variable binaryOutput
// ( 0 ) output wave will contain NaN for false or corresponding input wave value for true
// ( 1 ) output wave will contain '0' for false or '1' for true
Variable deprecation
Variable test, inequality
if ( deprecation )
NMDeprecationAlert()
endif
if ( ParamIsDefault( logic ) || !StringMatch( logic, "OR" ) )
logic = "AND"
inequality = 1
else
logic = "OR"
inequality = 0
endif
if ( ParamIsDefault( binaryOutput ) )
binaryOutput = 1
endif
if ( !ParamIsDefault( greaterThan ) )
test = testValue > greaterThan
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( !ParamIsDefault( greaterThanOrEqual ) )
if ( numtype( testValue ) == 2 )
test = 0
else
test = testValue >= greaterThanOrEqual
endif
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( !ParamIsDefault( lessThan ) )
test = testValue < lessThan
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( !ParamIsDefault( lessThanOrEqual ) )
test = testValue <= lessThanOrEqual
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( !ParamIsDefault( equal ) )
switch( numtype( equal ) )
case 0:
test = testValue == equal
break
case 1: // inf
if ( equal > 0 ) // +inf
test = ( numtype( testValue ) == 1 ) && ( testValue > 0 )
else
test = ( numtype( testValue ) == 1 ) && ( testValue < 0 )
endif
break
case 2: // NaN
test = numtype( testValue ) == 2
break
endswitch
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( !ParamIsDefault( notEqual ) )
switch( numtype( notEqual ) )
case 0:
test = testValue != notEqual
break
case 1: // inf
if ( notEqual > 0 ) // +inf
test = !( ( numtype( testValue ) == 1 ) && ( testValue > 0 ) )
else // -inf
test = !( ( numtype( testValue ) == 1 ) && ( testValue < 0 ) )
endif
break
case 2: // NaN
test = numtype( testValue ) != 2
break
endswitch
if ( StringMatch( logic, "OR" ) )
inequality = inequality || test
else
inequality = inequality && test
endif
endif
if ( binaryOutput )
return inequality
elseif ( inequality )
return testValue
else
return NaN
endif
End // NMInequality
//****************************************************************
//****************************************************************
Structure NMInequalityStruct
Variable greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, equal, notEqual, binaryOutput
EndStructure
//****************************************************************
//****************************************************************
Function NMInequalityStructNull( s )
STRUCT NMInequalityStruct &s
s.greaterThan = NaN; s.greaterThanOrEqual = NaN; s.lessThan = NaN; s.lessThanOrEqual = NaN;
s.equal = NaN; s.notEqual = NaN; s.binaryOutput = 1;
End // NMInequalityStructNull
//****************************************************************
//****************************************************************
Structure NMInequalityStructOld
// old inequality variables
Variable select, aValue, sValue, nValue
// new inequality variables
Variable lessThan, greaterThan
EndStructure
//****************************************************************
//****************************************************************
Function NMInequalityStructOldNull( s )
STRUCT NMInequalityStructOld &s
s.select = NaN; s.aValue = NaN; s.sValue = NaN; s.nValue = NaN
s.lessThan = NaN; s.greaterThan = NaN
End // NMInequalityStructOldNull
//****************************************************************
//****************************************************************
Function /S NMInequalityStructConvert( select, aValue, sValue, nValue, s )
Variable select
Variable aValue, sValue, nValue
STRUCT NMInequalityStructOld &s
NMInequalityStructOldNull( s )
s.select = select
s.aValue = aValue
s.sValue = sValue
s.nValue = nValue
return NMInequalityStructConvert2( s )
End // NMInequalityStructConvert
//****************************************************************
//****************************************************************
Function /S NMInequalityStructConvert2( s ) // convert old to new variables
STRUCT NMInequalityStructOld &s
switch( s.select )
case 1: // y > a
s.greaterThan = s.aValue
break
case 2: // y > a - n * s
s.greaterThan = s.aValue - s.nValue * s.sValue
break
case 3: // y < a
s.lessThan = s.aValue
break
case 4: // y < a + n * s
s.lessThan = s.aValue + s.nValue * s.sValue
break
case 5: // a < y < b
s.greaterThan = s.aValue
s.lessThan = s.sValue
break
case 6: // a - n * s < y < a + n * s
s.greaterThan = s.aValue - s.nValue * s.sValue
s.lessThan = s.aValue + s.nValue * s.sValue
break
endswitch
return "lessThan=" + num2str( s.lessThan ) + ";greaterThan=" + num2str( s.greaterThan ) + ";"
End // NMInequalityStructConvert2
//****************************************************************
//****************************************************************
Function /S NMInequalityCall( s, df [ promptStr ] )
STRUCT NMInequalityStruct &s
String df // data folder for global variables
String promptStr
String returnList
String ilist = "y > a;y ≥ a;y < b;y ≤ b;a < y < b;a ≤ y ≤ b;y = a;y ≠ a;"
if ( ParamIsDefault( promptStr ) || ( strlen( promptStr ) == 0 ) )
promptStr = NMPromptStr( "NM Inequality <>=" )
endif
String inequality = StrVarOrDefault( df + "InequalitySelect", "y > a" )
Variable binaryOutput = 1 + NumVarOrDefault( df + "InequalityBinary", 1 )
Variable aValue = NumVarOrDefault( df + "InequalityValueA", 0 )
Variable bValue = NumVarOrDefault( df + "InequalityValueB", 0 )
Prompt inequality, "inequality test for wave point values y:", popup ilist
Prompt binaryOutput, "denote true and false with:", popup "y and NaN;1 and 0;"
Prompt aValue, "enter value for a:"
Prompt bValue, "enter value for b:"
DoPrompt promptStr, inequality, binaryOutput
if ( V_flag == 1 )
return "" // cancel
endif
NMInequalityStructNull( s )
binaryOutput -= 1
SetNMstr( df + "InequalitySelect", inequality )
SetNMvar( df + "InequalityBinary", binaryOutput )
s.binaryOutput = binaryOutput
promptStr = NMPromptStr( inequality )
returnList = "inequality=" + inequality + ";"
strswitch( inequality )
case "y > a":
DoPrompt promptStr, aValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.greaterThan = aValue
else
s.greaterThan = NaN
endif
returnList += "greaterThan=" + num2str( s.greaterThan ) + ";"
break
case "y ≥ a":
DoPrompt promptStr, aValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.greaterThanOrEqual = aValue
else
s.greaterThanOrEqual = NaN
endif
returnList += "greaterThanOrEqual=" + num2str( s.greaterThanOrEqual ) + ";"
break
case "y < b":
DoPrompt promptStr, bValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( bValue ) == 0 )
SetNMvar( df + "InequalityValueB", bValue )
s.lessThan = bValue
else
s.lessThan = NaN
endif
returnList += "lessThan=" + num2str( s.greaterThan ) + ";"
break
case "y ≤ b":
DoPrompt promptStr, bValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( bValue ) == 0 )
SetNMvar( df + "InequalityValueB", bValue )
s.lessThanOrEqual = bValue
else
s.lessThanOrEqual = NaN
endif
returnList += "lessThanOrEqual=" + num2str( s.greaterThanOrEqual ) + ";"
break
case "a < y < b":
DoPrompt promptStr, aValue, bValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.greaterThan = aValue
else
s.greaterThan = NaN
endif
if ( numtype( bValue ) == 0 )
SetNMvar( df + "InequalityValueB", bValue )
s.lessThan = bValue
else
s.lessThan = NaN
endif
returnList += "greaterThan=" + num2str( s.greaterThan ) + ";"
returnList += "lessThan=" + num2str( s.greaterThan ) + ";"
break
case "a ≤ y ≤ b":
DoPrompt promptStr, aValue, bValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.greaterThanOrEqual = aValue
else
s.greaterThanOrEqual = NaN
endif
if ( numtype( bValue ) == 0 )
SetNMvar( df + "InequalityValueB", bValue )
s.lessThanOrEqual = bValue
else
s.lessThanOrEqual = NaN
endif
returnList += "greaterThanOrEqual=" + num2str( s.greaterThanOrEqual ) + ";"
returnList += "lessThanOrEqual=" + num2str( s.greaterThanOrEqual ) + ";"
break
case "y = a":
DoPrompt promptStr, aValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.equal = aValue
else
s.equal = NaN
endif
returnList += "equal=" + num2str( s.equal ) + ";"
break
case "y ≠ a":
DoPrompt promptStr, aValue
if ( V_flag == 1 )
return "" // cancel
endif
if ( numtype( aValue ) == 0 )
SetNMvar( df + "InequalityValueA", aValue )
s.notequal = aValue
else
s.notequal = NaN
endif
returnList += "notequal=" + num2str( s.notequal ) + ";"
break
endswitch
returnList += "binaryOutput=" + num2istr( binaryOutput ) + ";"
return returnList
End // NMInequalityCall
//****************************************************************
//****************************************************************
//
// Folder utility functions
//
//****************************************************************
//
// NMFolderVariableList
// return VariableList for a given folder (see Igor VariableList function)
//
//****************************************************************
Function /S NMFolderVariableList( folder, matchStr, separatorStr, variableTypeCode, fullPath )
String folder // ( "" ) for current folder
String matchStr, separatorStr // see Igor VariableList
Variable variableTypeCode // see Igor VariableList
Variable fullPath // ( 0 ) no, just variable name ( 1 ) yes, directory + variable name
Variable icnt
String sList, sName, oList = ""
String saveDF = GetDataFolder( 1 ) // save current directory
if ( strlen( folder ) == 0 )
folder = GetDataFolder( 1 )
endif
if ( !DataFolderExists( folder ) )
return NM2ErrorStr( 30, "folder", folder )
endif
SetDataFolder $folder
sList = VariableList( matchStr, separatorStr, variableTypeCode )
SetDataFolder $saveDF // back to original data folder
if ( fullPath )
for ( icnt = 0 ; icnt < ItemsInList( sList ) ; icnt += 1 )
sName = StringFromList( icnt, sList )
oList = AddListItem( folder+sName, oList, separatorStr, inf ) // full-path names
endfor
sList = oList
endif
return sList
End // NMFolderVariableList
//****************************************************************
//
// NMFolderStringList
// return StringList for a given folder (see Igor StringList function)
//
//****************************************************************
Function /S NMFolderStringList( folder, matchStr, separatorStr, fullPath )
String folder // ( "" ) for current folder
String matchStr, separatorStr // see Igor StringList
Variable fullPath // ( 0 ) no, just variable name ( 1 ) yes, directory + variable name
Variable icnt
String sList, sName, oList = ""
String saveDF = GetDataFolder( 1 ) // save current directory
if ( strlen( folder ) == 0 )
folder = GetDataFolder( 1 )
endif
if ( !DataFolderExists( folder ) )
return NM2ErrorStr( 30, "folder", folder )
endif
SetDataFolder $folder
sList = StringList( matchStr, separatorStr )
SetDataFolder $saveDF // back to original data folder
if ( fullPath )
for ( icnt = 0 ; icnt < ItemsInList( sList ) ; icnt += 1 )
sName = StringFromList( icnt, sList )
oList = AddListItem( folder+sName, oList, separatorStr, inf ) // full-path names
endfor
sList = oList
endif
return sList
End // NMFolderStringList
//****************************************************************
//****************************************************************
//
// Wave utility functions
//
//****************************************************************
//****************************************************************
Function NMUtilityWaveTest( wList )
String wList
Variable wcnt
String wName
if ( ItemsInList( wList ) == 0 )
return -1
endif
for ( wcnt = 0 ; wcnt < ItemsInList( wList ) ; wcnt += 1 )
wName = StringFromList( wcnt, wList )
if ( !WaveExists( $wName ) || ( WaveType( $wName ) == 0 ) )
return -1
endif
endfor
return 0
End // NMUtilityWaveTest
//****************************************************************
//****************************************************************
Function WavesExist( wList )
String wList
Variable wcnt
String wName
if ( ItemsInList( wList ) == 0 )
return 0
endif
for ( wcnt = 0; wcnt < ItemsInList( wList ); wcnt += 1 )
wName = StringFromList( wcnt, wList )
if ( !WaveExists( $wName ) )
return 0
endif
endfor
return 1 // yes, all exist
End // WavesExist
//****************************************************************
//****************************************************************
Function /S WhichWavesDontExist( wList )
String wList
Variable wcnt, numWaves = ItemsInList( wList )
String wName, returnList = ""
for ( wcnt = 0 ; wcnt < numWaves ; wcnt += 1 )
wName = StringFromList( wcnt, wList )
if ( !WaveExists( $wName ) )
returnList = AddListItem( wName, returnList, ";", inf )
endif
endfor
return returnList // those that dont exist
End // WhichWavesDontExist
//****************************************************************
//****************************************************************
Function /S NMWaveBrowser( promptStr [ numWavesLimit, numPoints, noText, noSelect ] )
String promptStr
Variable numWavesLimit // check number of waves selected
Variable numPoints // check number of points
Variable noText // check for text waves
Variable noSelect // no initial selection
Variable vflag, npnts, error
String optionsStr, wList, wName = "", saveDF = GetDataFolder( 1 )
if ( ParamIsDefault( numPoints ) )
wList = WaveList( "*", ";", "" )
if ( ItemsInList( wList ) > 0 )
wName = StringFromList( 0, wList )
endif
else
optionsStr = NMWaveListOptions( numPoints, 0 )
wList =WaveList( "*", ";", optionsStr )
if ( ItemsInList( wList ) > 0 )
wName = StringFromList( 0, wList )
endif
endif
if ( !noSelect && ( strlen( wName ) > 0 ) )
Execute "CreateBrowser prompt=" + NMQuotes( promptStr ) + ", showWaves=1, showVars=0, showStrs=0, select=" + NMQuotes( wName )
else
Execute "CreateBrowser prompt=" + NMQuotes( promptStr ) + ", showWaves=1, showVars=0, showStrs=0"
endif
SetDataFolder saveDF // in case user changed data folder
if ( ( exists( "V_Flag" ) != 2 ) || ( exists( "S_BrowserList" ) != 2 ) )
return "" // no flags
endif
vflag = NumVarOrDefault( "V_Flag", 0 )
wList = StrVarOrDefault( "S_BrowserList", "" )
if ( vflag == 0 )
return "" // cancel
endif
if ( !ParamIsDefault( numWavesLimit ) && ( ItemsInList( wList ) > numWavesLimit ) )
DoAlert /T="NM Wave Browser" 0, "error: number of waves selected was greater than " + num2istr( numWavesLimit ) + "."
error = 1
wList = ""
endif
if ( !error && !WavesExist( wList ) )
DoAlert /T="NM Wave Browser" 0, "error: one or more selected items are not a wave."
error = 1
wList = ""
endif
npnts = GetXstats( "points", wList )
if ( !error && !ParamIsDefault( numPoints ) && ( npnts != numPoints ) )
DoAlert /T="NM Wave Browser" 0, "error: one or more selected waves do not have a dimension of " + num2istr( numPoints ) + " points."
error = 1
wList = ""
endif
if ( !error && noText && ( NMUtilityWaveTest( wList ) != 0 ) )
DoAlert /T="NM Wave Browser" 0, "error: one or more selected items are text waves."
error = 1
wList = ""
endif
KillVariables /Z V_Flag
KillStrings /Z S_BrowserList
if ( ItemsInList( wList ) == 1 )
return StringFromList( 0, wList )
endif
return wList
End // NMWaveBrowser
//****************************************************************
//****************************************************************
Function WaveValOrDefault( wName, rowNum, defaultVal )
String wName // wave name
Variable rowNum // wave row number to retrive value
Variable defaultVal // default value if everything values