1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | |
---|
5 | // Version 1.0 |
---|
6 | // SRK 7 OCT 2009 |
---|
7 | // |
---|
8 | |
---|
9 | // Adding two raw .bt5 files: |
---|
10 | // - only files with the same angle range and the same number of points can be added. |
---|
11 | // - NO shifting is done - these are raw data files, and the angular shift is not known |
---|
12 | // - it can be repeated multiple times to add more than two files together |
---|
13 | // - the two added files are listed in the title of the summed file. |
---|
14 | // -- see AddBT5AndSave() if you want something that cen be automated to bypass the user dialogs. |
---|
15 | |
---|
16 | // Adding two data sets: |
---|
17 | // - here, two entire data sets (inlcluding the main beam) are added together after |
---|
18 | // loading and normalizing and coverting to Q. The data file is NOT saved out, because |
---|
19 | // it is not a format that can be re-read in for reduction. |
---|
20 | // - to use the summed data set, it is first summed in a separate panel, and then transferred |
---|
21 | // to either the active "SAM" or "EMP" data |
---|
22 | // - since the zero offset can make the point values not exactly the same, only those within a |
---|
23 | // certain tolerance are actually added. Points that cannot be added are still kept in the final |
---|
24 | // data set. |
---|
25 | // |
---|
26 | |
---|
27 | // issues |
---|
28 | // - are the errors calculated correctly? I think so... |
---|
29 | // - if there is a direct 1:1 correspondence of the data points, saving is easy |
---|
30 | // -- if not, then some points will have a different counting time |
---|
31 | // -- this is always the case if I do a "full" data set. |
---|
32 | // |
---|
33 | // - convert to countrate seems like a good idea, then 1+1=2 and I can propagate errors |
---|
34 | // -- but how to save the data? At this point, errCR != sqrt(CR) |
---|
35 | // -> answer is -- don't save the full data sets that have been summed... |
---|
36 | // |
---|
37 | // - Why can't I just use the whole set of files from the main USANS panel, and add what needs |
---|
38 | // to be added? Because if there is an angle shift, I have no way of knowing which files to apply |
---|
39 | // the shift to... |
---|
40 | // |
---|
41 | // - do I have anything hard-wired in the code that needs to be generalized before release? |
---|
42 | // |
---|
43 | |
---|
44 | |
---|
45 | // simple stuff to do: |
---|
46 | // - allow user to input Qpeak (maybe of no use?) If so, do it right away with a dialog |
---|
47 | // if no peak was found. |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | Proc ShowUSANSAddPanel() |
---|
52 | DoWindow/F USANS_Add_Panel |
---|
53 | if(V_Flag==0) |
---|
54 | Init_AddUSANS() |
---|
55 | USANS_Add_Panel() |
---|
56 | Endif |
---|
57 | End |
---|
58 | |
---|
59 | |
---|
60 | // initializes the folders and globals for use with the USANS_Add_Panel |
---|
61 | // |
---|
62 | // there is some overlap of the controls from the Main_USANS panel |
---|
63 | // separate waves are created for the lists in :AddPanel |
---|
64 | // |
---|
65 | Proc Init_AddUSANS() |
---|
66 | NewDataFolder/O root:Packages |
---|
67 | NewDataFolder/O root:Packages:NIST |
---|
68 | NewDataFolder/O root:Packages:NIST:USANS |
---|
69 | NewDataFolder/O root:Packages:NIST:USANS:Globals |
---|
70 | NewDataFolder/O/S root:Packages:NIST:USANS:Globals:AddPanel |
---|
71 | |
---|
72 | String/G root:Packages:NIST:USANS:Globals:gUSANSFolder = "root:Packages:NIST:USANS" |
---|
73 | String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
74 | |
---|
75 | //Preference value to determine if we are outputting XML |
---|
76 | // Variable/G root:Packages:NIST:USANS:Globals:gUseXMLOutput = 0 |
---|
77 | String/G FilterStr |
---|
78 | Variable/G gAddUSANSTolerance = 0.01 // add points if x is within 1% (an arbitrary choice!) |
---|
79 | |
---|
80 | Make/O/T/N=1 fileWave,AWave,BWave |
---|
81 | fileWave="" |
---|
82 | AWave="" |
---|
83 | BWave="" |
---|
84 | |
---|
85 | // Make/O/T/N=5 statusWave="" |
---|
86 | Make/O/B/U/N=1 selFileW |
---|
87 | |
---|
88 | |
---|
89 | SetDataFolder root: |
---|
90 | |
---|
91 | NewDataFolder/O $(USANSFolder+":TMP_A") |
---|
92 | NewDataFolder/O $(USANSFolder+":TMP_B") |
---|
93 | NewDataFolder/O $(USANSFolder+":SUM_AB") |
---|
94 | |
---|
95 | End |
---|
96 | |
---|
97 | |
---|
98 | //draws the USANS_Add_Panel, somewhat similar to the Main panel |
---|
99 | // |
---|
100 | // but used exclusively for adding files, and is a graph/control bar |
---|
101 | // |
---|
102 | |
---|
103 | Proc USANS_Add_Panel() |
---|
104 | PauseUpdate; Silent 1 // building window... |
---|
105 | Display /W=(100,44,900,493)/K=1 as "USANS_Add_Panel" |
---|
106 | DoWindow/C USANS_Add_Panel |
---|
107 | DoWindow/T USANS_Add_Panel, "Add Raw USANS Files" |
---|
108 | ControlBar/L 300 |
---|
109 | |
---|
110 | // ModifyGraph cbRGB=(36929,50412,31845) |
---|
111 | ModifyGraph cbRGB=(65535,60076,49151) |
---|
112 | |
---|
113 | // (I don't know where these end up anyhow...) |
---|
114 | // SetDrawLayer UserBack |
---|
115 | // SetDrawEnv fstyle= 1 |
---|
116 | // DrawText 12,53,"Data Files" |
---|
117 | // SetDrawEnv fstyle= 1 |
---|
118 | // DrawText 157,192,"Empty Scans" |
---|
119 | // SetDrawEnv fstyle= 1 |
---|
120 | // DrawText 154,54,"Sample Scans" |
---|
121 | // DrawLine 6,337,398,337 |
---|
122 | // DrawLine 5,33,393,33 |
---|
123 | // SetDrawEnv fstyle= 1 |
---|
124 | // DrawText 140,357,"Raw Data Header" |
---|
125 | // SetDrawEnv fstyle= 1 |
---|
126 | |
---|
127 | ListBox AfileLB,pos={5,55},size={110,230}//,proc=AddFileListBoxProc |
---|
128 | ListBox AfileLB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:fileWave |
---|
129 | ListBox AfileLB,selWave=root:Packages:NIST:USANS:Globals:AddPanel:selFileW,mode= 4 |
---|
130 | ListBox A_LB,pos={149,55},size={110,90},listWave=root:Packages:NIST:USANS:Globals:AddPanel:AWave |
---|
131 | ListBox A_LB,mode= 1,selRow= -1 |
---|
132 | Button Clear_A_Button,pos={227,148},size={35,20},proc=ClearABButtonProc,title="Clr" |
---|
133 | Button Clear_A_Button,help={"Clears the list of sample scans"} |
---|
134 | Button Clear_B_Button,pos={227,286},size={35,20},proc=ClearABButtonProc,title="Clr" |
---|
135 | Button Clear_B_Button,help={"Clears the list of empty scans"} |
---|
136 | Button ARefreshButton,pos={9,310},size={104,20},proc=RefreshListButtonProc,title="Refresh" |
---|
137 | Button ARefreshButton,help={"Refreshes the list of raw ICP data files"} |
---|
138 | Button Del_A_Button,pos={183,148},size={35,20},proc=DelAButtonProc,title="Del" |
---|
139 | Button Del_A_Button,help={"Deletes the selected file(s) from the list of SET A scans"} |
---|
140 | Button Del_B_Button,pos={183,286},size={35,20},proc=DelBButtonProc,title="Del" |
---|
141 | Button Del_B_Button,help={"Deletes the selected file(s) from the list of SET B scans"} |
---|
142 | ListBox B_LB,pos={151,194},size={110,90} |
---|
143 | ListBox B_LB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:BWave,mode= 1,selRow= 0 |
---|
144 | Button to_A_List,pos={118,55},size={25,90},proc=to_A_ListButtonProc,title="A\r->" |
---|
145 | Button to_A_List,help={"Adds the selected file(s) to the list of SET A scans"} |
---|
146 | Button to_B_List,pos={120,195},size={25,90},proc=to_B_ListButtonProc,title="B\r->" |
---|
147 | Button to_B_List,help={"Adds the selected file(s) to the list of SET B scans"} |
---|
148 | // ListBox StatusLB,pos={11,358},size={386,77} |
---|
149 | // ListBox StatusLB,listWave=root:Packages:NIST:USANS:Globals:AddPanel:statusWave |
---|
150 | Button pickPathButton,pos={6,8},size={80,20},proc=PickBT5PathButton,title="DataPath..." |
---|
151 | Button pickPathButton,help={"Select the data folder where the raw ICP data files are located"} |
---|
152 | Button PlotSelected_A_Button,pos={140,148},size={35,20},proc=PlotSelected_AB_ButtonProc,title="Plot" |
---|
153 | Button PlotSelected_A_Button,help={"Plot the selected sample scattering files in the COR_Graph"} |
---|
154 | Button PlotSelected_B_Button,pos={140,286},size={35,20},proc=PlotSelected_AB_ButtonProc,title="Plot" |
---|
155 | Button PlotSelected_B_Button,help={"Plot the selected empty cell scattering files in the COR_Graph"} |
---|
156 | Button pickSavePathButton,pos={97,8},size={80,20},proc=PickSaveButtonProc,title="SavePath..." |
---|
157 | Button pickSavePathButton,help={"Select the data folder where data is to be saved to disk"} |
---|
158 | Button USANSHelpButton,pos={220,6},size={50,20},proc=USANSAddFilesHelpButton,title="Help" |
---|
159 | Button USANSHelpButton,help={"Show the USANS reduction help file"} |
---|
160 | |
---|
161 | SetVariable FilterSetVar,pos={8,289},size={106,18},title="Filter",fSize=12 |
---|
162 | SetVariable FilterSetVar,value= root:Packages:NIST:USANS:Globals:AddPanel:FilterStr |
---|
163 | |
---|
164 | Button A_AddDone,pos={231,414},size={50,20},proc=AddUSANSDone,title="Done" |
---|
165 | Button A_AddDone,help={"Closes the panel"} |
---|
166 | Button AddUSANSButton,pos={12,368},size={80,20},proc=AddUSANSFilesButtonProc,title="Add Files" |
---|
167 | Button AddUSANSButton,help={"Adds the A and B files together"} |
---|
168 | Button AddUSANSButton,fColor=(16386,65535,16385) |
---|
169 | Button ClearSumButton,pos={159,322},size={80,20},proc=ClearSumButtonProc,title="Clear Sum" |
---|
170 | Button ClearSumButton,help={"Clears the summed data from the graph and clears the data in memory"} |
---|
171 | Button SaveSumButton,pos={13,405},size={80,20},proc=SaveSumButtonProc,title="Move Sum" |
---|
172 | Button SaveSumButton,help={"Saves the summed data as a fake bt5 file"} |
---|
173 | Button SaveSumButton,fColor=(16385,28398,65535) |
---|
174 | |
---|
175 | EndMacro |
---|
176 | |
---|
177 | // Show the help file, don't necessarily keep it with the experiment (/K=1) |
---|
178 | Function USANSAddFilesHelpButton(ctrlName) : ButtonControl |
---|
179 | String ctrlName |
---|
180 | |
---|
181 | DisplayHelpTopic/Z/K=1 "Adding Two Data Sets" |
---|
182 | if(V_flag !=0) |
---|
183 | DoAlert 0,"The USANS Data Reduction Help file could not be found" |
---|
184 | endif |
---|
185 | return(0) |
---|
186 | End |
---|
187 | |
---|
188 | Function AddUSANSDone(ba) : ButtonControl |
---|
189 | STRUCT WMButtonAction &ba |
---|
190 | |
---|
191 | switch( ba.eventCode ) |
---|
192 | case 2: // mouse up |
---|
193 | // click code here |
---|
194 | DoWindow/K USANS_Add_Panel |
---|
195 | break |
---|
196 | endswitch |
---|
197 | |
---|
198 | return 0 |
---|
199 | End |
---|
200 | |
---|
201 | Function AddUSANSFilesButtonProc(ba) : ButtonControl |
---|
202 | STRUCT WMButtonAction &ba |
---|
203 | |
---|
204 | switch( ba.eventCode ) |
---|
205 | case 2: // mouse up |
---|
206 | // click code here |
---|
207 | |
---|
208 | Add_AB("") |
---|
209 | |
---|
210 | break |
---|
211 | endswitch |
---|
212 | |
---|
213 | return 0 |
---|
214 | End |
---|
215 | |
---|
216 | Function ClearSumButtonProc(ba) : ButtonControl |
---|
217 | STRUCT WMButtonAction &ba |
---|
218 | |
---|
219 | switch( ba.eventCode ) |
---|
220 | case 2: // mouse up |
---|
221 | // click code here |
---|
222 | RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"SUM_AB") |
---|
223 | CleanOutFolder("SUM_AB") |
---|
224 | |
---|
225 | break |
---|
226 | endswitch |
---|
227 | |
---|
228 | return 0 |
---|
229 | End |
---|
230 | |
---|
231 | |
---|
232 | // really a "move" since I'm not sure about how to poroperly save... |
---|
233 | // |
---|
234 | Function SaveSumButtonProc(ba) : ButtonControl |
---|
235 | STRUCT WMButtonAction &ba |
---|
236 | |
---|
237 | switch( ba.eventCode ) |
---|
238 | case 2: // mouse up |
---|
239 | // click code here |
---|
240 | String type="" |
---|
241 | Prompt type,"Move the sumed data to:", popup, "EMP;SAM;" |
---|
242 | DoPrompt "Move Summed Data",type |
---|
243 | if(V_flag) |
---|
244 | return(0) |
---|
245 | endif |
---|
246 | |
---|
247 | MoveSummedData(type) |
---|
248 | |
---|
249 | break |
---|
250 | endswitch |
---|
251 | |
---|
252 | return 0 |
---|
253 | End |
---|
254 | |
---|
255 | Function Add_AB(ctrlName) : ButtonControl |
---|
256 | String ctrlName |
---|
257 | |
---|
258 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
259 | // copy waves over to the SUM_AB folder |
---|
260 | String fromType = "TMP_A",toType="SUM_AB" |
---|
261 | Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle_A") |
---|
262 | Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts_A") |
---|
263 | Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts_A") |
---|
264 | Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts_A") |
---|
265 | Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts_A") |
---|
266 | |
---|
267 | fromType = "TMP_B" |
---|
268 | Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle_B") |
---|
269 | Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts_B") |
---|
270 | Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts_B") |
---|
271 | Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts_B") |
---|
272 | Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts_B") |
---|
273 | |
---|
274 | SetDataFolder $(USANSFolder+":"+toType) |
---|
275 | Wave Angle_A = Angle_A |
---|
276 | Wave DetCts_A = DetCts_A |
---|
277 | Wave MonCts_A = MonCts_A |
---|
278 | Wave TransCts_A = TransCts_A |
---|
279 | Wave ErrDetCts_A = ErrDetCts_A |
---|
280 | |
---|
281 | Wave Angle_B = Angle_B |
---|
282 | Wave DetCts_B = DetCts_B |
---|
283 | Wave MonCts_B = MonCts_B |
---|
284 | Wave TransCts_B = TransCts_B |
---|
285 | Wave ErrDetCts_B = ErrDetCts_B |
---|
286 | |
---|
287 | Make/O/D/N=0 Angle,DetCts,MonCts,TransCts,ErrDetCts |
---|
288 | |
---|
289 | //do something with the wave note on each DetCts wave so it's not lost |
---|
290 | // String/G note_A = note(DetCts_A) |
---|
291 | // String/G note_B = note(DetCts_B) |
---|
292 | |
---|
293 | |
---|
294 | Variable minPt,minDelta |
---|
295 | Variable ii,jj,nA,nB,sumPt=0 |
---|
296 | nA = numpnts(Angle_A) |
---|
297 | nB = numpnts(Angle_B) |
---|
298 | Make/O/D/N=(nB) tmp_delta |
---|
299 | |
---|
300 | NVAR tol = root:Packages:NIST:USANS:Globals:AddPanel:gAddUSANSTolerance //1% error allowed as default |
---|
301 | |
---|
302 | for(ii=0;ii<nA;ii+=1) |
---|
303 | Redimension/N=(nB) tmp_delta |
---|
304 | tmp_delta = NaN //initialize every pass |
---|
305 | tmp_delta = abs( (Angle_A[ii] - Angle_B)/Angle_B ) |
---|
306 | |
---|
307 | WaveStats/Q tmp_delta |
---|
308 | minPt = V_minLoc |
---|
309 | minDelta = V_min |
---|
310 | |
---|
311 | if(minDelta < tol) |
---|
312 | // Printf "Angle_A %g matches with Angle_B %g with error %g\r",Angle_A[ii],Angle_B[minPt],minDelta |
---|
313 | // add the points to the sum waves |
---|
314 | InsertPoints sumPt,1,Angle,DetCts,MonCts,TransCts,ErrDetCts |
---|
315 | Angle[sumPt] = (Angle_A[ii]+Angle_B[minPt])/2 |
---|
316 | DetCts[sumPt] = (DetCts_A[ii] + DetCts_B[minPt])/2 |
---|
317 | MonCts[sumPt] = (MonCts_A[ii] + MonCts_B[minPt])/2 |
---|
318 | TransCts[sumPt] = (TransCts_A[ii] + TransCts_B[minPt])/2 |
---|
319 | ErrDetCts[sumPt] = sqrt(ErrDetCts_A[ii]^2 + ErrDetCts_B[minPt]^2)/2 |
---|
320 | |
---|
321 | sumPt += 1 |
---|
322 | // remove the point from B (all of them) |
---|
323 | DeletePoints minPt, 1, Angle_B,DetCts_B,MonCts_B,TransCts_B,ErrDetCts_B |
---|
324 | nB -= 1 |
---|
325 | // |
---|
326 | else |
---|
327 | //Printf "NoMatch for Angle_A %g with error %g\r",Angle_A[ii],minDelta |
---|
328 | // just copy it over |
---|
329 | InsertPoints sumPt,1,Angle,DetCts,MonCts,TransCts,ErrDetCts |
---|
330 | Angle[sumPt] = Angle_A[ii] |
---|
331 | DetCts[sumPt] = DetCts_A[ii] |
---|
332 | MonCts[sumPt] = MonCts_A[ii] |
---|
333 | TransCts[sumPt] = TransCts_A[ii] |
---|
334 | ErrDetCts[sumPt] = ErrDetCts_A[ii] |
---|
335 | |
---|
336 | sumPt += 1 |
---|
337 | endif |
---|
338 | |
---|
339 | endfor |
---|
340 | |
---|
341 | // bring in all of the unmatched "B" values, including the error |
---|
342 | Concatenate {Angle_B},Angle |
---|
343 | Concatenate {DetCts_B},DetCts |
---|
344 | Concatenate {MonCts_B},MonCts |
---|
345 | Concatenate {TransCts_B},TransCts |
---|
346 | Concatenate {ErrDetCts_B},ErrDetCts |
---|
347 | |
---|
348 | // then sort everything by angle |
---|
349 | Sort Angle,Angle,DetCts,MonCts,TransCts,ErrDetCts |
---|
350 | |
---|
351 | // update the wave note on detCts? it is zeroed now, for one |
---|
352 | String aNote="",bNote="",afile="",bFile="",str="" |
---|
353 | aNote=note(DetCts_A) |
---|
354 | aNote = ReplaceNumberByKey("PEAKANG",aNote,0,":",";") //set the angle to zero in the summed set |
---|
355 | //adjust the A wavenote, to account for the new dataset |
---|
356 | bNote = note(DetCts_B) |
---|
357 | bFile = StringByKey("FILE",bNote,":",";") |
---|
358 | |
---|
359 | aFile = StringByKey("FILE",aNote,":",";") |
---|
360 | aFile += "," + bfile |
---|
361 | aNote = ReplaceStringByKey("FILE",aNote,aFile,":",";") |
---|
362 | |
---|
363 | Note/K DetCts |
---|
364 | Note DetCts,aNote |
---|
365 | |
---|
366 | SetDataFolder root: |
---|
367 | |
---|
368 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
369 | String type="SUM_AB" |
---|
370 | if(WaveExists($(USANSFolder+":"+type+":Qvals"))) |
---|
371 | Duplicate/O $(USANSFolder+":"+type+":Qvals"),$(USANSFolder+":Graph:Qvals_"+type) |
---|
372 | Endif |
---|
373 | Duplicate/O $(USANSFolder+":"+type+":Angle"),$(USANSFolder+":Graph:Angle_"+type) |
---|
374 | Duplicate/O $(USANSFolder+":"+type+":DetCts"),$(USANSFolder+":Graph:DetCts_"+type) |
---|
375 | Duplicate/O $(USANSFolder+":"+type+":ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_"+type) |
---|
376 | |
---|
377 | |
---|
378 | Do_AB_Graph("SUM_AB") |
---|
379 | return(0) |
---|
380 | End |
---|
381 | |
---|
382 | |
---|
383 | // plots the selected A or B files onto the USANS_Add_Panel |
---|
384 | // Does the following: |
---|
385 | // - loads raw data |
---|
386 | // ?? normalizes counts to time and 1E6 monitor counts |
---|
387 | // - sorts by angle |
---|
388 | // - finds zero angle (and peak height) |
---|
389 | // X converts to q-values |
---|
390 | // X finds T wide |
---|
391 | // - updates the graph |
---|
392 | // |
---|
393 | Function PlotSelected_AB_ButtonProc(ctrlName) : ButtonControl |
---|
394 | String ctrlName |
---|
395 | |
---|
396 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
397 | |
---|
398 | String type="" |
---|
399 | if(cmpstr(ctrlName,"PlotSelected_A_Button")==0) |
---|
400 | type = "TMP_A" |
---|
401 | Wave/T listW=$(USANSFolder+":Globals:AddPanel:AWave") |
---|
402 | else |
---|
403 | type = "TMP_B" |
---|
404 | Wave/T listW=$(USANSFolder+":Globals:AddPanel:BWave") |
---|
405 | endif |
---|
406 | |
---|
407 | //get selected files from listbox (everything) |
---|
408 | //use the listBox wave directly |
---|
409 | |
---|
410 | //Wave for indication of current data set AJJ Sept 2006 |
---|
411 | // Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
412 | Variable ii,num=numpnts(listW) |
---|
413 | String fname="",fpath="",curPathStr="" |
---|
414 | PathInfo bt5PathName |
---|
415 | fpath = S_Path |
---|
416 | PathInfo bt5CurPathName |
---|
417 | curPathStr = S_Path |
---|
418 | |
---|
419 | // print fpath |
---|
420 | |
---|
421 | if(cmpstr("",listW[0])==0) |
---|
422 | return(0) //null item in 1st position, exit |
---|
423 | Endif |
---|
424 | |
---|
425 | //load, normalize, and append |
---|
426 | //loop over the number of items in the list |
---|
427 | for(ii=0;ii<num;ii+=1) |
---|
428 | fname = fpath + listw[ii] |
---|
429 | |
---|
430 | LoadBT5File(fname,"SWAP") //overwrite what's in the SWAP folder |
---|
431 | // Convert2Countrate("SWAP",0) //convert to cts/s, don't normalize to default Mon |
---|
432 | Convert2Countrate("SWAP",1) //convert to cts/s, yes, normalize to default Mon |
---|
433 | if(ii==0) //first time, overwrite |
---|
434 | NewDataWaves("SWAP",type) |
---|
435 | else //append to waves in "SAM" |
---|
436 | AppendDataWaves("SWAP",type) |
---|
437 | endif |
---|
438 | endfor |
---|
439 | //sort after all loaded |
---|
440 | DoAngleSort(type) |
---|
441 | |
---|
442 | //find the peak and convert to Q-values |
---|
443 | Variable zeroAngle = FindZeroAngle(type) |
---|
444 | if(zeroAngle == -9999) |
---|
445 | DoAlert 0,"Couldn't find a peak - using zero as zero angle" |
---|
446 | zeroAngle = 0 |
---|
447 | Endif |
---|
448 | |
---|
449 | // ConvertAngle2Qvals(type,zeroAngle) |
---|
450 | Wave angle = $(USANSFolder+":"+type+":Angle") |
---|
451 | Angle = angle[p] - zeroAngle |
---|
452 | |
---|
453 | // |
---|
454 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
455 | if(WaveExists($(USANSFolder+":"+type+":Qvals"))) |
---|
456 | Duplicate/O $(USANSFolder+":"+type+":Qvals"),$(USANSFolder+":Graph:Qvals_"+type) |
---|
457 | Endif |
---|
458 | Duplicate/O $(USANSFolder+":"+type+":Angle"),$(USANSFolder+":Graph:Angle_"+type) |
---|
459 | Duplicate/O $(USANSFolder+":"+type+":DetCts"),$(USANSFolder+":Graph:DetCts_"+type) |
---|
460 | Duplicate/O $(USANSFolder+":"+type+":ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_"+type) |
---|
461 | |
---|
462 | //now plot the data (or just bring the graph to the front) |
---|
463 | Do_AB_Graph(type) |
---|
464 | End |
---|
465 | |
---|
466 | // add SAM data to the graph if it exists and is not already on the graph |
---|
467 | // |
---|
468 | Function Do_AB_Graph(type) |
---|
469 | String type |
---|
470 | |
---|
471 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
472 | |
---|
473 | //is it already on the graph? |
---|
474 | SetDataFolder $(USANSFolder+":Graph") |
---|
475 | String list="" |
---|
476 | list = Wavelist("DetCts_"+type+"*",";","WIN:USANS_Add_Panel") |
---|
477 | if(strlen(list)!=0) |
---|
478 | //Print "SAM already on graph" |
---|
479 | SetDataFolder root: |
---|
480 | return(0) |
---|
481 | endif |
---|
482 | |
---|
483 | //check for the three possibilities |
---|
484 | if(cmpstr(type,"TMP_A")==0) |
---|
485 | //append the data if it exists |
---|
486 | If(waveExists($"DetCts_TMP_A")==1) |
---|
487 | // DoWindow/F USANS_Add_Panel |
---|
488 | AppendToGraph DetCts_TMP_A vs Angle_TMP_A |
---|
489 | ModifyGraph rgb(DetCts_TMP_A)=(1,12815,52428) |
---|
490 | ModifyGraph mode(DetCts_TMP_A)=3,marker(DetCts_TMP_A)=19,msize(DetCts_TMP_A)=2 |
---|
491 | ModifyGraph tickUnit=1,log=1,mirror=2,grid=1 |
---|
492 | ErrorBars/T=0 DetCts_TMP_A Y,wave=(ErrDetCts_TMP_A,ErrDetCts_TMP_A) |
---|
493 | endif |
---|
494 | endif |
---|
495 | |
---|
496 | if(cmpstr(type,"TMP_B")==0) |
---|
497 | //append the data if it exists |
---|
498 | If(waveExists($"DetCts_TMP_B")==1) |
---|
499 | // DoWindow/F USANS_Add_Panel |
---|
500 | AppendToGraph DetCts_TMP_B vs Angle_TMP_B |
---|
501 | ModifyGraph rgb(DetCts_TMP_B)=(1,39321,19939) |
---|
502 | ModifyGraph mode(DetCts_TMP_B)=3,marker(DetCts_TMP_B)=19,msize(DetCts_TMP_B)=2 |
---|
503 | ModifyGraph tickUnit=1,log=1,mirror=2,grid=1 |
---|
504 | ErrorBars/T=0 DetCts_TMP_B Y,wave=(ErrDetCts_TMP_B,ErrDetCts_TMP_B) |
---|
505 | endif |
---|
506 | endif |
---|
507 | |
---|
508 | if(cmpstr(type,"SUM_AB")==0) |
---|
509 | //append the data if it exists |
---|
510 | If(waveExists($"DetCts_SUM_AB")==1) |
---|
511 | // DoWindow/F USANS_Add_Panel |
---|
512 | AppendToGraph DetCts_SUM_AB vs Angle_SUM_AB |
---|
513 | ModifyGraph rgb(DetCts_SUM_AB)=(65535,0,0) |
---|
514 | ModifyGraph mode(DetCts_SUM_AB)=3,marker(DetCts_SUM_AB)=19,msize(DetCts_SUM_AB)=2 |
---|
515 | ModifyGraph tickUnit=1,log=1,mirror=2,grid=1 |
---|
516 | ErrorBars/T=0 DetCts_SUM_AB Y,wave=(ErrDetCts_SUM_AB,ErrDetCts_SUM_AB) |
---|
517 | endif |
---|
518 | endif |
---|
519 | |
---|
520 | if(strlen(list)==0) |
---|
521 | //drawing a new graph |
---|
522 | Legend |
---|
523 | Label left "(Counts/sec)/(MON)*10\\S6\\M" |
---|
524 | Label bottom "Angle (deg)" |
---|
525 | endif |
---|
526 | |
---|
527 | SetDataFolder root: |
---|
528 | End |
---|
529 | |
---|
530 | |
---|
531 | // copies the selected files from the raw file list box to the sam file listbox |
---|
532 | // |
---|
533 | // makes sure that any null items are removed from the wave attached to the listbox |
---|
534 | // |
---|
535 | Function to_A_ListButtonProc(ctrlName) : ButtonControl |
---|
536 | String ctrlName |
---|
537 | |
---|
538 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
539 | |
---|
540 | //Print "toSamList button" |
---|
541 | Wave/T fileWave=$(USANSFolder+":Globals:AddPanel:fileWave") |
---|
542 | Wave/T AWave=$(USANSFolder+":Globals:AddPanel:AWave") |
---|
543 | Wave sel=$(USANSFolder+":Globals:AddPanel:selFileW") |
---|
544 | //Wave to indicate Current status |
---|
545 | // Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
546 | |
---|
547 | |
---|
548 | Variable num=numpnts(sel),ii=0 |
---|
549 | variable lastPt=numpnts(AWave) |
---|
550 | do |
---|
551 | if(sel[ii] == 1) |
---|
552 | InsertPoints lastPt,1, AWave |
---|
553 | AWave[lastPt]=filewave[ii] |
---|
554 | // InsertPoints lastPt, 1, isCurrent |
---|
555 | // isCurrent[lastPt] = 0 |
---|
556 | lastPt +=1 |
---|
557 | endif |
---|
558 | ii+=1 |
---|
559 | while(ii<num) |
---|
560 | |
---|
561 | //clean out any (null) elements |
---|
562 | num=numpnts(AWave) |
---|
563 | for(ii=0;ii<num;ii+=1) |
---|
564 | if(cmpstr(AWave[ii],"") ==0) |
---|
565 | DeletePoints ii,1,AWave |
---|
566 | // DeletePoints ii,1,isCurrent |
---|
567 | num -= 1 |
---|
568 | Endif |
---|
569 | Endfor |
---|
570 | |
---|
571 | return(0) |
---|
572 | End |
---|
573 | |
---|
574 | // copies the selected files from the raw file list box to the sam file listbox |
---|
575 | // |
---|
576 | // makes sure that any null items are removed from the wave attached to the listbox |
---|
577 | // |
---|
578 | Function to_B_ListButtonProc(ctrlName) : ButtonControl |
---|
579 | String ctrlName |
---|
580 | |
---|
581 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
582 | |
---|
583 | //Print "toEmptyList button" |
---|
584 | Wave/T fileWave=$(USANSFolder+":Globals:AddPanel:fileWave") |
---|
585 | Wave/T BWave=$(USANSFolder+":Globals:AddPanel:BWave") |
---|
586 | Wave sel=$(USANSFolder+":Globals:AddPanel:selFileW") |
---|
587 | //Wave to indicate Current status |
---|
588 | // Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
589 | |
---|
590 | |
---|
591 | |
---|
592 | Variable num=numpnts(sel),ii=0 |
---|
593 | variable lastPt=numpnts(BWave) |
---|
594 | do |
---|
595 | if(sel[ii] == 1) |
---|
596 | InsertPoints lastPt,1, BWave |
---|
597 | BWave[lastPt]=filewave[ii] |
---|
598 | // InsertPoints lastPt, 1, isCurrent |
---|
599 | // isCurrent[lastPt] = 0 |
---|
600 | lastPt +=1 |
---|
601 | endif |
---|
602 | ii+=1 |
---|
603 | while(ii<num) |
---|
604 | |
---|
605 | //clean out any (null) elements |
---|
606 | num=numpnts(BWave) |
---|
607 | for(ii=0;ii<num;ii+=1) |
---|
608 | if(cmpstr(BWave[ii],"") ==0) |
---|
609 | DeletePoints ii,1,BWave |
---|
610 | // DeletePoints ii,1,isCurrent |
---|
611 | num -= 1 |
---|
612 | Endif |
---|
613 | Endfor |
---|
614 | |
---|
615 | return(0) |
---|
616 | End |
---|
617 | |
---|
618 | //deletes the selected file from the A list |
---|
619 | // multiple selections are not allowed |
---|
620 | // the cor_graph is not updated |
---|
621 | // |
---|
622 | Function DelAButtonProc(ctrlName) : ButtonControl |
---|
623 | String ctrlName |
---|
624 | |
---|
625 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
626 | |
---|
627 | ControlInfo A_LB |
---|
628 | Variable selRow=V_Value |
---|
629 | Wave lw=$(S_DataFolder + S_Value) |
---|
630 | DeletePoints selRow,1,lw |
---|
631 | //Clear out current flag AJJ Sept O6 |
---|
632 | // Wave isCurrent = $(USANSFolder+":Globals:AddPanel:SAMisCurrent") |
---|
633 | // DeletePoints selRow, 1, isCurrent |
---|
634 | End |
---|
635 | |
---|
636 | //deletes the selected file from the B list |
---|
637 | // multiple selections are not allowed |
---|
638 | // the cor_graph is not updated |
---|
639 | // |
---|
640 | Function DelBButtonProc(ctrlName) : ButtonControl |
---|
641 | String ctrlName |
---|
642 | |
---|
643 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
644 | |
---|
645 | ControlInfo B_LB |
---|
646 | Variable selRow=V_Value |
---|
647 | Wave lw=$(S_DataFolder + S_Value) |
---|
648 | DeletePoints selRow,1,lw |
---|
649 | //Clear out current flag AJJ Sept O6 |
---|
650 | // Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
651 | // DeletePoints selRow, 1, isCurrent |
---|
652 | End |
---|
653 | |
---|
654 | //clears either the A or B scan Lists... |
---|
655 | //Also clears the data folders and the COR_Graph |
---|
656 | // |
---|
657 | Function ClearABButtonProc(ctrlName) : ButtonControl |
---|
658 | String ctrlName |
---|
659 | |
---|
660 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
661 | |
---|
662 | SetDataFolder $(USANSFolder+":Globals:AddPanel") |
---|
663 | strswitch(ctrlName) |
---|
664 | case "Clear_A_Button": |
---|
665 | Make/O/T/N=1 AWave |
---|
666 | AWave="" |
---|
667 | |
---|
668 | //clear the graph, then the data folders as well |
---|
669 | RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"TMP_A") |
---|
670 | CleanOutFolder("TMP_A") |
---|
671 | RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"SUM_AB") |
---|
672 | CleanOutFolder("SUM_AB") |
---|
673 | break |
---|
674 | case "Clear_B_Button": |
---|
675 | Make/O/T/N=1 BWave |
---|
676 | BWave="" |
---|
677 | |
---|
678 | //clear the graph, then the data folders as well |
---|
679 | // CleanOutGraph("TMP_B") |
---|
680 | RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"TMP_B") |
---|
681 | CleanOutFolder("TMP_B") |
---|
682 | // CleanOutGraph("SUM_AB") |
---|
683 | RemoveFromGraph/W=USANS_Add_Panel/Z $("DetCts_"+"SUM_AB") |
---|
684 | CleanOutFolder("SUM_AB") |
---|
685 | break |
---|
686 | endswitch |
---|
687 | |
---|
688 | SetDataFolder root: |
---|
689 | End |
---|
690 | |
---|
691 | |
---|
692 | |
---|
693 | |
---|
694 | //move the summed data to one of the other data types for reduction |
---|
695 | // |
---|
696 | // type is either SAM or EMP |
---|
697 | // |
---|
698 | // -- still need to move stuff to the EMP folder?? |
---|
699 | // |
---|
700 | Function MoveSummedData(type) |
---|
701 | String type |
---|
702 | |
---|
703 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
704 | |
---|
705 | Variable zeroAngle=0 //summed data is already converted to zero angle |
---|
706 | ConvertAngle2Qvals("SUM_AB",zeroAngle) |
---|
707 | |
---|
708 | //find the Trans Cts for T_Wide |
---|
709 | FindTWideCts("SUM_AB") |
---|
710 | |
---|
711 | if(cmpstr(type,"EMP")==0) |
---|
712 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
713 | if(WaveExists($(USANSFolder+":SUM_AB:Qvals"))) |
---|
714 | Duplicate/O $(USANSFolder+":SUM_AB:Qvals"),$(USANSFolder+":Graph:Qvals_EMP") |
---|
715 | Endif |
---|
716 | Duplicate/O $(USANSFolder+":SUM_AB:Angle"),$(USANSFolder+":Graph:Angle_EMP") |
---|
717 | Duplicate/O $(USANSFolder+":SUM_AB:DetCts"),$(USANSFolder+":Graph:DetCts_EMP") |
---|
718 | Duplicate/O $(USANSFolder+":SUM_AB:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_EMP") |
---|
719 | |
---|
720 | // then copy everything to the EMP folder, for later processing steps |
---|
721 | NewDataWaves("SUM_AB","EMP") |
---|
722 | |
---|
723 | endif |
---|
724 | |
---|
725 | if(cmpstr(type,"SAM")==0) |
---|
726 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
727 | if(WaveExists($(USANSFolder+":SUM_AB:Qvals"))) |
---|
728 | Duplicate/O $(USANSFolder+":SUM_AB:Qvals"),$(USANSFolder+":Graph:Qvals_SAM") |
---|
729 | Endif |
---|
730 | Duplicate/O $(USANSFolder+":SUM_AB:Angle"),$(USANSFolder+":Graph:Angle_SAM") |
---|
731 | Duplicate/O $(USANSFolder+":SUM_AB:DetCts"),$(USANSFolder+":Graph:DetCts_SAM") |
---|
732 | Duplicate/O $(USANSFolder+":SUM_AB:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_SAM") |
---|
733 | |
---|
734 | // then copy everything to the SAM folder, for later processing steps |
---|
735 | NewDataWaves("SUM_AB","SAM") |
---|
736 | |
---|
737 | endif |
---|
738 | |
---|
739 | //now plot the data (or just bring the graph to the front) |
---|
740 | DoCORGraph() |
---|
741 | return(0) |
---|
742 | End |
---|
743 | |
---|
744 | |
---|
745 | ///////////////////////////////// |
---|
746 | // |
---|
747 | // |
---|
748 | // simple add procedures, if raw files are the same, and there's nothing to shift |
---|
749 | // |
---|
750 | // |
---|
751 | |
---|
752 | Proc SelectFilesToAdd(file1,file2) |
---|
753 | String file1,file2 |
---|
754 | Prompt file1, "First File", popup, BT5FileList("") |
---|
755 | Prompt file2, "Second File", popup, BT5FileList("") |
---|
756 | |
---|
757 | // Print file1,file2 |
---|
758 | |
---|
759 | LoadAndAddUSANS(file1,file2) |
---|
760 | |
---|
761 | String filen = file1[0,strlen(file1)-5]+"_SUM"+".BT5" |
---|
762 | |
---|
763 | GetAddedFileName(filen) |
---|
764 | End |
---|
765 | |
---|
766 | Proc GetAddedFileName(newName) |
---|
767 | String newName |
---|
768 | Prompt newName, "Enter new FileName" |
---|
769 | |
---|
770 | SaveAddedBT5Files(newName,1) // 1 asks to confirm the name w/ a dialog |
---|
771 | End |
---|
772 | |
---|
773 | |
---|
774 | // this procedure will add two and name without any dialogs. Pass it the three names |
---|
775 | // if the save name is null, you'll get a dialog |
---|
776 | Proc AddBT5AndSave(file1,file2,filen) |
---|
777 | String file1,file2,filen="TMP.BT5" |
---|
778 | Prompt file1, "First File", popup, BT5FileList("") |
---|
779 | Prompt file2, "Second File", popup, BT5FileList("") |
---|
780 | Prompt filen, "output file name" |
---|
781 | |
---|
782 | LoadAndAddUSANS(file1,file2) |
---|
783 | |
---|
784 | // String filen = file1[0,strlen(file1)-5]+"_SUM"+".BT5" |
---|
785 | |
---|
786 | PathInfo savePathName |
---|
787 | filen = S_Path + filen |
---|
788 | SaveAddedBT5Files(filen,0) //0==no dialog |
---|
789 | |
---|
790 | End |
---|
791 | |
---|
792 | |
---|
793 | |
---|
794 | Function/S BT5FileList(filter) |
---|
795 | String filter |
---|
796 | |
---|
797 | SVAR ext = root:Packages:NIST:USANS:Globals:MainPanel:gUExt |
---|
798 | filter = "*"+ext+"*" |
---|
799 | |
---|
800 | //get all the files, then trim the list |
---|
801 | String list=IndexedFile(bt5PathName,-1,"????") |
---|
802 | String newList="",item="" |
---|
803 | Variable num=ItemsInList(list,";"),ii |
---|
804 | for(ii=0;ii<num;ii+=1) |
---|
805 | item = StringFromList(ii, list ,";") |
---|
806 | |
---|
807 | if( stringmatch(item,filter) ) //ONLY keep files that match the filter + *.bt5 AJJ Sept 06 |
---|
808 | newlist += item + ";" |
---|
809 | endif |
---|
810 | //print "ii=",ii |
---|
811 | endfor |
---|
812 | newList = SortList(newList,";",0) //get them in order |
---|
813 | num=ItemsInList(newlist,";") |
---|
814 | |
---|
815 | |
---|
816 | return(newList) |
---|
817 | End |
---|
818 | |
---|
819 | |
---|
820 | // main add procedure, farms out as needed |
---|
821 | // |
---|
822 | Function LoadAndAddUSANS(file1,file2) |
---|
823 | String file1,file2 |
---|
824 | |
---|
825 | SVAR ext = root:Packages:NIST:USANS:Globals:MainPanel:gUExt |
---|
826 | |
---|
827 | //load each file into a textWave |
---|
828 | Make/O/T/N=200 tw1,tw2 |
---|
829 | |
---|
830 | String fname="",fpath="",fullPath="" |
---|
831 | Variable ctTime1,ang11,ang21 |
---|
832 | Variable ctTime2,ang12,ang22 |
---|
833 | Variable dialog=1 |
---|
834 | |
---|
835 | PathInfo/S savePathName |
---|
836 | fpath = S_Path |
---|
837 | |
---|
838 | if(strlen(S_Path)==0) |
---|
839 | DoAlert 0,"You must select a Save Path... from the main USANS_Panel" |
---|
840 | return(0) |
---|
841 | endif |
---|
842 | |
---|
843 | fname = fpath + file1 |
---|
844 | LoadBT5_toWave(file1,fpath,tw1,ctTime1,ang11,ang21) //redimensions tw1 |
---|
845 | Print "File 1: time, angle1, angle2",ctTime1,ang11,ang21 |
---|
846 | |
---|
847 | fname = fpath + file2 |
---|
848 | LoadBT5_toWave(file2,fpath,tw2,ctTime2,ang12,ang22) //redimensions tw2 |
---|
849 | Print "File 2: time, angle1, angle2",ctTime2,ang12,ang22 |
---|
850 | |
---|
851 | // check if OK to add |
---|
852 | // # lines loaded |
---|
853 | // #pts1 = #pts2 |
---|
854 | // angle range 1 = angle range 2 |
---|
855 | if(numpnts(tw1) != numpnts(tw2)) |
---|
856 | DoAlert 0,"Files are not the same length and can't be directly added" |
---|
857 | //Killwaves/Z tw1,tw2,tw3 |
---|
858 | abort |
---|
859 | return(0) |
---|
860 | endif |
---|
861 | if(ang11 != ang12) |
---|
862 | DoAlert 0,"Files don't start at the same angle and can't be directly added" |
---|
863 | //Killwaves/Z tw1,tw2,tw3 |
---|
864 | abort |
---|
865 | return(0) |
---|
866 | endif |
---|
867 | if(ang21 != ang22) |
---|
868 | DoAlert 0,"Files don't end at the same angle and can't be directly added" |
---|
869 | //Killwaves/Z tw1,tw2,tw3 |
---|
870 | abort |
---|
871 | return(0) |
---|
872 | endif |
---|
873 | |
---|
874 | //if OK, parse line-by-line into third textWave |
---|
875 | // add / update as necessary |
---|
876 | Print "OK to add" |
---|
877 | |
---|
878 | |
---|
879 | |
---|
880 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16 |
---|
881 | Variable a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16 |
---|
882 | Variable ii,valuesRead,countTime,num,refnum |
---|
883 | String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 |
---|
884 | String filen="",fileLabel="",buffer="",str="",term="\r\n" |
---|
885 | |
---|
886 | Duplicate/O/T tw2,tw3 |
---|
887 | tw3="" |
---|
888 | |
---|
889 | //line 0, info to update |
---|
890 | buffer = tw1[0] |
---|
891 | sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8 |
---|
892 | sprintf str,"%s %s 'I' %d 1 'TIME' %d 'SUM'",s1,s2+" "+s3+" "+s4+" "+s5,ctTime1+ctTime2,v3 |
---|
893 | // num=v3 |
---|
894 | tw3[0] = str+term |
---|
895 | tw3[1] = tw1[1] //labels, direct copy |
---|
896 | |
---|
897 | //line 2, sample label |
---|
898 | buffer = tw1[2] |
---|
899 | sscanf buffer,"%s",s1 |
---|
900 | tw3[2] = s1 + " = "+file1+" + "+file2+term |
---|
901 | tw3[3,12] = tw1[p] //unused values, direct copy |
---|
902 | |
---|
903 | num = numpnts(tw1) // |
---|
904 | //parse two lines at a time per data point,starting at 13 |
---|
905 | for(ii=13;ii<num-1;ii+=2) |
---|
906 | buffer = tw1[ii] |
---|
907 | sscanf buffer,"%g%g%g%g%g",v1,v2,v3,v4,v5 // 5 values here now |
---|
908 | |
---|
909 | buffer = tw2[ii] |
---|
910 | sscanf buffer,"%g%g%g%g%g",a1,a2,a3,a4,a5 // 5 values here now |
---|
911 | |
---|
912 | if(a1 != v1) |
---|
913 | DoAlert 0,"Angles don't match and can't be directly added" |
---|
914 | //Killwaves/Z tw1,tw2,tw3 |
---|
915 | abort |
---|
916 | return(0) |
---|
917 | endif |
---|
918 | |
---|
919 | sprintf str," %g %g %g %g %g",v1,v2+a2,v3+a3,v4+a4,v5+a5 |
---|
920 | tw3[ii] = str+term |
---|
921 | |
---|
922 | |
---|
923 | buffer = tw1[ii+1] |
---|
924 | sscanf buffer,"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g",v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16 |
---|
925 | |
---|
926 | buffer = tw2[ii+1] |
---|
927 | sscanf buffer,"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g",a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16 |
---|
928 | |
---|
929 | sprintf str,"%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g",a1+v1,a2+v2,a3+v3,a4+v4,a5+v5,a6+v6,a7+v7,a8+v8,a9+v9,a10+v10,a11+v11,a12+v12,a13+v13,a14+v14,a15+v15,a16+v16 |
---|
930 | tw3[ii+1] = str+term |
---|
931 | |
---|
932 | endfor |
---|
933 | |
---|
934 | // // write out the final file (=tw3) |
---|
935 | // filen = file1[0,strlen(file1)-5]+"_SUM"+ext |
---|
936 | // |
---|
937 | // if(dialog) |
---|
938 | // PathInfo/S savePathName |
---|
939 | // fullPath = DoSaveFileDialog("Save data as",fname=filen) |
---|
940 | // If(cmpstr(fullPath,"")==0) |
---|
941 | // //user cancel, don't write out a file |
---|
942 | // Close/A |
---|
943 | // Abort "no data file was written" |
---|
944 | // Endif |
---|
945 | // //Print "dialog fullpath = ",fullpath |
---|
946 | // Endif |
---|
947 | // |
---|
948 | // Open refNum as fullPath |
---|
949 | // wfprintf refnum, "%s",tw3 |
---|
950 | // Close refnum |
---|
951 | // |
---|
952 | // //killwaves/Z tw1,tw2,tw3 |
---|
953 | |
---|
954 | return(0) |
---|
955 | end |
---|
956 | |
---|
957 | // if you bypass the dialog, newname needs to be a full path |
---|
958 | Function SaveAddedBT5Files(newName,dialog) |
---|
959 | String newName |
---|
960 | Variable dialog |
---|
961 | |
---|
962 | Variable refnum |
---|
963 | String fullPath |
---|
964 | |
---|
965 | WAVE/T tw3=tw3 |
---|
966 | |
---|
967 | if(dialog) |
---|
968 | PathInfo/S savePathName |
---|
969 | fullPath = DoSaveFileDialog("Save data as",fname=newName) |
---|
970 | If(cmpstr(fullPath,"")==0) |
---|
971 | //user cancel, don't write out a file |
---|
972 | Close/A |
---|
973 | Abort "no data file was written" |
---|
974 | Endif |
---|
975 | newName=FullPath |
---|
976 | //Print "dialog fullpath = ",fullpath |
---|
977 | Endif |
---|
978 | |
---|
979 | |
---|
980 | Open refNum as newName |
---|
981 | wfprintf refnum, "%s",tw3 |
---|
982 | Close refnum |
---|
983 | |
---|
984 | return(0) |
---|
985 | End |
---|
986 | |
---|
987 | //returns count time and start/stop angles as written in header |
---|
988 | // number of lines in the file is a separate check |
---|
989 | // |
---|
990 | Function LoadBT5_toWave(fname,fpath,tw,ctTime,a1,a2) |
---|
991 | String fname,fpath |
---|
992 | WAVE/T tw |
---|
993 | Variable &ctTime,&a1,&a2 |
---|
994 | |
---|
995 | Variable numLinesLoaded = 0,firstchar,refnum |
---|
996 | String buffer ="" |
---|
997 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead |
---|
998 | String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 |
---|
999 | |
---|
1000 | Open/R/P=bt5PathName refNum as fname |
---|
1001 | |
---|
1002 | //read the data until EOF - assuming always a pair or lines |
---|
1003 | do |
---|
1004 | FReadLine refNum, buffer |
---|
1005 | if (strlen(buffer) == 0) |
---|
1006 | break // End of file |
---|
1007 | endif |
---|
1008 | firstChar = char2num(buffer[0]) |
---|
1009 | if ( (firstChar==10) || (firstChar==13) ) |
---|
1010 | break // Hit blank line. End of data in the file. |
---|
1011 | endif |
---|
1012 | |
---|
1013 | tw[numLinesLoaded] = buffer |
---|
1014 | |
---|
1015 | numlinesloaded += 1 |
---|
1016 | while(1) |
---|
1017 | |
---|
1018 | Close refNum // Close the file. |
---|
1019 | |
---|
1020 | //trim the waves to the correct number of points |
---|
1021 | Redimension/N=(numlinesloaded) tw |
---|
1022 | |
---|
1023 | buffer = tw[0] |
---|
1024 | sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8 |
---|
1025 | //v2 is the monitor prefactor. multiply monitor time by prefactor. AJJ 5 March 07 |
---|
1026 | ctTime=v1*v2 |
---|
1027 | |
---|
1028 | buffer = tw[6] |
---|
1029 | sscanf buffer, "%g%g%g%g",v1,v2,v3,v4 |
---|
1030 | a1=v2 |
---|
1031 | a2=v4 |
---|
1032 | |
---|
1033 | return(0) |
---|
1034 | End |
---|
1035 | /////////////////////////////////// |
---|