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

Last change on this file since 516 was 516, checked in by srkline, 14 years ago

Fixed bugs introduced in r515 concerning the back-compatibility of the kw=val strings for the
model functions. Now should work correctly when no models are loaded.

Changed integration limits on paracrystal models

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