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

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

changed the line endings on Auto_fit.ipf so that diff will work properly

Changed the 2D resolution calculation to match the style and variables used in the JAC paper w/ David and John. No effect on the calculation, just for consistency.

File size: 56.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// -- savePath seems to be obsolete. Report saving is sent to the procedure defined in Wrapper.ipf, and uses the home path
25//
26
27
28Menu "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
46End
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?
59Function 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)
66End
67
68Function 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)
75End
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//
82Function 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)
107End
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//
114Function 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)
170End
171
172
173//updates the lists (text waves) to display, depending on the current highlighted file
174Function 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)
212End
213
214
215//column 0 is the filenames, 1 is the checkboxes
216//returns the row that is selected, -1 if not found
217Function  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)
243end
244
245
246Proc 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
255End
256
257Function 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:
279End
280
281Window 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={180,208},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
344EndMacro
345
346
347Function 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
390End
391
392
393Function 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)
414End
415
416
417Function 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)
425End
426
427Function 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)
435End
436
437Function 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)
445End
446
447Function 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)
455End
456
457Function 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)
470End
471
472//expand or collapse the matrices to the number of parameters
473Function 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
506end
507
508
509Function 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
522End
523
524Function 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
541End
542
543Function 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
560End
561
562Function 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
579End
580
581Function 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
598End
599
600//returns the total number of files checked
601Function 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       
613End
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
624Function 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)
666End
667
668
669Function 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       
748        //fit it
749        //these two global variables must be created for IGOR to set them, so that
750        //any errors in the fitting can be diagnosed
751        Variable/G V_FitError=0                         //0=no err, 1=error,(2^1+2^0)=3=singular matrix
752        Variable/G V_FitQuitReason=0            //0=ok,1=maxiter,2=user stop,3=no chisq decrease
753        NVAR tol=root:AutoFit:fitTol
754        Variable/G V_FitTol=tol         //default is 0.0001
755        Variable/G V_fitOptions=4               //suppress the dialog during fitting (we're not waiting for OK, anyways)
756
757
758        Wave yw = $(DF+dataName+"_i")
759        Wave xw = $(DF+dataName+"_q")
760        Wave sw = $(DF+dataName+"_s")
761       
762        if(stringmatch(funcStr, "Smear*"))              // if it's a smeared function, need a struct
763                useRes=1
764        endif
765       
766        Struct ResSmearAAOStruct fs
767        WAVE/Z resW = $(DF+dataName+"_res")                     //these may not exist, if 3-column data is used
768        WAVE/Z fs.resW =  resW
769        WAVE yw=$(DF+dataName+"_i")
770        WAVE xw=$(DF+dataName+"_q")
771        WAVE sw=$(DF+dataName+"_s")
772        Wave fs.coefW = cw
773        Wave fs.yW = yw
774        Wave fs.xW = xw
775       
776        Duplicate/O yw $(DF+"FitYw")
777        WAVE fitYw = $(DF+"FitYw")
778        fitYw = NaN
779       
780        NVAR useGenCurveFit = root:Packages:NIST:gUseGenCurveFit
781        ///// SEE FitWrapper() for more details.
782       
783        Variable nPass = 1
784       
785        do      // outer do is the loop over passes
786        do      // this inner loop is abig switch to select the correct FutFunc to dispatch
787                if(useGenCurveFit)
788#if !(exists("GenCurveFit"))
789                        // XOP not available
790                        useGenCurveFit = 0
791                        Abort "Genetic Optimiztion XOP not available. Reverting to normal optimization."       
792#endif
793                        //send everything to a function, to reduce the clutter
794                        // useEps and useConstr are not needed
795                        // pass the structure to get the current waves, including the trimmed USANS matrix
796                        Variable chi,pt
797
798                        chi = DoGenCurveFit(useRes,useCursors,sw,fitYw,fs,funcStr,ParseHoldString(ii,numpar,holdMatrix),val,lolim,hilim,pt1,pt2)
799                        pt = val
800
801                        break
802                       
803                endif
804               
805               
806                if(useRes && useEps && useCursors && useConstr)         //do it all
807                        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
808                        break
809                endif
810               
811                if(useRes && useEps && useCursors)              //no constr
812                        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
813                        break
814                endif
815               
816                if(useRes && useEps && useConstr)               //no crsr
817                        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
818                        break
819                endif
820               
821                if(useRes && useCursors && useConstr)           //no eps
822                        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
823                        break
824                endif
825               
826                if(useRes && useCursors)                //no eps, no constr
827                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
828                        break
829                endif
830               
831                if(useRes && useEps)            //no crsr, no constr
832                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /STRC=fs
833                        break
834                endif
835       
836                if(useRes && useConstr)         //no crsr, no eps
837                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr /STRC=fs
838                        break
839                endif
840               
841                if(useRes)              //just res
842                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /STRC=fs
843                        break
844                endif
845               
846/////   same as above, but all without useRes (no /STRC flag)
847                if(useEps && useCursors && useConstr)           //do it all
848                        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
849                        break
850                endif
851               
852                if(useEps && useCursors)                //no constr
853                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /E=eps /D=fitYw
854                        break
855                endif
856               
857                if(useEps && useConstr)         //no crsr
858                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw /C=constr
859                        break
860                endif
861               
862                if(useCursors && useConstr)             //no eps
863                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw /C=constr
864                        break
865                endif
866               
867                if(useCursors)          //no eps, no constr
868                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw[pt1,pt2] /X=xw /W=sw /I=1 /D=fitYw
869                        break
870                endif
871               
872                if(useEps)              //no crsr, no constr
873                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /E=eps /D=fitYw
874                        break
875                endif
876       
877                if(useConstr)           //no crsr, no eps
878                        FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw /C=constr
879                        break
880                endif
881               
882                //just a plain vanilla fit
883                FuncFit/H=ParseHoldString(ii,numpar,holdMatrix) /NTHR=0 $funcStr cw, yw /X=xw /W=sw /I=1 /D=fitYw
884       
885        while(0)                //always exit the inner do to select the FutFunc syntax. The break will exit this loop
886       
887                if(nPass == 1)
888                        UpdateStatusString(dataname +" Fit #1")
889                        Variable/G gChiSq1 = V_chisq
890                endif
891               
892                if(nPass == 2)
893                        UpdateStatusString(dataname +" Fit #2")
894                        Variable/G gChiSq2 = V_chisq
895                endif
896               
897                if(nPass == 3)
898                        UpdateStatusString(dataname +" Fit #3")
899                endif
900               
901                nPass += 1
902        while(nPass < 4)
903
904        // append the fit
905        // need to manage duplicate copies
906        // Don't plot the full curve if cursors were used (set fitYw to NaN on entry...)
907        String traces=TraceNameList("", ";", 1 )                //"" as first parameter == look on the target graph
908        if(strsearch(traces,"FitYw",0) == -1)
909                if(useGenCurveFit && useCursors)
910                        WAVE trimX = trimX
911                        AppendtoGraph fitYw vs trimX
912                else
913                        AppendToGraph FitYw vs xw
914                endif
915        else
916                RemoveFromGraph FitYw
917                if(useGenCurveFit && useCursors)
918                        WAVE trimX = trimX
919                        AppendtoGraph fitYw vs trimX
920                else
921                        AppendToGraph FitYw vs xw
922                endif
923        endif
924        ModifyGraph lsize(FitYw)=2,rgb(FitYw)=(52428,1,1)
925
926
927        //do the report calling the function, not the proc
928        String topGraph= WinName(0,1)   //this is the topmost graph
929        SVAR suffix = root:AutoFit:gExt         //don't try to read as getModelSuffix(funcStr), since the smeared() may not be plotted
930        String parStr=GetWavesDataFolder(cw,1)+ WaveList("*param*"+"_"+suffix, "", "TEXT:1," )          // this is *hopefully* one wave
931
932        if(isNSE)
933                GenerateReport_NSE(funcStr,dataname,"par","myCoef",1)
934        else
935                W_GenerateReport(funcStr,dataname,$parStr,$"myCoef",1,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
936
937//              AutoFit_GenerateReport(funcStr,dataname,"par","myCoef",1)       
938        endif
939       
940        return(0)
941End
942
943//// to be able to simply fill in the pt range of the yw[lo,hi]
944//Function LowRange()
945//      NVAR val = root:AutoFit:ptLow
946//      return(val)
947//End
948//
949//Function HighRange()
950//      NVAR val = root:AutoFit:ptHigh
951//      return(val)
952//End
953
954//updates the status string, forcing a redraw twice, to overcome what seems to be a bug in Igor4
955//also updates the progress bar and the countdown
956Function UpdateStatusString(newStr)
957        String newStr
958       
959        SVAR gStatus=root:AutoFit:gStatus
960        SVAR gStatFormat=root:AutoFit:gStatFormat
961        gStatus=""
962        ControlUpdate/W=AutoFitPanel tb1                //clears the line
963        gStatus=gStatFormat+newStr
964        ControlUpdate/W=AutoFitPanel tb1
965       
966        //update the progress bar and timer
967        NVAR cur=root:AutoFit:curProgress
968        NVAR endProgress=root:AutoFit:endProgress
969        NVAR startTicks=root:AutoFit:startTicks
970        cur+=1
971       
972//      Print "****"
973//      Print "cur = ",cur
974       
975        Variable t2=ticks,projTot,projRemain
976        String titleStr=""
977       
978        projTot = (t2-startTicks)/(cur-1)*endProgress
979        projRemain = projTot - (t2-startTicks)
980        projRemain /= 60.15             //to seconds
981        DoWindow/F AutoFitPanel
982        ValDisplay progressValdisp,title=Secs2time(projRemain,5)
983        ControlUpdate/W=AutoFitPanel progressValdisp
984       
985//      Print "End Progress = ",endProgress
986//      Print "ProjTot = ",projTot/60.15
987//      Print "ProjRemain = ",projRemain
988       
989        return(0)
990End
991
992// returns a string with the name of the epsilon wave, or null if it doesn't exist
993Function/S GetEpsilonWave()
994       
995        String retStr="",testStr
996        SVAR extStr = root:AutoFit:gExt
997        //do you want to use epsilon wave?
998        ControlInfo/W=AutoFitPanel epsilonCheck
999        if(V_Value == 0)                //not checked
1000                return(retStr)
1001        endif
1002       
1003        testStr = "Epsilon_"+extStr
1004        if(waveexists($testStr) != 0)
1005                return(" /E="+testStr)
1006        endif
1007        return(retStr)
1008End
1009
1010//returns the y data to fit - "_i" suffix, and range if selected
1011// enter the range as the first element[0] as low point, second element[1] as high point
1012// leave the other elements blank
1013//
1014// if either point value is not entered, the whole data set is used
1015//
1016// -- if both of the elements are between 0 and 1, assume they are q-values (check for fractional part)
1017// and find the appropriate points...
1018//
1019Function ParseRangeString(set,dataStr,rMat,lo,hi)
1020        Variable set
1021        String dataStr
1022        WAVE/T rMat
1023        Variable &lo,&hi
1024       
1025        Variable useCursors
1026                       
1027        lo = str2num(rMat[0][set])
1028        hi = str2num(rMat[1][set])
1029       
1030        if(lo == 0 && hi == 0)
1031                return(0)
1032        endif
1033       
1034        if(numtype(lo) != 0 || numtype(hi) != 0)                //not a normal number
1035                return(0)               //don't use cursor values, use all of the dataset
1036        endif
1037       
1038       
1039        if(lo>=hi) //error in specification, or all data desired (both zero or undefined)
1040                return(0)               //use all of the dataset
1041        endif
1042       
1043       
1044        if(trunc(lo) != lo || trunc(hi) != hi)          //values have fractional parts
1045                WAVE xW = $("root:"+dataStr+":"+dataStr + "_q")
1046                FindLevel/P/Q xW, lo
1047                lo = trunc(V_levelX)            //find the corresponding point values
1048                FindLevel/P/Q xW, hi
1049                hi = trunc(V_levelX)
1050        endif
1051       
1052        Variable/G root:AutoFit:ptLow = lo
1053        Variable/G root:AutoFit:ptHigh = hi
1054
1055        return(1)
1056End
1057
1058//returns the holdStr, i.e. "1010101"
1059Function/S ParseHoldString(set,npar,hMat)
1060        Variable set,npar
1061        WAVE/T hMat
1062       
1063        Variable ii
1064        String retStr=""
1065       
1066        for(ii=0;ii<npar;ii+=1)
1067                if(strlen(hMat[ii][set]) == 0)
1068                        retStr += "0"
1069                else
1070                        retStr += hMat[ii][set]
1071                endif
1072        endfor
1073
1074//      Print retStr
1075       
1076        return(retStr)
1077End
1078
1079//returns only error - wave must already exist
1080Function ParseGuessString(set,npar,gMat,outWStr)
1081        Variable set,npar
1082        WAVE/T gMat
1083        String outWStr
1084       
1085        Variable ii
1086        String retStr=outWStr
1087       
1088        WAVE outWave=$outWStr
1089        for(ii=0;ii<npar;ii+=1)
1090                outWave[ii] = str2num(gMat[ii][set])
1091        endfor
1092        return(0)
1093End
1094
1095//the constraint wave is created here
1096Function/S ParseConstraints(set,npar,cMat,outWStr)
1097        Variable set,npar
1098        WAVE/T cMat
1099        String outWStr
1100       
1101        String retStr="",loStr="",hiStr=""
1102        Variable ii=0,jj=0     
1103        Make/O/T/N=0 $outWStr
1104        WAVE/T cw = $outWStr   
1105        //return "/C="+outWStr if parsed ok, or null if not
1106
1107        String listStr=""
1108        for(ii=0;ii<npar;ii+=1)
1109                listStr=cMat[ii][set]
1110                loStr=StringFromList(0, listStr ,";")
1111                hiStr=StringFromList(1, listStr ,";")
1112                if(cmpstr(loStr,"")!=0) //something there...
1113                        InsertPoints jj,1,cw            //insert before element jj
1114                        cw[jj] = "K"+num2Str(ii)+">"+loStr
1115                        jj+=1
1116                endif
1117                if(cmpstr(hiStr,"")!=0) //something there...
1118                        InsertPoints jj,1,cw            //insert before element jj
1119                        cw[jj] = "K"+num2Str(ii)+"<"+hiStr
1120                        jj+=1
1121                endif
1122        endfor
1123        if(numpnts(cw) > 0 )
1124                retStr = "/C=" + outWStr
1125        Endif
1126//      print "strlen, conStr= ",strlen(retStr),retstr
1127
1128        return(retStr)  //null string will be returned if no constraints
1129End
1130
1131
1132//*************************
1133Proc DoGraph(dataname)
1134        String dataname
1135       
1136        SetDataFolder $dataname
1137
1138        PauseUpdate; Silent 1           // building window...
1139        Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q")
1140        DoWindow/C AutoGraph
1141        ModifyGraph mode($(dataname+"_i"))=3
1142        ModifyGraph marker($(dataname+"_i"))=19
1143        ModifyGraph rgb($(dataname+"_i"))=(1,4,52428)
1144        ModifyGraph msize($(dataname+"_i"))=2
1145        ModifyGraph grid=1
1146        ModifyGraph log=1
1147        ModifyGraph tickUnit=1
1148        //
1149        ModifyGraph mirror=2
1150        //
1151        ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s"))
1152//      Legend/A=LB
1153//      Legend/A=LB/X=0.00/Y=-32                //defaults to the top right
1154        Legend/A=MT/E           // /X=-16.16/Y=5.17/E
1155       
1156        SetDataFolder root:
1157       
1158EndMacro
1159
1160Proc DoGraph_NSE(dataname)
1161        String dataname
1162       
1163        SetDataFolder $dataname
1164
1165        PauseUpdate; Silent 1           // building window...
1166        Display /W=(5,42,301,313)/K=1 $(dataname+"_i") vs $(dataname+"_q")
1167        DoWindow/C AutoGraph_NSE
1168        ModifyGraph mode($(dataname+"_i"))=3
1169        ModifyGraph marker($(dataname+"_i"))=19
1170        ModifyGraph rgb($(dataname+"_i"))=(1,4,52428)
1171        ModifyGraph msize($(dataname+"_i"))=3
1172        ModifyGraph zColor($(dataname+"_i"))={$(dataname+"__Q"),$(dataname+"__Q")[0]*0.99,*,Rainbow}
1173        ModifyGraph grid=1
1174        ModifyGraph mirror=2
1175        ModifyGraph log(left)=1
1176        ErrorBars $(dataname+"_i") Y,wave=($(dataname+"_s"),$(dataname+"_s"))
1177        Legend/A=MB
1178        SetAxis/A/E=1 bottom
1179        ModifyGraph standoff=0
1180        SetAxis left 0.1,1
1181        //ModifyGraph tickUnit(left)=1
1182EndMacro
1183
1184//*************************
1185
1186
1187//**************************
1188// Generate the report
1189//**************************
1190
1191////must have AutoGraph as the name of the graph window (any size)
1192//// func is the name of the function (for print only)
1193////par and coef are the exact names of the waves
1194////yesSave==1 will save the file(name=func+time)
1195////
1196////
1197//// general report function from the wrapper is used instead
1198////    W_GenerateReport(funcStr,folderStr,$parStr,cw,yesSave,V_chisq,W_sigma,V_npnts,V_FitError,V_FitQuitReason,V_startRow,V_endRow,topGraph)
1199////
1200//Function AutoFit_GenerateReport(func,dataname,par,myCoef,yesSave)
1201//      String func,dataname,par,myCoef
1202//      Variable yesSave
1203//     
1204//      String str,pictStr="P_"
1205//      Wave sigWave=$"W_sigma"
1206//      Wave ans=$myCoef
1207////    Wave/T param=$par
1208//      SVAR ext=root:AutoFit:gExt
1209//      Wave/T param=$"parameters_"+ext
1210//     
1211//      NVAR V_chisq = V_chisq
1212//      NVAR V_npnts = V_npnts
1213//      NVAR V_FitError = V_FitError
1214//      NVAR V_FitQuitReason = V_FitQuitReason
1215//      NVAR chi1=gChiSq1
1216//      NVAR chi2=gChiSq2
1217//      NVAR V_startRow = V_startRow
1218//      NVAR V_endRow = V_endRow
1219//     
1220//      // bring report up
1221//      DoWindow/F Report
1222//      if (V_flag == 0)                // Report notebook doesn't exist ?
1223//              NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1224//      endif
1225//     
1226//      // delete old stuff
1227//      Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1228//     
1229//      // insert title
1230//      Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1231//      sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1232//      Notebook Report ruler=Title, text=str
1233//     
1234//      // insert fit results
1235//      Variable num=numpnts(ans),ii=0
1236//      Notebook Report ruler=Normal; Notebook Report  margins={18,18,504}, tabs={63 + 3*8192}
1237//      str = "Data file: " + dataname + "\r\r"
1238//      Notebook Report text=str
1239//      do
1240//              sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii]
1241//              Notebook Report text=str
1242//              ii+=1
1243//      while(ii<num)
1244//     
1245//      //
1246//      Wave dataXw = $(dataname+"_q")
1247//      Variable nData=numpnts(dataXw)
1248//     
1249//      //
1250//      sprintf str,"chisq = %g , %g , %g\r",chi1,chi2,V_chisq
1251//      Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1252//      sprintf str,"Npnts = %g, sqrt(X^2/N) = %g\r",V_npnts,sqrt(V_chisq/V_npnts)
1253//      Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1254//      sprintf str "Fitted range = [%d,%d] = %g < Q < %g\r",V_startRow,V_endRow,dataXw(V_startRow),dataXw(V_endRow)
1255//      Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1256//      sprintf str,"V_FitError = %g\t\tV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason
1257//      Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1258//      Notebook Report ruler=Normal
1259//     
1260//      // insert graphs
1261//      Notebook Report picture={AutoGraph(0, 0, 400, 300), 0, 1}, text="\r"
1262//     
1263//
1264//      //Notebook Report picture={Table1, 0, 0}, text="\r"
1265//     
1266//      // show the top of the report
1267//      Notebook Report  selection= {startOfFile, startOfFile},  findText={"", 1}
1268//     
1269//      //save the notebook
1270//      if(yesSave)
1271//              String nameStr=CleanupName(func,0)
1272//              nameStr = nameStr[0,8]  //shorten the name
1273//              nameStr += "_"+dataname
1274//              //make sure the name is no more than 31 characters
1275//              namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1276//              Print "file saved as ",nameStr
1277//              SaveNotebook /O/P=savePath/S=2 Report as nameStr
1278//              //save the graph separately as a PICT file, 2x screen
1279//              pictStr += nameStr
1280//              pictStr = pictStr[0,28]         //need a shorter name - why?
1281//              DoWindow/F AutoGraph
1282//              // E=-5 is png @screen resolution
1283//              // E=2 is PICT @2x screen resolution
1284//              SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as pictStr
1285//      Endif
1286//     
1287//      // ???maybe print the notebook too?
1288//End
1289
1290
1291
1292//
1293//Proc DoGenerateReport(fname,dataname,param,coef,yesno)
1294//      String fname,dataname="",param,coef,yesno="No"
1295//      Prompt fname,"function name",popup,FunctionList("!Sme*",";","KIND:15,")
1296//      Prompt dataname,"name of the dataset"
1297//      Prompt param,"parameter names",popup,WaveList("par*",";","")
1298//      Prompt coef,"coefficient wave",popup,WaveList("coe*",";","")
1299//      Prompt yesno,"Save the report?",popup,"Yes;No;"
1300//     
1301//      //Print "fname = ",fname
1302//      //Print "param = ",param
1303//      //Print "coef = ",coef
1304//      //Print "yesno = ",yesno
1305//     
1306//      Variable doSave=0
1307//      if(cmpstr(yesno,"Yes")==0)
1308//              doSave=1
1309//      Endif
1310//      GenerateReport(fname,dataname,param,coef,dosave)
1311//     
1312//End
1313
1314
1315
1316//must have AutoGraph_NSE as the name of the graph window (any size)
1317// func is the name of the function (for print only)
1318//par and coef are the exact names of the waves
1319//yesSave==1 will save the file(name=func+time)
1320//
1321Function GenerateReport_NSE(func,dataname,par,coef,yesSave)
1322        String func,dataname,par,coef
1323        Variable yesSave
1324       
1325        String str
1326        Wave sigWave=$"W_sigma"
1327        Wave ans=$coef
1328        Wave/T param=$par
1329       
1330        NVAR V_chisq = V_chisq
1331        NVAR V_npnts = V_npnts
1332        NVAR V_FitError = V_FitError
1333        NVAR V_FitQuitReason = V_FitQuitReason
1334       
1335        // bring report up
1336        DoWindow/F Report
1337        if (V_flag == 0)                // Report notebook doesn't exist ?
1338                NewNotebook/W=(10,45,550,620)/F=1/N=Report as "Report"
1339        endif
1340       
1341        // delete old stuff
1342        Notebook Report selection={startOfFile, endOfFile}, text="\r", selection={startOfFile, startOfFile}
1343       
1344        // insert title
1345        Notebook Report newRuler=Title, justification=1, rulerDefaults={"Times", 16, 1, (0, 0, 0)}
1346        sprintf str, "Fit to %s, %s, %s\r\r", func,Secs2Date(datetime, 0), time()
1347        Notebook Report ruler=Title, text=str
1348       
1349        // insert fit results
1350        Variable num=numpnts(ans),ii=0
1351        Notebook Report ruler=Normal; Notebook Report  margins={18,18,504}, tabs={63 + 3*8192}
1352        str = "Data file: " + dataname + "\r\r"
1353        Notebook Report text=str
1354        do
1355                sprintf str, "%s = %g±%g\r", param[ii],ans[ii],sigwave[ii]
1356                Notebook Report text=str
1357                ii+=1
1358        while(ii<num)
1359               
1360        sprintf str,"chisq = %g\r",V_chisq
1361        Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1362        sprintf str,"Npnts = %g\r",V_npnts
1363        Notebook Report textRGB=(0,0,0),fstyle=0, text=str
1364        sprintf str,"V_FitError = %g\rV_FitQuitReason = %g\r",V_FitError,V_FitQuitReason
1365        Notebook Report textRGB=(65000,0,0),fstyle=1,text=str
1366        Notebook Report ruler=Normal
1367       
1368        // insert graphs
1369        Notebook Report picture={AutoGraph_NSE(0, 0, 400, 300), 0, 1}, text="\r"
1370        //Notebook Report picture={Table1, 0, 0}, text="\r"
1371       
1372        // show the top of the report
1373        Notebook Report  selection= {startOfFile, startOfFile},  findText={"", 1}
1374       
1375        //save the notebook
1376        if(yesSave)
1377                String nameStr=CleanupName(func,0)
1378                nameStr = nameStr[0,8]  //shorten the name
1379                nameStr += "_"+dataname
1380                //make sure the name is no more than 31 characters
1381                namestr = namestr[0,30]         //if shorter than 31, this will NOT pad to 31 characters
1382                Print "file saved as ",nameStr
1383                SaveNotebook /O/P=savePath/S=2 Report as nameStr
1384        Endif
1385
1386        //save a pict file, just of the graph
1387        namestr = "PICT_" + namestr
1388        namestr = namestr[0,28]         //PICT names in IGOR must be shorter, to allow auto-naming?
1389        DoWindow/F AutoGraph_NSE
1390        SavePICT /E=2/O/I/P=savePath /W=(0,0,3,3) as nameStr
1391End
1392
1393
1394//*********************
1395//
1396//*********************
1397// List utilities
1398//*********************
1399Function List2TextWave(list,sep,waveStr)
1400        String list,sep,waveStr
1401       
1402        Variable n= ItemsInList(list,sep)
1403        Make/O/T/N=(n) $waveStr= StringFromList(p,list,sep)
1404End
1405
1406Function List2NumWave(list,sep,waveStr)
1407        String list,sep,waveStr
1408       
1409        Variable n= ItemsInList(list,sep)
1410        Make/O/D/N=(n) $waveStr= str2num( StringFromList(p,list,sep) )
1411End
1412
1413Function/S TextWave2List(w,sep)
1414        Wave/T w
1415        String sep
1416       
1417        String newList=""
1418        Variable n=numpnts(w),ii=0
1419        do
1420                newList += w[ii] + sep
1421                ii+=1
1422        while(ii<n)
1423        return(newList)
1424End
1425
1426//for single precision numerical waves
1427Function/S NumWave2List(w,sep)
1428        Wave w
1429        String sep
1430       
1431        String newList="",temp=""
1432        Variable n=numpnts(w),ii=0,val
1433        do
1434                val=w[ii]
1435                temp=""
1436                sprintf temp,"%g",val
1437                newList += temp
1438                newList += sep
1439                ii+=1
1440        while(ii<n)
1441        return(newList)
1442End
1443
1444Function DoKillList(list)
1445        String list
1446       
1447        String item=""
1448        do
1449                item = StringFromList(0, list ,";" )
1450                KillWaves/Z $item
1451                list = RemoveFromList(item, list, ";")
1452        while(ItemsInList(list, ";")>0)
1453End
1454
1455//*********************
1456
1457
1458
1459//*******************
1460//Notebook Utils
1461//*******************
1462
1463Proc PrintOpenNotebooks()
1464
1465        String list=WinList("*", ";", "WIN:16")
1466        String item = ""
1467        do
1468                item=StringFromList(0,list,";")
1469                Print item
1470                PrintNotebook $item
1471                list = RemoveFromList(item, list, ";")
1472        while(ItemsInList(list, ";")>0)
1473End
1474
1475Proc CloseOpenNotebooks()
1476
1477        String list=WinList("*", ";", "WIN:16")
1478        String item = ""
1479        do
1480                item=StringFromList(0,list,";")
1481                DoWindow/K $item
1482                list = RemoveFromList(item, list, ";")
1483        while(ItemsInList(list, ";")>0)
1484End
1485
1486Proc Generate_PICTS_list()
1487        fGenerate_PICTS_list()
1488End
1489
1490//spits up a list of PICTS
1491Function fGenerate_PICTS_list()
1492
1493        String List=IndexedFile(savePath, -1, "PICT")
1494        List2TextWave(List,";","PICT_files")
1495        WAVE/T picts=$"PICT_files"
1496        Edit/K=1 picts
1497End
1498
1499Proc Layout_PICTS(pStr)
1500        String pStr=""
1501        Prompt pStr,"wave of PICTs to use",popup,WaveList("PICT_f*", ";", "")
1502               
1503        String List=TextWave2List($pStr,";")
1504        String item = ""
1505        //kill old picts
1506        KillPicts/A/Z
1507        //make a new layout
1508        Layout/C=1 as "PICT_Layout"
1509        DoWindow/C PICTLayout
1510        do
1511                item=StringFromList(0,List,";")
1512                //load each PICT, and append it to the layout
1513                Print "load item = ",item
1514                LoadPICT /O/Q/P=savePath item
1515                DoWindow/F PICTLayout           //be sure layout is on top
1516                AppendLayoutObject /F=1/W=PICTLayout picture  $item
1517                //AppendToLayout $item
1518                //Print item
1519                List = RemoveFromList(item, List, ";")
1520        while(ItemsInList(List, ";")>0)
1521        //tile the PICTs in the layout
1522        Tile/O=8
1523End
1524
1525//spit up a list of everything in the folder that is a text file
1526Proc Generate_Data_Checklist()
1527        fGenerate_Data_list()
1528End
1529Function fGenerate_Data_list()
1530
1531        String List=IndexedFile(dataPath, -1, "TEXT")
1532        List2TextWave(List,";","data_files")
1533        WAVE/T files=$"data_files"
1534        Duplicate/O/T files ModelToUse,Done
1535        ModelToUse = ""
1536        Done = ""
1537        Edit/K=1 files,ModelToUse,Done
1538End
1539
1540//***************
1541
1542// with all of the notebooks open for a given model (with N parameters)
1543// this will comile the reports, save the text notebook, then load it back in
1544// and put it in a table for easy printing
1545//
1546Proc CompileAndLoadReports()
1547        Compile_Reports()
1548        SaveNotebook /O/P=savePath/S=2 Compilation
1549//      Print "Saved as:  ",S_Path
1550        DoWindow/K Compilation
1551        LoadCompiledReports(S_Path)
1552End
1553
1554Proc LoadCompiledReports(str)
1555        String str
1556        LoadWave/J/D/W/E=1/K=0/V={"\t"," $",0,0} str
1557End
1558
1559Proc Compile_Reports(Number_of_Parameters)
1560        Variable Number_of_Parameters=7
1561        fCompile_Reports(Number_of_Parameters)
1562End
1563
1564Proc Compile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr)
1565        Variable WhichParameter=7
1566        String FileStr="FileName_",ParamStr="par_",ParamErrStr="parErr_"
1567        fCompile_GlobalFit_Reports(WhichParameter,FileStr,ParamStr,ParamErrStr)
1568End
1569
1570////
1571Function fCompile_Reports(nPar)
1572        Variable nPar
1573       
1574        String list=WinList("*", ";", "WIN:16")
1575        String item = "",textStr="",newStr=""
1576        Variable sstop,dum,chi
1577       
1578        Variable ii
1579        NewNotebook/F=0 /N=Compilation as "Compilation"
1580        Notebook Compilation text="Variable Name \tValues\tErrors\r"
1581        do
1582                item=StringFromList(0,list,";")
1583                DoWindow/F $item
1584               
1585                Notebook $item selection={(2,0), (3,0)}         //paragraph 3 (starts from 0) = filename
1586                GetSelection notebook,$item,2
1587                textStr=S_Selection
1588                textStr=textStr[0,strlen(textStr)-2]            //remove CR
1589                textStr=textStr[10,strlen(textStr)-1]           //remove "DATA FILE:
1590                Notebook Compilation text="File:\t"+textStr+"\t"
1591                Notebook Compilation text=textStr+"_err\r"
1592               
1593//              printf "%s %s\r",textStr,textStr+"_err"
1594//
1595// results are written as:  "%s = \t%g\t±\t%g\r"
1596//
1597                for(ii=0;ii<nPar;ii+=1)         //gather the parameters
1598               
1599                        Notebook $item selection={(ii+4,0), (ii+5,0)}           //paragraph 5           = parameter 0
1600                        GetSelection notebook,$item,2
1601                        textStr=S_Selection
1602                        textStr=textStr[0,strlen(textStr)-2]
1603                        //textStr=textStr[13,strlen(textStr)-1]         // remove "parameter"
1604                        textStr = ReplaceString("=",textStr,"")
1605                        textStr = ReplaceString("±\t",textStr,"")
1606                        Notebook Compilation text=textStr+"\r"
1607                        //printf "%s\r",textStr
1608                        //Print strlen(textStr)
1609                endfor
1610                //get the chi-squared/N value
1611                ii+=1
1612                Notebook $item selection={(ii+4,0), (ii+5,0)}           //
1613                GetSelection notebook,$item,2
1614                textStr=S_Selection
1615                Print textStr
1616               
1617                sscanf textStr,"Npnts = %g\t\tSqrt(X^2/N) = %g\r",dum,chi
1618                sprintf textStr,"Sqrt(X^2/N)\t%s\t\r",num2str(chi)
1619                Notebook Compilation text=textStr
1620               
1621                Notebook Compilation text="\r"          //separate items
1622               
1623                list = RemoveFromList(item, list, ";")
1624        while(ItemsInList(list, ";")>0)
1625       
1626        DoWindow/F Compilation
1627        Notebook Compilation selection={startOfFile,startOfFile}
1628End
1629
1630////
1631Function fCompile_GlobalFit_Reports(nPar,Files,Param,Param_err)
1632        Variable nPar
1633        String Files,Param,Param_Err
1634       
1635        String list=SortList(WinList("*", ";", "WIN:16"))
1636        String item = "",textStr="",fileStr,funcStr,dumStr
1637        Variable sstop,dum,chi,nFiles,val1,val2
1638       
1639        Variable ii,jj
1640
1641        nFiles = ItemsInList(list)
1642        Make/O/D/N=(nFiles) $Param,$Param_err
1643        Make/O/T/N=(nFiles) $Files
1644        WAVE pw = $Param
1645        WAVE pw_err = $Param_err
1646        WAVE/T fw = $Files
1647       
1648        for(jj=0;jj<nFiles;jj+=1)
1649       
1650                item=StringFromList(jj,list,";")
1651                DoWindow/F $item
1652               
1653                Notebook $item selection={(6,0), (7,0)}         //paragraph 7 (starts from 0) = filename
1654                GetSelection notebook,$item,2
1655                textStr=S_Selection
1656                sscanf textStr,"Data Set:%s ; Function:%s\r",fileStr,funcStr
1657                fw[jj] = fileStr
1658//              Notebook Compilation text=fileStr+"\r"
1659//              Notebook Compilation text=funcStr+"\r"
1660               
1661               
1662//              printf "%s %s\r",textStr,textStr+"_err"
1663
1664                for(ii=nPar;ii<=nPar;ii+=1)             //gather the parameters
1665               
1666                        Notebook $item selection={(ii+7,0), (ii+8,0)}           //paragraph 8           = parameter 0
1667                        GetSelection notebook,$item,2
1668                        textStr=S_Selection
1669//                      Print textStr
1670                        sscanf textStr,"%s %g +- %g\r",dumStr,val1,val2
1671                        pw[jj] = val1
1672                        pw_err[jj] = val2
1673                endfor
1674               
1675        endfor
1676
1677End
1678
1679
1680
1681//DOES NOT graph the data, does not create a weighting wave
1682//NSE data assumed to be 4-column
1683//q (all the same) - t(ns) - I(q,t) - dI(q,t)
1684Static Function LoadNSEDataWithName(fileStr)
1685        String fileStr
1686        //Load the waves, using default waveX names
1687        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
1688        LoadWave/G/D/A/Q fileStr
1689        String fileName = S_fileName
1690       
1691       
1692        String w0,w1,w2,n0,n1,n2,wt,w3,n3
1693        Variable rr,gg,bb
1694       
1695        // put the names of the four loaded waves into local names
1696        n0 = StringFromList(0, S_waveNames ,";" )
1697        n1 = StringFromList(1, S_waveNames ,";" )
1698        n2 = StringFromList(2, S_waveNames ,";" )
1699        n3 = StringFromList(3, S_waveNames ,";" )
1700       
1701       
1702        //remove the semicolon AND period from files from the VAX
1703        w0 = CleanupName((S_fileName+"__Q"),0)
1704        w1 = CleanupName((S_fileName+"__X"),0)
1705        w2 = CleanupName((S_fileName+"__Y"),0)
1706        w3 = CleanupName((S_fileName+"__S"),0)
1707       
1708        if(exists(w0) !=0)
1709                //waves already exist
1710                KillWaves $n0,$n1,$n2,$n3               // kill the default waveX that were loaded
1711                return(0)
1712        endif
1713       
1714        // Rename to give nice names
1715        Rename $n0, $w0
1716        Rename $n1, $w1
1717        Rename $n2, $w2
1718        Rename $n3, $w3
1719
1720End
1721
1722/////
1723//wStr is the coef_ wave with the initial guess
1724Function FillCoefGuess(wStr)
1725        String wStr
1726       
1727        Wave w=$wStr
1728        if (! WaveExists(w) )
1729                DoAlert 0, "The coefficient wave "+wStr+" does not exist. Either create the wave or enter the correct suffix"
1730                return(0)
1731        endif
1732        Wave/T guess=root:AutoFit:guessMatrix
1733        Variable ii=0,num=numpnts(w)
1734        Variable tmp
1735       
1736        Variable selRow,matrixRow
1737        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1738
1739        do
1740                tmp=w[ii]
1741                guess[ii][selRow] = num2str(tmp)
1742                ii+=1
1743        while(ii<num)
1744End
1745
1746/////
1747//wStr is the hold_ wave with the initial guess
1748Function FillHoldGuess(wStr)
1749        String wStr
1750       
1751        Wave w=$wStr
1752        if (! WaveExists(w) )
1753                DoAlert 0, "The hold wave "+wStr+" does not exist. Either create the wave or enter the correct suffix"
1754                return(0)
1755        endif
1756        Wave/T hold=root:AutoFit:holdMatrix
1757        Variable ii=0,num=numpnts(w)
1758        Variable tmp
1759       
1760        Variable selRow,matrixRow
1761        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1762       
1763        do
1764                tmp=w[ii]
1765                hold[ii][selRow] = num2str(tmp)
1766                ii+=1
1767        while(ii<num)
1768End
1769
1770/////
1771//wStr is the Constr_ wave with the initial guess
1772// --- this is a Text wave
1773Function FillConstrGuess(wStr)
1774        String wStr
1775       
1776        Wave/T w=$wStr
1777        if (! WaveExists(w) )
1778                DoAlert 0, "The Constraint wave "+wStr+" does not exist. Either create the (TEXT) wave or enter the correct suffix"
1779                return(0)
1780        endif
1781        Wave/T constr=root:AutoFit:constrMatrix
1782        Variable ii=0,num=numpnts(w)
1783        String tmp
1784       
1785        Variable selRow,matrixRow
1786        selRow = FindSelectedRowInLB(0) // send 0 to look at the column with filenames
1787
1788        do
1789                tmp=w[ii]
1790                constr[ii][selRow] = tmp
1791                ii+=1
1792        while(ii<num)
1793End
1794
1795////
1796//need the extension of the model wave to append
1797//
1798// it will plot the UN-smeared model for generating the initial guesses
1799// -- fitting will use Smeared or unsmeared, depending on the popup selection
1800//
1801//
1802Function fLoadSelected(extStr)
1803        string extStr
1804
1805        Variable datafile,ii
1806        String fullName,dataName,str
1807       
1808        WAVE/T fileWave=root:AutoFit:fileListWave
1809        Wave sel = root:AutoFit:fileSelWave
1810        ii=0
1811        do
1812                if((sel[ii][0] & 0x01) == 1)    // the file is selected in the list box
1813                        datafile = ii
1814                        break
1815                endif
1816                ii+=1
1817        while(ii<numpnts(sel))
1818       
1819        //load in the data
1820        PathInfo dataPath
1821        fullName = S_path
1822        fullName += fileWave[datafile][0]
1823
1824        str = "A_LoadOneDDataToName(\""+fullName+"\",\"\",0,1)"         //don't plot, force overwrite
1825        Execute str             
1826       
1827        dataName=GetFileNameFromPathNoSemi(fullName)
1828        dataname=CleanupName(dataname,0)
1829       
1830        //graph it - creates window named "AutoGraph"
1831        DoWindow/K tmpGraph
1832        Execute "DoGraph(\""+dataname+"\")"
1833        DoWindow/C tmpGraph
1834//      Wave/Z yw = $("ywave_"+extStr)
1835//      Wave/Z xw = $("xwave_"+extStr)
1836
1837        if(exists("ywave_"+extStr) && exists("xwave_"+extStr))
1838                AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr)
1839        else
1840                DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1841        endif
1842
1843//      ControlInfo/W=AutoFitPanel popup0
1844//      if(cmpstr(S_Value[0,4], "Smear" ) == 0 )
1845//              SetDataFolder $dataname
1846//              if(exists("smeared_"+extStr) && exists("smeared_qvals"))
1847//                     
1848//                      AppendtoGraph $("smeared_"+extStr) vs $("smeared_qvals")
1849//              else
1850//                      SetDataFolder root:
1851//                      DoAlert 0,"Smeared Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1852//              endif
1853//             
1854//      else
1855//              if(exists("ywave_"+extStr) && exists("xwave_"+extStr))
1856//                      AppendtoGraph $("ywave_"+extStr) vs $("xwave_"+extStr)
1857//              else
1858//                      DoAlert 0,"Model data with the suffix \""+extStr+"\" does not exist. Either plot the model or enter the correct suffix"
1859//              endif
1860//      endif
1861
1862
1863        SetDataFolder root:
1864        return(0)
1865End
1866
1867//loads the selected file in a temporary graph
1868Function LoadForGuessProc(ctrlName) : ButtonControl
1869        String ctrlName
1870       
1871        SVAR ext=root:AutoFit:gExt
1872        fLoadSelected(ext)
1873        return(0)
1874End
1875
1876//makes the holdWave and Constraint wave that are needed to set the values in the list boxes (and the matrix)
1877// these are not generated when plotting a model.
1878Function Make_HoldConstraintEps_Waves()
1879       
1880        SVAR  ext=root:AutoFit:gExt
1881        Variable num=numpnts($("coef_"+ext))
1882        if(WaveExists($("coef_"+ext)) == 0 )
1883                DoAlert 0,"coef_"+ext+" does not exist. You must set the prefix correctly and plot the model first"
1884        else
1885                Make/O/D/N=(num) $("Hold_"+ext)
1886                Make/O/T/N=(num) $("Constr_"+ext)
1887                Make/O/D/N=(num) $("Epsilon_"+ext)=0.0003
1888       
1889                String str=WinList("*", ";","WIN:2"),sel
1890                Prompt sel, "Select Table to Append Waves", popup str
1891                DoPrompt "asdf",sel
1892                if (V_Flag)
1893                        return 0        // user canceled
1894                endif
1895                DoWindow/F $sel
1896                AppendToTable $("Hold_"+ext), $("Constr_"+ext), $("Epsilon_"+ext)
1897        endif
1898End
1899//needs the name (as a string) of the coefficient wave
1900//it assumes "coef_" plus an extension
1901//
1902Function UseCoefAsGuess(ctrlName) : ButtonControl
1903        String ctrlName
1904       
1905        String wStr = "coef_"
1906        SVAR ext=root:AutoFit:gExt
1907        FillCoefGuess(wStr+ext)
1908        DisplayGuess()
1909        return(0)
1910End
1911
1912//needs the name (as a string) of the hold string wave
1913//it assumes "hold_" plus an extension
1914//
1915Function UseHoldAsGuess(ctrlName) : ButtonControl
1916        String ctrlName
1917       
1918//      String wStr = "hold_"
1919//      SVAR ext=root:AutoFit:gExt
1920//      FillHoldGuess(wStr+ext)
1921//      DisplayGuess()
1922        return(0)
1923End
1924
1925//needs the name (as a string) of the coefficient wave
1926//it assumes "constr" plus an extension
1927//
1928Function UseConstraintsAsGuess(ctrlName) : ButtonControl
1929        String ctrlName
1930       
1931//      String wStr = "Constr_"
1932//      SVAR ext=root:AutoFit:gExt
1933//      FillConstrGuess(wStr+ext)
1934//      DisplayGuess()
1935        return(0)
1936End
1937
Note: See TracBrowser for help on using the repository browser.