1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | |
---|
3 | // Functions and interfaces to manage datasets now that they are in data folders |
---|
4 | // Planned interface |
---|
5 | // - Panel to select/load data and then select operation |
---|
6 | // Planned functions: |
---|
7 | // - Rename a data set - AJJ Done Nov 2009 |
---|
8 | // - Duplicate a data set - AJJ Done Nov 2009 |
---|
9 | // - Subtract one data set from another |
---|
10 | // - Add one data set to another |
---|
11 | // - Divide data sets |
---|
12 | // - Multiply data sets |
---|
13 | // - Save a data folder to file |
---|
14 | |
---|
15 | Window DataManagementPanel() |
---|
16 | PauseUpdate; Silent 1 // building window... |
---|
17 | NewPanel /W=(459,44,959,364)/N=wrapperPanel/K=1 as "Data Set Management" |
---|
18 | ModifyPanel fixedSize=1 |
---|
19 | |
---|
20 | //Main bit of panel |
---|
21 | GroupBox grpBox_0,pos={20,10},size={460,75} |
---|
22 | |
---|
23 | Button DS1_button,pos={300,20},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 1" |
---|
24 | PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1",proc=DMDS_PopMenuProc |
---|
25 | PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
26 | |
---|
27 | Button DS2_button,pos={300,50},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 2" |
---|
28 | PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2",proc=DMDS_PopMenuProc |
---|
29 | PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
30 | |
---|
31 | //Default to disabled for second data set - only needed for arithmetic |
---|
32 | Button DS2_button,disable=2 |
---|
33 | PopupMenu DS2_popup,disable=2 |
---|
34 | |
---|
35 | //Tabs |
---|
36 | TabControl DSTabs,pos={20,90},size={460,200},tabLabel(0)="Management", proc=DSTabsProc |
---|
37 | TabControl DSTabs,tablabel(1)="Arithmetic" |
---|
38 | TabControl DSTabs,value=0 |
---|
39 | |
---|
40 | //Management Tab |
---|
41 | Button DSTabItem_0a,title="Rename",pos={75,200},size={150,20} |
---|
42 | Button DSTabItem_0b,title="Duplicate",pos={275,200},size={150,20} |
---|
43 | Button DSTabItem_0c,title="Save",pos={75,240},size={150,20} |
---|
44 | Button DSTabItem_0d,title="Unload",pos={275,240},size={150,20} |
---|
45 | SetVariable DSTabItem_0e,title="Old Name",pos={50,120},size={400,20} |
---|
46 | SetVariable DSTabItem_0e,fsize=12,value=_STR:"",noedit=2 |
---|
47 | SetVariable DSTabItem_0f,title="New Name (max 25 characters)",pos={50,150},size={400,20} |
---|
48 | SetVariable DSTabItem_0f,fsize=12,value=_STR:"" |
---|
49 | |
---|
50 | EndMacro |
---|
51 | |
---|
52 | //Must follow naming scheme to match buttons to popups |
---|
53 | //"Name_button" goes with "Name_popup" |
---|
54 | Function DM_LoadDataSetProc(ba) : ButtonControl |
---|
55 | STRUCT WMButtonAction &ba |
---|
56 | |
---|
57 | |
---|
58 | switch( ba.eventCode ) |
---|
59 | case 2: // mouse up |
---|
60 | // click code here |
---|
61 | String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" |
---|
62 | Execute cmd |
---|
63 | |
---|
64 | SVAR gLastFileName = root:packages:NIST:gLastFileName |
---|
65 | |
---|
66 | String windowName = ba.win |
---|
67 | String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" |
---|
68 | |
---|
69 | ControlUpdate/W=$(windowName) $(popupName) |
---|
70 | //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow |
---|
71 | // convoluted method to find the right item and pop the menu. |
---|
72 | |
---|
73 | String list,folderStr |
---|
74 | Variable num |
---|
75 | folderStr = CleanupName(gLastFileName,0) |
---|
76 | list = DM_DataSetPopupList() |
---|
77 | num=WhichListItem(folderStr,list,";",0,0) |
---|
78 | if(num != -1) |
---|
79 | PopupMenu $(popupName),mode=num+1,win=$(windowName) |
---|
80 | ControlUpdate/W=$(windowName) $(popupName) |
---|
81 | |
---|
82 | if (cmpstr(popupName,"DS1_popup") == 0) |
---|
83 | //send fake mouse action to popup to update old name if |
---|
84 | Struct WMPopupAction pa |
---|
85 | pa.eventCode = 2 //fake mouse up |
---|
86 | pa.win = windowName |
---|
87 | pa.ctrlName = "DS1_popup" |
---|
88 | DMDS_PopMenuProc(pa) |
---|
89 | endif |
---|
90 | endif |
---|
91 | break |
---|
92 | endswitch |
---|
93 | |
---|
94 | return 0 |
---|
95 | End |
---|
96 | |
---|
97 | Function DMDS_PopMenuProc(pa) : PopupMenuControl |
---|
98 | STRUCT WMPopupAction &pa |
---|
99 | |
---|
100 | switch( pa.eventCode ) |
---|
101 | case 2: // mouse up |
---|
102 | ControlInfo/W=$(pa.win) $(pa.ctrlName) |
---|
103 | SetVariable DSTabItem_0e,win=$(pa.win),value=_STR:S_Value |
---|
104 | |
---|
105 | SetDataFolder root: |
---|
106 | break |
---|
107 | endswitch |
---|
108 | |
---|
109 | return 0 |
---|
110 | End |
---|
111 | |
---|
112 | // is there a simpler way to do this? I don't think so. |
---|
113 | Function/S DM_DataSetPopupList() |
---|
114 | |
---|
115 | String str=GetAList(4) |
---|
116 | |
---|
117 | if(strlen(str)==0) |
---|
118 | str = "No data loaded" |
---|
119 | endif |
---|
120 | str = SortList(str) |
---|
121 | |
---|
122 | return(str) |
---|
123 | End |
---|
124 | |
---|
125 | Function/S DMGetDSName(dsNum) |
---|
126 | Variable dsNum |
---|
127 | |
---|
128 | String ctrlName |
---|
129 | if (dsNum == 1) |
---|
130 | ctrlName = "DS1_popup" |
---|
131 | elseif (dsNum == 2) |
---|
132 | ctrlName = "DS2_popup" |
---|
133 | endif |
---|
134 | |
---|
135 | ControlInfo/W=DataManagementPanel $(ctrlName) |
---|
136 | |
---|
137 | Return S_Value |
---|
138 | |
---|
139 | End |
---|
140 | |
---|
141 | // function to control the drawing of buttons in the TabControl on the main panel |
---|
142 | // Naming scheme for the buttons MUST be strictly adhered to... else buttons will |
---|
143 | // appear in odd places... |
---|
144 | // all buttons are named MainButton_NA where N is the tab number and A is the letter denoting |
---|
145 | // the button's position on that particular tab. |
---|
146 | // in this way, buttons will always be drawn correctly.. |
---|
147 | // |
---|
148 | Function DSTabsProc(name,tab) |
---|
149 | String name |
---|
150 | Variable tab |
---|
151 | |
---|
152 | // Print "name,number",name,tab |
---|
153 | String ctrlList = ControlNameList("",";"),item="",nameStr="" |
---|
154 | Variable num = ItemsinList(ctrlList,";"),ii,onTab |
---|
155 | for(ii=0;ii<num;ii+=1) |
---|
156 | //items all start w/"DSTabItem_" |
---|
157 | item=StringFromList(ii, ctrlList ,";") |
---|
158 | nameStr=item[0,9] |
---|
159 | if(cmpstr(nameStr,"DSTabItem_")==0) |
---|
160 | onTab = str2num(item[10]) |
---|
161 | ControlInfo $item |
---|
162 | switch (V_flag) |
---|
163 | case 1: |
---|
164 | Button $item,disable=(tab!=onTab) |
---|
165 | break |
---|
166 | case 2: |
---|
167 | CheckBox $item,disable=(tab!=onTab) |
---|
168 | break |
---|
169 | case 3: |
---|
170 | PopUpMenu $item,disable=(tab!=onTab) |
---|
171 | break |
---|
172 | case 5: |
---|
173 | SetVariable $item,disable=(tab!=onTab) |
---|
174 | break |
---|
175 | endswitch |
---|
176 | endif |
---|
177 | endfor |
---|
178 | |
---|
179 | //Deal with second data button |
---|
180 | //Make sure this gets changed if the number of the Arithmetic tab changes |
---|
181 | if (tab == 1) |
---|
182 | Button DS2_button,disable=0 |
---|
183 | PopupMenu DS2_popup,disable=0 |
---|
184 | else |
---|
185 | Button DS2_button,disable=2 |
---|
186 | PopupMenu DS2_popup,disable=2 |
---|
187 | endif |
---|
188 | End |
---|
189 | |
---|
190 | |
---|
191 | Function RenameDataSet(dataSetFolder, newName) |
---|
192 | String dataSetFolder |
---|
193 | String newName |
---|
194 | |
---|
195 | String dataSetFolderParent,basestr,objName |
---|
196 | Variable index = 0 |
---|
197 | |
---|
198 | //Abuse ParseFilePath to get path without folder name |
---|
199 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
200 | //Abuse ParseFilePath to get basestr |
---|
201 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
202 | |
---|
203 | try |
---|
204 | RenameDataFolder $(dataSetFolder) $(newName); AbortOnRTE |
---|
205 | |
---|
206 | |
---|
207 | SetDataFolder $(dataSetFolderParent+newName); AbortOnRTE |
---|
208 | do |
---|
209 | objName = GetIndexedObjName("",1,index) |
---|
210 | if (strlen(objName) == 0) |
---|
211 | break |
---|
212 | endif |
---|
213 | Rename $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
214 | index+=1 |
---|
215 | while(1) |
---|
216 | SetDataFolder root: |
---|
217 | catch |
---|
218 | Print "Aborted: " + num2str(V_AbortCode) |
---|
219 | SetDataFolder root: |
---|
220 | endtry |
---|
221 | End |
---|
222 | |
---|
223 | |
---|
224 | Function DuplicateDataSet(dataSetFolder, newName) |
---|
225 | String dataSetFolder |
---|
226 | String newName |
---|
227 | |
---|
228 | String dataSetFolderParent,basestr,objName |
---|
229 | Variable index = 0 |
---|
230 | |
---|
231 | //Abuse ParseFilePath to get path without folder name |
---|
232 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
233 | //Abuse ParseFilePath to get basestr |
---|
234 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
235 | |
---|
236 | try |
---|
237 | DuplicateDataFolder $(dataSetFolder) $(dataSetFolderParent+newName); AbortOnRTE |
---|
238 | |
---|
239 | SetDataFolder $(dataSetFolderParent+newName); AbortOnRTE |
---|
240 | do |
---|
241 | objName = GetIndexedObjName("",1,index) |
---|
242 | if (strlen(objName) == 0) |
---|
243 | break |
---|
244 | endif |
---|
245 | Rename $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
246 | index+=1 |
---|
247 | while(1) |
---|
248 | SetDataFolder root: |
---|
249 | catch |
---|
250 | Print "Aborted: " + num2str(V_AbortCode) |
---|
251 | SetDataFolder root: |
---|
252 | endtry |
---|
253 | End |
---|
254 | |
---|
255 | |
---|
256 | // Subtract Set2 From Set1 |
---|
257 | // Use Result_I = Set1_I - f*Set2_I |
---|
258 | Function SubtractDataSets(set1Folder,set2Folder,set2Scale,resultName) |
---|
259 | String set1Folder |
---|
260 | String set2Folder |
---|
261 | Variable set2Scale |
---|
262 | String resultName |
---|
263 | |
---|
264 | //Create folder for result |
---|
265 | |
---|
266 | //Create result waves |
---|
267 | |
---|
268 | //Do subtraction of I waves - including interpolation if necessary. |
---|
269 | //Can we flag when interpolation was necessary? |
---|
270 | |
---|
271 | //Generate correct result Q wave - including interpolation if necessary |
---|
272 | |
---|
273 | //Calculate result error wave - can we produce corrected Q error? |
---|
274 | |
---|
275 | //Generate history string to record what was done? |
---|
276 | |
---|
277 | End |
---|
278 | |
---|
279 | // Add Set2 to Set1 |
---|
280 | // Use Result_I = Set1_I + f*Set2_I |
---|
281 | Function AddDataSets(set1Folder,set2Folder,set2Scale,resultName) |
---|
282 | String set1Folder |
---|
283 | String set2Folder |
---|
284 | Variable set2Scale |
---|
285 | String resultName |
---|
286 | |
---|
287 | //Create folder for result |
---|
288 | |
---|
289 | //Create result waves |
---|
290 | |
---|
291 | //Do addition of I waves - including interpolation if necessary. |
---|
292 | //Can we flag when interpolation was necessary? |
---|
293 | |
---|
294 | //Generate correct result Q wave - including interpolation if necessary |
---|
295 | |
---|
296 | //Calculate result error wave - can we produce corrected Q error? |
---|
297 | |
---|
298 | //Generate history string to record what was done? |
---|
299 | |
---|
300 | End |
---|
301 | |
---|
302 | // Multiply Set1 by Set2 |
---|
303 | // Use Result_I = Set1_I * (f*Set2_I) |
---|
304 | Function MultiplyDataSets(set1Folder, set2Folder, set2Scale, resultName) |
---|
305 | String set1Folder |
---|
306 | String set2Folder |
---|
307 | Variable set2Scale |
---|
308 | String resultName |
---|
309 | |
---|
310 | //Create folder for result |
---|
311 | |
---|
312 | //Create result waves |
---|
313 | |
---|
314 | //Do multiplcation of I waves - including interpolation if necessary. |
---|
315 | //Can we flag when interpolation was necessary? |
---|
316 | |
---|
317 | //Generate correct result Q wave - including interpolation if necessary |
---|
318 | |
---|
319 | //Calculate result error wave - can we produce corrected Q error? |
---|
320 | |
---|
321 | //Generate history string to record what was done? |
---|
322 | |
---|
323 | End |
---|
324 | |
---|
325 | // Divide Set1 by Set2 |
---|
326 | // Use Result_I = Set1_I / (f*Set2_I) |
---|
327 | Function DivideDataSets(set1Folder, set2Folder, set2Scale, resultName) |
---|
328 | String set1Folder |
---|
329 | String set2Folder |
---|
330 | Variable set2Scale |
---|
331 | String resultName |
---|
332 | |
---|
333 | //Create folder for result |
---|
334 | |
---|
335 | //Create result waves |
---|
336 | |
---|
337 | //Do division of I waves - including interpolation if necessary. |
---|
338 | //Can we flag when interpolation was necessary? |
---|
339 | |
---|
340 | //Generate correct result Q wave - including interpolation if necessary |
---|
341 | |
---|
342 | //Calculate result error wave - can we produce corrected Q error? |
---|
343 | |
---|
344 | //Generate history string to record what was done? |
---|
345 | |
---|
346 | End |
---|
347 | |
---|
348 | Function SaveDataSetToFile(folderName) |
---|
349 | String folderName |
---|
350 | |
---|
351 | //Do saving of data file. |
---|
352 | |
---|
353 | //Include history string to record what was done? |
---|
354 | |
---|
355 | End |
---|