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 | /////////////////// Data Management Panel /////////////////////////////////////////////////////// |
---|
16 | |
---|
17 | Function MakeDMPanel() |
---|
18 | PauseUpdate; Silent 1 // building window... |
---|
19 | NewPanel /W=(459,44,959,364)/N=DataManagementPanel/K=1 as "Data Set Management" |
---|
20 | ModifyPanel fixedSize=1 |
---|
21 | |
---|
22 | //Main bit of panel |
---|
23 | GroupBox grpBox_0,pos={20,10},size={460,50} |
---|
24 | GroupBox grpBox_1,pos={20,80},size={460,200} |
---|
25 | |
---|
26 | Button DS1_button,pos={300,20},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 1" |
---|
27 | PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1",proc=DMDS_PopMenuProc |
---|
28 | PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
29 | |
---|
30 | //Management Tab |
---|
31 | Button Rename_button,title="Rename",pos={75,200},size={150,20} |
---|
32 | Button Duplicate_button,title="Duplicate",pos={275,200},size={150,20} |
---|
33 | Button Save_button,title="Save",pos={75,240},size={150,20} |
---|
34 | Button Unload_button,title="Unload",pos={275,240},size={150,20} |
---|
35 | SetVariable OldName_setvar,title="Old Name",pos={50,100},size={400,20} |
---|
36 | SetVariable OldName_setvar,fsize=12,value=_STR:"",noedit=2 |
---|
37 | SetVariable NewName_setvar,title="New Name (max 25 characters)",pos={50,140},size={400,20} |
---|
38 | SetVariable NewName_setvar,fsize=12,value=_STR:"",proc=setvarproc,live=1 |
---|
39 | |
---|
40 | End |
---|
41 | |
---|
42 | //Must follow naming scheme to match buttons to popups |
---|
43 | //"Name_button" goes with "Name_popup" |
---|
44 | Function DM_LoadDataSetProc(ba) : ButtonControl |
---|
45 | STRUCT WMButtonAction &ba |
---|
46 | |
---|
47 | |
---|
48 | switch( ba.eventCode ) |
---|
49 | case 2: // mouse up |
---|
50 | // click code here |
---|
51 | String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" |
---|
52 | Execute cmd |
---|
53 | |
---|
54 | SVAR gLastFileName = root:packages:NIST:gLastFileName |
---|
55 | |
---|
56 | String windowName = ba.win |
---|
57 | String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" |
---|
58 | |
---|
59 | ControlUpdate/W=$(windowName) $(popupName) |
---|
60 | //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow |
---|
61 | // convoluted method to find the right item and pop the menu. |
---|
62 | |
---|
63 | String list,folderStr |
---|
64 | Variable num |
---|
65 | folderStr = CleanupName(gLastFileName,0) |
---|
66 | list = DM_DataSetPopupList() |
---|
67 | num=WhichListItem(folderStr,list,";",0,0) |
---|
68 | if(num != -1) |
---|
69 | PopupMenu $(popupName),mode=num+1,win=$(windowName) |
---|
70 | ControlUpdate/W=$(windowName) $(popupName) |
---|
71 | |
---|
72 | if (cmpstr(popupName,"DS1_popup") == 0) |
---|
73 | //send fake mouse action to popup to update old name if |
---|
74 | Struct WMPopupAction pa |
---|
75 | pa.eventCode = 2 //fake mouse up |
---|
76 | pa.win = windowName |
---|
77 | pa.ctrlName = "DS1_popup" |
---|
78 | DMDS_PopMenuProc(pa) |
---|
79 | endif |
---|
80 | endif |
---|
81 | break |
---|
82 | endswitch |
---|
83 | |
---|
84 | return 0 |
---|
85 | End |
---|
86 | |
---|
87 | |
---|
88 | Function DMDS_PopMenuProc(pa) : PopupMenuControl |
---|
89 | STRUCT WMPopupAction &pa |
---|
90 | |
---|
91 | switch( pa.eventCode ) |
---|
92 | case 2: // mouse up |
---|
93 | ControlInfo/W=$(pa.win) $(pa.ctrlName) |
---|
94 | SetVariable OldName_setvar,win=$(pa.win),value=_STR:S_Value |
---|
95 | // ControlInfo/W=$(pa.win) DSTabItem_0e |
---|
96 | // SVAR val = S_Value |
---|
97 | // |
---|
98 | // ControlInfo/W=$(pa.win) $(pa.ctrlName) |
---|
99 | // val = S_Value |
---|
100 | |
---|
101 | SetDataFolder root: |
---|
102 | break |
---|
103 | endswitch |
---|
104 | |
---|
105 | return 0 |
---|
106 | End |
---|
107 | |
---|
108 | |
---|
109 | Function/S DMGetDSName(dsNum) |
---|
110 | Variable dsNum |
---|
111 | |
---|
112 | String ctrlName |
---|
113 | if (dsNum == 1) |
---|
114 | ctrlName = "DS1_popup" |
---|
115 | elseif (dsNum == 2) |
---|
116 | ctrlName = "DS2_popup" |
---|
117 | endif |
---|
118 | |
---|
119 | ControlInfo/W=DataManagementPanel $(ctrlName) |
---|
120 | |
---|
121 | Return S_Value |
---|
122 | |
---|
123 | End |
---|
124 | |
---|
125 | |
---|
126 | /////////////////////// Data Arithmetic Panel ///////////////////////////////////////// |
---|
127 | |
---|
128 | Function MakeDAPanel() |
---|
129 | PauseUpdate; Silent 1 // building window... |
---|
130 | DoWindow/K DataArithmeticPanel |
---|
131 | NewPanel /W=(459,44,959,404)/N=DataArithmeticPanel/K=1 as "Data Set Arithmetic" |
---|
132 | ModifyPanel fixedSize=1 |
---|
133 | |
---|
134 | //Main bit of panel |
---|
135 | GroupBox grpBox_0,pos={20,10},size={460,105} |
---|
136 | |
---|
137 | Button DS1_button,pos={300,20},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 1" |
---|
138 | Button DS1_button,valueColor=(65535,0,0),userdata="DS1" |
---|
139 | PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1" |
---|
140 | PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
141 | PopupMenu DS1_popup,fsize=12,fcolor=(65535,0,0),valueColor=(65535,0,0) |
---|
142 | |
---|
143 | Button DS2_button,pos={300,50},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 2" |
---|
144 | Button DS2_button,valueColor=(0,0,65535),userdata="DS2" |
---|
145 | PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2" |
---|
146 | PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
147 | PopupMenu DS2_popup,fsize=12,fcolor=(0,0,65535),valueColor=(0,0,65535) |
---|
148 | |
---|
149 | Button DAPlot_button,title="Plot",pos={175,85},size={150,20} |
---|
150 | Button DAPlot_button,proc=DAPlotButtonProc |
---|
151 | |
---|
152 | |
---|
153 | //Tabs |
---|
154 | TabControl DATabs,pos={20,120},size={460,220},tabLabel(0)="Subtract", proc=DATabsProc |
---|
155 | TabControl DATabs,tablabel(1)="Add",tablabel(2)="Multiply",tablabel(3)="Divide" |
---|
156 | TabControl DATabs,value=0 |
---|
157 | |
---|
158 | Button DACalculate_button,title="Calculate",pos={50,310},size={150,20} |
---|
159 | Button DACalculate_button,proc=DACalculateProc |
---|
160 | Button DASave_button,title="Save Result",pos={300,310},size={150,20} |
---|
161 | Button DASave_button,proc=DASaveProc |
---|
162 | Button DACursors_button,title="Get Matching Range",pos={175,250},size={150,20} |
---|
163 | Button DACursors_button,proc=DACursorButtonProc |
---|
164 | SetVariable DAResultName_sv,title="Result Name (max 25 characters)",pos={50,280},size={400,20} |
---|
165 | SetVariable DAResultName_Sv,fsize=12,value=_STR:"SubtractionResult",proc=setvarproc,live=1 |
---|
166 | CheckBox DANoDS2_cb,title="Data Set 2 = 1?",pos={300,180} |
---|
167 | CheckBox DANoDS2_cb,proc=DANoDS2Proc |
---|
168 | |
---|
169 | ValDisplay DARangeStar_vd,title="Start",pos={40,220},size={100,20},fsize=12,value=_NUM:0 |
---|
170 | ValDisplay DARangeEnd_vd,title="End ",pos={160,220},size={100,20},fsize=12,value=_NUM:0 |
---|
171 | |
---|
172 | SetVariable DAScale_sv,title="Scale Factor (f)",pos={280,220},size={180,20},fsize=12,value=_NUM:1 |
---|
173 | |
---|
174 | GroupBox grpBox_1,pos={30,210},size={440,70} |
---|
175 | |
---|
176 | NewPanel/HOST=DataArithmeticPanel/N=arithDisplay/W=(50,150,170,190) |
---|
177 | arithDisplayProc(0) |
---|
178 | |
---|
179 | End |
---|
180 | |
---|
181 | |
---|
182 | Function MakeDAPlotPanel() |
---|
183 | PauseUpdate; Silent 1 // building window... |
---|
184 | DoWindow/K DAPlotPanel |
---|
185 | NewPanel /W=(14,44,454,484)/N=DAPlotPanel/K=1 as "Data Set Arithmetic" |
---|
186 | ModifyPanel fixedSize=1 |
---|
187 | |
---|
188 | Display/HOST=DAPlotPanel/N=DAPlot/W=(0,0,440,400) |
---|
189 | ShowInfo |
---|
190 | SetActiveSubWindow DAPlotPanel |
---|
191 | Checkbox DAPlot_log_cb, title="Log I(q)", pos={20,410},value=0 |
---|
192 | Checkbox DAPlot_log_cb, proc=DALogLinIProc |
---|
193 | |
---|
194 | |
---|
195 | End |
---|
196 | |
---|
197 | Function AddDAPlot(dataset) |
---|
198 | Variable dataset |
---|
199 | |
---|
200 | String win = "DataArithmeticPanel" |
---|
201 | String DS1name,DS2name,ResultName |
---|
202 | |
---|
203 | switch(dataset) |
---|
204 | case 1: |
---|
205 | ControlInfo/W=$(win) DS1_popup |
---|
206 | DS1name = S_Value |
---|
207 | Wave qWave = $("root:"+DS1name+":"+DS1name+"_q") |
---|
208 | Wave iWave = $("root:"+DS1name+":"+DS1name+"_i") |
---|
209 | Wave errWave = $("root:"+DS1name+":"+DS1name+"_s") |
---|
210 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
211 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS1name+"_i"), Y wave=(errWave,errWave) |
---|
212 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS1name+"_i"))=(65535,0,0) |
---|
213 | ControlInfo/W=$(win) DANoDS2_cb |
---|
214 | // if (V_Value == 1) |
---|
215 | // Cursor/W=DAPlotPanel#DAPlot A, $(DS1name+"_i"), leftx(iWave) |
---|
216 | // Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS1name+"_i"), rightx(iWave) |
---|
217 | // endif |
---|
218 | break |
---|
219 | case 2: |
---|
220 | ControlInfo/W=$(win) DANoDS2_cb |
---|
221 | if (V_Value == 0) |
---|
222 | ControlInfo/W=$(win) DS2_popup |
---|
223 | DS2name = S_Value |
---|
224 | Wave qWave = $("root:"+DS2name+":"+DS2name+"_q") |
---|
225 | Wave iWave = $("root:"+DS2name+":"+DS2name+"_i") |
---|
226 | Wave errWave = $("root:"+DS2name+":"+DS2name+"_s") |
---|
227 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
228 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS2name+"_i"), Y wave=(errWave,errWave) |
---|
229 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS2name+"_i"))=(0,0,65535) |
---|
230 | Cursor/W=DAPlotPanel#DAPlot A, $(DS2name+"_i"), leftx(iWave) |
---|
231 | Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS2name+"_i"), rightx(iWave) |
---|
232 | else |
---|
233 | ControlInfo/W=$(win) DS1_popup |
---|
234 | DS1name = S_Value |
---|
235 | if (!DataFolderExists("root:NullSolvent")) |
---|
236 | DuplicateDataSet("root:"+DS1name,"NullSolvent") |
---|
237 | endif |
---|
238 | Wave qWave =root:NullSolvent:NullSolvent_q |
---|
239 | Wave iWave = root:NullSolvent:NullSolvent_i |
---|
240 | Wave errWave = root:NullSolvent:NullSolvent_s |
---|
241 | iWave = 1 |
---|
242 | errWave = 0.1 |
---|
243 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
244 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 NullSolvent_i, Y wave=(errWave,errWave) |
---|
245 | ModifyGraph/W=DAPlotPanel#DAPlot rgb(NullSolvent_i)=(0,0,65535) |
---|
246 | Cursor/W=DAPlotPanel#DAPlot A, NullSolvent_i, leftx(iWave) |
---|
247 | Cursor/W=DAPlotPanel#DAPlot/A=0 B, NullSolvent_i, rightx(iWave) |
---|
248 | endif |
---|
249 | break |
---|
250 | case 3: |
---|
251 | ControlInfo/W=$(win) DAResultName_sv |
---|
252 | ResultName = S_Value |
---|
253 | Wave qWave = $("root:"+ResultName+":"+ResultName+"_q") |
---|
254 | Wave iWave = $("root:"+ResultName+":"+ResultName+"_i") |
---|
255 | Wave errWave = $("root:"+ResultName+":"+ResultName+"_s") |
---|
256 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
257 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(ResultName+"_i"), Y wave=(errWave,errWave) |
---|
258 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(ResultName+"_i"))=(0,65535,0) |
---|
259 | break |
---|
260 | endswitch |
---|
261 | |
---|
262 | ControlInfo/W=DAPlotPanel DAPlot_log_cb |
---|
263 | ModifyGraph/W=DAPlotPanel#DAPlot mode=3, msize=2, marker=19, mirror=1, tick=2, log(bottom)=1,log(left)=V_Value |
---|
264 | |
---|
265 | End |
---|
266 | |
---|
267 | Function arithDisplayProc(s) |
---|
268 | Variable s |
---|
269 | |
---|
270 | SetActiveSubWindow DataArithmeticPanel#arithDisplay |
---|
271 | |
---|
272 | switch (s) |
---|
273 | case 0: |
---|
274 | //Subtract |
---|
275 | DrawAction/L=progFront delete |
---|
276 | DrawRect 0,0,120,40 |
---|
277 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
278 | DrawText 10,32,"I" |
---|
279 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
280 | DrawText 20,30,"=" |
---|
281 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
282 | DrawText 35,32,"I" |
---|
283 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
284 | DrawText 95,32,"I" |
---|
285 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
286 | DrawText 52,32,"-" |
---|
287 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
288 | DrawText 75,30,"f" |
---|
289 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
290 | DrawText 85,32,"*" |
---|
291 | break |
---|
292 | case 1: |
---|
293 | //Add |
---|
294 | DrawAction/L=progFront delete |
---|
295 | DrawRect 0,0,120,40 |
---|
296 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
297 | DrawText 10,32,"I" |
---|
298 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
299 | DrawText 20,30,"=" |
---|
300 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
301 | DrawText 35,32,"I" |
---|
302 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
303 | DrawText 95,32,"I" |
---|
304 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
305 | DrawText 52,32,"+" |
---|
306 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
307 | DrawText 75,30,"f" |
---|
308 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
309 | DrawText 85,32,"*" |
---|
310 | break |
---|
311 | case 2: |
---|
312 | //Multiply |
---|
313 | DrawAction/L=progFront delete |
---|
314 | DrawRect 0,0,120,40 |
---|
315 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
316 | DrawText 10,32,"I" |
---|
317 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
318 | DrawText 20,30,"=" |
---|
319 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
320 | DrawText 35,32,"I" |
---|
321 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
322 | DrawText 95,32,"I" |
---|
323 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
324 | DrawText 52,32,"*" |
---|
325 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
326 | DrawText 66,30,"(" |
---|
327 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
328 | DrawText 75,30,"f" |
---|
329 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
330 | DrawText 85,32,"*" |
---|
331 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
332 | DrawText 105,30,")" |
---|
333 | break |
---|
334 | case 3: |
---|
335 | //Divide |
---|
336 | DrawAction/L=progFront delete |
---|
337 | DrawRect 0,0,120,40 |
---|
338 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
339 | DrawText 10,32,"I" |
---|
340 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
341 | DrawText 20,30,"=" |
---|
342 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
343 | DrawText 35,32,"I" |
---|
344 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
345 | DrawText 95,32,"I" |
---|
346 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
347 | DrawText 52,32,"/" |
---|
348 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
349 | DrawText 66,30,"(" |
---|
350 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
351 | DrawText 75,30,"f" |
---|
352 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
353 | DrawText 85,32,"*" |
---|
354 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
355 | DrawText 105,30,")" |
---|
356 | break |
---|
357 | endswitch |
---|
358 | |
---|
359 | SetActiveSubWindow DataArithmeticPanel |
---|
360 | |
---|
361 | return 0 |
---|
362 | End |
---|
363 | |
---|
364 | //Must follow naming scheme to match buttons to popups |
---|
365 | //"Name_button" goes with "Name_popup" |
---|
366 | Function DA_LoadDataSetProc(ba) : ButtonControl |
---|
367 | STRUCT WMButtonAction &ba |
---|
368 | |
---|
369 | switch( ba.eventCode ) |
---|
370 | case 2: // mouse up |
---|
371 | // click code here |
---|
372 | String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" |
---|
373 | Execute cmd |
---|
374 | |
---|
375 | SVAR gLastFileName = root:packages:NIST:gLastFileName |
---|
376 | |
---|
377 | String windowName = ba.win |
---|
378 | String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" |
---|
379 | |
---|
380 | ControlUpdate/W=$(windowName) $(popupName) |
---|
381 | //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow |
---|
382 | // convoluted method to find the right item and pop the menu. |
---|
383 | |
---|
384 | String list,folderStr |
---|
385 | Variable num |
---|
386 | folderStr = CleanupName(gLastFileName,0) |
---|
387 | list = DM_DataSetPopupList() |
---|
388 | num=WhichListItem(folderStr,list,";",0,0) |
---|
389 | if(num != -1) |
---|
390 | PopupMenu $(popupName),mode=num+1,win=$(windowName) |
---|
391 | ControlUpdate/W=$(windowName) $(popupName) |
---|
392 | |
---|
393 | endif |
---|
394 | break |
---|
395 | endswitch |
---|
396 | |
---|
397 | return 0 |
---|
398 | End |
---|
399 | |
---|
400 | // function to control the drawing of buttons in the TabControl on the main panel |
---|
401 | // Naming scheme for the buttons MUST be strictly adhered to... else buttons will |
---|
402 | // appear in odd places... |
---|
403 | // all buttons are named MainButton_NA where N is the tab number and A is the letter denoting |
---|
404 | // the button's position on that particular tab. |
---|
405 | // in this way, buttons will always be drawn correctly.. |
---|
406 | // |
---|
407 | Function DATabsProc(name,tab) |
---|
408 | String name |
---|
409 | Variable tab |
---|
410 | |
---|
411 | // Print "name,number",name,tab |
---|
412 | String ctrlList = ControlNameList("",";"),item="",nameStr="" |
---|
413 | Variable num = ItemsinList(ctrlList,";"),ii,onTab |
---|
414 | for(ii=0;ii<num;ii+=1) |
---|
415 | //items all start w/"DSTabItem_" |
---|
416 | item=StringFromList(ii, ctrlList ,";") |
---|
417 | nameStr=item[0,9] |
---|
418 | if(cmpstr(nameStr,"DATabItem_")==0) |
---|
419 | onTab = str2num(item[10]) |
---|
420 | ControlInfo $item |
---|
421 | switch (V_flag) |
---|
422 | case 1: |
---|
423 | Button $item,disable=(tab!=onTab) |
---|
424 | break |
---|
425 | case 2: |
---|
426 | CheckBox $item,disable=(tab!=onTab) |
---|
427 | break |
---|
428 | case 3: |
---|
429 | PopUpMenu $item,disable=(tab!=onTab) |
---|
430 | break |
---|
431 | case 5: |
---|
432 | SetVariable $item,disable=(tab!=onTab) |
---|
433 | break |
---|
434 | endswitch |
---|
435 | endif |
---|
436 | endfor |
---|
437 | |
---|
438 | arithDisplayProc(tab) |
---|
439 | End |
---|
440 | |
---|
441 | |
---|
442 | Function DACalculateProc(ba) : ButtonControl |
---|
443 | STRUCT WMButtonAction &ba |
---|
444 | |
---|
445 | String DS1,DS2,Resultname |
---|
446 | |
---|
447 | switch(ba.eventCode) |
---|
448 | case 2: |
---|
449 | //Which tab? |
---|
450 | ControlInfo/W=$(ba.win) DATabs |
---|
451 | Variable tabNum = V_value |
---|
452 | Print "Tab number "+num2str(tabNum) |
---|
453 | |
---|
454 | ControlInfo/W=$(ba.win) DS1_popup |
---|
455 | DS1 = S_Value |
---|
456 | ControlInfo/W=$(ba.win) DANoDS2_cb |
---|
457 | if (V_Value == 0) |
---|
458 | ControlInfo/W=$(ba.win) DS2_popup |
---|
459 | DS2 = S_Value |
---|
460 | else |
---|
461 | DS2 = "NullSolvent" |
---|
462 | endif |
---|
463 | ControlInfo/W=$(ba.win) DAResultName_sv |
---|
464 | Resultname = S_Value |
---|
465 | ControlInfo/W=$(ba.win) DAScale_sv |
---|
466 | Variable Scalefactor = V_Value |
---|
467 | |
---|
468 | switch(tabNum) |
---|
469 | case 0: |
---|
470 | //do subtraction |
---|
471 | //print "Subtraction of "+DS2+" from "+DS1+" with sf "+num2str(scalefactor)+ " into "+Resultname |
---|
472 | SubtractDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
473 | break |
---|
474 | case 1: |
---|
475 | //do addition |
---|
476 | AddDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
477 | break |
---|
478 | case 2: |
---|
479 | //do multiplication |
---|
480 | MultiplyDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
481 | break |
---|
482 | case 3: |
---|
483 | //do division |
---|
484 | DivideDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
485 | break |
---|
486 | endswitch |
---|
487 | |
---|
488 | //Sort out plot |
---|
489 | //Fake button press to DAPlotButtonProc |
---|
490 | STRUCT WMButtonAction ba2 |
---|
491 | ba2.win = ba.win |
---|
492 | ba2.ctrlName = "DAPlot_button" |
---|
493 | ba2.eventCode = 2 |
---|
494 | DAPlotButtonProc(ba2) |
---|
495 | AddDAPlot(3) |
---|
496 | SetActiveSubWindow DAPlotPanel |
---|
497 | DoWindow/F DataArithmeticPanel |
---|
498 | endswitch |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | End |
---|
503 | |
---|
504 | Function DAPlotButtonProc(ba) : ButtonControl |
---|
505 | STRUCT WMButtonAction &ba |
---|
506 | |
---|
507 | String win = ba.win |
---|
508 | |
---|
509 | switch (ba.eventCode) |
---|
510 | case 2: |
---|
511 | //mouse up |
---|
512 | //Get folder for DS1 |
---|
513 | DoWindow DAPlotPanel |
---|
514 | if (V_Flag == 0) |
---|
515 | MakeDAPlotPanel() |
---|
516 | else |
---|
517 | DoWindow/HIDE=0/F DAPlotPanel |
---|
518 | do |
---|
519 | String tracename = StringFromList(0,TraceNameList("DAPlotPanel#DAPlot",";",1),";") |
---|
520 | if (cmpstr(tracename,"")==0) |
---|
521 | break |
---|
522 | else |
---|
523 | RemoveFromGraph/W=DAPlotPanel#DAPlot $tracename |
---|
524 | endif |
---|
525 | while(1) |
---|
526 | endif |
---|
527 | |
---|
528 | ControlInfo/W=$(win) DS1_popup |
---|
529 | String DS1 = S_Value |
---|
530 | if (cmpstr(DS1,"") != 0 ) |
---|
531 | AddDAPlot(1) |
---|
532 | endif |
---|
533 | //Get folder for DS2 |
---|
534 | ControlInfo/W=$(win) DS2_popup |
---|
535 | String DS2 = S_Value |
---|
536 | if (cmpstr(DS2,"") != 0) |
---|
537 | AddDAPlot(2) |
---|
538 | endif |
---|
539 | break |
---|
540 | endswitch |
---|
541 | |
---|
542 | return 0 |
---|
543 | End |
---|
544 | |
---|
545 | Function DALogLinIProc(cba) : CheckBoxControl |
---|
546 | STRUCT WMCheckBoxAction &cba |
---|
547 | |
---|
548 | switch(cba.eventcode) |
---|
549 | case 2: |
---|
550 | |
---|
551 | ModifyGraph/W=DAPlotPanel#DAPlot log(left)=cba.checked |
---|
552 | |
---|
553 | endswitch |
---|
554 | |
---|
555 | |
---|
556 | End |
---|
557 | |
---|
558 | Function DACursorButtonProc(ba) : ButtonControl |
---|
559 | STRUCT WMButtonAction &ba |
---|
560 | |
---|
561 | String DS1,DS2 |
---|
562 | |
---|
563 | switch(ba.eventCode) |
---|
564 | case 2: |
---|
565 | |
---|
566 | ControlInfo/W=$(ba.win) DS1_popup |
---|
567 | DS1 = S_Value |
---|
568 | ControlInfo/W=$(ba.win) DANoDS2_cb |
---|
569 | Variable NoDS2 = V_Value |
---|
570 | if (NoDS2 == 0) |
---|
571 | ControlInfo/W=$(ba.win) DS2_popup |
---|
572 | DS2 = S_Value |
---|
573 | else |
---|
574 | DS2 = "NullSolvent" |
---|
575 | endif |
---|
576 | |
---|
577 | //AJJ Nov 2009 - UGLY - Will have to revisit this when we deal with hierarchical folders |
---|
578 | Wave set1_i = $("root:"+DS1+":"+DS1+"_i") |
---|
579 | Wave set1_q = $("root:"+DS1+":"+DS1+"_q") |
---|
580 | Wave set2_i = $("root:"+DS2+":"+DS2+"_i") |
---|
581 | Wave set2_q = $("root:"+DS2+":"+DS2+"_q") |
---|
582 | Duplicate/O set1_i tmp_i |
---|
583 | Duplicate/O set1_q tmp_q |
---|
584 | tmp_i = set1_i / interp(set1_q[p],set2_q,set2_i) |
---|
585 | |
---|
586 | //Get cursors |
---|
587 | Variable q1,q2 |
---|
588 | |
---|
589 | DoWindow/F DAPlotPanel |
---|
590 | SetActiveSubWindow DAPlotPanel#DAPlot |
---|
591 | |
---|
592 | q1 = CsrXWaveRef(A)[pcsr(A)] |
---|
593 | q2 = CsrXWaveRef(B)[pcsr(B)] |
---|
594 | |
---|
595 | //Update value display |
---|
596 | ValDisplay DARangeStar_vd,value=_NUM:q1, win=$(ba.win) |
---|
597 | ValDisplay DARangeEnd_vd,value=_NUM:q2, win=$(ba.win) |
---|
598 | |
---|
599 | //Calculate scalefactor |
---|
600 | |
---|
601 | if (NoDS2 == 1) |
---|
602 | Wave avgWave = set1_i |
---|
603 | else |
---|
604 | Wave avgWave = tmp_i |
---|
605 | endif |
---|
606 | |
---|
607 | Variable p1 = BinarySearch(tmp_q,q1) |
---|
608 | Variable p2 = BinarySearch(tmp_q,q2) |
---|
609 | |
---|
610 | //print avgWave |
---|
611 | |
---|
612 | WaveStats/Q/R=[p1,p2] avgWave |
---|
613 | //print V_avg |
---|
614 | //Update sv control |
---|
615 | SetVariable DAScale_sv, value=_NUM:V_avg, win=$(ba.win) |
---|
616 | |
---|
617 | KillWaves/Z tmp_i,tmp_q |
---|
618 | DoWindow/F DataArithmeticPanel |
---|
619 | endswitch |
---|
620 | |
---|
621 | End |
---|
622 | |
---|
623 | |
---|
624 | Function DANoDS2Proc(cba) : CheckBoxControl |
---|
625 | STRUCT WMCheckBoxAction &cba |
---|
626 | |
---|
627 | |
---|
628 | switch(cba.eventCode) |
---|
629 | case 2: |
---|
630 | if (cba.checked == 1) |
---|
631 | //Disable DS2 popup etc |
---|
632 | PopupMenu DS2_popup win=$(cba.win), disable=2 |
---|
633 | Button DS2_button win=$(cba.win), disable=2 |
---|
634 | else |
---|
635 | //Enable DS2 popup etc |
---|
636 | PopupMenu DS2_popup win=$(cba.win), disable=0 |
---|
637 | Button DS2_button win=$(cba.win), disable=0 |
---|
638 | endif |
---|
639 | //Sort out plot |
---|
640 | //Fake button press to DAPlotButtonProc |
---|
641 | STRUCT WMButtonAction ba2 |
---|
642 | ba2.win = cba.win |
---|
643 | ba2.ctrlName = "DAPlot_button" |
---|
644 | ba2.eventCode = 2 |
---|
645 | DAPlotButtonProc(ba2) |
---|
646 | SetActiveSubWindow DAPlotPanel |
---|
647 | DoWindow/F DataArithmeticPanel |
---|
648 | endswitch |
---|
649 | |
---|
650 | End |
---|
651 | |
---|
652 | Function DASaveProc(ba) : ButtonControl |
---|
653 | STRUCT WMButtonAction &ba |
---|
654 | |
---|
655 | switch(ba.eventCode) |
---|
656 | case 2: |
---|
657 | ControlInfo/W=$(ba.win) DAResultName_sv |
---|
658 | SaveDataSetToFile(S_Value) |
---|
659 | break |
---|
660 | endswitch |
---|
661 | |
---|
662 | |
---|
663 | End |
---|
664 | |
---|
665 | /////////////////////// Common Panel Functions /////////////////////////////////////// |
---|
666 | |
---|
667 | |
---|
668 | // is there a simpler way to do this? I don't think so. |
---|
669 | Function/S DM_DataSetPopupList() |
---|
670 | |
---|
671 | String str=GetAList(4) |
---|
672 | |
---|
673 | if(strlen(str)==0) |
---|
674 | str = "No data loaded" |
---|
675 | endif |
---|
676 | str = SortList(str) |
---|
677 | |
---|
678 | return(str) |
---|
679 | End |
---|
680 | |
---|
681 | |
---|
682 | Function SetVarProc(sva) : SetVariableControl |
---|
683 | STRUCT WMSetVariableAction &sva |
---|
684 | |
---|
685 | switch( sva.eventCode ) |
---|
686 | case 1: // mouse up |
---|
687 | case 2: // Enter key |
---|
688 | case 3: // Live update |
---|
689 | String sv = sva.sval |
---|
690 | if( strlen(sv) > 25 ) |
---|
691 | sv= sv[0,24] |
---|
692 | SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv |
---|
693 | Beep |
---|
694 | endif |
---|
695 | break |
---|
696 | endswitch |
---|
697 | return 0 |
---|
698 | End |
---|
699 | |
---|
700 | |
---|
701 | ////////////////////// Functions to do manipulations /////////////////////////////////// |
---|
702 | |
---|
703 | Function RenameDataSet(dataSetFolder, newName) |
---|
704 | String dataSetFolder |
---|
705 | String newName |
---|
706 | |
---|
707 | String dataSetFolderParent,basestr,objName |
---|
708 | Variable index = 0 |
---|
709 | |
---|
710 | //Abuse ParseFilePath to get path without folder name |
---|
711 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
712 | //Abuse ParseFilePath to get basestr |
---|
713 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
714 | |
---|
715 | // try |
---|
716 | RenameDataFolder $(dataSetFolder) $(newName)//; AbortOnRTE |
---|
717 | |
---|
718 | |
---|
719 | SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE |
---|
720 | do |
---|
721 | objName = GetIndexedObjName("",1,index) |
---|
722 | if (strlen(objName) == 0) |
---|
723 | break |
---|
724 | endif |
---|
725 | Rename $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
726 | index+=1 |
---|
727 | while(1) |
---|
728 | SetDataFolder root: |
---|
729 | // catch |
---|
730 | // Print "Aborted: " + num2str(V_AbortCode) |
---|
731 | // SetDataFolder root: |
---|
732 | // endtry |
---|
733 | End |
---|
734 | |
---|
735 | |
---|
736 | Function DuplicateDataSet(dataSetFolder, newName) |
---|
737 | String dataSetFolder |
---|
738 | String newName |
---|
739 | |
---|
740 | String dataSetFolderParent,basestr,objName |
---|
741 | Variable index = 0 |
---|
742 | |
---|
743 | //Abuse ParseFilePath to get path without folder name |
---|
744 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
745 | //Abuse ParseFilePath to get basestr |
---|
746 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
747 | |
---|
748 | SetDataFolder $(dataSetFolderParent) |
---|
749 | // try |
---|
750 | DuplicateDataFolder $(dataSetFolder) $(dataSetFolderParent+newName)//; AbortOnRTE |
---|
751 | |
---|
752 | SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE |
---|
753 | do |
---|
754 | objName = GetIndexedObjName("",1,index) |
---|
755 | if (strlen(objName) == 0) |
---|
756 | break |
---|
757 | endif |
---|
758 | Rename $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
759 | index+=1 |
---|
760 | while(1) |
---|
761 | SetDataFolder root: |
---|
762 | // catch |
---|
763 | // Print "Aborted: " + num2str(V_AbortCode) |
---|
764 | // SetDataFolder root: |
---|
765 | // |
---|
766 | // endtry |
---|
767 | End |
---|
768 | |
---|
769 | |
---|
770 | // Subtract Set2 From Set1 |
---|
771 | // Use Result_I = Set1_I - f*Set2_I |
---|
772 | Function SubtractDataSets(set1Name,set2Name,set2Scale,resultName) |
---|
773 | String set1Name |
---|
774 | String set2Name |
---|
775 | Variable set2Scale |
---|
776 | String resultName |
---|
777 | |
---|
778 | String set1Path = "root:"+set1Name+":" |
---|
779 | String set2Path = "root:"+set2Name+":" |
---|
780 | String resultPath = "root:"+resultName+":" |
---|
781 | |
---|
782 | SetDataFolder root: |
---|
783 | //Create folder for result |
---|
784 | //UnloadDataSet(resultName) |
---|
785 | if (!DataFolderExists(resultPath)) |
---|
786 | //Make the folder |
---|
787 | DuplicateDataSet(set1Path,resultName) |
---|
788 | endif |
---|
789 | |
---|
790 | //Do subtraction of I waves - including interpolation if necessary. |
---|
791 | Wave result_i = $(resultPath+resultName+"_i") |
---|
792 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
793 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
794 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
795 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
796 | result_i = set1_i - (set2Scale*interp(set1_q[p],set2_q,set2_i)) |
---|
797 | |
---|
798 | |
---|
799 | //Calculate result error wave - can we produce corrected Q error? |
---|
800 | |
---|
801 | //Generate history string to record what was done? |
---|
802 | |
---|
803 | End |
---|
804 | |
---|
805 | // Add Set2 to Set1 |
---|
806 | // Use Result_I = Set1_I + f*Set2_I |
---|
807 | Function AddDataSets(set1Name,set2Name,set2Scale,resultName) |
---|
808 | String set1Name |
---|
809 | String set2Name |
---|
810 | Variable set2Scale |
---|
811 | String resultName |
---|
812 | |
---|
813 | String set1Path = "root:"+set1Name+":" |
---|
814 | String set2Path = "root:"+set2Name+":" |
---|
815 | String resultPath = "root:"+resultName+":" |
---|
816 | |
---|
817 | SetDataFolder root: |
---|
818 | //Create folder for result |
---|
819 | //UnloadDataSet(resultName) |
---|
820 | if (DataFolderExists(resultPath) != 1) |
---|
821 | //Make the folder |
---|
822 | DuplicateDataSet(set1Path,resultName) |
---|
823 | endif |
---|
824 | |
---|
825 | //Do addition of I waves - including interpolation if necessary. |
---|
826 | Wave result_i = $(resultPath+resultName+"_i") |
---|
827 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
828 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
829 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
830 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
831 | result_i = set1_i + set2Scale*interp(set1_q[p],set2_q,set2_i) |
---|
832 | |
---|
833 | //Calculate result error wave - can we produce corrected Q error? |
---|
834 | |
---|
835 | //Generate history string to record what was done? |
---|
836 | |
---|
837 | End |
---|
838 | |
---|
839 | // Multiply Set1 by Set2 |
---|
840 | // Use Result_I = Set1_I * (f*Set2_I) |
---|
841 | Function MultiplyDataSets(set1Name, set2Name, set2Scale, resultName) |
---|
842 | String set1Name |
---|
843 | String set2Name |
---|
844 | Variable set2Scale |
---|
845 | String resultName |
---|
846 | |
---|
847 | String set1Path = "root:"+set1Name+":" |
---|
848 | String set2Path = "root:"+set2Name+":" |
---|
849 | String resultPath = "root:"+resultName+":" |
---|
850 | |
---|
851 | SetDataFolder root: |
---|
852 | //Create folder for result |
---|
853 | //UnloadDataSet(resultName) |
---|
854 | if (DataFolderExists(resultPath) != 1) |
---|
855 | //Make the folder |
---|
856 | DuplicateDataSet(set1Path,resultName) |
---|
857 | endif |
---|
858 | |
---|
859 | //Do multiplcation of I waves - including interpolation if necessary. |
---|
860 | Wave result_i = $(resultPath+resultName+"_i") |
---|
861 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
862 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
863 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
864 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
865 | result_i = set1_i*set2Scale*interp(set1_q[p],set2_q,set2_i) |
---|
866 | |
---|
867 | |
---|
868 | //Calculate result error wave - can we produce corrected Q error? |
---|
869 | |
---|
870 | //Generate history string to record what was done? |
---|
871 | |
---|
872 | End |
---|
873 | |
---|
874 | // Divide Set1 by Set2 |
---|
875 | // Use Result_I = Set1_I / (f*Set2_I) |
---|
876 | Function DivideDataSets(set1Name, set2Name, set2Scale, resultName) |
---|
877 | String set1Name |
---|
878 | String set2Name |
---|
879 | Variable set2Scale |
---|
880 | String resultName |
---|
881 | |
---|
882 | String set1Path = "root:"+set1Name+":" |
---|
883 | String set2Path = "root:"+set2Name+":" |
---|
884 | String resultPath = "root:"+resultName+":" |
---|
885 | |
---|
886 | SetDataFolder root: |
---|
887 | //Create folder for result |
---|
888 | //UnloadDataSet(resultName) |
---|
889 | if (DataFolderExists(resultPath) != 1) |
---|
890 | //Make the folder |
---|
891 | DuplicateDataSet(set1Path,resultName) |
---|
892 | endif |
---|
893 | |
---|
894 | //Do division of I waves - including interpolation if necessary. |
---|
895 | Wave result_i = $(resultPath+resultName+"_i") |
---|
896 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
897 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
898 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
899 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
900 | result_i = set1_i/(set2Scale*interp(set1_q[p],set2_q,set2_i) ) |
---|
901 | |
---|
902 | //Calculate result error wave - can we produce corrected Q error? |
---|
903 | |
---|
904 | //Generate history string to record what was done? |
---|
905 | |
---|
906 | End |
---|
907 | |
---|
908 | |
---|
909 | ///////////////////////////Other Utility functions //////////////////////////// |
---|
910 | |
---|
911 | Function SaveDataSetToFile(folderName) |
---|
912 | String folderName |
---|
913 | |
---|
914 | String protoStr = "" |
---|
915 | //Check for history string in folder |
---|
916 | //If it doesn't exist then |
---|
917 | |
---|
918 | //Do saving of data file. |
---|
919 | |
---|
920 | NVAR gXML_Write = root:Packages:NIST:gXML_Write |
---|
921 | |
---|
922 | if (gXML_Write == 1) |
---|
923 | ReWrite1DXMLData(folderName) |
---|
924 | else |
---|
925 | fReWrite1DData(folderName,"tab","CRLF") |
---|
926 | endif |
---|
927 | |
---|
928 | // NISTSave1DData(folderName,protoStr) |
---|
929 | |
---|
930 | //Include history string to record what was done? |
---|
931 | |
---|
932 | End |
---|
933 | |
---|
934 | |
---|
935 | //This will be hideous |
---|
936 | Function UnloadDataSet(folderName) |
---|
937 | String folderName |
---|
938 | |
---|
939 | |
---|
940 | End |
---|
941 | |
---|
942 | |
---|
943 | //////////////////// Write data functions //////////////////////////////////// |
---|
944 | // AJJ Nov 2009 - should move towards unified writer |
---|
945 | // |
---|
946 | ////////////////////////////////////////////////////////////////////////// |
---|
947 | |
---|
948 | //Function NISTSave1DData(folderPath,protoStr) |
---|
949 | // String folderPath, protoStr |
---|
950 | // |
---|
951 | // //protoStr is string that will be written to either |
---|
952 | // |
---|
953 | // |
---|
954 | //End |
---|