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

Last change on this file since 1147 was 1147, checked in by srkline, 4 years ago

bug fix for Igor 8 - removing the setIgorOption forceCOLORONCOLOR for windows graphics. No longer needed in Igor 8, and generates an error. removed this line in the initialization step in all packages.

bug fix for the defining of a mask for sector averaging in VSANS. beam center in [cm] was incorrectly converted to [pixels]. No other calculations were affected.

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