Repository navigation
Expand file tree
/
Copy pathMultiFileLoader.ipf
More file actions
402 lines (344 loc) · 19.1 KB
/
Copy pathMultiFileLoader.ipf
File metadata and controls
402 lines (344 loc) · 19.1 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
#pragma rtGlobals=1 // Use modern global access method.
#pragma version = 1.2
Menu "jtgSpectroscopy"
Submenu "Other Data Load Procs"
"File Load",MultiFileLoad()
End
End
//name of datafolder path used for file load functions
Static StrConstant ksDFPath = "root:Packages:JTG:MultiFileLoader:"
Static StrConstant ksDefaultDataPath = "C:My Stuff:pg:Fluorescence:Data:SPEX_Data:SPEX FL3-22 Data:Data Files:2007:"
//*************************************************************************************************************//
//***** Notes *****//
//*************************************************************************************************************//
// 4/21/2008 //
// User can change the string constants above as well as the menu entry above as needed. //
// The function bpMFLGetSelectedFileList will compile a string containing a semicolon //
// separated list of files selected from the listbox. The user could operated on each selected//
// item as it is found by adding code to bpMFLGetSelectedFileList or simply operate on //
// the string after bpMFLGetSelectedFileList completes . The selected list is saved in a //
// string named FileList in a folder that is in the in the path dictated by ksDFPath. //
// The folder is uniquely named using a base name of MultiFileLoadPanel. //
//*************************************************************************************************************//
//*************************************************************************************************************//
//***** MultiFileLoad *****//
//*************************************************************************************************************//
// Start Multiple file load routine. Display control panel; create waves used to handle waves //
// and wave selections. //
// 10/31/06 modified code so that data folders are used to hold waves (list of files) and string //
// unique to a MultiFileLoad panel. Now multiple panels can be open and each will retain //
// its own unique information set; each of which can open files from different directories. //
// A hook function is set for each open panel and when the panel is killed the associated //
// data folder and waves are also killed. //
// 4/21/08 Removed file loading specific code and generalized so that a string list of selected//
// files is compiled and stored in the panel specific data folder. //
//************************************************************************************************************//
Function MultiFileLoad()
String PanelName
String DFName
String DataLocation
String KnownFileTypes
PanelName = UniqueName("MultiFileLoadPanel", 9, 0 )
DataLocation = ksDFPath + PanelName
//Create data folders to hold panel info; ksDFPath is string constant
//see top of procedure file for its value. Folder has same name as panel name.
CreateDFPath(ksDFPath, PanelName)
String/G $(DataLocation + ":PathToFiles") = ksDefaultDataPath
make /O /T /N=10 $(DataLocation + ":w")
make /O /B /U /N=10 $(DataLocation + ":sw") = 0
Wave/T w = $(DataLocation + ":w")
Wave sw = $(DataLocation + ":sw")
String/G $(DataLocation + ":FileList") = ""
String/G $(DataLocation + ":FileNumberList") = ""
Variable/G $(DataLocation + ":NumberOfFiles") = 0
KnownFileTypes = "\"_Auto_;Spex (.SPT);PE L-9 (.SP);Foss (.TXT);HP UVVis (.WAV);HySPEC (.TIF); TIFF (.TIF);"
KnownFileTypes += "MM log (.LOG);GRAMS (.SPC);Text (.???);TextMatrix (.CSV)\""
PauseUpdate; Silent 1 // building window...
NewPanel /K=1 /W=(338.0,67.0,776,288)
DoWindow /C $PanelName //change graph window name
DoWindow /T $PanelName PanelName //change graph window title
SetVariable svPath,pos={66,24},size={284,16},proc=GetFileList,title="Path"
SetVariable svPath,value= $(DataLocation + ":PathToFiles") //PathToFiles
Button btnSetPath,pos={8,22},size={50,20},proc=bpMFLSetPath,title="Set Path"
Button btnUpdateList,pos={359,22},size={65,20},proc=bpMFLUpdateList,title="Update List"
Button btnUpdateList,help={"Update list of files from current path."}
GroupBox gbPath frame=1, title="Path", pos={2,5}, size={431, 43}
ListBox lbFiles disable=0, editStyle= 0, listWave= w, mode=10, pos={2,55}
ListBox lbFiles selWave=sw, size={200,150}, widths={200}
Button btnGetSelectedFileList,pos={262,55},size={50,20},proc=bpMFLGetSelectedFileList,title="Get Files"
PopupMenu popFileType,disable=1,pos={206,90},size={158,21},title="File Type",proc=poprocFileType
PopupMenu popFileType,mode=1,value= #KnownFileTypes //list of known file types for pop up menu
SetWindow kwTopWin, hook(MultiFileLoadCleanUp )=MultiFileLoadHook
End Function
//*************************************************************************************************************//
//***** End of MultiFileLoad *****//
//*************************************************************************************************************//
//************************************************************************************************************//
//***** MultiFileLoadHook *****//
//************************************************************************************************************//
// Added 10/31/06 //
// Event processing function for panel created by MultiFileLoad function. //
// First intended purpuose is to clean up when the MultiFileLoad panel is killed. It is used //
// to delete waves ("w" & "sw") and folder created by when the panel is opened. //
//************************************************************************************************************//
Function MultiFileLoadHook(s)
STRUCT WMWinHookStruct &s
Variable statusCode = 0
String PanelName
String DFName
PanelName = s.winName
DFName = ksDFPath + PanelName
if(s.eventCode == 2) //kill window: clean up
KillDataFolder $DFName
statusCode = 1
endif
return statusCode // 0 if nothing done, else 1
End
//************************************************************************************************************//
//***** End of MultiFileLoadHook *****//
//************************************************************************************************************//
//*************************************************************************************************************//
//***** bpMFLSetPath *****//
//*************************************************************************************************************//
// Called by Set Path button on panel. Opens dialog to select new symbolic path to //
// directory containing files to load. Then calls routine to get all files from that directory and //
// load into wave w for display in the list box. //
// 10/31/06 Modified for data folder use. //
//*************************************************************************************************************//
Function bpMFLSetPath(ctrlName)
String ctrlName
String Msg
String PanelName
String DataLocation
if(stringmatch(ctrlName, "btnSetPath") != 1)
return 0
endif
//string and waves associated with this panel instance are located in a data folder named
//after the panel name
PanelName = WinName(0, 64) //name of top panel
DataLocation = ksDFPath + PanelName
SVAR PathToFiles = $(DataLocation + ":PathToFiles")
Msg = "Browse To The File Location..."
NewPath /M=Msg /O jtgSpecFileLoader
if(V_flag != 0) //user hit cancel
return 0
endif
PathInfo jtgSpecFileLoader
if(V_flag == 0)//path doesn't exist
return 0
endif
//update path variable
PathToFiles = S_path
//fill listbox with files from new path
GetFileList("",0,"","")
End Function
//*************************************************************************************************************//
//***** End of bpMFLSetPath *****//
//*************************************************************************************************************//
//*************************************************************************************************************//
//***** poprocFileType *****//
//*************************************************************************************************************//
// Currently, this is not really used although it is called when the popup menu popFileType is //
// accessed. This could, perhaps be used to limit the items appearing in the list boxt. Or //
// maybe some other control could be used for this purpose. //
//*************************************************************************************************************//
Function poprocFileType(ctrlName,popNum,popStr) : PopupMenuControl
String ctrlName
Variable popNum
String popStr
if(stringmatch(ctrlName, "popFileType") != 1)
return 0
endif
// print popStr
End Function
//*************************************************************************************************************//
//***** End of poprocFileType *****//
//*************************************************************************************************************//
//*************************************************************************************************************//
//***** bpMFLGetSelectedFileList *****//
//*************************************************************************************************************//
// Called by Get Files buttons on controll panel. Check wave sw to determine which files //
// were selected and assign to output string. //
// Query popFileType control to determine which routine to call for loading the files. //
// 10/31/06 Modified for data folder use. //
// user specific code could be put in the if/endif segment in this procedure or user could act //
// on FileNameList stored in the package folder //
//*************************************************************************************************************//
Function bpMFLGetSelectedFileList(ctrlName)
String ctrlName
Variable index
Variable NumFiles
String FPath_Name
String FName
// String FType
String FBaseName
String FExtension
String PanelName
String DataLocation
if(stringmatch(ctrlName, "btnGetSelectedFileList") != 1)
return 0
endif
////string and waves associated with this panel instance are located in a data folder named
////after the panel name
PanelName = WinName(0, 64) //name of top panel
DataLocation = ksDFPath + PanelName
Wave/T w = $(DataLocation + ":w")
Wave sw = $(DataLocation + ":sw")
SVAR PathToFiles = $(DataLocation + ":PathToFiles")
SVAR FileNameList = $(DataLocation + ":FileList")
NVAR NumberOfFiles = $(DataLocation + ":NumberOfFiles")
SVAR FileNumberList = $(DataLocation + ":FileNumberList")
////Check popFileType control (labelled "File Type") to determine
////which file loading routine to call.
// ControlInfo popFileType
// if(abs(V_flag) == 3)
// FType = S_Value //type of file to open, Spex, Lambda9...
// else
// DoAlert 0, "Problem with file type."
// return 0
// endif
FileNameList = ""
FileNumberList = ""
NumFiles = numpnts(sw)
index = 0
Do
//bit one or bit 3 is set if listbox row(index) was selected (listbox mode 10)
if(((sw[index] & 0x01) || (sw[index] & 0x08)) == 1)
//user specific code could be put in this if/endif segment
//or user could act on FileNameList stored in the package folder
FName = w[index]
FileNameList += FName + ";"
FileNumberList += num2str(index) + ";"
FPath_Name = PathToFiles + FName
FBaseName = ParseFilePath(3, FName, ":", 0, 0)
FExtension = ParseFilePath(4, FName, ":", 0, 0)
endif
index += 1
While (index < NumFiles)
NumberOfFiles = ItemsInList(FileNameList, ";")
//For debugging print a list of files selected for loading and a list of their position in the
//wave of all files in directory.
// print FileNameList
// print FileNumberList
End Function
//*************************************************************************************************************//
//***** End of bpMFLGetSelectedFileList *****//
//*************************************************************************************************************//
//*************************************************************************************************************//
//***** GetFileList *****//
//*************************************************************************************************************//
// Get list of files from current path jtgSpecFileLoader, redimension waves used to hold //
// file names and list box attributes. //
// This will automatically put new list into listbox. //
// 10/31/06 Modified for data folder use. //
// 6/20/07:
// added line "sw = 0" to clear all selections when the listbox is updated //
//*************************************************************************************************************//
Function GetFileList(ctrlName,varNum,varStr,varName)
String ctrlName
Variable varNum // value of variable as number
String varStr // value of variable as string
String varName // name of variable
String PanelName
String DataLocation
//string and waves associated with this panel instance are located in a data folder named
//after the panel name
PanelName = WinName(0, 64) //name of top panel
DataLocation = ksDFPath + PanelName
Wave/T w = $(DataLocation + ":w")
Wave sw = $(DataLocation + ":sw")
Variable NumFiles
Variable i = 0
String FileList = IndexedFile(jtgSpecFileLoader, -1, "????")
FileList = SortList(FileList, ";", 16) //16: case-insensitive alphanumeric sort that sorts wave0 and wave9 before wave10.
NumFiles = itemsinlist(FileList, ";")
Redimension /N=(NumFiles) w
Redimension /N=(NumFiles) sw
sw = 0
w[] = StringFromList(p, FileList, ";")
End Function
//*************************************************************************************************************//
//***** End of GetFileList *****//
//*************************************************************************************************************//
//*************************************************************************************************************//
//***** bpMFLUpdateList *****//
//*************************************************************************************************************//
// Update list of files in displayed in list box lbFiles. //
// This button procedures just calls GetFileList procedure. //
// 01/17/07 Modified for data folder use. //
//*************************************************************************************************************//
Function bpMFLUpdateList(ctrlName)
String ctrlName
if(stringmatch(ctrlName, "btnUpdateList") != 1)
return 0
endif
GetFileList("",0,"","")
End Function
//*************************************************************************************************************//
//***** End of bpMFLUpdateList *****//
//*************************************************************************************************************//
//************************************************************************************************************//
//***** Static Function CreateDFPath *****//
//************************************************************************************************************//
// Standard function used to created a new data folder and the path to it if it does not exist. //
// Function is delared as static in case it exists in other open procedure files. //
//************************************************************************************************************//
Static Function CreateDFPath(sFullDFPath, sNewDF)
String sFullDFPath
String sNewDF
String sEntireDFPath //path plus new folder
Variable incr
String sPathElement = ""
String sPartialPath = ""
String sPathChar = ""
sEntireDFPath = sFullDFPath + sNewDF
//check that path and folder strings aren't empty
if((strlen(sFullDFPath) == 0) || (strlen(sNewDF) == 0 ) == 1)
DoAlert 0, "Missing Data Folder Path... check string constant at start of procedure."
return 0
endif
//Does path already exist?
//then check for its existence, if it alrealdy exists, alert user and return success
If(DataFolderExists(sEntireDFPath))
//print "Path already exists: ", sEntireDFPath
return 1
EndIf
//Are there any ":" at front?
Do
sPathChar = sEntireDFPath[0]
if(stringmatch(sPathChar, ":") == 0)
break
endif
sPartialPath += ":"
sEntireDFPath = sEntireDFPath[1, inf]
While(1)
incr = 0
//if the first part of the path is "root:", this is a special case. It always exists and we don't
//need to create it, so skip over it.
//break path at folders and work with each part of the path
sPathElement = StringFromList(incr, sEntireDFPath, ":")
If(stringmatch(sPathElement, "root"))
sPartialPath = "root:"
incr += 1
EndIf
Do
//break path at folders and work with each part of the path
sPathElement = StringFromList(incr, sEntireDFPath, ":")
//exit loop when we encounter a null string, this usually means that all elements of loop
//have been processed
If(!strlen(sPathElement))
break
EndIf
sPartialPath += sPathElement
// print "creating: ", sPartialPath
NewDataFolder/O $sPartialPath
//need ":" to separate path elements, but NewDataFolder doesn't like this on the end of a path
//string, so we append it here.
sPartialPath += ":"
incr += 1
While(1)
return 1
End
//************************************************************************************************************//
//***** End of CreateDFPath *****//
//************************************************************************************************************//