source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/PlotManager.ipf @ 172

Last change on this file since 172 was 172, checked in by srkline, 15 years ago

Tweaks to the template to open the file loader and fit wrapper, and to re-arrange the SANS Models menu.

File size: 8.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=3.00
3#pragma IgorVersion=6.0
4
5
6//////////////////////////////////////////
7//
8// Plot manager that is largely based on the plot manager in the Reduction package
9//
10// "A_" is crudely prepended to function names to avoid conflicts
11//
12// -- data folders will sitll overlap, but should not be an issue
13//
14// 28SEP07 SRK
15//
16//////////////////////////////////////////
17Proc Show_Plot_Manager()
18        A_Init_OneDLoader()
19        DoWindow/F Plot_Manager
20        if(V_flag==0)
21                A_Plot_Manager()
22        endif
23        A_OneDLoader_GetListButton("")
24End
25
26Window A_Plot_Manager() : Panel
27        PauseUpdate; Silent 1           // building window...
28        NewPanel /W=(658,347,1018,737)/N=Plot_Manager/K=1 as "Plot Manager"
29        ModifyPanel cbRGB=(37265,65535,32896)
30        ModifyPanel fixedSize=1
31       
32        Button button0,pos={165,353},size={50,20},proc=A_PlotManager_Done,title="Done"
33        PopupMenu popup0,pos={15,225},size={233,20},title="Data in Memory"
34        PopupMenu popup0,mode=1,value= #"A_OneDDataInMemory()"
35        Button button2,pos={122,259},size={100,20},proc=A_PlotManager_Append,title="Append Data"
36        Button button3,pos={15,259},size={80,20},proc=A_PlotManager_newGraph,title="New Graph"
37        Button button4,pos={15,293},size={220,20},proc=A_PlotManager_Kill,title="Remove Selection From Memory"
38        Button button5,pos={15,323},size={220,20},proc=A_PlotManager_KillAll,title="Remove All Data From Memory"
39        ListBox fileList,pos={13,11},size={206,179}
40        ListBox fileList,listWave=root:myGlobals:OneDLoader:fileWave
41        ListBox fileList,selWave=root:myGlobals:OneDLoader:selWave,mode= 4
42        Button button6,pos={238,153},size={100,20},proc=A_OneDLoader_LoadButton,title="Load File(s)"
43        Button button6,help={"Loads the selected files into memory and will graph them if that option is checked"}
44        Button button7,pos={238,20},size={100,20},proc=A_OneDLoader_NewFolderButton,title="New Folder"
45        Button button7,help={"Select a new data folder"}
46        GroupBox group0,pos={222,108},size={50,4},title="Shift-click to load"
47        GroupBox group0_1,pos={222,123},size={50,4},title="multiple files"
48        GroupBox group1,pos={7,207},size={350,4}
49EndMacro
50
51//uses the same data folder listing as the wrapper
52// if it's right there, it's right here
53Function/S A_OneDDataInMemory()
54        String list = W_DataSetPopupList()
55        return(list)
56end
57
58
59Function A_PlotManager_Done(ctrlName) : ButtonControl
60        String ctrlName
61        DoWindow/K Plot_Manager
62End
63
64Function A_PlotManager_Append(ctrlName) : ButtonControl
65        String ctrlName
66        //appends data set from memory
67       
68        //get the current selection
69        ControlInfo popup0
70        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
71                Abort "You must load data from a file into memory before appending the data"
72        Endif
73       
74        A_PM_doAppend(S_Value)
75       
76        DoWindow/F Plot_Manager
77End
78
79//actually does the appending
80//pass it the name of the wave, find the q-i-s waves
81Function A_PM_doAppend(DF)
82        String DF
83        //appends data set from memory
84        String qStr,eStr,istr
85        Variable rr,gg,bb
86       
87        if(cmpstr(WinList("*", ";","WIN:1"),"") == 0 )
88                DoAlert 0,"There are no open graphs. Please use the New Graph button"
89                return(0)
90        endif
91       
92        SetDataFolder $("root:"+DF)
93        //iStr will end in "i"
94        qStr = DF+"_q"
95        eStr = DF+"_s"
96        iStr = DF+"_i"
97       
98        rr = abs(trunc(enoise(65535)))
99        gg = abs(trunc(enoise(65535)))
100        bb = abs(trunc(enoise(65535)))
101       
102        // append to whatever is top-most graph
103        AppendToGraph $iStr vs $qStr
104        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb($iStr)=(rr,gg,bb)
105        ErrorBars $iStr Y,wave=($eStr,$eStr)
106
107        SetDataFolder root:
108End
109
110Proc A_PlotManager_newGraph(ctrlName) : ButtonControl
111        String ctrlName
112       
113        //get the current selection
114        ControlInfo popup0
115        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
116                Abort "You must load data from a file into memory before plotting the data"
117        Endif
118       
119        A_PM_doNewGraph(S_Value)
120        DoWindow/F Plot_Manager
121End
122
123Function A_PM_doNewGraph(DF)
124        String DF
125
126        String qStr,eStr,iStr
127        Variable rr,gg,bb
128       
129        SetDataFolder $("root:"+DF)
130        //iStr will end in "i"
131        qStr = DF+"_q"
132        eStr = DF+"_s"
133        iStr = DF+"_i"
134       
135        rr = abs(trunc(enoise(65535)))
136        gg = abs(trunc(enoise(65535)))
137        bb = abs(trunc(enoise(65535)))
138       
139        // always make a new graph
140        Display $iStr vs $qStr
141        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb=(rr,gg,bb)
142        ModifyGraph grid=1,mirror=2,standoff=0
143        ErrorBars $iStr Y,wave=($eStr,$eStr)
144       
145        Label left "I(q)"
146        SVAR angst = root:myGlobals:gAngstStr
147        Label bottom "q (A\\S-1\\M)"
148       
149        Legend
150       
151        SetDataFolder root:
152End
153
154//kill the specified wave (if possible)
155Proc A_PlotManager_Kill(ctrlName) : ButtonControl
156        String ctrlName
157       
158        String DF
159
160        ControlInfo popup0
161        DF=S_Value              //this will end in "i"
162
163        KillDataFolder/Z $DF
164        ControlUpdate popup0            //refresh the popup, very important if last item removed
165End
166
167//kill the specified wave (if possible)
168Proc A_PlotManager_KillAll(ctrlName) : ButtonControl
169        String ctrlName
170       
171        String DF
172
173        String list =  A_OneDDataInMemory()
174        Variable num=ItemsInList(list),ii
175       
176        ii=0
177        do     
178                DF=StringFromList(ii, list  ,";")
179                KillDataFolder/Z $DF
180                ii+=1
181        while(ii<num)
182        ControlUpdate popup0            //refresh the popup, very important if all items are removed
183End
184
185Proc A_Init_OneDLoader()
186        //create the data folder
187        NewDataFolder/O/S root:myGlobals:OneDLoader
188        //create the waves
189        Make/O/T/N=1 fileWave=""
190        Make/O/N=1 selWave=0
191        Variable/G ind=0
192        SetDataFolder root:
193End
194
195
196//prompt for a new path, and get a new listing
197Function A_OneDLoader_NewFolderButton(ctrlName) : ButtonControl
198        String ctrlName
199
200        A_PickPath()
201        A_OneDLoader_GetListButton("")
202        return(0)
203End
204
205//filters to remove only the files that are named like a raw data file, i.e. "*.SAn"
206//does not check to see if they really are RAW files though...(too tedious)
207Function A_OneDLoader_GetListButton(ctrlName) : ButtonControl
208        String ctrlName
209       
210        //make sure that path exists
211        PathInfo catPathName
212        if (V_flag == 0)
213                Abort "Folder path does not exist - use \"New Folder\" button on Main Panel"
214        Endif
215       
216        String newList = A_ReducedDataFileList("")
217        Variable num
218       
219        num=ItemsInList(newlist,";")
220        WAVE/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
221        WAVE selWave=$"root:myGlobals:OneDLoader:selWave"
222        Redimension/N=(num) fileWave
223        Redimension/N=(num) selWave
224        fileWave = StringFromList(p,newlist,";")
225        Sort filewave,filewave
226End
227
228Function A_OneDLoader_LoadButton(ctrlName) : ButtonControl
229        String ctrlName
230       
231        //loop through the selected files in the list...
232        Wave/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
233        Wave sel=$"root:myGlobals:OneDLoader:selWave"
234        Variable num=numpnts(sel),ii=0
235        String fname="",pathStr="",fullPath="",newFileName=""
236       
237        PathInfo catPathName                    //this is where the files are
238        pathStr=S_path
239       
240        Variable doGraph,cnt
241
242        ControlInfo check0
243        doGraph=V_Value
244        cnt=0
245        // get the current state
246        do
247                if(sel[ii] == 1)
248                        fname=pathStr + fileWave[ii]
249                        Execute "A_LoadOneDDataWithName(\""+fname+"\",1)"
250                        cnt += 1        //a file was loaded
251                endif
252                ii+=1
253        while(ii<num)
254
255        return(0)
256End
257
258
259//function called by the popups to get a file list of data that can be sorted
260// this procedure simply removes the raw data files from the string - there
261//can be lots of other junk present, but this is very fast...
262//
263// could also use the alternate procedure of keeping only file with the proper extension
264//
265// another possibility is to get a listing of the text files, but is unreliable on
266// Windows, where the data file must be .txt (and possibly OSX)
267//
268Function/S A_ReducedDataFileList(ctrlName)
269        String ctrlName
270
271        String list="",newList="",item=""
272        Variable num,ii
273       
274        //check for the path
275        PathInfo catPathName
276        if(V_Flag==0)
277                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
278                Return("")
279        Endif
280       
281        list = IndexedFile(catpathName,-1,"????")
282        num=ItemsInList(list,";")
283        //print "num = ",num
284        for(ii=(num-1);ii>=0;ii-=1)
285                item = StringFromList(ii, list  ,";")
286                //simply remove all that are not raw data files (SA1 SA2 SA3)
287                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
288                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
289                                newlist += item + ";"
290                        endif
291                endif
292        endfor
293        //sort
294        newList = SortList(newList,";",0)
295
296        return newlist
297End
Note: See TracBrowser for help on using the repository browser.