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

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

Added PlotManager?.ipf (1st incarnation) to allow batch loading and plotting of data sets. Panel can be accessed from the macros menu.

PlotManager? is loaded as part of the Includes_3.01, and is completely stand-alone.

Needs some stress-testing.

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//////////////////////////////////////////
17Macro 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
31        Button button0,pos={165,353},size={50,20},proc=A_PlotManager_Done,title="Done"
32        PopupMenu popup0,pos={15,225},size={233,20},title="Data in Memory"
33        PopupMenu popup0,mode=1,value= #"A_OneDDataInMemory()"
34        Button button2,pos={122,259},size={100,20},proc=A_PlotManager_Append,title="Append Data"
35        Button button3,pos={15,259},size={80,20},proc=A_PlotManager_newGraph,title="New Graph"
36        Button button4,pos={15,293},size={220,20},proc=A_PlotManager_Kill,title="Remove Selection From Memory"
37        Button button5,pos={15,323},size={220,20},proc=A_PlotManager_KillAll,title="Remove All Data From Memory"
38        ListBox fileList,pos={13,11},size={206,179}
39        ListBox fileList,listWave=root:myGlobals:OneDLoader:fileWave
40        ListBox fileList,selWave=root:myGlobals:OneDLoader:selWave,mode= 4
41        Button button6,pos={238,153},size={100,20},proc=A_OneDLoader_LoadButton,title="Load File(s)"
42        Button button6,help={"Loads the selected files into memory and will graph them if that option is checked"}
43        Button button7,pos={238,20},size={100,20},proc=A_OneDLoader_NewFolderButton,title="New Folder"
44        Button button7,help={"Select a new data folder"}
45        GroupBox group0,pos={222,108},size={50,4},title="Shift-click to load"
46        GroupBox group0_1,pos={222,123},size={50,4},title="multiple files"
47        GroupBox group1,pos={7,207},size={350,4}
48EndMacro
49
50//uses the same data folder listing as the wrapper
51// if it's right there, it's right here
52Function/S A_OneDDataInMemory()
53        String list = W_DataSetPopupList()
54        return(list)
55end
56
57
58Function A_PlotManager_Done(ctrlName) : ButtonControl
59        String ctrlName
60        DoWindow/K Plot_Manager
61End
62
63Function A_PlotManager_Append(ctrlName) : ButtonControl
64        String ctrlName
65        //appends data set from memory
66       
67        //get the current selection
68        ControlInfo popup0
69        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
70                Abort "You must load data from a file into memory before appending the data"
71        Endif
72       
73        A_PM_doAppend(S_Value)
74       
75        DoWindow/F Plot_Manager
76End
77
78//actually does the appending
79//pass it the name of the wave, find the q-i-s waves
80Function A_PM_doAppend(DF)
81        String DF
82        //appends data set from memory
83        String qStr,eStr,istr
84        Variable rr,gg,bb
85       
86        if(cmpstr(WinList("*", ";","WIN:1"),"") == 0 )
87                DoAlert 0,"There are no open graphs. Please use the New Graph button"
88                return(0)
89        endif
90       
91        SetDataFolder $("root:"+DF)
92        //iStr will end in "i"
93        qStr = DF+"_q"
94        eStr = DF+"_s"
95        iStr = DF+"_i"
96       
97        rr = abs(trunc(enoise(65535)))
98        gg = abs(trunc(enoise(65535)))
99        bb = abs(trunc(enoise(65535)))
100       
101        // append to whatever is top-most graph
102        AppendToGraph $iStr vs $qStr
103        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb($iStr)=(rr,gg,bb)
104        ErrorBars $iStr Y,wave=($eStr,$eStr)
105
106        SetDataFolder root:
107End
108
109Proc A_PlotManager_newGraph(ctrlName) : ButtonControl
110        String ctrlName
111       
112        //get the current selection
113        ControlInfo popup0
114        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
115                Abort "You must load data from a file into memory before plotting the data"
116        Endif
117       
118        A_PM_doNewGraph(S_Value)
119        DoWindow/F Plot_Manager
120End
121
122Function A_PM_doNewGraph(DF)
123        String DF
124
125        String qStr,eStr,iStr
126        Variable rr,gg,bb
127       
128        SetDataFolder $("root:"+DF)
129        //iStr will end in "i"
130        qStr = DF+"_q"
131        eStr = DF+"_s"
132        iStr = DF+"_i"
133       
134        rr = abs(trunc(enoise(65535)))
135        gg = abs(trunc(enoise(65535)))
136        bb = abs(trunc(enoise(65535)))
137       
138        // always make a new graph
139        Display $iStr vs $qStr
140        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb=(rr,gg,bb)
141        ModifyGraph grid=1,mirror=2,standoff=0
142        ErrorBars $iStr Y,wave=($eStr,$eStr)
143       
144        Label left "I(q)"
145        SVAR angst = root:myGlobals:gAngstStr
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.