source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Auto_Fit.ipf @ 826

Last change on this file since 826 was 826, checked in by srkline, 12 years ago

Adding Auto_Fit.ipf to the Analysis/Alpha? procedures. This is a package that is still in need of more design (and then testing) before release. The intent is for it to be used for unattended batch fitting of a list of data files using a single model function.

It's a single file to include after the analysis package has been included.

Some instructions are available, more after design is finished.

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