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

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

Changes to the analysis package to add a few more model functions. Documentation and XOPs are to follow later.

General n-point gaussian quadrature has been added to GaussUtils? by including a Gauss-Laguere point generator from Numerical Recipes. See the Paracrystal models for an example, since they needed more than the 76 point quadrature.

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