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

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

Closing RT ticket by using 76 point quadrature on MultiShell? model

Also has some minor changes to PlotManager? and Wrapper, intermediate changes as I'm working towards 2D fitting functions. Shouldn't break anything, but doesn't really add anything just yet.

File size: 8.0 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        Label bottom "q (A\\S-1\\M)"
147       
148        Legend
149       
150        SetDataFolder root:
151End
152
153//kill the specified wave (if possible)
154Proc A_PlotManager_Kill(ctrlName) : ButtonControl
155        String ctrlName
156       
157        String DF
158
159        ControlInfo popup0
160        DF=S_Value              //this will end in "i"
161
162        KillDataFolder/Z $DF
163        ControlUpdate popup0            //refresh the popup, very important if last item removed
164End
165
166//kill the specified wave (if possible)
167Proc A_PlotManager_KillAll(ctrlName) : ButtonControl
168        String ctrlName
169       
170        String DF
171
172        String list =  A_OneDDataInMemory()
173        Variable num=ItemsInList(list),ii
174       
175        ii=0
176        do     
177                DF=StringFromList(ii, list  ,";")
178                KillDataFolder/Z $DF
179                ii+=1
180        while(ii<num)
181        ControlUpdate popup0            //refresh the popup, very important if all items are removed
182End
183
184Proc A_Init_OneDLoader()
185        //create the data folder
186        NewDataFolder/O/S root:myGlobals:OneDLoader
187        //create the waves
188        Make/O/T/N=1 fileWave=""
189        Make/O/N=1 selWave=0
190        Variable/G ind=0
191        SetDataFolder root:
192End
193
194
195//prompt for a new path, and get a new listing
196Function A_OneDLoader_NewFolderButton(ctrlName) : ButtonControl
197        String ctrlName
198
199        A_PickPath()
200        A_OneDLoader_GetListButton("")
201        return(0)
202End
203
204//filters to remove only the files that are named like a raw data file, i.e. "*.SAn"
205//does not check to see if they really are RAW files though...(too tedious)
206Function A_OneDLoader_GetListButton(ctrlName) : ButtonControl
207        String ctrlName
208       
209        //make sure that path exists
210        PathInfo catPathName
211        if (V_flag == 0)
212                Abort "Folder path does not exist - use \"New Folder\" button on Main Panel"
213        Endif
214       
215        String newList = A_ReducedDataFileList("")
216        Variable num
217       
218        num=ItemsInList(newlist,";")
219        WAVE/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
220        WAVE selWave=$"root:myGlobals:OneDLoader:selWave"
221        Redimension/N=(num) fileWave
222        Redimension/N=(num) selWave
223        fileWave = StringFromList(p,newlist,";")
224        Sort filewave,filewave
225End
226
227Function A_OneDLoader_LoadButton(ctrlName) : ButtonControl
228        String ctrlName
229       
230        //loop through the selected files in the list...
231        Wave/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
232        Wave sel=$"root:myGlobals:OneDLoader:selWave"
233        Variable num=numpnts(sel),ii=0
234        String fname="",pathStr="",fullPath="",newFileName=""
235       
236        PathInfo catPathName                    //this is where the files are
237        pathStr=S_path
238       
239        Variable doGraph,cnt
240
241        ControlInfo check0
242        doGraph=V_Value
243        cnt=0
244        // get the current state
245        do
246                if(sel[ii] == 1)
247                        fname=pathStr + fileWave[ii]
248                        Execute "A_LoadOneDDataWithName(\""+fname+"\",1)"
249                        cnt += 1        //a file was loaded
250                endif
251                ii+=1
252        while(ii<num)
253
254        return(0)
255End
256
257
258//function called by the popups to get a file list of data that can be sorted
259// this procedure simply removes the raw data files from the string - there
260//can be lots of other junk present, but this is very fast...
261//
262// could also use the alternate procedure of keeping only file with the proper extension
263//
264// another possibility is to get a listing of the text files, but is unreliable on
265// Windows, where the data file must be .txt (and possibly OSX)
266//
267Function/S A_ReducedDataFileList(ctrlName)
268        String ctrlName
269
270        String list="",newList="",item=""
271        Variable num,ii
272       
273        //check for the path
274        PathInfo catPathName
275        if(V_Flag==0)
276                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
277                Return("")
278        Endif
279       
280        list = IndexedFile(catpathName,-1,"????")
281        num=ItemsInList(list,";")
282        //print "num = ",num
283        for(ii=(num-1);ii>=0;ii-=1)
284                item = StringFromList(ii, list  ,";")
285                //simply remove all that are not raw data files (SA1 SA2 SA3)
286                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
287                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
288                                newlist += item + ";"
289                        endif
290                endif
291        endfor
292        //sort
293        newList = SortList(newList,";",0)
294
295        return newlist
296End
Note: See TracBrowser for help on using the repository browser.