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

Last change on this file since 999 was 999, checked in by srkline, 7 years ago

changes to a few analysis models to make these Igor 7-ready

adding mask editing utilities

many changes to event mode for easier processing of split lists

updated event mode help file

+ lots more!

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