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

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

Added 2D versions of sphere and GaussPeak? to the package. Probably never need them, but good for testing.

File size: 31.0 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=97  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  SANS_Model_List[95] = "Sphere_2D.ipf"
242  SANS_Model_List[96] = "PeakGauss2D.ipf"
243
244  ///end paste here
245End
246
247//another way to add a single procedure name to the list
248// (only in the current experiment!)
249// not a permanent add to the template, unless you re-save the
250// template
251Proc AddProcedureToList(ProcedureName)
252        String ProcedureName
253       
254        SetDataFolder root:Packages:NIST:FileList
255        Variable num
256        num=numpnts(fileWave)
257        Redimension/N=(num+1) fileWave
258        fileWave[num] = ProcedureName
259        num=numpnts(selWave)
260        Redimension/N=(num+1) selWave
261        selWave[num] = 0
262       
263        SetDataFolder root:
264End
265/////////////////////////////////////////////////////////////
266
267
268Proc doCheck(val)
269        Variable val
270        // a switch for me to turn off file checking
271        root:Packages:NIST:FileList:checkForFiles=val   //0==no check, 1=check 
272End
273
274
275//Function MakeMenu_ButtonProc(ctrlName) : ButtonControl
276//      String ctrlName
277
278//      RefreshMenu()
279//End
280
281//procedure for drawing the simple panel to pick and compile selected models
282//
283Proc Procedure_List()
284        PauseUpdate; Silent 1           // building window...
285        NewPanel /W=(1115,44,1453,363) /K=2
286        DoWindow/C Procedure_List
287        ModifyPanel fixedSize=1
288       
289        ListBox fileList,pos={4,3},size={200,203},listWave=root:Packages:NIST:FileList:fileWave
290        ListBox fileList,selWave=root:Packages:NIST:FileList:selWave,mode= 4
291        ListBox inclList,pos={4,212},size={200,100}
292        ListBox inclList,listWave=root:Packages:NIST:FileList:includedFileWave
293        ListBox inclList,selWave=root:Packages:NIST:FileList:selToDelWave,mode= 4
294        Button button0,pos={212,173},size={110,20},proc=FileList_InsertButtonProc,title="Include File(s)"
295        Button button0,help={"Includes the selected procedures, functions appear under the SANS Models menu"}
296        Button button5,pos={212,283},size={110,20},proc=FileList_RemoveButtonProc,title="Remove File(s)"
297        Button button5,help={"Removes selected procedures from the experiment"}
298        Button PickerButton,pos={212,14},size={90,20},proc=FileList_HelpButtonProc,title="Help"
299        Button PickerButton,help={"If you need help understanding what a help button does, you really need help"}
300        Button button1,pos={212,37},size={100,20},proc=FileList_HelpButtonProc,title="Function Help"
301        Button button1,help={"If you need help understanding what a help button does, you really need help"}
302        GroupBox group0,pos={203,128},size={46,11},title="Select model functions"
303        GroupBox group0_1,pos={203,145},size={46,11},title="to include"
304EndMacro
305
306
307//button function to prompt user to select path where procedures are located
308Function FL_PickButtonProc(ctrlName) : ButtonControl
309        String ctrlName
310
311        PickProcPath()
312End
313
314//bring the help notebook to the front
315Function FileList_HelpButtonProc(ctrlName) : ButtonControl
316        String ctrlName
317
318        if(cmpstr(ctrlName,"PickerButton")==0)          //PickerButton is the picker help
319                DisplayHelpTopic/Z/K=1 "SANS Model Picker"
320                if(V_flag !=0)
321                        DoAlert 0,"The SANS Model Picker Help file could not be found"
322                endif
323                return(0)
324        endif
325       
326        //otherwise, show the help for the selected function   
327        //loop through the selected files in the list...
328        //
329        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
330        Wave sel=$"root:Packages:NIST:FileList:selWave"
331       
332        Variable num=numpnts(sel),ii
333        String fname=""
334       
335//      NVAR doCheck=root:Packages:NIST:FileList:checkForFiles
336        ii=num-1                //work bottom-up to not lose the index
337        do
338                if(sel[ii] == 1)               
339                                fname = fileWave[ii] //RemoveExten(fileWave[ii])
340                endif
341                ii-=1
342        while(ii>=0)
343       
344        // nothing selected in the list to include,
345        //try the list of already-included files
346        if(cmpstr(fname,"")==0)
347                Wave/T inclFileWave=$"root:Packages:NIST:FileList:includedFileWave"
348                Wave seltoDel=$"root:Packages:NIST:FileList:selToDelWave"
349                num=numpnts(seltoDel)
350                ii=num-1                //work bottom-up to not lose the index
351                do
352                        if(seltoDel[ii] == 1)           
353                                        fname = inclFileWave[ii] //RemoveExten(fileWave[ii])
354                        endif
355                        ii-=1
356                while(ii>=0)
357        endif
358       
359        if(cmpstr(fname,"")!=0)
360//              Print "show help for ",RemoveExten(fname)
361//              Print fname[strlen(fname)-11,strlen(fname)-1]
362//              Print fname
363                if(cmpstr(fname[strlen(fname)-7,strlen(fname)-1],"_Sq.ipf") ==0 )
364                        DisplayHelpTopic/Z/K=1 "How Form Factors and Structure Factors are Combined"
365                        if(V_flag !=0)
366                                DoAlert 0,"The Help file could not be found"
367                        endif
368                else
369                        DisplayHelpTopic/Z/K=1 fname
370                        if(V_flag !=0)
371                                DoAlert 0,"The Help file could not be found for " + fname
372                        endif
373                endif
374        else
375                DoAlert 0,"Please select a function from the list to display its help file"
376        endif
377       
378        return(0)
379End
380
381//closes the panel when done
382Function FileListDoneButtonProc(ctrlName) : ButtonControl
383        String ctrlName
384
385        //kill the panel
386        DoWindow/K Procedure_List
387        return(0)
388End
389
390//reads in the list of procedures
391// (in practice, the list will be part of the experiment)
392// but this can be used to easily update the list if
393// new models are added, or if a custom list is desired
394// - these lists could also be stored in the template
395//
396Function FileList_GetListButtonProc(ctrlName) : ButtonControl
397        String ctrlName
398       
399        String list=""
400
401        if(Exists("root:Packages:NIST:FileList:SANS_Model_List") != 1)
402                SetDataFolder root:Packages:NIST:FileList
403                LoadWave/A/T
404                WAVE/T w=$(StringFromList(0,S_WaveNames,";"))
405                SetDataFolder root:
406        else
407                WAVE/T w=$("root:Packages:NIST:FileList:SANS_Model_List")
408        endif
409       
410//      // convert the input wave to a semi-list
411//      SVAR allFiles=root:Packages:NIST:FileList:allFiles
412//      allFiles=MP_TextWave2SemiList(w)
413        list=MP_TextWave2SemiList(w)
414       
415        //get the list of available files from the specified path
416        String newList="",item=""
417        Variable num=ItemsInList(list,";"),ii
418
419        // remove the items that have already been included
420        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
421        Variable numInc=numpnts(includedFileWave)
422        for(ii=0;ii<numInc;ii+=1)
423                list = RemoveFromList(includedFileWave[ii],list,";")
424        endfor
425        list = SortList(list,";",0)
426        num=ItemsInList(list,";")
427        WAVE/T fileWave=$"root:Packages:NIST:FileList:fileWave"
428        WAVE selWave=$"root:Packages:NIST:FileList:selWave"
429        Redimension/N=(num) fileWave            //make the waves the proper length
430        Redimension/N=(num) selWave
431        fileWave = StringFromList(p,list,";")           //converts the list to a wave
432        Sort filewave,filewave
433       
434        return(0)
435End
436
437//*******OLD WAY*******
438//*******NOT USED*******
439//gets the list of files in the folder specified by procPathName
440//filters the list to remove some of the procedures that the user does not need to see
441// list is assigned to textbox wave
442Function OLD_FileList_GetListButtonProc(ctrlName) : ButtonControl
443        String ctrlName
444       
445        //make sure that path exists
446        PathInfo procPathName
447        if (V_flag == 0)
448                //Abort "Folder path does not exist - use Pick Path button to set path"
449                //build the path to the User Procedures folder
450                PathInfo Igor
451        //      Print S_Path
452                String UserProcStr=S_path+"User Procedures:"
453                NewPath/O/Q procPathName  UserProcStr
454        Endif
455       
456        String list=""
457//      list=IndexedFile(procPathName,-1,"????")
458
459// new way, to catch all files in all subfolders
460        SVAR allFiles=root:Packages:NIST:FileList:allFiles
461        allFiles=""             //clear the list
462
463        ListAllFilesAndFolders("procPathName",1,1,0)    //this sets allFiles
464        list = allFiles
465       
466        //get the list of available files from the specified path
467       
468        String newList="",item=""
469        Variable num=ItemsInList(list,";"),ii
470        //remove procedures from the list the are unrelated, or may be loaded by default (Utils)
471        list = RemoveFromList(".DS_Store",list,";")             //occurs on OSX, not "hidden" to Igor
472        list = RemoveFromList("GaussUtils.ipf",list,";" )
473        list = RemoveFromList("PlotUtils.ipf",list,";" )
474        list = RemoveFromList("PlotUtilsMacro.ipf",list,";" )
475        list = RemoveFromList("WriteModelData.ipf",list,";" )
476        list = RemoveFromList("WMMenus.ipf",list,";" )
477        list = RemoveFromList("DemoLoader.ipf",list,";" )
478        // remove the items that have already been included
479        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
480        Variable numInc=numpnts(includedFileWave)
481        for(ii=0;ii<numInc;ii+=1)
482                list = RemoveFromList(includedFileWave[ii],list,";")
483        endfor
484        list = SortList(list,";",0)
485        num=ItemsInList(list,";")
486        WAVE/T fileWave=$"root:Packages:NIST:FileList:fileWave"
487        WAVE selWave=$"root:Packages:NIST:FileList:selWave"
488        Redimension/N=(num) fileWave            //make the waves the proper length
489        Redimension/N=(num) selWave
490        fileWave = StringFromList(p,list,";")           //converts the list to a wave
491        Sort filewave,filewave
492End
493
494// returns 1 if the file exists, 0 if the file is not there
495// fails miserably if there are aliases in the UP folder, although
496// the #include doesn't mind
497//
498// SRK -2010- I need to look in the special directory too (look there first)
499//
500Function CheckFileInUPFolder(fileStr)
501        String fileStr
502
503        Variable err=0
504        String/G root:Packages:NIST:FileList:allFiles=""
505        SVAR allFiles = root:Packages:NIST:FileList:allFiles
506
507        SVAR fileVerExt = root:Packages:NIST:SANS_ANA_EXTENSION
508
509        fileStr = RemoveExten(fileStr)+fileVerExt
510       
511        // the Igor 6.1 User Procedure Path, same sub-folders as in Igor App Folder
512        // the installer MOVES items here, so no troubles with aliases
513        String userPathStr=RemoveEnding(SpecialDirPath("Igor Pro User Files",0,0,0),":")+":"
514        String UPStr=userPathStr+"User Procedures:"
515        NewPath /O/Q/Z UPPath ,UPStr
516        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets the global string allFiles
517        String list = allFiles
518        err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
519        if(err != -1)
520                return(1)               //name was found somewhere
521        endif
522       
523        // name not found, try looking in the Igor Pro/ folder
524        // this will still fail if aliases are present here
525        PathInfo Igor
526        UPStr=S_path+"User Procedures:"
527        NewPath /O/Q/Z UPPath ,UPStr
528        ListAllFilesAndFolders("UPPath",1,1,0)  //this sets the global string allFiles
529        list = allFiles
530//      err = FindListItem(fileStr, list ,";" ,0)
531        err = strsearch(list, fileStr, 0,2)             //this is not case-sensitive, but Igor 5!
532//      err = strsearch(list, fileStr, 0)               //this is Igor 4+ compatible
533//      Print err
534        if(err == -1)
535                return(0)
536        else
537                return(1)               //name was found somewhere
538        endif
539End
540
541
542Function FileList_InsertButtonProc(ctrlName) : ButtonControl
543        String ctrlName
544       
545        //loop through the selected files in the list...
546        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
547        Wave sel=$"root:Packages:NIST:FileList:selWave"
548        //and adjust the included file lists
549        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
550        Wave selToDel=$"root:Packages:NIST:FileList:selToDelWave"
551
552        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
553       
554        Variable numIncl=numpnts(includedFileWave)
555        Variable num=numpnts(sel),ii,ok
556        String fname=""
557
558        //Necessary for every analysis experiment
559        Execute/P "INSERTINCLUDE \"PlotUtilsMacro_v40\""
560        Execute/P "INSERTINCLUDE \"GaussUtils_v40\""
561        Execute/P "INSERTINCLUDE \"WriteModelData_v40\""
562       
563        NVAR doCheck=root:Packages:NIST:FileList:checkForFiles
564       
565        ii=num-1                //work bottom-up to not lose the index
566        do
567                if(sel[ii] == 1)
568                        //can I make sure the file exists before trying to include it?
569                        if(doCheck)
570                                ok = CheckFileInUPFolder(fileWave[ii])
571                        endif
572                        if(ok || !doCheck)
573                                fname = RemoveExten(fileWave[ii])       
574                                Execute/P "INSERTINCLUDE \""+fname+fileVerExt+"\""
575                                // add to the already included list, and remove from the to-include list (and selWaves also)
576                                InsertPoints numpnts(includedFileWave), 1, includedFileWave,selToDel
577                                includedFileWave[numpnts(includedFileWave)-1]=fileWave[ii]
578                               
579                                DeletePoints ii, 1, fileWave,sel
580                        else
581                                DoAlert 0,"File "+fileWave[ii]+" was not found in the User Procedures folder, so it was not included"
582                        endif
583                endif
584                ii-=1
585        while(ii>=0)
586//      Execute/P "COMPILEPROCEDURES ";Execute/P/Q/Z "RefreshMenu()"
587        Execute/P "COMPILEPROCEDURES "
588       
589        sel=0           //clear the selections
590        selToDel=0
591       
592        return(0)
593End
594
595Function FileList_RemoveButtonProc(ctrlName) : ButtonControl
596        String ctrlName
597       
598        //loop through the selected files in the list...
599        Wave/T includedFileWave=$"root:Packages:NIST:FileList:includedFileWave"
600        Wave selToDel=$"root:Packages:NIST:FileList:selToDelWave"
601        // and put the unwanted procedures back in the to-add list
602        Wave/T fileWave=$"root:Packages:NIST:FileList:fileWave"
603        Wave sel=$"root:Packages:NIST:FileList:selWave"
604       
605        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
606       
607        Variable num=numpnts(selToDel),ii
608        String fname="",funcToDelStr=""
609       
610        ii=num-1                //work backwards
611        do
612                if(selToDel[ii] == 1)
613                        fname = RemoveExten(includedFileWave[ii])
614                        Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\""
615                        //add to the to-include list
616                        InsertPoints numpnts(fileWave), 1, fileWave,sel
617                        fileWave[numpnts(fileWave)-1]=includedFileWave[ii]
618                        //delete the point
619                        DeletePoints ii, 1, includedFileWave,selToDel
620                        //
621                        // could kill dependencies connected to the procedure file, but really not necessary
622                        //funcToDelStr = FunctionList("*",";","WIN:"+fname+fileVerExt+".ipf")
623                        //KillAllDependentObjects("root:",funcToDelStr, 1, 1, 0)
624                         
625                endif
626                ii-=1
627        while(ii>=0)
628        Execute/P "COMPILEPROCEDURES "
629       
630        sel=0
631        selToDel=0
632       
633        Sort filewave,filewave
634        return(0)
635End
636
637Function KillDependentVariables(folderStr,funcToDelStr)
638        String folderStr,funcToDelStr
639       
640        String objName,formStr,funcStr,matchStr
641        Variable index = 0,loc
642       
643        do
644                objName = GetIndexedObjName(folderStr, 2, index)
645                if (strlen(objName) == 0)
646                        break
647                endif
648                formStr = GetFormula($(folderStr+objName))
649                if(strlen(formStr) != 0)
650                        loc = strsearch(formStr,"(",0)
651                        funcStr = formStr[0,loc-1]
652//                      Print objName,funcStr
653                        matchStr = ListMatch(funcToDelStr, funcStr ,";")
654                        if(strlen(matchStr) != 0)
655                                SetFormula $(folderStr+objName),""              //kill the dependency
656                                Printf "killed the dependency of %s on the function %s\r",folderStr+objName,matchStr
657                        endif
658                               
659                endif
660                               
661                index += 1
662        while(1)
663End
664
665
666
667// doesn't really kill all objects...
668// kills the dependency formula for any variable that has a formula that contains a function name
669// that matches anything in the funcToDelStr, which are functions that are about to be removed
670// from the experiment by DELETEINCLUDE
671//
672// recursively looks through all data folders
673//
674// on the first call:
675// pass "root:" as the pathName
676// full = 1
677// recurse = 1
678// level = 0
679//
680Function KillAllDependentObjects(pathName,funcToDelStr, full, recurse, level)
681        String pathName         // Name of symbolic path in which to look for folders.
682        String funcToDelStr             //list of functions to look for
683        Variable full                   // True to print full paths instead of just folder name.
684        Variable recurse                // True to recurse (do it for subfolders too).
685        Variable level          // Recursion level. Pass 0 for the top level.
686       
687        Variable ii
688        String prefix
689       
690//      SVAR allFiles=root:Packages:NIST:FileList:allFiles
691        // Build a prefix (a number of tabs to indicate the folder level by indentation)
692        prefix = ""
693        ii = 0
694        do
695                if (ii >= level)
696                        break
697                endif
698                prefix += "\t"                                  // Indent one more tab
699                ii += 1
700        while(1)
701       
702//      Printf "%s%s\r", prefix, pathName
703//      Print IndexedFile($pathName,-1,"????")
704        //allFiles += IndexedFile($pathName,-1,"????")
705       
706        KillDependentVariables(pathName,funcToDelStr)
707       
708        String path
709        ii = 0
710        do
711                path = GetIndexedObjName(pathName, 4, ii)
712                if (strlen(path) == 0)
713                        break                                                   // No more folders
714                endif
715                path = pathName+path+":"                        //the full path
716//              Print "ii, path = ",ii,path
717
718                if (recurse)                                            // Do we want to go into subfolder?
719                        KillAllDependentObjects(path, funcToDelStr, full, recurse, level+1)
720                endif
721               
722                ii += 1
723        while(1)
724End
725
726
727//removes ANY ".ext" extension from the name
728// - wipes out all after the "dot"
729// - procedure files to be included (using quotes) must be in User Procedures folder
730// and end in .ipf?
731Function/S RemoveExten(str)
732        String str
733       
734        Variable loc=0
735        String tempStr=""
736       
737        loc=strsearch(str,".",0)
738        tempStr=str[0,loc-1]
739        return(tempStr)
740End
741
742// function to have user select the path where the procedure files are
743//      - the selected path is set as procPathName
744//
745// setting the path to "igor" does not seem to have the desired effect of
746// bringing up the Igor Pro folder in the NewPath Dialog
747//
748//may also be able to use folder lists on HD - for more sophisticated listings
749Function PickProcPath()
750       
751        //set the global string to the selected pathname
752        PathInfo/S Igor
753       
754        NewPath/O/M="pick the SANS Procedure folder" procPathName
755        return(0)               //no error
756End
757
758
759//my menu, seemingly one item, but really a long string for each submenu
760// if root:MenuItemStr exists
761//Menu "SANS Models"
762//      StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr_def","ModelPicker_Panel")//, RefreshMenu()
763//      SubMenu "Unsmeared Models"
764//              StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr1","ModelPicker_Panel")
765//      End
766//      SubMenu "Smeared Models"
767//              StrVarOrDefault("root:Packages:NIST:FileList:MenuItemStr2","ModelPicker_Panel")
768//      End
769//      SubMenu "Models 3"
770//              StrVarOrDefault("root:MenuItemStr3","ModelPicker_Panel")
771//      End
772//End
773
774//wrapper to use the A_ prepended file loader from the dynamically defined menu
775//Proc LoadSANSorUSANSData()
776//      A_LoadOneDData()
777//End
778
779//// tweaked to find RPA model which has an extra parameter in the declaration
780//Function RefreshMenu()
781//
782//      String list="",sep=";"
783//     
784//      //list = "Refresh Menu"+sep+"ModelPicker_Panel"+sep+"-"+sep
785//      list = "ModelPicker_Panel"+sep+"-"+sep
786////    list += MacroList("LoadO*",sep,"KIND:1,NPARAMS:0")              //data loader
787//      list += "Load SANS or USANS Data;"              //use the wrapper above to get the right loader
788////    list += "Reset Resolution Waves;"               // resets the resolution waves used for the calculations
789////    list += "Freeze Model;"                                         // freeze a model to compare plots on the same graph
790//      list += MacroList("WriteM*",sep,"KIND:1,NPARAMS:4")             //data writer
791//      list += "-"+sep
792//      String/G root:Packages:NIST:FileList:MenuItemStr_def = TrimListTo255(list)
793//     
794//      list = ""
795//      list += MacroList("*",sep,"KIND:1,NPARAMS:3")                           //unsmeared plot procedures
796//      list += MacroList("Plot*",sep,"KIND:1,NPARAMS:4")                               //RPA has 4 parameters
797//      list = RemoveFromList("FreezeModel", list ,";")                 // remove FreezeModel, it's not a model
798//      //      list += "-"+sep
799//      String/G root:Packages:NIST:FileList:MenuItemStr1 = TrimListTo255(list)
800//
801//      list=""
802//      list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:1")                   //smeared plot procedures
803//      list += MacroList("PlotSmea*",sep,"KIND:1,NPARAMS:2")                   //smeared RPA has 2 parameters
804//      String/G root:Packages:NIST:FileList:MenuItemStr2 = TrimListTo255(list)
805//
806//      BuildMenu "SANS Models"
807//     
808//      return(0)
809//End
810
811//if the length of any of the strings is more than 255, the menu will disappear
812Function/S TrimListTo255(list)
813        String list
814       
815        Variable len,num
816        num = itemsinlist(list,";")
817        len = strlen(list)
818        if(len>255)
819                DoAlert 0, "Not all menu items are shown - remove some of the models"
820                do
821                        list = RemoveListItem(num-1, list  ,";" )
822                        len=strlen(list)
823                        num=itemsinlist(list,";")
824                while(len>255)
825        endif
826        return(list)
827End
828
829Function/S MP_TextWave2SemiList(textW)
830        Wave/T textW
831       
832        String list=""
833        Variable num=numpnts(textW),ii=0
834        do
835                list += textw[ii] + ";"
836                ii+=1
837        while(ii<num)
838        return(list)
839End
840
841Function MP_SemiList2TextWave(list,outWStr)
842        String list,outWStr
843       
844        Variable num=itemsinList(list)
845        Make/T/O/N=(num) $outWStr
846        WAVE/T w=$outWStr
847        w = StringFromList(p,list,";")
848        return(0)
849End
850
851//modified to get a list of all files in folder and subfolders
852// passed back through a global variable
853Function ListAllFilesAndFolders(pathName, full, recurse, level)
854        String pathName         // Name of symbolic path in which to look for folders.
855        Variable full                   // True to print full paths instead of just folder name.
856        Variable recurse                // True to recurse (do it for subfolders too).
857        Variable level          // Recursion level. Pass 0 for the top level.
858       
859        Variable ii
860        String prefix
861       
862        SVAR allFiles=root:Packages:NIST:FileList:allFiles
863        // Build a prefix (a number of tabs to indicate the folder level by indentation)
864        prefix = ""
865        ii = 0
866        do
867                if (ii >= level)
868                        break
869                endif
870                prefix += "\t"                                  // Indent one more tab
871                ii += 1
872        while(1)
873       
874//      Printf "%s%s\r", prefix, pathName
875//      Print IndexedFile($pathName,-1,"????")
876        allFiles += IndexedFile($pathName,-1,"????")
877       
878        String path
879        ii = 0
880        do
881                path = IndexedDir($pathName, ii, full)
882                if (strlen(path) == 0)
883                        break                                                   // No more folders
884                endif
885//              Printf "%s%s\r", prefix, path
886               
887                if (recurse)                                            // Do we want to go into subfolder?
888                        String subFolderPathName = "tempPrintFoldersPath_" + num2istr(level+1)
889                       
890                        // Now we get the path to the new parent folder
891                        String subFolderPath
892                        if (full)
893                                subFolderPath = path    // We already have the full path.
894                        else
895                                PathInfo $pathName              // We have only the folder name. Need to get full path.
896                                subFolderPath = S_path + path
897                        endif
898                       
899                        NewPath/Q/O $subFolderPathName, subFolderPath
900                        ListAllFilesAndFolders(subFolderPathName, full, recurse, level+1)
901                        KillPath/Z $subFolderPathName
902                endif
903               
904                ii += 1
905        while(1)
906End
907
908
909// utility function to get the list of all functions
910// first - select and include all of the models
911//
912Proc GetAllModelFunctions()
913        String str =  FunctionList("*",";","KIND:10,NINDVARS:1")
914        Print itemsinList(str)
915
916        MP_SemiList2TextWave(str,"UserFunctionList")
917        edit UserFunctionList
918end
919
920// allows an easy way to "freeze" a model calculation
921// - duplicates X and Y waves (tags them _q and _i)
922// - kill the dependecy
923// - append it to the top graph
924// - it can later be exported with WriteModelData
925//
926// in Igor 5, you can restrict the WaveList to be just the top graph...
927// SRK  09 JUN 2006
928//
929// made data folder-aware in a somewhat messy way, but wavelist works only on the
930// current data folder, and WaveSelectorWidget is waaaaaay too complex
931//
932Function FreezeModel()
933        String modelType
934        Prompt modelType,"What type of model to freeze? (smeared models use the current data set)",popup,"Unsmeared Model;Smeared Model;"
935        DoPrompt "Type of Data",modelType
936       
937        if(V_Flag==1)           //user canceled
938                return(1)
939        endif
940       
941        String xWave,yWave,newNameStr
942
943        SetDataFolder root:
944        if(cmpstr(modelType,"Smeared Model")==0)
945                ControlInfo/W=WrapperPanel popup_0
946                String folderStr=S_Value
947                SetDataFolder $("root:"+folderStr)
948       
949                Prompt xwave,"X data",popup,WaveList("s*",";","")
950                Prompt ywave,"Y data",popup,WaveList("s*",";","")
951                Prompt newNameStr,"new name for the waves, _q and _i will be appended"
952        else
953                Prompt xwave,"X data",popup,WaveList("x*",";","")
954                Prompt ywave,"Y data",popup,WaveList("y*",";","")
955                Prompt newNameStr,"new name for the waves, _q and _i will be appended"
956        endif
957
958        DoPrompt "Select the Waves to Freeze",xwave,ywave,newNameStr
959        if(V_Flag==1)           //user canceled
960                SetDataFolder root:
961                return(1)
962        endif
963
964        Duplicate/O $xwave,$(newNameStr+"_q")
965        Duplicate/O $ywave,$(newNameStr+"_i")
966        SetFormula $(newNameStr+"_i"), ""
967       
968        AppendToGraph $(newNameStr+"_i") vs $(newNameStr+"_q")
969       
970        SetDataFolder root:
971end
Note: See TracBrowser for help on using the repository browser.