1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=4.00 |
---|
3 | #pragma IgorVersion=6.0 |
---|
4 | |
---|
5 | // This is to be used with the Analysis packages ONLY |
---|
6 | // there are a number of utility procedures here for loading |
---|
7 | // data and generating valid lists of data files that are |
---|
8 | // directly copied from the Reduction package |
---|
9 | // -- There WILL be name conflicts if you mix the two... |
---|
10 | // |
---|
11 | // 16 DEC 05 SRK |
---|
12 | // prepended function names with A_ to tag them for the |
---|
13 | // "A"nalysis parckage, though nearly all are duplicate procedures |
---|
14 | // so there will be no overlap with the reduction package |
---|
15 | // |
---|
16 | // |
---|
17 | // these extra procedures are used by: |
---|
18 | // Linearized fits (duplicated in Reduction - will need to handle gently) |
---|
19 | // Invariant (no overlap with reduction) |
---|
20 | // |
---|
21 | // SRK MAR 2005 |
---|
22 | |
---|
23 | // create a KW=string; of model=coef correspondence as the models are plotted, rather than |
---|
24 | // some other hard-wired solution |
---|
25 | Function AddModelToStrings(funcStr,coefStr,suffix) |
---|
26 | String funcStr,coefStr,suffix |
---|
27 | |
---|
28 | if(exists("root:Packages:NIST:coefKWStr")==0) |
---|
29 | String/G root:Packages:NIST:coefKWStr="" |
---|
30 | String/G root:Packages:NIST:suffixKWStr="" |
---|
31 | endif |
---|
32 | SVAR coefKWStr = root:Packages:NIST:coefKWStr |
---|
33 | SVAR suffixKWStr = root:Packages:NIST:suffixKWStr |
---|
34 | coefKWStr += funcStr+"="+coefStr+";" |
---|
35 | suffixKWStr += coefStr+"="+suffix+";" |
---|
36 | end |
---|
37 | |
---|
38 | // loads a 1-d (ascii) datafile and plots the data |
---|
39 | // will overwrite existing data if user is OK with this |
---|
40 | // - multiple datasets can be automatically plotted on the same graph |
---|
41 | // |
---|
42 | //substantially easier to write this as a Proc rather than a function... |
---|
43 | |
---|
44 | // |
---|
45 | Proc A_LoadOneDData() |
---|
46 | A_LoadOneDDataWithName("",1) //will prompt for file and plot data |
---|
47 | End |
---|
48 | |
---|
49 | // load the data specified by fileStr (a full path:name) |
---|
50 | // and plots if doPlot==1 |
---|
51 | // if fileStr is null, a dialog is presented to select the file |
---|
52 | // |
---|
53 | // 3 cases (if) |
---|
54 | // - 3 columns = QIS, no resolution |
---|
55 | // - 6 columns = QSIG, SANS w/resolution |
---|
56 | // - 5 columns = old-style desmeared USANS data (from VAX) |
---|
57 | // |
---|
58 | // This loader replaces the A_LoadOneDData() which was almost completely duplicated code |
---|
59 | // |
---|
60 | //new version, 19JUN07 that loads each data set into a separate data folder |
---|
61 | // the data folder is given the "base name" of the data file as it's loaded |
---|
62 | // |
---|
63 | Proc A_LoadOneDDataWithName(fileStr,doPlot) |
---|
64 | String fileStr |
---|
65 | Variable doPlot |
---|
66 | |
---|
67 | Variable rr,gg,bb,refnum |
---|
68 | String w0,w1,w2,n0,n1,n2 |
---|
69 | String w3,w4,w5,n3,n4,n5 //3 extra waves to load |
---|
70 | SetDataFolder root: //build sub-folders for each data set under root |
---|
71 | Variable dQv = root:Packages:NIST:USANS_dQv |
---|
72 | |
---|
73 | if (cmpStr(fileStr,"") == 0) |
---|
74 | //No filename given, open dialog |
---|
75 | Open/D/R refnum |
---|
76 | if (cmpstr(S_filename,"") == 0) |
---|
77 | return |
---|
78 | else |
---|
79 | fileStr = S_filename |
---|
80 | endif |
---|
81 | endif |
---|
82 | |
---|
83 | if (isXML(fileStr) == 1) |
---|
84 | LoadNISTXMLData(fileStr,doPlot) |
---|
85 | else |
---|
86 | //Load the waves, using default waveX names |
---|
87 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
---|
88 | LoadWave/G/D/A/Q fileStr |
---|
89 | //String fileName = S_fileName |
---|
90 | String basestr = ParseFilePath(3,ParseFilePath(5,S_Path,":",0,0),":",0,0) |
---|
91 | String fileName = ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0) |
---|
92 | Variable numCols = V_flag |
---|
93 | |
---|
94 | if(numCols==3) //simple 3-column data with no resolution information |
---|
95 | |
---|
96 | // put the names of the three loaded waves into local names |
---|
97 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
98 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
99 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
100 | |
---|
101 | //remove the semicolon AND period from files from the VAX |
---|
102 | w0 = CleanupName((basestr + "_q"),0) |
---|
103 | w1 = CleanupName((basestr + "_i"),0) |
---|
104 | w2 = CleanupName((basestr + "_s"),0) |
---|
105 | |
---|
106 | //String baseStr=w1[0,strlen(w1)-3] |
---|
107 | if(DataFolderExists("root:"+baseStr)) |
---|
108 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
109 | if(V_flag==2) //user selected No, don't load the data |
---|
110 | SetDataFolder root: |
---|
111 | KillWaves $n0,$n1,$n2 // kill the default waveX that were loaded |
---|
112 | //if(DataFolderExists("root:Packages:NIST")) |
---|
113 | // String/G root:Packages:NIST:gLastFileName = filename |
---|
114 | //endif |
---|
115 | return //quits the macro |
---|
116 | endif |
---|
117 | SetDataFolder $("root:"+baseStr) |
---|
118 | else |
---|
119 | NewDataFolder/S $("root:"+baseStr) |
---|
120 | endif |
---|
121 | |
---|
122 | ////overwrite the existing data, if it exists |
---|
123 | Duplicate/O $("root:"+n0), $w0 |
---|
124 | Duplicate/O $("root:"+n1), $w1 |
---|
125 | Duplicate/O $("root:"+n2), $w2 |
---|
126 | |
---|
127 | // no resolution matrix to make |
---|
128 | |
---|
129 | SetScale d,0,0,"1/A",$w0 |
---|
130 | SetScale d,0,0,"1/cm",$w1 |
---|
131 | |
---|
132 | endif //3-col data |
---|
133 | |
---|
134 | if(numCols == 6) //6-column SANS or USANS data that has resolution information |
---|
135 | |
---|
136 | // put the names of the (default named) loaded waves into local names |
---|
137 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
138 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
139 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
140 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
141 | n4 = StringFromList(4, S_waveNames ,";" ) |
---|
142 | n5 = StringFromList(5, S_waveNames ,";" ) |
---|
143 | |
---|
144 | //remove the semicolon AND period from files from the VAX |
---|
145 | w0 = CleanupName((basestr + "_q"),0) |
---|
146 | w1 = CleanupName((basestr + "_i"),0) |
---|
147 | w2 = CleanupName((basestr + "_s"),0) |
---|
148 | w3 = CleanupName((basestr + "sq"),0) |
---|
149 | w4 = CleanupName((basestr + "qb"),0) |
---|
150 | w5 = CleanupName((basestr + "fs"),0) |
---|
151 | |
---|
152 | //String baseStr=w1[0,strlen(w1)-3] |
---|
153 | if(DataFolderExists("root:"+baseStr)) |
---|
154 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
155 | if(V_flag==2) //user selected No, don't load the data |
---|
156 | SetDataFolder root: |
---|
157 | KillWaves $n0,$n1,$n2,$n3,$n4,$n5 // kill the default waveX that were loaded |
---|
158 | if(DataFolderExists("root:Packages:NIST")) |
---|
159 | String/G root:Packages:NIST:gLastFileName = filename |
---|
160 | endif //set the last file loaded to the one NOT loaded |
---|
161 | return //quits the macro |
---|
162 | endif |
---|
163 | SetDataFolder $("root:"+baseStr) |
---|
164 | else |
---|
165 | NewDataFolder/S $("root:"+baseStr) |
---|
166 | endif |
---|
167 | |
---|
168 | ////overwrite the existing data, if it exists |
---|
169 | Duplicate/O $("root:"+n0), $w0 |
---|
170 | Duplicate/O $("root:"+n1), $w1 |
---|
171 | Duplicate/O $("root:"+n2), $w2 |
---|
172 | Duplicate/O $("root:"+n3), $w3 |
---|
173 | Duplicate/O $("root:"+n4), $w4 |
---|
174 | Duplicate/O $("root:"+n5), $w5 |
---|
175 | |
---|
176 | // need to switch based on SANS/USANS |
---|
177 | if (isSANSResolution($w3[0])) //checks to see if the first point of the wave is <0] |
---|
178 | // make a resolution matrix for SANS data |
---|
179 | Variable np=numpnts($w0) |
---|
180 | Make/D/O/N=(np,4) $(baseStr+"_res") |
---|
181 | |
---|
182 | $(baseStr+"_res")[][0] = $w3[p] //sigQ |
---|
183 | $(baseStr+"_res")[][1] = $w4[p] //qBar |
---|
184 | $(baseStr+"_res")[][2] = $w5[p] //fShad |
---|
185 | $(baseStr+"_res")[][3] = $w0[p] //Qvalues |
---|
186 | else |
---|
187 | //the data is USANS data |
---|
188 | // marix calculation here, but for now, just copy the waves |
---|
189 | //$(baseStr+"_res")[][0] = $w3[p] //sigQ |
---|
190 | //$(baseStr+"_res")[][1] = $w4[p] //qBar |
---|
191 | //$(baseStr+"_res")[][2] = $w5[p] //fShad |
---|
192 | //$(baseStr+"_res")[][3] = $w0[p] //Qvalues |
---|
193 | dQv = -$w3[0] |
---|
194 | |
---|
195 | USANS_CalcWeights(baseStr,dQv) |
---|
196 | |
---|
197 | endif |
---|
198 | Killwaves/Z $w3,$w4,$w5 //get rid of the resolution waves that are in the matrix |
---|
199 | |
---|
200 | SetScale d,0,0,"1/A",$w0 |
---|
201 | SetScale d,0,0,"1/cm",$w1 |
---|
202 | |
---|
203 | endif //6-col data |
---|
204 | |
---|
205 | // Load ORNL data from Heller program |
---|
206 | if(numCols == 4) //4-column SANS or USANS data that has resolution information |
---|
207 | |
---|
208 | // put the names of the (default named) loaded waves into local names |
---|
209 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
210 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
211 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
212 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
213 | |
---|
214 | //remove the semicolon AND period from files from the VAX |
---|
215 | w0 = CleanupName((basestr + "_q"),0) |
---|
216 | w1 = CleanupName((basestr + "_i"),0) |
---|
217 | w2 = CleanupName((basestr + "_s"),0) |
---|
218 | w3 = CleanupName((basestr + "sq"),0) |
---|
219 | w4 = CleanupName((basestr + "qb"),0) |
---|
220 | w5 = CleanupName((basestr + "fs"),0) |
---|
221 | |
---|
222 | |
---|
223 | //String baseStr=w1[0,strlen(w1)-3] |
---|
224 | if(DataFolderExists("root:"+baseStr)) |
---|
225 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
226 | if(V_flag==2) //user selected No, don't load the data |
---|
227 | SetDataFolder root: |
---|
228 | KillWaves $n0,$n1,$n2,$n3 // kill the default waveX that were loaded |
---|
229 | if(DataFolderExists("root:Packages:NIST")) |
---|
230 | String/G root:Packages:NIST:gLastFileName = filename |
---|
231 | endif //set the last file loaded to the one NOT loaded |
---|
232 | return //quits the macro |
---|
233 | endif |
---|
234 | SetDataFolder $("root:"+baseStr) |
---|
235 | else |
---|
236 | NewDataFolder/S $("root:"+baseStr) |
---|
237 | endif |
---|
238 | |
---|
239 | ////overwrite the existing data, if it exists |
---|
240 | Duplicate/O $("root:"+n0), $w0 |
---|
241 | Duplicate/O $("root:"+n1), $w1 |
---|
242 | Duplicate/O $("root:"+n2), $w2 |
---|
243 | Duplicate/O $("root:"+n3), $w3 |
---|
244 | Duplicate/O $("root:"+n0), $w4 // Set qb wave to nominal measured Q values |
---|
245 | Duplicate/O $("root:"+n0), $w5 // Make wave of appropriate length |
---|
246 | $w5 = 1 // Set all shadowfactor to 1 |
---|
247 | |
---|
248 | // need to switch based on SANS/USANS |
---|
249 | if (isSANSResolution($w3[0])) //checks to see if the first point of the wave is <0] |
---|
250 | // make a resolution matrix for SANS data |
---|
251 | Variable np=numpnts($w0) |
---|
252 | Make/D/O/N=(np,4) $(baseStr+"_res") |
---|
253 | |
---|
254 | $(baseStr+"_res")[][0] = $w3[p] //sigQ |
---|
255 | $(baseStr+"_res")[][1] = $w4[p] //qBar |
---|
256 | $(baseStr+"_res")[][2] = $w5[p] //fShad |
---|
257 | $(baseStr+"_res")[][3] = $w0[p] //Qvalues |
---|
258 | else |
---|
259 | //the data is USANS data |
---|
260 | // marix calculation here, but for now, just copy the waves |
---|
261 | //$(baseStr+"_res")[][0] = $w3[p] //sigQ |
---|
262 | //$(baseStr+"_res")[][1] = $w4[p] //qBar |
---|
263 | //$(baseStr+"_res")[][2] = $w5[p] //fShad |
---|
264 | //$(baseStr+"_res")[][3] = $w0[p] //Qvalues |
---|
265 | dQv = -$w3[0] |
---|
266 | |
---|
267 | USANS_CalcWeights(baseStr,dQv) |
---|
268 | |
---|
269 | endif |
---|
270 | Killwaves/Z $w3,$w4,$w5 //get rid of the resolution waves that are in the matrix |
---|
271 | |
---|
272 | SetScale d,0,0,"1/A",$w0 |
---|
273 | SetScale d,0,0,"1/cm",$w1 |
---|
274 | |
---|
275 | endif //4-col data |
---|
276 | |
---|
277 | |
---|
278 | if(numCols==5) //this is the "old-style" VAX desmeared data format |
---|
279 | |
---|
280 | // put the names of the three loaded waves into local names |
---|
281 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
282 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
283 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
284 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
285 | n4 = StringFromList(4, S_waveNames ,";" ) |
---|
286 | |
---|
287 | |
---|
288 | //remove the semicolon AND period from files from the VAX |
---|
289 | w0 = CleanupName((basestr+"_q"),0) |
---|
290 | w1 = CleanupName((basestr+"_i"),0) |
---|
291 | w2 = CleanupName((basestr+"_s"),0) |
---|
292 | w3 = CleanupName((basestr+"_ism"),0) |
---|
293 | w4 = CleanupName((basestr+"_fit_ism"),0) |
---|
294 | |
---|
295 | //String baseStr=w1[0,strlen(w1)-3] |
---|
296 | if(DataFolderExists("root:"+baseStr)) |
---|
297 | DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
298 | if(V_flag==2) //user selected No, don't load the data |
---|
299 | KillWaves $n0,$n1,$n2,$n3,$n4,$n5 // kill the default waveX that were loaded |
---|
300 | //if(DataFolderExists("root:Packages:NIST")) |
---|
301 | // String/G root:Packages:NIST:gLastFileName = filename |
---|
302 | //endif //set the last file loaded to the one NOT loaded |
---|
303 | return //quits the macro |
---|
304 | endif |
---|
305 | SetDataFolder $("root:"+baseStr) |
---|
306 | else |
---|
307 | NewDataFolder/S $("root:"+baseStr) |
---|
308 | endif |
---|
309 | |
---|
310 | ////overwrite the existing data, if it exists |
---|
311 | Duplicate/O $("root:"+n0), $w0 |
---|
312 | Duplicate/O $("root:"+n1), $w1 |
---|
313 | Duplicate/O $("root:"+n2), $w2 |
---|
314 | Duplicate/O $("root:"+n3), $w3 |
---|
315 | Duplicate/O $("root:"+n4), $w4 |
---|
316 | |
---|
317 | // no resolution matrix |
---|
318 | endif //5-col data |
---|
319 | |
---|
320 | ////// |
---|
321 | if(DataFolderExists("root:Packages:NIST")) |
---|
322 | String/G root:Packages:NIST:gLastFileName = filename |
---|
323 | endif |
---|
324 | |
---|
325 | |
---|
326 | //plot if desired |
---|
327 | if(doPlot) |
---|
328 | // assign colors randomly |
---|
329 | rr = abs(trunc(enoise(65535))) |
---|
330 | gg = abs(trunc(enoise(65535))) |
---|
331 | bb = abs(trunc(enoise(65535))) |
---|
332 | |
---|
333 | // if target window is a graph, and user wants to append, do so |
---|
334 | DoWindow/B Plot_Manager |
---|
335 | if(WinType("") == 1) |
---|
336 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
337 | if(V_Flag == 1) |
---|
338 | AppendToGraph $w1 vs $w0 |
---|
339 | ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1 |
---|
340 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
341 | ModifyGraph tickUnit(left)=1 |
---|
342 | else |
---|
343 | //new graph |
---|
344 | Display $w1 vs $w0 |
---|
345 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
346 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
347 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
348 | ModifyGraph tickUnit(left)=1 |
---|
349 | Legend |
---|
350 | endif |
---|
351 | else |
---|
352 | // graph window was not target, make new one |
---|
353 | Display $w1 vs $w0 |
---|
354 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
355 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
356 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
357 | ModifyGraph tickUnit(left)=1 |
---|
358 | Legend |
---|
359 | endif |
---|
360 | endif |
---|
361 | |
---|
362 | //go back to the root folder and clean up before leaving |
---|
363 | SetDataFolder root: |
---|
364 | KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5 |
---|
365 | |
---|
366 | endif |
---|
367 | End |
---|
368 | |
---|
369 | |
---|
370 | //procedure for loading NSE data in the format (4-columns) |
---|
371 | // qvals - time - I(q,t) - dI(q,t) |
---|
372 | // |
---|
373 | // |
---|
374 | // this does NOT load the data into separate folders... |
---|
375 | // |
---|
376 | Proc A_LoadNSEData() |
---|
377 | A_LoadNSEDataWithName("",1) |
---|
378 | End |
---|
379 | |
---|
380 | Proc A_LoadNSEDataWithName(fileStr,doPlot) |
---|
381 | |
---|
382 | //Load the waves, using default waveX names |
---|
383 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
---|
384 | LoadWave/G/D/A fileStr |
---|
385 | String filename = S_fileName |
---|
386 | |
---|
387 | String w0,w1,w2,n0,n1,n2,wt,w3,n3 |
---|
388 | Variable rr,gg,bb |
---|
389 | |
---|
390 | // put the names of the three loaded waves into local names |
---|
391 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
392 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
393 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
394 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
395 | |
---|
396 | |
---|
397 | //remove the semicolon AND period from files from the VAX |
---|
398 | w0 = CleanupName(("qvals_"+S_fileName),0) |
---|
399 | w1 = CleanupName(("time_"+S_fileName),0) |
---|
400 | w2 = CleanupName(("iqt_"+S_fileName),0) |
---|
401 | w3 = CleanupName(("iqterr_"+S_fileName),0) |
---|
402 | |
---|
403 | if(exists(w0) !=0) |
---|
404 | DoAlert 0,"This file has already been loaded. Use Append to Graph..." |
---|
405 | KillWaves $n0,$n1,$n2 // kill the default waveX that were loaded |
---|
406 | return |
---|
407 | endif |
---|
408 | |
---|
409 | // Rename to give nice names |
---|
410 | Rename $n0, $w0 |
---|
411 | Rename $n1, $w1 |
---|
412 | Rename $n2, $w2 |
---|
413 | Rename $n3, $w3 |
---|
414 | |
---|
415 | if(doPlot) |
---|
416 | // assign colors randomly |
---|
417 | rr = abs(trunc(enoise(65535))) |
---|
418 | gg = abs(trunc(enoise(65535))) |
---|
419 | bb = abs(trunc(enoise(65535))) |
---|
420 | |
---|
421 | // if target window is a graph, and user wants to append, do so |
---|
422 | if(WinType("") == 1) |
---|
423 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
424 | if(V_Flag == 1) |
---|
425 | AppendToGraph $w2 vs $w1 |
---|
426 | ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
---|
427 | ErrorBars $w2 Y,wave=($w3,$w3) |
---|
428 | else |
---|
429 | //new graph |
---|
430 | Display $w2 vs $w1 |
---|
431 | ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
---|
432 | ErrorBars $w2 Y,wave=($w3,$w3) |
---|
433 | Legend |
---|
434 | endif |
---|
435 | else |
---|
436 | // graph window was not target, make new one |
---|
437 | Display $w2 vs $w1 |
---|
438 | ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1 |
---|
439 | ErrorBars $w2 Y,wave=($w3,$w3) |
---|
440 | Legend |
---|
441 | endif |
---|
442 | endif //doPlot |
---|
443 | |
---|
444 | End |
---|
445 | |
---|
446 | //procedure for loading desmeared USANS data in the format (5-columns) |
---|
447 | // qvals - I(q) - sig I - Ism(q) - fitted Ism(q) |
---|
448 | //no weighting wave is created (not needed in IGOR 4) |
---|
449 | // |
---|
450 | // not really ever used... |
---|
451 | // |
---|
452 | Proc A_LoadUSANSData() |
---|
453 | |
---|
454 | //Load the waves, using default waveX names |
---|
455 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
---|
456 | LoadWave/G/D/A |
---|
457 | String filename = S_fileName |
---|
458 | |
---|
459 | String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4 |
---|
460 | Variable rr,gg,bb |
---|
461 | |
---|
462 | // put the names of the three loaded waves into local names |
---|
463 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
464 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
465 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
466 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
467 | n4 = StringFromList(4, S_waveNames ,";" ) |
---|
468 | |
---|
469 | |
---|
470 | //remove the semicolon AND period from files from the VAX |
---|
471 | w0 = CleanupName((S_fileName+"_q"),0) |
---|
472 | w1 = CleanupName((S_fileName+"_i"),0) |
---|
473 | w2 = CleanupName((S_fileName+"_s"),0) |
---|
474 | w3 = CleanupName((S_fileName+"_ism"),0) |
---|
475 | w4 = CleanupName((S_fileName+"_fit_ism"),0) |
---|
476 | |
---|
477 | if(exists(w0) !=0) //the wave already exists |
---|
478 | DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?" |
---|
479 | if(V_flag==2) //user selected No |
---|
480 | KillWaves $n0,$n1,$n2,$n3,$n4 // kill the default waveX that were loaded |
---|
481 | if(DataFolderExists("root:Packages:NIST")) |
---|
482 | String/G root:Packages:NIST:gLastFileName = filename |
---|
483 | endif //set the last file loaded to the one NOT loaded |
---|
484 | return //quits the macro |
---|
485 | endif |
---|
486 | endif |
---|
487 | |
---|
488 | ////overwrite the existing data, if it exists |
---|
489 | Duplicate/O $n0, $w0 |
---|
490 | Duplicate/O $n1, $w1 |
---|
491 | Duplicate/O $n2, $w2 |
---|
492 | Duplicate/O $n3, $w3 |
---|
493 | Duplicate/O $n4, $w4 |
---|
494 | KillWaves $n0,$n1,$n2,$n3,$n4 |
---|
495 | |
---|
496 | if(DataFolderExists("root:Packages:NIST")) |
---|
497 | String/G root:Packages:NIST:gLastFileName = filename |
---|
498 | endif |
---|
499 | |
---|
500 | // assign colors randomly |
---|
501 | rr = abs(trunc(enoise(65535))) |
---|
502 | gg = abs(trunc(enoise(65535))) |
---|
503 | bb = abs(trunc(enoise(65535))) |
---|
504 | |
---|
505 | // if target window is a graph, and user wants to append, do so |
---|
506 | if(WinType("") == 1) |
---|
507 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
508 | if(V_Flag == 1) |
---|
509 | AppendToGraph $w1 vs $w0 |
---|
510 | ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
---|
511 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
512 | else |
---|
513 | //new graph |
---|
514 | Display $w1 vs $w0 |
---|
515 | ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
---|
516 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
517 | Legend |
---|
518 | endif |
---|
519 | else |
---|
520 | // graph window was not target, make new one |
---|
521 | Display $w1 vs $w0 |
---|
522 | ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2 |
---|
523 | ErrorBars $w1 Y,wave=($w2,$w2) |
---|
524 | Legend |
---|
525 | endif |
---|
526 | |
---|
527 | End |
---|
528 | |
---|
529 | |
---|
530 | //// Extra "Utility Procedures" |
---|
531 | // to pick path, get a list of data files, and make sure that a valid filename |
---|
532 | // is passed to LoadOneDDataWithName() |
---|
533 | // |
---|
534 | |
---|
535 | //prompts user to choose the local folder that contains the SANS Data |
---|
536 | //only one folder can be used, and its path is catPathName (and is a NAME, not a string) |
---|
537 | //this will overwrite the path selection |
---|
538 | //returns 1 if no path selected as error condition |
---|
539 | Function A_PickPath() |
---|
540 | |
---|
541 | //set the global string to the selected pathname |
---|
542 | NewPath/O/M="pick the SANS data folder" catPathName |
---|
543 | PathInfo/S catPathName |
---|
544 | String dum = S_path |
---|
545 | String alertStr = "" |
---|
546 | alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood" |
---|
547 | //alertStr += " Please see the manual for details." |
---|
548 | if (V_flag == 0) |
---|
549 | //path does not exist - no folder selected |
---|
550 | String/G root:Packages:NIST:gCatPathStr = "no folder selected" |
---|
551 | return(1) |
---|
552 | else |
---|
553 | //set the global to the path (as a string) |
---|
554 | // need 4 \ since it is the escape character |
---|
555 | if(cmpstr("\\\\",dum[0,1])==0) //Windoze user going through network neighborhood |
---|
556 | DoAlert 0,alertStr |
---|
557 | KillPath catPathName |
---|
558 | return(1) |
---|
559 | endif |
---|
560 | String/G root:Packages:NIST:gCatPathStr = dum |
---|
561 | return(0) //no error |
---|
562 | endif |
---|
563 | End |
---|
564 | |
---|
565 | //Function attempts to find valid filename from partial name that has been stripped of |
---|
566 | //the VAX version number. The partial name is tried first |
---|
567 | //*** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
568 | //version numers up to ;10 are tried |
---|
569 | //only the "name;vers" is returned. the path is not prepended, hence the return string |
---|
570 | //is not a complete specification of the file |
---|
571 | // |
---|
572 | // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary |
---|
573 | // since from marquee, the filename field (textread[0]) must be used, and can be a mix of |
---|
574 | // upper/lowercase letters, while the filename on the server (should) be all caps |
---|
575 | // now makes repeated calls to ValidFileString() |
---|
576 | // |
---|
577 | Function/S A_FindValidFilename(partialName) |
---|
578 | String PartialName |
---|
579 | |
---|
580 | String retStr="" |
---|
581 | |
---|
582 | //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 |
---|
583 | retStr = A_ValidFileString(partialName) |
---|
584 | if(cmpstr(retStr,"") !=0) |
---|
585 | //non-null return |
---|
586 | return(retStr) |
---|
587 | Endif |
---|
588 | |
---|
589 | //if the partial name is derived from the file header, there can be spaces at the beginning |
---|
590 | //or in the middle of the filename - depending on the prefix and initials used |
---|
591 | // |
---|
592 | //remove any leading spaces from the name before starting |
---|
593 | partialName = A_RemoveAllSpaces(partialName) |
---|
594 | |
---|
595 | //try name with no spaces |
---|
596 | retStr = A_ValidFileString(partialName) |
---|
597 | if(cmpstr(retStr,"") !=0) |
---|
598 | //non-null return |
---|
599 | return(retStr) |
---|
600 | Endif |
---|
601 | |
---|
602 | //try all UPPERCASE |
---|
603 | partialName = UpperStr(partialName) |
---|
604 | retStr = A_ValidFileString(partialName) |
---|
605 | if(cmpstr(retStr,"") !=0) |
---|
606 | //non-null return |
---|
607 | return(retStr) |
---|
608 | Endif |
---|
609 | |
---|
610 | //try all lowercase (ret null if failure) |
---|
611 | partialName = LowerStr(partialName) |
---|
612 | retStr = A_ValidFileString(partialName) |
---|
613 | if(cmpstr(retStr,"") !=0) |
---|
614 | //non-null return |
---|
615 | return(retStr) |
---|
616 | else |
---|
617 | return(retStr) |
---|
618 | Endif |
---|
619 | End |
---|
620 | |
---|
621 | //function to test a binary file to see if it is a RAW binary SANS file |
---|
622 | //first checks the total bytes in the file (which for raw data is 33316 bytes) |
---|
623 | //**note that the "DIV" file will also show up as a raw file by the run field |
---|
624 | //should be listed in CAT/SHORT and in patch windows |
---|
625 | // |
---|
626 | //Function then checks the file fname (full path:file) for "RAW" run.type field |
---|
627 | //if not found, the data is not raw data and zero is returned |
---|
628 | Function A_CheckIfRawData(fname) |
---|
629 | String fname |
---|
630 | |
---|
631 | Variable refnum,totalBytes |
---|
632 | String testStr="" |
---|
633 | |
---|
634 | Open/R/T="????TEXT" refNum as fname |
---|
635 | //get the total number of bytes in the file, to avoid moving past EOF |
---|
636 | FStatus refNum |
---|
637 | totalBytes = V_logEOF |
---|
638 | //Print totalBytes |
---|
639 | if(totalBytes!=33316) |
---|
640 | //can't possibly be a raw data file |
---|
641 | Close refnum |
---|
642 | return(0) //not a raw SANS file |
---|
643 | Endif |
---|
644 | FSetPos refNum,75 |
---|
645 | FReadLine/N=3 refNum,testStr |
---|
646 | Close refNum |
---|
647 | |
---|
648 | if(cmpstr(testStr,"RAW")==0) |
---|
649 | //true, is raw data file |
---|
650 | Return(1) |
---|
651 | else |
---|
652 | //some other file |
---|
653 | Return(0) |
---|
654 | Endif |
---|
655 | End |
---|
656 | |
---|
657 | //list (input) is a list, typically returned from IndexedFile() |
---|
658 | //which is semicolon-delimited, and may contain filesnames from the VAX |
---|
659 | //that contain version numbers, where the version number appears as a separate list item |
---|
660 | //(and also as a non-existent file) |
---|
661 | //these numbers must be purged from the list, especially for display in a popup |
---|
662 | //or list processing of filenames |
---|
663 | //the function returns the list, cleaned of version numbers (up to 11) |
---|
664 | //raw data files will typically never have a version number other than 1. |
---|
665 | Function/S A_RemoveVersNumsFromList(list) |
---|
666 | String list |
---|
667 | |
---|
668 | //get rid of version numbers first (up to 11) |
---|
669 | Variable ii,num |
---|
670 | String item |
---|
671 | num = ItemsInList(list,";") |
---|
672 | ii=1 |
---|
673 | do |
---|
674 | item = num2str(ii) |
---|
675 | list = RemoveFromList(item, list ,";" ) |
---|
676 | ii+=1 |
---|
677 | while(ii<12) |
---|
678 | |
---|
679 | return (list) |
---|
680 | End |
---|
681 | |
---|
682 | //Function attempts to find valid filename from partial name that has been stripped of |
---|
683 | //the VAX version number. The partial name is tried first |
---|
684 | //*** the PATH is hard-wired to catPathName (which is assumed to exist) |
---|
685 | //version numers up to ;10 are tried |
---|
686 | //only the "name;vers" is returned. the path is not prepended, hence the return string |
---|
687 | //is not a complete specification of the file |
---|
688 | // |
---|
689 | Function/S A_ValidFileString(partialName) |
---|
690 | String partialName |
---|
691 | |
---|
692 | String tempName = "",msg="" |
---|
693 | Variable ii,refnum |
---|
694 | |
---|
695 | ii=0 |
---|
696 | do |
---|
697 | if(ii==0) |
---|
698 | //first pass, try the partialName |
---|
699 | tempName = partialName |
---|
700 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) |
---|
701 | if(V_flag == 0) |
---|
702 | //file exists |
---|
703 | Close refnum //YES needed, |
---|
704 | break |
---|
705 | endif |
---|
706 | else |
---|
707 | tempName = partialName + ";" + num2str(ii) |
---|
708 | Open/Z/R/T="????TEXT"/P=catPathName refnum tempName |
---|
709 | if(V_flag == 0) |
---|
710 | //file exists |
---|
711 | Close refnum |
---|
712 | break |
---|
713 | endif |
---|
714 | Endif |
---|
715 | ii+=1 |
---|
716 | //print "ii=",ii |
---|
717 | while(ii<11) |
---|
718 | //go get the selected bits of information, using tempName, which exists |
---|
719 | if(ii>=11) |
---|
720 | //msg = partialName + " not found. is version number > 11?" |
---|
721 | //DoAlert 0, msg |
---|
722 | //PathInfo catPathName |
---|
723 | //Print S_Path |
---|
724 | Return ("") //use null string as error condition |
---|
725 | Endif |
---|
726 | |
---|
727 | Return (tempName) |
---|
728 | End |
---|
729 | |
---|
730 | //function to remove all spaces from names when searching for filenames |
---|
731 | //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) |
---|
732 | //but the text field in the header WILL, if less than 3 characters were used for the |
---|
733 | //user's initials, and can have leading spaces if prefix was less than 5 characters |
---|
734 | // |
---|
735 | //returns a string identical to the original string, except with the interior spaces removed |
---|
736 | // |
---|
737 | Function/S A_RemoveAllSpaces(str) |
---|
738 | String str |
---|
739 | |
---|
740 | String tempstr = str |
---|
741 | Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename |
---|
742 | ii=0 |
---|
743 | do |
---|
744 | len = strlen(tempStr) |
---|
745 | spc = strsearch(tempStr," ",0) //is the last character a space? |
---|
746 | if (spc == -1) |
---|
747 | break //no more spaces found, get out |
---|
748 | endif |
---|
749 | str = tempstr |
---|
750 | tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string |
---|
751 | While(1) //should never be more than 2 or 3 |
---|
752 | |
---|
753 | If(strlen(tempStr) < 1) |
---|
754 | tempStr = "" //be sure to return a null string if problem found |
---|
755 | Endif |
---|
756 | |
---|
757 | //Print strlen(tempstr) |
---|
758 | |
---|
759 | Return(tempStr) |
---|
760 | |
---|
761 | End |
---|