1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=4.0 |
---|
4 | |
---|
5 | //**************************** |
---|
6 | // Vers. 1.2 092101 |
---|
7 | // |
---|
8 | // NSORT panel for combining and inter-normalizing 2 or 3 datasets |
---|
9 | // that have previously been averaged |
---|
10 | // |
---|
11 | // - handles 3 or 6-column datasets |
---|
12 | // allows manual scaling |
---|
13 | // allows user to interactively delete data points from either end of any datset |
---|
14 | // |
---|
15 | //********************* |
---|
16 | |
---|
17 | //main entry point for displaying the nsort panel |
---|
18 | //initializes folder/globals as needed |
---|
19 | // |
---|
20 | Proc ShowNSORTPanel() |
---|
21 | DoWindow/F NSORT_Panel |
---|
22 | if(V_flag==0) |
---|
23 | InitNSORTPanel() |
---|
24 | NSORT_Panel() |
---|
25 | Endif |
---|
26 | SetDataFolder root: |
---|
27 | PathInfo/S catPathName |
---|
28 | String junk = S_path |
---|
29 | if (V_flag == 0) |
---|
30 | //path does not exist - no folder selected |
---|
31 | String/G root:myGlobals:NSORT:gPathStr = "no folder selected" |
---|
32 | else |
---|
33 | String/G root:myGlobals:NSORT:gPathStr = junk |
---|
34 | endif |
---|
35 | LowQPopMenuProc("",1,"") |
---|
36 | MedQPopMenuProc("",1,"") |
---|
37 | HighQPopMenuProc("",1,"") |
---|
38 | End |
---|
39 | |
---|
40 | //initializes globals/folder for the NSORT panel as needed |
---|
41 | //all of the globals are stored in root:myGlobals:NSORT folder |
---|
42 | //the globals are the values displayed in the panel |
---|
43 | // |
---|
44 | Proc InitNSORTPanel() |
---|
45 | |
---|
46 | //set up the global variables needed for the NSORT panel |
---|
47 | NewDataFolder/O root:myGlobals:NSORT |
---|
48 | Variable/G root:myGlobals:NSORT:gScale1_2 = 1 |
---|
49 | Variable/G root:myGlobals:NSORT:gScale2_3 = 1 |
---|
50 | // |
---|
51 | //save the number of points to trim from beginning/end of the data files |
---|
52 | // |
---|
53 | Variable/G root:myGlobals:NSORT:gPtsBeg1 = NumVarOrDefault("root:myGlobals:NSORT:gPtsBeg1", 0 ) |
---|
54 | Variable/G root:myGlobals:NSORT:gPtsEnd1 = NumVarOrDefault("root:myGlobals:NSORT:gPtsEnd1", 0 ) |
---|
55 | Variable/G root:myGlobals:NSORT:gPtsBeg2 = NumVarOrDefault("root:myGlobals:NSORT:gPtsBeg2", 0 ) |
---|
56 | Variable/G root:myGlobals:NSORT:gPtsEnd2 = NumVarOrDefault("root:myGlobals:NSORT:gPtsEnd2", 0 ) |
---|
57 | Variable/G root:myGlobals:NSORT:gPtsBeg3 = NumVarOrDefault("root:myGlobals:NSORT:gPtsBeg3", 0 ) |
---|
58 | Variable/G root:myGlobals:NSORT:gPtsEnd3 = NumVarOrDefault("root:myGlobals:NSORT:gPtsEnd3", 0 ) |
---|
59 | |
---|
60 | Variable/G root:myGlobals:NSORT:gColumns1 = 0 |
---|
61 | Variable/G root:myGlobals:NSORT:gColumns2 = 0 |
---|
62 | Variable/G root:myGlobals:NSORT:gColumns3 = 0 |
---|
63 | Variable/G root:myGlobals:NSORT:gNormToNum = 1 |
---|
64 | String/G root:myGlobals:NSORT:gPathStr = "" |
---|
65 | String/G root:myGlobals:NSORT:gDataPopList = "none" |
---|
66 | String/G root:myGlobals:NSORT:gDataPopList_3 = "none" |
---|
67 | |
---|
68 | SetDataFolder root: //(redundant) |
---|
69 | End |
---|
70 | |
---|
71 | |
---|
72 | //loads datasets (3-column or 6-column) for use in NSORTing |
---|
73 | //identical in function to normal file loading routine LoadQISData() |
---|
74 | //except that this routine builds custom names to keep track of |
---|
75 | //high-med-low q datasets (as defined by setNum input) |
---|
76 | // |
---|
77 | Function LoadDataForNSORT(fileStr,setNum) |
---|
78 | String fileStr //full path:name to a valid file |
---|
79 | Variable setNum //number of set (used for naming) = 0, 1, or 2 (ONLY) |
---|
80 | |
---|
81 | Variable err=0 |
---|
82 | |
---|
83 | LoadWave/G/D/A/Q fileStr // (/Q) option suppresses printing to history |
---|
84 | String nm0,nm1,nm2 |
---|
85 | String firstFileName = S_fileName |
---|
86 | Variable pt=0,begPts,endPts |
---|
87 | |
---|
88 | NVAR gColumns1 = root:myGlobals:NSORT:gColumns1 |
---|
89 | NVAR gColumns2 = root:myGlobals:NSORT:gColumns2 |
---|
90 | NVAR gColumns3 = root:myGlobals:NSORT:gColumns3 |
---|
91 | NVAR begPts1 = root:myGlobals:NSORT:gPtsBeg1 |
---|
92 | NVAR endPts1 = root:myGlobals:NSORT:gPtsEnd1 |
---|
93 | NVAR begPts2 = root:myGlobals:NSORT:gPtsBeg2 |
---|
94 | NVAR endPts2 = root:myGlobals:NSORT:gPtsEnd2 |
---|
95 | NVAR begPts3 = root:myGlobals:NSORT:gPtsBeg3 |
---|
96 | NVAR endPts3 = root:myGlobals:NSORT:gPtsEnd3 |
---|
97 | |
---|
98 | String typStr="",trimStr="" |
---|
99 | |
---|
100 | do |
---|
101 | if(V_flag == 3) //Three waves loaded |
---|
102 | // put the names of the three loaded waves into local names |
---|
103 | nm0 = StringFromList(0, S_waveNames ,";" ) |
---|
104 | nm1 = StringFromList(1, S_waveNames ,";" ) |
---|
105 | nm2 = StringFromList(2, S_waveNames ,";" ) |
---|
106 | |
---|
107 | //rename to give desired names - can't use rename if waves exist - it will generate an error |
---|
108 | if(setNum == 1) |
---|
109 | gColumns1 = 3 |
---|
110 | typStr = "LowQSet" |
---|
111 | trimStr = "TrimLowQSet" |
---|
112 | begPts = begPts1 |
---|
113 | endPts = endPts1 |
---|
114 | else |
---|
115 | if(setNum == 2) |
---|
116 | gColumns2 = 3 |
---|
117 | typStr = "MedQSet" |
---|
118 | trimStr = "TrimMedQSet" |
---|
119 | begPts = begPts2 |
---|
120 | endPts = endPts2 |
---|
121 | else |
---|
122 | gColumns3 = 3 |
---|
123 | typStr="HighQSet" |
---|
124 | trimStr = "TrimHighQSet" |
---|
125 | begPts = begPts3 |
---|
126 | endPts = endPts3 |
---|
127 | Endif |
---|
128 | Endif |
---|
129 | Duplicate/O $nm0, $(typStr+"_q") |
---|
130 | Duplicate/O $nm1, $(typStr+"_i") |
---|
131 | Duplicate/O $nm2, $(typStr+"_s") |
---|
132 | KillWaves/Z $nm0,$nm1,$nm2 |
---|
133 | //create the "trimmed" dataset too, start by duplicating the original sets |
---|
134 | Duplicate/O $(typStr+"_q"),$(trimStr+"_q") |
---|
135 | Duplicate/O $(typStr+"_i"),$(trimStr+"_i") |
---|
136 | Duplicate/O $(typStr+"_s"),$(trimStr+"_s") |
---|
137 | WaveStats/Q $(typStr+"_q") //get info about the original q-values read in |
---|
138 | pt = V_npnts-endPts |
---|
139 | DeletePoints pt,endPts,$(trimStr+"_q"),$(trimStr+"_i"),$(trimStr+"_s") //delete end points first |
---|
140 | DeletePoints 0,begPts,$(trimStr+"_q"),$(trimStr+"_i"),$(trimStr+"_s") //then delete points from beginning |
---|
141 | |
---|
142 | Return err |
---|
143 | break |
---|
144 | endif //End of what happens if 3 columns are loaded |
---|
145 | |
---|
146 | if(V_flag == 6) //Six waves loaded |
---|
147 | String nm3,nm4,nm5 |
---|
148 | // put the names of the three loaded waves into local names |
---|
149 | nm0 = StringFromList(0, S_waveNames ,";" ) |
---|
150 | nm1 = StringFromList(1, S_waveNames ,";" ) |
---|
151 | nm2 = StringFromList(2, S_waveNames ,";" ) |
---|
152 | nm3 = StringFromList(3, S_waveNames ,";" ) |
---|
153 | nm4 = StringFromList(4, S_waveNames ,";" ) |
---|
154 | nm5 = StringFromList(5, S_waveNames ,";" ) |
---|
155 | |
---|
156 | if(setNum == 1) |
---|
157 | gColumns1 = 6 |
---|
158 | typStr = "LowQSet" |
---|
159 | trimStr = "TrimLowQSet" |
---|
160 | begPts = begPts1 |
---|
161 | endPts = endPts1 |
---|
162 | else |
---|
163 | if(setNum == 2) |
---|
164 | gColumns2 = 6 |
---|
165 | typStr = "MedQSet" |
---|
166 | trimStr = "TrimMedQSet" |
---|
167 | begPts = begPts2 |
---|
168 | endPts = endPts2 |
---|
169 | else |
---|
170 | gColumns3 = 6 |
---|
171 | typStr="HighQSet" |
---|
172 | trimStr = "TrimHighQSet" |
---|
173 | begPts = begPts3 |
---|
174 | endPts = endPts3 |
---|
175 | Endif |
---|
176 | Endif |
---|
177 | Duplicate/O $nm0, $(typStr+"_q") |
---|
178 | Duplicate/O $nm1, $(typStr+"_i") |
---|
179 | Duplicate/O $nm2, $(typStr+"_s") |
---|
180 | Duplicate/O $nm3, $(typStr+"_sq") |
---|
181 | Duplicate/O $nm4, $(typStr+"_qb") |
---|
182 | Duplicate/O $nm5, $(typStr+"_fs") |
---|
183 | KillWaves/Z $nm0,$nm1,$nm2,$nm3,$nm4,$nm5 |
---|
184 | //create the "trimmed" dataset too |
---|
185 | Duplicate/O $(typStr+"_q"),$(trimStr+"_q") |
---|
186 | Duplicate/O $(typStr+"_i"),$(trimStr+"_i") |
---|
187 | Duplicate/O $(typStr+"_s"),$(trimStr+"_s") |
---|
188 | Duplicate/O $(typStr+"_sq"),$(trimStr+"_sq") |
---|
189 | Duplicate/O $(typStr+"_qb"),$(trimStr+"_qb") |
---|
190 | Duplicate/O $(typStr+"_fs"),$(trimStr+"_fs") |
---|
191 | WaveStats/Q $(typStr+"_q") //get info about the original q-values read in |
---|
192 | pt = V_npnts-endPts |
---|
193 | DeletePoints pt,endPts,$(trimStr+"_q"),$(trimStr+"_i"),$(trimStr+"_s"),$(trimStr+"_sq"),$(trimStr+"_qb"),$(trimStr+"_fs") //delete end points first |
---|
194 | DeletePoints 0,begPts,$(trimStr+"_q"),$(trimStr+"_i"),$(trimStr+"_s"),$(trimStr+"_sq"),$(trimStr+"_qb"),$(trimStr+"_fs") //then delete points from beginning |
---|
195 | |
---|
196 | Return err |
---|
197 | break |
---|
198 | endif //End of Six waves loaded |
---|
199 | |
---|
200 | //Next stuff gets executed if not 3 or 6 (example, if 0 ) |
---|
201 | err=1 |
---|
202 | return err |
---|
203 | while(0) |
---|
204 | End |
---|
205 | |
---|
206 | //writes out the NSORTed file, includeing header information about how the file |
---|
207 | //was genereated - from which files, and how it was normalized |
---|
208 | //protocol info makes no sense here - go back to the original, separate files |
---|
209 | //if you want to know that information |
---|
210 | // |
---|
211 | // this is the 3-column version - there's a separate function for 6-column data |
---|
212 | //will ALWAYS prompt for a filename |
---|
213 | // |
---|
214 | Function Write3ColNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23) |
---|
215 | Wave q3,i3,sig3 |
---|
216 | String firstFileName,secondFileName,thirdFileName,normTo |
---|
217 | Variable norm12,norm23 |
---|
218 | |
---|
219 | Variable err=0,refNum |
---|
220 | String fullPath="" |
---|
221 | //check each wave - else REALLY FATAL error when writing file |
---|
222 | If(!(WaveExists(q3))) |
---|
223 | err = 1 |
---|
224 | return err |
---|
225 | Endif |
---|
226 | If(!(WaveExists(i3))) |
---|
227 | err = 1 |
---|
228 | return err |
---|
229 | Endif |
---|
230 | If(!(WaveExists(sig3))) |
---|
231 | err = 1 |
---|
232 | return err |
---|
233 | Endif |
---|
234 | |
---|
235 | Variable dialog = 1 |
---|
236 | if(dialog) |
---|
237 | Open/D refnum as fullpath //won't actually open the file |
---|
238 | If(cmpstr(S_filename,"")==0) |
---|
239 | //user cancel, don't write out a file |
---|
240 | Close/A |
---|
241 | Abort "no data file was written" |
---|
242 | Endif |
---|
243 | fullpath = S_filename |
---|
244 | //Print "dialog fullpath = ",fullpath |
---|
245 | Endif |
---|
246 | |
---|
247 | String formatStr = "%15.4g %15.4g %15.4g\r\n" |
---|
248 | //actually open the file |
---|
249 | Open refNum as fullpath |
---|
250 | |
---|
251 | fprintf refnum,"FILE CREATED: %s \r\n",date() |
---|
252 | fprintf refNum, "NSORT-ed %s \t + %s\t + %s\r\n",firstFileName, secondFileName,thirdFileName |
---|
253 | fprintf refNum, "normalized to %s\r\n",normTo |
---|
254 | fprintf refNum, "multiplicative factor 1-2 = %12.8g\t multiplicative factor 2-3 = %12.8g\r\n",norm12,norm23 |
---|
255 | fprintf refnum,"The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) |\r\n" |
---|
256 | wfprintf refnum, formatStr, q3,i3,sig3 |
---|
257 | |
---|
258 | Close refnum |
---|
259 | |
---|
260 | Return err |
---|
261 | End |
---|
262 | |
---|
263 | //writes out the NSORTed file, includeing header information about how the file |
---|
264 | //was generated - from which files, and how it was normalized |
---|
265 | //protocol info makes no sense here - go back to the original, separate files |
---|
266 | //if you want to know that information |
---|
267 | // |
---|
268 | // this is the 6-column version - there's a separate function for 3-column data |
---|
269 | //will ALWAYS prompt for a filename |
---|
270 | // |
---|
271 | Function Write6ColNSORTedFile(q3,i3,sig3,sq3,qb3,fs3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23) |
---|
272 | Wave q3,i3,sig3,sq3,qb3,fs3 |
---|
273 | String firstFileName,secondFileName,thirdFileName,normTo |
---|
274 | Variable norm12,norm23 |
---|
275 | |
---|
276 | Variable err=0,refNum |
---|
277 | String fullPath="" |
---|
278 | //check each wave - else REALLY FATAL error when writing file |
---|
279 | If(!(WaveExists(q3))) |
---|
280 | err = 1 |
---|
281 | return err |
---|
282 | Endif |
---|
283 | If(!(WaveExists(i3))) |
---|
284 | err = 1 |
---|
285 | return err |
---|
286 | Endif |
---|
287 | If(!(WaveExists(sig3))) |
---|
288 | err = 1 |
---|
289 | return err |
---|
290 | Endif |
---|
291 | If(!(WaveExists(sq3))) |
---|
292 | err = 1 |
---|
293 | return err |
---|
294 | Endif |
---|
295 | If(!(WaveExists(qb3))) |
---|
296 | err = 1 |
---|
297 | return err |
---|
298 | Endif |
---|
299 | If(!(WaveExists(fs3))) |
---|
300 | err = 1 |
---|
301 | return err |
---|
302 | Endif |
---|
303 | |
---|
304 | Variable dialog = 1 |
---|
305 | // 05SEP05 SRK -- added to automatically combine files from a table - see the end of NSORT.ipf for details |
---|
306 | // - use the flag set in DoCombineFiles() to decide if the table entries should be used |
---|
307 | // root:myGlobals:CombineTable:useTable= (1) (0) |
---|
308 | //if(exists("root:myGlobals:CombineTable:SaveName")) |
---|
309 | NVAR/Z useTable = root:myGlobals:CombineTable:useTable |
---|
310 | if(NVAR_Exists(useTable) && useTable==1) |
---|
311 | SVAR str=$"root:myGlobals:CombineTable:SaveNameStr" //messy, but pass in as a global |
---|
312 | fullPath = str |
---|
313 | String str2 = "Is the file name "+str+" correct?" |
---|
314 | DoAlert 1,str2 |
---|
315 | if(V_flag==1) |
---|
316 | dialog=0 //bypass the dialog if the name is good |
---|
317 | endif |
---|
318 | endif |
---|
319 | |
---|
320 | if(dialog) |
---|
321 | Open/D refnum as fullpath //won't actually open the file |
---|
322 | If(cmpstr(S_filename,"")==0) |
---|
323 | //user cancel, don't write out a file |
---|
324 | Close/A |
---|
325 | Abort "no data file was written" |
---|
326 | Endif |
---|
327 | fullpath = S_filename |
---|
328 | //Print "dialog fullpath = ",fullpath |
---|
329 | Endif |
---|
330 | |
---|
331 | String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" |
---|
332 | //actually open the file |
---|
333 | Open refNum as fullpath |
---|
334 | |
---|
335 | fprintf refnum,"FILE CREATED: %s \r\n",date() |
---|
336 | fprintf refNum, "NSORT-ed %s \t + %s\t + %s\r\n",firstFileName, secondFileName,thirdFileName |
---|
337 | fprintf refNum, "normalized to %s\r\n",normTo |
---|
338 | fprintf refNum, "multiplicative factor 1-2 = %12.8g\t multiplicative factor 2-3 = %12.8g\r\n",norm12,norm23 |
---|
339 | fprintf refnum,"The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n" |
---|
340 | wfprintf refnum, formatStr, q3,i3,sig3,sq3,qb3,fs3 |
---|
341 | |
---|
342 | Close refnum |
---|
343 | |
---|
344 | Return err |
---|
345 | End |
---|
346 | |
---|
347 | //unused tesing procedure |
---|
348 | // |
---|
349 | Proc AskToStripPoints(nb,ne) |
---|
350 | Variable nb=7,ne=0 |
---|
351 | Prompt nb,"Points to strip from beginning of file" |
---|
352 | Prompt ne,"Points to strip from end of file" |
---|
353 | |
---|
354 | gBegPts = nb |
---|
355 | gEndPts = ne |
---|
356 | |
---|
357 | End |
---|
358 | |
---|
359 | //gets the scaling constant to make (best) overlap of the specified datasets |
---|
360 | //the scaling value is an average value of the individual scaling values for |
---|
361 | //every data point (at the low q end) of set 2 that overlaps with set 1 |
---|
362 | //(as if set 1 were held fixed) |
---|
363 | //num2 is the highest point number in set 2 that can overlap with set 1 |
---|
364 | //(num2+1) individual scaling values are computed |
---|
365 | //wave2 must be multiplied by norm to rescale to wave1 |
---|
366 | //the scale factor is the return value |
---|
367 | // |
---|
368 | Function GetScalingInOverlap(num2,wave1q,wave1i,wave2q,wave2i) |
---|
369 | Variable num2 //largest point number of wave2 in overlap region |
---|
370 | Wave wave1q,wave1i,wave2q,wave2i //1 = first dataset, 2= second dataset |
---|
371 | |
---|
372 | Variable ii,ival1,newi,ratio |
---|
373 | ratio=0 |
---|
374 | ii=0 |
---|
375 | do |
---|
376 | //get scaling factor at each point of wave 2 in the overlap region |
---|
377 | newi = interp(wave2q[ii],wave1q,wave1i) //get the intensity of wave1 at an overlap point |
---|
378 | ratio += newi/wave2i[ii] //get the scale factor |
---|
379 | //Print "ratio = ",ratio |
---|
380 | ii+=1 |
---|
381 | while(ii<=num2) |
---|
382 | Variable norm |
---|
383 | norm = ratio/(num2+1) // +1 counts for point zero |
---|
384 | //Print "norm = ",norm |
---|
385 | |
---|
386 | Return norm |
---|
387 | End |
---|
388 | |
---|
389 | Function ShowNSORTHelp(ctrlName) : ButtonControl |
---|
390 | String ctrlName |
---|
391 | DisplayHelpTopic/K=1 "SANS Data Reduction Tutorial[Sort and Combine Averaged Datasets]" |
---|
392 | End |
---|
393 | |
---|
394 | //button action procedure that simply closes the NSORT panel when done |
---|
395 | //and removes the NSORT-specific waves that were created |
---|
396 | // - the graph window must be killed first, so that the waves will not |
---|
397 | //be in use |
---|
398 | // |
---|
399 | Function NSORT_DoneButton(ctrlName) : ButtonControl |
---|
400 | String ctrlName |
---|
401 | |
---|
402 | DoWindow/K NSORT_Panel |
---|
403 | |
---|
404 | DoWindow/K NSORT_Graph |
---|
405 | |
---|
406 | //clean up the temporary waves in the root: folder |
---|
407 | SetDataFolder root: |
---|
408 | |
---|
409 | KillWaves/Z LowQSet_q,LowQSet_i,LowQSet_s,LowQSet_sq,LowQSet_qb,LowQSet_fs |
---|
410 | KillWaves/Z TrimLowQSet_q,TrimLowQSet_i,TrimLowQSet_s,TrimLowQSet_sq,TrimLowQSet_qb,TrimLowQSet_fs |
---|
411 | KillWaves/Z MedQSet_q,MedQSet_i,MedQSet_s,MedQSet_sq,MedQSet_qb,MedQSet_fs |
---|
412 | KillWaves/Z TrimMedQSet_q,TrimMedQSet_i,TrimMedQSet_s,TrimMedQSet_sq,TrimMedQSet_qb,TrimMedQSet_fs |
---|
413 | KillWaves/Z HighQSet_q,HighQSet_i,HighQSet_s,HighQSet_sq,HighQSet_qb,HighQSet_fs |
---|
414 | KillWaves/Z TrimHighQSet_q,TrimHighQSet_i,TrimHighQSet_s,TrimHighQSet_sq,TrimHighQSet_qb,TrimHighQSet_fs |
---|
415 | |
---|
416 | End |
---|
417 | |
---|
418 | //button action procedure that plots dataset specified |
---|
419 | //on an NSORT graph window. |
---|
420 | //switch is on input controlName (low-med-high set) |
---|
421 | //parses partial filename from corresponding popup menu |
---|
422 | //builds a valid filename, loads the data (re-loads if already on graph) |
---|
423 | //and plots twice - once for the full datset (open symbols) |
---|
424 | //and once for the "trimmed" dataset (solid symbols, same color) |
---|
425 | // |
---|
426 | Function Plot_0_Button(ctrlName) : ButtonControl |
---|
427 | String ctrlName |
---|
428 | |
---|
429 | String tempName="",partialName="" |
---|
430 | Variable setNum,err |
---|
431 | //switch on ctrlName string - Plot_1, Plot_2, Plot_3 |
---|
432 | if(cmpstr(ctrlName,"Plot_1")==0) |
---|
433 | //low-q |
---|
434 | setNum = 1 |
---|
435 | ControlInfo $"popup_1" |
---|
436 | else |
---|
437 | if(cmpstr(ctrlName,"Plot_2")==0) |
---|
438 | //medium-q |
---|
439 | setNum = 2 |
---|
440 | ControlInfo $"popup_2" |
---|
441 | else |
---|
442 | //high-q |
---|
443 | setNum = 3 |
---|
444 | ControlInfo $"popup_3" |
---|
445 | Endif |
---|
446 | Endif |
---|
447 | |
---|
448 | //find the file from the partial filename |
---|
449 | If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) ) |
---|
450 | //null selection, or "none" from any popup |
---|
451 | Abort "no file selected in popup menu" |
---|
452 | else |
---|
453 | //selection not null |
---|
454 | partialName = S_value |
---|
455 | //Print partialName |
---|
456 | Endif |
---|
457 | //get a valid file based on this partialName and catPathName |
---|
458 | tempName = FindValidFilename(partialName) |
---|
459 | |
---|
460 | //prepend path to tempName for read routine |
---|
461 | PathInfo catPathName |
---|
462 | tempName = S_path + tempName |
---|
463 | |
---|
464 | //load in the data (into the root directory) |
---|
465 | err = LoadDataForNSORT(tempName,setNum) |
---|
466 | |
---|
467 | //bring the plot to the front, and put the new data on it |
---|
468 | //and put cursors on the plotted dataset |
---|
469 | //if the dataset is already on the graph, it will have been overwritten and updated by the load routine |
---|
470 | //actually plot it twice, open(opaque) circles for the full dataset, |
---|
471 | // then solid (filled) circles for the points actually kept |
---|
472 | String list="",searchStr="" |
---|
473 | Variable isOnPlot=0 |
---|
474 | |
---|
475 | DoWindow/F NSORT_Graph |
---|
476 | if(V_flag == 0) |
---|
477 | //no window, create one |
---|
478 | if(cmpstr(ctrlName,"Plot_1")==0) |
---|
479 | //low-q |
---|
480 | Display/K=1 |
---|
481 | DoWindow/C NSORT_Graph |
---|
482 | DisplayLowSet() |
---|
483 | else |
---|
484 | if(cmpstr(ctrlName,"Plot_2")==0) |
---|
485 | //medium-q |
---|
486 | Display/K=1 |
---|
487 | DoWindow/C NSORT_Graph |
---|
488 | DisplayMedSet() |
---|
489 | else |
---|
490 | //high-q |
---|
491 | Display/K=1 |
---|
492 | DoWindow/C NSORT_Graph |
---|
493 | DisplayHighSet() |
---|
494 | Endif |
---|
495 | Endif |
---|
496 | Legend |
---|
497 | else |
---|
498 | //plot already exists, waves have been updated |
---|
499 | //make sure that the desired waves are actually on the graph, and add them if they aren't |
---|
500 | list = TraceNameList("NSORT_Graph",";",1) |
---|
501 | |
---|
502 | if(cmpstr(ctrlName,"Plot_1")==0) |
---|
503 | //low-q |
---|
504 | isOnPlot = strsearch(list, "LowQSet_i", 0) // isOnPlot == -1 if it is NOT found in the list |
---|
505 | if(isOnPlot == -1) |
---|
506 | DisplayLowSet() |
---|
507 | Endif |
---|
508 | else |
---|
509 | if(cmpstr(ctrlName,"Plot_2")==0) |
---|
510 | //medium-q |
---|
511 | isOnPlot = strsearch(list, "MedQSet_i", 0) // isOnPlot == -1 if it is NOT found in the list |
---|
512 | if(isOnPlot == -1) |
---|
513 | DisplayMedSet() |
---|
514 | Endif |
---|
515 | else |
---|
516 | //high-q |
---|
517 | isOnPlot = strsearch(list, "HighQSet_i", 0) // isOnPlot == -1 if it is NOT found in the list |
---|
518 | if(isOnPlot == -1) |
---|
519 | DisplayHighSet() |
---|
520 | Endif |
---|
521 | Endif |
---|
522 | Endif |
---|
523 | Endif |
---|
524 | //the stripPoints variable boxes should also update the graph, if necessary |
---|
525 | |
---|
526 | End |
---|
527 | |
---|
528 | //adds both high-q sets (full and trimmed) to the graph, which is |
---|
529 | //assumed to exist along with the high-q waves |
---|
530 | // |
---|
531 | Function DisplayHighSet() |
---|
532 | //function assumes that the window "NSORT_Graph" already exists |
---|
533 | DoWindow/F NSORT_Graph |
---|
534 | AppendToGraph $"HighQSet_i" vs $"HighQSet_q" |
---|
535 | ModifyGraph log=1,mode=3,marker($"HighQSet_i")=8,msize=2,rgb($"HighQSet_i")=(0,0,65535),opaque($"HighQSet_i")=1 |
---|
536 | ErrorBars $"HighQSet_i" Y,wave=($"HighQSet_s",$"HighQSet_s") |
---|
537 | AppendToGraph $"TrimHighQSet_i" vs $"TrimHighQSet_q" |
---|
538 | ModifyGraph mode($"TrimHighQSet_i")=3,marker($"TrimHighQSet_i")=19,msize=2,rgb($"TrimHighQSet_i")=(0,0,65535) |
---|
539 | End |
---|
540 | |
---|
541 | //adds both med-q sets (full and trimmed) to the graph, which is |
---|
542 | //assumed to exist along with the med-q waves |
---|
543 | // |
---|
544 | Function DisplayMedSet() |
---|
545 | //function assumes that the window "NSORT_Graph" already exists |
---|
546 | DoWindow/F NSORT_Graph |
---|
547 | AppendToGraph $"MedQSet_i" vs $"MedQSet_q" |
---|
548 | ModifyGraph log=1,mode=3,marker($"MedQSet_i")=8,msize=2,rgb($"MedQSet_i")=(65535,0,0),opaque($"MedQSet_i")=1 |
---|
549 | ErrorBars $"MedQSet_i" Y,wave=($"MedQSet_s",$"MedQSet_s") |
---|
550 | AppendToGraph $"TrimMedQSet_i" vs $"TrimMedQSet_q" |
---|
551 | ModifyGraph mode($"TrimMedQSet_i")=3,marker($"TrimMedQSet_i")=19,msize=2,rgb($"TrimMedQSet_i")=(65535,0,0) |
---|
552 | End |
---|
553 | |
---|
554 | //adds both low-q sets (full and trimmed) to the graph, which is |
---|
555 | //assumed to exist along with the low-q waves |
---|
556 | // |
---|
557 | Function DisplayLowSet() |
---|
558 | //function assumes that the window "NSORT_Graph" already exists |
---|
559 | DoWindow/F NSORT_Graph |
---|
560 | AppendToGraph $"LowQSet_i" vs $"LowQSet_q" |
---|
561 | ModifyGraph log=1,mode=3,marker($"LowQSet_i")=8,msize=2,rgb($"LowQSet_i")=(2,39321,1),opaque($"LowQSet_i")=1 |
---|
562 | ErrorBars $"LowQSet_i" Y,wave=($"LowQSet_s",$"LowQSet_s") |
---|
563 | AppendToGraph $"TrimLowQSet_i" vs $"TrimLowQSet_q" |
---|
564 | ModifyGraph mode($"TrimLowQSet_i")=3,marker($"TrimLowQSet_i")=19,msize=2,rgb($"TrimLowQSet_i")=(2,39321,1) |
---|
565 | End |
---|
566 | |
---|
567 | //button action procedure to set both the main global of the catPath string |
---|
568 | //and also the duplicate global string used in the NSORT folder |
---|
569 | //after path selected, the popup menus are updated |
---|
570 | // |
---|
571 | Function NSORTPickPathButton(ctrlName) : ButtonControl |
---|
572 | String ctrlName |
---|
573 | |
---|
574 | Variable err = PickPath() //sets global path value |
---|
575 | SVAR pathStr = root:myGlobals:gCatPathStr |
---|
576 | |
---|
577 | //set the global string for NSORT to the selected pathname |
---|
578 | String/G root:myGlobals:NSORT:gPathStr = pathStr |
---|
579 | |
---|
580 | //call each of the popup menu proc's to re-set the menu choices |
---|
581 | //setting the checkboxes to force update |
---|
582 | // CheckBox check_0,win=NSORT_Panel,value=1 |
---|
583 | // CheckBox check_1,win=NSORT_Panel,value=1 |
---|
584 | // CheckBox check_2,win=NSORT_Panel,value=1 |
---|
585 | LowQPopMenuProc("popup_1",1,"") |
---|
586 | MedQPopMenuProc("popup_2",1,"") |
---|
587 | HighQPopMenuProc("popup_3",1,"") |
---|
588 | |
---|
589 | End |
---|
590 | |
---|
591 | |
---|
592 | //action procedure associated with the setvar box |
---|
593 | //when a value is entered, the global value is set, and the corresponding dataset |
---|
594 | //is updated on the plot, showing the new result of removing this number of points |
---|
595 | //"Plot_1" is the low-q button name |
---|
596 | //"Plot_2" is the med-q button name |
---|
597 | //"Plot_3" is the high-q button name |
---|
598 | //calling plot_0_Button() responds as if that named button were pressed |
---|
599 | // |
---|
600 | Function SetBegOrEnd(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
601 | String ctrlName |
---|
602 | Variable varNum |
---|
603 | String varStr |
---|
604 | String varName |
---|
605 | |
---|
606 | // global is automatically updated as the value is entered |
---|
607 | String numStr= num2Str( str2num(ctrlName[4]) ) |
---|
608 | Plot_0_Button("Plot_"+numStr) |
---|
609 | DoWindow/F NSORT_Panel |
---|
610 | End |
---|
611 | |
---|
612 | //Function SetEnd_1(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
613 | // String ctrlName |
---|
614 | // Variable varNum |
---|
615 | // String varStr |
---|
616 | // String varName |
---|
617 | // |
---|
618 | // //Variable/G root:myGlobals:NSORT:gPtsEnd1 = varNum |
---|
619 | // print str2num(ctrlName[4]),ctrlName,varNum,varStr,varName |
---|
620 | // Plot_0_Button("Plot_1") |
---|
621 | // DoWindow/F NSORT_Panel |
---|
622 | //End |
---|
623 | // |
---|
624 | ////see comments on SetEnd_1() |
---|
625 | //// |
---|
626 | //Function SetEnd_2(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
627 | // String ctrlName |
---|
628 | // Variable varNum |
---|
629 | // String varStr |
---|
630 | // String varName |
---|
631 | // |
---|
632 | // Variable/G root:myGlobals:NSORT:gPtsEnd2 = varNum |
---|
633 | // Plot_0_Button("Plot_2") |
---|
634 | // DoWindow/F NSORT_Panel |
---|
635 | //End |
---|
636 | // |
---|
637 | ////see comments on SetEnd_1() |
---|
638 | //// |
---|
639 | //Function SetEnd_3(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
640 | // String ctrlName |
---|
641 | // Variable varNum |
---|
642 | // String varStr |
---|
643 | // String varName |
---|
644 | // |
---|
645 | // Variable/G root:myGlobals:NSORT:gPtsEnd3 = varNum |
---|
646 | // Plot_0_Button("Plot_3") |
---|
647 | // DoWindow/F NSORT_Panel |
---|
648 | //End |
---|
649 | // |
---|
650 | ////see comments on SetEnd_1() |
---|
651 | //// |
---|
652 | //Function SetBeg_1(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
653 | // String ctrlName |
---|
654 | // Variable varNum |
---|
655 | // String varStr |
---|
656 | // String varName |
---|
657 | // |
---|
658 | // Variable/G root:myGlobals:NSORT:gPtsBeg1 = varNum |
---|
659 | // Plot_0_Button("Plot_1") |
---|
660 | // DoWindow/F NSORT_Panel |
---|
661 | //End |
---|
662 | // |
---|
663 | ////see comments on SetEnd_1() |
---|
664 | //// |
---|
665 | //Function SetBeg_2(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
666 | // String ctrlName |
---|
667 | // Variable varNum |
---|
668 | // String varStr |
---|
669 | // String varName |
---|
670 | // |
---|
671 | // Variable/G root:myGlobals:NSORT:gPtsBeg2 = varNum |
---|
672 | // Plot_0_Button("Plot_2") |
---|
673 | // DoWindow/F NSORT_Panel |
---|
674 | //End |
---|
675 | // |
---|
676 | ////see comments on SetEnd_1() |
---|
677 | //// |
---|
678 | //Function SetBeg_3(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
679 | // String ctrlName |
---|
680 | // Variable varNum |
---|
681 | // String varStr |
---|
682 | // String varName |
---|
683 | // |
---|
684 | // Variable/G root:myGlobals:NSORT:gPtsBeg3 = varNum |
---|
685 | // Plot_0_Button("Plot_3") |
---|
686 | // DoWindow/F NSORT_Panel |
---|
687 | //End |
---|
688 | |
---|
689 | ////obsolete button control |
---|
690 | //Function ManualScaleButton(ctrlName) : ButtonControl |
---|
691 | // String ctrlName |
---|
692 | // |
---|
693 | // Execute "ManualScalePrompt()" |
---|
694 | // |
---|
695 | //End |
---|
696 | // |
---|
697 | ////obsolete missing param dialog |
---|
698 | //Proc ManualScalePrompt(s12,s23) |
---|
699 | // Variable s12 = 1 |
---|
700 | // Variable s23 = 1 |
---|
701 | // Prompt s12,"enter the multiplier for medium q set" |
---|
702 | // Prompt s23,"enter the multiplier for high q set" |
---|
703 | // |
---|
704 | // Variable/G root:myGlobals:NSORT:gScale1_2 = s12 |
---|
705 | // Variable/G root:myGlobals:NSORT:gScale2_3 = s23 |
---|
706 | //End |
---|
707 | |
---|
708 | //this will--- |
---|
709 | //re-load the data sets (since they may not have been loaded if they were not plotted) |
---|
710 | // apply the scaling to the datasets (so that they will show up in the graph) |
---|
711 | //and actually write the file |
---|
712 | // |
---|
713 | // then "pop" the lists to get the new file lists with the new name in the list |
---|
714 | // |
---|
715 | Function WriteNSORTFileButton(ctrlName) : ButtonControl |
---|
716 | String ctrlName |
---|
717 | |
---|
718 | // Put here the dialog that says if ANY of the datasets had 3-column data, the results will all have only three columns |
---|
719 | // Set the number of output columns |
---|
720 | Variable isAThree = 0, isASix = 0 |
---|
721 | String fileStr="" |
---|
722 | |
---|
723 | NVAR Columns1 = root:myGlobals:NSORT:gColumns1 |
---|
724 | NVAR Columns2 = root:myGlobals:NSORT:gColumns2 |
---|
725 | NVAR Columns3 = root:myGlobals:NSORT:gColumns3 |
---|
726 | if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) ) |
---|
727 | isAThree = 1 |
---|
728 | endif |
---|
729 | if( (Columns1 == 6) || (Columns2 == 6) || (Columns3 == 6) ) |
---|
730 | isASix = 1 |
---|
731 | endif |
---|
732 | if( (isAThree == 1) && (isASix == 1)) |
---|
733 | DoAlert 0, "These files contained a mixture of 3-column and 6-column data. Only 3 columns were output." |
---|
734 | endif |
---|
735 | |
---|
736 | //is there just one data set? if so, then dispatch to a simpler routine, since no normalization is needed |
---|
737 | ControlInfo popup_2 //if MedQSet is "none", then so is HighQSet |
---|
738 | fileStr = S_Value |
---|
739 | if(cmpstr(fileStr,"none") == 0) |
---|
740 | //send just the trimmed (LowQ) set to be written out |
---|
741 | WAVE lowq = $"TrimLowQSet_q" |
---|
742 | WAVE lowi = $"TrimLowQSet_i" |
---|
743 | WAVE lows = $"TrimLowQSet_s" |
---|
744 | WAVE/Z lowsq = $"TrimLowQSet_sq" |
---|
745 | WAVE/Z lowqb = $"TrimLowQSet_qb" |
---|
746 | WAVE/Z lowfs = $"TrimLowQSet_fs" |
---|
747 | NVAR scaleFactor= root:myGlobals:NSORT:gScale1_2 |
---|
748 | // |
---|
749 | lowi *= scaleFactor |
---|
750 | lows *= scaleFactor |
---|
751 | |
---|
752 | ControlInfo popup_1 |
---|
753 | if(isAThree) |
---|
754 | Write3ColNSORTedFile(lowq,lowi,lows,S_Value,"none","none",S_Value,scaleFactor,1) |
---|
755 | else |
---|
756 | Write6ColNSORTedFile(lowq,lowi,lows,lowsq,lowqb,lowfs,S_Value,"none","none",S_Value,scaleFactor,1) |
---|
757 | endif |
---|
758 | // just get the new list and return - don't actually "pop" the menu, or the selected item will change |
---|
759 | SVAR popList = root:myGlobals:NSORT:gDataPopList |
---|
760 | SVAR popList_3 = root:myGlobals:NSORT:gDataPopList_3 |
---|
761 | popList = filterButtonProc("") |
---|
762 | popList_3 = "none;" + filterButtonProc("") |
---|
763 | return(0) |
---|
764 | endif |
---|
765 | |
---|
766 | |
---|
767 | //two or more datasets, combine them |
---|
768 | //have they been manually or auto-normalized? |
---|
769 | ControlInfo AutoCheck |
---|
770 | Variable checked = V_Value |
---|
771 | |
---|
772 | //do the normalization and update the global scale factors displayed in the Panel |
---|
773 | Variable err = DoAutoScaleFromPanel(checked) // DoAutoScaleFromPanel writes out the datafile |
---|
774 | |
---|
775 | // just get the new list - don't actually "pop" the menu, or the selected item will change |
---|
776 | SVAR popList = root:myGlobals:NSORT:gDataPopList |
---|
777 | SVAR popList_3 = root:myGlobals:NSORT:gDataPopList_3 |
---|
778 | popList = filterButtonProc("") |
---|
779 | popList_3 = "none;" + filterButtonProc("") |
---|
780 | |
---|
781 | return(0) |
---|
782 | End |
---|
783 | |
---|
784 | |
---|
785 | //window recreation macro for NSORT Panel |
---|
786 | // |
---|
787 | Window NSORT_Panel() |
---|
788 | PauseUpdate; Silent 1 // building window... |
---|
789 | NewPanel /W=(569,69,944,485)/K=2 |
---|
790 | ModifyPanel cbRGB=(49151,53155,65535) |
---|
791 | ModifyPanel fixedSize=1 |
---|
792 | SetDrawLayer UserBack |
---|
793 | SetDrawEnv fstyle= 5 |
---|
794 | DrawText 35,20,"NSORT - Rescale and combine 1-D files" |
---|
795 | DrawLine 0,55,346,55 |
---|
796 | DrawLine 0,128,346,128 |
---|
797 | DrawLine 0,214,346,214 |
---|
798 | DrawLine 0,295,346,295 |
---|
799 | SetDrawEnv fstyle= 5 |
---|
800 | DrawText 5,74,"Low Q:" |
---|
801 | SetDrawEnv fstyle= 5 |
---|
802 | DrawText 5,148,"Medium Q:" |
---|
803 | SetDrawEnv fstyle= 5 |
---|
804 | DrawText 8,234,"High Q: (or none)" |
---|
805 | SetDrawEnv fstyle= 4 |
---|
806 | DrawText 178,75,"Delete Points?" |
---|
807 | SetDrawEnv fstyle= 4 |
---|
808 | DrawText 178,146,"Delete Points?" |
---|
809 | SetDrawEnv fstyle= 4 |
---|
810 | DrawText 184,236,"Delete Points?" |
---|
811 | DrawLine 0,363,346,363 |
---|
812 | DrawText 31,357,"To Manually scale data, enter scale factors above" |
---|
813 | Button NSORT_Done,pos={274,384},size={50,20},proc=NSORT_DoneButton,title="Done" |
---|
814 | Button NSORT_Done,help={"closes the panel"} |
---|
815 | Button Plot_1,pos={279,63},size={50,20},proc=Plot_0_Button,title="Plot" |
---|
816 | Button Plot_1,help={"Plots the dataset from the popup, showing the full set as open circles and the trimmed set as solid circles"} |
---|
817 | Button Plot_2,pos={283,144},size={50,20},proc=Plot_0_Button,title="Plot" |
---|
818 | Button Plot_2,help={"Plots the dataset from the popup, showing the full set as open circles and the trimmed set as solid circles"} |
---|
819 | Button Plot_3,pos={284,223},size={50,20},proc=Plot_0_Button,title="Plot" |
---|
820 | Button Plot_3,help={"Plots the dataset from the popup, showing the full set as open circles and the trimmed set as solid circles"} |
---|
821 | Button PathButton,pos={6,26},size={80,20},proc=NSORTPickPathButton,title="Pick Path" |
---|
822 | Button PathButton,help={"Select the local path to the folder containing your SANS data"} |
---|
823 | Button helpButton,pos={340,26},size={25,20},proc=ShowNSORTHelp,title="?" |
---|
824 | Button helpButton,help={"Show the help file for sorting and internormalizing 1-D data sets"} |
---|
825 | SetVariable setPath,pos={95,29},size={240,14},title="Path:",fSize=10 |
---|
826 | SetVariable setPath,limits={0,0,0},value= root:myGlobals:NSORT:gPathStr |
---|
827 | SetVariable setPath,help={"The current path to the local folder with SANS data"} |
---|
828 | SetVariable end_1,pos={182,101},size={80,14},proc=SetBegOrEnd,title="End Pts" |
---|
829 | SetVariable end_1,fSize=10,help={"How many points to remove from the high-q end of this dataset"} |
---|
830 | SetVariable end_1,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsEnd1 |
---|
831 | SetVariable end_2,pos={182,176},size={80,14},proc=SetBegOrEnd,title="End Pts" |
---|
832 | SetVariable end_2,fSize=10,help={"How many points to remove from the high-q end of this dataset"} |
---|
833 | SetVariable end_2,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsEnd2 |
---|
834 | SetVariable end_3,pos={182,269},size={80,14},proc=SetBegOrEnd,title="End Pts" |
---|
835 | SetVariable end_3,fSize=10,help={"How many points to remove from the high-q end of this dataset"} |
---|
836 | SetVariable end_3,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsEnd3 |
---|
837 | SetVariable beg_1,pos={182,79},size={80,14},proc=SetBegOrEnd,title="Beg Pts" |
---|
838 | SetVariable beg_1,fSize=10,help={"How many points to remove from the low-q end of this dataset"} |
---|
839 | SetVariable beg_1,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsBeg1 |
---|
840 | SetVariable beg_2,pos={182,155},size={80,14},proc=SetBegOrEnd,title="Beg Pts" |
---|
841 | SetVariable beg_2,fSize=10,help={"How many points to remove from the low-q end of this dataset"} |
---|
842 | SetVariable beg_2,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsBeg2 |
---|
843 | SetVariable beg_3,pos={182,246},size={80,14},proc=SetBegOrEnd,title="Beg Pts" |
---|
844 | SetVariable beg_3,fSize=10,help={"How many points to remove from the low-q end of this dataset"} |
---|
845 | SetVariable beg_3,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsBeg3 |
---|
846 | Button DoCombine,pos={13,382},size={160,20},proc=WriteNSORTFileButton,title="Write Combined File" |
---|
847 | Button DoCombine,help={"Combine and normalize the selected files as specifed"} |
---|
848 | SetVariable scale_12,pos={159,305},size={160,14},proc=SetScale_12,title="Mult factor 1-2" |
---|
849 | SetVariable scale_12,fSize=10,help={"Factor that will multiply medium-q set to scale to low-q set"} |
---|
850 | SetVariable scale_12,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gScale1_2 |
---|
851 | SetVariable scale_23,pos={159,325},size={160,14},proc=SetScale_23,title="Mult factor 2-3" |
---|
852 | SetVariable scale_23,fSize=10,help={"Factor that will multiply high-q set to scale to medium-q set"} |
---|
853 | SetVariable scale_23,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gScale2_3 |
---|
854 | CheckBox check1,pos={5,105},size={160,20},proc=CheckProc,title="Normalize to this file",value=1 |
---|
855 | CheckBox check1,help={"If checked, the combined dataset will be normalized to this dataset"} |
---|
856 | CheckBox check2,pos={5,185},size={160,20},proc=CheckProc,title="Normalize to this file",value=0 |
---|
857 | CheckBox check2,help={"If checked, the combined dataset will be normalized to this dataset"} |
---|
858 | CheckBox check3,pos={4,270},size={160,20},proc=CheckProc,title="Normalize to this file",value=0 |
---|
859 | CheckBox check3,help={"If checked, the combined dataset will be normalized to this dataset"} |
---|
860 | PopupMenu popup_1,pos={6,77},size={99,19},proc=LowQPopMenuProc |
---|
861 | PopupMenu popup_1,mode=1,value= #"root:myGlobals:NSORT:gDataPopList" |
---|
862 | PopupMenu popup_1,help={"Choose the dataset with the lowest overall q-value (longest detector distance)"} |
---|
863 | PopupMenu popup_2,pos={6,153},size={99,19},proc=MedQPopMenuProc |
---|
864 | PopupMenu popup_2,mode=1,value= #"root:myGlobals:NSORT:gDataPopList_3" |
---|
865 | PopupMenu popup_2,help={"Choose the dataset with the intermediate q-values (\"medium\" detector distance)"} |
---|
866 | PopupMenu popup_3,pos={6,239},size={99,19},proc=HighQPopMenuProc |
---|
867 | PopupMenu popup_3,mode=1,value= #"root:myGlobals:NSORT:gDataPopList_3" |
---|
868 | PopupMenu popup_3,help={"Choose the dataset with the highest overall q-value (shortest detector distance), or NONE if no third set desired"} |
---|
869 | CheckBox AutoCheck,pos={14,310},size={100,20},title="Auto Scale",value=1 |
---|
870 | CheckBox AutoCheck,help={"If checked, the scale factor will be automatically determined, if not checked, the current values in the fields will be used"} |
---|
871 | // CheckBox check_0,pos={282,91},size={80,20},title="Update ?",value=1 |
---|
872 | // CheckBox check_0,help={"If checked, the list of data files will be updated from disk, unchecked (faster) will not refresh the list"} |
---|
873 | // CheckBox check_1,pos={282,174},size={80,20},title="Update ?",value=1 |
---|
874 | // CheckBox check_1,help={"If checked, the list of data files will be updated from disk, unchecked (faster) will not refresh the list"} |
---|
875 | // CheckBox check_2,pos={282,257},size={80,20},title="Update ?",value=1 |
---|
876 | // CheckBox check_2,help={"If checked, the list of data files will be updated from disk, unchecked (faster) will not refresh the list"} |
---|
877 | EndMacro |
---|
878 | |
---|
879 | //sets the scale factor (multiplicative) between sets 1 and 2 |
---|
880 | //re-sets the global variable |
---|
881 | // |
---|
882 | Function SetScale_12(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
883 | String ctrlName |
---|
884 | Variable varNum |
---|
885 | String varStr |
---|
886 | String varName |
---|
887 | |
---|
888 | Variable/G root:myGlobals:NSORT:gScale1_2 = varNum |
---|
889 | |
---|
890 | End |
---|
891 | |
---|
892 | //sets the scale factor (multiplicative) between sets 2 and 3 |
---|
893 | //re-sets the global variable |
---|
894 | // |
---|
895 | Function SetScale_23(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
896 | String ctrlName |
---|
897 | Variable varNum |
---|
898 | String varStr |
---|
899 | String varName |
---|
900 | |
---|
901 | Variable/G root:myGlobals:NSORT:gScale2_3 = varNum |
---|
902 | End |
---|
903 | |
---|
904 | //control procedures for the checkboxes to specify which file is to be |
---|
905 | //held fixed (so all other files are normalized to the checked file |
---|
906 | //the three checkboxes behave as "radio buttons" - only one can be checked |
---|
907 | // |
---|
908 | Function CheckProc(ctrlName,checked) : CheckBoxControl |
---|
909 | String ctrlName |
---|
910 | Variable checked |
---|
911 | |
---|
912 | //controls the three checkboxes to act as "radio buttons" to have only one file to |
---|
913 | //normalize to. |
---|
914 | //all three boxes should call this routine |
---|
915 | |
---|
916 | //do the "radio button control" |
---|
917 | do |
---|
918 | if(cmpstr(ctrlName,"check2") == 0) |
---|
919 | CheckBox check1 value=0 |
---|
920 | CheckBox check2 value=1 |
---|
921 | CheckBox check3 value=0 |
---|
922 | Variable/G root:myGlobals:NSORT:gNormToNum = 2 |
---|
923 | break |
---|
924 | Endif |
---|
925 | if(cmpstr(ctrlName,"check3") == 0) |
---|
926 | CheckBox check1 value=0 |
---|
927 | CheckBox check2 value=0 |
---|
928 | CheckBox check3 value=1 |
---|
929 | Variable/G root:myGlobals:NSORT:gNormToNum = 3 |
---|
930 | break |
---|
931 | Endif |
---|
932 | //default case is normalize to file1 |
---|
933 | CheckBox check1 value=1 |
---|
934 | CheckBox check2 value=0 |
---|
935 | CheckBox check3 value=0 |
---|
936 | Variable/G root:myGlobals:NSORT:gNormToNum = 1 |
---|
937 | While(0) |
---|
938 | ControlUpdate/A/W=NSORT_Panel |
---|
939 | |
---|
940 | End |
---|
941 | |
---|
942 | //when menu is popped, it gets a valid list to display and updates the control |
---|
943 | //**for speed, refreshes list only if checkbox is checked |
---|
944 | // |
---|
945 | // 2002- always refreshes, as new (fast) filter is used |
---|
946 | Function LowQPopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
947 | String ctrlName |
---|
948 | Variable popNum |
---|
949 | String popStr |
---|
950 | |
---|
951 | //only update the popup if the "update" checkbox is checked |
---|
952 | //to improve speed |
---|
953 | // Variable checked = 0 |
---|
954 | // ControlInfo check_0 |
---|
955 | // checked = V_value |
---|
956 | |
---|
957 | // If(checked) |
---|
958 | String/G root:myGlobals:NSORT:gDataPopList = filterButtonProc("") |
---|
959 | ControlUpdate popup_1 |
---|
960 | // Endif |
---|
961 | |
---|
962 | End |
---|
963 | |
---|
964 | //when menu is popped, it gets a valid list to display and updates the control |
---|
965 | //**for speed, refreshes list only if checkbox is checked |
---|
966 | // |
---|
967 | Function MedQPopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
968 | String ctrlName |
---|
969 | Variable popNum |
---|
970 | String popStr |
---|
971 | |
---|
972 | //only update the popup if the "update" checkbox is checked |
---|
973 | //to improve speed |
---|
974 | // Variable checked = 0 |
---|
975 | // ControlInfo check_1 |
---|
976 | // checked = V_value |
---|
977 | |
---|
978 | // If(checked) |
---|
979 | String/G root:myGlobals:NSORT:gDataPopList_3 = "none;" + filterButtonProc("") |
---|
980 | ControlUpdate popup_2 |
---|
981 | if(cmpstr(popStr,"none")==0) |
---|
982 | PopupMenu popup_3,mode=1 //force "none" (item #1) to be the selection |
---|
983 | CheckBox AutoCheck,value=0 //un-check the auto-scale checkbox |
---|
984 | DoAlert 0,"You have only one data set. Auto Scaling has been unchecked and Mult Factor 1-2 will be applied to your data. Remember to re-check this as needed"// remind the user of this fact |
---|
985 | RemoveFromGraph/Z MedQSet_i,TrimMedQSet_i,HighQSet_i,TrimHighQSet_i //remove the data from the graph |
---|
986 | Endif |
---|
987 | //endif |
---|
988 | End |
---|
989 | |
---|
990 | //when menu is popped, it gets a valid list to display and updates the control |
---|
991 | // - will be different, since set 3 can also be "none" if only 2 sets |
---|
992 | //are to be NSORTed |
---|
993 | //**for speed, refreshes list only if checkbox is checked |
---|
994 | // |
---|
995 | Function HighQPopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl |
---|
996 | String ctrlName |
---|
997 | Variable popNum |
---|
998 | String popStr |
---|
999 | |
---|
1000 | //only update the popup if the "update" checkbox is checked |
---|
1001 | //to improve speed |
---|
1002 | // Variable checked = 0 |
---|
1003 | // ControlInfo check_2 |
---|
1004 | // checked = V_value |
---|
1005 | |
---|
1006 | // If(checked) |
---|
1007 | //add the option "none" to the file list (which should already end with a semicolon) |
---|
1008 | String/G root:myGlobals:NSORT:gDataPopList_3 = "none;" + filterButtonProc("") |
---|
1009 | |
---|
1010 | ControlUpdate popup_3 |
---|
1011 | if(cmpstr(popStr,"none")==0) |
---|
1012 | RemoveFromGraph/Z HighQSet_i,TrimHighQSet_i //remove the data from the graph |
---|
1013 | Endif |
---|
1014 | ControlInfo popup_2 |
---|
1015 | if(cmpstr(S_Value,"none")==0) |
---|
1016 | PopupMenu popup_3,mode=1 //force "none" (item #1) to be the selection if medium is none |
---|
1017 | endif |
---|
1018 | // Endif |
---|
1019 | |
---|
1020 | End |
---|
1021 | |
---|
1022 | //function returning a string (list) of semicolon separated filenames |
---|
1023 | //that are not version numbers, and not raw data files |
---|
1024 | //(can't really pare out other files any better - trying to just get ascii I vs. q) |
---|
1025 | //works in folder specified by catPathName, (abort if it doesn't exist) |
---|
1026 | // |
---|
1027 | //***** UNUSED ******** - simpler fileFilter is used to simply filter out the raw data |
---|
1028 | // |
---|
1029 | Function/S GetValidNSORTPopupList() |
---|
1030 | |
---|
1031 | String list = "none;something;" |
---|
1032 | |
---|
1033 | PathInfo catPathName |
---|
1034 | String path = S_path |
---|
1035 | if(V_flag == 0) |
---|
1036 | Abort "path does not exist - use Pick Path button" |
---|
1037 | Endif |
---|
1038 | |
---|
1039 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
1040 | |
---|
1041 | //trim version numbers from list |
---|
1042 | Variable num = ItemsInList(list,";") |
---|
1043 | Variable ii,isRAW |
---|
1044 | String item = "",listCopy = "", fullName = "",partialName = "" |
---|
1045 | |
---|
1046 | ii=1 |
---|
1047 | do |
---|
1048 | item = num2str(ii) |
---|
1049 | list = RemoveFromList(item,list,";") |
---|
1050 | ii+=1 |
---|
1051 | while (ii<12) |
---|
1052 | |
---|
1053 | //trim raw data files from list |
---|
1054 | listCopy = list //scan through items in copy, change list |
---|
1055 | num = ItemsInList(listCopy,";") //get the new number of items in the list |
---|
1056 | ii=0 |
---|
1057 | do |
---|
1058 | //build valid fileName |
---|
1059 | item = StringFromList(ii,listCopy,";") |
---|
1060 | if (strlen(item) !=0 ) |
---|
1061 | partialName = FindValidFileName(item) |
---|
1062 | if(strlen(partialName) !=0) //non-null return from FindValidFileName() |
---|
1063 | fullName = path + partialName |
---|
1064 | //check if RAW, if so, remove from list |
---|
1065 | isRAW = CheckIfRAWData(fullName) |
---|
1066 | if(isRAW) |
---|
1067 | list = RemoveFromList(item,list,";") |
---|
1068 | Endif |
---|
1069 | Endif |
---|
1070 | Endif |
---|
1071 | ii+=1 |
---|
1072 | While(ii<num) |
---|
1073 | |
---|
1074 | return list |
---|
1075 | End |
---|
1076 | |
---|
1077 | //be sure to use the "Trim.." datasets that have had the bad points removed |
---|
1078 | //and then do the scaling based on the choices in the panel |
---|
1079 | //input (auto) is a switch |
---|
1080 | // |
---|
1081 | Function DoAutoScaleFromPanel(auto) |
---|
1082 | Variable auto //if auto == 1, do the scaling, if 0, use manual scale values |
---|
1083 | |
---|
1084 | NVAR normTo = root:myGlobals:NSORT:gNormToNum |
---|
1085 | Variable err=0,setNum,norm12,norm23 |
---|
1086 | String fileStr="",tempName="",name1="",name2="",name3="",normToStr="" |
---|
1087 | |
---|
1088 | //Set the number of output columns |
---|
1089 | Variable numOutputColumns = 0 |
---|
1090 | |
---|
1091 | NVAR Columns1 = root:myGlobals:NSORT:gColumns1 |
---|
1092 | NVAR Columns2 = root:myGlobals:NSORT:gColumns2 |
---|
1093 | NVAR Columns3 = root:myGlobals:NSORT:gColumns3 |
---|
1094 | if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) ) |
---|
1095 | numOutputColumns = 3 |
---|
1096 | else |
---|
1097 | if( (Columns1 == 6) && (Columns2 == 6) && ((Columns3 == 0) || (Columns3 == 6)) ) |
---|
1098 | numOutputColumns = 6 |
---|
1099 | endif |
---|
1100 | endif |
---|
1101 | |
---|
1102 | //rescale 1-2 |
---|
1103 | |
---|
1104 | //load file1 |
---|
1105 | ControlInfo $"popup_1" |
---|
1106 | fileStr = S_Value |
---|
1107 | name1 = fileStr |
---|
1108 | setNum = 1 |
---|
1109 | //get a valid file based on this partialName and catPathName |
---|
1110 | tempName = FindValidFilename(fileStr) |
---|
1111 | |
---|
1112 | //prepend path to tempName for read routine |
---|
1113 | PathInfo catPathName |
---|
1114 | tempName = S_path + tempName |
---|
1115 | err = LoadDataForNSORT(tempName,setNum) |
---|
1116 | //////end load file1 |
---|
1117 | |
---|
1118 | //load file2 |
---|
1119 | ControlInfo $"popup_2" |
---|
1120 | fileStr = S_Value |
---|
1121 | name2 = fileStr |
---|
1122 | setNum = 2 |
---|
1123 | //get a valid file based on this partialName and catPathName |
---|
1124 | tempName = FindValidFilename(fileStr) |
---|
1125 | |
---|
1126 | //prepend path to tempName for read routine |
---|
1127 | PathInfo catPathName |
---|
1128 | tempName = S_path + tempName |
---|
1129 | err = LoadDataForNSORT(tempName,setNum) |
---|
1130 | //////end load file2 |
---|
1131 | |
---|
1132 | //load file3 , if necessary |
---|
1133 | ControlInfo $"popup_3" |
---|
1134 | fileStr = S_Value |
---|
1135 | name3 = fileStr |
---|
1136 | setNum = 3 |
---|
1137 | if(cmpstr(fileStr,"none") == 0) |
---|
1138 | //do nothing |
---|
1139 | else |
---|
1140 | //get a valid file based on this partialName and catPathName |
---|
1141 | tempName = FindValidFilename(fileStr) |
---|
1142 | |
---|
1143 | //prepend path to tempName for read routine |
---|
1144 | PathInfo catPathName |
---|
1145 | tempName = S_path + tempName |
---|
1146 | err = LoadDataForNSORT(tempName,setNum) |
---|
1147 | Endif |
---|
1148 | //////end load file3 |
---|
1149 | |
---|
1150 | //assign filename of file to normalize to |
---|
1151 | if(normTo == 1) |
---|
1152 | normToStr = name1 |
---|
1153 | else |
---|
1154 | if(normTo == 2) |
---|
1155 | normToStr = name2 |
---|
1156 | else |
---|
1157 | normToStr = name3 |
---|
1158 | Endif |
---|
1159 | Endif |
---|
1160 | |
---|
1161 | Variable n1,n2,n12,num2 |
---|
1162 | Variable n3,n123 |
---|
1163 | |
---|
1164 | if(numOutputColumns == 3) //Start the 3-column specific stuff here. |
---|
1165 | //order points in sets 1-2, indexing overlap region |
---|
1166 | //put result in temporary waves |
---|
1167 | WaveStats/Q $"TrimLowQSet_q" |
---|
1168 | n1 = V_npnts |
---|
1169 | WaveStats/Q $"TrimMedQSet_q" |
---|
1170 | n2 = V_npnts |
---|
1171 | n12 = n1+ n2 |
---|
1172 | |
---|
1173 | Make/O/N=(n12) q12,i12,sig12 |
---|
1174 | WAVE lowq = $"TrimLowQSet_q" |
---|
1175 | WAVE medq = $"TrimMedQSet_q" |
---|
1176 | WAVE lowi = $"TrimLowQSet_i" |
---|
1177 | WAVE medi = $"TrimMedQSet_i" |
---|
1178 | WAVE lows = $"TrimLowQSet_s" |
---|
1179 | WAVE meds = $"TrimMedQSet_s" |
---|
1180 | q12[0,n1-1] = lowq[p] |
---|
1181 | q12[n1,n1+n2-1]= medq[p-n1] |
---|
1182 | i12[0,n1-1] = lowi[p] |
---|
1183 | i12[n1,n1+n2-1]= medi[p-n1] |
---|
1184 | sig12[0,n1-1] = lows[p] |
---|
1185 | sig12[n1,n1+n2-1]= meds[p-n1] |
---|
1186 | |
---|
1187 | Sort q12, q12,i12,sig12 |
---|
1188 | ///////////////// |
---|
1189 | |
---|
1190 | //find the maximum point number of set 2 in the overlap region |
---|
1191 | FindLevel/P/Q medq,(lowq[n1-1]) |
---|
1192 | num2 = trunc(V_levelX) |
---|
1193 | //Print "num2 = ",num2 |
---|
1194 | |
---|
1195 | if (auto) |
---|
1196 | //there must be overlap points to use auto-scaling |
---|
1197 | if(numtype(num2) != 0) |
---|
1198 | Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." |
---|
1199 | endif |
---|
1200 | //do auto-scaling of data |
---|
1201 | norm12 = GetScalingInOverlap(num2,lowq,lowi,medq,medi) |
---|
1202 | //Set the global variable for the 1-2 scale factor |
---|
1203 | Variable/G root:myGlobals:NSORT:gScale1_2 = norm12 |
---|
1204 | else |
---|
1205 | //use the value from the panel ( which is the global) |
---|
1206 | NVAR temp12 = root:myGlobals:NSORT:gScale1_2 |
---|
1207 | norm12 = temp12 |
---|
1208 | Endif |
---|
1209 | |
---|
1210 | If(normTo== 2) |
---|
1211 | //normalize to second file, so multiply 1st by 1/norm |
---|
1212 | norm12 = 1/norm12 |
---|
1213 | lowi *= norm12 |
---|
1214 | lows *= norm12 |
---|
1215 | else |
---|
1216 | //normalize to first file, OR THIRD FILE so multiply 2nd by norm |
---|
1217 | medi *= norm12 |
---|
1218 | meds *= norm12 |
---|
1219 | Endif |
---|
1220 | |
---|
1221 | //Print "NSORT-ed ",name1," + ", name2 |
---|
1222 | //Print "normalized to ",normTo |
---|
1223 | //Print "multiplicative factor = ",norm12 |
---|
1224 | |
---|
1225 | |
---|
1226 | //Make the combined, scaled dataset by overwriting the old sets |
---|
1227 | Make/O/N=(n12) q12,i12,sig12 |
---|
1228 | q12[0,n1-1] = lowq[p] |
---|
1229 | q12[n1,n1+n2-1]= medq[p-n1] |
---|
1230 | i12[0,n1-1] = lowi[p] |
---|
1231 | i12[n1,n1+n2-1]= medi[p-n1] |
---|
1232 | sig12[0,n1-1] = lows[p] |
---|
1233 | sig12[n1,n1+n2-1]= meds[p-n1] |
---|
1234 | |
---|
1235 | Sort q12, q12,i12,sig12 |
---|
1236 | //at this point 1-2 are combined |
---|
1237 | //do we need to continue, or write out the set here and stop? |
---|
1238 | if(cmpstr(name3,"none") == 0) |
---|
1239 | //stop here |
---|
1240 | norm23 = 1 //norm23 was not used |
---|
1241 | Variable/G root:myGlobals:NSORT:gScale2_3 = 1 |
---|
1242 | //If any of them have three columns write three column data |
---|
1243 | err=Write3ColNSORTedFile(q12,i12,sig12,name1,name2,name3,normToStr,norm12,norm23) |
---|
1244 | //cleanup waves before exiting |
---|
1245 | KillWaves/Z q12,i12,sig12 |
---|
1246 | return err |
---|
1247 | Endif |
---|
1248 | |
---|
1249 | //need to add the third file... which was already loaded at the top of the function |
---|
1250 | ///// |
---|
1251 | //order points in sets 12-3, indexing overlap region |
---|
1252 | //put result in temporary waves |
---|
1253 | WaveStats/Q q12 |
---|
1254 | n12 = V_npnts |
---|
1255 | WaveStats/Q $"TrimHighQSet_q" |
---|
1256 | n3 = V_npnts |
---|
1257 | n123 = n12+ n3 |
---|
1258 | |
---|
1259 | Make/O/N=(n123) q123,i123,sig123 |
---|
1260 | WAVE highq = $"TrimHighQSet_q" |
---|
1261 | WAVE highi = $"TrimHighQSet_i" |
---|
1262 | WAVE highs = $"TrimHighQSet_s" |
---|
1263 | |
---|
1264 | q123[0,n12-1] = q12[p] |
---|
1265 | q123[n1,n12+n3-1]= highq[p-n12] |
---|
1266 | i123[0,n12-1] = i12[p] |
---|
1267 | i123[n1,n12+n3-1]= highi[p-n12] |
---|
1268 | sig123[0,n12-1] = sig12[p] |
---|
1269 | sig123[n1,n12+n3-1]= highs[p-n12] |
---|
1270 | |
---|
1271 | Sort q123, q123,i123,sig123 |
---|
1272 | ///////////////// |
---|
1273 | |
---|
1274 | //old method |
---|
1275 | //first point of overlap region (from set 3) |
---|
1276 | //FindLevel/P/Q q123,(highq[0]) |
---|
1277 | //Variable firstOverlapPt = V_levelX |
---|
1278 | //last point of overlap region (from set 12) |
---|
1279 | //FindLevel/P/Q q123,(q12[n12-1]) |
---|
1280 | //Variable lastOverlapPt = V_levelX |
---|
1281 | //end old method, not used |
---|
1282 | |
---|
1283 | //find the maximum point number of set 2 in the overlap region |
---|
1284 | FindLevel/P/Q highq,(q12[n12-1]) |
---|
1285 | num2 = trunc(V_levelX) |
---|
1286 | //Print "num2 = ",num2 |
---|
1287 | |
---|
1288 | if (auto) |
---|
1289 | //there must be overlap points to use auto-scaling |
---|
1290 | if(numtype(num2) != 0) |
---|
1291 | Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." |
---|
1292 | endif |
---|
1293 | //do auto-scaling of data |
---|
1294 | norm23 = GetScalingInOverlap(num2,q12,i12,highq,highi) |
---|
1295 | //Set the global variable for the 12 - 3 scale factor |
---|
1296 | Variable/G root:myGlobals:NSORT:gScale2_3 = norm23 |
---|
1297 | else |
---|
1298 | //use the value from the panel ( which is the global) |
---|
1299 | NVAR temp23 = root:myGlobals:NSORT:gScale2_3 |
---|
1300 | norm23 = temp23 |
---|
1301 | Endif |
---|
1302 | |
---|
1303 | If( (normTo== 1) || (normTo ==2) ) |
---|
1304 | //normalize to first or second file, so multiply third by norm23 |
---|
1305 | highi *= norm23 |
---|
1306 | highs *= norm23 |
---|
1307 | else |
---|
1308 | //normalize to THIRD file, 1-2 by 1/norm23 |
---|
1309 | norm23 = 1/norm23 |
---|
1310 | i12 *= norm23 |
---|
1311 | sig12 *= norm23 |
---|
1312 | Endif |
---|
1313 | |
---|
1314 | //Print "NSORT-ed ",name1," + ", name2, " + ", name3 |
---|
1315 | //Print "normalized to ",normTo |
---|
1316 | //Print "multiplicative factor 1-2 = ",norm12," multiplicative factor 12 - 3 = ",norm23 |
---|
1317 | |
---|
1318 | |
---|
1319 | Make/O/N=(n123) q123,i123,sig123 |
---|
1320 | q123[0,n12-1] = q12[p] |
---|
1321 | q123[n12,n12+n3-1]= highq[p-n12] |
---|
1322 | i123[0,n12-1] = i12[p] |
---|
1323 | i123[n12,n12+n3-1]= highi[p-n12] |
---|
1324 | sig123[0,n12-1] = sig12[p] |
---|
1325 | sig123[n12,n12+n3-1]= highs[p-n12] |
---|
1326 | |
---|
1327 | Sort q123, q123,i123,sig123 |
---|
1328 | //at this point 12 - 3 are combined |
---|
1329 | //write out the set here and stop |
---|
1330 | |
---|
1331 | err=Write3ColNSORTedFile(q123,i123,sig123,name1,name2,name3,normToStr,norm12,norm23) |
---|
1332 | //cleanup waves before exiting |
---|
1333 | KillWaves/Z q12,i12,sig12,q123,i123,sig123 |
---|
1334 | //combined dataset will already be displayed if the NSORT_Graph is open |
---|
1335 | |
---|
1336 | //////////////// |
---|
1337 | return err |
---|
1338 | endif // End the 3-column specific stuff here |
---|
1339 | |
---|
1340 | if(numOutputColumns == 6) // Start the 6-column specific stuff here |
---|
1341 | //order points in sets 1-2, indexing overlap region |
---|
1342 | //put result in temporary waves |
---|
1343 | WaveStats/Q $"TrimLowQSet_q" |
---|
1344 | n1 = V_npnts |
---|
1345 | WaveStats/Q $"TrimMedQSet_q" |
---|
1346 | n2 = V_npnts |
---|
1347 | n12 = n1+ n2 |
---|
1348 | |
---|
1349 | Make/O/N=(n12) q12,i12,sig12,sq12,qb12,fs12 |
---|
1350 | WAVE lowq = $"TrimLowQSet_q" |
---|
1351 | WAVE medq = $"TrimMedQSet_q" |
---|
1352 | WAVE lowi = $"TrimLowQSet_i" |
---|
1353 | WAVE medi = $"TrimMedQSet_i" |
---|
1354 | WAVE lows = $"TrimLowQSet_s" |
---|
1355 | WAVE meds = $"TrimMedQSet_s" |
---|
1356 | WAVE lowsq = $"TrimLowQSet_sq" |
---|
1357 | WAVE medsq = $"TrimMedQSet_sq" |
---|
1358 | WAVE lowqb = $"TrimLowQSet_qb" |
---|
1359 | WAVE medqb = $"TrimMedQSet_qb" |
---|
1360 | WAVE lowfs = $"TrimLowQSet_fs" |
---|
1361 | WAVE medfs = $"TrimMedQSet_fs" |
---|
1362 | |
---|
1363 | q12[0,n1-1] = lowq[p] |
---|
1364 | q12[n1,n1+n2-1]= medq[p-n1] |
---|
1365 | i12[0,n1-1] = lowi[p] |
---|
1366 | i12[n1,n1+n2-1]= medi[p-n1] |
---|
1367 | sig12[0,n1-1] = lows[p] |
---|
1368 | sig12[n1,n1+n2-1]= meds[p-n1] |
---|
1369 | sq12[0,n1-1] = lowsq[p] |
---|
1370 | sq12[n1,n1+n2-1]= medsq[p-n1] |
---|
1371 | qb12[0,n1-1] = lowqb[p] |
---|
1372 | qb12[n1,n1+n2-1]= medqb[p-n1] |
---|
1373 | fs12[0,n1-1] = lowfs[p] |
---|
1374 | fs12[n1,n1+n2-1]= medfs[p-n1] |
---|
1375 | |
---|
1376 | Sort q12, q12,i12,sig12,sq12,qb12,fs12 |
---|
1377 | ///////////////// |
---|
1378 | |
---|
1379 | //find the maximum point number of set 2 in the overlap region |
---|
1380 | FindLevel/P/Q medq,(lowq[n1-1]) |
---|
1381 | num2 = trunc(V_levelX) |
---|
1382 | //Print "num2 = ",num2 |
---|
1383 | |
---|
1384 | if (auto) |
---|
1385 | //there must be overlap points to use auto-scaling |
---|
1386 | if(numtype(num2) != 0) |
---|
1387 | Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." |
---|
1388 | endif |
---|
1389 | //do auto-scaling of data |
---|
1390 | norm12 = GetScalingInOverlap(num2,lowq,lowi,medq,medi) |
---|
1391 | //Set the global variable for the 1-2 scale factor |
---|
1392 | Variable/G root:myGlobals:NSORT:gScale1_2 = norm12 |
---|
1393 | else |
---|
1394 | //use the value from the panel ( which is the global) |
---|
1395 | NVAR temp12 = root:myGlobals:NSORT:gScale1_2 |
---|
1396 | norm12 = temp12 |
---|
1397 | Endif |
---|
1398 | |
---|
1399 | If(normTo== 2) |
---|
1400 | //normalize to second file, so multiply 1st by 1/norm |
---|
1401 | norm12 = 1/norm12 |
---|
1402 | lowi *= norm12 |
---|
1403 | lows *= norm12 |
---|
1404 | else |
---|
1405 | //normalize to first file, OR THIRD FILE so multiply 2nd by norm |
---|
1406 | medi *= norm12 |
---|
1407 | meds *= norm12 |
---|
1408 | Endif |
---|
1409 | |
---|
1410 | //Print "NSORT-ed ",name1," + ", name2 |
---|
1411 | //Print "normalized to ",normTo |
---|
1412 | //Print "multiplicative factor = ",norm12 |
---|
1413 | |
---|
1414 | |
---|
1415 | //Make the combined, scaled dataset by overwriting the old sets |
---|
1416 | Make/O/N=(n12) q12,i12,sig12,sq12,qb12,fs12 |
---|
1417 | q12[0,n1-1] = lowq[p] |
---|
1418 | q12[n1,n1+n2-1]= medq[p-n1] |
---|
1419 | i12[0,n1-1] = lowi[p] |
---|
1420 | i12[n1,n1+n2-1]= medi[p-n1] |
---|
1421 | sig12[0,n1-1] = lows[p] |
---|
1422 | sig12[n1,n1+n2-1]= meds[p-n1] |
---|
1423 | sq12[0,n1-1] = lowsq[p] |
---|
1424 | sq12[n1,n1+n2-1]= medsq[p-n1] |
---|
1425 | qb12[0,n1-1] = lowqb[p] |
---|
1426 | qb12[n1,n1+n2-1]= medqb[p-n1] |
---|
1427 | fs12[0,n1-1] = lowfs[p] |
---|
1428 | fs12[n1,n1+n2-1]= medfs[p-n1] |
---|
1429 | |
---|
1430 | Sort q12, q12,i12,sig12,sq12,qb12,fs12 |
---|
1431 | //at this point 1-2 are combined |
---|
1432 | //do we need to continue, or write out the set here and stop? |
---|
1433 | if(cmpstr(name3,"none") == 0) |
---|
1434 | //stop here |
---|
1435 | norm23 = 1 //norm23 was not used |
---|
1436 | Variable/G root:myGlobals:NSORT:gScale2_3 = 1 |
---|
1437 | //If any of them have three columns write three column data |
---|
1438 | err=Write6ColNSORTedFile(q12,i12,sig12,sq12,qb12,fs12,name1,name2,name3,normToStr,norm12,norm23) |
---|
1439 | //cleanup waves before exiting |
---|
1440 | KillWaves/Z q12,i12,sig12,sq12,qb12,fs12 |
---|
1441 | return err |
---|
1442 | Endif |
---|
1443 | |
---|
1444 | //need to add the third file... which was already loaded at the top of the function |
---|
1445 | ///// |
---|
1446 | //order points in sets 12-3, indexing overlap region |
---|
1447 | //put result in temporary waves |
---|
1448 | WaveStats/Q q12 |
---|
1449 | n12 = V_npnts |
---|
1450 | WaveStats/Q $"TrimHighQSet_q" |
---|
1451 | n3 = V_npnts |
---|
1452 | n123 = n12+ n3 |
---|
1453 | |
---|
1454 | Make/O/N=(n123) q123,i123,sig123,sq123,qb123,fs123 |
---|
1455 | WAVE highq = $"TrimHighQSet_q" |
---|
1456 | WAVE highi = $"TrimHighQSet_i" |
---|
1457 | WAVE highs = $"TrimHighQSet_s" |
---|
1458 | WAVE highsq = $"TrimHighQSet_sq" |
---|
1459 | WAVE highqb = $"TrimHighQSet_qb" |
---|
1460 | WAVE highfs = $"TrimHighQSet_fs" |
---|
1461 | |
---|
1462 | q123[0,n12-1] = q12[p] |
---|
1463 | q123[n1,n12+n3-1]= highq[p-n12] |
---|
1464 | i123[0,n12-1] = i12[p] |
---|
1465 | i123[n1,n12+n3-1]= highi[p-n12] |
---|
1466 | sig123[0,n12-1] = sig12[p] |
---|
1467 | sig123[n1,n12+n3-1]= highs[p-n12] |
---|
1468 | sq123[0,n12-1] = sq12[p] |
---|
1469 | sq123[n1,n12+n3-1]= highsq[p-n12] |
---|
1470 | qb123[0,n12-1] = qb12[p] |
---|
1471 | qb123[n1,n12+n3-1]= highqb[p-n12] |
---|
1472 | fs123[0,n12-1] = fs12[p] |
---|
1473 | fs123[n1,n12+n3-1]= highfs[p-n12] |
---|
1474 | |
---|
1475 | Sort q123, q123,i123,sig123,sq123,qb123,fs123 |
---|
1476 | ///////////////// |
---|
1477 | |
---|
1478 | //old method |
---|
1479 | //first point of overlap region (from set 3) |
---|
1480 | //FindLevel/P/Q q123,(highq[0]) |
---|
1481 | //Variable firstOverlapPt = V_levelX |
---|
1482 | //last point of overlap region (from set 12) |
---|
1483 | //FindLevel/P/Q q123,(q12[n12-1]) |
---|
1484 | //Variable lastOverlapPt = V_levelX |
---|
1485 | //end old method, not used |
---|
1486 | |
---|
1487 | //find the maximum point number of set 2 in the overlap region |
---|
1488 | FindLevel/P/Q highq,(q12[n12-1]) |
---|
1489 | num2 = trunc(V_levelX) |
---|
1490 | //Print "num2 = ",num2 |
---|
1491 | |
---|
1492 | if (auto) |
---|
1493 | //there must be overlap points to use auto-scaling |
---|
1494 | if(numtype(num2) != 0) |
---|
1495 | Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." |
---|
1496 | endif |
---|
1497 | //do auto-scaling of data |
---|
1498 | norm23 = GetScalingInOverlap(num2,q12,i12,highq,highi) |
---|
1499 | //Set the global variable for the 12 - 3 scale factor |
---|
1500 | Variable/G root:myGlobals:NSORT:gScale2_3 = norm23 |
---|
1501 | else |
---|
1502 | //use the value from the panel ( which is the global) |
---|
1503 | NVAR temp23 = root:myGlobals:NSORT:gScale2_3 |
---|
1504 | norm23 = temp23 |
---|
1505 | Endif |
---|
1506 | |
---|
1507 | If( (normTo== 1) || (normTo ==2) ) |
---|
1508 | //normalize to first or second file, so multiply third by norm23 |
---|
1509 | highi *= norm23 |
---|
1510 | highs *= norm23 |
---|
1511 | else |
---|
1512 | //normalize to THIRD file, 1-2 by 1/norm23 |
---|
1513 | norm23 = 1/norm23 |
---|
1514 | i12 *= norm23 |
---|
1515 | sig12 *= norm23 |
---|
1516 | Endif |
---|
1517 | |
---|
1518 | //Print "NSORT-ed ",name1," + ", name2, " + ", name3 |
---|
1519 | //Print "normalized to ",normTo |
---|
1520 | //Print "multiplicative factor 1-2 = ",norm12," multiplicative factor 12 - 3 = ",norm23 |
---|
1521 | |
---|
1522 | |
---|
1523 | Make/O/N=(n123) q123,i123,sig123,sq123,qb123,fs123 |
---|
1524 | q123[0,n12-1] = q12[p] |
---|
1525 | q123[n12,n12+n3-1]= highq[p-n12] |
---|
1526 | i123[0,n12-1] = i12[p] |
---|
1527 | i123[n12,n12+n3-1]= highi[p-n12] |
---|
1528 | sig123[0,n12-1] = sig12[p] |
---|
1529 | sig123[n12,n12+n3-1]= highs[p-n12] |
---|
1530 | sq123[0,n12-1] = sq12[p] |
---|
1531 | sq123[n12,n12+n3-1]= highsq[p-n12] |
---|
1532 | qb123[0,n12-1] = qb12[p] |
---|
1533 | qb123[n12,n12+n3-1]= highqb[p-n12] |
---|
1534 | fs123[0,n12-1] = fs12[p] |
---|
1535 | fs123[n12,n12+n3-1]= highfs[p-n12] |
---|
1536 | |
---|
1537 | Sort q123, q123,i123,sig123,sq123,qb123,fs123 |
---|
1538 | //at this point 12 - 3 are combined |
---|
1539 | //write out the set here and stop |
---|
1540 | |
---|
1541 | err=Write6ColNSORTedFile(q123,i123,sig123,sq123,qb123,fs123,name1,name2,name3,normToStr,norm12,norm23) |
---|
1542 | //cleanup waves before exiting |
---|
1543 | KillWaves/Z q12,i12,sig12,sq12,qb12,fs12,q123,i123,sig123,sq123,qb123,fs123 |
---|
1544 | //combined dataset will already be displayed if the NSORT_Graph is open |
---|
1545 | |
---|
1546 | //////////////// |
---|
1547 | return err |
---|
1548 | endif // End the 6-column specific stuff here |
---|
1549 | |
---|
1550 | End |
---|
1551 | |
---|
1552 | //function called byt the popups to get a file list of data that can be sorted |
---|
1553 | // this procedure simply removes the raw data files from the string - there |
---|
1554 | //can be lots of other junk present, but this is very fast... |
---|
1555 | // |
---|
1556 | // could also use the alternate procedure of keeping only file with the proper extension |
---|
1557 | // |
---|
1558 | // another possibility is to get a listing of the text files, but is unreliable on |
---|
1559 | // Windows, where the data file must be .txt (and possibly OSX) |
---|
1560 | // |
---|
1561 | Function/S filterButtonProc(ctrlName) |
---|
1562 | String ctrlName |
---|
1563 | |
---|
1564 | String list="",newList="",item="" |
---|
1565 | Variable num,ii |
---|
1566 | |
---|
1567 | //check for the path |
---|
1568 | PathInfo catPathName |
---|
1569 | if(V_Flag==0) |
---|
1570 | DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" |
---|
1571 | Return("") |
---|
1572 | Endif |
---|
1573 | |
---|
1574 | list = IndexedFile(catpathName,-1,"????") |
---|
1575 | num=ItemsInList(list,";") |
---|
1576 | //print "num = ",num |
---|
1577 | for(ii=(num-1);ii>=0;ii-=1) |
---|
1578 | item = StringFromList(ii, list ,";") |
---|
1579 | //simply remove all that are not raw data files (SA1 SA2 SA3) |
---|
1580 | if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") ) |
---|
1581 | if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files |
---|
1582 | newlist += item + ";" |
---|
1583 | endif |
---|
1584 | endif |
---|
1585 | endfor |
---|
1586 | //remove VAX version numbers |
---|
1587 | newList = RemoveVersNumsFromList(newList) |
---|
1588 | //sort |
---|
1589 | newList = SortList(newList,";",0) |
---|
1590 | |
---|
1591 | return newlist |
---|
1592 | End |
---|
1593 | |
---|
1594 | ///////////////////////////////////////////////////////////// |
---|
1595 | //testing, may speed up NSORT |
---|
1596 | Proc Set3NSORTFiles(low,med,hi,prefix) |
---|
1597 | Variable low=1,med=2,hi=3 |
---|
1598 | String prefix="LIPID" |
---|
1599 | |
---|
1600 | //make strings from the numbers |
---|
1601 | String absStr="" |
---|
1602 | Variable popNum |
---|
1603 | DoWindow/F NSORT_Panel |
---|
1604 | |
---|
1605 | //lowQ menu |
---|
1606 | absStr = prefix+ThreeDigitString(low)+".ABS" |
---|
1607 | popNum = 1+WhichListItem(absStr,root:myGlobals:NSORT:gDataPopList,";",0) |
---|
1608 | PopupMenu popup_1,win=NSORT_Panel,mode=(popNum) |
---|
1609 | //medQ (a different list for the popup) |
---|
1610 | absStr = prefix+ThreeDigitString(med)+".ABS" |
---|
1611 | popNum = 1+WhichListItem(absStr,root:myGlobals:NSORT:gDataPopList_3,";",0) |
---|
1612 | PopupMenu popup_2,win=NSORT_Panel,mode=(popNum) |
---|
1613 | //highQ (same pop list as medQ) |
---|
1614 | if(hi != 0) |
---|
1615 | absStr = prefix+ThreeDigitString(hi)+".ABS" |
---|
1616 | popNum = 1+WhichListItem(absStr,root:myGlobals:NSORT:gDataPopList_3,";",0) |
---|
1617 | PopupMenu popup_3,win=NSORT_Panel,mode=(popNum) |
---|
1618 | endif |
---|
1619 | End |
---|
1620 | |
---|
1621 | Function/S ThreeDigitString(num) |
---|
1622 | Variable num |
---|
1623 | |
---|
1624 | //make a three character string of the run number |
---|
1625 | String numStr="" |
---|
1626 | if(num<10) |
---|
1627 | numStr = "00"+num2str(num) |
---|
1628 | else |
---|
1629 | if(num<100) |
---|
1630 | numStr = "0"+num2str(num) |
---|
1631 | else |
---|
1632 | numStr = num2str(num) |
---|
1633 | Endif |
---|
1634 | Endif |
---|
1635 | //Print "numstr = ",numstr |
---|
1636 | return(numstr) |
---|
1637 | End |
---|
1638 | |
---|
1639 | //more beta procedures - to create a table of scattering runs to combine with NSORT |
---|
1640 | Proc CreateTableToCombine() |
---|
1641 | |
---|
1642 | NewDataFolder/O root:myGlobals:CombineTable |
---|
1643 | DoWindow/F CombineTable |
---|
1644 | |
---|
1645 | Make/O/T/N=0 $"root:myGlobals:CombineTable:Filenames" |
---|
1646 | Make/O/T/N=0 $"root:myGlobals:CombineTable:Suffix" |
---|
1647 | Make/O/T/N=0 $"root:myGlobals:CombineTable:Labels" |
---|
1648 | Make/O/D/N=0 $"root:myGlobals:CombineTable:SDD" |
---|
1649 | Make/O/D/N=0 $"root:myGlobals:CombineTable:RunNumber" |
---|
1650 | Make/O/D/N=0 $"root:myGlobals:CombineTable:IsTrans" |
---|
1651 | |
---|
1652 | If(V_Flag==0) |
---|
1653 | BuildCombineTableWindow() |
---|
1654 | ModifyTable width(:myGlobals:CombineTable:SDD)=40 |
---|
1655 | ModifyTable width(:myGlobals:CombineTable:Labels)=180 |
---|
1656 | |
---|
1657 | ModifyTable width(Point)=0 //JUN04, remove point numbers - confuses users since point != run |
---|
1658 | Endif |
---|
1659 | |
---|
1660 | //get a list of all files in the folder, some will be junk version numbers that don't exist |
---|
1661 | String list,partialName,tempName,temp="" |
---|
1662 | list = IndexedFile(catPathName,-1,"????") //get all files in folder |
---|
1663 | Variable numitems,ii,ok |
---|
1664 | |
---|
1665 | //remove version numbers from semicolon-delimited list |
---|
1666 | list = RemoveVersNumsFromList(list) |
---|
1667 | numitems = ItemsInList(list,";") |
---|
1668 | |
---|
1669 | //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS |
---|
1670 | //***version numbers have been removed*** |
---|
1671 | String str,fullName |
---|
1672 | Variable lastPoint |
---|
1673 | ii=0 |
---|
1674 | |
---|
1675 | Make/T/O/N=0 notRAWlist |
---|
1676 | do |
---|
1677 | //get current item in the list |
---|
1678 | partialName = StringFromList(ii, list, ";") |
---|
1679 | //get a valid file based on this partialName and catPathName |
---|
1680 | tempName = FindValidFilename(partialName) |
---|
1681 | If(cmpstr(tempName,"")==0) //a null string was returned |
---|
1682 | //write to notebook that file was not found |
---|
1683 | //if string is not a number, report the error |
---|
1684 | if(str2num(partialName) == NaN) |
---|
1685 | str = "this file was not found: "+partialName+"\r\r" |
---|
1686 | //Notebook CatWin,font="Times",fsize=12,text=str |
---|
1687 | Endif |
---|
1688 | else |
---|
1689 | //prepend path to tempName for read routine |
---|
1690 | PathInfo catPathName |
---|
1691 | FullName = S_path + tempName |
---|
1692 | //make sure the file is really a RAW data file |
---|
1693 | ok = CheckIfRawData(fullName) |
---|
1694 | if (!ok) |
---|
1695 | //write to notebook that file was not a RAW SANS file |
---|
1696 | lastPoint = numpnts(notRAWlist) |
---|
1697 | InsertPoints lastPoint,1,notRAWlist |
---|
1698 | notRAWlist[lastPoint]=tempname |
---|
1699 | else |
---|
1700 | //go write the header information to the Notebook |
---|
1701 | GetHeaderInfoToCombineWave(fullName,tempName) |
---|
1702 | Endif |
---|
1703 | Endif |
---|
1704 | ii+=1 |
---|
1705 | while(ii<numitems) |
---|
1706 | //Now sort them all based on the suffix data (orders them as collected) |
---|
1707 | // SortCombineWaves() |
---|
1708 | // sort by label |
---|
1709 | SortCombineByLabel() |
---|
1710 | // remove the transmission waves |
---|
1711 | // |
---|
1712 | RemoveTransFilesFromCombine() |
---|
1713 | // |
---|
1714 | // make the waves and table for the sets to combine |
---|
1715 | Make/O/N=0 $"root:myGlobals:CombineTable:Low" |
---|
1716 | Make/O/N=0 $"root:myGlobals:CombineTable:Medium" |
---|
1717 | Make/O/N=0 $"root:myGlobals:CombineTable:High" |
---|
1718 | Make/O/T/N=0 $"root:myGlobals:CombineTable:Prefix" |
---|
1719 | Make/O/T/N=0 $"root:myGlobals:CombineTable:SaveName" |
---|
1720 | MakeTableToCombine() |
---|
1721 | |
---|
1722 | End |
---|
1723 | |
---|
1724 | |
---|
1725 | Function RemoveTransFilesFromCombine() |
---|
1726 | Wave/T filenames = $"root:myGlobals:CombineTable:Filenames" |
---|
1727 | Wave/T suffix = $"root:myGlobals:CombineTable:Suffix" |
---|
1728 | Wave/T labels = $"root:myGlobals:CombineTable:Labels" |
---|
1729 | Wave sdd = $"root:myGlobals:CombineTable:SDD" |
---|
1730 | Wave runnum = $"root:myGlobals:CombineTable:RunNumber" |
---|
1731 | Wave isTrans = $"root:myGlobals:CombineTable:IsTrans" |
---|
1732 | |
---|
1733 | Variable num=numpnts(isTrans),ii |
---|
1734 | ii=num-1 |
---|
1735 | do |
---|
1736 | if(isTrans[ii] != 0) |
---|
1737 | DeletePoints ii, 1, filenames,suffix,labels,sdd,runnum,isTrans |
---|
1738 | endif |
---|
1739 | ii-=1 |
---|
1740 | while(ii>=0) |
---|
1741 | return(0) |
---|
1742 | End |
---|
1743 | |
---|
1744 | Function MakeTabletoCombine() |
---|
1745 | |
---|
1746 | Wave low = $"root:myGlobals:CombineTable:Low" |
---|
1747 | Wave medium = $"root:myGlobals:CombineTable:Medium" |
---|
1748 | Wave high = $"root:myGlobals:CombineTable:High" |
---|
1749 | Wave/T prefix = $"root:myGlobals:CombineTable:Prefix" |
---|
1750 | Wave/T saveName = $"root:myGlobals:CombineTable:SaveName" |
---|
1751 | |
---|
1752 | DoWindow/F ToCombine |
---|
1753 | if(V_flag==0) |
---|
1754 | edit Low,Medium,High,Prefix,SaveName as "Run Numbers to Combine" |
---|
1755 | DoWindow/C ToCombine |
---|
1756 | endif |
---|
1757 | AutoPositionWindow/M=1/R=CombineTable toCombine |
---|
1758 | |
---|
1759 | |
---|
1760 | ///// |
---|
1761 | SetWindow kwTopWin hook=CombineTableHook, hookevents=1 // mouse down events |
---|
1762 | |
---|
1763 | end |
---|
1764 | |
---|
1765 | Function BuildCombineTableWindow() |
---|
1766 | Wave/T Filenames = $"root:myGlobals:CombineTable:Filenames" |
---|
1767 | Wave/T Labels = $"root:myGlobals:CombineTable:Labels" |
---|
1768 | Wave SDD = $"root:myGlobals:CombineTable:SDD" |
---|
1769 | Wave/T suffix = $"root:myGlobals:CombineTable:Suffix" |
---|
1770 | Wave runnum = $"root:myGlobals:CombineTable:RunNumber" |
---|
1771 | Wave isTrans = $"root:myGlobals:CombineTable:IsTrans" |
---|
1772 | |
---|
1773 | // Edit Filenames, Labels, DateAndTime, SDD, Lambda, CntTime, TotCnts, CntRate, Transmission, Thickness, XCenter, YCenter, NumAttens as "Files to Combine" |
---|
1774 | Edit Labels, SDD, runNum as "Files to Combine" |
---|
1775 | // SetWindow kwTopWin hook=CombineTableHook, hookevents=1 // mouse down events |
---|
1776 | |
---|
1777 | String name="CombineTable" |
---|
1778 | DoWindow/C $name |
---|
1779 | return(0) |
---|
1780 | End |
---|
1781 | |
---|
1782 | //reads header information and puts it in the appropriate waves for display in the table. |
---|
1783 | //fname is the full path for opening (and reading) information from the file |
---|
1784 | //which alreay was found to exist. sname is the file;vers to be written out, |
---|
1785 | //avoiding the need to re-extract it from fname. |
---|
1786 | Function GetHeaderInfoToCombineWave(fname,sname) |
---|
1787 | String fname,sname |
---|
1788 | |
---|
1789 | String textstr,temp,lbl,date_time,suffix |
---|
1790 | Variable ctime,lambda,sdd,detcnt,cntrate,refNum,trans,thick,xcenter,ycenter,numatten |
---|
1791 | Variable lastPoint, beamstop |
---|
1792 | |
---|
1793 | Wave/T GFilenames = $"root:myGlobals:CombineTable:Filenames" |
---|
1794 | Wave/T GSuffix = $"root:myGlobals:CombineTable:Suffix" |
---|
1795 | Wave/T GLabels = $"root:myGlobals:CombineTable:Labels" |
---|
1796 | Wave GSDD = $"root:myGlobals:CombineTable:SDD" |
---|
1797 | Wave GRunNumber = $"root:myGlobals:CombineTable:RunNumber" |
---|
1798 | Wave GIsTrans = $"root:myGlobals:CombineTable:IsTrans" |
---|
1799 | |
---|
1800 | lastPoint = numpnts(GLambda) |
---|
1801 | |
---|
1802 | Open/R refNum as fname |
---|
1803 | |
---|
1804 | InsertPoints lastPoint,1,GFilenames |
---|
1805 | GFilenames[lastPoint]=sname |
---|
1806 | |
---|
1807 | //read the file suffix |
---|
1808 | FSetPos refNum,19 |
---|
1809 | FReadLine/N=4 refNum,suffix |
---|
1810 | InsertPoints lastPoint,1,GSuffix |
---|
1811 | GSuffix[lastPoint]=suffix |
---|
1812 | |
---|
1813 | // read the sample.label text field |
---|
1814 | FSetPos refNum,98 //will start reading at byte 99 |
---|
1815 | FReadLine/N=60 refNum,lbl |
---|
1816 | InsertPoints lastPoint,1,GLabels |
---|
1817 | GLabels[lastPoint]=lbl |
---|
1818 | |
---|
1819 | Close refNum |
---|
1820 | |
---|
1821 | //read the reals with GBLoadWave |
---|
1822 | String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" |
---|
1823 | String strToExecute |
---|
1824 | |
---|
1825 | //SDD |
---|
1826 | strToExecute = GBLoadStr + "/S=260/U=1" + "\"" + fname + "\"" |
---|
1827 | Execute strToExecute |
---|
1828 | Wave w=$"tempGBWave0" |
---|
1829 | sdd = w[0] |
---|
1830 | InsertPoints lastPoint,1,GSDD |
---|
1831 | GSDD[lastPoint]=sdd |
---|
1832 | |
---|
1833 | //the run number (not displayed in the table, but carried along) |
---|
1834 | InsertPoints lastPoint,1,GRunNumber |
---|
1835 | GRunNumber[lastPoint] = GetRunNumFromFile(sname) |
---|
1836 | |
---|
1837 | // 0 if the file is a scattering file, 1 (truth) if the file is a transmission file |
---|
1838 | InsertPoints lastPoint,1,GIsTrans |
---|
1839 | GIsTrans[lastPoint] = CheckIfBeamstopOut(fname, -5) //returns one if beamstop is "out" |
---|
1840 | |
---|
1841 | KillWaves/Z w |
---|
1842 | return(0) |
---|
1843 | End |
---|
1844 | |
---|
1845 | //sorts all of the waves of header information using the suffix (A123) |
---|
1846 | //the result is that all of the data is in the order that it was collected, |
---|
1847 | // regardless of how the prefix or run numbers were changed by the user |
---|
1848 | Function SortCombineWaves() |
---|
1849 | Wave/T GFilenames = $"root:myGlobals:CombineTable:Filenames" |
---|
1850 | Wave/T GSuffix = $"root:myGlobals:CombineTable:Suffix" |
---|
1851 | Wave/T GLabels = $"root:myGlobals:CombineTable:Labels" |
---|
1852 | Wave GSDD = $"root:myGlobals:CombineTable:SDD" |
---|
1853 | Wave GRunNumber = $"root:myGlobals:CombineTable:RunNumber" |
---|
1854 | Wave GIsTrans = $"root:myGlobals:CombineTable:IsTrans" |
---|
1855 | |
---|
1856 | // Sort GSuffix, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens,GRunNumber,GIsTrans |
---|
1857 | Sort GSuffix, GSuffix, GFilenames, GLabels, GSDD, GRunNumber, GIsTrans |
---|
1858 | return(0) |
---|
1859 | End |
---|
1860 | |
---|
1861 | //sorts all of the waves of header information using the suffix (A123) |
---|
1862 | //the result is that all of the data is in the order that it was collected, |
---|
1863 | // regardless of how the prefix or run numbers were changed by the user |
---|
1864 | Function SortCombineByLabel() |
---|
1865 | Wave/T GFilenames = $"root:myGlobals:CombineTable:Filenames" |
---|
1866 | Wave/T GSuffix = $"root:myGlobals:CombineTable:Suffix" |
---|
1867 | Wave/T GLabels = $"root:myGlobals:CombineTable:Labels" |
---|
1868 | Wave GSDD = $"root:myGlobals:CombineTable:SDD" |
---|
1869 | Wave GRunNumber = $"root:myGlobals:CombineTable:RunNumber" |
---|
1870 | Wave GIsTrans = $"root:myGlobals:CombineTable:IsTrans" |
---|
1871 | |
---|
1872 | Sort GLabels, GSuffix, GFilenames, GLabels, GSDD, GRunNumber, GIsTrans |
---|
1873 | // Sort {GLabels, GSDD}, GSuffix, GFilenames, GLabels, GSDD, GRunNumber, GIsTrans //sort on GLabels, GSDD breaks the tie |
---|
1874 | return(0) |
---|
1875 | End |
---|
1876 | |
---|
1877 | //main procedure, called from the menu |
---|
1878 | // sets a flag (temporarily) to use the names from the table |
---|
1879 | // during the procedure that writes the data files. |
---|
1880 | // |
---|
1881 | // |
---|
1882 | Proc DoCombineFiles() |
---|
1883 | |
---|
1884 | // Wave lowWave = $"root:myGlobals:CombineTable:Low" |
---|
1885 | // Wave mediumWave = $"root:myGlobals:CombineTable:Medium" |
---|
1886 | // Wave highWave = $"root:myGlobals:CombineTable:High" |
---|
1887 | // Wave/T prefixWave = $"root:myGlobals:CombineTable:Prefix" |
---|
1888 | // Wave/T saveNameWave = $"root:myGlobals:CombineTable:SaveName" |
---|
1889 | |
---|
1890 | String savedDataFolder = GetDataFolder(1) // save |
---|
1891 | SetDataFolder root:myGlobals:CombineTable: |
---|
1892 | |
---|
1893 | Variable/G useTable=1 |
---|
1894 | |
---|
1895 | Variable num=numpnts(low),ii,lowFile,medFile,hiFile |
---|
1896 | String prefixStr = "" |
---|
1897 | Pathinfo catPathName |
---|
1898 | String path=S_Path |
---|
1899 | |
---|
1900 | ii=0 |
---|
1901 | do |
---|
1902 | lowFile = Low[ii] |
---|
1903 | medFile = Medium[ii] |
---|
1904 | hiFile = high[ii] |
---|
1905 | prefixStr = prefix[ii] |
---|
1906 | |
---|
1907 | Set3NSORTFiles(lowFile,medFile,hiFile,prefixStr) //set the files and pop the NSORT popups |
---|
1908 | |
---|
1909 | //pass the new file name in as a global (ugh!) |
---|
1910 | String/G root:myGlobals:CombineTable:SaveNameStr = path+saveName[ii] |
---|
1911 | //combine the files and write the data |
---|
1912 | WriteNSORTFileButton("") |
---|
1913 | |
---|
1914 | ii+=1 |
---|
1915 | while(ii<num) |
---|
1916 | |
---|
1917 | Variable/G useTable=0 |
---|
1918 | |
---|
1919 | SetDataFolder savedDataFolder |
---|
1920 | |
---|
1921 | End |
---|
1922 | |
---|
1923 | |
---|
1924 | |
---|
1925 | |
---|
1926 | // Commentized lines here are incomplete - and NON-FUNCTIONING |
---|
1927 | // |
---|
1928 | //// Window hook example: |
---|
1929 | // |
---|
1930 | Function CombineTableHook(infoStr) |
---|
1931 | String infoStr |
---|
1932 | String event= StringByKey("EVENT",infoStr) |
---|
1933 | // Print "EVENT= ",event |
---|
1934 | strswitch(event) |
---|
1935 | case "mousedown": |
---|
1936 | Variable xpix= NumberByKey("MOUSEX",infoStr) |
---|
1937 | Variable ypix= NumberByKey("MOUSEY",infoStr) |
---|
1938 | Variable modif= NumberByKey("MODIFIERS",infoStr) |
---|
1939 | if(modif == 2) //bit 1 set, shift key is down |
---|
1940 | PopupContextualMenu/C=(xpix, ypix) "combine;" |
---|
1941 | strswitch(S_selection) |
---|
1942 | case "combine": |
---|
1943 | //Print "combine the files" |
---|
1944 | SendSelectionToTable() |
---|
1945 | break; |
---|
1946 | // case "no": |
---|
1947 | // break; |
---|
1948 | // case "maybe": |
---|
1949 | // // do something because "maybe" was chosen |
---|
1950 | // break; |
---|
1951 | endswitch //on selection |
---|
1952 | endif |
---|
1953 | endswitch // on event |
---|
1954 | |
---|
1955 | return 0 |
---|
1956 | End |
---|
1957 | |
---|
1958 | //ASSUMES 3 FILES!!!! |
---|
1959 | Function SendSelectionToTable() |
---|
1960 | |
---|
1961 | DoWindow/F ToCombine |
---|
1962 | if(V_flag==0) |
---|
1963 | // Make/O/N=0 $"root:myGlobals:CombineTable:Low" |
---|
1964 | // Make/O/N=0 $"root:myGlobals:CombineTable:Medium" |
---|
1965 | // Make/O/N=0 $"root:myGlobals:CombineTable:High" |
---|
1966 | // Make/O/T/N=0 $"root:myGlobals:CombineTable:Prefix" |
---|
1967 | // Make/O/T/N=0 $"root:myGlobals:CombineTable:SaveName" |
---|
1968 | // edit Low,Medium,High,Prefix,SaveName as "Run Numbers to Combine" |
---|
1969 | // DoWindow/C ToCombine |
---|
1970 | |
---|
1971 | return(0) |
---|
1972 | |
---|
1973 | else |
---|
1974 | Wave low = $"root:myGlobals:CombineTable:Low" |
---|
1975 | Wave medium = $"root:myGlobals:CombineTable:Medium" |
---|
1976 | Wave high = $"root:myGlobals:CombineTable:High" |
---|
1977 | Wave/T prefix = $"root:myGlobals:CombineTable:Prefix" |
---|
1978 | Wave/T saveName = $"root:myGlobals:CombineTable:SaveName" |
---|
1979 | |
---|
1980 | Wave/T gLabels = $"root:myGlobals:CombineTable:Labels" |
---|
1981 | Wave gSDD = $"root:myGlobals:CombineTable:SDD" |
---|
1982 | Wave gRunNumber = $"root:myGlobals:CombineTable:RunNumber" |
---|
1983 | endif |
---|
1984 | |
---|
1985 | GetSelection table,CombineTable,3 |
---|
1986 | // Print V_startRow, V_endRow |
---|
1987 | |
---|
1988 | Variable num=V_endRow-V_startRow+1 |
---|
1989 | Variable ii |
---|
1990 | Make/O/T/N=(num) tmpLbl |
---|
1991 | Make/O/N=(num) tmpSDD,tmpRun |
---|
1992 | for(ii=V_startRow;ii<=V_endRow;ii+=1) |
---|
1993 | tmpLbl[ii-V_startRow] = gLabels[ii] |
---|
1994 | tmpSDD[ii-V_startRow] = gSDD[ii] |
---|
1995 | tmpRun[ii-V_startRow] = gRunNumber[ii] |
---|
1996 | endfor |
---|
1997 | Sort tmpSDD, tmpSDD,tmpLbl,tmpRun |
---|
1998 | |
---|
1999 | // Print tmpSDD |
---|
2000 | |
---|
2001 | num=numpnts(low) |
---|
2002 | InsertPoints num, 1, low,medium,high |
---|
2003 | low[num] = tmpRun[2] |
---|
2004 | medium[num] = tmpRun[1] |
---|
2005 | high[num] = tmpRun[0] |
---|
2006 | |
---|
2007 | return(0) |
---|
2008 | end |
---|