-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNM_Import.ipf
513 lines (350 loc) · 14.9 KB
/
NM_Import.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
#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
//
//****************************************************************
//****************************************************************
//
// Import file functions
//
//****************************************************************
//****************************************************************
StrConstant NMImportDF = "root:Packages:NeuroMatic:Import:"
//****************************************************************
//****************************************************************
//****************************************************************
Function /S ImportDF()
if ( NMVarGet( "ImportPrompt" ) == 0 )
return GetDataFolder( 1 )
endif
CheckImport()
return "root:Packages:NeuroMatic:Import:"
End // ImportDF
//****************************************************************
//****************************************************************
//****************************************************************
Function CheckImport()
CheckNMPackageDF( "Import" )
End // CheckImport
//****************************************************************
//****************************************************************
//****************************************************************
Function CallNMImportFileManager( file, df, fileType, option ) // call appropriate import data function
String file
String df
String fileType
String option // "header", "data" or "test"
Variable success = -1
if ( strlen( fileType ) > 0 )
success = NMImportFileManager( file, df, fileType, option )
else
if ( ReadPclampFormat( file ) > 0 )
fileType = "Pclamp"
success = NMImportFileManager( file, df, fileType, option )
elseif ( ReadAxographFormat( file ) > 0 )
fileType = "Axograph"
success = NMImportFileManager( file, df, fileType, option )
else
NMDoAlert( "Abort NMImportFileManager: file format not recognized for " + file )
fileType = ""
endif
endif
SetNMstr( df+"DataFileType", fileType )
return success
End // CallNMImportFileManager
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImportFileManager( file, df, filetype, option ) // call appropriate import data function
String file
String df // data folder to import to ( "" ) for current
String filetype // data file type ( ie. "axograph" or "Pclamp" )
String option // "header" to read data header
// "data" to read data
// "test" to test whether this file manager supports file type
Variable /G success // success flag ( 1 ) yes ( 0 ) no; or the number of data waves read
if ( strlen( df ) == 0 )
df = GetDataFolder( 1 )
endif
df = LastPathColon( df, 1 )
strswitch( filetype )
default:
return 0
case "Axograph": // ( see ReadAxograph.ipf )
strswitch( option )
case "header":
Execute "success = ReadAxograph( " + NMQuotes( file ) + "," + NMQuotes( df ) + ", 0 )"
break
case "data":
Execute "success = ReadAxograph( " + NMQuotes( file ) + "," + NMQuotes( df ) + ", 1 )"
break
case "test":
success = 1
break
endswitch
break
case "Pclamp": // ( see ReadPclamp.ipf )
strswitch( option )
case "header":
Execute "success = ReadPclampHeader( " + NMQuotes( file ) + "," + NMQuotes( df ) + " )"
break
case "data":
Execute "success = ReadPclampData( " + NMQuotes( file ) + "," + NMQuotes( df ) + " )"
break
case "test":
success = 1
break
endswitch
break
endswitch
Variable ss = success
KillVariables /Z success
return ss
End // NMImportFileManager
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMImportFile( folder, fileList [ nmPrefix, history ] ) // import a data file
String folder // folder name, or "new" for new folder, or "one" to import into a single folder
String fileList // list of external file names
Variable nmPrefix // ( 0 ) no ( 1 ) yes, force "nm" prefix when creating NM data folders
Variable history
Variable fcnt, newFolder, success, emptyfolder
String file, folder2, saveDF, vlist = "", df
String replaceStringList = NMStrGet( "FileNameReplaceStringList" )
vList = NMCmdStr( folder, vList )
vList = NMCmdStr( fileList, vList )
if ( ParamIsDefault( nmPrefix ) )
nmPrefix = 1
else
vlist = NMCmdNumOptional( "nmPrefix", nmPrefix, vlist )
endif
if ( history )
NMCommandHistory( vList )
endif
for ( fcnt = 0 ; fcnt < ItemsInList( fileList ) ; fcnt += 1 )
file = StringFromList( fcnt, fileList )
if ( ( strlen( file ) == 0 ) || ( FileExistsAndNonZero( file ) == 0 ) )
continue
endif
if ( StringMatch( folder, "one" ) == 1 )
if ( fcnt == 0 )
folder2 = NMFolderNameCreate( file, nmPrefix = nmPrefix, replaceStringList = replaceStringList )
endif
elseif ( ( strlen( folder ) == 0 ) || ( StringMatch( folder, "new" ) == 1 ) )
folder2 = NMFolderNameCreate( file, nmPrefix = nmPrefix, replaceStringList = replaceStringList )
else
folder2 = folder
endif
saveDF = GetDataFolder( 0 )
if ( DataFolderExists( folder2 ) == 1 )
NMFolderChange( folder2 )
//elseif ( ( NMNumChannels() == 0 ) && ( ItemsInList( WaveList( "*", ";", "" ) ) == 0 ) )
// NMFolderRename( "" , folder2 ) // removed this option due to conflict with NMImportWaves 13 July 2012
else
folder2 = NMFolderNew( folder2 )
newFolder = 1
if ( strlen( folder2 ) == 0 )
continue
endif
endif
df = GetDataFolder( 1 )
SetNMstr( df+"CurrentFile", file )
SetNMstr( df+"FileName", NMChild( file ) )
SetNMstr( ImportDF()+"CurrentFile", file )
SetNMstr( ImportDF()+"FileName", NMChild( file ) )
success = NMImport( file, newFolder )
if ( ( success < 0 ) && ( newfolder == 1 ) )
KillDataFolder /Z $folder2
NMFolderChange( saveDF )
folder2 = ""
endif
endfor
UpdateNM( 0 )
KillVariables /Z V_Flag, WaveBgn, WaveEnd
KillStrings /Z S_filename, S_wavenames
KillWaves /Z DumWave0, DumWave1
return folder
End // NMImportFile
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImport( file, xnewFolder ) // main import data function
String file
Variable xnewFolder // NOT USED ANYMORE
Variable success, amode, saveprompt, totalNumWaves, numChannels
String acqMode, wPrefix, wList, prefixFolder, folderName
String df = ImportDF()
String folder = CurrentNMFolder( 1 ) // import into current data folder
String folderShort = CurrentNMFolder( 0 )
if ( CheckCurrentFolder() == 0 )
return 0
endif
Variable importPrompt = NMVarGet( "ImportPrompt" )
String saveWavePrefix = StrVarOrDefault( "WavePrefix", NMStrGet( "WavePrefix" ) )
if ( FileExistsAndNonZero( file ) == 0 )
NMDoAlert( "Error: external data file has not been selected." )
return -1
endif
success = CallNMImportFileManager( file, df, "", "header" )
if ( success <= 0 )
return -1
endif
totalNumWaves = NumVarOrDefault( df+"TotalNumWaves", 0 )
numChannels = NumVarOrDefault( df+"NumChannels", 1 )
SetNMStr( df + "FolderName", GetDataFolder( 0 ) )
SetNMvar( df+"WaveBgn", 0 )
SetNMvar( df+"WaveEnd", ceil( totalNumWaves / numChannels ) - 1 )
CheckNMstr( df+"WavePrefix", NMStrGet( "WavePrefix" ) )
if ( importPrompt == 1 )
NMImportPanel() // open panel to display header info and request user input
endif
if ( NumVarOrDefault( df+"WaveBgn", -1 ) < 0 ) // user aborted
return -1
endif
folderName = StrVarOrDefault( df+"FolderName", folderShort )
if ( !StringMatch( folderName, folderShort ) )
NMFolderRename( folderShort, folderName )
folder = CurrentNMFolder( 1 )
endif
wPrefix = StrVarOrDefault( df+"WavePrefix", NMStrGet( "WavePrefix" ) )
SetNMvar( "WaveBgn", NumVarOrDefault( df+"WaveBgn", 0 ) )
SetNMvar( "WaveEnd", NumVarOrDefault( df+"WaveEnd", -1 ) )
SetNMstr( "WavePrefix", wPrefix )
SetNMstr( "CurrentFile", file )
success = CallNMImportFileManager( file, folder, StrVarOrDefault( df+"DataFileType", "" ), "Data" ) // now read the data
if ( success < 0 ) // user aborted
return -1
endif
PrintNMFolderDetails( GetDataFolder( 1 ) )
NMSet( wavePrefixNoPrompt = wPrefix )
prefixFolder = CurrentNMPrefixFolder()
acqMode = StrVarOrDefault( df+"AcqMode", "" )
amode = str2num( acqMode[0] )
if ( ( numtype( amode ) == 0 ) && ( amode == 3 ) ) // gap free
if ( NumVarOrDefault( df+"ConcatWaves", 0 ) == 1 )
NMChanSelect( "All" )
wList = NMMainConcatenate( newPrefix = "C_" )
if ( ItemsInList( wList ) == NMNumWaves() * NMNumChannels() )
NMKillWaves( wList, updateSets = 1, noAlert = 1 )
else
NMDoAlert( "Alert: waves may have not been properly concatenated." )
endif
NMSet( wavePrefixNoPrompt = "C_Record" )
else
NMMainXScaleMode( mode = "Continuous" )
endif
endif
return 1
End // NMImport
//****************************************************************
//****************************************************************
//****************************************************************
//
// Import File Panel
// panel called to request user input
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImportPanel()
if ( CheckCurrentFolder() == 0 )
return 0
endif
Variable x1, x2, y1, y2, yinc, height = 330, width = 280
String df = ImportDF()
Variable xpixels = NMScreenPixelsX()
Variable waveEnd = NumVarOrDefault( df+"WaveEnd", 0 )
Variable concat = NumVarOrDefault( df+"ConcatWaves", 0 )
String acqmode = StrVarOrDefault( df+"AcqMode", "" )
Variable amode = str2num( acqMode[0] )
String fileType = StrVarOrDefault( df+"DataFileType", "UNKNOWN" )
x1 = ( xpixels - width ) / 2
y1 = 200
x2 = x1 + width
y2 = y1 + height
DoWindow /K ImportPanel
NewPanel /N=ImportPanel/W=( x1,y1,x2,y2 ) as "Import " + fileType + " File"
x1 = 20
y1 = 45
yinc = 23
SetDrawEnv fsize= 11
DrawText x1, 30, "File: " + StrVarOrDefault( df+"FileName", "" )
SetVariable NM_NumChannelSet, title="channels: ", limits={1,10,0}, pos={x1,y1}, size={240,50}, frame=0, value=$( df+"NumChannels" ), win=ImportPanel, proc=NMImportSetVariable
SetVariable NM_SampIntSet, title="sample interval ( ms ): ", limits={0,10,0}, pos={x1,y1+1*yinc}, size={240,50}, frame=0, value=$( df+"SampleInterval" ), win=ImportPanel
SetVariable NM_SPSSet, title="samples: ", limits={0,inf,0}, pos={x1,y1+2*yinc}, size={240,50}, frame=0, value=$( df+"SamplesPerWave" ), win=ImportPanel
SetVariable NM_AcqModeSet, title="acquisition mode: ", pos={x1,y1+3*yinc}, size={240,50}, frame=0, value=$( df+"AcqMode" ), win=ImportPanel
if ( ( numtype( amode ) == 0 ) && ( amode == 3 ) ) // gap free
CheckBox NM_ConcatWaves, title="concatenate waves", pos={x1+50,y1+4*yinc}, size={16,18}, value=( concat ), proc=NMImportCheckBox, win=ImportPanel
y1 += 15
endif
yinc = 28
SetVariable NM_FolderNameSet, title="folder name ", pos={x1,y1+4*yinc}, size={240,60}, frame=1, value=$( df+"FolderName" ), win=ImportPanel
SetVariable NM_WavePrefixSet, title="wave prefix ", pos={x1,y1+5*yinc}, size={240,60}, frame=1, value=$( df+"WavePrefix" ), win=ImportPanel
SetVariable NM_WaveBgnSet, title="wave beg ", limits={0,waveEnd-1,0}, pos={x1,y1+6*yinc}, size={140,60}, frame=1, value=$( df+"WaveBgn" ), win=ImportPanel
SetVariable NM_WaveEndSet, title="wave end ", limits={0,waveEnd-1,0}, pos={x1,y1+7*yinc}, size={140,60}, frame=1, value=$( df+"WaveEnd" ), win=ImportPanel
Button NM_AbortButton, title="Abort", pos={55,y1+8.5*yinc}, size={50,20}, win=ImportPanel, proc=NMImportButton
Button NM_ContinueButton, title="Open File", pos={145,y1+8.5*yinc}, size={80,20}, win=ImportPanel, proc=NMImportButton
PauseForUser ImportPanel
End // NMImportPanel
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImportCheckBox( ctrlName, checked ) : CheckBoxControl
String ctrlName; Variable checked
String df = ImportDF()
strswitch( ctrlName )
case "NM_ConcatWaves":
SetNMvar( df+"ConcatWaves", checked )
break
endswitch
End // NMImportCheckBox
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImportButton( ctrlName ) : ButtonControl
String ctrlName
String df = ImportDF()
if ( StringMatch( ctrlName, "NM_AbortButton" ) == 1 )
SetNMvar( df+"WaveBgn", -1 )
endif
DoWindow /K ImportPanel
End // NMImportButton
//****************************************************************
//****************************************************************
//****************************************************************
Function NMImportSetVariable( ctrlName, varNum, varStr, varName ) : SetVariableControl
String ctrlName; Variable varNum; String varStr, varName
Variable chncnt, totalWaves, numChannels
String df = ImportDF()
strswitch( ctrlName )
case "NM_NumChannelSet":
totalWaves = NumVarOrDefault( df+"TotalNumWaves", 0 )
numChannels = NumVarOrDefault( df+"NumChannels", 1 )
SetNMvar( df+"WaveEnd", ceil( totalWaves / numChannels ) - 1 )
break
endswitch
End // NMImportSetVariable
//****************************************************************
//****************************************************************
//****************************************************************