-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathNM_UtilityWaveLists.ipf
More file actions
10394 lines (7242 loc) · 248 KB
/
NM_UtilityWaveLists.ipf
File metadata and controls
10394 lines (7242 loc) · 248 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
//
//****************************************************************
//****************************************************************
//
// Utility Functions that work with Wave Lists
//
// String folder // NM data folder where waves in wList exist
// String wList // list of input wave names with ";" seperator ( full-path does not work, use folder )
// String xWave // name of x-scale wave of wList, only for x-y paired data sets
// Variable xbgn, xend // x-axis window begin and end
//
//****************************************************************
//****************************************************************
Constant NMGraphAxisStandoff = 0 // ( 0 ) no ( 1 ) yes
Constant NMGraphShowInfo = 0 // ( 0 ) no ( 1 ) yes
StrConstant NMInterpolateAlg = "cubic spline" // "linear" or "cubic spline" or "smoothing spline"
StrConstant NMAlignAtList = "zero;max alignment value;min alignment value;average alignment value;"
Static Constant XaxisStatsTolerance = 1e-4 // for dx, leftx and rightx comparisons
//****************************************************************
//****************************************************************
Structure NMParams
// inputs
String fxn // function name
String paramList // list of parameters used in function execution
String folder // NM data folder where waves in wList exist
String wList // list of input wave names with ";" seperator ( full-path does not work, use folder )
String xWave // name of x-scale wave of wList, only for x-y paired data sets
String wavePrefix // wave prefix ( e.g. "Record" )
String prefixFolder // e.g. "root:nmFolder0:NMPrefix_Record:"
Variable chanNum // channel number
Variable transforms // use channel transforms ( 0 ) no ( 1 ) yes
String waveSelect // wave select ( e.g. "All" or "Set1" )
String xLabel, yLabel // x-axis and y-axis labels
// outputs
String successList // list of names that successfully pass thru function execution
String failureList // list of names that failed to pass thru function execution
String newList // list of names of things created in function ( e.g. waves, variables, strings )
String windowList // list of windows made
EndStructure // NMParams
//****************************************************************
//****************************************************************
Function NMParamsNull( nm )
STRUCT NMParams &nm
nm.fxn = ""; nm.paramList = ""
nm.folder = ""; nm.wList = ""; nm.xWave = ""
nm.wavePrefix = ""; nm.prefixFolder = ""; nm.chanNum = NaN; nm.transforms = 0; nm.waveSelect = ""
nm.xLabel = ""; nm.yLabel = ""
nm.successList = ""; nm.failureList = ""; nm.newList = ""; nm.windowList = ""
End // NMParamsNull
//****************************************************************
//****************************************************************
Function NMParamVarAdd( varName, varValue, nm [ integer ])
String varName
Variable varValue
STRUCT NMParams &nm
Variable integer
if ( integer )
nm.paramList += varName + "=" + num2istr( varValue ) + ";"
else
nm.paramList += varName + "=" + num2str( varValue ) + ";"
endif
End // NMParamVarAdd
//****************************************************************
//****************************************************************
Function NMParamStrAdd( strName, strValue, nm )
String strName
String strValue
STRUCT NMParams &nm
nm.paramList += strName + "=" + strValue + ";"
End // NMParamStrAdd
//****************************************************************
//****************************************************************
Function NMParamsInit( folder, wList, nm [ fxn, paramList, xWave ] )
String folder, wList
STRUCT NMParams &nm
String fxn, paramList, xWave
String wName
if ( ItemsInList( wList ) == 0 )
return 1 // error
endif
if ( strlen( folder ) == 0 )
folder = NMParent( wList )
if ( ItemsInList( folder ) > 1 )
return NMError( 90, GetRTStackInfo( 2 ), "wave input list contains multiple parent directories", "" )
endif
endif
folder = CheckNMFolderPath( folder )
if ( !DataFolderExists( folder ) )
return NMError( 30, GetRTStackInfo( 2 ), "folder", folder )
endif
if ( ParamIsDefault( xWave ) )
xWave = ""
elseif ( strlen( xWave ) > 0 )
if ( NMUtilityWaveTest( folder + xWave ) != 0 )
return NMError( 1, GetRTStackInfo( 2 ), "xWave", xWave )
endif
wName = StringFromList( 0, wList )
if ( numpnts( $folder + xWave ) != numpnts( $folder + wName ) )
return NMError( 5, GetRTStackInfo( 2 ), "xWave", xWave )
endif
endif
NMParamsNull( nm )
nm.folder = folder
nm.wList = NMChild( wList )
nm.xWave = xWave
if ( ParamIsDefault( fxn ) )
nm.fxn = GetRTStackInfo( 2 )
else
nm.fxn = fxn
endif
if ( !ParamIsDefault( paramList ) )
nm.paramList = NMCmdVarListConvert( paramList )
endif
return 0
End // NMParamsInit
//****************************************************************
//****************************************************************
Function NMParamsError( nm [ skipWaveList, skipXwave ] )
STRUCT NMParams &nm
Variable skipWaveList, skipXwave
Variable wcnt, numWaves, npnts
String wName, badList = ""
if ( ItemsInList( nm.wList ) == 0 )
return 1 // error
endif
if ( !DataFolderExists( nm.folder ) )
return NMError( 30, GetRTStackInfo( 2 ), "folder", nm.folder )
endif
if ( !skipWaveList )
for ( wcnt = 0 ; wcnt < ItemsInList( nm.wList ) ; wcnt += 1 )
wName = StringFromList( wcnt, nm.wList )
if ( !WaveExists( $nm.folder + wName ) )
badList += wName + ";"
endif
endfor
numWaves = ItemsInList( badList )
if ( numWaves >= 1 )
NMDoAlert( "Abort: the following waves do not exist: " + badList, title=GetRTStackInfo( 2 ) )
return 1 // error
endif
endif
if ( !skipXwave && strlen( nm.xWave ) > 0 )
if ( NMUtilityWaveTest( nm.folder + nm.xWave ) != 0 )
return NMError( 1, GetRTStackInfo( 2 ), "xWave", nm.folder + nm.xWave )
endif
npnts = GetXstats( "numPnts" , nm.wList, folder=nm.folder )
if ( numpnts( $nm.folder + nm.xWave ) != npnts )
return NMError( 5, GetRTStackInfo( 2 ), "xWave", nm.folder + nm.xWave )
endif
endif
return 0 // OK
End // NMParamsError
//****************************************************************
//****************************************************************
Function NMParamsComputeFailures( nm )
STRUCT NMParams &nm
nm.failureList = RemoveFromList( nm.successList, nm.wList )
End // NMParamsComputeFailures
//****************************************************************
//****************************************************************
//
// Edit Functions
// Make, Move, Duplicate, Rename, Renumber...
//
//****************************************************************
//****************************************************************
Structure NMMakeStruct
Variable numWaves, xpnts, dx, ypnts, dy, value, noiseStdv, precision, overwrite
String xLabel, yLabel
EndStructure
//****************************************************************
//****************************************************************
Function NMMakeStructNull( m )
STRUCT NMMakeStruct &m
m.xLabel = ""
m.yLabel = ""
End
//****************************************************************
//****************************************************************
Function NMMakeError( numWaves, xpnts )
Variable numWaves, xpnts
if ( ( numtype( numWaves ) > 0 ) || ( numWaves <= 0 ) )
return NM2Error( 10, "numWaves", num2istr( numWaves ) )
endif
if ( ( numtype( xpnts ) > 0 ) || ( xpnts <= 0 ) )
return NM2Error( 10, "xpnts", num2istr( xpnts ) )
endif
//if ( ( numtype( dx ) > 0 ) || ( dx <= 0 ) )
//return NM2Error( 10, "dx", num2istr( dx ) )
//endif
return 0
End // NMMakeError
//****************************************************************
//****************************************************************
Function /S NMMake2( nm, m [ history ] )
STRUCT NMParams &nm // uses nm.folder, nm.wList, nm.wavePrefix, nm.chanNum
STRUCT NMMakeStruct &m
Variable history
Variable wcnt, createNames, value = m.value
String wName
SetNMstr( NMDF + "OutputWaveList", "" )
nm.folder = CheckNMFolderPath( nm.folder )
if ( !DataFolderExists( nm.folder ) )
return NM2ErrorStr( 30, "folder", nm.folder )
endif
if ( ItemsInList( nm.wList ) > 0 )
m.numWaves = ItemsInList( nm.wList )
elseif ( strlen( nm.wavePrefix ) == 0 )
return ""
else
createNames = 1
endif
if ( ( numtype( m.dx ) > 0 ) || ( m.dx <= 0 ) )
m.dx = 1
endif
if ( ( numtype( m.dy ) > 0 ) || ( m.dy <= 0 ) )
m.dy = 1
endif
//if ( m.waveLength > 0 )
//m.xpnts = m.waveLength / m.dx
//endif
if ( NMMakeError( m.numWaves, m.xpnts ) != 0 )
return ""
endif
NMParamVarAdd( "xpnts", m.xpnts, nm )
NMParamVarAdd( "dx", m.dx, nm )
if ( ( numtype( m.ypnts ) == 0 ) && ( m.ypnts > 0 ) )
NMParamVarAdd( "ypnts", m.ypnts, nm )
NMParamVarAdd( "dy", m.dy, nm )
endif
NMParamVarAdd( "value", m.value, nm )
if ( m.precision != 2 )
m.precision = 1
endif
NMParamVarAdd( "precision", m.precision, nm )
if ( ( numtype( m.noiseStdv ) == 0 ) && ( m.noiseStdv > 0 ) )
NMParamVarAdd( "noiseStdv", m.noiseStdv, nm )
value = 0
endif
for ( wcnt = 0 ; wcnt < m.numWaves ; wcnt += 1 )
if ( createNames )
wName = GetWaveName( nm.wavePrefix, nm.chanNum, wcnt )
nm.wList += wName + ";"
else
wName = StringFromList( wcnt, nm.wList )
endif
if ( !m.overwrite && WaveExists( $nm.folder + wName ) )
continue
endif
if ( ( numtype( m.ypnts ) == 0 ) && ( m.ypnts > 0 ) )
if ( m.precision == 2 )
Make /D/O/N=( m.xpnts, m.ypnts ) $nm.folder + wName = value
else
Make /O/N=( m.xpnts, m.ypnts ) $nm.folder + wName = value
endif
else
if ( m.precision == 2 )
Make /D/O/N=( m.xpnts ) $nm.folder + wName = value
else
Make /O/N=( m.xpnts ) $nm.folder + wName = value
endif
endif
if ( !WaveExists( $nm.folder + wName ) )
continue
endif
nm.successList += wName + ";"
nm.newList += nm.folder + wName + ";"
Wave wtemp = $nm.folder + wName
SetScale /P x 0, m.dx, wtemp
if ( m.noiseSTDV > 0 )
wtemp += gnoise( m.noiseSTDV )
endif
NMNoteType( nm.folder + wName, "NMWave", m.xLabel, m.yLabel, "" )
NMLoopWaveNote( nm.folder + wName, nm.paramList )
endfor
//NMParamVarAdd( "pnts", m.xpnts, nm, integer=1 )
NMParamsComputeFailures( nm )
if ( history )
NMLoopHistory( nm )
endif
SetNMstr( NMDF + "OutputWaveList", nm.newList )
return nm.newList
End // NMMake2
//****************************************************************
//****************************************************************
Function /S NMMove2( nm, toFolder [ copySets, history ] )
STRUCT NMParams &nm // uses nm.folder, nm.wList // copySets uses nm.wavePrefix, nm.prefixFolder, nm.chanNum
String toFolder // where to move selected waves
Variable copySets // copy Sets and Groups ( 0 ) no ( 1 ) yes
Variable history
Variable icnt, wcnt, numWaves, numSets
String wName, newPrefixFolder, fromF, toF, chanChar = "", setsList, setName
String fromSetVarName, toSetVarName, fromWList, toWList
if ( NMParamsError( nm ) != 0 )
return ""
endif
SetNMstr( NMDF + "OutputWaveList", "" )
numWaves = ItemsInList( nm.wList )
toFolder = CheckNMFolderPath( toFolder )
if ( !IsNMDataFolder( toFolder ) )
return NM2ErrorStr( 30, "toFolder", toFolder )
endif
if ( StringMatch( nm.folder, toFolder ) )
return NM2ErrorStr( 33, "toFolder", toFolder )
endif
NMParamStrAdd( "from", NMChild( nm.folder ), nm )
NMParamStrAdd( "to", NMChild( toFolder ), nm )
if ( copySets && DataFolderExists( nm.prefixFolder ) && ( strlen( nm.wavePrefix ) > 0 ) && ( numtype( nm.chanNum ) == 0 ) )
newPrefixFolder = NMPrefixFolderDF( toFolder, nm.wavePrefix )
if ( !DataFolderExists( newPrefixFolder ) )
NewDataFolder $RemoveEnding( newPrefixFolder, ":" )
endif
chanChar = ChanNum2Char( nm.chanNum )
fromF = nm.prefixFolder + "Chan" + chanChar
toF = newPrefixFolder + "Chan" + chanChar
if ( DataFolderExists( fromF ) && !DataFolderExists( toF ) )
DuplicateDataFolder $fromF, $toF // copy channel graph configurations
endif
setsList = NMSetsListAll( prefixFolder=nm.prefixFolder )
numSets = ItemsInList( setsList )
endif
for ( wcnt = 0 ; wcnt < numWaves ; wcnt += 1 )
wName = StringFromList( wcnt, nm.wList )
if ( WaveExists( $toFolder + wName ) )
continue // wave name conflict
endif
MoveWave $( nm.folder + wName ) $( toFolder + wName )
if ( !WaveExists( $nm.folder + wName ) && WaveExists( $toFolder + wName ) )
// moved
else
continue
endif
NMLoopWaveNote( toFolder + wName, nm.paramList )
nm.successList += wName + ";"
nm.newList += toFolder + wName + ";"
for ( icnt = 0 ; icnt < numSets ; icnt += 1 )
setName = StringFromList( icnt, setsList )
fromSetVarName = nm.prefixFolder + setName + NMSetsListSuffix + chanChar
toSetVarName = newPrefixFolder + setName + NMSetsListSuffix + chanChar
fromWList = StrVarOrDefault( fromSetVarName, "" )
if ( WhichListItem( wName, fromWList ) >= 0 )
toWList = StrVarOrDefault( toSetVarName, "" )
toWList = NMAddToList( wName, toWList, ";" )
SetNMstr( toSetVarName, toWList )
endif
endfor
endfor
NMParamsComputeFailures( nm )
if ( history )
NMLoopHistory( nm )
endif
SetNMstr( NMDF + "OutputWaveList", nm.newList )
return nm.newList
End // NMMove2
//****************************************************************
//****************************************************************
Function /S NMDuplicate( wList [ folder, xWave, xbgn, xend, toFolder, newPrefix, overwrite, deprecation ] )
String wList, folder, xWave // see description at top
Variable xbgn, xend // x-axis window begin and end
String toFolder // copy waves to this folder
String newPrefix // new wave prefix of duplicated waves ( must specify if there is no toFolder )
Variable overwrite, deprecation
STRUCT NMParams nm
if ( deprecation )
NMDeprecationAlert()
endif
if ( ParamIsDefault( folder ) )
folder = ""
endif
if ( StringMatch( wList, "_ALL_" ) )
wList = NMFolderWaveList( folder, "*", ";", "", 0 )
endif
if ( NMParamsInit( folder, wList, nm, xWave=xWave ) != 0 )
return ""
endif
if ( ParamIsDefault( xbgn ) || ( numtype( xbgn ) > 0 ) )
xbgn = -inf
endif
if ( ParamIsDefault( xend ) || ( numtype( xend ) > 0 ) )
xend = inf
endif
if ( ParamIsDefault( toFolder ) )
if ( ParamIsDefault( newPrefix ) || ( strlen( newPrefix ) == 0 ) )
return NM2ErrorStr( 21, "newPrefix", "" )
endif
toFolder = nm.folder
else
toFolder = CheckNMFolderPath( toFolder )
if ( !DataFolderExists( toFolder ) ) // create new NM folder
toFolder = NMChild( toFolder )
NMFolderNew( toFolder, setCurrent=0 )
if ( IsNMDataFolder( toFolder ) )
toFolder = CheckNMFolderPath( toFolder )
else
return NM2ErrorStr( 30, "toFolder", toFolder )
endif
endif
if ( ParamIsDefault( newPrefix ) )
newPrefix = ""
endif
endif
if ( StringMatch( nm.folder, toFolder ) && ( strlen( newPrefix ) == 0 ) )
return NM2ErrorStr( 21, "newPrefix", "" ) // cannot overwrite self
endif
return NMDuplicate2( nm, xbgn=xbgn, xend=xend, toFolder=toFolder, newPrefix=newPrefix, overwrite=overwrite )
End // NMDuplicate
//****************************************************************
//****************************************************************
Function /S NMDuplicate2( nm [ xbgn, xend, toFolder, newPrefix, overwrite, copySets, history ] )
STRUCT NMParams &nm // uses nm.folder, nm.wList, nm.xWave // copySets uses nm.wavePrefix, nm.prefixFolder, nm.chanNum
Variable xbgn, xend // x-axis window begin and end
String toFolder // copy waves to this folder
String newPrefix // new wave prefix of duplicated waves ( must specify if there is no toFolder )
Variable overwrite
Variable copySets
Variable history
Variable wcnt, icnt, pbgn, pend, xflag, numWaves, npnts, numSets
String wName, newName, newPrefixFolder, existList = ""
String chanChar = "", setsList, setName
String fromF, toF, fromSetVarName, toSetVarName, fromWList, toWList
if ( NMParamsError( nm ) != 0 )
return ""
endif
SetNMstr( NMDF + "OutputWaveList", "" )
numWaves = ItemsInList( nm.wList )
if ( ParamIsDefault( xbgn ) || ( numtype( xbgn ) > 0 ) )
xbgn = -inf
endif
if ( ParamIsDefault( xend ) || ( numtype( xend ) > 0 ) )
xend = inf
endif
if ( ParamIsDefault( toFolder ) )
if ( ParamIsDefault( newPrefix ) || ( strlen( newPrefix ) == 0 ) )
return NM2ErrorStr( 21, "newPrefix", "" )
endif
toFolder = nm.folder
else
toFolder = CheckNMFolderPath( toFolder )
if ( !DataFolderExists( toFolder ) )
toFolder = NMChild( toFolder )
NMFolderNew( toFolder, setCurrent=0 )
if ( IsNMDataFolder( toFolder ) )
toFolder = CheckNMFolderPath( toFolder )
else
return NM2ErrorStr( 30, "toFolder", toFolder )
endif
endif
if ( ParamIsDefault( newPrefix ) )
newPrefix = ""
endif
endif
if ( StringMatch( nm.folder, toFolder ) && ( strlen( newPrefix ) == 0 ) )
return NM2ErrorStr( 21, "newPrefix", "" ) // cannot overwrite self
endif
if ( ( numtype( xbgn ) == 0 ) || ( numtype( xend ) == 0 ) )
NMParamVarAdd( "xbgn", xbgn, nm )
NMParamVarAdd( "xend", xend, nm )
endif
if ( strlen( nm.xWave ) > 0 )
pbgn = NMX2Pnt( nm.folder + nm.xWave, xbgn )
pend = NMX2Pnt( nm.folder + nm.xWave, xend )
NMParamStrAdd( "xwave", nm.xWave, nm )
xflag = 1
endif
if ( strlen( toFolder ) > 0 )
NMParamStrAdd( "from", NMChild( nm.folder ), nm )
NMParamStrAdd( "to", NMChild( toFolder ), nm )
endif
if ( strlen( newPrefix ) > 0 )
NMParamStrAdd( "prefix", newPrefix, nm )
endif
for ( wcnt = 0; wcnt < numWaves; wcnt += 1 )
wName = StringFromList( wcnt, nm.wList )
newName = toFolder + newPrefix + wName
if ( WaveExists( $newName ) )
existList += newName + ";"
endif
endfor
if ( !overwrite && ( ItemsInList( existList ) > 0 ) )
existList = NMUtilityWaveListShort( existList )
return NM2ErrorStr( 90, "waves have conflicting names: " + existList, "" )
endif
if ( copySets && DataFolderExists( nm.prefixFolder ) && ( strlen( nm.wavePrefix ) > 0 ) && ( numtype( nm.chanNum ) == 0 ) )
newPrefixFolder = NMPrefixFolderDF( toFolder, newPrefix + nm.wavePrefix )
if ( !DataFolderExists( newPrefixFolder ) )
NewDataFolder $RemoveEnding( newPrefixFolder, ":" )
endif
chanChar = ChanNum2Char( nm.chanNum )
fromF = nm.prefixFolder + "Chan" + chanChar
toF = newPrefixFolder + "Chan" + chanChar
if ( DataFolderExists( fromF ) && !DataFolderExists( toF ) )
DuplicateDataFolder $fromF, $toF // copy channel graph configurations
endif
setsList = NMSetsListAll( prefixFolder=nm.prefixFolder )
numSets = ItemsInList( setsList )
endif
for ( wcnt = 0; wcnt < numWaves; wcnt += 1 )
if ( NMProgressTimer( wcnt, numWaves, "Copying Waves..." ) == 1 )
break // cancel
endif
wName = StringFromList( wcnt, nm.wList )
Wave wtemp = $nm.folder + wName
newName = toFolder + newPrefix + wName
if ( ( numtype( xbgn ) == 1 ) && ( numtype( xend ) == 1 ) )
Duplicate /O wtemp $newName // entire wave
else
if ( !xflag )
pbgn = x2pnt( wtemp, xbgn )
pend = x2pnt( wtemp, xend )
pbgn = max( pbgn, 0 )
pend = min( pend, numpnts( wtemp ) - 1 )
endif
Duplicate /O/R=[ pbgn, pend ] wtemp $newName
endif
if ( !WaveExists( $newName ) )
continue
endif
NMLoopWaveNote( newName, nm.paramList )
nm.successList += wName + ";"
nm.newList += newName + ";"
for ( icnt = 0 ; icnt < numSets ; icnt += 1 )
setName = StringFromList( icnt, setsList )
fromSetVarName = nm.prefixFolder + setName + NMSetsListSuffix + chanChar
toSetVarName = newPrefixFolder + setName + NMSetsListSuffix + chanChar
fromWList = StrVarOrDefault( fromSetVarName, "" )
if ( WhichListItem( wName, fromWList ) >= 0 )
toWList = StrVarOrDefault( toSetVarName, "" )
toWList = NMAddToList( NMChild( newName ), toWList, ";" )
SetNMstr( toSetVarName, toWList )
endif
endfor
endfor
NMParamsComputeFailures( nm )
if ( history )
NMLoopHistory( nm )
endif
SetNMstr( NMDF + "OutputWaveList", nm.newList )
return nm.newList
End // NMDuplicate2
//****************************************************************
//****************************************************************
Function /S NMConcatenate2( nm, wName [ dimension, overwrite, history ] )
STRUCT NMParams &nm // uses nm.folder, nm.wList
String wName // output wave name
Variable dimension // output wave dimension ( 1 ) 1D, default ( 2 ) 2D
Variable overwrite
Variable history
String wList, txt
if ( NMParamsError( nm ) != 0 )
return ""
endif
SetNMstr( NMDF + "OutputWaveList", "" )
wList = NMUtilityWaveListShort( nm.wList )
if ( ParamIsDefault( dimension ) )
dimension = 1
endif
NMParamVarAdd( "dimension", dimension, nm )
NMParamStrAdd( "wList", wList, nm )
wList = CheckNMWavePath( nm.folder, nm.wList ) // create full-path wave list
if ( overwrite || !WaveExists( $nm.folder + wName ) )
if ( dimension == 2 )
Concatenate /O wList, $nm.folder + wName
else
Concatenate /O/NP wList, $nm.folder + wName
endif
if ( WaveExists( $nm.folder + wName ) )
nm.successList = nm.wList
nm.newList = nm.folder + wName
NMLoopWaveNote( nm.folder + wName, nm.paramList )
else
nm.failureList = nm.wList
endif
endif
if ( history )
NMLoopHistory( nm )
endif
SetNMstr( NMDF + "OutputWaveList", nm.newList )
return nm.newList
End // NMConcatenate2
//****************************************************************
//****************************************************************
Function /S NMSplit2( nm, outputWaveLength, newPrefix [ xbgn, xend, overwrite, history ] )
STRUCT NMParams &nm // uses nm.folder, nm.wList
Variable outputWaveLength // output wave length
String newPrefix // prefix name of output wave
Variable xbgn, xend // x-axis window begin and end of input waves, use ( -inf, inf ) for all
Variable overwrite, history
Variable wcnt, numWaves, npnts
String wName, newPrefix2, splitList
String thisFxn = GetRTStackInfo( 1 )
if ( NMParamsError( nm ) != 0 )
return ""
endif
SetNMstr( NMDF + "OutputWaveList", "" )
numWaves = ItemsInList( nm.wList )
if ( ( numtype( outputWaveLength ) > 0 ) || ( outputWaveLength <= 0 ) )
return NM2ErrorStr( 10, "outputWaveLength", num2str( outputWaveLength ) )
endif
if ( strlen( newPrefix ) == 0 )
return NM2ErrorStr( 21, "newPrefix", "" )
endif
NMParamStrAdd( "prefix", newPrefix, nm )
if ( ParamIsDefault( xbgn ) || ( numtype ( xbgn ) > 0 ) )
xbgn = -inf
endif
if ( ParamIsDefault( xend ) || ( numtype ( xend ) > 0 ) )
xend = inf
endif
for ( wcnt = 0 ; wcnt < numWaves ; wcnt += 1 )
if ( NMProgressTimer( wcnt, numWaves, "Splitting Waves..." ) == 1 )
break // cancel
endif
wName = StringFromList( wcnt, nm.wList )
Wave wtemp = $nm.folder + wName
npnts = outputWaveLength / deltax( wtemp )
if ( npnts >= numpnts( wtemp ) )
NMHistory( thisFxn + " Error : output wave points is too large for wave " + nm.folder + wName )
continue
endif
newPrefix2 = newPrefix + wName + "_"
splitList = NMSplitWave( nm.folder + wName, newPrefix2, -1, xbgn, xend, outputWaveLength, overwrite=overwrite )
if ( ItemsInList( splitList ) > 0 )
nm.successList += wName + ";"
nm.newList += splitList
endif
endfor
NMParamsComputeFailures( nm )
if ( history )
NMLoopHistory( nm )
endif
SetNMstr( NMDF + "OutputWaveList", nm.newList )
return nm.newList
End // NMSplit2
//****************************************************************
//****************************************************************
Function /S NMSplitWave( wName, outPrefix, chanNum, xbgn, xend, splitWaveLength [ overwrite, deprecation ] )
String wName // wave to break up
String outPrefix // output wave prefix
Variable chanNum // channel number for output wave ( -1 ) for none
Variable xbgn, xend // x-axis window begin and end, use ( -inf, inf ) for all
Variable splitWaveLength // wave length of new output waves
Variable overwrite // overwrite output waves if they already exist ( 0 ) no, alert user ( 1 ) yes
Variable deprecation
Variable npnts, numWaves, wcnt, pbgn, pend, plimit
String folder, newName, paramList, returnList = ""
if ( deprecation )
NMDeprecationAlert()
endif
if ( NMUtilityWaveTest( wName ) < 0 )
return NM2ErrorStr( 1, "wName", wName )
endif
if ( strlen( outPrefix ) == 0 )
return NM2ErrorStr( 21, "outPrefix", outPrefix )
endif
if ( numtype( xbgn ) == 2 )
return NM2ErrorStr( 10, "xbgn", num2istr( xbgn ) )
endif
if ( numtype( xend ) == 2 )
return NM2ErrorStr( 10, "xend", num2istr( xend ) )
endif
if ( ( numtype( splitWaveLength ) > 0 ) || ( splitWaveLength <= 0 ) )
return NM2ErrorStr( 10, "splitWaveLength", num2istr( splitWaveLength ) )
endif
folder = NMParent( wName )
npnts = splitWaveLength / deltax( $wName )