source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Packages/ModelPicker/SANSModelPicker_v40.ipf @ 774

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

Added the Two-Yukawa structure factor calculations to those model functions with S(Q).

Fixed the name of Vesicle_UL_Sq.ipf to be consistent.

File size: 30.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
3#pragma version=4.00
4
5//************************
6//
7// Utility procedure to allow the user to select exactly which fitting
8// functions they wish to include in their experiment. Smearing and plotting
9// procedures are automatically included
10//
11// Functions are now in "SANS Models" Menu, with submenus for
12// smeared/unsmeared functions
13//
14// this change was prompted due to the 31 item limitation of Windows submenus
15// resulting in functions being unavailable in the curve fitting dialog
16//
17// A built-in list of procedure files is included, and should match the current
18// distribution package -- see the procedure asdf() for instructions on how
19// to update the built-in list of procedures
20//
21// SRK 091801
22//
23// Updated for easier use 02 JUL 04 SRK
24//
25// SRK 16DEC05 added utility function to get the list of all functions
26// first - select and include all of the models
27//    -- Proc GetAllModelFunctions()
28//
29// SEE TypeNewModelList() for instructions on how to permanently add new model
30// functions to the list... (APR 06 SRK)
31//
32// added Freeze Model - to duplicate a model function/strip the dependency
33// and plot it on the top graph - so that parameters can be changed...
34// SRK 09 JUN 2006
35//
36//***************************
37
38// main procedure for invoking the Procedure list panel
39// initializes each time to make sure
40Proc ModelPicker_Panel()
41       
42        DoWindow/F Procedure_List
43        if(V_Flag==0)
44                Init_FileList()
45                Procedure_List()
46//              AutoPositionWindow/M=1/R=WrapperPanel Procedure_List            //keep it on-screen
47        endif
48End
49
50// initialization procedure to create the necessary data folder and the waves for
51// the list box in the panel
52Proc Init_FileList()
53        //create the data folders  and globals
54        NewDataFolder/O root:Packages
55        NewDataFolder/O root:Packages:NIST
56       
57        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
58                String/G root:Packages:NIST:gAngstStr = num2char(-127)
59//              Variable/G root:myGlobals:gIsMac = 1
60        else
61                //either Windows or Windows NT
62                String/G root:Packages:NIST:gAngstStr = num2char(-59)
63//              Variable/G root:myGlobals:gIsMac = 0
64                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
65                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
66        endif
67       
68        if(!DataFolderExists("root:Packages:NIST:FileList"))
69                NewDataFolder/O/S root:Packages:NIST:FileList
70                //create the waves
71                Make/O/T/N=0 fileWave,includedFileWave
72                Make/O/N=0 selWave,selToDelWave
73        //      String/G allFiles=""
74                String/G MenuItemStr1=""
75                String/G MenuItemStr2=""
76                //DON'T create MenuItemStr_def
77               
78                // a switch for me to turn off file checking
79                Variable/G checkForFiles=1              //set to true initially
80               
81                // always turn off file checking for me
82                checkForFiles = !(stringmatch(ParseFilePath(0,SpecialDirPath("Desktop",0,0,0),":",1,1),"s*ine"))                //zero for me
83               
84                // turn off file checking if the proper alias to the NCNR procedures is there
85                PathInfo igor
86                NewPath/O/Q tmpUPPath S_Path + "User Procedures" 
87                String fileList = IndexedFile(tmpUPPath,-1,"????")
88                if(strsearch(fileList, "NCNR_User_Procedures", 0  , 2) != -1)   //ignore case
89                        checkforfiles = 0
90                        Print "found the proper procedures"
91                endif
92               
93                //fill the list of procedures
94                //
95                // first time, create wave from built-in list
96                FileList_BuiltInList()          //makes sure that the wave exists
97                FileList_GetListButtonProc("")  //converts it into a list for the panel
98               
99                // "include" nothing to force a load of the utility procedures
100                FileList_InsertButtonProc("")
101               
102
103               
104                SetDataFolder root:
105        Endif
106End
107
108
109// for my own testing to read in a new list of procedures
110// FileList_GetListButtonProc("") will only read in a new list
111// if the wave SANS_Model_List does not exist
112Proc ReadNewProcList()
113        KillWaves/Z root:Packages:NIST:FileList:SANS_Model_List         //kill the old list
114        FileList_GetListButtonProc("")
115End
116
117// To create a new "Built-in" list of procedures, edit the
118// wave SANS_Model_List (a text wave), adding your new procedure names
119// (sort alphabetically if desired)
120// then use TypeNewModelList() to spit out the text format.
121// then paste this list into FileList_BuiltInList
122//
123// note that you won't have help for these new procedures until
124// you update the function documentation, making the name of the procedure
125// file a Subtopic
126//
127Proc TypeNewModelList()
128        variable ii=0,num=numpnts(root:Packages:NIST:FileList:SANS_Model_List)
129        printf "Make/O/T/N=%d  SANS_Model_List\r\r",num
130        do
131                printf "SANS_Model_List[%d] = \"%s\"\r",ii,root:Packages:NIST:FileList:SANS_Model_List[ii]
132                ii+=1
133        while(ii<num)
134End
135
136Proc FileList_BuiltInList()
137        SetDataFolder root:Packages:NIST:FileList
138
139////paste here... after deleting the old make statement and list
140       
141  Make/O/T/N=95  SANS_Model_List
142
143  SANS_Model_List[0] = "BE_Polyelectrolyte.ipf"
144  SANS_Model_List[1] = "CoreShellCylinder.ipf"
145  SANS_Model_List[2] = "CoreShell_Sq.ipf"
146  SANS_Model_List[3] = "CoreShell.ipf"
147  SANS_Model_List[4] = "Cylinder_Sq.ipf"
148  SANS_Model_List[5] = "Cylinder.ipf"
149  SANS_Model_List[6] = "DAB_model.ipf"
150  SANS_Model_List[7] = "HPMSA.ipf"
151  SANS_Model_List[8] = "HardSphereStruct.ipf"
152  SANS_Model_List[9] = "HollowCylinders.ipf"
153  SANS_Model_List[10] = "Lorentz_model.ipf"
154  SANS_Model_List[11] = "OblateCoreShell_Sq.ipf"
155  SANS_Model_List[12] = "OblateCoreShell.ipf"
156  SANS_Model_List[13] = "Peak_Gauss_model.ipf"
157  SANS_Model_List[14] = "Peak_Lorentz_model.ipf"
158  SANS_Model_List[15] = "PolyCoreShellRatio_Sq.ipf"
159  SANS_Model_List[16] = "PolyCoreShellRatio.ipf"
160  SANS_Model_List[17] = "PolyCore_Sq.ipf"
161  SANS_Model_List[18] = "PolyCore.ipf"
162  SANS_Model_List[19] = "PolyHardSphereInten.ipf"
163  SANS_Model_List[20] = "PolyRectSphere_Sq.ipf"
164  SANS_Model_List[21] = "PolyRectSphere.ipf"
165  SANS_Model_List[22] = "Power_Law_model.ipf"
166  SANS_Model_List[23] = "ProlateCoreShell_Sq.ipf"
167  SANS_Model_List[24] = "ProlateCoreShell.ipf"
168  SANS_Model_List[25] = "SmearedRPA.ipf"
169  SANS_Model_List[26] = "Sphere_Sq.ipf"
170  SANS_Model_List[27] = "Sphere.ipf"
171  SANS_Model_List[28] = "SquareWellStruct.ipf"
172  SANS_Model_List[29] = "StackedDiscs.ipf"
173  SANS_Model_List[30] = "Teubner.ipf"
174  SANS_Model_List[31] = "UniformEllipsoid_Sq.ipf"
175  SANS_Model_List[32] = "UniformEllipsoid.ipf"
176  SANS_Model_List[33] = "CoreShellCyl2D.ipf"
177  SANS_Model_List[34] = "Cylinder_2D.ipf"
178  SANS_Model_List[35] = "Ellipsoid2D.ipf"
179  SANS_Model_List[36] = "EllipticalCylinder2D.ipf"
180  SANS_Model_List[37] = "Beaucage.ipf"
181  SANS_Model_List[38] = "BimodalSchulzSpheres.ipf"
182  SANS_Model_List[39] = "BinaryHardSpheres.ipf"
183  SANS_Model_List[40] = "Cylinder_PolyLength.ipf"
184  SANS_Model_List[41] = "Cylinder_PolyRadius.ipf"
185  SANS_Model_List[42] = "Debye.ipf"
186  SANS_Model_List[43] = "EllipticalCylinder.ipf"
187  SANS_Model_List[44] = "FlexCyl_EllipCross.ipf"
188  SANS_Model_List[45] = "FlexCyl_PolyLen.ipf"
189  SANS_Model_List[46] = "FlexCyl_PolyRadius.ipf"
190  SANS_Model_List[47] = "FlexibleCylinder.ipf"
191  SANS_Model_List[48] = "Fractal.ipf"
192  SANS_Model_List[49] = "GaussSpheres_Sq.ipf"
193  SANS_Model_List[50] = "GaussSpheres.ipf"
194  SANS_Model_List[51] = "LamellarFF_HG.ipf"
195  SANS_Model_List[52] = "LamellarFF.ipf"
196  SANS_Model_List[53] = "LamellarPS_HG.ipf"
197  SANS_Model_List[54] = "LamellarPS.ipf"
198  SANS_Model_List[55] = "LogNormalSphere_Sq.ipf"
199  SANS_Model_List[56] = "LogNormalSphere.ipf"
200  SANS_Model_List[57] = "MultiShell.ipf"
201  SANS_Model_List[58] = "Parallelepiped.ipf"
202  SANS_Model_List[59] = "PolyCoreShellCylinder.ipf"
203  SANS_Model_List[60] = "SchulzSpheres_Sq.ipf"
204  SANS_Model_List[61] = "SchulzSpheres.ipf"
205  SANS_Model_List[62] = "StickyHardSphereStruct.ipf"
206  SANS_Model_List[63] = "TriaxialEllipsoid.ipf"
207  SANS_Model_List[64] = "Vesicle_UL_Sq.ipf"
208  SANS_Model_List[65] = "Vesicle_UL.ipf"
209  //2008 Models
210  SANS_Model_List[66] = "Core_and_NShells.ipf"
211  SANS_Model_List[67] = "PolyCore_and_NShells.ipf"
212  SANS_Model_List[68] = "Fractal_PolySphere.ipf"
213  SANS_Model_List[69] = "GaussLorentzGel.ipf"
214  SANS_Model_List[70] = "PolyGaussCoil.ipf"
215  SANS_Model_List[71] = "Two_Power_Law.ipf"
216  SANS_Model_List[72] = "BroadPeak.ipf"
217  SANS_Model_List[73] = "CorrelationLengthModel.ipf"
218  SANS_Model_List[74] = "TwoLorentzian.ipf"
219  SANS_Model_List[75] = "PolyGaussShell.ipf"
220  SANS_Model_List[76] = "LamellarParacrystal.ipf"
221  SANS_Model_List[77] = "SC_ParaCrystal.ipf"
222  SANS_Model_List[78] = "BCC_ParaCrystal.ipf"
223  SANS_Model_List[79] = "FCC_ParaCrystal.ipf"
224  SANS_Model_List[80] = "Spherocylinder.ipf"
225  SANS_Model_List[81] = "Dumbbell.ipf"
226  SANS_Model_List[82] = "ConvexLens.ipf"
227  SANS_Model_List[83] = "CappedCylinder.ipf"
228  SANS_Model_List[84] = "Barbell.ipf"
229  //2009 Models
230  SANS_Model_List[85] = "PolyCoreBicelle.ipf"
231  SANS_Model_List[86] = "CSParallelepiped.ipf"
232  SANS_Model_List[87] = "Fractal_PolyCore.ipf"
233  SANS_Model_List[88] = "FuzzySpheres.ipf"
234  SANS_Model_List[89] = "FuzzySpheres_Sq.ipf"
235        //2010 models
236  SANS_Model_List[90] = "Guinier_Porod.ipf"
237  SANS_Model_List[91] = "PolymerExcludVol.ipf"
238  SANS_Model_List[92] = "Raspberry.ipf"
239  SANS_Model_List[93] = "PolyRaspberry.ipf"
240  SANS_Model_List[94] = "Two_Yukawa.ipf"
241
242  ///end paste here
243End
244
245//another way to add a single procedure name to the list
246// (only in the current experiment!)
247// not a permanent add to the template, unless you re-save the
248// template
249Proc AddProcedureToList(ProcedureName)
250        String ProcedureName
251       
252        SetDataFolder root:Packages:NIST:FileList
253        Variable num
254        num=numpnts(fileWave)
255        Redimension/N=(num+1) fileWave
256        fileWave[num] = ProcedureName
257        num=numpnts(selWave)
258        Redimension/N=(num+1) selWave
259        selWave[num] = 0
260       
261        SetDataFolder root:
262End
263/////////////////////////////////////////////////////////////
264
265
266Proc doCheck(val)
267        Variable val
268        // a switch for me to turn off file checking
269        root:Packages:NIST:FileList:checkForFiles=val   //0==no check, 1=check 
270End
271
272
273//Function MakeMenu_ButtonProc(ctrlName) : ButtonControl
274//      String ctrlName
275
276//      RefreshMenu()
277//End
278
279//procedure for drawing the simple panel to pick and compile selected models
280//
281Proc Procedure_List()
282        PauseUpdate; Silent 1           // building window...
283        NewPanel /W=(1115,44,1453,363) /K=2
284        DoWindow/C Procedure_List
285        ModifyPanel fixedSize=1
286       
287        ListBox fileList,pos={4,3},size={200,203},listWave=root:Packages:NIST:FileList:fileWave
288        ListBox fileList,selWave=root:Packages:NIST:FileList:selWave,mode= 4
289        ListBox inclList,pos={4,212},size={200,100}
290        ListBox inclList,listWave=root:Packages:NIST:FileList:includedFileWave
291        ListBox inclList,selWave=root:Packages:NIST:FileList:selToDelWave,mode= 4
292        Button button0,pos={212,173},size={110,20},proc=FileList_InsertButtonProc,title="Include File(s)"
293        Button button0,help={"Includes the selected procedures, functions appear under the SANS Models menu"}
294        Button button5,pos={212,283},size={110,20},proc=FileList_RemoveButtonProc,title="Remove File(s)"
295        Button button5,help={"Removes selected procedures from the experiment"}
296        Button PickerButton,pos={212,14},size={90,20},proc=FileList_HelpButtonProc,title="Help"
297        Button PickerButton,help={"If you need help understanding what a help button does, you really need help"}
298        Button button1,pos={212,37},size={100,20},proc=FileList_HelpButtonProc,title="Function Help"
299        Button button1,help={"If you need help understanding what a help button does, you really need help"}
300        GroupBox group0,pos={203,128},size={46,11},title="Select model functions"
301        GroupBox group0_1,pos={203,145},size={46,11},title="to include"
302EndMacro
303
304
305//button function to prompt user to select path where procedures are located
306Function FL_PickButtonProc(ctrlName) : ButtonControl
307        String ctrlName
308
309        PickProcPath()
310End
311
312//bring the help notebook to the front
313Function FileList_HelpButtonProc(ctrlName) : ButtonControl
314        String ctrlName
315
316        if(cmpstr(ctrlName,"PickerButton")==0)          //PickerButton is the picker help
317                DisplayHelpTopic/Z/K=1 "SANS Model Picker"
318                if(V_flag !=0)
319                        DoAlert 0,"The SANS Model Picker Help file could not be found"
320                endif
321                return(0)
322        endif
323       
324        //otherwise, show the help for the selected function   
325        //loop through the selected files in the list...
326        //
327        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
328        Wave sel=$"root:Packages:NIST:FileList:selWave"
329       
330        Variable num=numpnts(sel),ii
331        String fname=""
332       
333//      NVAR doCheck=root:Packages:NIST:FileList:checkForFiles
334        ii=num-1                //work bottom-up to not lose the index
335        do
336                if(sel[ii] == 1)               
337                                fname = fileWave[ii] //RemoveExten(fileWave[ii])
338                endif
339                ii-=1
340        while(ii>=0)
341       
342        // nothing selected in the list to include,
343        //try the list of already-included files
344        if(cmpstr(fname,"")==0)
345                Wave/T inclFileWave=$"root:Packages:NIST:FileList:includedFileWave"
346                Wave seltoDel=$"root:Packages:NIST:FileList:selToDelWave"
347                num=numpnts(seltoDel)
348                ii=num-1                //work bottom-up to not lose the index
349                do
350                        if(seltoDel[ii] == 1)           
351                                        fname = inclFileWave[ii] //RemoveExten(fileWave[ii])
352                        endif
353                        ii-=1
354                while(ii>=0)
355        endif
356       
357        if(cmpstr(fname,"")!=0)
358//              Print "show help for ",RemoveExten(fname)
359//              Print fname[strlen(fname)-11,strlen(fname)-1]
360//              Print fname
361                if(cmpstr(fname[strlen(fname)-7,strlen(fname)-1],"_Sq.ipf") ==0 )
362                        DisplayHelpTopic/Z/K=1 "How Form Factors and Structure Factors are Combined"
363                        if(V_flag !=0)
364                                DoAlert 0,"The Help file could not be found"
365                        endif
366                else
367                        DisplayHelpTopic/Z/K=1 fname
368                        if(V_flag !=0)
369                                DoAlert 0,"The Help file could not be found for " + fname
370                        endif
371                endif
372        else
373                DoAlert 0,"Please select a function from the list to display its help file"
374        endif
375       
376        return(0)
377End
378
379//closes the panel when done
380Function FileListDoneButtonProc(ctrlName) : ButtonControl
381        String ctrlName
382
383        //kill the panel
384        DoWindow/K Procedure_List
385        return(0)
386End
387
388//reads in the list of procedures
389// (in practice, the list will be part of the experiment)
390// but this can be used to easily update the list if
391// new models are added, or if a custom list is desired
392// - these lists could also be stored in the template
393//
394Function FileList_GetListButtonProc(ctrlName) : ButtonControl
395        String ctrlName
396       
397        String list=""
398
399        if(Exists("root:Packages:NIST:FileList:SANS_Model_List") != 1)
400                SetDataFolder root:Packages:NIST:FileList
401                LoadWave/A/T
402                WAVE/T w=$(StringFromList(0,S_WaveNames,";"))
403                SetDataFolder root:
404        else
405                WAVE/T w=$("root:Packages:NIST:FileList:SANS_Model_List")
406        endif
407       
408//      // convert the input wave to a semi-list
409//      SVAR allFiles=root:Packages:NIST:FileList:allFiles
410//      allFiles=MP_TextWave2SemiList(w)
411        list=MP_TextWave2SemiList(w)
412       
413        //get the list of available files from the specified path
414        String newList="",item=""
415        Variable num=ItemsInList(list,";"),ii
416
417        // remove the items that have already been included
418        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
419        Variable numInc=numpnts(includedFileWave)
420        for(ii=0;ii<numInc;ii+=1)
421                list = RemoveFromList(includedFileWave[ii],list,";")
422        endfor
423        list = SortList(list,";",0)
424        num=ItemsInList(list,";")
425        WAVE/T fileWave=$"root:Packages:NIST:FileList:fileWave"
426        WAVE selWave=$"root:Packages:NIST:FileList:selWave"
427        Redimension/N=(num) fileWave            //make the waves the proper length
428        Redimension/N=(num) selWave
429        fileWave = StringFromList(p,list,";")           //converts the list to a wave
430        Sort filewave,filewave
431       
432        return(0)
433End
434
435//*******OLD WAY*******
436//*******NOT USED*******
437//gets the list of files in the folder specified by procPathName
438//filters the list to remove some of the procedures that the user does not need to see
439// list is assigned to textbox wave
440Function OLD_FileList_GetListButtonProc(ctrlName) : ButtonControl
441        String ctrlName
442       
443        //make sure that path exists
444        PathInfo procPathName
445        if (V_flag == 0)
446                //Abort "Folder path does not exist - use Pick Path button to set path"
447                //build the path to the User Procedures folder
448                PathInfo Igor
449        //      Print S_Path
450                String UserProcStr=S_path+"User Procedures:"
451                NewPath/O/Q procPathName  UserProcStr
452        Endif
453       
454        String list=""
455//      list=IndexedFile(procPathName,-1,"????")
456
457// new way, to catch all files in all subfolders
458        SVAR allFiles=root:Packages:NIST:FileList:allFiles
459        allFiles=""             //clear the list
460
461        ListAllFilesAndFolders("procPathName",1,1,0)    //this sets allFiles
462        list = allFiles
463       
464        //get the list of available files from the specified path
465       
466        String newList="",item=""
467        Variable num=ItemsInList(list,";"),ii
468        //remove procedures from the list the are unrelated, or may be loaded by default (Utils)
469        list = RemoveFromList(".DS_Store",list,";")             //occurs on OSX, not "hidden" to Igor
470        list = RemoveFromList("GaussUtils.ipf",list,";" )
471        list = RemoveFromList("PlotUtils.ipf",list,";" )
472        list = RemoveFromList("PlotUtilsMacro.ipf",list,";" )
473        list = RemoveFromList("WriteModelData.ipf",list,";" )
474        list = RemoveFromList("WMMenus.ipf",list,";" )
475        list = RemoveFromList("DemoLoader.ipf",list,";" )
476        // remove the items that have already been included
477        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
478        Variable numInc=numpnts(includedFileWave)
479        for(ii=0;ii<numInc;ii+=1)
480                list = RemoveFromList(includedFileWave[ii],list,";")
481        endfor
482        list = SortList(list,";",0)
483        num=ItemsInList(list,";")
484        WAVE/T fileWave=$"root:Packages:NIST:FileList:fileWave"
485        WAVE selWave=$"root:Packages:NIST:FileList:selWave"
486        Redimension/N=(num) fileWave            //make the waves the proper length
487        Redimension/N=(num) selWave
488        fileWave = StringFromList(p,list,";")           //converts the list to a wave
489        Sort filewave,filewave
490End
491
492// returns 1 if the file exists, 0 if the file is not there
493// fails miserably if there are aliases in the UP folder, although
494// the #include doesn't mind
495//
496// SRK -2010- I need to look in the special directory too (look there first)
497//
498Function CheckFileInUPFolder(fileStr)
499        String fileStr
500
501        Variable err=0
502        String/G root:Packages:NIST:FileList:allFiles=""
503        SVAR allFiles = root:Packages:NIST:FileList:allFiles
504
505        SVAR fileVerExt = root:Packages:NIST:SANS_ANA_EXTENSION
506
507        fileStr = RemoveExten(fileStr)+fileVerExt
508       
509        // the Igor 6.1 User Procedure Path, same sub-folders as in Igor App Folder
510        // the installer MOVES items here, so no troubles with aliases
511        String userPathStr=RemoveEnding(SpecialDirPath("Igor Pro User Files",0,0,0),":")+":"
512        String UPStr=userPathStr+"User Procedures:"
513        NewPath /O/Q/Z UPPath ,UPStr
514        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets the global string allFiles
515        String list = allFiles
516        err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
517        if(err != -1)
518                return(1)               //name was found somewhere
519        endif
520       
521        // name not found, try looking in the Igor Pro/ folder
522        // this will still fail if aliases are present here
523        PathInfo Igor
524        UPStr=S_path+"User Procedures:"
525        NewPath /O/Q/Z UPPath ,UPStr
526        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets the global string allFiles
527        list = allFiles
528//      err = FindListItem(fileStr, list ,";" ,0)
529        err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
530//      err = strsearch(list, fileStr, 0)               //this is Igor 4+ compatible
531//      Print err
532        if(err == -1)
533                return(0)
534        else
535                return(1)               //name was found somewhere
536        endif
537End
538
539
540Function FileList_InsertButtonProc(ctrlName) : ButtonControl
541        String ctrlName
542       
543        //loop through the selected files in the list...
544        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
545        Wave sel=$"root:Packages:NIST:FileList:selWave"
546        //and adjust the included file lists
547        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
548        Wave selToDel=$"root:Packages:NIST:FileList:selToDelWave"
549
550        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
551       
552        Variable numIncl=numpnts(includedFileWave)
553        Variable num=numpnts(sel),ii,ok
554        String fname=""
555
556        //Necessary for every analysis experiment
557        Execute/P "INSERTINCLUDE \"PlotUtilsMacro_v40\""
558        Execute/P "INSERTINCLUDE \"GaussUtils_v40\""
559        Execute/P "INSERTINCLUDE \"WriteModelData_v40\""
560       
561        NVAR doCheck=root:Packages:NIST:FileList:checkForFiles
562       
563        ii=num-1                //work bottom-up to not lose the index
564        do
565                if(sel[ii] == 1)
566                        //can I make sure the file exists before trying to include it?
567                        if(doCheck)
568                                ok = CheckFileInUPFolder(fileWave[ii])
569                        endif
570                        if(ok || !doCheck)
571                                fname = RemoveExten(fileWave[ii])       
572                                Execute/P "INSERTINCLUDE \""+fname+fileVerExt+"\""
573                                // add to the already included list, and remove from the to-include list (and selWaves also)
574                                InsertPoints numpnts(includedFileWave), 1, includedFileWave,selToDel
575                                includedFileWave[numpnts(includedFileWave)-1]=fileWave[ii]
576                               
577                                DeletePoints ii, 1, fileWave,sel
578                        else
579                                DoAlert 0,"File "+fileWave[ii]+" was not found in the User Procedures folder, so it was not included"
580                        endif
581                endif
582                ii-=1
583        while(ii>=0)
584//      Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
585        Execute/P "COMPILEPROCEDURES "
586       
587        sel=0           //clear the selections
588        selToDel=0
589       
590        return(0)
591End
592
593Function FileList_RemoveButtonProc(ctrlName) : ButtonControl
594        String ctrlName
595       
596        //loop through the selected files in the list...
597        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
598        Wave selToDel=$"root:Packages:NIST:FileList:selToDelWave"
599        // and put the unwanted procedures back in the to-add list
600        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
601        Wave sel=$"root:Packages:NIST:FileList:selWave"
602       
603        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
604       
605        Variable num=numpnts(selToDel),ii
606        String fname="",funcToDelStr=""
607       
608        ii=num-1                //work backwards
609        do
610                if(selToDel[ii] == 1)
611                        fname = RemoveExten(includedFileWave[ii])
612                        Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\""
613                        //add to the to-include list
614                        InsertPoints numpnts(fileWave), 1, fileWave,sel
615                        fileWave[numpnts(fileWave)-1]=includedFileWave[ii]
616                        //delete the point
617                        DeletePoints ii, 1, includedFileWave,selToDel
618                        //
619                        // could kill dependencies connected to the procedure file, but really not necessary
620                        //funcToDelStr = FunctionList("*",";","WIN:"+fname+fileVerExt+".ipf")
621                        //KillAllDependentObjects("root:",funcToDelStr, 1, 1, 0)
622                         
623                endif
624                ii-=1
625        while(ii>=0)
626        Execute/P "COMPILEPROCEDURES "
627       
628        sel=0
629        selToDel=0
630       
631        Sort filewave,filewave
632        return(0)
633End
634
635Function KillDependentVariables(folderStr,funcToDelStr)
636        String folderStr,funcToDelStr
637       
638        String objName,formStr,funcStr,matchStr
639        Variable index = 0,loc
640       
641        do
642                objName = GetIndexedObjName(folderStr, 2, index)
643                if (strlen(objName) == 0)
644                        break
645                endif
646                formStr = GetFormula($(folderStr+objName))
647                if(strlen(formStr) != 0)
648                        loc = strsearch(formStr,"(",0)
649                        funcStr = formStr[0,loc-1]
650//                      Print objName,funcStr
651                        matchStr = ListMatch(funcToDelStr, funcStr ,";")
652                        if(strlen(matchStr) != 0)
653                                SetFormula $(folderStr+objName),""              //kill the dependency
654                                Printf "killed the dependency of %s on the function %s\r",folderStr+objName,matchStr
655                        endif
656                               
657                endif
658                               
659                index += 1
660        while(1)
661End
662
663
664
665// doesn't really kill all objects...
666// kills the dependency formula for any variable that has a formula that contains a function name
667// that matches anything in the funcToDelStr, which are functions that are about to be removed
668// from the experiment by DELETEINCLUDE
669//
670// recursively looks through all data folders
671//
672// on the first call:
673// pass "root:" as the pathName
674// full = 1
675// recurse = 1
676// level = 0
677//
678Function KillAllDependentObjects(pathName,funcToDelStr, full, recurse, level)
679        String pathName         // Name of symbolic path in which to look for folders.
680        String funcToDelStr             //list of functions to look for
681        Variable full                   // True to print full paths instead of just folder name.
682        Variable recurse                // True to recurse (do it for subfolders too).
683        Variable level          // Recursion level. Pass 0 for the top level.
684       
685        Variable ii
686        String prefix
687       
688//      SVAR allFiles=root:Packages:NIST:FileList:allFiles
689        // Build a prefix (a number of tabs to indicate the folder level by indentation)
690        prefix = ""
691        ii = 0
692        do
693                if (ii >= level)
694                        break
695                endif
696                prefix += "\t"                                  // Indent one more tab
697                ii += 1
698        while(1)
699       
700//      Printf "%s%s\r", prefix, pathName
701//      Print IndexedFile($pathName,-1,"????")
702        //allFiles += IndexedFile($pathName,-1,"????")
703       
704        KillDependentVariables(pathName,funcToDelStr)
705       
706        String path
707        ii = 0
708        do
709                path = GetIndexedObjName(pathName, 4, ii)
710                if (strlen(path) == 0)
711                        break                                                   // No more folders
712                endif
713                path = pathName+path+":"                        //the full path
714//              Print "ii, path = ",ii,path
715
716                if (recurse)                                            // Do we want to go into subfolder?
717                        KillAllDependentObjects(path, funcToDelStr, full, recurse, level+1)
718                endif
719               
720                ii += 1
721        while(1)
722End
723
724
725//removes ANY ".ext" extension from the name
726// - wipes out all after the "dot"
727// - procedure files to be included (using quotes) must be in User Procedures folder
728// and end in .ipf?
729Function/S RemoveExten(str)
730        String str
731       
732        Variable loc=0
733        String tempStr=""
734       
735        loc=strsearch(str,".",0)
736        tempStr=str[0,loc-1]
737        return(tempStr)
738End
739
740// function to have user select the path where the procedure files are
741//      - the selected path is set as procPathName
742//
743// setting the path to "igor" does not seem to have the desired effect of
744// bringing up the Igor Pro folder in the NewPath Dialog
745//
746//may also be able to use folder lists on HD - for more sophisticated listings
747Function PickProcPath()
748       
749        //set the global string to the selected pathname
750        PathInfo/S Igor
751       
752        NewPath/O/M="pick the SANS Procedure folder" procPathName
753        return(0)               //no error
754End
755
756
757//my menu, seemingly one item, but really a long string for each submenu
758// if root:MenuItemStr exists
759//Menu "SANS Models"
760//      StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr_def","ModelPicker_Panel")//, RefreshMenu()
761//      SubMenu "Unsmeared Models"
762//              StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr1","ModelPicker_Panel")
763//      End
764//      SubMenu "Smeared Models"
765//              StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr2","ModelPicker_Panel")
766//      End
767//      SubMenu "Models 3"
768//              StrVarOrDefault("root:MenuItemStr3","ModelPicker_Panel")
769//      End
770//End
771
772//wrapper to use the A_ prepended file loader from the dynamically defined menu
773//Proc LoadSANSorUSANSData()
774//      A_LoadOneDData()
775//End
776
777//// tweaked to find RPA model which has an extra parameter in the declaration
778//Function RefreshMenu()
779//
780//      String list="",sep=";"
781//     
782//      //list = "Refresh Menu"+sep+"ModelPicker_Panel"+sep+"-"+sep
783//      list = "ModelPicker_Panel"+sep+"-"+sep
784////    list += MacroList("LoadO*",sep,"KIND:1,NPARAMS:0")              //data loader
785//      list += "Load SANS or USANS Data;"              //use the wrapper above to get the right loader
786////    list += "Reset Resolution Waves;"               // resets the resolution waves used for the calculations
787////    list += "Freeze Model;"                                         // freeze a model to compare plots on the same graph
788//      list += MacroList("WriteM*",sep,"KIND:1,NPARAMS:4")             //data writer
789//      list += "-"+sep
790//      String/G root:Packages:NIST:FileList:MenuItemStr_def = TrimListTo255(list)
791//     
792//      list = ""
793//      list += MacroList("*",sep,"KIND:1,NPARAMS:3")                           //unsmeared plot procedures
794//      list += MacroList("Plot*",sep,"KIND:1,NPARAMS:4")                               //RPA has 4 parameters
795//      list = RemoveFromList("FreezeModel", list ,";")                 // remove FreezeModel, it's not a model
796//      //      list += "-"+sep
797//      String/G root:Packages:NIST:FileList:MenuItemStr1 = TrimListTo255(list)
798//
799//      list=""
800//      list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:1")                   //smeared plot procedures
801//      list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:2")                   //smeared RPA has 2 parameters
802//      String/G root:Packages:NIST:FileList:MenuItemStr2 = TrimListTo255(list)
803//
804//      BuildMenu "SANS Models"
805//     
806//      return(0)
807//End
808
809//if the length of any of the strings is more than 255, the menu will disappear
810Function/S TrimListTo255(list)
811        String list
812       
813        Variable len,num
814        num = itemsinlist(list,";")
815        len = strlen(list)
816        if(len>255)
817                DoAlert 0, "Not all menu items are shown - remove some of the models"
818                do
819                        list = RemoveListItem(num-1, list  ,";" )
820                        len=strlen(list)
821                        num=itemsinlist(list,";")
822                while(len>255)
823        endif
824        return(list)
825End
826
827Function/S MP_TextWave2SemiList(textW)
828        Wave/T textW
829       
830        String list=""
831        Variable num=numpnts(textW),ii=0
832        do
833                list += textw[ii] + ";"
834                ii+=1
835        while(ii<num)
836        return(list)
837End
838
839Function MP_SemiList2TextWave(list,outWStr)
840        String list,outWStr
841       
842        Variable num=itemsinList(list)
843        Make/T/O/N=(num) $outWStr
844        WAVE/T w=$outWStr
845        w = StringFromList(p,list,";")
846        return(0)
847End
848
849//modified to get a list of all files in folder and subfolders
850// passed back through a global variable
851Function ListAllFilesAndFolders(pathName, full, recurse, level)
852        String pathName         // Name of symbolic path in which to look for folders.
853        Variable full                   // True to print full paths instead of just folder name.
854        Variable recurse                // True to recurse (do it for subfolders too).
855        Variable level          // Recursion level. Pass 0 for the top level.
856       
857        Variable ii
858        String prefix
859       
860        SVAR allFiles=root:Packages:NIST:FileList:allFiles
861        // Build a prefix (a number of tabs to indicate the folder level by indentation)
862        prefix = ""
863        ii = 0
864        do
865                if (ii >= level)
866                        break
867                endif
868                prefix += "\t"                                  // Indent one more tab
869                ii += 1
870        while(1)
871       
872//      Printf "%s%s\r", prefix, pathName
873//      Print IndexedFile($pathName,-1,"????")
874        allFiles += IndexedFile($pathName,-1,"????")
875       
876        String path
877        ii = 0
878        do
879                path = IndexedDir($pathName, ii, full)
880                if (strlen(path) == 0)
881                        break                                                   // No more folders
882                endif
883//              Printf "%s%s\r", prefix, path
884               
885                if (recurse)                                            // Do we want to go into subfolder?
886                        String subFolderPathName = "tempPrintFoldersPath_" + num2istr(level+1)
887                       
888                        // Now we get the path to the new parent folder
889                        String subFolderPath
890                        if (full)
891                                subFolderPath = path    // We already have the full path.
892                        else
893                                PathInfo $pathName              // We have only the folder name. Need to get full path.
894                                subFolderPath = S_path + path
895                        endif
896                       
897                        NewPath/Q/O $subFolderPathName, subFolderPath
898                        ListAllFilesAndFolders(subFolderPathName, full, recurse, level+1)
899                        KillPath/Z $subFolderPathName
900                endif
901               
902                ii += 1
903        while(1)
904End
905
906
907// utility function to get the list of all functions
908// first - select and include all of the models
909//
910Proc GetAllModelFunctions()
911        String str =  FunctionList("*",";","KIND:10,NINDVARS:1")
912        Print itemsinList(str)
913
914        MP_SemiList2TextWave(str,"UserFunctionList")
915        edit UserFunctionList
916end
917
918// allows an easy way to "freeze" a model calculation
919// - duplicates X and Y waves (tags them _q and _i)
920// - kill the dependecy
921// - append it to the top graph
922// - it can later be exported with WriteModelData
923//
924// in Igor 5, you can restrict the WaveList to be just the top graph...
925// SRK  09 JUN 2006
926//
927// made data folder-aware in a somewhat messy way, but wavelist works only on the
928// current data folder, and WaveSelectorWidget is waaaaaay too complex
929//
930Function FreezeModel()
931        String modelType
932        Prompt modelType,"What type of model to freeze? (smeared models use the current data set)",popup,"Unsmeared Model;Smeared Model;"
933        DoPrompt "Type of Data",modelType
934       
935        if(V_Flag==1)           //user canceled
936                return(1)
937        endif
938       
939        String xWave,yWave,newNameStr
940
941        SetDataFolder root:
942        if(cmpstr(modelType,"Smeared Model")==0)
943                ControlInfo/W=WrapperPanel popup_0
944                String folderStr=S_Value
945                SetDataFolder $("root:"+folderStr)
946       
947                Prompt xwave,"X data",popup,WaveList("s*",";","")
948                Prompt ywave,"Y data",popup,WaveList("s*",";","")
949                Prompt newNameStr,"new name for the waves, _q and _i will be appended"
950        else
951                Prompt xwave,"X data",popup,WaveList("x*",";","")
952                Prompt ywave,"Y data",popup,WaveList("y*",";","")
953                Prompt newNameStr,"new name for the waves, _q and _i will be appended"
954        endif
955
956        DoPrompt "Select the Waves to Freeze",xwave,ywave,newNameStr
957        if(V_Flag==1)           //user canceled
958                SetDataFolder root:
959                return(1)
960        endif
961
962        Duplicate/O $xwave,$(newNameStr+"_q")
963        Duplicate/O $ywave,$(newNameStr+"_i")
964        SetFormula $(newNameStr+"_i"), ""
965       
966        AppendToGraph $(newNameStr+"_i") vs $(newNameStr+"_q")
967       
968        SetDataFolder root:
969end
Note: See TracBrowser for help on using the repository browser.