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

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