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=DANameSetvarproc,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 | // |
---|
129 | Function MakeDAPanel() |
---|
130 | DoWindow/F DataArithmeticPanel |
---|
131 | if(V_flag==0) |
---|
132 | fMakeDAPanel() |
---|
133 | else |
---|
134 | DoWindow/F DAPlotPanel |
---|
135 | endif |
---|
136 | |
---|
137 | return(0) |
---|
138 | End |
---|
139 | |
---|
140 | Function fMakeDAPanel() |
---|
141 | PauseUpdate; Silent 1 // building window... |
---|
142 | DoWindow/K DataArithmeticPanel |
---|
143 | NewPanel /W=(459,44,959,404)/N=DataArithmeticPanel/K=2 as "Data Set Arithmetic" |
---|
144 | ModifyPanel fixedSize=1 |
---|
145 | |
---|
146 | //Main bit of panel |
---|
147 | GroupBox grpBox_0,pos={20,10},size={460,105} |
---|
148 | |
---|
149 | Button DS1_button,pos={300,20},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 1" |
---|
150 | Button DS1_button,valueColor=(65535,0,0),userdata="DS1" |
---|
151 | PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1" |
---|
152 | PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
153 | PopupMenu DS1_popup,proc=DA_PopupProc |
---|
154 | PopupMenu DS1_popup,fsize=12,fcolor=(65535,0,0),valueColor=(65535,0,0) |
---|
155 | |
---|
156 | Button DS2_button,pos={300,50},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 2" |
---|
157 | Button DS2_button,valueColor=(0,0,65535),userdata="DS2" |
---|
158 | PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2" |
---|
159 | PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()" |
---|
160 | PopupMenu DS2_popup,proc=DA_PopupProc |
---|
161 | PopupMenu DS2_popup,fsize=12,fcolor=(0,0,65535),valueColor=(0,0,65535) |
---|
162 | |
---|
163 | Button DAPlot_button,title="Plot",pos={100,85},size={150,20} |
---|
164 | Button DAPlot_button,proc=DAPlotButtonProc |
---|
165 | Button DADone_button,title="Done",pos={360,85},size={60,20} |
---|
166 | Button DADone_button,proc=DADoneButtonProc |
---|
167 | Button DAHelp_button,title="?",pos={440,85},size={30,20} |
---|
168 | Button DAHelp_button,proc=DAHelpButtonProc |
---|
169 | |
---|
170 | |
---|
171 | //Tabs |
---|
172 | TabControl DATabs,pos={20,120},size={460,220},tabLabel(0)="Subtract", proc=DATabsProc |
---|
173 | TabControl DATabs,tablabel(1)="Add",tablabel(2)="Multiply",tablabel(3)="Divide" |
---|
174 | TabControl DATabs,value=0 |
---|
175 | |
---|
176 | Button DACalculate_button,title="Calculate",pos={50,310},size={150,20} |
---|
177 | Button DACalculate_button,proc=DACalculateProc |
---|
178 | Button DASave_button,title="Save Result",pos={300,310},size={150,20} |
---|
179 | Button DASave_button,proc=DASaveProc |
---|
180 | Button DACursors_button,title="Get Matching Range",pos={175,250},size={150,20} |
---|
181 | Button DACursors_button,proc=DACursorButtonProc |
---|
182 | |
---|
183 | SetVariable DAResultName_sv,title="Result Name (max 25 characters)",pos={50,280},size={400,20} |
---|
184 | SetVariable DAResultName_Sv,fsize=12,proc=DANameSetvarproc,live=1 |
---|
185 | //Update the result name |
---|
186 | ControlInfo/W=DataArithmeticPanel DS1_popup |
---|
187 | if (cmpstr(S_Value,"No data loaded") == 0) |
---|
188 | SetVariable DAResultName_sv,value=_STR:"SubtractionResult" |
---|
189 | else |
---|
190 | //fake call to popup |
---|
191 | STRUCT WMPopupAction pa |
---|
192 | pa.win = "DataArithmeticPanel" |
---|
193 | pa.ctrlName = "DS1_popup" |
---|
194 | pa.eventCode = 2 |
---|
195 | DA_PopupProc(pa) |
---|
196 | endif |
---|
197 | |
---|
198 | CheckBox DANoDS2_cb,title="Data Set 2 = 1?",pos={300,180} |
---|
199 | CheckBox DANoDS2_cb,proc=DANoDS2Proc |
---|
200 | |
---|
201 | ValDisplay DARangeStar_vd,title="Start",pos={40,220},size={100,20},fsize=12,value=_NUM:0 |
---|
202 | ValDisplay DARangeEnd_vd,title="End ",pos={160,220},size={100,20},fsize=12,value=_NUM:0 |
---|
203 | |
---|
204 | SetVariable DAScale_sv,title="Scale Factor (f)",pos={280,220},size={180,20},fsize=12,value=_NUM:1 |
---|
205 | |
---|
206 | GroupBox grpBox_1,pos={30,210},size={440,70} |
---|
207 | |
---|
208 | NewPanel/HOST=DataArithmeticPanel/N=arithDisplay/W=(50,150,170,190) |
---|
209 | |
---|
210 | //Update the result name |
---|
211 | ControlInfo/W=DataArithmeticPanel DS1_popup |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | arithDisplayProc(0) |
---|
216 | |
---|
217 | End |
---|
218 | |
---|
219 | |
---|
220 | Function MakeDAPlotPanel() |
---|
221 | PauseUpdate; Silent 1 // building window... |
---|
222 | DoWindow/K DAPlotPanel |
---|
223 | NewPanel /W=(14,44,454,484)/N=DAPlotPanel/K=1 as "Data Set Arithmetic" |
---|
224 | ModifyPanel fixedSize=1 |
---|
225 | |
---|
226 | Display/HOST=DAPlotPanel/N=DAPlot/W=(0,0,440,400) |
---|
227 | Legend |
---|
228 | ShowInfo |
---|
229 | SetActiveSubWindow DAPlotPanel |
---|
230 | Checkbox DAPlot_log_cb, title="Log I(q)", pos={20,410},value=0 |
---|
231 | Checkbox DAPlot_log_cb, proc=DALogLinIProc |
---|
232 | |
---|
233 | End |
---|
234 | |
---|
235 | Function AddDAPlot(dataset) |
---|
236 | Variable dataset |
---|
237 | |
---|
238 | String win = "DataArithmeticPanel" |
---|
239 | String DS1name,DS2name,ResultName |
---|
240 | |
---|
241 | switch(dataset) |
---|
242 | case 1: |
---|
243 | ControlInfo/W=$(win) DS1_popup |
---|
244 | DS1name = S_Value |
---|
245 | Wave qWave = $("root:"+DS1name+":"+DS1name+"_q") |
---|
246 | Wave iWave = $("root:"+DS1name+":"+DS1name+"_i") |
---|
247 | Wave errWave = $("root:"+DS1name+":"+DS1name+"_s") |
---|
248 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
249 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS1name+"_i"), Y wave=(errWave,errWave) |
---|
250 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS1name+"_i"))=(65535,0,0) |
---|
251 | ControlInfo/W=$(win) DANoDS2_cb |
---|
252 | // if (V_Value == 1) |
---|
253 | // Cursor/W=DAPlotPanel#DAPlot A, $(DS1name+"_i"), leftx(iWave) |
---|
254 | // Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS1name+"_i"), rightx(iWave) |
---|
255 | // endif |
---|
256 | break |
---|
257 | case 2: |
---|
258 | ControlInfo/W=$(win) DANoDS2_cb |
---|
259 | if (V_Value == 0) |
---|
260 | ControlInfo/W=$(win) DS2_popup |
---|
261 | DS2name = S_Value |
---|
262 | if(cmpstr(DS2name,"No data loaded")==0) |
---|
263 | break //in case someone loads set 1, but not set two, then plots |
---|
264 | endif |
---|
265 | Wave qWave = $("root:"+DS2name+":"+DS2name+"_q") |
---|
266 | Wave iWave = $("root:"+DS2name+":"+DS2name+"_i") |
---|
267 | Wave errWave = $("root:"+DS2name+":"+DS2name+"_s") |
---|
268 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
269 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS2name+"_i"), Y wave=(errWave,errWave) |
---|
270 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS2name+"_i"))=(0,0,65535) |
---|
271 | Cursor/W=DAPlotPanel#DAPlot A, $(DS2name+"_i"), leftx(iWave) |
---|
272 | Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS2name+"_i"), rightx(iWave) |
---|
273 | else |
---|
274 | ControlInfo/W=$(win) DS1_popup |
---|
275 | DS1name = S_Value |
---|
276 | DuplicateDataSet("root:"+DS1name,"NullSolvent",1) |
---|
277 | Wave qWave =root:NullSolvent:NullSolvent_q |
---|
278 | Wave iWave = root:NullSolvent:NullSolvent_i |
---|
279 | Wave errWave = root:NullSolvent:NullSolvent_s |
---|
280 | Wave iWaveDS1 = $("root:"+DS1name+":"+DS1name+"_i") |
---|
281 | iWave = 1 |
---|
282 | errWave = 0 |
---|
283 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
284 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 NullSolvent_i, Y wave=(errWave,errWave) |
---|
285 | ModifyGraph/W=DAPlotPanel#DAPlot rgb(NullSolvent_i)=(0,0,65535) |
---|
286 | //Cursor/W=DAPlotPanel#DAPlot A, NullSolvent_i, leftx(iWave) |
---|
287 | //Cursor/W=DAPlotPanel#DAPlot/A=0 B, NullSolvent_i, rightx(iWave) |
---|
288 | if(strlen(CsrInfo(A,"DAPlotPanel#DAPlot")) == 0) //cursors not already on the graph |
---|
289 | Cursor/W=DAPlotPanel#DAPlot A, $(DS1Name+"_i"), leftx(iWaveDS1) |
---|
290 | Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS1Name+"_i"), rightx(iWaveDS1) |
---|
291 | endif |
---|
292 | endif |
---|
293 | break |
---|
294 | case 3: |
---|
295 | ControlInfo/W=$(win) DAResultName_sv |
---|
296 | ResultName = S_Value |
---|
297 | Wave qWave = $("root:"+ResultName+":"+ResultName+"_q") |
---|
298 | Wave iWave = $("root:"+ResultName+":"+ResultName+"_i") |
---|
299 | Wave errWave = $("root:"+ResultName+":"+ResultName+"_s") |
---|
300 | AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave |
---|
301 | ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(ResultName+"_i"), Y wave=(errWave,errWave) |
---|
302 | ModifyGraph/W=DAPlotPanel#DAPlot rgb($(ResultName+"_i"))=(0,65535,0) |
---|
303 | break |
---|
304 | endswitch |
---|
305 | |
---|
306 | ControlInfo/W=DAPlotPanel DAPlot_log_cb |
---|
307 | ModifyGraph/W=DAPlotPanel#DAPlot mode=3, msize=2, marker=19, mirror=1, tick=2, log(bottom)=1,log(left)=V_Value,tickUnit=1 |
---|
308 | End |
---|
309 | |
---|
310 | Function arithDisplayProc(s) |
---|
311 | Variable s |
---|
312 | |
---|
313 | SetActiveSubWindow DataArithmeticPanel#arithDisplay |
---|
314 | |
---|
315 | switch (s) |
---|
316 | case 0: |
---|
317 | //Subtract |
---|
318 | DrawAction/L=progFront delete |
---|
319 | DrawRect 0,0,120,40 |
---|
320 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
321 | DrawText 10,32,"I" |
---|
322 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
323 | DrawText 20,30,"=" |
---|
324 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
325 | DrawText 35,32,"I" |
---|
326 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
327 | DrawText 95,32,"I" |
---|
328 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
329 | DrawText 52,32,"-" |
---|
330 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
331 | DrawText 75,30,"f" |
---|
332 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
333 | DrawText 85,32,"*" |
---|
334 | break |
---|
335 | case 1: |
---|
336 | //Add |
---|
337 | DrawAction/L=progFront delete |
---|
338 | DrawRect 0,0,120,40 |
---|
339 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
340 | DrawText 10,32,"I" |
---|
341 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
342 | DrawText 20,30,"=" |
---|
343 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
344 | DrawText 35,32,"I" |
---|
345 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
346 | DrawText 95,32,"I" |
---|
347 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
348 | DrawText 52,32,"+" |
---|
349 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
350 | DrawText 75,30,"f" |
---|
351 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
352 | DrawText 85,32,"*" |
---|
353 | break |
---|
354 | case 2: |
---|
355 | //Multiply |
---|
356 | DrawAction/L=progFront delete |
---|
357 | DrawRect 0,0,120,40 |
---|
358 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
359 | DrawText 10,32,"I" |
---|
360 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
361 | DrawText 20,30,"=" |
---|
362 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
363 | DrawText 35,32,"I" |
---|
364 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
365 | DrawText 95,32,"I" |
---|
366 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
367 | DrawText 52,32,"*" |
---|
368 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
369 | DrawText 66,30,"(" |
---|
370 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
371 | DrawText 75,30,"f" |
---|
372 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
373 | DrawText 85,32,"*" |
---|
374 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
375 | DrawText 105,30,")" |
---|
376 | break |
---|
377 | case 3: |
---|
378 | //Divide |
---|
379 | DrawAction/L=progFront delete |
---|
380 | DrawRect 0,0,120,40 |
---|
381 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) |
---|
382 | DrawText 10,32,"I" |
---|
383 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
384 | DrawText 20,30,"=" |
---|
385 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) |
---|
386 | DrawText 35,32,"I" |
---|
387 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) |
---|
388 | DrawText 95,32,"I" |
---|
389 | SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
390 | DrawText 52,32,"/" |
---|
391 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
392 | DrawText 66,30,"(" |
---|
393 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
394 | DrawText 75,30,"f" |
---|
395 | SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) |
---|
396 | DrawText 85,32,"*" |
---|
397 | SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) |
---|
398 | DrawText 105,30,")" |
---|
399 | break |
---|
400 | endswitch |
---|
401 | |
---|
402 | SetActiveSubWindow DataArithmeticPanel |
---|
403 | |
---|
404 | return 0 |
---|
405 | End |
---|
406 | |
---|
407 | //Must follow naming scheme to match buttons to popups |
---|
408 | //"Name_button" goes with "Name_popup" |
---|
409 | Function DA_LoadDataSetProc(ba) : ButtonControl |
---|
410 | STRUCT WMButtonAction &ba |
---|
411 | |
---|
412 | switch( ba.eventCode ) |
---|
413 | case 2: // mouse up |
---|
414 | // click code here |
---|
415 | String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" |
---|
416 | Execute cmd |
---|
417 | |
---|
418 | SVAR gLastFileName = root:packages:NIST:gLastFileName |
---|
419 | |
---|
420 | String windowName = ba.win |
---|
421 | String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" |
---|
422 | |
---|
423 | ControlUpdate/W=$(windowName) $(popupName) |
---|
424 | //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow |
---|
425 | // convoluted method to find the right item and pop the menu. |
---|
426 | |
---|
427 | String list,folderStr |
---|
428 | Variable num |
---|
429 | folderStr = CleanupName(gLastFileName,0) |
---|
430 | list = DM_DataSetPopupList() |
---|
431 | num=WhichListItem(folderStr,list,";",0,0) |
---|
432 | if(num != -1) |
---|
433 | PopupMenu $(popupName),mode=num+1,win=$(windowName) |
---|
434 | ControlUpdate/W=$(windowName) $(popupName) |
---|
435 | |
---|
436 | endif |
---|
437 | //fake call to popup |
---|
438 | STRUCT WMPopupAction pa |
---|
439 | pa.win = ba.win |
---|
440 | pa.ctrlName = "DS1_popup" |
---|
441 | pa.eventCode = 2 |
---|
442 | DA_PopupProc(pa) |
---|
443 | break |
---|
444 | endswitch |
---|
445 | |
---|
446 | return 0 |
---|
447 | End |
---|
448 | |
---|
449 | Function DA_PopupProc(pa) : PopupMenuControl |
---|
450 | STRUCT WMPopupAction &pa |
---|
451 | |
---|
452 | String resultName |
---|
453 | |
---|
454 | switch( pa.eventCode) |
---|
455 | case 2: |
---|
456 | //print "Called by "+pa.ctrlname+" with value "+pa.popStr |
---|
457 | ControlInfo/W=$(pa.win) $(pa.ctrlName) |
---|
458 | String popStr = S_Value |
---|
459 | if (stringmatch(pa.ctrlname,"*DS1*") == 1) |
---|
460 | resultName = stringfromlist(0,popStr,"_")+"_mod" |
---|
461 | |
---|
462 | SetVariable DAResultName_sv win=$(pa.win), value=_STR:resultName |
---|
463 | endif |
---|
464 | break |
---|
465 | endswitch |
---|
466 | |
---|
467 | |
---|
468 | End |
---|
469 | |
---|
470 | // function to control the drawing of buttons in the TabControl on the main panel |
---|
471 | // Naming scheme for the buttons MUST be strictly adhered to... else buttons will |
---|
472 | // appear in odd places... |
---|
473 | // all buttons are named MainButton_NA where N is the tab number and A is the letter denoting |
---|
474 | // the button's position on that particular tab. |
---|
475 | // in this way, buttons will always be drawn correctly.. |
---|
476 | // |
---|
477 | Function DATabsProc(tca) : TabControl |
---|
478 | STRUCT WMTabControlAction &tca |
---|
479 | |
---|
480 | switch (tca.eventCode) |
---|
481 | case 2: |
---|
482 | // Print "name,number",name,tab |
---|
483 | String ctrlList = ControlNameList("",";"),item="",nameStr="" |
---|
484 | Variable num = ItemsinList(ctrlList,";"),ii,onTab |
---|
485 | for(ii=0;ii<num;ii+=1) |
---|
486 | //items all start w/"DSTabItem_" |
---|
487 | item=StringFromList(ii, ctrlList ,";") |
---|
488 | nameStr=item[0,9] |
---|
489 | if(cmpstr(nameStr,"DATabItem_")==0) |
---|
490 | onTab = str2num(item[10]) |
---|
491 | ControlInfo $item |
---|
492 | switch (V_flag) |
---|
493 | case 1: |
---|
494 | Button $item,disable=(tca.tab!=onTab) |
---|
495 | break |
---|
496 | case 2: |
---|
497 | CheckBox $item,disable=(tca.tab!=onTab) |
---|
498 | break |
---|
499 | case 3: |
---|
500 | PopUpMenu $item,disable=(tca.tab!=onTab) |
---|
501 | break |
---|
502 | case 5: |
---|
503 | SetVariable $item,disable=(tca.tab!=onTab) |
---|
504 | break |
---|
505 | endswitch |
---|
506 | endif |
---|
507 | endfor |
---|
508 | |
---|
509 | arithDisplayProc(tca.tab) |
---|
510 | break |
---|
511 | endswitch |
---|
512 | End |
---|
513 | |
---|
514 | |
---|
515 | Function DACalculateProc(ba) : ButtonControl |
---|
516 | STRUCT WMButtonAction &ba |
---|
517 | |
---|
518 | String DS1,DS2,Resultname |
---|
519 | |
---|
520 | switch(ba.eventCode) |
---|
521 | case 2: |
---|
522 | //Which tab? |
---|
523 | ControlInfo/W=$(ba.win) DATabs |
---|
524 | Variable tabNum = V_value |
---|
525 | //Print "Tab number "+num2str(tabNum) |
---|
526 | |
---|
527 | ControlInfo/W=$(ba.win) DS1_popup |
---|
528 | DS1 = S_Value |
---|
529 | ControlInfo/W=$(ba.win) DANoDS2_cb |
---|
530 | if (V_Value == 0) |
---|
531 | ControlInfo/W=$(ba.win) DS2_popup |
---|
532 | DS2 = S_Value |
---|
533 | else |
---|
534 | DS2 = "NullSolvent" |
---|
535 | endif |
---|
536 | ControlInfo/W=$(ba.win) DAResultName_sv |
---|
537 | Resultname = CleanupName(S_Value, 0 ) //clean up any bad characters, and put the cleaned string back |
---|
538 | SetVariable DAResultName_sv,value=_STR:ResultName |
---|
539 | |
---|
540 | ControlInfo/W=$(ba.win) DAScale_sv |
---|
541 | Variable Scalefactor = V_Value |
---|
542 | |
---|
543 | switch(tabNum) |
---|
544 | case 0: |
---|
545 | //do subtraction |
---|
546 | //print "Subtraction of "+DS2+" from "+DS1+" with sf "+num2str(scalefactor)+ " into "+Resultname |
---|
547 | SubtractDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
548 | break |
---|
549 | case 1: |
---|
550 | //do addition |
---|
551 | AddDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
552 | break |
---|
553 | case 2: |
---|
554 | //do multiplication |
---|
555 | MultiplyDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
556 | break |
---|
557 | case 3: |
---|
558 | //do division |
---|
559 | DivideDataSets(DS1,DS2,Scalefactor,Resultname) |
---|
560 | break |
---|
561 | endswitch |
---|
562 | |
---|
563 | //Sort out plot |
---|
564 | //Fake button press to DAPlotButtonProc |
---|
565 | STRUCT WMButtonAction ba2 |
---|
566 | ba2.win = ba.win |
---|
567 | ba2.ctrlName = "DAPlot_button" |
---|
568 | ba2.eventCode = 2 |
---|
569 | |
---|
570 | // I've commented this out - the cursors get reset to the ends since this removes all sets from the graph, and |
---|
571 | // then replots them. What is the real purpose of this call? To clear the old result off before adding the |
---|
572 | // new one? |
---|
573 | // DAPlotButtonProc(ba2) |
---|
574 | ba2.userData = ResultName |
---|
575 | DAPlotRemoveResult(ba2) |
---|
576 | |
---|
577 | |
---|
578 | AddDAPlot(3) |
---|
579 | DoWindow/F DataArithmeticPanel |
---|
580 | // SetActiveSubWindow DAPlotPanel |
---|
581 | endswitch |
---|
582 | |
---|
583 | End |
---|
584 | |
---|
585 | // remove what is not the |
---|
586 | // |
---|
587 | Function DAPlotRemoveResult(ba) : ButtonControl |
---|
588 | STRUCT WMButtonAction &ba |
---|
589 | |
---|
590 | String win = ba.win |
---|
591 | String ResultName = ba.userData |
---|
592 | String item="",traceList="" |
---|
593 | Variable ii=0,num |
---|
594 | |
---|
595 | switch (ba.eventCode) |
---|
596 | case 2: //mouse up |
---|
597 | //data set 1 |
---|
598 | ControlInfo/W=$(win) DS1_popup |
---|
599 | String DS1 = S_Value |
---|
600 | |
---|
601 | //Get folder for DS2 |
---|
602 | ControlInfo/W=$(win) DS2_popup |
---|
603 | String DS2 = S_Value |
---|
604 | |
---|
605 | // state of the checkbox |
---|
606 | ControlInfo/W=$(win) DANoDS2_cb |
---|
607 | if(V_flag) |
---|
608 | DS2 = "NullSolvent" |
---|
609 | endif |
---|
610 | |
---|
611 | DoWindow DAPlotPanel |
---|
612 | if (V_Flag == 0) |
---|
613 | MakeDAPlotPanel() |
---|
614 | else |
---|
615 | DoWindow/HIDE=0/F DAPlotPanel |
---|
616 | traceList = TraceNameList("DAPlotPanel#DAPlot",";",1) |
---|
617 | num=ItemsInList(traceList) |
---|
618 | ii=0 |
---|
619 | do |
---|
620 | item = StringFromList(ii,traceList,";") |
---|
621 | if (stringmatch(item,ResultName+"*")==1) //it it's the specific trace I've asked to remove |
---|
622 | RemoveFromGraph/W=DAPlotPanel#DAPlot $item |
---|
623 | elseif (stringmatch(item,DS1+"*")==0 && stringmatch(item,DS2+"*")==0) //if it's not set1 & not set2 |
---|
624 | RemoveFromGraph/W=DAPlotPanel#DAPlot $item |
---|
625 | endif |
---|
626 | |
---|
627 | ii+=1 |
---|
628 | while(ii<num) |
---|
629 | endif |
---|
630 | |
---|
631 | break |
---|
632 | endswitch |
---|
633 | |
---|
634 | return 0 |
---|
635 | End |
---|
636 | |
---|
637 | |
---|
638 | Function DAPlotButtonProc(ba) : ButtonControl |
---|
639 | STRUCT WMButtonAction &ba |
---|
640 | |
---|
641 | String win = ba.win |
---|
642 | |
---|
643 | switch (ba.eventCode) |
---|
644 | case 2: |
---|
645 | //mouse up |
---|
646 | //Get folder for DS1 |
---|
647 | DoWindow DAPlotPanel |
---|
648 | if (V_Flag == 0) |
---|
649 | MakeDAPlotPanel() |
---|
650 | else |
---|
651 | DoWindow/HIDE=0/F DAPlotPanel |
---|
652 | do |
---|
653 | String tracename = StringFromList(0,TraceNameList("DAPlotPanel#DAPlot",";",1),";") |
---|
654 | if (cmpstr(tracename,"")==0) |
---|
655 | break |
---|
656 | else |
---|
657 | RemoveFromGraph/W=DAPlotPanel#DAPlot $tracename |
---|
658 | endif |
---|
659 | while(1) |
---|
660 | endif |
---|
661 | |
---|
662 | ControlInfo/W=$(win) DS1_popup |
---|
663 | String DS1 = S_Value |
---|
664 | if (cmpstr(DS1,"") != 0 ) |
---|
665 | AddDAPlot(1) |
---|
666 | endif |
---|
667 | //Get folder for DS2 |
---|
668 | ControlInfo/W=$(win) DS2_popup |
---|
669 | String DS2 = S_Value |
---|
670 | if (cmpstr(DS2,"") != 0) |
---|
671 | AddDAPlot(2) |
---|
672 | endif |
---|
673 | break |
---|
674 | endswitch |
---|
675 | |
---|
676 | return 0 |
---|
677 | End |
---|
678 | |
---|
679 | Function DADoneButtonProc(ba) : ButtonControl |
---|
680 | STRUCT WMButtonAction &ba |
---|
681 | |
---|
682 | String win = ba.win |
---|
683 | |
---|
684 | switch (ba.eventCode) |
---|
685 | case 2: |
---|
686 | DoWindow/K DAPlotPanel |
---|
687 | DoWindow/K DataArithmeticPanel |
---|
688 | break |
---|
689 | endswitch |
---|
690 | |
---|
691 | return 0 |
---|
692 | End |
---|
693 | |
---|
694 | Function DAHelpButtonProc(ba) : ButtonControl |
---|
695 | STRUCT WMButtonAction &ba |
---|
696 | |
---|
697 | String win = ba.win |
---|
698 | |
---|
699 | switch (ba.eventCode) |
---|
700 | case 2: |
---|
701 | // click code here |
---|
702 | DisplayHelpTopic/Z/K=1 "Data Set Arithmetic" |
---|
703 | if(V_flag !=0) |
---|
704 | DoAlert 0,"The Data Set Arithmetic Help file could not be found" |
---|
705 | endif |
---|
706 | break |
---|
707 | endswitch |
---|
708 | |
---|
709 | return 0 |
---|
710 | End |
---|
711 | |
---|
712 | Function DALogLinIProc(cba) : CheckBoxControl |
---|
713 | STRUCT WMCheckBoxAction &cba |
---|
714 | |
---|
715 | switch(cba.eventcode) |
---|
716 | case 2: |
---|
717 | |
---|
718 | ModifyGraph/W=DAPlotPanel#DAPlot log(left)=cba.checked |
---|
719 | |
---|
720 | endswitch |
---|
721 | |
---|
722 | |
---|
723 | End |
---|
724 | |
---|
725 | Function DACursorButtonProc(ba) : ButtonControl |
---|
726 | STRUCT WMButtonAction &ba |
---|
727 | |
---|
728 | String DS1,DS2 |
---|
729 | |
---|
730 | switch(ba.eventCode) |
---|
731 | case 2: |
---|
732 | |
---|
733 | ControlInfo/W=$(ba.win) DS1_popup |
---|
734 | DS1 = S_Value |
---|
735 | ControlInfo/W=$(ba.win) DANoDS2_cb |
---|
736 | Variable NoDS2 = V_Value |
---|
737 | if (NoDS2 == 0) |
---|
738 | ControlInfo/W=$(ba.win) DS2_popup |
---|
739 | DS2 = S_Value |
---|
740 | else |
---|
741 | DS2 = "NullSolvent" |
---|
742 | endif |
---|
743 | |
---|
744 | //AJJ Nov 2009 - UGLY - Will have to revisit this when we deal with hierarchical folders |
---|
745 | Wave set1_i = $("root:"+DS1+":"+DS1+"_i") |
---|
746 | Wave set1_q = $("root:"+DS1+":"+DS1+"_q") |
---|
747 | Wave set2_i = $("root:"+DS2+":"+DS2+"_i") |
---|
748 | Wave set2_q = $("root:"+DS2+":"+DS2+"_q") |
---|
749 | Duplicate/O set1_i tmp_i |
---|
750 | Duplicate/O set1_q tmp_q |
---|
751 | tmp_i = set1_i / interp(set1_q[p],set2_q,set2_i) |
---|
752 | |
---|
753 | //Get cursors |
---|
754 | Variable q1,q2 |
---|
755 | |
---|
756 | DoWindow/F DAPlotPanel |
---|
757 | SetActiveSubWindow DAPlotPanel#DAPlot |
---|
758 | |
---|
759 | q1 = CsrXWaveRef(A)[pcsr(A)] |
---|
760 | q2 = CsrXWaveRef(B)[pcsr(B)] |
---|
761 | |
---|
762 | //Update value display |
---|
763 | ValDisplay DARangeStar_vd,value=_NUM:q1, win=$(ba.win) |
---|
764 | ValDisplay DARangeEnd_vd,value=_NUM:q2, win=$(ba.win) |
---|
765 | |
---|
766 | //Calculate scalefactor |
---|
767 | |
---|
768 | if (NoDS2 == 1) |
---|
769 | Wave avgWave = set1_i |
---|
770 | else |
---|
771 | Wave avgWave = tmp_i |
---|
772 | endif |
---|
773 | |
---|
774 | Variable p1 = BinarySearch(tmp_q,q1) |
---|
775 | Variable p2 = BinarySearch(tmp_q,q2) |
---|
776 | |
---|
777 | //print avgWave |
---|
778 | |
---|
779 | WaveStats/Q/R=[p1,p2] avgWave |
---|
780 | //print V_avg |
---|
781 | //Update sv control |
---|
782 | SetVariable DAScale_sv, value=_NUM:V_avg, win=$(ba.win) |
---|
783 | |
---|
784 | KillWaves/Z tmp_i,tmp_q |
---|
785 | DoWindow/F DataArithmeticPanel |
---|
786 | endswitch |
---|
787 | |
---|
788 | End |
---|
789 | |
---|
790 | |
---|
791 | Function DANoDS2Proc(cba) : CheckBoxControl |
---|
792 | STRUCT WMCheckBoxAction &cba |
---|
793 | |
---|
794 | |
---|
795 | switch(cba.eventCode) |
---|
796 | case 2: |
---|
797 | if (cba.checked == 1) |
---|
798 | //Disable DS2 popup etc |
---|
799 | PopupMenu DS2_popup win=$(cba.win), disable=2 |
---|
800 | Button DS2_button win=$(cba.win), disable=2 |
---|
801 | else |
---|
802 | //Enable DS2 popup etc |
---|
803 | PopupMenu DS2_popup win=$(cba.win), disable=0 |
---|
804 | Button DS2_button win=$(cba.win), disable=0 |
---|
805 | endif |
---|
806 | //Sort out plot |
---|
807 | //Fake button press to DAPlotButtonProc |
---|
808 | STRUCT WMButtonAction ba2 |
---|
809 | ba2.win = cba.win |
---|
810 | ba2.ctrlName = "DAPlot_button" |
---|
811 | ba2.eventCode = 2 |
---|
812 | DAPlotButtonProc(ba2) |
---|
813 | SetActiveSubWindow DAPlotPanel |
---|
814 | DoWindow/F DataArithmeticPanel |
---|
815 | endswitch |
---|
816 | |
---|
817 | End |
---|
818 | |
---|
819 | Function DASaveProc(ba) : ButtonControl |
---|
820 | STRUCT WMButtonAction &ba |
---|
821 | |
---|
822 | switch(ba.eventCode) |
---|
823 | case 2: |
---|
824 | ControlInfo/W=$(ba.win) DAResultName_sv |
---|
825 | SaveDataSetToFile(S_Value) |
---|
826 | break |
---|
827 | endswitch |
---|
828 | |
---|
829 | |
---|
830 | End |
---|
831 | |
---|
832 | /////////////////////// Common Panel Functions /////////////////////////////////////// |
---|
833 | |
---|
834 | |
---|
835 | // is there a simpler way to do this? I don't think so. |
---|
836 | Function/S DM_DataSetPopupList() |
---|
837 | |
---|
838 | String str=GetAList(4) |
---|
839 | |
---|
840 | if(strlen(str)==0) |
---|
841 | str = "No data loaded" |
---|
842 | endif |
---|
843 | str = SortList(str) |
---|
844 | |
---|
845 | return(str) |
---|
846 | End |
---|
847 | |
---|
848 | |
---|
849 | Function DANameSetvarproc(sva) : SetVariableControl |
---|
850 | STRUCT WMSetVariableAction &sva |
---|
851 | |
---|
852 | switch( sva.eventCode ) |
---|
853 | case 1: // mouse up |
---|
854 | case 2: // Enter key |
---|
855 | case 3: // Live update |
---|
856 | String sv = sva.sval |
---|
857 | if( strlen(sv) > 25 ) |
---|
858 | sv= sv[0,24] |
---|
859 | SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv |
---|
860 | Beep |
---|
861 | endif |
---|
862 | break |
---|
863 | endswitch |
---|
864 | return 0 |
---|
865 | End |
---|
866 | |
---|
867 | |
---|
868 | ////////////////////// Functions to do manipulations /////////////////////////////////// |
---|
869 | |
---|
870 | Function RenameDataSet(dataSetFolder, newName) |
---|
871 | String dataSetFolder |
---|
872 | String newName |
---|
873 | |
---|
874 | String dataSetFolderParent,basestr,objName |
---|
875 | Variable index = 0 |
---|
876 | |
---|
877 | //Abuse ParseFilePath to get path without folder name |
---|
878 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
879 | //Abuse ParseFilePath to get basestr |
---|
880 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
881 | |
---|
882 | // try |
---|
883 | RenameDataFolder $(dataSetFolder) $(newName)//; AbortOnRTE |
---|
884 | |
---|
885 | |
---|
886 | SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE |
---|
887 | do |
---|
888 | objName = GetIndexedObjName("",1,index) |
---|
889 | if (strlen(objName) == 0) |
---|
890 | break |
---|
891 | endif |
---|
892 | Rename $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
893 | index+=1 |
---|
894 | while(1) |
---|
895 | SetDataFolder root: |
---|
896 | // catch |
---|
897 | // Print "Aborted: " + num2str(V_AbortCode) |
---|
898 | // SetDataFolder root: |
---|
899 | // endtry |
---|
900 | End |
---|
901 | |
---|
902 | |
---|
903 | Function DuplicateDataSet(dataSetFolder, newName, forceoverwrite) |
---|
904 | String dataSetFolder |
---|
905 | String newName |
---|
906 | Variable forceoverwrite |
---|
907 | |
---|
908 | String dataSetFolderParent,basestr,objName |
---|
909 | Variable index = 0 |
---|
910 | |
---|
911 | //Abuse ParseFilePath to get path without folder name |
---|
912 | dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0) |
---|
913 | //Abuse ParseFilePath to get basestr |
---|
914 | basestr = ParseFilePath(0,dataSetFolder,":",1,0) |
---|
915 | |
---|
916 | print "Duplicating "+dataSetFolder+" as "+newName |
---|
917 | |
---|
918 | SetDataFolder $(dataSetFolderParent) |
---|
919 | |
---|
920 | if (!DataFolderExists(newName)) |
---|
921 | NewDataFolder $(newName) |
---|
922 | else |
---|
923 | if (!forceoverwrite) |
---|
924 | DoAlert 1, "A dataset with the name "+newName+" already exists. Overwrite?" |
---|
925 | if (V_flag == 2) |
---|
926 | return 1 |
---|
927 | endif |
---|
928 | endif |
---|
929 | endif |
---|
930 | |
---|
931 | //If we are here, the folder (now) exists and the user has agreed to overwrite |
---|
932 | //either in the function call or from the alert. |
---|
933 | do |
---|
934 | objName = GetIndexedObjName(basestr,1,index) |
---|
935 | if (strlen(objName) == 0) |
---|
936 | break |
---|
937 | endif |
---|
938 | objname = ":"+basestr+":"+objname |
---|
939 | Duplicate/O $(objName) $(ReplaceString(basestr,objName,newName)) |
---|
940 | index+=1 |
---|
941 | while(1) |
---|
942 | |
---|
943 | SetDataFolder root: |
---|
944 | return 0 |
---|
945 | End |
---|
946 | |
---|
947 | |
---|
948 | // Subtract Set2 From Set1 |
---|
949 | // Use Result_I = Set1_I - f*Set2_I |
---|
950 | Function SubtractDataSets(set1Name,set2Name,set2Scale,resultName) |
---|
951 | String set1Name |
---|
952 | String set2Name |
---|
953 | Variable set2Scale |
---|
954 | String resultName |
---|
955 | |
---|
956 | String set1Path = "root:"+set1Name+":" |
---|
957 | String set2Path = "root:"+set2Name+":" |
---|
958 | String resultPath = "root:"+resultName+":" |
---|
959 | |
---|
960 | SetDataFolder root: |
---|
961 | //Create folder for result |
---|
962 | //UnloadDataSet(resultName) |
---|
963 | //Make the folder |
---|
964 | if (DuplicateDataSet(set1Path,resultName,0)) |
---|
965 | return 1 |
---|
966 | else |
---|
967 | //Do subtraction of I waves - including interpolation if necessary. |
---|
968 | Wave result_i = $(resultPath+resultName+"_i") |
---|
969 | Wave result_s = $(resultPath+resultName+"_s") |
---|
970 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
971 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
972 | Wave set1_s = $(set1Path+set1Name+"_s") |
---|
973 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
974 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
975 | Wave set2_s = $(set2Path+set2Name+"_s") |
---|
976 | |
---|
977 | result_i = set1_i - (set2Scale*interp(set1_q[p],set2_q,set2_i)) |
---|
978 | result_s = sqrt(set1_s^2 + set2Scale^2*interp(set1_q[p],set2_q,set2_s)) |
---|
979 | //Calculate result error wave - can we produce corrected Q error? |
---|
980 | |
---|
981 | //Generate history string to record what was done? |
---|
982 | return 0 |
---|
983 | endif |
---|
984 | End |
---|
985 | |
---|
986 | // Add Set2 to Set1 |
---|
987 | // Use Result_I = Set1_I + f*Set2_I |
---|
988 | Function AddDataSets(set1Name,set2Name,set2Scale,resultName) |
---|
989 | String set1Name |
---|
990 | String set2Name |
---|
991 | Variable set2Scale |
---|
992 | String resultName |
---|
993 | |
---|
994 | String set1Path = "root:"+set1Name+":" |
---|
995 | String set2Path = "root:"+set2Name+":" |
---|
996 | String resultPath = "root:"+resultName+":" |
---|
997 | |
---|
998 | SetDataFolder root: |
---|
999 | //Create folder for result |
---|
1000 | if(DuplicateDataSet(set1Path,resultName,0)) |
---|
1001 | //User said no overwrite |
---|
1002 | return 1 |
---|
1003 | else |
---|
1004 | //Do addition of I waves - including interpolation if necessary. |
---|
1005 | Wave result_i = $(resultPath+resultName+"_i") |
---|
1006 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
1007 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
1008 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
1009 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
1010 | result_i = set1_i + set2Scale*interp(set1_q[p],set2_q,set2_i) |
---|
1011 | |
---|
1012 | //Calculate result error wave - can we produce corrected Q error? |
---|
1013 | |
---|
1014 | //Generate history string to record what was done? |
---|
1015 | return 0 |
---|
1016 | endif |
---|
1017 | End |
---|
1018 | |
---|
1019 | // Multiply Set1 by Set2 |
---|
1020 | // Use Result_I = Set1_I * (f*Set2_I) |
---|
1021 | Function MultiplyDataSets(set1Name, set2Name, set2Scale, resultName) |
---|
1022 | String set1Name |
---|
1023 | String set2Name |
---|
1024 | Variable set2Scale |
---|
1025 | String resultName |
---|
1026 | |
---|
1027 | String set1Path = "root:"+set1Name+":" |
---|
1028 | String set2Path = "root:"+set2Name+":" |
---|
1029 | String resultPath = "root:"+resultName+":" |
---|
1030 | |
---|
1031 | SetDataFolder root: |
---|
1032 | //Create folder for result |
---|
1033 | //Make the folder |
---|
1034 | if(DuplicateDataSet(set1Path,resultName,0)) |
---|
1035 | //User said no overwrite |
---|
1036 | return 1 |
---|
1037 | else |
---|
1038 | //Do multiplcation of I waves - including interpolation if necessary. |
---|
1039 | Wave result_i = $(resultPath+resultName+"_i") |
---|
1040 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
1041 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
1042 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
1043 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
1044 | result_i = set1_i*set2Scale*interp(set1_q[p],set2_q,set2_i) |
---|
1045 | |
---|
1046 | |
---|
1047 | //Calculate result error wave - can we produce corrected Q error? |
---|
1048 | |
---|
1049 | //Generate history string to record what was done? |
---|
1050 | return 0 |
---|
1051 | endif |
---|
1052 | End |
---|
1053 | |
---|
1054 | // Divide Set1 by Set2 |
---|
1055 | // Use Result_I = Set1_I / (f*Set2_I) |
---|
1056 | Function DivideDataSets(set1Name, set2Name, set2Scale, resultName) |
---|
1057 | String set1Name |
---|
1058 | String set2Name |
---|
1059 | Variable set2Scale |
---|
1060 | String resultName |
---|
1061 | |
---|
1062 | String set1Path = "root:"+set1Name+":" |
---|
1063 | String set2Path = "root:"+set2Name+":" |
---|
1064 | String resultPath = "root:"+resultName+":" |
---|
1065 | |
---|
1066 | SetDataFolder root: |
---|
1067 | //Create folder for result |
---|
1068 | //Make the folder |
---|
1069 | if(DuplicateDataSet(set1Path,resultName,0)) |
---|
1070 | //User said no overwrite |
---|
1071 | return 1 |
---|
1072 | else |
---|
1073 | //Do division of I waves - including interpolation if necessary. |
---|
1074 | Wave result_i = $(resultPath+resultName+"_i") |
---|
1075 | Wave set1_i = $(set1Path+set1Name+"_i") |
---|
1076 | Wave set1_q = $(set1Path+set1Name+"_q") |
---|
1077 | Wave set2_i = $(set2Path+set2Name+"_i") |
---|
1078 | Wave set2_q = $(set2Path+set2Name+"_q") |
---|
1079 | result_i = set1_i/(set2Scale*interp(set1_q[p],set2_q,set2_i) ) |
---|
1080 | |
---|
1081 | //Calculate result error wave - can we produce corrected Q error? |
---|
1082 | |
---|
1083 | //Generate history string to record what was done? |
---|
1084 | return 0 |
---|
1085 | endif |
---|
1086 | End |
---|
1087 | |
---|
1088 | |
---|
1089 | ///////////////////////////Other Utility functions //////////////////////////// |
---|
1090 | |
---|
1091 | Function SaveDataSetToFile(folderName) |
---|
1092 | String folderName |
---|
1093 | |
---|
1094 | String protoStr = "" |
---|
1095 | //Check for history string in folder |
---|
1096 | //If it doesn't exist then |
---|
1097 | |
---|
1098 | //Do saving of data file. |
---|
1099 | |
---|
1100 | NVAR gXML_Write = root:Packages:NIST:gXML_Write |
---|
1101 | |
---|
1102 | if (gXML_Write == 1) |
---|
1103 | ReWrite1DXMLData(folderName) |
---|
1104 | else |
---|
1105 | fReWrite1DData(folderName,"tab","CRLF") |
---|
1106 | endif |
---|
1107 | |
---|
1108 | // NISTSave1DData(folderName,protoStr) |
---|
1109 | |
---|
1110 | //Include history string to record what was done? |
---|
1111 | |
---|
1112 | End |
---|
1113 | |
---|
1114 | |
---|
1115 | //This will be hideous |
---|
1116 | Function UnloadDataSet(folderName) |
---|
1117 | String folderName |
---|
1118 | |
---|
1119 | |
---|
1120 | End |
---|
1121 | |
---|
1122 | |
---|
1123 | //////////////////// Write data functions //////////////////////////////////// |
---|
1124 | // AJJ Nov 2009 - should move towards unified writer |
---|
1125 | // |
---|
1126 | ////////////////////////////////////////////////////////////////////////// |
---|
1127 | |
---|
1128 | //Function NISTSave1DData(folderPath,protoStr) |
---|
1129 | // String folderPath, protoStr |
---|
1130 | // |
---|
1131 | // //protoStr is string that will be written to either |
---|
1132 | // |
---|
1133 | // |
---|
1134 | //End |
---|