1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | |
---|
3 | |
---|
4 | // This was originally written 2001-2003 ish. This works very differently than SANSview, and I havne't |
---|
5 | // mentioned that this exists, so that their ideas will be new. Still, some of this may be |
---|
6 | // serviceable for use within the Igor package, with some cleanup of the interface and functionality. |
---|
7 | // |
---|
8 | // |
---|
9 | // |
---|
10 | // to do - July 2010 |
---|
11 | // |
---|
12 | // X- smeared models don't work at all (now they work) |
---|
13 | // -- the report is good, but the parsing is not great - the format |
---|
14 | // could be more convenient to read back in to a table (text col, num cols (matrix that can be plotted?) |
---|
15 | // -- Maybe the report could be compiled as waves. Then they would be numeric. Nothing to plot them against |
---|
16 | // other than file names, but with a table of values and names, one could manually enter a meaningful |
---|
17 | // column of values to plot against. |
---|
18 | // -- Make_HoldConstraintEps_Waves() is currently disabled, both on the macros menu and the checkbox on the panel |
---|
19 | // Constraints and holds are part of the matrix already, soo this would only be for epsilon |
---|
20 | // -- Many of the items on the Macros menu are just junk. |
---|
21 | // |
---|
22 | // -- Comprehensive instructions (after features are finalized) |
---|
23 | // |
---|
24 | // -- savePath seems to be obsolete. Report saving is sent to the procedure defined in Wrapper.ipf, and uses the home path |
---|
25 | // |
---|
26 | |
---|
27 | |
---|
28 | Menu "Macros" |
---|
29 | SubMenu "Auto-Fit" |
---|
30 | "InitializeAutoFitPanel" |
---|
31 | "-" |
---|
32 | "Generate_Data_Checklist" |
---|
33 | // "Make_HoldConstraintEps_Waves" //this is currently disabled |
---|
34 | "-" |
---|
35 | "CompileAndLoadReports" |
---|
36 | "LoadCompiledReports" |
---|
37 | "Compile_GlobalFit_Reports" |
---|
38 | "-" |
---|
39 | "PrintOpenNotebooks" |
---|
40 | "Close Open Notebooks" |
---|
41 | "-" |
---|
42 | "Generate_PICTS_list" |
---|
43 | "Layout_PICTS" |
---|
44 | |
---|
45 | End |
---|
46 | End |
---|
47 | |
---|
48 | |
---|
49 | //*********** |
---|
50 | //Automatic fitting routines for SANS or NSE data |
---|
51 | //requires model functions and their associated files |
---|
52 | // |
---|
53 | //************** |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | //path to the data |
---|
58 | // ? have this automatically do the listing? |
---|
59 | Function PDPButton(ctrlName) : ButtonControl |
---|
60 | String ctrlName |
---|
61 | |
---|
62 | //set the global string to the selected pathname |
---|
63 | NewPath/O/M="pick the data folder" dataPath |
---|
64 | PathInfo/S dataPath |
---|
65 | Return(0) |
---|
66 | End |
---|
67 | |
---|
68 | Function SavePathButtonProc(ctrlName) : ButtonControl |
---|
69 | String ctrlName |
---|
70 | |
---|
71 | //set the global string to the selected pathname |
---|
72 | NewPath/O/M="pick the save folder" savePath |
---|
73 | PathInfo/S savePath |
---|
74 | Return(0) |
---|
75 | End |
---|
76 | |
---|
77 | // |
---|
78 | // this re-sizes AND re-initializes the guessMatrix |
---|
79 | // and is only done when the files are re-listed, using the list button - since the |
---|
80 | // new list will screw up the correspondence with the guess matrix |
---|
81 | // |
---|
82 | Function FileListButtonProc(ctrlName) : ButtonControl |
---|
83 | String ctrlName |
---|
84 | |
---|
85 | DoAlert 1,"This will re-initialize the file list and ALL of the entries in the guess matrix. Do you want to proceed?" |
---|
86 | if(V_flag!=1) //if the answer is not yes, get out |
---|
87 | return(0) |
---|
88 | endif |
---|
89 | |
---|
90 | String fileList="" |
---|
91 | fileList = IndexedFile(dataPath,-1,"????") |
---|
92 | fileList = RemoveFromList(".DS_Store", fileList, ";",0) |
---|
93 | List2TextWave(Filelist,";","root:AutoFit:fileListWave") |
---|
94 | Wave/T lw = $"root:AutoFit:fileListWave" |
---|
95 | Redimension/N=(-1,2) lw |
---|
96 | lw[][1] = "" |
---|
97 | Variable num = DimSize(lw,0) |
---|
98 | |
---|
99 | Wave sw = $"root:AutoFit:fileSelWave" |
---|
100 | Redimension/B/N=(num,2) sw |
---|
101 | sw[][1] = (sw[p][1] == 0) ? 2^5 : sw[p][1] //if the element is zero, make it 32, otherwise leave it alone |
---|
102 | |
---|
103 | // force a re-size (and re-initialization) of the guess-hold-constr-range matrices |
---|
104 | ToMatrixButtonProc("") |
---|
105 | |
---|
106 | return(0) |
---|
107 | End |
---|
108 | |
---|
109 | // |
---|
110 | // this re-sizes AND re-initializes the guessMatrix |
---|
111 | // and is only done when the files are re-listed, using the list button - since the |
---|
112 | // new list will screw up the correspondence with the guess matrix |
---|
113 | // |
---|
114 | Function ToMatrixButtonProc(ctrlName) : ButtonControl |
---|
115 | String ctrlName |
---|
116 | |
---|
117 | SetDataFolder root:AutoFit |
---|
118 | WAVE sel = fileSelWave |
---|
119 | NVAR numPar=numPar |
---|
120 | Variable jj,numSelFiles=0 |
---|
121 | |
---|
122 | //update the number of steps for the progress bar |
---|
123 | // commented out - SRK - 28MAR05 |
---|
124 | // NVAR cur=curProgress |
---|
125 | // NVAR totSteps=endProgress |
---|
126 | // cur=0 |
---|
127 | // totSteps=numSelFiles*3 //3 fits per file |
---|
128 | // ValDisplay progressValdisp,limits={0,totSteps,0} |
---|
129 | // ControlUpdate/W=AutoFitPanel progressValdisp |
---|
130 | |
---|
131 | //redimension the matrices and lists |
---|
132 | Redimension/N=(numPar,DimSize(sel,0)) guessMatrix,HoldMatrix,constrMatrix,rangeMatrix |
---|
133 | Redimension/N=(numPar) guessList,holdList,constrList,rangeList,guessSel,holdSel,constrSel,rangeSel |
---|
134 | |
---|
135 | //Set the matrices to zero |
---|
136 | WAVE/T aa = guessMatrix |
---|
137 | WAVE/T bb = holdMatrix |
---|
138 | WAVE/T cc = constrMatrix |
---|
139 | WAVE/T rr = rangeMatrix |
---|
140 | aa="1" |
---|
141 | bb="0" |
---|
142 | cc="" //set to no constraints |
---|
143 | rr="0" // zero in points 0 and 1 force a fit of all of the data (default) |
---|
144 | //set the Lists to "0" |
---|
145 | WAVE/T dd=guessList |
---|
146 | WAVE/T ee=holdList |
---|
147 | WAVE/T ff=constrList |
---|
148 | WAVE/T rrl=rangeList |
---|
149 | dd="0" |
---|
150 | ee="0" |
---|
151 | ff="0" |
---|
152 | rrl="0" |
---|
153 | //Set the sel waves to 2 (editable) |
---|
154 | WAVE gg=guessSel |
---|
155 | WAVE hh=holdSel |
---|
156 | WAVE ii=constrSel |
---|
157 | WAVE rrs=rangeSel |
---|
158 | gg=2 |
---|
159 | hh=2 |
---|
160 | ii=2 |
---|
161 | rrs=2 |
---|
162 | |
---|
163 | SetDataFolder root: |
---|
164 | |
---|
165 | DisplayGuess() |
---|
166 | tabProc("",0) //force the Guess tab to top |
---|
167 | TabControl tabC,value=0 |
---|
168 | |
---|
169 | return(0) |
---|
170 | End |
---|
171 | |
---|
172 | |
---|
173 | //updates the lists (text waves) to display, depending on the current highlighted file |
---|
174 | Function DisplayGuess() |
---|
175 | |
---|
176 | //find the selected data file -[][0] is the file, not the checkbox |
---|
177 | Variable row |
---|
178 | row = FindSelectedRowInLB(0) // send 0 to look at the column with filenames |
---|
179 | |
---|
180 | //update the text waves based on the values in the matrix |
---|
181 | WAVE/T gm = root:AutoFit:guessMatrix |
---|
182 | WAVE/T gl = root:AutoFit:guessList |
---|
183 | |
---|
184 | // the hold matrix |
---|
185 | WAVE/T hm=root:AutoFit:holdMatrix |
---|
186 | WAVE/T hl=root:AutoFit:holdList |
---|
187 | |
---|
188 | // the constraint matrix |
---|
189 | WAVE/T cm=root:AutoFit:constrMatrix |
---|
190 | WAVE/T cl=root:AutoFit:constrList |
---|
191 | |
---|
192 | // the range matrix |
---|
193 | WAVE/T rm=root:AutoFit:rangeMatrix |
---|
194 | WAVE/T rl=root:AutoFit:rangeList |
---|
195 | |
---|
196 | WAVE sel = root:AutoFit:fileSelWave |
---|
197 | if( (sel[row][1] & 0x10) == 16 ) //box is checked |
---|
198 | |
---|
199 | gl = gm[p][row] |
---|
200 | hl = hm[p][row] |
---|
201 | cl = cm[p][row] |
---|
202 | rl = rm[p][row] |
---|
203 | else |
---|
204 | //file is not checked, don't display guess |
---|
205 | gl = "Not checked" |
---|
206 | hl = "Not checked" |
---|
207 | cl = "Not checked" |
---|
208 | rl = "Not checked" |
---|
209 | endif |
---|
210 | |
---|
211 | return(0) |
---|
212 | End |
---|
213 | |
---|
214 | |
---|
215 | //column 0 is the filenames, 1 is the checkboxes |
---|
216 | //returns the row that is selected, -1 if not found |
---|
217 | Function FindSelectedRowInLB(col) |
---|
218 | Variable col |
---|
219 | |
---|
220 | WAVE sel = root:AutoFit:fileSelWave |
---|
221 | Variable jj=0,row=-1 |
---|
222 | if(col==0) |
---|
223 | do |
---|
224 | if( (sel[jj][0] & 0x01) == 1 ) //returns 1 (bit 0) if selected, 0 otherwise |
---|
225 | row=jj |
---|
226 | //print "Row = ",jj |
---|
227 | break |
---|
228 | endif |
---|
229 | jj+=1 |
---|
230 | while(jj<DimSize(sel,0)) |
---|
231 | else |
---|
232 | do |
---|
233 | if( (sel[jj][1] & 0x01) == 1 ) //the checkbox is selected, but not necessarily checked! |
---|
234 | row=jj |
---|
235 | //print "Row = ",jj |
---|
236 | break |
---|
237 | endif |
---|
238 | jj+=1 |
---|
239 | while(jj<DimSize(sel,0)) |
---|
240 | endif |
---|
241 | |
---|
242 | return(row) |
---|
243 | end |
---|
244 | |
---|
245 | |
---|
246 | Proc InitializeAutoFitPanel() |
---|
247 | if (wintype("AutoFitPanel") == 0) |
---|
248 | InitializeAutoFit() |
---|
249 | AutoFitPanel() |
---|
250 | tabProc("",0) //force the tab control to display correctly |
---|
251 | else |
---|
252 | DoWindow/F AutoFitPanel |
---|
253 | endif |
---|
254 | // RangeCheckProc("",1) //check the box to use all of the data |
---|
255 | End |
---|
256 | |
---|
257 | Function InitializeAutoFit() |
---|
258 | //set up all of the globals for the lists, globals, etc... |
---|
259 | NewDataFolder/O/S root:AutoFit |
---|
260 | Make/O/T/N=(1,2) fileListWave //list boxes need text waves |
---|
261 | Make/O/B/N=(1,2) fileSelWave //for the checkboxes |
---|
262 | Make/O/T/N=1 guessList,holdList,ConstrList,rangeList //list boxes need text waves |
---|
263 | Make/O/T/N=(1,1) guessMatrix,holdMatrix,rangeMatrix //guesses, etc... need real values (later) |
---|
264 | Make/O/T/N=(1,1) constrMatrix //constraint matrix is text |
---|
265 | Make/O/B/N=1 guessSel,holdSel,ConstrSel,rangeSel //SelWave is byte data |
---|
266 | Variable/G numPar=5,ptLow=0,ptHigh=0,fitTol=1e-3,curProgress=0,endProgress=10 |
---|
267 | Variable/G startTicks=0 |
---|
268 | |
---|
269 | String/G gStatFormat="\K(65535,0,0)\f01" |
---|
270 | String/G gStatus=gStatFormat+"the fit engine is currently idle" |
---|
271 | string/g gExt="ABC" |
---|
272 | |
---|
273 | fileListWave = "" |
---|
274 | |
---|
275 | //make the second column of the file sel wave a checkbox (set bit 5) |
---|
276 | fileSelWave[][1] = 2^5 |
---|
277 | |
---|
278 | SetDataFolder root: |
---|
279 | End |
---|
280 | |
---|
281 | Window AutoFitPanel() |
---|
282 | PauseUpdate; Silent 1 // building window... |
---|
283 | NewPanel /W=(685,44,1001,740) /K=1 |
---|
284 | DoWindow/C AutoFitPanel |
---|
285 | SetDrawLayer UserBack |
---|
286 | // DrawText 11,418,"Point Range" |
---|
287 | // DrawText 5,167,"Suffix" |
---|
288 | DrawLine 8,362,287,362 |
---|
289 | PopupMenu popup0,pos={2,2},size={175,20},title="pick a function" |
---|
290 | PopupMenu popup0,mode=1,value= #"User_FunctionPopupList()",proc=AF_FuncPopupProc |
---|
291 | |
---|
292 | ListBox lb pos={11,90},size={280,230},proc=FileListboxProc |
---|
293 | ListBox lb listWave=root:AutoFit:fileListWave,selWave=root:AutoFit:fileSelWave |
---|
294 | ListBox lb editStyle=1,mode=5 |
---|
295 | ListBox lb userColumnResize=1,widths={200,80} |
---|
296 | |
---|
297 | // Button DelButton,pos={245,61},size={40,20},proc=DelButtonProc,title="Del",disable=2 |
---|
298 | Button PathButton,pos={6,61},size={50,20},proc=PDPButton,title="Path..." |
---|
299 | Button FileListButton,pos={182,61},size={50,20},proc=FileListButtonProc,title="List" |
---|
300 | ListBox guessBox,pos={24,398},size={139,208},disable=1,proc=UpdateGuessMatrixProc |
---|
301 | ListBox guessBox,frame=2,listWave=root:AutoFit:guessList |
---|
302 | ListBox guessBox,selWave=root:AutoFit:guessSel,mode= 2,selRow= 0 |
---|
303 | Button FillAllGuessButton,pos={196,406},size={50,20},disable=1,proc=FillAllGuessButtonProc,title="Fill All" |
---|
304 | Button FillAllHoldButton,pos={196,406},size={50,20},disable=1,proc=FillAllHoldButtonProc,title="Fill All" |
---|
305 | Button FillAllConstrButton,pos={196,406},size={50,20},proc=FillAllConstrButtonProc,title="Fill All" |
---|
306 | Button FillAllRangeB,pos={196,406},size={50,20},disable=1,proc=FillAllRangeButtonProc,title="Fill All" |
---|
307 | SetVariable NumParams,pos={7,31},size={161,15},proc=SetNumParamProc,title="Number of Parameters" |
---|
308 | SetVariable NumParams,limits={2,Inf,0},value= root:AutoFit:numPar |
---|
309 | // CheckBox typeCheck,pos={207,31},size={32,14},title="NSE Data?",value=0 |
---|
310 | // SetVariable fitTol,pos={80,208},size={80,15},title="Fit Tol" |
---|
311 | // SetVariable fitTol,limits={0.0001,0.1,0},value= root:AutoFit:fitTol |
---|
312 | CheckBox epsilonCheck,pos={156,335},size={32,14},value=0,title="Use Epsilon Wave?" |
---|
313 | |
---|
314 | TabControl tabC,pos={13,371},size={273,244},proc=tabProc,tabLabel(0)="Guess" |
---|
315 | TabControl tabC,tabLabel(1)="Hold",tabLabel(2)="Constraint",tabLabel(3)="Range",value= 0 |
---|
316 | // CheckBox rangeCheck,pos={92,404},size={32,14},proc=RangeCheckProc,title="All" |
---|
317 | // CheckBox rangeCheck,value= 1,disable=2 |
---|
318 | SetVariable lowPt,pos={136,404},size={60,15},title="low" |
---|
319 | SetVariable lowPt,limits={0,Inf,0},value= root:AutoFit:ptLow,noedit=1,disable=1 |
---|
320 | SetVariable highPt,pos={201,404},size={60,15},title=" to " |
---|
321 | SetVariable highPt,limits={0,Inf,0},value= root:AutoFit:ptHigh,noedit=1,disable=1 |
---|
322 | ListBox holdBox,pos={24,398},size={139,208},disable=1,proc=UpdateHoldMatrixProc |
---|
323 | ListBox holdBox,frame=2,listWave=root:AutoFit:holdList |
---|
324 | ListBox holdBox,selWave=root:AutoFit:holdSel,mode= 2,selRow= 2 |
---|
325 | ListBox ConstrBox,pos={24,398},size={170,208},proc=UpdateConstrMatrixProc |
---|
326 | ListBox ConstrBox,frame=2,listWave=root:AutoFit:ConstrList |
---|
327 | ListBox ConstrBox,selWave=root:AutoFit:ConstrSel,mode= 2,selRow= 2 |
---|
328 | ListBox RangeBox,pos={24,398},size={139,208},proc=UpdateRangeMatrixProc |
---|
329 | ListBox RangeBox,frame=2,listWave=root:AutoFit:rangeList |
---|
330 | ListBox RangeBox,selWave=root:AutoFit:RangeSel,mode= 2,selRow= 2 |
---|
331 | // Button MatrixButton,pos={12,205},size={60,20},proc=ToMatrixButtonProc,title="Matrix",disable=2 |
---|
332 | Button DoItButton,pos={21,632},size={80,20},proc=DoTheFitsButtonProc,title="Do the fits" |
---|
333 | Button savePathButton,pos={82,61},size={80,20},proc=SavePathButtonProc,title="Save Path..." |
---|
334 | TitleBox tb1,pos={139,634},size={128,12},anchor=MC,variable=root:AutoFit:gStatus,frame=0 |
---|
335 | Button button0,pos={14,331},size={40,20},title="Plot",proc=LoadForGuessProc |
---|
336 | // SetVariable extStr,pos={4,170},size={40,15},title=" ",value= root:AutoFit:gExt |
---|
337 | |
---|
338 | Button GuessCoefB,pos={198,440},size={50,20},title="Guess",proc=UseCoefAsGuess |
---|
339 | Button GuessHoldB,pos={198,440},size={50,20},title="Guess",disable=1,proc=UseHoldAsGuess |
---|
340 | Button GuessConstrB,pos={198,440},size={50,20},title="Guess",disable=1,proc=UseConstraintsAsGuess |
---|
341 | |
---|
342 | ValDisplay progressValdisp,pos={113,663},size={161,7},title="00:00" |
---|
343 | ValDisplay progressValdisp,limits={0,root:AutoFit:endProgress,0},barmisc={0,0},value= root:AutoFit:curProgress |
---|
344 | EndMacro |
---|
345 | |
---|
346 | |
---|
347 | Function AF_FuncPopupProc(pa) : PopupMenuControl |
---|
348 | STRUCT WMPopupAction &pa |
---|
349 | |
---|
350 | switch( pa.eventCode ) |
---|
351 | case 2: // mouse up |
---|
352 | Variable popNum = pa.popNum |
---|
353 | String popStr = pa.popStr |
---|
354 | String name=pa.ctrlName |
---|
355 | Variable num=0,nc |
---|
356 | |
---|
357 | String coefStr = getFunctionCoef(popStr) |
---|
358 | String str |
---|
359 | |
---|
360 | NVAR pts1 = root:AutoFit:numPar |
---|
361 | SVAR suff = root:AutoFit:gExt |
---|
362 | |
---|
363 | Wave/Z coef=$("root:"+coefStr) |
---|
364 | if(WaveExists(coef)) |
---|
365 | num=numpnts(coef) |
---|
366 | suff = getModelSuffix(popStr) //get the suffix from the unsmeared model function |
---|
367 | else |
---|
368 | //try getting rid of "Smeared" from the beginning of the function string |
---|
369 | nc = strlen(popStr) |
---|
370 | str = getFunctionCoef(popStr[7,nc-1]) |
---|
371 | Wave/Z cw = $("root:"+str) |
---|
372 | if(WaveExists(cw)) |
---|
373 | num=numpnts(cw) |
---|
374 | endif |
---|
375 | suff = getModelSuffix(popStr[7,nc-1]) //get the suffix from the unsmeared model function |
---|
376 | endif |
---|
377 | |
---|
378 | // set the globals |
---|
379 | pts1 = num |
---|
380 | |
---|
381 | |
---|
382 | |
---|
383 | // set the size of the matrix of initial guesses |
---|
384 | SetNumParamProc("",num,"","") |
---|
385 | |
---|
386 | break |
---|
387 | endswitch |
---|
388 | |
---|
389 | return 0 |
---|
390 | End |
---|
391 | |
---|
392 | |
---|
393 | Function tabProc(name,tab) |
---|
394 | String name |
---|
395 | Variable tab |
---|
396 | |
---|
397 | Button FillAllGuessButton disable= (tab!=0) |
---|
398 | Button GuessCoefB disable=(tab!=0) |
---|
399 | ListBox guessBox disable= (tab!=0) |
---|
400 | |
---|
401 | Button FillAllHoldButton disable= (tab!=1) |
---|
402 | Button GuessHoldB disable=(tab!=1) |
---|
403 | ListBox holdBox disable=(tab!=1) |
---|
404 | |
---|
405 | Button FillAllConstrButton disable= (tab!=2) |
---|
406 | Button GuessConstrB disable=(tab!=2) |
---|
407 | ListBox ConstrBox disable=(tab!=2) |
---|
408 | |
---|
409 | //no buttons on the range tab |
---|
410 | ListBox RangeBox disable=(tab!=3) |
---|
411 | Button FillAllRangeB disable= (tab!=3) |
---|
412 | |
---|
413 | return(0) |
---|
414 | End |
---|
415 | |
---|
416 | |
---|
417 | Function FillAllGuessButtonProc(ctrlName) : ButtonControl |
---|
418 | String ctrlName |
---|
419 | |
---|
420 | //fills all of the guesses with the "current" list of guesses |
---|
421 | WAVE/T gl=root:AutoFit:guessList |
---|
422 | WAVE/T gm=root:AutoFit:guessMatrix |
---|
423 | gm[][] = gl[p] |
---|
424 | return(0) |
---|
425 | End |
---|
426 | |
---|
427 | Function FillAllHoldButtonProc(ctrlName) : ButtonControl |
---|
428 | String ctrlName |
---|
429 | |
---|
430 | //fills all of the guesses with the "current" list of guesses |
---|
431 | WAVE/T hl=root:AutoFit:holdList |
---|
432 | WAVE/T hm=root:AutoFit:holdMatrix |
---|
433 | hm[][] = hl[p] |
---|
434 | return(0) |
---|
435 | End |
---|
436 | |
---|
437 | Function FillAllConstrButtonProc(ctrlName) : ButtonControl |
---|
438 | String ctrlName |
---|
439 | |
---|
440 | //fills all of the guesses with the "current" list of guesses |
---|
441 | WAVE/T cl=root:AutoFit:constrList |
---|
442 | WAVE/T cm=root:AutoFit:ConstrMatrix |
---|
443 | cm[][] = cl[p] |
---|
444 | return(0) |
---|
445 | End |
---|
446 | |
---|
447 | Function FillAllRangeButtonProc(ctrlName) : ButtonControl |
---|
448 | String ctrlName |
---|
449 | |
---|
450 | //fills all of the range values with the top values |
---|
451 | WAVE/T rl=root:AutoFit:rangeList |
---|
452 | WAVE/T rm=root:AutoFit:rangeMatrix |
---|
453 | rm[][] = rl[p] |
---|
454 | return(0) |
---|
455 | End |
---|
456 | |
---|
457 | Function SetNumParamProc(ctrlName,varNum,varStr,varName) : SetVariableControl |
---|
458 | String ctrlName |
---|
459 | Variable varNum |
---|
460 | String varStr |
---|
461 | String varName |
---|
462 | |
---|
463 | //set the number of parameters for the function |
---|
464 | Variable/G numPar=varNum |
---|
465 | |
---|
466 | // adjust the number of parameters in the guesses |
---|
467 | SetMatrixRows(varNum) |
---|
468 | |
---|
469 | return(0) |
---|
470 | End |
---|
471 | |
---|
472 | //expand or collapse the matrices to the number of parameters |
---|
473 | Function SetMatrixRows(newRows) |
---|
474 | Variable newRows |
---|
475 | |
---|
476 | SetDataFolder root:AutoFit |
---|
477 | |
---|
478 | WAVE/T aa = guessMatrix |
---|
479 | WAVE/T bb = holdMatrix |
---|
480 | WAVE/T cc = constrMatrix |
---|
481 | WAVE/T rr = rangeMatrix |
---|
482 | |
---|
483 | Redimension/N=(newRows,-1) aa,bb,cc,rr |
---|
484 | |
---|
485 | //redimension the lists too |
---|
486 | WAVE/T dd=guessList |
---|
487 | WAVE/T ee=holdList |
---|
488 | WAVE/T ff=constrList |
---|
489 | WAVE/T rrl=rangeList |
---|
490 | Redimension/N=(newRows) dd,ee,ff,rrl |
---|
491 | |
---|
492 | WAVE gg=guessSel |
---|
493 | WAVE hh=holdSel |
---|
494 | WAVE ii=constrSel |
---|
495 | WAVE rrs=rangeSel |
---|
496 | //set the selection wave for the individual lists to 2 == editable |
---|
497 | Redimension/N=(newRows) gg,hh,ii,rrs |
---|
498 | gg=2 |
---|
499 | hh=2 |
---|
500 | ii=2 |
---|
501 | rrs=2 |
---|
502 | |
---|
503 | SetDataFolder root: |
---|
504 | |
---|
505 | return 0 |
---|
506 | end |
---|
507 | |
---|
508 | |
---|
509 | Function FileListboxProc(ctrlName,row,col,event) |
---|
510 | String ctrlName // name of this control |
---|
511 | Variable row // row if click in interior, -1 if click in title |
---|
512 | Variable col // column number |
---|
513 | Variable event // event code |
---|
514 | |
---|
515 | if(event==4 && col==0) //selection of a file, not a checkbox |
---|
516 | //then update the listbox display of guesses for the new file |
---|
517 | // Print "file selected" |
---|
518 | DisplayGuess() |
---|
519 | Endif |
---|
520 | |
---|
521 | return 0 // other return values reserved |
---|
522 | End |
---|
523 | |
---|
524 | Function UpdateGuessMatrixProc(ctrlName,row,col,event) |
---|
525 | String ctrlName // name of this control |
---|
526 | Variable row // row if click in interior, -1 if click in title |
---|
527 | Variable col // column number |
---|
528 | Variable event // event code |
---|
529 | |
---|
530 | if(event==7) //finished edit of a cell, update the matrix of guesses |
---|
531 | //Print "updating" |
---|
532 | WAVE/T gl=root:AutoFit:guessList |
---|
533 | WAVE/T gm=root:AutoFit:guessMatrix |
---|
534 | //put new value in guessMatrix |
---|
535 | Variable datafile |
---|
536 | datafile = FindSelectedRowInLB(0) //selected row in file list |
---|
537 | gm[row][datafile] = gl[row] |
---|
538 | //print "row= ",row |
---|
539 | Endif |
---|
540 | return 0 // other return values reserved |
---|
541 | End |
---|
542 | |
---|
543 | Function UpdateHoldMatrixProc(ctrlName,row,col,event) |
---|
544 | String ctrlName // name of this control |
---|
545 | Variable row // row if click in interior, -1 if click in title |
---|
546 | Variable col // column number |
---|
547 | Variable event // event code |
---|
548 | |
---|
549 | if(event==7) //finished edit of a cell, update the matrix of guesses |
---|
550 | //Print "updating" |
---|
551 | WAVE/T hl=root:AutoFit:holdList |
---|
552 | WAVE/T hm=root:AutoFit:holdMatrix |
---|
553 | // put new value in holdMatrix |
---|
554 | Variable datafile |
---|
555 | datafile = FindSelectedRowInLB(0) |
---|
556 | hm[row][datafile] = hl[row] |
---|
557 | //print "row= ",row |
---|
558 | Endif |
---|
559 | return 0 // other return values reserved |
---|
560 | End |
---|
561 | |
---|
562 | Function UpdateConstrMatrixProc(ctrlName,row,col,event) |
---|
563 | String ctrlName // name of this control |
---|
564 | Variable row // row if click in interior, -1 if click in title |
---|
565 | Variable col // column number |
---|
566 | Variable event // event code |
---|
567 | |
---|
568 | if(event==7) //finished edit of a cell, update the matrix of guesses |
---|
569 | //Print "updating" |
---|
570 | WAVE/T cl=root:AutoFit:ConstrList |
---|
571 | WAVE/T cm=root:AutoFit:constrMatrix |
---|
572 | //put new value in constrMatrix |
---|
573 | Variable datafile |
---|
574 | datafile = FindSelectedRowInLB(0) |
---|
575 | cm[row][datafile] = cl[row] |
---|
576 | //print "row= ",row |
---|
577 | Endif |
---|
578 | return 0 // other return values reserved |
---|
579 | End |
---|
580 | |
---|
581 | Function UpdateRangeMatrixProc(ctrlName,row,col,event) |
---|
582 | String ctrlName // name of this control |
---|
583 | Variable row // row if click in interior, -1 if click in title |
---|
584 | Variable col // column number |
---|
585 | Variable event // event code |
---|
586 | |
---|
587 | if(event==7) //finished edit of a cell, update the matrix of guesses |
---|
588 | //Print "updating" |
---|
589 | WAVE/T cl=root:AutoFit:RangeList |
---|
590 | WAVE/T cm=root:AutoFit:RangeMatrix |
---|
591 | //put new value in constrMatrix |
---|
592 | Variable datafile |
---|
593 | datafile = FindSelectedRowInLB(0) |
---|
594 | cm[row][datafile] = cl[row] |
---|
595 | //print "row= ",row |
---|
596 | Endif |
---|
597 | return 0 // other return values reserved |
---|
598 | End |
---|
599 | |
---|
600 | //returns the total number of files checked |
---|
601 | Function numChecked() |
---|
602 | |
---|
603 | WAVE sel = root:AutoFit:fileSelWave |
---|
604 | |
---|
605 | Variable ii,num=0 |
---|
606 | for(ii=0;ii<DimSize(sel,0);ii+=1) |
---|
607 | if( (sel[ii][1] & 0x10) == 16 ) |
---|
608 | num += 1 |
---|
609 | endif |
---|
610 | endfor |
---|
611 | return num |
---|
612 | |
---|
613 | End |
---|
614 | |
---|
615 | |
---|
616 | //Function RangeCheckProc(ctrlName,checked) : CheckBoxControl |
---|
617 | // String ctrlName |
---|
618 | // Variable checked |
---|
619 | // |
---|
620 | // SetVariable lowPt disable=(checked) |
---|
621 | // SetVariable highPt disable=(checked) |
---|
622 | //End |
---|
623 | |
---|
624 | Function DoTheFitsButtonProc(ctrlName) : ButtonControl |
---|
625 | String ctrlName |
---|
626 | |
---|
627 | //read the values from the panel |
---|
628 | ControlInfo/W=AutoFitPanel popup0 |
---|
629 | String funcStr=S_Value |
---|
630 | String fileName |
---|
631 | NVAR numPar=root:AutoFit:numPar |
---|
632 | NVAR startTicks=root:AutoFit:startTicks |
---|
633 | NVAR curProgress=root:AutoFit:curProgress |
---|
634 | NVAR endProgress=root:AutoFit:endProgress |
---|
635 | |
---|
636 | WAVE/T fileWave=root:AutoFit:fileListWave |
---|
637 | WAVE sel = root:AutoFit:fileSelWave |
---|
638 | |
---|
639 | WAVE/T guessMatrix=root:AutoFit:guessMatrix |
---|
640 | WAVE/T holdMatrix=root:AutoFit:holdMatrix |
---|
641 | WAVE/T constrMatrix=root:AutoFit:constrMatrix |
---|
642 | WAVE/T rangeMatrix=root:AutoFit:rangeMatrix |
---|
643 | |
---|
644 | Variable ii=0,numFiles=DimSize(fileWave,0),t1=ticks,t2,matrixindex,count=0 |
---|
645 | //print numFiles |
---|
646 | //for the timer-progress bar - timer shows time, bar shows number of fits remaining |
---|
647 | curProgress = 0 |
---|
648 | endProgress = 3*numChecked() //3 fits per file that is fit |
---|
649 | ValDisplay progressValdisp,limits={0,endProgress,0} |
---|
650 | ControlUpdate/W=AutoFitPanel progressValdisp |
---|
651 | |
---|
652 | //print "numChecked() = ",numChecked() |
---|
653 | startTicks=t1 //starting now |
---|
654 | for(ii=0;ii<numFiles;ii+=1) //loop over everything in the file list, dispatching only checked items |
---|
655 | if( (sel[ii][1] & 0x10) == 16 ) //the box is checked, then go fit it |
---|
656 | fileName = fileWave[ii][0] |
---|
657 | DoOneFit(funcStr,fileName,numPar,fileWave,ii,guessMatrix,holdMatrix,constrMatrix,rangeMatrix) |
---|
658 | count+=1 |
---|
659 | endif |
---|
660 | endfor |
---|
661 | UpdateStatusString("All files processed") |
---|
662 | t2=ticks |
---|
663 | t1=(t2-t1)/60 |
---|
664 | Printf "All %d files processed in %g seconds =(%g minutes) =(%g hours)\r",count,t1,t1/60,t1/60/60 |
---|
665 | return(0) |
---|
666 | End |
---|
667 | |
---|
668 | |
---|
669 | Function DoOneFit(funcStr,fileName,numPar,fileWave,ii,guessMatrix,holdMatrix,constrMatrix,rangeMatrix) |
---|
670 | String funcStr,fileName |
---|
671 | Variable numPar |
---|
672 | WAVE/T fileWave //length <= ii |
---|
673 | Variable ii //index in the full list |
---|
674 | WAVE/T guessMatrix,holdMatrix,constrMatrix,rangeMatrix |
---|
675 | |
---|
676 | String list="",fullName="",dataname="",str="" |
---|
677 | //be sure all is clear (no data, window... etc) |
---|
678 | DoWindow/K AutoGraph //no error is reported |
---|
679 | DoWindow/K AutoGraph_NSE |
---|
680 | list=WaveList("*__*",";","") //not case sensitive? |
---|
681 | DoKillList(list) //get rid of all of the old data |
---|
682 | list=WaveList("wave*",";","") //"wave(n)" can be generated if not all NSE times are collected |
---|
683 | DoKillList(list) |
---|
684 | |
---|
685 | //SANS or NSE data? |
---|
686 | ControlInfo/W=AutoFitPanel typeCheck |
---|
687 | Variable isNSE=v_value |
---|
688 | //load in the data |
---|
689 | PathInfo dataPath |
---|
690 | fullName = S_path |
---|
691 | //fullName += fileWave[ii] |
---|
692 | fullName += fileName |
---|
693 | if(isNSE) |
---|
694 | //load, don't plot |
---|
695 | str = "A_LoadNSEDataWithName(\""+fullName+"\",0)" |
---|
696 | Execute str |
---|
697 | // A_LoadNSEDataWithName(fullName,0) //load, don't plot |
---|
698 | else |
---|
699 | //load, default name, no plot, overwrite data if needed |
---|
700 | str = "A_LoadOneDDataToName(\""+fullName+"\",\"\",0,1)" |
---|
701 | Execute str |
---|
702 | // A_LoadOneDDataToName(fullName,"",0,1) //load, default name, no plot, overwrite data if needed |
---|
703 | endif |
---|
704 | dataName=GetFileNameFromPathNoSemi(fullName) |
---|
705 | dataname=CleanupName(dataname,0) |
---|
706 | |
---|
707 | //graph it - creates window named "AutoGraph" |
---|
708 | if(isNSE) |
---|
709 | Execute "DoGraph_NSE(\""+dataname+"\")" |
---|
710 | else |
---|
711 | Execute "DoGraph(\""+dataname+"\")" |
---|
712 | endif |
---|
713 | |
---|
714 | //generate the needed strings to add to the execute stmt |
---|
715 | // rangeStr, guessStr,constrStr,holdStr |
---|
716 | // and waves - the coefficient wave and paramter wave |
---|
717 | Variable useRes,useEps,useCursors,useConstr |
---|
718 | Variable val,pt1,pt2 |
---|
719 | useEps = 0 |
---|
720 | useConstr = 0 |
---|
721 | useCursors = 0 |
---|
722 | useRes = 0 |
---|
723 | |
---|
724 | String holdStr="",rangeStr="",cStr="",epsilonStr="" |
---|
725 | String DF="root:"+dataname+":" |
---|
726 | |
---|
727 | |
---|
728 | Make/O/D/N=(numPar) myCoef //always named "myCoef" |
---|
729 | Wave cw = root:myCoef |
---|
730 | |
---|
731 | //range string |
---|
732 | useCursors = ParseRangeString(ii,dataname,rangeMatrix,pt1,pt2) //read range from the matrix, return values and set flag |
---|
733 | |
---|
734 | |
---|
735 | //params to hold |
---|
736 | holdStr = ParseHoldString(ii,numpar,holdMatrix) |
---|
737 | //initial guesses |
---|
738 | ParseGuessString(ii,numpar,guessMatrix,"myCoef") |
---|
739 | //constraints |
---|
740 | cStr = ParseConstraints(ii,numpar,constrMatrix,"myConstraints") |
---|
741 | WAVE/Z constr = $"myConstraints" |
---|
742 | if(strlen(cStr)!=0) |
---|
743 | useConstr = 1 |
---|
744 | endif |
---|
745 | //epsilon wave |
---|
746 | epsilonStr = GetEpsilonWave() |
---|
747 | if(strlen(epsilonStr) > 0) |
---|
748 | Wave eps=$epsilonStr //in the root folder |
---|
749 | useEps = 1 |
---|
750 | endif |
---|
751 | |
---|
752 | //fit it |
---|
753 | //these two global variables must be created for IGOR to set them, so that |
---|
754 | //any errors in the fitting can be diagnosed |
---|
755 | Variable/G V_FitError=0 //0=no err, 1=error,(2^1+2^0)=3=singular matrix |
---|
756 | Variable/G V_FitQuitReason=0 //0=ok,1=maxiter,2=user stop,3=no chisq decrease |
---|
757 | NVAR tol=root:AutoFit:fitTol |
---|
758 | Variable/G V_FitTol=tol //default is 0.0001 |
---|
759 | Variable/G V_fitOptions=4 //suppress the dialog during fitting (we're not waiting for OK, anyways) |
---|
760 | |
---|
761 | |
---|
762 | Wave yw = $(DF+dataName+"_i") |
---|
763 | Wave xw = $(DF+dataName+"_q") |
---|
764 | Wave sw = $(DF+dataName+"_s") |
---|
765 | |
---|
766 | if(stringmatch(funcStr, "Smear*")) // if it's a smeared function, need a struct |
---|
767 | useRes=1 |
---|
768 | endif |
---|
769 | |
---|
770 | Struct ResSmearAAOStruct fs |
---|
771 | WAVE/Z resW = $(DF+dataName+"_res") //these may not exist, if 3-column data is used |
---|
772 | WAVE/Z fs.resW = resW |
---|
773 | WAVE yw=$(DF+dataName+"_i") |
---|
774 | WAVE xw=$(DF+dataName+"_q") |
---|
775 | WAVE sw=$(DF+dataName+"_s") |
---|
776 | Wave fs.coefW = cw |
---|
777 | Wave fs.yW = yw |
---|
778 | Wave fs.xW = xw |
---|
779 | |
---|
780 | Duplicate/O yw $(DF+"FitYw") |
---|
781 | WAVE fitYw = $(DF+"FitYw") |
---|
782 | fitYw = NaN |
---|
783 | |
---|
784 | NVAR useGenCurveFit = root:Packages:NIST:gUseGenCurveFit |
---|
785 | ///// SEE FitWrapper() for more details. |
---|
786 | |
---|
787 | Variable nPass = 1 |
---|
788 | |
---|
789 | do // outer do is the loop over passes |
---|
790 | do // this inner loop is abig switch to select the correct FutFunc to dispatch |
---|
791 | if(useGenCurveFit) |
---|
792 | #if !(exists("GenCurveFit")) |
---|
793 | // XOP not available |
---|
794 | useGenCurveFit = 0 |
---|
795 | Abort "Genetic Optimiztion XOP not available. Reverting to normal optimization." |
---|
796 | #endif |
---|
797 | //send everything to a function, to reduce the clutter |
---|
798 | // useEps and useConstr are not needed |
---|
799 | // pass the structure to get the current waves, including the trimmed USANS matrix |
---|
800 | Variable chi,pt |
---|
801 | |
---|
802 | chi = DoGenCurveFit(useRes,useCursors,sw,fitYw,fs,funcStr,ParseHoldString(ii,numpar,holdMatrix),val,lolim,hilim,pt1,pt2) |
---|
803 | pt = val |
---|
804 | |
---|
805 | break |
---|
806 | |
---|
807 | endif |
---|
808 | |
---|
809 | |
---|
810 | if(useRes && useEps && useCursors && useConstr) //do it all |
---|
811 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs |
---|
812 | break |
---|
813 | endif |
---|
814 | |
---|
815 | if(useRes && useEps && useCursors) //no constr |
---|
816 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs |
---|
817 | break |
---|
818 | endif |
---|
819 | |
---|
820 | if(useRes && useEps && useConstr) //no crsr |
---|
821 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr /STRC=fs |
---|
822 | break |
---|
823 | endif |
---|
824 | |
---|
825 | if(useRes && useCursors && useConstr) //no eps |
---|
826 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs |
---|
827 | break |
---|
828 | endif |
---|
829 | |
---|
830 | if(useRes && useCursors) //no eps, no constr |
---|
831 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /STRC=fs |
---|
832 | break |
---|
833 | endif |
---|
834 | |
---|
835 | if(useRes && useEps) //no crsr, no constr |
---|
836 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs |
---|
837 | break |
---|
838 | endif |
---|
839 | |
---|
840 | if(useRes && useConstr) //no crsr, no eps |
---|
841 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs |
---|
842 | break |
---|
843 | endif |
---|
844 | |
---|
845 | if(useRes) //just res |
---|
846 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /STRC=fs |
---|
847 | break |
---|
848 | endif |
---|
849 | |
---|
850 | ///// same as above, but all without useRes (no /STRC flag) |
---|
851 | if(useEps && useCursors && useConstr) //do it all |
---|
852 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr |
---|
853 | break |
---|
854 | endif |
---|
855 | |
---|
856 | if(useEps && useCursors) //no constr |
---|
857 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw |
---|
858 | break |
---|
859 | endif |
---|
860 | |
---|
861 | if(useEps && useConstr) //no crsr |
---|
862 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr |
---|
863 | break |
---|
864 | endif |
---|
865 | |
---|
866 | if(useCursors && useConstr) //no eps |
---|
867 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /C=constr |
---|
868 | break |
---|
869 | endif |
---|
870 | |
---|
871 | if(useCursors) //no eps, no constr |
---|
872 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw |
---|
873 | break |
---|
874 | endif |
---|
875 | |
---|
876 | if(useEps) //no crsr, no constr |
---|
877 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw |
---|
878 | break |
---|
879 | endif |
---|
880 | |
---|
881 | if(useConstr) //no crsr, no eps |
---|
882 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr |
---|
883 | break |
---|
884 | endif |
---|
885 | |
---|
886 | //just a plain vanilla fit |
---|
887 | FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw |
---|
888 | |
---|
889 | while(0) //always exit the inner do to select the FutFunc syntax. The break will exit this loop |
---|
890 | |
---|
891 | if(nPass == 1) |
---|
892 | UpdateStatusString(dataname +" Fit #1") |
---|
893 | Variable/G gChiSq1 = V_chisq |
---|
894 | endif |
---|
895 | |
---|
896 | if(nPass == 2) |
---|
897 | UpdateStatusString(dataname +" Fit #2") |
---|
898 | Variable/G gChiSq2 = V_chisq |
---|
899 | endif |
---|
900 | |
---|
901 | if(nPass == 3) |
---|
902 | UpdateStatusString(dataname +" Fit #3") |
---|
903 | endif |
---|
904 | |
---|
905 | nPass += 1 |
---|
906 | while(nPass < 4) |
---|
907 | |
---|
908 | // append the fit |
---|
909 | // need to manage duplicate copies |
---|
910 | // Don't plot the full curve if cursors were used (set fitYw to NaN on entry...) |
---|
911 | String traces=TraceNameList("", ";", 1 ) //"" as first parameter == look on the target graph |
---|
912 | if(strsearch(traces,"FitYw",0) == -1) |
---|
913 | if(useGenCurveFit && useCursors) |
---|
914 | WAVE trimX = trimX |
---|
915 | AppendtoGraph fitYw vs trimX |
---|
916 | else |
---|
917 | AppendToGraph FitYw vs xw |
---|
918 | endif |
---|
919 | else |
---|
920 | RemoveFromGraph FitYw |
---|
921 | if(useGenCurveFit && useCursors) |
---|
922 | WAVE trimX = trimX |
---|
923 | AppendtoGraph fitYw vs trimX |
---|
924 | else |
---|
925 | AppendToGraph FitYw vs xw |
---|
926 | endif |
---|
927 | endif |
---|
928 | ModifyGraph lsize(FitYw)=2,rgb(FitYw)=(52428,1,1) |
---|
929 | |
---|
930 | |
---|
931 | //do the report calling the function, not the proc |
---|
932 | String topGraph= WinName(0,1) //this is the topmost graph |
---|
933 | SVAR suffix = root:AutoFit:gExt //don't try to read as getModelSuffix(funcStr), since the smeared() may not be plotted |
---|
934 | String parStr=GetWavesDataFolder(cw,1)+ WaveList("*param*"+"_"+suffix, "", "TEXT:1," ) // this is *hopefully* one wave |
---|
935 | |
---|
936 | if(isNSE) |
---|
937 | GenerateReport_NSE(funcStr,dataname,"par","myCoef",1) |
---|
938 | else |
---|
939 | W_GenerateReport(funcStr,dataname,$parStr,$"myCoef",1,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph) |
---|
940 | |
---|
941 | // AutoFit_GenerateReport(funcStr,dataname,"par","myCoef",1) |
---|
942 | endif |
---|
943 | |
---|
944 | return(0) |
---|
945 | End |
---|
946 | |
---|
947 | //// to be able to simply fill in the pt range of the yw[lo,hi] |
---|
948 | //Function LowRange() |
---|
949 | // NVAR val = root:AutoFit:ptLow |
---|
950 | // return(val) |
---|
951 | //End |
---|
952 | // |
---|
953 | //Function HighRange() |
---|
954 | // NVAR val = root:AutoFit:ptHigh |
---|
955 | // return(val) |
---|
956 | //End |
---|
957 | |
---|
958 | //updates the status string, forcing a redraw twice, to overcome what seems to be a bug in Igor4 |
---|
959 | //also updates the progress bar and the countdown |
---|
960 | Function UpdateStatusString(newStr) |
---|
961 | String newStr |
---|
962 | |
---|
963 | SVAR gStatus=root:AutoFit:gStatus |
---|
964 | SVAR gStatFormat=root:AutoFit:gStatFormat |
---|
965 | gStatus="" |
---|
966 | ControlUpdate/W=AutoFitPanel tb1 //clears the line |
---|
967 | gStatus=gStatFormat+newStr |
---|
968 | ControlUpdate/W=AutoFitPanel tb1 |
---|
969 | |
---|
970 | //update the progress bar and timer |
---|
971 | NVAR cur=root:AutoFit:curProgress |
---|
972 | NVAR endProgress=root:AutoFit:endProgress |
---|
973 | NVAR startTicks=root:AutoFit:startTicks |
---|
974 | cur+=1 |
---|
975 | |
---|
976 | // Print "****" |
---|
977 | // Print "cur = ",cur |
---|
978 | |
---|
979 | Variable t2=ticks,projTot,projRemain |
---|
980 | String titleStr="" |
---|
981 | |
---|
982 | projTot = (t2-startTicks)/(cur-1)*endProgress |
---|
983 | projRemain = projTot - (t2-startTicks) |
---|
984 | projRemain /= 60.15 //to seconds |
---|
985 | DoWindow/F AutoFitPanel |
---|
986 | ValDisplay progressValdisp,title=Secs2time(projRemain,5) |
---|
987 | ControlUpdate/W=AutoFitPanel progressValdisp |
---|
988 | |
---|
989 | // Print "End Progress = ",endProgress |
---|
990 | // Print "ProjTot = ",projTot/60.15 |
---|
991 | // Print "ProjRemain = ",projRemain |
---|
992 | |
---|
993 | return(0) |
---|
994 | End |
---|
995 | |
---|
996 | // returns a string with the name of the epsilon wave, or null if it doesn't exist |
---|
997 | Function/S GetEpsilonWave() |
---|
998 | |
---|
999 | String retStr="",testStr |
---|
1000 | SVAR extStr = root:AutoFit:gExt |
---|
1001 | //do you want to use epsilon wave? |
---|
1002 | ControlInfo/W=AutoFitPanel epsilonCheck |
---|
1003 | if(V_Value == 0) //not checked |
---|
1004 | return(retStr) |
---|
1005 | endif |
---|
1006 | |
---|
1007 | testStr = "Epsilon_"+extStr |
---|
1008 | if(waveexists($testStr) != 0) |
---|
1009 | // return(" /E="+testStr) |
---|
1010 | return(testStr) |
---|
1011 | endif |
---|
1012 | return(retStr) |
---|
1013 | End |
---|
1014 | |
---|
1015 | //returns the y data to fit - "_i" suffix, and range if selected |
---|
1016 | // enter the range as the first element[0] as low point, second element[1] as high point |
---|
1017 | // leave the other elements blank |
---|
1018 | // |
---|
1019 | // if either point value is not entered, the whole data set is used |
---|
1020 | // |
---|
1021 | // -- if both of the elements are between 0 and 1, assume they are q-values (check for fractional part) |
---|
1022 | // and find the appropriate points... |
---|
1023 | // |
---|
1024 | Function ParseRangeString(set,dataStr,rMat,lo,hi) |
---|
1025 | Variable set |
---|
1026 | String dataStr |
---|
1027 | WAVE/T rMat |
---|
1028 | Variable &lo,&hi |
---|
1029 | |
---|
1030 | Variable useCursors |
---|
1031 | |
---|
1032 | lo = str2num(rMat[0][set]) |
---|
1033 | hi = str2num(rMat[1][set]) |
---|
1034 | |
---|
1035 | if(lo == 0 && hi == 0) |
---|
1036 | return(0) |
---|
1037 | endif |
---|
1038 | |
---|
1039 | if(numtype(lo) != 0 || numtype(hi) != 0) //not a normal number |
---|
1040 | return(0) //don't use cursor values, use all of the dataset |
---|
1041 | endif |
---|
1042 | |
---|
1043 | |
---|
1044 | if(lo>=hi) //error in specification, or all data desired (both zero or undefined) |
---|
1045 | return(0) //use all of the dataset |
---|
1046 | endif |
---|
1047 | |
---|
1048 | |
---|
1049 | if(trunc(lo) != lo || trunc(hi) != hi) //values have fractional parts |
---|
1050 | WAVE xW = $("root:"+dataStr+":"+dataStr + "_q") |
---|
1051 | FindLevel/P/Q xW, lo |
---|
1052 | lo = trunc(V_levelX) //find the corresponding point values |
---|
1053 | FindLevel/P/Q xW, hi |
---|
1054 | hi = trunc(V_levelX) |
---|
1055 | endif |
---|
1056 | |
---|
1057 | Variable/G root:AutoFit:ptLow = lo |
---|
1058 | Variable/G root:AutoFit:ptHigh = hi |
---|
1059 | |
---|
1060 | return(1) |
---|
1061 | End |
---|
1062 | |
---|
1063 | //returns the holdStr, i.e. "1010101" |
---|
1064 | Function/S ParseHoldString(set,npar,hMat) |
---|
1065 | Variable set,npar |
---|
1066 | WAVE/T hMat |
---|
1067 | |
---|
1068 | Variable ii |
---|
1069 | String retStr="" |
---|
1070 | |
---|
1071 | for(ii=0;ii<npar;ii+=1) |
---|
1072 | if(strlen(hMat[ii][set]) == 0) |
---|
1073 | retStr += "0" |
---|
1074 | else |
---|
1075 | retStr += hMat[ii][set] |
---|
1076 | endif |
---|
1077 | endfor |
---|
1078 | |
---|
1079 | // Print retStr |
---|
1080 | |
---|
1081 | return(retStr) |
---|
1082 | End |
---|
1083 | |
---|
1084 | //returns only error - wave must already exist |
---|
1085 | Function ParseGuessString(set,npar,gMat,outWStr) |
---|
1086 | Variable set,npar |
---|
1087 | WAVE/T gMat |
---|
1088 | String outWStr |
---|
1089 | |
---|
1090 | Variable ii |
---|
1091 | String retStr=outWStr |
---|
1092 | |
---|
1093 | WAVE outWave=$outWStr |
---|
1094 | for(ii=0;ii<npar;ii+=1) |
---|
1095 | outWave[ii] = str2num(gMat[ii][set]) |
---|
1096 | endfor |
---|
1097 | return(0) |
---|
1098 | End |
---|
1099 | |
---|
1100 | //the constraint wave is created here |
---|
1101 | Function/S ParseConstraints(set,npar,cMat,outWStr) |
---|
1102 | Variable set,npar |
---|
1103 | WAVE/T cMat |
---|
1104 | String outWStr |
---|
1105 | |
---|
1106 | String retStr="",loStr="",hiStr="" |
---|
1107 | Variable ii=0,jj=0 |
---|
1108 | Make/O/T/N=0 $outWStr |
---|
1109 | WAVE/T cw = $outWStr |
---|
1110 | //return "/C="+outWStr if parsed ok, or null if not |
---|
1111 | |
---|
1112 | String listStr="" |
---|
1113 | for(ii=0;ii<npar;ii+=1) |
---|
1114 | listStr=cMat[ii][set] |
---|
1115 | loStr=StringFromList(0, listStr ,";") |
---|
1116 | hiStr=StringFromList(1, listStr ,";") |
---|
1117 | if(cmpstr(loStr,"")!=0) //something there... |
---|
1118 | InsertPoints jj,1,cw //insert before element jj |
---|
1119 | cw[jj] = "K"+num2Str(ii)+">"+loStr |
---|
1120 | jj+=1 |
---|
1121 | endif |
---|
1122 | if(cmpstr(hiStr,"")!=0) //something there... |
---|
1123 | InsertPoints jj,1,cw //insert before element jj |
---|
1124 | cw[jj] = "K"+num2Str(ii)+"<"+hiStr |
---|
1125 | jj+=1 |
---|
1126 | endif |
---|
1127 | endfor |
---|
1128 | if(numpnts(cw) > 0 ) |
---|
1129 | retStr = "/C=" + outWStr |
---|
1130 | Endif |
---|
1131 | // print "strlen, conStr= ",strlen(retStr),retstr |
---|
1132 | |
---|
1133 | return(retStr) //null string will be returned if no constraints |
---|
1134 | End |
---|
1135 | |
---|
1136 | |
---|
1137 | //************************* |
---|
1138 | Proc DoGraph(dataname) |
---|
1139 | String dataname |
---|
1140 | |
---|
1141 | SetDataFolder $dataname |
---|
1142 | |
---|
1143 | PauseUpdate; Silent 1 // building window... |
---|
1144 | Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q") |
---|
1145 | DoWindow/C AutoGraph |
---|
1146 | ModifyGraph mode($(dataname+"_i"))=3 |
---|
1147 | ModifyGraph marker($(dataname+"_i"))=19 |
---|
1148 | ModifyGraph rgb($(dataname+"_i"))=(1,4,52428) |
---|
1149 | ModifyGraph msize($(dataname+"_i"))=2 |
---|
1150 | ModifyGraph grid=1 |
---|
1151 | ModifyGraph log=1 |
---|
1152 | ModifyGraph tickUnit=1 |
---|
1153 | // |
---|
1154 | ModifyGraph mirror=2 |
---|
1155 | // |
---|
1156 | ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s")) |
---|
1157 | // Legend/A=LB |
---|
1158 | // Legend/A=LB/X=0.00/Y=-32 //defaults to the top right |
---|
1159 | Legend/A=MT/E // /X=-16.16/Y=5.17/E |
---|
1160 | |
---|
1161 | SetDataFolder root: |
---|
1162 | |
---|
1163 | EndMacro |
---|
1164 | |
---|
1165 | Proc DoGraph_NSE(dataname) |
---|
1166 | String dataname |
---|
1167 | |
---|
1168 | SetDataFolder $dataname |
---|
1169 | |
---|
1170 | PauseUpdate; Silent 1 // building window... |
---|
1171 | Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q") |
---|
1172 | DoWindow/C AutoGraph_NSE |
---|
1173 | ModifyGraph mode($(dataname+"_i"))=3 |
---|
1174 | ModifyGraph marker($(dataname+"_i"))=19 |
---|
1175 | ModifyGraph rgb($(dataname+"_i"))=(1,4,52428) |
---|
1176 | ModifyGraph msize($(dataname+"_i"))=3 |
---|
1177 | ModifyGraph zColor($(dataname+"_i"))={$(dataname+"__Q"),$(dataname+"__Q")[0]*0.99,*,Rainbow} |
---|
1178 | ModifyGraph grid=1 |
---|
1179 | ModifyGraph mirror=2 |
---|
1180 | ModifyGraph log(left)=1 |
---|
1181 | ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s")) |
---|
1182 | Legend/A=MB |
---|
1183 | SetAxis/A/E=1 bottom |
---|
1184 | ModifyGraph standoff=0 |
---|
1185 | SetAxis left 0.1,1 |
---|
1186 | //ModifyGraph tickUnit(left)=1 |
---|
1187 | EndMacro |
---|
1188 | |
---|
1189 | //************************* |
---|
1190 | |
---|
1191 | |
---|
1192 | //************************** |
---|
1193 | // Generate the report |
---|
1194 | //************************** |
---|
1195 | |
---|
1196 | ////must have AutoGraph as the name of the graph window (any size) |
---|
1197 | //// func is the name of the function (for print only) |
---|
1198 | ////par and coef are the exact names of the waves |
---|
1199 | ////yesSave==1 will save the file(name=func+time) |
---|
1200 | //// |
---|
1201 | //// |
---|
1202 | //// general report function from the wrapper is used instead |
---|
1203 | //// W_GenerateReport(funcStr,folderStr,$parStr,cw,yesSave,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph) |
---|
1204 | //// |
---|
1205 | //Function AutoFit_GenerateReport(func,dataname,par,myCoef,yesSave) |
---|
1206 | // String func,dataname,par,myCoef |
---|
1207 | // Variable yesSave |
---|
1208 | // |
---|
1209 | // String str,pictStr="P_" |
---|
1210 | // Wave sigWave=$"W_sigma" |
---|
1211 | // Wave ans=$myCoef |
---|
1212 | //// Wave/T param=$par |
---|
1213 | // SVAR ext=root:AutoFit:gExt |
---|
1214 | // Wave/T param=$"parameters_"+ext |
---|
1215 | // |
---|
1216 | // NVAR V_chisq = V_chisq |
---|
1217 | // NVAR V_npnts = V_npnts |
---|
1218 | // NVAR V_FitError = V_FitError |
---|
1219 | // NVAR V_FitQuitReason = V_FitQuitReason |
---|
1220 | // NVAR chi1=gChiSq1 |
---|
1221 | // NVAR chi2=gChiSq2 |
---|
1222 | // NVAR V_startRow = V_startRow |
---|
1223 | // NVAR V_endRow = V_endRow |
---|
1224 | // |
---|
1225 | // // bring report up |
---|
1226 | // DoWindow/F Report |
---|
1227 | // if (V_flag == 0) // Report notebook doesn't exist ? |
---|
1228 | // NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report" |
---|
1229 | // endif |
---|
1230 | // |
---|
1231 | // // delete old stuff |
---|
1232 | // Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile} |
---|
1233 | // |
---|
1234 | // // insert title |
---|
1235 | // Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)} |
---|
1236 | // sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time() |
---|
1237 | // Notebook Report ruler=Title, text=str |
---|
1238 | // |
---|
1239 | // // insert fit results |
---|
1240 | // Variable num=numpnts(ans),ii=0 |
---|
1241 | // Notebook Report ruler=Normal; Notebook Report margins={18,18,504}, tabs={63 + 3*8192} |
---|
1242 | // str = "Data file: " + dataname + "\r\r" |
---|
1243 | // Notebook Report text=str |
---|
1244 | // do |
---|
1245 | // sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii] |
---|
1246 | // Notebook Report text=str |
---|
1247 | // ii+=1 |
---|
1248 | // while(ii<num) |
---|
1249 | // |
---|
1250 | // // |
---|
1251 | // Wave dataXw = $(dataname+"_q") |
---|
1252 | // Variable nData=numpnts(dataXw) |
---|
1253 | // |
---|
1254 | // // |
---|
1255 | // sprintf str,"chisq = %g , %g , %g\r",chi1,chi2,V_chisq |
---|
1256 | // Notebook Report textRGB=(65000,0,0),fstyle=1,text=str |
---|
1257 | // sprintf str,"Npnts = %g, sqrt(X^2/N) = %g\r",V_npnts,sqrt(V_chisq/V_npnts) |
---|
1258 | // Notebook Report textRGB=(0,0,0),fstyle=0, text=str |
---|
1259 | // sprintf str "Fitted range = [%d,%d] = %g < Q < %g\r",V_startRow,V_endRow,dataXw(V_startRow),dataXw(V_endRow) |
---|
1260 | // Notebook Report textRGB=(0,0,0),fstyle=0, text=str |
---|
1261 | // sprintf str,"V_FitError = %g\t\tV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason |
---|
1262 | // Notebook Report textRGB=(65000,0,0),fstyle=1,text=str |
---|
1263 | // Notebook Report ruler=Normal |
---|
1264 | // |
---|
1265 | // // insert graphs |
---|
1266 | // Notebook Report picture={AutoGraph(0, 0, 400, 300), 0, 1}, text="\r" |
---|
1267 | // |
---|
1268 | // |
---|
1269 | // //Notebook Report picture={Table1, 0, 0}, text="\r" |
---|
1270 | // |
---|
1271 | // // show the top of the report |
---|
1272 | // Notebook Report selection= {startOfFile, startOfFile}, findText={"", 1} |
---|
1273 | // |
---|
1274 | // //save the notebook |
---|
1275 | // if(yesSave) |
---|
1276 | // String nameStr=CleanupName(func,0) |
---|
1277 | // nameStr = nameStr[0,8] //shorten the name |
---|
1278 | // nameStr += "_"+dataname |
---|
1279 | // //make sure the name is no more than 31 characters |
---|
1280 | // namestr = namestr[0,30] //if shorter than 31, this will NOT pad to 31 characters |
---|
1281 | // Print "file saved as ",nameStr |
---|
1282 | // SaveNotebook /O/P=savePath/S=2 Report as nameStr |
---|
1283 | // //save the graph separately as a PICT file, 2x screen |
---|
1284 | // pictStr += nameStr |
---|
1285 | // pictStr = pictStr[0,28] //need a shorter name - why? |
---|
1286 | // DoWindow/F AutoGraph |
---|
1287 | // // E=-5 is png @screen resolution |
---|
1288 | // // E=2 is PICT @2x screen resolution |
---|
1289 | // SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as pictStr |
---|
1290 | // Endif |
---|
1291 | // |
---|
1292 | // // ???maybe print the notebook too? |
---|
1293 | //End |
---|
1294 | |
---|
1295 | |
---|
1296 | |
---|
1297 | // |
---|
1298 | //Proc DoGenerateReport(fname,dataname,param,coef,yesno) |
---|
1299 | // String fname,dataname="",param,coef,yesno="No" |
---|
1300 | // Prompt fname,"function name",popup,FunctionList("!Sme*",";","KIND:15,") |
---|
1301 | // Prompt dataname,"name of the dataset" |
---|
1302 | // Prompt param,"parameter names",popup,WaveList("par*",";","") |
---|
1303 | // Prompt coef,"coefficient wave",popup,WaveList("coe*",";","") |
---|
1304 | // Prompt yesno,"Save the report?",popup,"Yes;No;" |
---|
1305 | // |
---|
1306 | // //Print "fname = ",fname |
---|
1307 | // //Print "param = ",param |
---|
1308 | // //Print "coef = ",coef |
---|
1309 | // //Print "yesno = ",yesno |
---|
1310 | // |
---|
1311 | // Variable doSave=0 |
---|
1312 | // if(cmpstr(yesno,"Yes")==0) |
---|
1313 | // doSave=1 |
---|
1314 | // Endif |
---|
1315 | // GenerateReport(fname,dataname,param,coef,dosave) |
---|
1316 | // |
---|
1317 | //End |
---|
1318 | |
---|
1319 | |
---|
1320 | |
---|
1321 | //must have AutoGraph_NSE as the name of the graph window (any size) |
---|
1322 | // func is the name of the function (for print only) |
---|
1323 | //par and coef are the exact names of the waves |
---|
1324 | //yesSave==1 will save the file(name=func+time) |
---|
1325 | // |
---|
1326 | Function GenerateReport_NSE(func,dataname,par,coef,yesSave) |
---|
1327 | String func,dataname,par,coef |
---|
1328 | Variable yesSave |
---|
1329 | |
---|
1330 | String str |
---|
1331 | Wave sigWave=$"W_sigma" |
---|
1332 | Wave ans=$coef |
---|
1333 | Wave/T param=$par |
---|
1334 | |
---|
1335 | NVAR V_chisq = V_chisq |
---|
1336 | NVAR V_npnts = V_npnts |
---|
1337 | NVAR V_FitError = V_FitError |
---|
1338 | NVAR V_FitQuitReason = V_FitQuitReason |
---|
1339 | |
---|
1340 | // bring report up |
---|
1341 | DoWindow/F Report |
---|
1342 | if (V_flag == 0) // Report notebook doesn't exist ? |
---|
1343 | NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report" |
---|
1344 | endif |
---|
1345 | |
---|
1346 | // delete old stuff |
---|
1347 | Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile} |
---|
1348 | |
---|
1349 | // insert title |
---|
1350 | Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)} |
---|
1351 | sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time() |
---|
1352 | Notebook Report ruler=Title, text=str |
---|
1353 | |
---|
1354 | // insert fit results |
---|
1355 | Variable num=numpnts(ans),ii=0 |
---|
1356 | Notebook Report ruler=Normal; Notebook Report margins={18,18,504}, tabs={63 + 3*8192} |
---|
1357 | str = "Data file: " + dataname + "\r\r" |
---|
1358 | Notebook Report text=str |
---|
1359 | do |
---|
1360 | sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii] |
---|
1361 | Notebook Report text=str |
---|
1362 | ii+=1 |
---|
1363 | while(ii<num) |
---|
1364 | |
---|
1365 | sprintf str,"chisq = %g\r",V_chisq |
---|
1366 | Notebook Report textRGB=(65000,0,0),fstyle=1,text=str |
---|
1367 | sprintf str,"Npnts = %g\r",V_npnts |
---|
1368 | Notebook Report textRGB=(0,0,0),fstyle=0, text=str |
---|
1369 | sprintf str,"V_FitError = %g\rV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason |
---|
1370 | Notebook Report textRGB=(65000,0,0),fstyle=1,text=str |
---|
1371 | Notebook Report ruler=Normal |
---|
1372 | |
---|
1373 | // insert graphs |
---|
1374 | Notebook Report picture={AutoGraph_NSE(0, 0, 400, 300), 0, 1}, text="\r" |
---|
1375 | //Notebook Report picture={Table1, 0, 0}, text="\r" |
---|
1376 | |
---|
1377 | // show the top of the report |
---|
1378 | Notebook Report selection= {startOfFile, startOfFile}, findText={"", 1} |
---|
1379 | |
---|
1380 | //save the notebook |
---|
1381 | if(yesSave) |
---|
1382 | String nameStr=CleanupName(func,0) |
---|
1383 | nameStr = nameStr[0,8] //shorten the name |
---|
1384 | nameStr += "_"+dataname |
---|
1385 | //make sure the name is no more than 31 characters |
---|
1386 | namestr = namestr[0,30] //if shorter than 31, this will NOT pad to 31 characters |
---|
1387 | Print "file saved as ",nameStr |
---|
1388 | SaveNotebook /O/P=savePath/S=2 Report as nameStr |
---|
1389 | Endif |
---|
1390 | |
---|
1391 | //save a pict file, just of the graph |
---|
1392 | namestr = "PICT_" + namestr |
---|
1393 | namestr = namestr[0,28] //PICT names in IGOR must be shorter, to allow auto-naming? |
---|
1394 | DoWindow/F AutoGraph_NSE |
---|
1395 | SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as nameStr |
---|
1396 | End |
---|
1397 | |
---|
1398 | |
---|
1399 | //********************* |
---|
1400 | // |
---|
1401 | //********************* |
---|
1402 | // List utilities |
---|
1403 | //********************* |
---|
1404 | // |
---|
1405 | // List2TextWave is also in SANS_Utilities.ipf, but to keep from having big lists of dependencies, |
---|
1406 | // have definitions here that are local and Static |
---|
1407 | |
---|
1408 | // |
---|
1409 | Static Function List2TextWave(list,sep,waveStr) |
---|
1410 | String list,sep,waveStr |
---|
1411 | |
---|
1412 | Variable n= ItemsInList(list,sep) |
---|
1413 | Make/O/T/N=(n) $waveStr= StringFromList(p,list,sep) |
---|
1414 | End |
---|
1415 | |
---|
1416 | Function List2NumWave(list,sep,waveStr) |
---|
1417 | String list,sep,waveStr |
---|
1418 | |
---|
1419 | Variable n= ItemsInList(list,sep) |
---|
1420 | Make/O/D/N=(n) $waveStr= str2num( StringFromList(p,list,sep) ) |
---|
1421 | End |
---|
1422 | |
---|
1423 | Function/S TextWave2List(w,sep) |
---|
1424 | Wave/T w |
---|
1425 | String sep |
---|
1426 | |
---|
1427 | String newList="" |
---|
1428 | Variable n=numpnts(w),ii=0 |
---|
1429 | do |
---|
1430 | newList += w[ii] + sep |
---|
1431 | ii+=1 |
---|
1432 | while(ii<n) |
---|
1433 | return(newList) |
---|
1434 | End |
---|
1435 | |
---|
1436 | //for single precision numerical waves |
---|
1437 | Function/S NumWave2List(w,sep) |
---|
1438 | Wave w |
---|
1439 | String sep |
---|
1440 | |
---|
1441 | String newList="",temp="" |
---|
1442 | Variable n=numpnts(w),ii=0,val |
---|
1443 | do |
---|
1444 | val=w[ii] |
---|
1445 | temp="" |
---|
1446 | sprintf temp,"%g",val |
---|
1447 | newList += temp |
---|
1448 | newList += sep |
---|
1449 | ii+=1 |
---|
1450 | while(ii<n) |
---|
1451 | return(newList) |
---|
1452 | End |
---|
1453 | |
---|
1454 | Function DoKillList(list) |
---|
1455 | String list |
---|
1456 | |
---|
1457 | String item="" |
---|
1458 | do |
---|
1459 | item = StringFromList(0, list ,";" ) |
---|
1460 | KillWaves/Z $item |
---|
1461 | list = RemoveFromList(item, list, ";") |
---|
1462 | while(ItemsInList(list, ";")>0) |
---|
1463 | End |
---|
1464 | |
---|
1465 | //********************* |
---|
1466 | |
---|
1467 | |
---|
1468 | |
---|
1469 | //******************* |
---|
1470 | //Notebook Utils |
---|
1471 | //******************* |
---|
1472 | |
---|
1473 | Proc PrintOpenNotebooks() |
---|
1474 | |
---|
1475 | String list=WinList("*", ";", "WIN:16") |
---|
1476 | String item = "" |
---|
1477 | do |
---|
1478 | item=StringFromList(0,list,";") |
---|
1479 | Print item |
---|
1480 | PrintNotebook $item |
---|
1481 | list = RemoveFromList(item, list, ";") |
---|
1482 | while(ItemsInList(list, ";")>0) |
---|
1483 | End |
---|
1484 | |
---|
1485 | Proc CloseOpenNotebooks() |
---|
1486 | |
---|
1487 | String list=WinList("*", ";", "WIN:16") |
---|
1488 | String item = "" |
---|
1489 | do |
---|
1490 | item=StringFromList(0,list,";") |
---|
1491 | DoWindow/K $item |
---|
1492 | list = RemoveFromList(item, list, ";") |
---|
1493 | while(ItemsInList(list, ";")>0) |
---|
1494 | End |
---|
1495 | |
---|
1496 | Proc Generate_PICTS_list() |
---|
1497 | fGenerate_PICTS_list() |
---|
1498 | End |
---|
1499 | |
---|
1500 | //spits up a list of PICTS |
---|
1501 | Function fGenerate_PICTS_list() |
---|
1502 | |
---|
1503 | String List=IndexedFile(savePath, -1, "PICT") |
---|
1504 | List2TextWave(List,";","PICT_files") |
---|
1505 | WAVE/T picts=$"PICT_files" |
---|
1506 | Edit/K=1 picts |
---|
1507 | End |
---|
1508 | |
---|
1509 | Proc Layout_PICTS(pStr) |
---|
1510 | String pStr="" |
---|
1511 | Prompt pStr,"wave of PICTs to use",popup,WaveList("PICT_f*", ";", "") |
---|
1512 | |
---|
1513 | String List=TextWave2List($pStr,";") |
---|
1514 | String item = "" |
---|
1515 | //kill old picts |
---|
1516 | KillPicts/A/Z |
---|
1517 | //make a new layout |
---|
1518 | Layout/C=1 as "PICT_Layout" |
---|
1519 | DoWindow/C PICTLayout |
---|
1520 | do |
---|
1521 | item=StringFromList(0,List,";") |
---|
1522 | //load each PICT, and append it to the layout |
---|
1523 | Print "load item = ",item |
---|
1524 | LoadPICT /O/Q/P=savePath item |
---|
1525 | DoWindow/F PICTLayout //be sure layout is on top |
---|
1526 | AppendLayoutObject /F=1/W=PICTLayout picture $item |
---|
1527 | //AppendToLayout $item |
---|
1528 | //Print item |
---|
1529 | List = RemoveFromList(item, List, ";") |
---|
1530 | while(ItemsInList(List, ";")>0) |
---|
1531 | //tile the PICTs in the layout |
---|
1532 | Tile/O=8 |
---|
1533 | End |
---|
1534 | |
---|
1535 | //spit up a list of everything in the folder that is a text file |
---|
1536 | Proc Generate_Data_Checklist() |
---|
1537 | fGenerate_Data_list() |
---|
1538 | End |
---|
1539 | Function fGenerate_Data_list() |
---|
1540 | |
---|
1541 | String List=IndexedFile(dataPath, -1, "TEXT") |
---|
1542 | List2TextWave(List,";","data_files") |
---|
1543 | WAVE/T files=$"data_files" |
---|
1544 | Duplicate/O/T files ModelToUse,Done |
---|
1545 | ModelToUse = "" |
---|
1546 | Done = "" |
---|
1547 | Edit/K=1 files,ModelToUse,Done |
---|
1548 | End |
---|
1549 | |
---|
1550 | //*************** |
---|
1551 | |
---|
1552 | // with all of the notebooks open for a given model (with N parameters) |
---|
1553 | // this will comile the reports, save the text notebook, then load it back in |
---|
1554 | // and put it in a table for easy printing |
---|
1555 | // |
---|
1556 | Proc CompileAndLoadReports() |
---|
1557 | Compile_Reports() |
---|
1558 | SaveNotebook /O/P=savePath/S=2 Compilation |
---|
1559 | // Print "Saved as: ",S_Path |
---|
1560 | DoWindow/K Compilation |
---|
1561 | LoadCompiledReports(S_Path) |
---|
1562 | End |
---|
1563 | |
---|
1564 | Proc LoadCompiledReports(str) |
---|
1565 | String str |
---|
1566 | LoadWave/J/D/W/E=1/K=0/V={"\t"," $",0,0} str |
---|
1567 | End |
---|
1568 | |
---|
1569 | Proc Compile_Reports(Number_of_Parameters) |
---|
1570 | Variable Number_of_Parameters=7 |
---|
1571 | fCompile_Reports(Number_of_Parameters) |
---|
1572 | fCompile_ReportsTable(Number_of_Parameters) |
---|
1573 | End |
---|
1574 | |
---|
1575 | Proc Compile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr) |
---|
1576 | Variable WhichParameter=7 |
---|
1577 | String FileStr="FileName_",ParamStr="par_",ParamErrStr="parErr_" |
---|
1578 | fCompile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr) |
---|
1579 | End |
---|
1580 | |
---|
1581 | //// |
---|
1582 | Function fCompile_Reports(nPar) |
---|
1583 | Variable nPar |
---|
1584 | |
---|
1585 | String list=WinList("*", ";", "WIN:16") |
---|
1586 | String item = "",textStr="",newStr="" |
---|
1587 | Variable sstop,dum,chi |
---|
1588 | |
---|
1589 | Variable ii |
---|
1590 | NewNotebook/F=0 /N=Compilation as "Compilation" |
---|
1591 | Notebook Compilation text="Variable Name \tValues\tErrors\r" |
---|
1592 | do |
---|
1593 | item=StringFromList(0,list,";") |
---|
1594 | DoWindow/F $item |
---|
1595 | |
---|
1596 | Notebook $item selection={(2,0), (3,0)} //paragraph 3 (starts from 0) = filename |
---|
1597 | GetSelection notebook,$item,2 |
---|
1598 | textStr=S_Selection |
---|
1599 | textStr=textStr[0,strlen(textStr)-2] //remove CR |
---|
1600 | textStr=textStr[10,strlen(textStr)-1] //remove "DATA FILE: |
---|
1601 | Notebook Compilation text="File:\t"+textStr+"\t" |
---|
1602 | Notebook Compilation text=textStr+"_err\r" |
---|
1603 | |
---|
1604 | // printf "%s %s\r",textStr,textStr+"_err" |
---|
1605 | // |
---|
1606 | // results are written as: "%s = \t%g\t±\t%g\r" |
---|
1607 | // |
---|
1608 | for(ii=0;ii<nPar;ii+=1) //gather the parameters |
---|
1609 | |
---|
1610 | Notebook $item selection={(ii+4,0), (ii+5,0)} //paragraph 5 = parameter 0 |
---|
1611 | GetSelection notebook,$item,2 |
---|
1612 | textStr=S_Selection |
---|
1613 | textStr=textStr[0,strlen(textStr)-2] |
---|
1614 | //textStr=textStr[13,strlen(textStr)-1] // remove "parameter" |
---|
1615 | textStr = ReplaceString("=",textStr,"") |
---|
1616 | textStr = ReplaceString("±\t",textStr,"") |
---|
1617 | Notebook Compilation text=textStr+"\r" |
---|
1618 | //printf "%s\r",textStr |
---|
1619 | //Print strlen(textStr) |
---|
1620 | endfor |
---|
1621 | //get the chi-squared/N value |
---|
1622 | ii+=1 |
---|
1623 | Notebook $item selection={(ii+4,0), (ii+5,0)} // |
---|
1624 | GetSelection notebook,$item,2 |
---|
1625 | textStr=S_Selection |
---|
1626 | Print textStr |
---|
1627 | |
---|
1628 | sscanf textStr,"Npnts = %g\t\tSqrt(X^2/N) = %g\r",dum,chi |
---|
1629 | sprintf textStr,"Sqrt(X^2/N)\t%s\t\r",num2str(chi) |
---|
1630 | Notebook Compilation text=textStr |
---|
1631 | |
---|
1632 | Notebook Compilation text="\r" //separate items |
---|
1633 | |
---|
1634 | list = RemoveFromList(item, list, ";") |
---|
1635 | while(ItemsInList(list, ";")>0) |
---|
1636 | |
---|
1637 | DoWindow/F Compilation |
---|
1638 | Notebook Compilation selection={startOfFile,startOfFile} |
---|
1639 | End |
---|
1640 | |
---|
1641 | //// |
---|
1642 | // compiles the results into a table. |
---|
1643 | Function fCompile_ReportsTable(nPar) |
---|
1644 | Variable nPar |
---|
1645 | |
---|
1646 | String list=WinList("*", ";", "WIN:16") |
---|
1647 | String item = "",textStr="",newStr="",str |
---|
1648 | Variable sstop,dum,chi |
---|
1649 | |
---|
1650 | Variable ii,numRep,jj,val1,val2,pt |
---|
1651 | numRep=ItemsInList(list,";") |
---|
1652 | |
---|
1653 | Make/O/T/N=(numRep) fittedFiles |
---|
1654 | Make/O/D/N=(numRep) chiSQ |
---|
1655 | Edit fittedFiles,chiSQ |
---|
1656 | |
---|
1657 | for(ii=0;ii<nPar;ii+=1) //waves for the parameters |
---|
1658 | Make/O/D/N=(numRep) $("par"+num2str(ii)),$("par"+num2str(ii)+"_err") |
---|
1659 | AppendToTable $("par"+num2str(ii)),$("par"+num2str(ii)+"_err") |
---|
1660 | endfor |
---|
1661 | |
---|
1662 | for(jj=0;jj<numRep;jj+=1) |
---|
1663 | |
---|
1664 | item=StringFromList(jj,list,";") |
---|
1665 | DoWindow/F $item |
---|
1666 | Notebook $item selection={(2,0), (3,0)} //paragraph 3 (starts from 0) = filename |
---|
1667 | GetSelection notebook,$item,2 |
---|
1668 | textStr=S_Selection |
---|
1669 | textStr=textStr[0,strlen(textStr)-2] //remove CR |
---|
1670 | textStr=textStr[10,strlen(textStr)-1] //remove "DATA FILE: |
---|
1671 | |
---|
1672 | fittedFiles[jj] = textStr |
---|
1673 | // |
---|
1674 | // results are written as: "%s = \t%g\t±\t%g\r" |
---|
1675 | // |
---|
1676 | for(ii=0;ii<nPar;ii+=1) //gather the parameters |
---|
1677 | Notebook $item selection={(ii+4,0), (ii+5,0)} //paragraph 5 = parameter 0 |
---|
1678 | GetSelection notebook,$item,2 |
---|
1679 | textStr=S_Selection |
---|
1680 | textStr=textStr[0,strlen(textStr)-2] |
---|
1681 | // find the "=" |
---|
1682 | pt = strsearch(textStr,"=",0,0) |
---|
1683 | textStr = textStr[pt,strlen(textStr)-1] |
---|
1684 | sscanf textStr,"= \t%g\t ± \t%g\r",val1,val2 |
---|
1685 | |
---|
1686 | Print textStr |
---|
1687 | |
---|
1688 | Wave w1 = $("par"+num2str(ii)) |
---|
1689 | Wave w2 = $("par"+num2str(ii)+"_err") |
---|
1690 | |
---|
1691 | w1[jj] = val1 |
---|
1692 | w2[jj] = val2 |
---|
1693 | |
---|
1694 | //textStr = ReplaceString("=",textStr,"") |
---|
1695 | //textStr = ReplaceString("±\t",textStr,"") |
---|
1696 | //Notebook Compilation text=textStr+"\r" |
---|
1697 | //printf "%s\r",textStr |
---|
1698 | //Print strlen(textStr) |
---|
1699 | endfor |
---|
1700 | //get the chi-squared/N value |
---|
1701 | ii += 1 |
---|
1702 | Notebook $item selection={(ii+4,0), (ii+5,0)} // |
---|
1703 | GetSelection notebook,$item,2 |
---|
1704 | textStr=S_Selection |
---|
1705 | Print textStr |
---|
1706 | |
---|
1707 | sscanf textStr,"Npnts = %g\t\tSqrt(X^2/N) = %g\r",dum,chi |
---|
1708 | |
---|
1709 | chiSQ[jj] = chi |
---|
1710 | endfor |
---|
1711 | |
---|
1712 | return(0) |
---|
1713 | End |
---|
1714 | |
---|
1715 | |
---|
1716 | //// |
---|
1717 | Function fCompile_GlobalFit_Reports(nPar,Files,Param,Param_err) |
---|
1718 | Variable nPar |
---|
1719 | String Files,Param,Param_Err |
---|
1720 | |
---|
1721 | String list=SortList(WinList("*", ";", "WIN:16")) |
---|
1722 | String item = "",textStr="",fileStr,funcStr,dumStr |
---|
1723 | Variable sstop,dum,chi,nFiles,val1,val2 |
---|
1724 | |
---|
1725 | Variable ii,jj |
---|
1726 | |
---|
1727 | nFiles = ItemsInList(list) |
---|
1728 | Make/O/D/N=(nFiles) $Param,$Param_err |
---|
1729 | Make/O/T/N=(nFiles) $Files |
---|
1730 | WAVE pw = $Param |
---|
1731 | WAVE pw_err = $Param_err |
---|
1732 | WAVE/T fw = $Files |
---|
1733 | |
---|
1734 | for(jj=0;jj<nFiles;jj+=1) |
---|
1735 | |
---|
1736 | item=StringFromList(jj,list,";") |
---|
1737 | DoWindow/F $item |
---|
1738 | |
---|
1739 | Notebook $item selection={(6,0), (7,0)} //paragraph 7 (starts from 0) = filename |
---|
1740 | GetSelection notebook,$item,2 |
---|
1741 | textStr=S_Selection |
---|
1742 | sscanf textStr,"Data Set:%s ; Function:%s\r",fileStr,funcStr |
---|
1743 | fw[jj] = fileStr |
---|
1744 | // Notebook Compilation text=fileStr+"\r" |
---|
1745 | // Notebook Compilation text=funcStr+"\r" |
---|
1746 | |
---|
1747 | |
---|
1748 | // printf "%s %s\r",textStr,textStr+"_err" |
---|
1749 | |
---|
1750 | for(ii=nPar;ii<=nPar;ii+=1) //gather the parameters |
---|
1751 | |
---|
1752 | Notebook $item selection={(ii+7,0), (ii+8,0)} //paragraph 8 = parameter 0 |
---|
1753 | GetSelection notebook,$item,2 |
---|
1754 | textStr=S_Selection |
---|
1755 | // Print textStr |
---|
1756 | sscanf textStr,"%s %g +- %g\r",dumStr,val1,val2 |
---|
1757 | pw[jj] = val1 |
---|
1758 | pw_err[jj] = val2 |
---|
1759 | endfor |
---|
1760 | |
---|
1761 | endfor |
---|
1762 | |
---|
1763 | End |
---|
1764 | |
---|
1765 | |
---|
1766 | |
---|
1767 | //DOES NOT graph the data, does not create a weighting wave |
---|
1768 | //NSE data assumed to be 4-column |
---|
1769 | //q (all the same) - t(ns) - I(q,t) - dI(q,t) |
---|
1770 | Static Function LoadNSEDataWithName(fileStr) |
---|
1771 | String fileStr |
---|
1772 | //Load the waves, using default waveX names |
---|
1773 | //if no path or file is specified for LoadWave, the default Mac open dialog will appear |
---|
1774 | LoadWave/G/D/A/Q fileStr |
---|
1775 | String fileName = S_fileName |
---|
1776 | |
---|
1777 | |
---|
1778 | String w0,w1,w2,n0,n1,n2,wt,w3,n3 |
---|
1779 | Variable rr,gg,bb |
---|
1780 | |
---|
1781 | // put the names of the four loaded waves into local names |
---|
1782 | n0 = StringFromList(0, S_waveNames ,";" ) |
---|
1783 | n1 = StringFromList(1, S_waveNames ,";" ) |
---|
1784 | n2 = StringFromList(2, S_waveNames ,";" ) |
---|
1785 | n3 = StringFromList(3, S_waveNames ,";" ) |
---|
1786 | |
---|
1787 | |
---|
1788 | //remove the semicolon AND period from files from the VAX |
---|
1789 | w0 = CleanupName((S_fileName+"__Q"),0) |
---|
1790 | w1 = CleanupName((S_fileName+"__X"),0) |
---|
1791 | w2 = CleanupName((S_fileName+"__Y"),0) |
---|
1792 | w3 = CleanupName((S_fileName+"__S"),0) |
---|
1793 | |
---|
1794 | if(exists(w0) !=0) |
---|
1795 | //waves already exist |
---|
1796 | KillWaves $n0,$n1,$n2,$n3 // kill the default waveX that were loaded |
---|
1797 | return(0) |
---|
1798 | endif |
---|
1799 | |
---|
1800 | // Rename to give nice names |
---|
1801 | Rename $n0, $w0 |
---|
1802 | Rename $n1, $w1 |
---|
1803 | Rename $n2, $w2 |
---|
1804 | Rename $n3, $w3 |
---|
1805 | |
---|
1806 | End |
---|
1807 | |
---|
1808 | ///// |
---|
1809 | //wStr is the coef_ wave with the initial guess |
---|
1810 | Function FillCoefGuess(wStr) |
---|
1811 | String wStr |
---|
1812 | |
---|
1813 | Wave w=$wStr |
---|
1814 | if (! WaveExists(w) ) |
---|
1815 | DoAlert 0, "The coefficient wave "+wStr+" does not exist. Either create the wave or enter the correct suffix" |
---|
1816 | return(0) |
---|
1817 | endif |
---|
1818 | Wave/T guess=root:AutoFit:guessMatrix |
---|
1819 | Variable ii=0,num=numpnts(w) |
---|
1820 | Variable tmp |
---|
1821 | |
---|
1822 | Variable selRow,matrixRow |
---|
1823 | selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames |
---|
1824 | |
---|
1825 | do |
---|
1826 | tmp=w[ii] |
---|
1827 | guess[ii][selRow] = num2str(tmp) |
---|
1828 | ii+=1 |
---|
1829 | while(ii<num) |
---|
1830 | End |
---|
1831 | |
---|
1832 | ///// |
---|
1833 | //wStr is the hold_ wave with the initial guess |
---|
1834 | Function FillHoldGuess(wStr) |
---|
1835 | String wStr |
---|
1836 | |
---|
1837 | Wave w=$wStr |
---|
1838 | if (! WaveExists(w) ) |
---|
1839 | DoAlert 0, "The hold wave "+wStr+" does not exist. Either create the wave or enter the correct suffix" |
---|
1840 | return(0) |
---|
1841 | endif |
---|
1842 | Wave/T hold=root:AutoFit:holdMatrix |
---|
1843 | Variable ii=0,num=numpnts(w) |
---|
1844 | Variable tmp |
---|
1845 | |
---|
1846 | Variable selRow,matrixRow |
---|
1847 | selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames |
---|
1848 | |
---|
1849 | do |
---|
1850 | tmp=w[ii] |
---|
1851 | hold[ii][selRow] = num2str(tmp) |
---|
1852 | ii+=1 |
---|
1853 | while(ii<num) |
---|
1854 | End |
---|
1855 | |
---|
1856 | ///// |
---|
1857 | //wStr is the Constr_ wave with the initial guess |
---|
1858 | // --- this is a Text wave |
---|
1859 | Function FillConstrGuess(wStr) |
---|
1860 | String wStr |
---|
1861 | |
---|
1862 | Wave/T w=$wStr |
---|
1863 | if (! WaveExists(w) ) |
---|
1864 | DoAlert 0, "The Constraint wave "+wStr+" does not exist. Either create the (TEXT) wave or enter the correct suffix" |
---|
1865 | return(0) |
---|
1866 | endif |
---|
1867 | Wave/T constr=root:AutoFit:constrMatrix |
---|
1868 | Variable ii=0,num=numpnts(w) |
---|
1869 | String tmp |
---|
1870 | |
---|
1871 | Variable selRow,matrixRow |
---|
1872 | selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames |
---|
1873 | |
---|
1874 | do |
---|
1875 | tmp=w[ii] |
---|
1876 | constr[ii][selRow] = tmp |
---|
1877 | ii+=1 |
---|
1878 | while(ii<num) |
---|
1879 | End |
---|
1880 | |
---|
1881 | //// |
---|
1882 | //need the extension of the model wave to append |
---|
1883 | // |
---|
1884 | // it will plot the UN-smeared model for generating the initial guesses |
---|
1885 | // -- fitting will use Smeared or unsmeared, depending on the popup selection |
---|
1886 | // |
---|
1887 | // |
---|
1888 | Function fLoadSelected(extStr) |
---|
1889 | string extStr |
---|
1890 | |
---|
1891 | Variable datafile,ii |
---|
1892 | String fullName,dataName,str |
---|
1893 | |
---|
1894 | WAVE/T fileWave=root:AutoFit:fileListWave |
---|
1895 | Wave sel = root:AutoFit:fileSelWave |
---|
1896 | ii=0 |
---|
1897 | do |
---|
1898 | if((sel[ii][0] & 0x01) == 1) // the file is selected in the list box |
---|
1899 | datafile = ii |
---|
1900 | break |
---|
1901 | endif |
---|
1902 | ii+=1 |
---|
1903 | while(ii<numpnts(sel)) |
---|
1904 | |
---|
1905 | //load in the data |
---|
1906 | PathInfo dataPath |
---|
1907 | fullName = S_path |
---|
1908 | fullName += fileWave[datafile][0] |
---|
1909 | |
---|
1910 | str = "A_LoadOneDDataToName(\""+fullName+"\",\"\",0,1)" //don't plot, force overwrite |
---|
1911 | Execute str |
---|
1912 | |
---|
1913 | dataName=GetFileNameFromPathNoSemi(fullName) |
---|
1914 | dataname=CleanupName(dataname,0) |
---|
1915 | |
---|
1916 | //graph it - creates window named "AutoGraph" |
---|
1917 | DoWindow/K tmpGraph |
---|
1918 | Execute "DoGraph(\""+dataname+"\")" |
---|
1919 | DoWindow/C tmpGraph |
---|
1920 | // Wave/Z yw = $("ywave_"+extStr) |
---|
1921 | // Wave/Z xw = $("xwave_"+extStr) |
---|
1922 | |
---|
1923 | if(exists("ywave_"+extStr) && exists("xwave_"+extStr)) |
---|
1924 | AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr) |
---|
1925 | else |
---|
1926 | DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix" |
---|
1927 | endif |
---|
1928 | |
---|
1929 | // ControlInfo/W=AutoFitPanel popup0 |
---|
1930 | // if(cmpstr(S_Value[0,4], "Smear" ) == 0 ) |
---|
1931 | // SetDataFolder $dataname |
---|
1932 | // if(exists("smeared_"+extStr) && exists("smeared_qvals")) |
---|
1933 | // |
---|
1934 | // AppendtoGraph $("smeared_"+extStr) vs $("smeared_qvals") |
---|
1935 | // else |
---|
1936 | // SetDataFolder root: |
---|
1937 | // DoAlert 0,"Smeared Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix" |
---|
1938 | // endif |
---|
1939 | // |
---|
1940 | // else |
---|
1941 | // if(exists("ywave_"+extStr) && exists("xwave_"+extStr)) |
---|
1942 | // AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr) |
---|
1943 | // else |
---|
1944 | // DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix" |
---|
1945 | // endif |
---|
1946 | // endif |
---|
1947 | |
---|
1948 | |
---|
1949 | SetDataFolder root: |
---|
1950 | return(0) |
---|
1951 | End |
---|
1952 | |
---|
1953 | //loads the selected file in a temporary graph |
---|
1954 | Function LoadForGuessProc(ctrlName) : ButtonControl |
---|
1955 | String ctrlName |
---|
1956 | |
---|
1957 | SVAR ext=root:AutoFit:gExt |
---|
1958 | fLoadSelected(ext) |
---|
1959 | return(0) |
---|
1960 | End |
---|
1961 | |
---|
1962 | //makes the holdWave and Constraint wave that are needed to set the values in the list boxes (and the matrix) |
---|
1963 | // these are not generated when plotting a model. |
---|
1964 | Function Make_HoldConstraintEps_Waves() |
---|
1965 | |
---|
1966 | SVAR ext=root:AutoFit:gExt |
---|
1967 | Variable num=numpnts($("coef_"+ext)) |
---|
1968 | if(WaveExists($("coef_"+ext)) == 0 ) |
---|
1969 | DoAlert 0,"coef_"+ext+" does not exist. You must set the prefix correctly and plot the model first" |
---|
1970 | else |
---|
1971 | Make/O/D/N=(num) $("Hold_"+ext) |
---|
1972 | Make/O/T/N=(num) $("Constr_"+ext) |
---|
1973 | Make/O/D/N=(num) $("Epsilon_"+ext)=0.0003 |
---|
1974 | |
---|
1975 | String str=WinList("*", ";","WIN:2"),sel |
---|
1976 | Prompt sel, "Select Table to Append Waves", popup str |
---|
1977 | DoPrompt "asdf",sel |
---|
1978 | if (V_Flag) |
---|
1979 | return 0 // user canceled |
---|
1980 | endif |
---|
1981 | DoWindow/F $sel |
---|
1982 | AppendToTable $("Hold_"+ext), $("Constr_"+ext), $("Epsilon_"+ext) |
---|
1983 | endif |
---|
1984 | End |
---|
1985 | //needs the name (as a string) of the coefficient wave |
---|
1986 | //it assumes "coef_" plus an extension |
---|
1987 | // |
---|
1988 | Function UseCoefAsGuess(ctrlName) : ButtonControl |
---|
1989 | String ctrlName |
---|
1990 | |
---|
1991 | String wStr = "coef_" |
---|
1992 | SVAR ext=root:AutoFit:gExt |
---|
1993 | FillCoefGuess(wStr+ext) |
---|
1994 | DisplayGuess() |
---|
1995 | return(0) |
---|
1996 | End |
---|
1997 | |
---|
1998 | //needs the name (as a string) of the hold string wave |
---|
1999 | //it assumes "hold_" plus an extension |
---|
2000 | // |
---|
2001 | Function UseHoldAsGuess(ctrlName) : ButtonControl |
---|
2002 | String ctrlName |
---|
2003 | |
---|
2004 | // String wStr = "hold_" |
---|
2005 | // SVAR ext=root:AutoFit:gExt |
---|
2006 | // FillHoldGuess(wStr+ext) |
---|
2007 | // DisplayGuess() |
---|
2008 | return(0) |
---|
2009 | End |
---|
2010 | |
---|
2011 | //needs the name (as a string) of the coefficient wave |
---|
2012 | //it assumes "constr" plus an extension |
---|
2013 | // |
---|
2014 | Function UseConstraintsAsGuess(ctrlName) : ButtonControl |
---|
2015 | String ctrlName |
---|
2016 | |
---|
2017 | // String wStr = "Constr_" |
---|
2018 | // SVAR ext=root:AutoFit:gExt |
---|
2019 | // FillConstrGuess(wStr+ext) |
---|
2020 | // DisplayGuess() |
---|
2021 | return(0) |
---|
2022 | End |
---|
2023 | |
---|