-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNM_ImportPclamp.ipf
3038 lines (2239 loc) · 103 KB
/
NM_ImportPclamp.ipf
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
//
//****************************************************************
//****************************************************************
//
// Read PClamp Functions
//
// PClamp file header details from Axon Instruments, now Molecular Devices.
// Code for reading ABF format 1 and 2 files.
// Code for calling ReadPclampXOP if installed.
//
// Non-Static functions to be called:
// ReadPclampFormat( file )
// ReadPClampHeader( file, dataFolder )
// ReadPClampData( file, dataFolder )
// NM_ABFHeaderVar( varNameOrMatchStr [ folder, alert ] ) // reads from existing ABFHeader subfolder
// NM_ABFHeaderStr( varNameOrMatchStr [ folder, alert ] ) // reads from existing ABFHeader subfolder
// NM_ABFHeaderWaveName( matchStr [ folder ] ) // returns full path name for wave in ABFHeader subfolder
//
//****************************************************************
//****************************************************************
Static Constant ABF_SCALEWAVES = 1 // ( 0 ) no ( 1 ) yes, scale waves by scale factor read from header file
Static Constant ABF_XOP_ON = 1 // ( 0 ) no, turn off XOP if it exists ( slower ) ( 1 ) yes, use XOP to read data if it exists
Static StrConstant ABF_SUBFOLDERNAME = "ABFHeader"
Static StrConstant ABF_WAVENAMETIME1 = "ABF_WaveTimeStamps"
Static StrConstant ABF_WAVENAMETIME2 = "ABF_WaveStartTimes"
StrConstant ABF_STRINGERROR = "CouldNotFindHeaderString"
//****************************************************************
//****************************************************************
//****************************************************************
Static Constant ABF_NUMADCS = 16
Static Constant ABF_NUMDACS = 4
Static Constant ABF_EPOCHCOUNT = 10
Static Constant ABF_ADCUNITLEN = 8
Static Constant ABF_ADCNAMELEN = 10
Static Constant ABF_DACUNITLEN = 8
Static Constant ABF_DACNAMELEN = 10
Static Constant ABF_BLOCK = 512
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPclampXOPExists()
if ( ABF_XOP_ON && ( exists( "ReadPclamp" ) == 4 ) )
return 1
endif
return 0
End // ReadPclampXOPExists
//****************************************************************
//****************************************************************
//****************************************************************
Function NM_ABFHeaderVar( varNameOrMatchStr [ folder, alert ] )
String varNameOrMatchStr
String folder
Variable alert
String varList, varName = ""
if ( ParamIsDefault( folder ) )
folder = CurrentNMFolder( 1 ) + ABF_SUBFOLDERNAME + ":"
else
folder = ParseFilePath( 2, folder, ":", 0, 0 ) + ABF_SUBFOLDERNAME + ":"
endif
if ( strsearch( varNameOrMatchStr, "*", 0 ) >= 0 ) // found match string
varList = NMFolderVariableList( folder, varNameOrMatchStr, ";", 4, 0 )
if ( ItemsInList( varList ) > 0 )
varName = StringFromList( 0, varList )
endif
else
varName = varNameOrMatchStr
endif
if ( ( strlen( varName ) > 0 ) && ( exists( folder + varName ) == 2 ) )
return NumVarOrDefault( folder + varName, NaN )
endif
if ( alert )
NM2Error( 13, "varNameOrMatchStr", varNameOrMatchStr )
endif
return NaN
End // NM_ABFHeaderVar
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NM_ABFHeaderStr( varNameOrMatchStr [ folder, alert ] )
String varNameOrMatchStr
String folder
Variable alert
String varList, varName = ""
if ( ParamIsDefault( folder ) )
folder = CurrentNMFolder( 1 ) + ABF_SUBFOLDERNAME + ":"
else
folder = ParseFilePath( 2, folder, ":", 0, 0 ) + ABF_SUBFOLDERNAME + ":"
endif
if ( strsearch( varNameOrMatchStr, "*", 0 ) >= 0 ) // found match string
varList = NMFolderStringList( folder, varNameOrMatchStr, ";", 0 )
if ( ItemsInList( varList ) > 0 )
varName = StringFromList( 0, varList )
endif
else
varName = varNameOrMatchStr
endif
if ( ( strlen( varName ) > 0 ) && ( exists( folder + varName ) == 2 ) )
return StrVarOrDefault( folder + varName, ABF_STRINGERROR )
endif
if ( alert )
NM2Error( 23, "varNameOrMatchStr", varNameOrMatchStr )
endif
return ABF_STRINGERROR
End // NM_ABFHeaderStr
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NM_ABFHeaderWaveName( matchStr [ folder ] )
String matchStr
String folder
String wList, wName
if ( ParamIsDefault( folder ) )
folder = CurrentNMFolder( 1 ) + ABF_SUBFOLDERNAME + ":"
else
folder = ParseFilePath( 2, folder, ":", 0, 0 ) + ABF_SUBFOLDERNAME + ":"
endif
wList = NMFolderWaveList( folder, matchStr, ";", "", 1 )
if ( ItemsInList( wList ) > 0 )
return StringFromList( 0, wList )
endif
return ""
End // NM_ABFHeaderWaveName
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPclampFormat( file )
String file // external ABF data file
String fileID = ReadPclampString( file, 0, 4 ) // file ID signature
KillWaves /Z NM_ReadPclampWave0, NM_ReadPclampWave1
strswitch( fileID )
case "ABF ":
return 1
case "ABF2":
return 2
endswitch
return -1
End // ReadPclampFormat
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPClampHeader( file, df )
String file // external ABF data file
String df // NM data folder where everything is imported
Variable format = ReadPclampFormat( file )
df = ParseFilePath( 2, df, ":", 0, 0 )
switch( format )
case 1:
case 2:
break
default:
Print "Import File Aborted: file not of Pclamp format"
return -1
endswitch
if ( ReadPclampXOPExists() )
return ReadPClampHeaderXOP( file, df )
endif
switch( format )
case 1:
return ReadPClampHeader1( file, df )
case 2:
return ReadPClampHeader2( file, df )
endswitch
//ReadPclampXOPAlert()
return -1
End // ReadPClampHeader
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPClampData( file, df )
String file // external ABF data file
String df // NM data folder where everything is imported
Variable format = ReadPclampFormat( file )
df = ParseFilePath( 2, df, ":", 0, 0 )
switch( format )
case 1:
case 2:
break
default:
Print "Import File Aborted: file not of Pclamp format"
return -1
endswitch
if ( ReadPclampXOPExists() )
return ReadPClampDataXOP( file, df )
endif
switch( format )
case 1:
case 2: // can use old version for reading data
return ReadPClampData1( file, df )
endswitch
//ReadPclampXOPAlert()
return -1
End // ReadPClampData
//****************************************************************
//****************************************************************
//****************************************************************
//
// Read ABF Utility Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPclampVarPointer( file, varType )
String file // external ABF data file
String varType // variable type
if ( exists( "ABF_Read_Pointer" ) != 2 )
NM2Error( 13, "ABF_Read_Pointer", "" )
return NaN // this global variable is required
endif
NVAR ABF_Read_Pointer
ABF_Read_Pointer = ReadPclampFile( file, varType, ABF_Read_Pointer, 1 )
if ( numtype( ABF_Read_Pointer ) > 0 )
NM2Error( 10, "ABF_Read_Pointer", num2str( ABF_Read_Pointer ) )
return Nan
endif
if ( !WaveExists( $"NM_ReadPclampWave0" ) )
NM2Error( 1, "NM_ReadPclampWave0", "" )
return Nan
endif
Wave NM_ReadPclampWave0
if ( 0 < numpnts( NM_ReadPclampWave0 ) )
return NM_ReadPclampWave0[ 0 ]
else
return NaN
endif
End // ReadPclampVarPointer
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPclampVar( file, varType, pointer )
String file // external ABF data file
String varType // variable type
Variable pointer // read file pointer in bytes
if ( !FileExistsAndNonZero( file ) )
return NaN
endif
pointer = ReadPclampFile( file, varType, pointer, 1 )
if ( numtype( pointer ) > 0 )
NM2Error( 10, "pointer", num2str( pointer ) )
return Nan
endif
if ( !WaveExists( $"NM_ReadPclampWave0" ) )
NM2Error( 1, "NM_ReadPclampWave0", "" )
return Nan
endif
Wave NM_ReadPclampWave0
if ( 0 < numpnts( NM_ReadPclampWave0 ) )
return NM_ReadPclampWave0[ 0 ]
else
return NaN
endif
End // ReadPclampVar
//****************************************************************
//****************************************************************
//****************************************************************
Function /T ReadPclampString( file, pointer, numCharToRead )
String file // external ABF data file
Variable pointer // read file pointer in bytes
Variable numCharToRead // number of characters to read
Variable icnt
String str = ""
if ( !FileExistsAndNonZero( file ) )
return ""
endif
pointer = ReadPclampFile( file, "char", pointer, numCharToRead )
if ( numtype( pointer ) > 0 )
return NM2ErrorStr( 10, "pointer", num2str( pointer ) )
endif
if ( !WaveExists( $"NM_ReadPclampWave0" ) )
return NM2ErrorStr( 1, "NM_ReadPclampWave0", "" )
endif
Wave NM_ReadPclampWave0
for ( icnt = 0 ; icnt < numCharToRead ; icnt += 1 )
if ( icnt < numpnts( NM_ReadPclampWave0 ) )
str += num2char( NM_ReadPclampWave0[ icnt ] )
endif
endfor
return str
End // ReadPclampString
//****************************************************************
//****************************************************************
//****************************************************************
Function ReadPclampFile( file, varType, pointer, numVarToRead )
String file // external ABF data file
String varType // variable type
Variable pointer // read file pointer in bytes
Variable numVarToRead // number of variables to read starting from pointer
Variable bytes = 0
if ( !FileExistsAndNonZero( file ) )
return Nan
endif
if ( ( numtype( pointer ) > 0 ) || ( pointer < 0 ) )
NM2Error( 10, "pointer", num2str( pointer ) )
return Nan
endif
if ( ( numtype( numVarToRead ) > 0 ) || ( numVarToRead < 0 ) )
NM2Error( 10, "numVarToRead", num2str( numVarToRead ) )
return Nan
endif
strswitch( varType )
case "char":
bytes = 1
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={8,8+64}/U=(numVarToRead)/W=1/Q file
break
case "unicode":
case "short":
bytes = 2
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={16,2}/U=(numVarToRead)/W=1/Q file
break
case "uint": // unsigned integer
bytes = 4
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={32+64,32+64}/U=(numVarToRead)/W=1/Q file
break
case "long":
bytes = 4
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={32,2}/U=(numVarToRead)/W=1/Q file
break
case "float":
bytes = 4
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={2,2}/U=(numVarToRead)/W=1/Q file
break
case "double":
bytes = 8
GBLoadWave /B/N=NM_ReadPClampWave/O/S=(pointer)/T={4,4}/U=(numVarToRead)/W=1/Q file
break
default:
NM2Error( 20, "varType", varType )
return Nan
endswitch
return ( pointer + bytes * numVarToRead )
End // ReadPclampFile
//****************************************************************
//****************************************************************
//****************************************************************
Static Function /T RemoveEndSpaces( str )
String str
Variable icnt
for ( icnt = strlen( str ) - 1; icnt >= 0; icnt -= 1 )
if ( !stringmatch( str[ icnt, icnt ], " " ) )
return str[ 0, icnt ]
endif
endfor
return str
End // RemoveEndSpaces
//****************************************************************
//****************************************************************
//****************************************************************
//
// ReadPclampHeaderUpdateNM parameters
//
// VARIABLES
// nOperationMode
// nDataFormat
// lActualAcqLength // ReadPclampHeader1 or XOP
// SectionData_NumEntries1 // ReadPclampHeader2
// nADCNumChannels
// lNumSamplesPerEpisode
// lActualEpisodes // ReadPclampHeader1 or XOP
// uActualEpisodes // ReadPclampHeader2
// fADCSampleInterval
// fADCSequenceInterval
// fADCSecondSampleInterval
// fADCRange
// lADCResolution
//
// WAVES
// nADCSamplingSeq
// fInstrumentScaleFactor
// sADCChannelName
// sADCUnits
// fTelegraphAdditGain
//
//****************************************************************
//****************************************************************
//****************************************************************
Static Function ReadPclampHeaderUpdateNM( df, hdf )
String df // where to update NM variables and waves
String hdf // ABF header data folder
Variable ccnt, chanNum, tempvar
Variable amode, dataFormat, acqLength, numChannels, samplesPerWave, episodes
Variable sampleInterval, splitClock, ADCRange
String acqMode, yl, yu, wName
String thisfxn = GetRTStackInfo( 1 )
df = ParseFilePath( 2, df, ":", 0, 0 )
CheckNMwave( df+"FileScaleFactors", ABF_NUMADCS, 1 )
CheckNMtwave( df+"yLabel", ABF_NUMADCS, "" )
Wave scaleFactors = $df+"FileScaleFactors"
Wave /T yAxisLabels = $df+"yLabel"
scaleFactors = 1
yAxisLabels = ""
amode = NM_ABFHeaderVar( "*OperationMode", folder = df )
switch( amode )
case 1:
acqMode = "1 ( Event-Driven )"
break
case 2:
acqMode = "2 ( Oscilloscope, loss free )"
break
case 3:
acqMode = "3 ( Gap-Free )"
break
case 4:
acqMode = "4 ( Oscilloscope, high-speed )"
break
case 5:
acqMode = "5 ( Episodic )"
break
default:
Print thisfxn + " Error: unknown acquisition mode :", acqMode
return -1
endswitch
SetNMstr( df+"AcqMode", acqMode )
dataFormat = NM_ABFHeaderVar( "*DataFormat", folder = df, alert = 1 )
if ( numtype( dataFormat ) > 0 )
Print thisfxn + " Error: unknown data format"
return -1
endif
SetNMvar( df+"DataFormat", dataFormat )
acqLength = NM_ABFHeaderVar( "*ActualAcqLength", folder = df ) // ReadPclampHeader1 or XOP
if ( numtype( acqLength ) > 0 )
acqLength = NM_ABFHeaderVar( "*SectionData_NumEntries1", folder = df ) // ReadPclampHeader2
endif
if ( acqLength < 0 )
Print thisfxn + " Error: unknown acquisition length :", acqLength
return -1
endif
SetNMvar( df+"AcqLength", acqLength )
numChannels = NM_ABFHeaderVar( "*ADCNumChannels", folder = df )
if ( ( numtype( numChannels ) > 0 ) || ( numChannels <= 0 ) )
Print thisfxn + " Error: unknown number of channels :", numChannels
return -1
endif
SetNMvar( df+"NumChannels", numChannels )
samplesPerWave = NM_ABFHeaderVar( "*NumSamplesPerEpisode", folder = df )
if ( ( numtype( samplesPerWave ) > 0 ) || ( samplesPerWave < 0 ) )
Print thisfxn + " Error: unknown number of samples :", samplesPerWave
return -1
endif
if ( numChannels > 1 )
samplesPerWave /= numChannels
endif
SetNMvar( df+"SamplesPerWave", samplesPerWave )
episodes = NM_ABFHeaderVar( "*ActualEpisodes", folder = df )
if ( numtype( episodes ) > 0 )
Print thisfxn + " Error: unknown number of episodes"
return -1
endif
if ( ( amode == 3 ) || ( episodes == 0 ) ) // gap free
episodes = acqLength / ( SamplesPerWave * NumChannels )
endif
if ( episodes <= 0 )
Print thisfxn + " Error: unknown number of episodes :", episodes
return -1
endif
SetNMvar( df+"NumWaves", episodes )
SetNMvar( df+"TotalNumWaves", episodes * NumChannels )
sampleInterval = NM_ABFHeaderVar( "*ADCSampleInterval", folder = df )
if ( numtype( sampleInterval ) > 0 )
sampleInterval = NM_ABFHeaderVar( "*ADCSequenceInterval", folder = df )
sampleInterval = sampleInterval / 1000
elseif ( sampleInterval > 0 )
sampleInterval = ( sampleInterval * NumChannels ) / 1000
endif
if ( ( numtype( sampleInterval ) > 0 ) || ( sampleInterval <= 0 ) )
Print thisfxn + " Error: unknown sample interval :", sampleInterval
return -1
endif
SetNMvar( df+"SampleInterval", sampleInterval )
splitClock = NM_ABFHeaderVar( "*ADCSecondSampleInterval", folder = df )
SetNMvar( df+"SplitClock", splitClock )
if ( ( numtype( splitClock ) == 0 ) && ( splitClock > 0 ) )
NMDoAlert( "Warning: data contains split-clock recording, which is not supported by this version of NeuroMatic." )
endif
//
// Hardware Info
//
ADCRange = NM_ABFHeaderVar( "*ADCRange", folder = df ) // ADC positive full-scale input ( volts )
SetNMvar( df+"ADCRange", ADCRange )
Variable ADCResolution = NM_ABFHeaderVar( "*ADCResolution", folder = df ) // number of ADC counts in ADC range
SetNMvar( df+"ADCResolution", ADCResolution )
//
// Multi-channel Info
//
wName = NM_ABFHeaderWaveName( "*ADCSamplingSeq", folder = df )
if ( !WaveExists( $wName ) )
Print thisfxn + " Error: cannot locate ADCSamplingSeq wave"
return -1
endif
Wave nADCSamplingSeq = $wName
wName = NM_ABFHeaderWaveName( "*InstrumentScaleFactor", folder = df )
if ( !WaveExists( $wName ) )
Print thisfxn + " Error: cannot locate InstrumentScaleFactor wave"
return -1
endif
Wave fInstrumentScaleFactor = $wName
wName = NM_ABFHeaderWaveName( "*ADCChannelName", folder = df )
if ( !WaveExists( $wName ) )
Print thisfxn + " Error: cannot locate ADCChannelName wave"
return -1
endif
Wave /T sADCChannelName = $wName
wName = NM_ABFHeaderWaveName( "*ADCUnits", folder = df )
if ( !WaveExists( $wName ) )
Print thisfxn + " Error: cannot locate ADCUnits wave"
return -1
endif
Wave /T sADCUnits = $wName
for ( ccnt = 0; ccnt < NumChannels; ccnt += 1 )
if ( ( ccnt >= numpnts( nADCSamplingSeq ) ) || ( ccnt >= numpnts( yAxisLabels ) ) )
break
endif
chanNum = nADCSamplingSeq[ ccnt ]
if ( ( chanNum >= 0 ) && ( chanNum < numpnts( sADCChannelName ) ) )
yl = RemoveEndSpaces( sADCChannelName[ chanNum ] )
yu = RemoveEndSpaces( sADCUnits[ chanNum ] )
if ( ( strlen( yl ) > 0 ) || ( strlen( yu ) > 0 ) )
yAxisLabels[ ccnt ] = yl + " ( " + yu + " )"
endif
endif
endfor
for ( ccnt = 0; ccnt < NumChannels; ccnt += 1 )
if ( ( ccnt >= numpnts( nADCSamplingSeq ) ) || ( ccnt >= numpnts( scaleFactors ) ) )
break
endif
chanNum = nADCSamplingSeq[ ccnt ]
if ( ( chanNum >= 0 ) && ( chanNum < numpnts( fInstrumentScaleFactor ) ) )
tempvar = fInstrumentScaleFactor[ chanNum ]
else
tempvar = Nan
endif
if ( ( numtype( tempvar ) == 0 ) && ( tempvar > 0 ) )
scaleFactors[ ccnt ] = ADCRange / ( ADCResolution * tempvar )
else
scaleFactors[ ccnt ] = ADCRange / ADCResolution
endif
endfor
//
// Extended Environmental Info
//
wName = NM_ABFHeaderWaveName( "*TelegraphAdditGain", folder = df )
if ( WaveExists( $wName ) )
Wave fTelegraphAdditGain = $wName
for ( ccnt = 0; ccnt < NumChannels; ccnt += 1 )
if ( ( ccnt >= numpnts( nADCSamplingSeq ) ) || ( ccnt >= numpnts( scaleFactors ) ) )
break
endif
chanNum = nADCSamplingSeq[ ccnt ]
if ( ( chanNum >= 0 ) && ( chanNum < numpnts( fTelegraphAdditGain ) ) )
tempvar = fTelegraphAdditGain[ chanNum ]
else
tempvar = NAN
endif
if ( ( numtype( tempvar ) == 0 ) && ( tempvar > 0 ) )
scaleFactors[ ccnt ] /= tempvar
//print "chan" + num2istr( ccnt ) + " telegraph gain:", NM_ReadPclampWave0[ ccnt ]
endif
endfor
endif
CheckNMwave( df+"FileScaleFactors", numChannels, 1 )
CheckNMtwave( df+"yLabel", numChannels, "" )
return 0
End // ReadPclampHeaderUpdateNM
//****************************************************************
//****************************************************************
//****************************************************************
Static Function PclampTimeStamps( file, format, amode, df, wName, episodeNum ) // modified from code from Gerard Borst, Erasmus MC, Dept of Neuroscience
String file
Variable format // pclamp format
Variable amode // acquisition mode
String df // NM data folder where everything is imported
String wName // wave name
Variable episodeNum // corresponding episode number for this wave
Variable fileStartTime, fileStartMillisecs, stopwatchTime
Variable runsPerTrial, episodesPerRun, triggerSource, episodeStartToStart, recordStart
String tstr, wNote
String thisfxn = GetRTStackInfo( 1 )
df = ParseFilePath( 2, df, ":", 0, 0 )
String wavePrefix = StrVarOrDefault( df + "WavePrefix", NMStrGet( "WavePrefix" ) )
String wNameT1 = df + ABF_WAVENAMETIME1
String wNameT2 = df + ABF_WAVENAMETIME2
Variable sampleInterval = NumVarOrDefault( df + "SampleInterval", NaN )
Variable samplesPerWave = NumVarOrDefault( df + "SamplesPerWave", NaN )
Variable numChannels = NumVarOrDefault( df + "NumChannels", NaN )
if ( ( numtype( sampleInterval ) > 0 ) || ( numtype( samplesPerWave ) > 0 ) )
Print thisfxn + " Error: cannot locate SampleInterval or SamplesPerWave"
return -1
endif
if ( ( numtype( numChannels ) > 0 ) || ( numChannels <= 0 ) )
Print thisfxn + " Error: cannot locate NumChannels"
return -1
endif
fileStartTime = NM_ABFHeaderVar( "*FileStartTimeMS", folder = df )
if ( numtype( fileStartTime ) == 0 )
fileStartTime /= 1000 // convert to seconds
else
fileStartTime = NM_ABFHeaderVar( "*FileStartTime", folder = df )
// time of day in seconds past midnight when data portion of this file was first written to
endif
if ( numtype( fileStartTime ) > 0 )
Print thisfxn + " Error: cannot locate FileStartTime"
return -1
endif
fileStartMillisecs = NM_ABFHeaderVar( "*FileStartMillisecs", folder = df ) // msec portion of lFileStartTime
if ( numtype( fileStartMillisecs ) == 0 )
fileStartTime += fileStartMillisecs / 1000
endif
//Print "FileStartTime", NMSecondsToStopwatch( fileStartTime )
tstr = NMSecondsToStopwatch( fileStartTime )
tstr = ReplaceString( ":", tstr, "," )
NMNoteStrReplace( wName, "ABF_FileStartTime", tstr )
sprintf tstr, "%.3f", fileStartTime
NMNoteStrReplace( wName, "ABF_FileStartTimeSeconds", tstr )
stopwatchTime = NM_ABFHeaderVar( "*StopwatchTime", folder = df )
if ( numtype( stopwatchTime ) > 0 )
Print thisfxn + " Error: cannot locate StopwatchTime"
return -1
endif
//Print "StopwatchTime", NMSecondsToStopwatch( stopwatchTime )
tstr = NMSecondsToStopwatch( stopwatchTime )
tstr = ReplaceString( ":", tstr, "," )
NMNoteStrReplace( wName, "ABF_StopwatchTime", tstr )
sprintf tstr, "%.3f", stopwatchTime
NMNoteStrReplace( wName, "ABF_StopwatchTimeSeconds", tstr )
runsPerTrial = NM_ABFHeaderVar( "*RunsPerTrial", folder = df )
// requested number of runs/trial. 0=Run until terminated by user. Runs are averaged. If nOperationMode = 3 (gap free), the value of this parameter is 1. See lAverageCount.
if ( numtype( runsPerTrial ) > 0 )
Print thisfxn + " Error: cannot locate RunsPerTrial"
return -1
endif
if ( runsPerTrial > 1 )
return 0 // finished, the remaining code currently only works for files with one run per trial
endif
episodesPerRun = NM_ABFHeaderVar( "*EpisodesPerRun", folder = df )
// requested number of episodes/run. 0=Run until terminated by user. If nOperationMode = 3 (gap free), this parameter is 1 and the requested acquisition length is set in fSecondsPerRun.
if ( numtype( episodesPerRun ) > 0 )
Print thisfxn + " Error: cannot locate EpisodesPerRun"
return -1
endif
triggerSource = NM_ABFHeaderVar( "*TriggerSource", folder = df )
// trigger source: N (>=0) = Physical channel number selected for threshold detection; -1 = external trigger; -2 = keyboard; -3 = use start-to-start interval. If nOperationMode=3 (gap-free) 0 = start immediately.
if ( numtype( triggerSource ) > 0 )
Print thisfxn + " Error: cannot locate TriggerSource"
return -1
endif
episodeStartToStart = NM_ABFHeaderVar( "*EpisodeStartToStart", folder = df )
// time between start of sweeps (seconds). Use when nTriggerSource = "start-to-start".
if ( numtype( episodeStartToStart ) > 0 )
Print thisfxn + " Error: cannot locate EpisodeStartToStart"
return -1
endif
if ( ( episodesPerRun > 1 ) && ( triggerSource != -3 ) && ( episodeNum > 0 ) )
//Print "Start of episode cannot be reliably determined from ABF header"
return 0
endif
if ( ( episodesPerRun == 1 ) && ( episodeNum > 0 ) )
//Print thisfxn + " Error: wrong episode number : ", episodeNum
//return -1
// could be gap-free with XOP import
endif
recordStart = fileStartTime + episodeNum * episodeStartToStart // assumes no missing traces, ascending order, etc. !!!!!!!!!!!!!!!!!
tstr = NMSecondsToStopwatch( recordStart )
tstr = ReplaceString( ":", tstr, "," )
NMNoteStrReplace( wName, "ABF_EpisodeTime", tstr )
sprintf tstr, "%.3f", recordStart
NMNoteStrReplace( wName, "ABF_EpisodeTimeSeconds", tstr )
if ( ( amode == 3 ) || ( episodesPerRun <= 1 ) )
return 0
endif
if ( WaveExists( $wNameT1 ) == 0 )
Make /O/N=( episodesPerRun ) $wNameT1 = NaN
wNote = "Folder:" + GetDataFolder( 0 )
wNote += NMCR + "File:" + NMNoteCheck( file )
NMNoteType( wNameT1, "Pclamp " + num2str( format ), "episode #", "seconds past midnight", wNote )
endif
if ( WaveExists( $wNameT2 ) == 0 )
Make /O/N=( episodesPerRun ) $wNameT2 = NaN
wNote = "Folder:" + GetDataFolder( 0 )
wNote += NMCR + "File:" + NMNoteCheck( file )
NMNoteType( wNameT2, "Pclamp " + num2str( format ), "episode #", NMXunits, wNote )
endif
Wave wt1 = $wNameT1
if ( ( episodeNum >= 0 ) && ( episodeNum < numpnts( wt1 ) ) && ( numtype( wt1[ episodeNum ] ) > 0 ) )
wt1[ episodeNum ] = recordStart
endif
Wave wt2 = $wNameT2
if ( ( episodeNum >= 0 ) && ( episodeNum < numpnts( wt2 ) ) && ( numtype( wt2[ episodeNum ] ) > 0 ) )
wt2[ episodeNum ] = episodeNum * episodeStartToStart * 1000 // ms
endif
return 0
End // PclampTimeStamps
//****************************************************************
//****************************************************************
//****************************************************************
//
// ABF format 1
//
//****************************************************************
//****************************************************************
//****************************************************************
Static Function ReadPClampHeader1( file, df )
String file // external ABF data file
String df // NM data folder where everything is imported
Variable ccnt, icnt, chan
Variable numChannels, headerSize
String fileSignature
Variable readAll = NumVarOrDefault( NMDF+"ABF_HeaderReadAll", 0 )
if ( ReadPclampFormat( file ) != 1 )
return -1
endif
df = ParseFilePath( 2, df, ":", 0, 0 )
String hdf = df + ABF_SUBFOLDERNAME + ":"
if ( readAll )
NMProgressCall( -1, "Reading ABF Header ..." )
endif
NewDataFolder /O $RemoveEnding( hdf, ":" ) // create subfolder in current directory
// File ID and Size information