1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma Version=2.21 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | //******************** |
---|
6 | // 101101 Vers. 1 |
---|
7 | // |
---|
8 | // Main initialization procedures for USANS reduction |
---|
9 | // initializes globals and oflders |
---|
10 | // draws the main panel for user interaction |
---|
11 | // action procedures for the USANS_Panel |
---|
12 | // |
---|
13 | // |
---|
14 | // |
---|
15 | // 09 NOV 04 vers 1.1 |
---|
16 | // - updated dOmega and dQv |
---|
17 | // - write out dQv to 6-column data sets for analysis compatibility |
---|
18 | // |
---|
19 | // |
---|
20 | //******************** |
---|
21 | |
---|
22 | Menu "USANS" |
---|
23 | "USANS Reduction Panel",ShowUSANSPanel() |
---|
24 | "Build USANS Notebook" |
---|
25 | "Desmear USANS Data",Desmear() |
---|
26 | "-" |
---|
27 | "Load USANS Data",A_LoadOneDData() |
---|
28 | "Convert to 6 Columns",Convert3ColTo6Col() |
---|
29 | "-" |
---|
30 | "Feedback or Bug Report",U_OpenTracTicketPage("") |
---|
31 | "Check for Updates",CheckForLatestVersion() |
---|
32 | End |
---|
33 | |
---|
34 | // Bring the USANS_Panel to the front |
---|
35 | // ALWAYS initializes the folders and variables |
---|
36 | // then draws the panel if necessary |
---|
37 | // |
---|
38 | Proc ShowUSANSPanel() |
---|
39 | //version number |
---|
40 | Variable/G root:USANS_RED_VERSION=2.21 //distribution as of Jan 2007 |
---|
41 | |
---|
42 | Init_MainUSANS() |
---|
43 | DoWindow/F USANS_Panel |
---|
44 | if(V_Flag==0) |
---|
45 | USANS_Panel() |
---|
46 | Endif |
---|
47 | End |
---|
48 | |
---|
49 | // initializes the folders and globals for use with the USANS_Panel |
---|
50 | // waves for the listboxes must exist before the panel is drawn |
---|
51 | // "dummy" values for the COR_Graph are set here |
---|
52 | // instrumental constants are set here as well |
---|
53 | // |
---|
54 | Proc Init_MainUSANS() |
---|
55 | NewDataFolder/O root:Packages |
---|
56 | NewDataFolder/O root:Packages:NIST |
---|
57 | NewDataFolder/O root:Packages:NIST:USANS |
---|
58 | NewDataFolder/O root:Packages:NIST:USANS:Globals |
---|
59 | NewDataFolder/O/S root:Packages:NIST:USANS:Globals:MainPanel |
---|
60 | |
---|
61 | String/G root:Packages:NIST:USANS:Globals:gUSANSFolder = "root:Packages:NIST:USANS" |
---|
62 | String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
63 | //NB This is also hardcoded a bit further down - search for "WHY WHY WHY" AJJ Sept 08 |
---|
64 | |
---|
65 | //Preference value to determine if we are outputting XML |
---|
66 | Variable/G root:Packages:NIST:USANS:Globals:gUseXMLOutput = 0 |
---|
67 | |
---|
68 | Make/O/T/N=1 fileWave,samWave,empWave,curWave //Added curWave Sept 06 A. Jackson |
---|
69 | fileWave="" |
---|
70 | samWave="" |
---|
71 | empWave="" |
---|
72 | curWave="" //Added Sept 06 A. Jackson |
---|
73 | //Wave for handling Current Data AJJ Sept 06 |
---|
74 | Make/O/N=1 SAMisCurrent,EMPisCurrent |
---|
75 | SAMisCurrent = 0 |
---|
76 | EMPisCurrent = 0 |
---|
77 | Make/O/T/N=5 statusWave="" |
---|
78 | Make/O/B/U/N=1 selFileW |
---|
79 | Make/O/B/U/N=1 cselFileW |
---|
80 | //for the graph control bar |
---|
81 | Variable/G gTransWide = 1 |
---|
82 | Variable/G gTransRock = 1 |
---|
83 | Variable/G gEmpCts = 0.76 //default values as of 15 DEC 05 J. Barker |
---|
84 | Variable/G gBkgCts = 0.62 //default values as of 15 DEC 05 J. Barker |
---|
85 | Variable/G gThick = 0.1 |
---|
86 | Variable/G gTypeCheck=1 |
---|
87 | Variable/G gTransRatio=1 |
---|
88 | //Text filter for data files AJJ Sept 06 |
---|
89 | String/G FilterStr |
---|
90 | Variable/G gUseCurrentData = 0 |
---|
91 | |
---|
92 | SetDataFolder root: |
---|
93 | |
---|
94 | NewDataFolder/O $(USANSFolder+":RAW") |
---|
95 | NewDataFolder/O $(USANSFolder+":SAM") |
---|
96 | NewDataFolder/O $(USANSFolder+":COR") |
---|
97 | NewDataFolder/O $(USANSFolder+":EMP") |
---|
98 | NewDataFolder/O $(USANSFolder+":BKG") |
---|
99 | NewDataFolder/O $(USANSFolder+":SWAP") |
---|
100 | NewDataFolder/O $(USANSFolder+":Graph") |
---|
101 | |
---|
102 | //dummy waves for bkg and emp levels |
---|
103 | Make/O $(USANSFolder+":EMP:empLevel"),$(USANSFolder+":BKG:bkgLevel") |
---|
104 | //WHY WHY WHY????? |
---|
105 | //Explicit dependency |
---|
106 | root:Packages:NIST:USANS:EMP:empLevel := root:Packages:NIST:USANS:Globals:MainPanel:gEmpCts //dependency to connect to SetVariable in panel |
---|
107 | root:Packages:NIST:USANS:BKG:bkgLevel := root:Packages:NIST:USANS:Globals:MainPanel:gBkgCts |
---|
108 | |
---|
109 | |
---|
110 | //INSTRUMENTAL CONSTANTS |
---|
111 | Variable/G root:Packages:NIST:USANS:Globals:MainPanel:gTheta_H = 3.9e-6 //Darwin FWHM (pre- NOV 2004) |
---|
112 | Variable/G root:Packages:NIST:USANS:Globals:MainPanel:gTheta_V = 0.014 //Vertical divergence (pre- NOV 2004) |
---|
113 | //Variable/G root:Globals:MainPanel:gDomega = 2.7e-7 //Solid angle of detector (pre- NOV 2004) |
---|
114 | Variable/G root:Packages:NIST:USANS:Globals:MainPanel:gDomega = 7.1e-7 //Solid angle of detector (NOV 2004) |
---|
115 | Variable/G root:Packages:NIST:USANS:Globals:MainPanel:gDefaultMCR= 1e6 //factor for normalization |
---|
116 | |
---|
117 | //Variable/G root:Globals:MainPanel:gDQv = 0.037 //divergence, in terms of Q (1/A) (pre- NOV 2004) |
---|
118 | Variable/G root:Packages:NIST:USANS:Globals:MainPanel:gDQv = 0.117 //divergence, in terms of Q (1/A) (NOV 2004) |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | End |
---|
123 | |
---|
124 | //draws the USANS_Panel, the main control panel for the macros |
---|
125 | // |
---|
126 | |
---|
127 | Window USANS_Panel() : Panel |
---|
128 | PauseUpdate; Silent 1 // building window... |
---|
129 | NewPanel /W=(600,44,1015,493)/K=1 as "USANS_Panel" |
---|
130 | SetDrawLayer UserBack |
---|
131 | SetDrawEnv fstyle= 1 |
---|
132 | DrawText 12,53,"Data Files" |
---|
133 | SetDrawEnv fstyle= 1 |
---|
134 | DrawText 157,192,"Empty Scans" |
---|
135 | SetDrawEnv fstyle= 1 |
---|
136 | DrawText 154,54,"Sample Scans" |
---|
137 | DrawLine 6,337,398,337 |
---|
138 | DrawLine 5,33,393,33 |
---|
139 | SetDrawEnv fstyle= 1 |
---|
140 | DrawText 140,357,"Raw Data Header" |
---|
141 | SetDrawEnv fstyle= 1 |
---|
142 | DrawText 293,55,"Current Data" |
---|
143 | ListBox fileLB,pos={5,55},size={110,230},proc=FileListBoxProc |
---|
144 | ListBox fileLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:fileWave |
---|
145 | ListBox fileLB,selWave=root:Packages:NIST:USANS:Globals:MainPanel:selFileW,mode= 4 |
---|
146 | ListBox samLB,pos={149,55},size={110,90},listWave=root:Packages:NIST:USANS:Globals:MainPanel:samWave |
---|
147 | ListBox samLB,mode= 1,selRow= -1 |
---|
148 | Button ClearSamButton,pos={224,148},size={35,21},proc=ClearButtonProc,title="Clr" |
---|
149 | Button ClearSamButton,help={"Clears the list of sample scans"} |
---|
150 | Button ClearEmpButton,pos={227,286},size={35,20},proc=ClearButtonProc,title="Clr" |
---|
151 | Button ClearEmpButton,help={"Clears the list of empty scans"} |
---|
152 | Button RefreshButton,pos={9,310},size={104,20},proc=RefreshListButtonProc,title="Refresh" |
---|
153 | Button RefreshButton,help={"Refreshes the list of raw ICP data files"} |
---|
154 | Button DelSamButton,pos={186,148},size={35,20},proc=DelSamButtonProc,title="Del" |
---|
155 | Button DelSamButton,help={"Deletes the selected file(s) from the list of sample scans"} |
---|
156 | Button DelEmpButton,pos={190,286},size={35,20},proc=DelEmpButtonProc,title="Del" |
---|
157 | Button DelEmpButton,help={"Deletes the selected file(s) from the list of empty scans"} |
---|
158 | ListBox empLB,pos={151,194},size={110,90} |
---|
159 | ListBox empLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:empWave,mode= 1,selRow= 0 |
---|
160 | Button toSamList,pos={118,55},size={25,90},proc=toSamListButtonProc,title="S->" |
---|
161 | Button toSamList,help={"Adds the selected file(s) to the list of sample scans"} |
---|
162 | Button toEmpList,pos={120,195},size={25,90},proc=toEmptyListButtonProc,title="E->" |
---|
163 | Button toEmpList,help={"Adds the selected file(s) to the list of empty (cell) scans"} |
---|
164 | ListBox StatusLB,pos={11,358},size={386,77} |
---|
165 | ListBox StatusLB,listWave=root:Packages:NIST:USANS:Globals:MainPanel:statusWave |
---|
166 | Button pickPathButton,pos={6,8},size={80,20},proc=PickBT5PathButton,title="DataPath..." |
---|
167 | Button pickPathButton,help={"Select the data folder where the raw ICP data files are located"} |
---|
168 | Button PlotSelectedSAMButton,pos={148,148},size={35,20},proc=PlotSelectedSAMButtonProc,title="Plot" |
---|
169 | Button PlotSelectedSAMButton,help={"Plot the selected sample scattering files in the COR_Graph"} |
---|
170 | Button PlotSelectedEMPButton,pos={152,286},size={35,20},proc=PlotSelectedEMPButtonProc,title="Plot" |
---|
171 | Button PlotSelectedEMPButton,help={"Plot the selected empty cell scattering files in the COR_Graph"} |
---|
172 | Button pickSavePathButton,pos={97,8},size={80,20},proc=PickSaveButtonProc,title="SavePath..." |
---|
173 | Button pickSavePathButton,help={"Select the data folder where data is to be saved to disk"} |
---|
174 | Button USANSHelpButton,pos={341,6},size={50,20},proc=USANSHelpButtonProc,title="Help" |
---|
175 | Button USANSHelpButton,help={"Show the USANS reduction help file"} |
---|
176 | Button RefreshCurrent,pos={298,310},size={95,20},proc=RefreshCurrentButtonProc,title="Refresh",disable=2 |
---|
177 | Button RefreshCurrent,help={"Updates data files on Charlotte and gets current data file name"} |
---|
178 | Button AddCurToSAM,pos={264,55},size={25,90},proc=CurtoSamListButtonProc,title="<-S",disable=2 |
---|
179 | Button AddCurToSAM,help={"Adds the current data file to the list of sample scans"} |
---|
180 | Button AddCurToEMP,pos={265,194},size={25,90},proc=CurtoEmptyListButtonProc,title="<-E",disable=2 |
---|
181 | Button AddCurToEMP,help={"Adds the current data file to the list of empty scans"} |
---|
182 | ListBox CurFileBox,pos={295,55},size={100,230},proc=FileListBoxProc,disable=1 |
---|
183 | ListBox CurFileBox,listWave=root:Packages:NIST:USANS:Globals:MainPanel:curWave,mode=1 |
---|
184 | SetVariable FilterSetVar,pos={8,289},size={106,18},title="Filter",fSize=12 |
---|
185 | SetVariable FilterSetVar,value= root:Packages:NIST:USANS:Globals:MainPanel:FilterStr |
---|
186 | CheckBox UseCurrentData,pos={298,290},size={10,10},proc=UseCurrentDataProc,title="Enable Current Data" |
---|
187 | CheckBox UseCurrentData,value=0 |
---|
188 | Button USANSFeedback,pos={220,6},size={100,20},proc=U_OpenTracTicketPage,title="Feedback" |
---|
189 | |
---|
190 | EndMacro |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | //draws a simple graph of the monitor counts, transmission counts, and detector counts |
---|
195 | // plots the selected raw data file when "plot raw" is selected from the USANS_Panel |
---|
196 | // |
---|
197 | Proc GraphRawData() |
---|
198 | PauseUpdate; Silent 1 // building window... |
---|
199 | String fldrSav= GetDataFolder(1) |
---|
200 | String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
201 | SetDataFolder $(USANSFolder+":RAW:") |
---|
202 | //String textStr = StringForRawGraph() |
---|
203 | //textStr=StringByKey("FILE",textStr,":",";")+" MONRATE:"+num2str(mean(MonCts)/NumberByKey("TIMEPT",textStr,":",";")) |
---|
204 | Display /W=(600,525,1015,850)/L=left1/B=bottom1 /K=1 DetCts vs Angle as "Raw Data" |
---|
205 | ModifyGraph margin(top)=50 |
---|
206 | //Display /W=(600,525,1015,850) /K=1 DetCts vs Angle as "Raw Data" |
---|
207 | DoWindow/C RawDataWin |
---|
208 | //AppendToGraph/L=left1 /B=bottom1 DetCts vs Angle |
---|
209 | AppendToGraph/L=left2/B=bottom1 TransCts vs Angle |
---|
210 | AppendToGraph/L=left3/B=bottom1 MonCts vs Angle |
---|
211 | SetAxis/A/N=2 left1 |
---|
212 | SetAxis/A/N=2 left2 |
---|
213 | SetAxis/A/N=2 left3 |
---|
214 | ModifyGraph mode=4, marker=19 |
---|
215 | ModifyGraph rgb(TransCts)=(1,4,52428),rgb(MonCts)=(1,39321,19939) |
---|
216 | ModifyGraph msize=1,grid=1,mirror=2,standoff=1,lblPos=50,tickUnit=1,notation=1,freePos={0.1,kwFraction} |
---|
217 | ModifyGraph nticks(left2)=2 |
---|
218 | ModifyGraph nticks(left3)=2 |
---|
219 | ModifyGraph mirror(bottom1)=0 |
---|
220 | ModifyGraph axisEnab(left1)={0.1,0.5},gridEnab(left1)={0.1,1} |
---|
221 | ModifyGraph axisEnab(left2)={0.57,0.77},gridEnab(left2)={0.1,1} |
---|
222 | ModifyGraph axisEnab(left3)={0.8,1},gridEnab={0.1,1} |
---|
223 | ModifyGraph axisEnab(bottom1)={0.1,1},gridEnab(bottom1)={0.1,1} |
---|
224 | ErrorBars/T=0 DetCts Y,wave=(ErrDetCts,ErrDetCts) |
---|
225 | TextBox/F=0/E=2/A=MB/Y=2/N=text1 "Angle" |
---|
226 | TextBox/F=0/O=90/E=2/A=LC/X=2/N=text2 "Counts" |
---|
227 | //TextBox/N=text1/A=RC/X=0.50/Y=-2 textStr |
---|
228 | //Label bottom1 "Angle (degrees)" |
---|
229 | Label left1 " " |
---|
230 | Label left2 " " |
---|
231 | Label left3 " " |
---|
232 | TitleForRawGraph() |
---|
233 | SetDataFolder fldrSav |
---|
234 | End |
---|
235 | |
---|
236 | // plots the selected EMP files onto the COR_Graph |
---|
237 | // Does the following: |
---|
238 | // - loads raw data |
---|
239 | // - normalizes counts to time and 1E6 monitor counts |
---|
240 | // sorts by angle |
---|
241 | // finds zero angle (and peak height) |
---|
242 | // converts to q-values |
---|
243 | // finds T wide |
---|
244 | // updates the graph |
---|
245 | // |
---|
246 | Function PlotSelectedEMPButtonProc(ctrlName) : ButtonControl |
---|
247 | String ctrlName |
---|
248 | |
---|
249 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
250 | |
---|
251 | //get selected files from listbox (everything) |
---|
252 | //use the listBox wave directly |
---|
253 | Wave/T listW=$(USANSFolder+":Globals:MainPanel:empWave") |
---|
254 | //Wave for indication of current data set AJJ Sept 2006 |
---|
255 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
256 | Variable ii,num=numpnts(listW) |
---|
257 | String fname="",fpath="",curPathStr="" |
---|
258 | PathInfo bt5PathName |
---|
259 | fpath = S_Path |
---|
260 | PathInfo bt5CurPathName |
---|
261 | curPathStr = S_Path |
---|
262 | |
---|
263 | if(cmpstr("",listW[0])==0) |
---|
264 | return(0) //null item in 1st position, exit |
---|
265 | Endif |
---|
266 | |
---|
267 | //load, normalize, and append |
---|
268 | //loop over the number of items in the list |
---|
269 | for(ii=0;ii<num;ii+=1) |
---|
270 | |
---|
271 | //Check to see if file is current data set AJJ Sept 06 |
---|
272 | if (isCurrent[ii] == 1) |
---|
273 | fname = curPathStr + listw[ii] |
---|
274 | else |
---|
275 | fname = fpath + listw[ii] |
---|
276 | endif |
---|
277 | |
---|
278 | |
---|
279 | LoadBT5File(fname,"SWAP") //overwrite what's in the SWAP folder |
---|
280 | Convert2Countrate("SWAP") |
---|
281 | if(ii==0) //first time, overwrite |
---|
282 | NewDataWaves("SWAP","EMP") |
---|
283 | else //append to waves in "EMP" |
---|
284 | AppendDataWaves("SWAP","EMP") |
---|
285 | endif |
---|
286 | endfor |
---|
287 | //sort after all loaded |
---|
288 | DoAngleSort("EMP") |
---|
289 | |
---|
290 | //find the peak and convert to Q-values |
---|
291 | Variable zeroAngle = FindZeroAngle("EMP") |
---|
292 | if(zeroAngle == -9999) |
---|
293 | DoAlert 0,"Couldn't find a peak - using zero as zero angle" |
---|
294 | zeroAngle = 0 |
---|
295 | Endif |
---|
296 | ConvertAngle2Qvals("EMP",zeroAngle) |
---|
297 | |
---|
298 | //find the Trans Cts for T_Wide |
---|
299 | FindTWideCts("EMP") |
---|
300 | |
---|
301 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
302 | if(WaveExists($(USANSFolder+":EMP:Qvals"))) |
---|
303 | Duplicate/O $(USANSFolder+":EMP:Qvals"),$(USANSFolder+":Graph:Qvals_EMP") |
---|
304 | Endif |
---|
305 | Duplicate/O $(USANSFolder+":EMP:Angle"),$(USANSFolder+":Graph:Angle_EMP") |
---|
306 | Duplicate/O $(USANSFolder+":EMP:DetCts"),$(USANSFolder+":Graph:DetCts_EMP") |
---|
307 | Duplicate/O $(USANSFolder+":EMP:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_EMP") |
---|
308 | |
---|
309 | //now plot the data (or just bring the graph to the front) |
---|
310 | DoCORGraph() |
---|
311 | End |
---|
312 | |
---|
313 | // plots the selected SAM files onto the COR_Graph |
---|
314 | // Does the following: |
---|
315 | // - loads raw data |
---|
316 | // - normalizes counts to time and 1E6 monitor counts |
---|
317 | // sorts by angle |
---|
318 | // finds zero angle (and peak height) |
---|
319 | // converts to q-values |
---|
320 | // finds T wide |
---|
321 | // updates the graph |
---|
322 | // |
---|
323 | Function PlotSelectedSAMButtonProc(ctrlName) : ButtonControl |
---|
324 | String ctrlName |
---|
325 | |
---|
326 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
327 | |
---|
328 | //get selected files from listbox (everything) |
---|
329 | //use the listBox wave directly |
---|
330 | Wave/T listW=$(USANSFolder+":Globals:MainPanel:samWave") |
---|
331 | //Wave for indication of current data set AJJ Sept 2006 |
---|
332 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
333 | Variable ii,num=numpnts(listW) |
---|
334 | String fname="",fpath="",curPathStr="" |
---|
335 | PathInfo bt5PathName |
---|
336 | fpath = S_Path |
---|
337 | PathInfo bt5CurPathName |
---|
338 | curPathStr = S_Path |
---|
339 | |
---|
340 | print fpath |
---|
341 | |
---|
342 | if(cmpstr("",listW[0])==0) |
---|
343 | return(0) //null item in 1st position, exit |
---|
344 | Endif |
---|
345 | |
---|
346 | //load, normalize, and append |
---|
347 | //loop over the number of items in the list |
---|
348 | for(ii=0;ii<num;ii+=1) |
---|
349 | fname = fpath + listw[ii] |
---|
350 | |
---|
351 | //Check to see if file is current data set AJJ Sept 06 |
---|
352 | if (isCurrent[ii] == 1) |
---|
353 | fname = curPathStr + listw[ii] |
---|
354 | else |
---|
355 | fname = fpath + listw[ii] |
---|
356 | endif |
---|
357 | |
---|
358 | LoadBT5File(fname,"SWAP") //overwrite what's in the SWAP folder |
---|
359 | Convert2Countrate("SWAP") |
---|
360 | if(ii==0) //first time, overwrite |
---|
361 | NewDataWaves("SWAP","SAM") |
---|
362 | else //append to waves in "SAM" |
---|
363 | AppendDataWaves("SWAP","SAM") |
---|
364 | endif |
---|
365 | endfor |
---|
366 | //sort after all loaded |
---|
367 | DoAngleSort("SAM") |
---|
368 | |
---|
369 | //find the peak and convert to Q-values |
---|
370 | Variable zeroAngle = FindZeroAngle("SAM") |
---|
371 | if(zeroAngle == -9999) |
---|
372 | DoAlert 0,"Couldn't find a peak - using zero as zero angle" |
---|
373 | zeroAngle = 0 |
---|
374 | Endif |
---|
375 | ConvertAngle2Qvals("SAM",zeroAngle) |
---|
376 | //find the Trans Cts for T_Wide |
---|
377 | FindTWideCts("SAM") |
---|
378 | // |
---|
379 | //copy the data to plot to the root:Graph directory, and give clear names |
---|
380 | if(WaveExists($(USANSFolder+":SAM:Qvals"))) |
---|
381 | Duplicate/O $(USANSFolder+":SAM:Qvals"),$(USANSFolder+":Graph:Qvals_SAM") |
---|
382 | Endif |
---|
383 | Duplicate/O $(USANSFolder+":SAM:Angle"),$(USANSFolder+":Graph:Angle_SAM") |
---|
384 | Duplicate/O $(USANSFolder+":SAM:DetCts"),$(USANSFolder+":Graph:DetCts_SAM") |
---|
385 | Duplicate/O $(USANSFolder+":SAM:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_SAM") |
---|
386 | |
---|
387 | //now plot the data (or just bring the graph to the front) |
---|
388 | DoCORGraph() |
---|
389 | End |
---|
390 | |
---|
391 | //sort the data in the "type"folder, based on angle |
---|
392 | //carry along all associated waves |
---|
393 | // |
---|
394 | Function DoAngleSort(type) |
---|
395 | String type |
---|
396 | |
---|
397 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
398 | |
---|
399 | Wave angle = $(USANSFolder+":"+Type+":Angle") |
---|
400 | Wave detCts = $(USANSFolder+":"+Type+":DetCts") |
---|
401 | Wave ErrdetCts = $(USANSFolder+":"+Type+":ErrDetCts") |
---|
402 | Wave MonCts = $(USANSFolder+":"+Type+":MonCts") |
---|
403 | Wave TransCts = $(USANSFolder+":"+Type+":TransCts") |
---|
404 | |
---|
405 | Sort Angle DetCts,ErrDetCts,MonCts,TransCts,Angle |
---|
406 | return(0) |
---|
407 | End |
---|
408 | |
---|
409 | // converts to countrate per 1E6 monitor counts (default value) |
---|
410 | // by dividing by the counting time (reported in header in seconds per point) |
---|
411 | // and the globally defined monitor count |
---|
412 | // |
---|
413 | // works on data in "type" folder |
---|
414 | // |
---|
415 | // note that trans detector counts are NOT normalized to 1E6 mon cts (not necessary) |
---|
416 | // |
---|
417 | Function Convert2Countrate(type) |
---|
418 | String type |
---|
419 | |
---|
420 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
421 | |
---|
422 | String noteStr = note($(USANSFolder+":"+Type+":DetCts")) |
---|
423 | Variable ctTime |
---|
424 | ctTime = NumberByKey("TIMEPT",noteStr,":",";") |
---|
425 | print ctTime |
---|
426 | //normalize by counting time |
---|
427 | Wave detCts = $(USANSFolder+":"+Type+":DetCts") |
---|
428 | Wave ErrdetCts = $(USANSFolder+":"+Type+":ErrDetCts") |
---|
429 | Wave MonCts = $(USANSFolder+":"+Type+":MonCts") |
---|
430 | Wave TransCts = $(USANSFolder+":"+Type+":TransCts") |
---|
431 | |
---|
432 | detCts /= ctTime |
---|
433 | ErrDetCts /= ctTime |
---|
434 | MonCts /= ctTime |
---|
435 | TransCts /= ctTime |
---|
436 | |
---|
437 | //normalize to monitor countrate [=] counts/monitor |
---|
438 | //trans countrate does not need to be normalized |
---|
439 | NVAR defaultMCR=$(USANSFolder+":Globals:MainPanel:gDefaultMCR") |
---|
440 | DetCts /= monCts/defaultMCR |
---|
441 | ErrDetCts /= MonCts/defaultMCR |
---|
442 | |
---|
443 | //adjust the note (now on basis of 1 second) |
---|
444 | ctTime = 1 |
---|
445 | noteStr = ReplaceNumberByKey("TIMEPT",noteStr,ctTime,":",";") |
---|
446 | Note/K detCts |
---|
447 | Note detCts,noteStr |
---|
448 | |
---|
449 | return(0) |
---|
450 | End |
---|
451 | |
---|
452 | |
---|
453 | // copies data from one folder to another |
---|
454 | // |
---|
455 | // used for the first set, simply obliterate the old waves in the folder |
---|
456 | // |
---|
457 | Function NewDataWaves(fromType,toType) |
---|
458 | String fromType,toType |
---|
459 | |
---|
460 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
461 | |
---|
462 | Duplicate/O $(USANSFolder+":"+fromType+":Angle"),$(USANSFolder+":"+toType+":Angle") |
---|
463 | Duplicate/O $(USANSFolder+":"+fromType+":DetCts"),$(USANSFolder+":"+toType+":DetCts") |
---|
464 | Duplicate/O $(USANSFolder+":"+fromType+":ErrDetCts"),$(USANSFolder+":"+toType+":ErrDetCts") |
---|
465 | Duplicate/O $(USANSFolder+":"+fromType+":MonCts"),$(USANSFolder+":"+toType+":MonCts") |
---|
466 | Duplicate/O $(USANSFolder+":"+fromType+":TransCts"),$(USANSFolder+":"+toType+":TransCts") |
---|
467 | |
---|
468 | //check for qvals wave, move if it's there |
---|
469 | if(WaveExists($(USANSFolder+":"+fromType+":Qvals"))) |
---|
470 | Duplicate/O $(USANSFolder+":"+fromType+":Qvals"),$(USANSFolder+":"+toType+":Qvals") |
---|
471 | Endif |
---|
472 | |
---|
473 | End |
---|
474 | |
---|
475 | //to add additional data to a folder, need to concatenate the data in the waves |
---|
476 | //and need to update the wave note associated with "DetCts" to include the additional file |
---|
477 | // |
---|
478 | Function AppendDataWaves(fromType,toType) |
---|
479 | String fromType,toType |
---|
480 | |
---|
481 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
482 | |
---|
483 | String fromNote="",toNote="",newNote="",fromfile="",toFile="" |
---|
484 | |
---|
485 | |
---|
486 | ConcatenateData( (USANSFolder+":"+toType+":Angle"),(USANSFolder+":"+fromType+":Angle") ) //appends "from" at the end of "to" |
---|
487 | ConcatenateData( (USANSFolder+":"+toType+":DetCts"),(USANSFolder+":"+fromType+":DetCts") ) |
---|
488 | ConcatenateData( (USANSFolder+":"+toType+":ErrDetCts"),(USANSFolder+":"+fromType+":ErrDetCts") ) |
---|
489 | ConcatenateData( (USANSFolder+":"+toType+":MonCts"),(USANSFolder+":"+fromType+":MonCts") ) |
---|
490 | ConcatenateData( (USANSFolder+":"+toType+":TransCts"),(USANSFolder+":"+fromType+":TransCts") ) |
---|
491 | |
---|
492 | |
---|
493 | //adjust the wavenote, to account for the new dataset |
---|
494 | fromNote = note($(USANSFolder+":"+fromType+":DetCts")) |
---|
495 | fromFile = StringByKey("FILE",fromNote,":",";") |
---|
496 | toNote = note($(USANSFolder+":"+toType+":DetCts")) |
---|
497 | toFile = StringByKey("FILE",toNote,":",";") |
---|
498 | toFile += "," + fromfile |
---|
499 | toNote = ReplaceStringByKey("FILE",toNote,toFile,":",";") |
---|
500 | Note/K $(USANSFolder+":"+toType+":DetCts") |
---|
501 | Note $(USANSFolder+":"+toType+":DetCts"),toNote |
---|
502 | |
---|
503 | Return(0) |
---|
504 | End |
---|
505 | |
---|
506 | // action procedure to select the raw data path where the bt5 files are located |
---|
507 | // |
---|
508 | Function PickBT5PathButton(PathButton) : ButtonControl |
---|
509 | String PathButton |
---|
510 | |
---|
511 | //Print "DataPathButton Proc" |
---|
512 | Variable err = PickBT5Path() //=1 if error |
---|
513 | |
---|
514 | End |
---|
515 | |
---|
516 | //pick the data folder to save the data to - in general must be a local disk, not the ICP database.... |
---|
517 | // |
---|
518 | Function PickSaveButtonProc(ctrlName) : ButtonControl |
---|
519 | String ctrlName |
---|
520 | |
---|
521 | NewPath/O/M="SAVE data to the selected folder" savePathName |
---|
522 | PathInfo/S savePathName |
---|
523 | String dum = S_path |
---|
524 | if (V_flag == 0) |
---|
525 | return(1) |
---|
526 | else |
---|
527 | return(0) //no error |
---|
528 | endif |
---|
529 | End |
---|
530 | |
---|
531 | // Show the help file, don't necessarily keep it with the experiment (/K=1) |
---|
532 | Function USANSHelpButtonProc(ctrlName) : ButtonControl |
---|
533 | String ctrlName |
---|
534 | |
---|
535 | DisplayHelpTopic/Z/K=1 "USANS Data Reduction" |
---|
536 | if(V_flag !=0) |
---|
537 | DoAlert 0,"The USANS Data Reduction Help file could not be found" |
---|
538 | endif |
---|
539 | return(0) |
---|
540 | End |
---|
541 | |
---|
542 | //prompts user to choose the local folder that contains the BT5 Data |
---|
543 | //only one folder can be used, and its path is bt5PathName (and is a NAME, not a string) |
---|
544 | //this will overwrite the path selection |
---|
545 | //returns 1 if no path selected as error condition |
---|
546 | Function PickBT5Path() |
---|
547 | |
---|
548 | NVAR isChecked = root:Packages:NIST:USANS:Globals:MainPanel:gUseCurrentData |
---|
549 | |
---|
550 | //set the global string to the selected pathname |
---|
551 | NewPath/O/M="pick the BT5 data folder" bt5PathName |
---|
552 | PathInfo/S bt5PathName |
---|
553 | String dum = S_path |
---|
554 | if (V_flag == 0) |
---|
555 | //Path does not exist |
---|
556 | return(1) |
---|
557 | else |
---|
558 | if (isChecked == 1) |
---|
559 | NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path) |
---|
560 | return(0) //no error |
---|
561 | Endif |
---|
562 | endif |
---|
563 | End |
---|
564 | |
---|
565 | //action procedure to load and plot a raw data file |
---|
566 | // loads the data based on selected file and bt5pathname |
---|
567 | // draws a new graph if necessary |
---|
568 | // otherwise just updates the data |
---|
569 | // |
---|
570 | Function PlotRawButtonProc(ctrlName) : ButtonControl |
---|
571 | String ctrlName |
---|
572 | |
---|
573 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
574 | |
---|
575 | String fname="" |
---|
576 | |
---|
577 | if (cmpstr(ctrlName,"FileLB") == 0) |
---|
578 | //Print "PlotRaw Button" |
---|
579 | //take the selection, and simply plot the counts vs. angle - don't save the data anyplace special |
---|
580 | //get the selected wave |
---|
581 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") |
---|
582 | Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") |
---|
583 | Variable ii=0,num=numpnts(sel),err |
---|
584 | |
---|
585 | |
---|
586 | PathInfo bt5PathName |
---|
587 | fname = S_Path |
---|
588 | do |
---|
589 | if(sel[ii] == 1) |
---|
590 | fname+=filewave[ii] |
---|
591 | break |
---|
592 | endif |
---|
593 | ii+=1 |
---|
594 | while(ii<num) |
---|
595 | elseif (cmpstr(ctrlName,"CurFileBox" )== 0) |
---|
596 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave") |
---|
597 | PathInfo bt5CurPathName |
---|
598 | fname = S_Path |
---|
599 | fname+=filewave[0] |
---|
600 | endif |
---|
601 | //Print fname |
---|
602 | err = LoadBT5File(fname,"RAW") |
---|
603 | if(err) |
---|
604 | return(err) |
---|
605 | endif |
---|
606 | //if the "Raw Data" Graph exists, do nothing - else draw it |
---|
607 | //DoWindow/F RawDataWin |
---|
608 | if(WinType("RawDataWin")!=1) |
---|
609 | Execute "GraphRawData()" |
---|
610 | else |
---|
611 | //just update the textbox |
---|
612 | //String textStr=StringForRawGraph() |
---|
613 | //TextBox/W=RawDataWin/C/N=text1/A=RC/X=0.50/Y=-2 textStr |
---|
614 | //TextBox/W=RawDataWin/C/E=2/A=MT/X=0/Y=0/N=text0 textStr |
---|
615 | TitleForRawGraph() |
---|
616 | Endif |
---|
617 | //bring the panel back to the front |
---|
618 | DoWindow/F USANS_Panel |
---|
619 | End |
---|
620 | |
---|
621 | // action procedure for the raw data listbox |
---|
622 | // responds to selection or (shift)selection events |
---|
623 | // by acting if the "status" button was pressed |
---|
624 | //(note that the status button is obsolete and not drawn on the USANS_Panel, but |
---|
625 | // I kept the nomenclature) |
---|
626 | // |
---|
627 | Function FileListBoxProc(ctrlName,row,col,event) |
---|
628 | String ctrlName |
---|
629 | Variable row,col,event |
---|
630 | |
---|
631 | if (cmpstr(ctrlName, "fileLB") == 0) |
---|
632 | //event == 4 is a selection |
---|
633 | //event == 5 is a selection + shift key |
---|
634 | if( (event==4) || (event==5) ) |
---|
635 | StatusButtonProc(ctrlName) //act as if status button was pressed |
---|
636 | PlotRawButtonProc(ctrlName) //automatically plots the raw data |
---|
637 | Endif |
---|
638 | return(0) |
---|
639 | elseif (cmpstr(ctrlName,"CurFileBox") == 0) |
---|
640 | //print "Selected current data" |
---|
641 | if (event == 4) |
---|
642 | StatusButtonProc(ctrlName) |
---|
643 | PlotRawButtonProc(ctrlName) |
---|
644 | endif |
---|
645 | return(0) |
---|
646 | endif |
---|
647 | return(1) |
---|
648 | End |
---|
649 | |
---|
650 | // displays the status of the selected file in the raw data file list box |
---|
651 | // - spits the information out to a second listbox |
---|
652 | // - called automatically as an action when there is a selection in the file listbox |
---|
653 | // not used as a button procedure anymore |
---|
654 | // |
---|
655 | Function StatusButtonProc(ctrlName) |
---|
656 | String ctrlName |
---|
657 | |
---|
658 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
659 | |
---|
660 | String fname="" |
---|
661 | |
---|
662 | |
---|
663 | if(cmpstr(ctrlName,"fileLB")==0) |
---|
664 | //Print "Status Button" |
---|
665 | //display the (first) selected wave |
---|
666 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") |
---|
667 | Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") |
---|
668 | Variable ii=0,num=numpnts(sel) |
---|
669 | |
---|
670 | PathInfo bt5PathName |
---|
671 | fname = S_Path |
---|
672 | do |
---|
673 | if(sel[ii] == 1) |
---|
674 | fname+=filewave[ii] |
---|
675 | break |
---|
676 | endif |
---|
677 | ii+=1 |
---|
678 | while(ii<num) |
---|
679 | elseif(cmpstr(ctrlName,"CurFileBox")==0) |
---|
680 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:curWave") |
---|
681 | PathInfo bt5CurPathName |
---|
682 | fname = S_Path |
---|
683 | fname+=filewave[0] |
---|
684 | endif |
---|
685 | //Print fname |
---|
686 | ReadBT5Header(fname) |
---|
687 | End |
---|
688 | |
---|
689 | // copies the selected files from the raw file list box to the sam file listbox |
---|
690 | // |
---|
691 | // makes sure that any null items are removed from the wave attached to the listbox |
---|
692 | // |
---|
693 | Function toSamListButtonProc(ctrlName) : ButtonControl |
---|
694 | String ctrlName |
---|
695 | |
---|
696 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
697 | |
---|
698 | //Print "toSamList button" |
---|
699 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") |
---|
700 | Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave") |
---|
701 | Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") |
---|
702 | //Wave to indicate Current status |
---|
703 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
704 | |
---|
705 | |
---|
706 | Variable num=numpnts(sel),ii=0 |
---|
707 | variable lastPt=numpnts(samWave) |
---|
708 | do |
---|
709 | if(sel[ii] == 1) |
---|
710 | InsertPoints lastPt,1, samWave |
---|
711 | samWave[lastPt]=filewave[ii] |
---|
712 | InsertPoints lastPt, 1, isCurrent |
---|
713 | isCurrent[lastPt] = 0 |
---|
714 | lastPt +=1 |
---|
715 | endif |
---|
716 | ii+=1 |
---|
717 | while(ii<num) |
---|
718 | |
---|
719 | //clean out any (null) elements |
---|
720 | num=numpnts(samwave) |
---|
721 | for(ii=0;ii<num;ii+=1) |
---|
722 | if(cmpstr(samWave[ii],"") ==0) |
---|
723 | DeletePoints ii,1,samWave |
---|
724 | DeletePoints ii,1,isCurrent |
---|
725 | num -= 1 |
---|
726 | Endif |
---|
727 | Endfor |
---|
728 | |
---|
729 | return(0) |
---|
730 | End |
---|
731 | |
---|
732 | // copies the selected files from the raw file list box to the sam file listbox |
---|
733 | // |
---|
734 | // makes sure that any null items are removed from the wave attached to the listbox |
---|
735 | // |
---|
736 | Function toEmptyListButtonProc(ctrlName) : ButtonControl |
---|
737 | String ctrlName |
---|
738 | |
---|
739 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
740 | |
---|
741 | //Print "toEmptyList button" |
---|
742 | Wave/T fileWave=$(USANSFolder+":Globals:MainPanel:fileWave") |
---|
743 | Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave") |
---|
744 | Wave sel=$(USANSFolder+":Globals:MainPanel:selFileW") |
---|
745 | //Wave to indicate Current status |
---|
746 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
747 | |
---|
748 | |
---|
749 | |
---|
750 | Variable num=numpnts(sel),ii=0 |
---|
751 | variable lastPt=numpnts(empWave) |
---|
752 | do |
---|
753 | if(sel[ii] == 1) |
---|
754 | InsertPoints lastPt,1, empWave |
---|
755 | empWave[lastPt]=filewave[ii] |
---|
756 | InsertPoints lastPt, 1, isCurrent |
---|
757 | isCurrent[lastPt] = 0 |
---|
758 | lastPt +=1 |
---|
759 | endif |
---|
760 | ii+=1 |
---|
761 | while(ii<num) |
---|
762 | |
---|
763 | //clean out any (null) elements |
---|
764 | num=numpnts(empwave) |
---|
765 | for(ii=0;ii<num;ii+=1) |
---|
766 | if(cmpstr(empWave[ii],"") ==0) |
---|
767 | DeletePoints ii,1,empWave |
---|
768 | DeletePoints ii,1,isCurrent |
---|
769 | num -= 1 |
---|
770 | Endif |
---|
771 | Endfor |
---|
772 | |
---|
773 | return(0) |
---|
774 | End |
---|
775 | |
---|
776 | //deletes the selected file from the sam list |
---|
777 | // multiple selections are not allowed |
---|
778 | // the cor_graph is not updated |
---|
779 | // |
---|
780 | Function DelSamButtonProc(ctrlName) : ButtonControl |
---|
781 | String ctrlName |
---|
782 | |
---|
783 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
784 | |
---|
785 | ControlInfo SamLB |
---|
786 | Variable selRow=V_Value |
---|
787 | Wave lw=$(S_DataFolder + S_Value) |
---|
788 | DeletePoints selRow,1,lw |
---|
789 | //Clear out current flag AJJ Sept O6 |
---|
790 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
791 | DeletePoints selRow, 1, isCurrent |
---|
792 | End |
---|
793 | |
---|
794 | //deletes the selected file from the emp list |
---|
795 | // multiple selections are not allowed |
---|
796 | // the cor_graph is not updated |
---|
797 | // |
---|
798 | Function DelEmpButtonProc(ctrlName) : ButtonControl |
---|
799 | String ctrlName |
---|
800 | |
---|
801 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
802 | |
---|
803 | ControlInfo EmpLB |
---|
804 | Variable selRow=V_Value |
---|
805 | Wave lw=$(S_DataFolder + S_Value) |
---|
806 | DeletePoints selRow,1,lw |
---|
807 | //Clear out current flag AJJ Sept O6 |
---|
808 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
809 | DeletePoints selRow, 1, isCurrent |
---|
810 | End |
---|
811 | |
---|
812 | //refreshes the file list presented in the raw data file listbox |
---|
813 | //bt5PathName is hard-wired in, will prompt if none exists |
---|
814 | // reads directly from disk |
---|
815 | // |
---|
816 | // EXCLUDES all files that do not match "*.bt5*" (not case sensitive) |
---|
817 | // |
---|
818 | // sorts the list to alphabetical order |
---|
819 | // |
---|
820 | Function RefreshListButtonProc(ctrlName) : ButtonControl |
---|
821 | String ctrlName |
---|
822 | |
---|
823 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
824 | |
---|
825 | SVAR FilterStr = $(USANSFolder+":Globals:MainPanel:FilterStr") |
---|
826 | print FilterStr |
---|
827 | String filter |
---|
828 | |
---|
829 | //check for path and force user to pick a path |
---|
830 | do |
---|
831 | PathInfo bt5PathName |
---|
832 | if(V_Flag) |
---|
833 | break |
---|
834 | Endif |
---|
835 | PickBT5Path() |
---|
836 | while(V_Flag==0) |
---|
837 | |
---|
838 | //Get the filter and determine the match string required AJJ Sept06 |
---|
839 | if (stringmatch(FilterStr,"!")) |
---|
840 | filter = FilterStr+"*.bt5*" |
---|
841 | else |
---|
842 | filter = "*.bt5*" |
---|
843 | endif |
---|
844 | |
---|
845 | //get all the files, then trim the list |
---|
846 | String list=IndexedFile(bt5PathName,-1,"????") |
---|
847 | String newList="",item="" |
---|
848 | Variable num=ItemsInList(list,";"),ii |
---|
849 | for(ii=0;ii<num;ii+=1) |
---|
850 | item = StringFromList(ii, list ,";") |
---|
851 | |
---|
852 | if( stringmatch(item,filter) ) //ONLY keep files that match the filter + *.bt5 AJJ Sept 06 |
---|
853 | newlist += item + ";" |
---|
854 | endif |
---|
855 | //print "ii=",ii |
---|
856 | endfor |
---|
857 | newList = SortList(newList,";",0) //get them in order |
---|
858 | num=ItemsInList(newlist,";") |
---|
859 | Wave/T fileWave = $(USANSFolder+":Globals:MainPanel:fileWave") |
---|
860 | Wave selFileW = $(USANSFolder+":Globals:MainPanel:selFileW") |
---|
861 | Redimension/N=(num) fileWave |
---|
862 | Redimension/N=(num) selFileW |
---|
863 | fileWave="" |
---|
864 | selFileW = 0 |
---|
865 | fileWave = StringFromList(p,newlist,";") // ! quick and easy assignment of the list |
---|
866 | Sort filewave,filewave |
---|
867 | |
---|
868 | End |
---|
869 | |
---|
870 | //clears either the sample or empty scan Lists... |
---|
871 | //Also clears the data folders and the COR_Graph |
---|
872 | // |
---|
873 | // very useful to make sure that the data is really what you think it is on the cor_graph |
---|
874 | // |
---|
875 | Function ClearButtonProc(ctrlName) : ButtonControl |
---|
876 | String ctrlName |
---|
877 | |
---|
878 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
879 | |
---|
880 | SetDataFolder $(USANSFolder+":Globals:MainPanel") |
---|
881 | strswitch(ctrlName) |
---|
882 | case "ClearSamButton": |
---|
883 | Make/O/T/N=1 samWave |
---|
884 | samWave="" |
---|
885 | //Clear out current flags AJJ Sept O6 |
---|
886 | Make/O/N=1 SAMisCurrent,EMPisCurrent |
---|
887 | SAMisCurrent = 0 |
---|
888 | EMPisCurrent = 0 |
---|
889 | //clear the graph, then the data folders as well |
---|
890 | CleanOutGraph("SAM") |
---|
891 | CleanOutFolder("SAM") |
---|
892 | CleanOutGraph("COR") |
---|
893 | CleanOutFolder("COR") |
---|
894 | break |
---|
895 | case "ClearEmpButton": |
---|
896 | Make/O/T/N=1 empWave |
---|
897 | empWave="" |
---|
898 | //Clear out current flags AJJ Sept O6 |
---|
899 | Make/O/N=1 SAMisCurrent,EMPisCurrent |
---|
900 | SAMisCurrent = 0 |
---|
901 | EMPisCurrent = 0 |
---|
902 | //clear the graph, then the data folders as well |
---|
903 | CleanOutGraph("EMP") |
---|
904 | CleanOutFolder("EMP") |
---|
905 | CleanOutGraph("COR") |
---|
906 | CleanOutFolder("COR") |
---|
907 | break |
---|
908 | endswitch |
---|
909 | // uncheck the cursors |
---|
910 | UseCrsrCheckProc("",0) |
---|
911 | |
---|
912 | DoWindow/F USANS_Panel //focus back to MainPanel |
---|
913 | SetDataFolder root: |
---|
914 | End |
---|
915 | |
---|
916 | //reads header information, to display on main panel only |
---|
917 | // called from the action procedure of the raw data listbox |
---|
918 | // |
---|
919 | // puts the pertinent information in the "statusWave" that is associated |
---|
920 | //with the status listbox (which will automatically update) |
---|
921 | // |
---|
922 | Function ReadBT5Header(fname) |
---|
923 | String fname |
---|
924 | |
---|
925 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
926 | |
---|
927 | Variable err=0,refNum |
---|
928 | Wave/T statusWave=$(USANSFolder+":Globals:MainPanel:statusWave") |
---|
929 | |
---|
930 | Open/R refNum as fname //READ-ONLY.......if fname is "", a dialog will be presented |
---|
931 | if(refnum==0) |
---|
932 | return(1) //user cancelled |
---|
933 | endif |
---|
934 | //read in the ASCII data line-by-line |
---|
935 | Variable numLinesLoaded = 0,firstchar |
---|
936 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead |
---|
937 | String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 |
---|
938 | |
---|
939 | //parse the first line |
---|
940 | FReadLine refnum,buffer |
---|
941 | sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8 |
---|
942 | statusWave[0] = "FILE: "+s1 |
---|
943 | statusWave[1] = "DATE: "+s2+" "+s3+" "+s4+" "+s5 |
---|
944 | |
---|
945 | //v1 is the time per point (sec) |
---|
946 | //v2 is the monitor prefactor. Let's multiply the time by the prefactor. AJJ 5 March 07 |
---|
947 | statusWave[2] = "TIME/PT: "+num2istr(v1*v2)+" sec" |
---|
948 | |
---|
949 | //skip the next line |
---|
950 | FReadLine refnum,buffer |
---|
951 | //the next line is the title, use it all except the last character - causes formatting oddities in listBox |
---|
952 | FReadLine refnum,buffer |
---|
953 | statusWave[3] = "TITLE: "+ buffer[0,strlen(buffer)-2] |
---|
954 | |
---|
955 | //skip the next 3 lines |
---|
956 | For(ii=0;ii<3;ii+=1) |
---|
957 | FReadLine refnum,buffer |
---|
958 | EndFor |
---|
959 | |
---|
960 | //parse the angular range from the next line |
---|
961 | FReadLine refnum,buffer |
---|
962 | sscanf buffer,"%g%g%g%g",v1,v2,v3,v4 |
---|
963 | statusWave[4] = "RANGE: "+num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3) |
---|
964 | |
---|
965 | Close refNum // Close the file, read-only, so don't need to move to EOF first |
---|
966 | return err // Zero signifies no error. |
---|
967 | End |
---|
968 | |
---|
969 | // given a string that is the wavenote of the just-loaded raw data file |
---|
970 | // pick out the file and time list items (and values) |
---|
971 | //and return a string that is to be used for the textbox in the graph of raw data |
---|
972 | // |
---|
973 | Function TitleForRawGraph() |
---|
974 | |
---|
975 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
976 | |
---|
977 | WAVE detCts=$(USANSFolder+":RAW:detCts") |
---|
978 | WAVE monCts = $(USANSFolder+":RAW:monCts") |
---|
979 | String str=note(detCts) |
---|
980 | |
---|
981 | String retStr="\\JC" |
---|
982 | retStr += StringByKey("FILE",str,":",";")+"\r" |
---|
983 | retStr += "Count Time: "+StringByKey("TIMEPT",str,":",";") |
---|
984 | retStr += " \tMonitor Rate: "+num2str(mean(monCts)/NumberByKey("TIMEPT",str,":",";"))+"\r" |
---|
985 | retStr += "\\s(DetCts) DetCts \\s(TransCts) TransCts \\s(MonCts) MonCts" |
---|
986 | |
---|
987 | TextBox/W=RawDataWin/C/E=2/A=MT/X=5/Y=0/N=text0 retStr |
---|
988 | End |
---|
989 | |
---|
990 | |
---|
991 | //concatenates datasets (full names are passed in as a string) |
---|
992 | //tacks w2 onto the end of w1 (so keep w1) |
---|
993 | // |
---|
994 | // copied from a wavemetrics procedure (concatenatewaves?) |
---|
995 | Function ConcatenateData(w1, w2) |
---|
996 | String w1, w2 |
---|
997 | |
---|
998 | Variable numPoints1, numPoints2 |
---|
999 | |
---|
1000 | if (Exists(w1) == 0) |
---|
1001 | Duplicate $w2, $w1 |
---|
1002 | else |
---|
1003 | String wInfo=WaveInfo($w2, 0) |
---|
1004 | numPoints1 = numpnts($w1) |
---|
1005 | numPoints2 = numpnts($w2) |
---|
1006 | Redimension/N=(numPoints1 + numPoints2) $w1 |
---|
1007 | Wave/D ww1=$w1 |
---|
1008 | Wave/D ww2=$w2 |
---|
1009 | ww1[numPoints1, ] = ww2[p-numPoints1] |
---|
1010 | endif |
---|
1011 | End |
---|
1012 | |
---|
1013 | //takes the given inputs, subtracts EMP and BKG from the SAM data |
---|
1014 | //the user must supply the correct sample thickness, BKGLevel, and EMPLevel for extrapolation |
---|
1015 | Function DoCorrectData() |
---|
1016 | |
---|
1017 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1018 | |
---|
1019 | //constants |
---|
1020 | // NVAR thetaH = root:Globals:MainPanel:gTheta_H //Darwin FWHM |
---|
1021 | // NVAR thetaV = root:Globals:MainPanel:gTheta_V //Vertical divergence |
---|
1022 | NVAR dOmega = $(USANSFolder+":Globals:MainPanel:gDomega") //Solid angle of detector |
---|
1023 | NVAR defaultMCR = $(USANSFolder+":Globals:MainPanel:gDefaultMCR") |
---|
1024 | |
---|
1025 | //waves |
---|
1026 | Wave iqSAM = $(USANSFolder+":SAM:DetCts") |
---|
1027 | Wave errSAM = $(USANSFolder+":SAM:ErrDetCts") |
---|
1028 | Wave qvalSAM = $(USANSFolder+":SAM:Qvals") |
---|
1029 | Wave iqEMP = $(USANSFolder+":EMP:DetCts") |
---|
1030 | Wave errEMP = $(USANSFolder+":EMP:ErrDetCts") |
---|
1031 | Wave qvalEMP = $(USANSFolder+":EMP:Qvals") |
---|
1032 | //BKG,EMP levels,trans,thick |
---|
1033 | NVAR bkgLevel = $(USANSFolder+":Globals:MainPanel:gBkgCts") |
---|
1034 | NVAR empLevel = $(USANSFolder+":Globals:MainPanel:gEmpCts") |
---|
1035 | NVAR Trock = $(USANSFolder+":Globals:MainPanel:gTransRock") |
---|
1036 | NVAR Twide = $(USANSFolder+":Globals:MainPanel:gTransWide") |
---|
1037 | NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick") |
---|
1038 | //New waves in COR folder, same length as SAM data |
---|
1039 | Duplicate/O iqSAM,$(USANSFolder+":COR:DetCts") |
---|
1040 | Duplicate/O errSAM,$(USANSFolder+":COR:ErrDetCts") |
---|
1041 | Duplicate/O qvalSAM,$(USANSFolder+":COR:Qvals") |
---|
1042 | Wave iqCOR = $(USANSFolder+":COR:DetCts") |
---|
1043 | Wave qvalCOR = $(USANSFolder+":COR:Qvals") |
---|
1044 | Wave errCOR = $(USANSFolder+":COR:ErrDetCts") |
---|
1045 | |
---|
1046 | //correction done here |
---|
1047 | //q-values of EMP must be interpolated to match SAM data |
---|
1048 | //use the extrapolated value of EMP beyind its measured range |
---|
1049 | Variable num=numpnts(iqSAM),ii,scale,tempI,temperr,maxq,wq |
---|
1050 | maxq = qvalEMP[(numpnts(qvalEMP)-1)] //maximum measure q-value for the empty |
---|
1051 | |
---|
1052 | for(ii=0;ii<num;ii+=1) |
---|
1053 | wq = qvalSAM[ii] //q-point of the sample |
---|
1054 | if(wq<maxq) |
---|
1055 | tempI = interp(wq,qvalEMP,iqEMP) |
---|
1056 | temperr = interp(wq,qvalEMP,errEMP) |
---|
1057 | else |
---|
1058 | tempI = empLevel |
---|
1059 | //temperr = sqrt(empLevel) |
---|
1060 | temperr = 0 //JGB 5/31/01 |
---|
1061 | endif |
---|
1062 | iqCOR[ii] = iqSAM[ii] - Trock*tempI - (1-Trock)*bkglevel |
---|
1063 | errCOR[ii] = sqrt(errSAM[ii]^2 + Trock^2*temperr^2) //Trock^2; JGB 5/31/01 |
---|
1064 | endfor |
---|
1065 | |
---|
1066 | String str=note(iqEMP) |
---|
1067 | Variable pkHtEMP=NumberByKey("PEAKVAL", str,":",";") |
---|
1068 | //absolute scaling factor |
---|
1069 | scale = 1/(Twide*thick*dOmega*pkHtEMP) |
---|
1070 | iqCOR *= scale |
---|
1071 | errCOR *= scale |
---|
1072 | |
---|
1073 | //copy to Graph directory to plot |
---|
1074 | Duplicate/O $(USANSFolder+":COR:Qvals"),$(USANSFolder+":Graph:Qvals_COR") |
---|
1075 | Duplicate/O $(USANSFolder+":COR:DetCts"),$(USANSFolder+":Graph:DetCts_COR") |
---|
1076 | Duplicate/O $(USANSFolder+":COR:ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_COR") |
---|
1077 | |
---|
1078 | //now plot the data (or just bring the graph to the front) |
---|
1079 | DoCORGraph() |
---|
1080 | return(0) |
---|
1081 | End |
---|
1082 | |
---|
1083 | //cleans out the specified data folder (type) |
---|
1084 | // and clears out the same-named data from the Graph folder |
---|
1085 | // kills what is not in use |
---|
1086 | // |
---|
1087 | Function CleanOutFolder(type) |
---|
1088 | String type |
---|
1089 | |
---|
1090 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1091 | |
---|
1092 | SetDataFolder $(USANSFolder+":"+type) |
---|
1093 | Killwaves/Z DetCts,Qvals,ErrDetCts,Angle,MonCts,TransCts |
---|
1094 | |
---|
1095 | SetDataFolder $(USANSFolder+":Graph") |
---|
1096 | KillWaves/Z $("DetCts_"+type),$("ErrDetCts_"+type),$("Qvals_"+type) |
---|
1097 | |
---|
1098 | SetDataFolder root: |
---|
1099 | End |
---|
1100 | |
---|
1101 | // removes the selected datatype from the COR_Graph |
---|
1102 | // |
---|
1103 | Function CleanOutGraph(type) |
---|
1104 | String type |
---|
1105 | |
---|
1106 | DoWindow/F COR_Graph |
---|
1107 | if(V_flag) |
---|
1108 | RemoveFromGraph/W=COR_Graph/Z $("DetCts_"+type) |
---|
1109 | endif |
---|
1110 | End |
---|
1111 | |
---|
1112 | //Edits by AJJ, September 2006 |
---|
1113 | //Add functions to get data from Current Folder |
---|
1114 | |
---|
1115 | Function RefreshCurrentButtonProc(ctrlName) : ButtonControl |
---|
1116 | String ctrlName |
---|
1117 | |
---|
1118 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1119 | |
---|
1120 | //Prod the web update page |
---|
1121 | //This is a horrible kludge that doesn't really work as the |
---|
1122 | //webscript does not update the current run as of Sept 26 2006 |
---|
1123 | //Will get Nick M to look into it |
---|
1124 | BrowseURL/Z "http://www-i.ncnr.nist.gov/icpdata/recent.php?action=1&instr=bt5" |
---|
1125 | |
---|
1126 | Print "Waiting 20s for update..." |
---|
1127 | Sleep/S 20 |
---|
1128 | Print "Waited 20s, new file should be there." |
---|
1129 | |
---|
1130 | //check for path and force user to pick a path |
---|
1131 | //assume that if bt5PathName has been assigned, so has bt5CurPathName |
---|
1132 | do |
---|
1133 | PathInfo bt5PathName |
---|
1134 | if(V_Flag) |
---|
1135 | break |
---|
1136 | Endif |
---|
1137 | PickBT5Path() |
---|
1138 | while(V_Flag==0) |
---|
1139 | |
---|
1140 | PathInfo bt5CurPathName |
---|
1141 | if(V_flag==0) |
---|
1142 | NewPath/O/M="Select Current Data" bt5CurPathName, getCurrentPath(S_Path) |
---|
1143 | endif |
---|
1144 | |
---|
1145 | //get all the files, then trim the list |
---|
1146 | String list=IndexedFile(bt5CurPathName,-1,"????") |
---|
1147 | String newList="",item="" |
---|
1148 | Variable num=ItemsInList(list,";"),ii |
---|
1149 | for(ii=0;ii<num;ii+=1) |
---|
1150 | item = StringFromList(ii, list ,";") |
---|
1151 | if( stringmatch(item,"*.bt5*") ) //ONLY keep files with ".bt5" in the name (NOT case-sensitive) |
---|
1152 | newlist += item + ";" |
---|
1153 | endif |
---|
1154 | //print "ii=",ii |
---|
1155 | endfor |
---|
1156 | newList = SortList(newList,";",0) //get them in order |
---|
1157 | num=ItemsInList(newlist,";") |
---|
1158 | Wave/T curWave = $(USANSFolder+":Globals:MainPanel:curWave") |
---|
1159 | Redimension/N=(num) curWave |
---|
1160 | curWave="" |
---|
1161 | curWave = StringFromList(p,newlist,";") // ! quick and easy assignment of the list |
---|
1162 | Sort curwave,curwave |
---|
1163 | |
---|
1164 | End |
---|
1165 | |
---|
1166 | //Reduced version of toSamListButtonProc for putting current data into Sample data |
---|
1167 | Function CurtoSamListButtonProc(ctrlName) : ButtonControl |
---|
1168 | String ctrlName |
---|
1169 | |
---|
1170 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1171 | |
---|
1172 | Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave") |
---|
1173 | Wave/T samWave=$(USANSFolder+":Globals:MainPanel:samWave") |
---|
1174 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:SAMisCurrent") |
---|
1175 | |
---|
1176 | Variable num, ii = 0 |
---|
1177 | variable lastPt=numpnts(samWave) |
---|
1178 | |
---|
1179 | InsertPoints lastPt,1, samWave |
---|
1180 | samWave[lastPt]=curwave[ii] |
---|
1181 | InsertPoints lastPt, 1, isCurrent |
---|
1182 | isCurrent[lastPt] = 1 |
---|
1183 | |
---|
1184 | //clean out any (null) elements |
---|
1185 | num = numpnts(samwave) |
---|
1186 | for(ii=0;ii<num;ii+=1) |
---|
1187 | if(cmpstr(samWave[ii],"") ==0) |
---|
1188 | DeletePoints ii,1,samWave |
---|
1189 | DeletePoints ii,1,isCurrent |
---|
1190 | num -= 1 |
---|
1191 | Endif |
---|
1192 | Endfor |
---|
1193 | |
---|
1194 | return(0) |
---|
1195 | End |
---|
1196 | |
---|
1197 | //Reduced version of toEmptyListButtonProc for putting current data into Empty data |
---|
1198 | Function CurtoEmptyListButtonProc(ctrlName) : ButtonControl |
---|
1199 | String ctrlName |
---|
1200 | |
---|
1201 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1202 | |
---|
1203 | Wave/T curWave=$(USANSFolder+":Globals:MainPanel:curWave") |
---|
1204 | Wave/T empWave=$(USANSFolder+":Globals:MainPanel:empWave") |
---|
1205 | Wave isCurrent = $(USANSFolder+":Globals:MainPanel:EMPisCurrent") |
---|
1206 | |
---|
1207 | Variable num, ii=0 |
---|
1208 | variable lastPt=numpnts(empWave) |
---|
1209 | |
---|
1210 | InsertPoints lastPt,1, empWave |
---|
1211 | empWave[lastPt]=curwave[ii] |
---|
1212 | InsertPoints lastPt, 1, isCurrent |
---|
1213 | isCurrent[lastPt] = 1 |
---|
1214 | |
---|
1215 | |
---|
1216 | //clean out any (null) elements |
---|
1217 | num=numpnts(empwave) |
---|
1218 | for(ii=0;ii<num;ii+=1) |
---|
1219 | if(cmpstr(empWave[ii],"") ==0) |
---|
1220 | DeletePoints ii,1,empWave |
---|
1221 | DeletePoints ii,1,isCurrent |
---|
1222 | num -= 1 |
---|
1223 | Endif |
---|
1224 | Endfor |
---|
1225 | |
---|
1226 | |
---|
1227 | return(0) |
---|
1228 | End |
---|
1229 | |
---|
1230 | Function UseCurrentDataProc(ctrlName,checked) : CheckBoxControl |
---|
1231 | String ctrlName |
---|
1232 | Variable checked |
---|
1233 | |
---|
1234 | SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder |
---|
1235 | |
---|
1236 | NVAR isChecked = $(USANSFolder+":Globals:MainPanel:gUseCurrentData") |
---|
1237 | |
---|
1238 | if (checked == 1) |
---|
1239 | DoAlert 1, "Enabling Current Data requires access to the NCNR Network.\rDo you wish to continue?" |
---|
1240 | if(V_flag == 1) |
---|
1241 | ModifyControl/Z CurFileBox, disable=0 |
---|
1242 | ModifyControl/Z AddCurToSAM, disable=0 |
---|
1243 | ModifyControl/Z AddCurToEMP, disable=0 |
---|
1244 | ModifyControl/Z RefreshCurrent,disable=0 |
---|
1245 | isChecked = 1 |
---|
1246 | endif |
---|
1247 | else |
---|
1248 | ModifyControl/Z CurFileBox, disable=1 |
---|
1249 | ModifyControl/Z AddCurToSAM, disable=2 |
---|
1250 | ModifyControl/Z AddCurToEMP, disable=2 |
---|
1251 | ModifyControl/Z RefreshCurrent,disable=2 |
---|
1252 | isChecked = 0 |
---|
1253 | endif |
---|
1254 | |
---|
1255 | End |
---|
1256 | |
---|
1257 | //Function to get path for Current file |
---|
1258 | Function/S getCurrentPath(inPath) |
---|
1259 | String inPath |
---|
1260 | |
---|
1261 | Variable pos=0,mpos = 0 |
---|
1262 | Variable i = 0,j = 0 |
---|
1263 | // The saga continues... |
---|
1264 | // Originally used ParseFilePath - not in Igor 4 |
---|
1265 | // Switched to strsearch, but useful searching from end of string not in Igor 4 |
---|
1266 | // Now have ugly loops going through the string, but should work. |
---|
1267 | |
---|
1268 | for( i = 0;i<4; i+=1) |
---|
1269 | do |
---|
1270 | pos = strsearch(inPath,":",j) |
---|
1271 | if (pos != -1) |
---|
1272 | mpos = pos |
---|
1273 | endif |
---|
1274 | j = pos+1 |
---|
1275 | while (pos !=-1) |
---|
1276 | |
---|
1277 | inPath = inPath[0,mpos -1] |
---|
1278 | pos = 0 |
---|
1279 | mpos = 0 |
---|
1280 | j = 0 |
---|
1281 | endfor |
---|
1282 | |
---|
1283 | inPath = inPath + ":current:" |
---|
1284 | |
---|
1285 | return inPath |
---|
1286 | |
---|
1287 | End |
---|
1288 | |
---|
1289 | // |
---|
1290 | Function U_OpenTracTicketPage(ctrlName) |
---|
1291 | String ctrlName |
---|
1292 | DoAlert 1,"Your web browser will open to a page where you can submit your bug report or feature request. OK?" |
---|
1293 | if(V_flag==1) |
---|
1294 | BrowseURL "http://danse.chem.utk.edu/trac/newticket" |
---|
1295 | endif |
---|
1296 | End |
---|