source: sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/PlotManager/PlotManager_v40.ipf @ 414

Last change on this file since 414 was 414, checked in by ajj, 14 years ago

Commonizing plotmanager

File size: 8.8 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=4.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:Packages:NIST:OneDLoader:fileWave
41        ListBox fileList,selWave=root:Packages:NIST: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}
49        Button button8,pos={238,50},size={100,20},proc=A_OneDLoader_HelpButton,title="Help"
50EndMacro
51
52//open the Help file for the Fit Manager
53Function A_OneDLoader_HelpButton(ba) : ButtonControl
54        STRUCT WMButtonAction &ba
55
56        switch( ba.eventCode )
57                case 2: // mouse up
58                        // click code here
59                        DisplayHelpTopic/K=1/Z "Plot Manager"
60                        if(V_flag !=0)
61                                DoAlert 0,"The Plot Manager Help file could not be found"
62                        endif
63                        break
64        endswitch
65
66        return 0
67End
68
69//uses the same data folder listing as the wrapper
70// if it's right there, it's right here
71Function/S A_OneDDataInMemory()
72        String list = W_DataSetPopupList()
73        return(list)
74end
75
76
77Function A_PlotManager_Done(ctrlName) : ButtonControl
78        String ctrlName
79        DoWindow/K Plot_Manager
80End
81
82Function A_PlotManager_Append(ctrlName) : ButtonControl
83        String ctrlName
84        //appends data set from memory
85       
86        //get the current selection
87        ControlInfo popup0
88        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
89                Abort "You must load data from a file into memory before appending the data"
90        Endif
91       
92        A_PM_doAppend(S_Value)
93       
94        DoWindow/F Plot_Manager
95End
96
97//actually does the appending
98//pass it the name of the wave, find the q-i-s waves
99Function A_PM_doAppend(DF)
100        String DF
101        //appends data set from memory
102        String qStr,eStr,istr
103        Variable rr,gg,bb
104       
105        if(cmpstr(WinList("*", ";","WIN:1"),"") == 0 )
106                DoAlert 0,"There are no open graphs. Please use the New Graph button"
107                return(0)
108        endif
109       
110        SetDataFolder $("root:"+DF)
111        //iStr will end in "i"
112        qStr = DF+"_q"
113        eStr = DF+"_s"
114        iStr = DF+"_i"
115       
116        rr = abs(trunc(enoise(65535)))
117        gg = abs(trunc(enoise(65535)))
118        bb = abs(trunc(enoise(65535)))
119       
120        // append to whatever is top-most graph
121        AppendToGraph $iStr vs $qStr
122        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb($iStr)=(rr,gg,bb)
123        ErrorBars $iStr Y,wave=($eStr,$eStr)
124
125        SetDataFolder root:
126End
127
128Proc A_PlotManager_newGraph(ctrlName) : ButtonControl
129        String ctrlName
130       
131        //get the current selection
132        ControlInfo popup0
133        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
134                Abort "You must load data from a file into memory before plotting the data"
135        Endif
136       
137        A_PM_doNewGraph(S_Value)
138        DoWindow/F Plot_Manager
139End
140
141Function A_PM_doNewGraph(DF)
142        String DF
143
144        String qStr,eStr,iStr
145        Variable rr,gg,bb
146       
147        SetDataFolder $("root:"+DF)
148        //iStr will end in "i"
149        qStr = DF+"_q"
150        eStr = DF+"_s"
151        iStr = DF+"_i"
152       
153        rr = abs(trunc(enoise(65535)))
154        gg = abs(trunc(enoise(65535)))
155        bb = abs(trunc(enoise(65535)))
156       
157        // always make a new graph
158        Display $iStr vs $qStr
159        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb=(rr,gg,bb)
160        ModifyGraph grid=1,mirror=2,standoff=0
161        ErrorBars $iStr Y,wave=($eStr,$eStr)
162        ModifyGraph tickUnit=1
163                               
164        Label left "I(q)"
165        Label bottom "q (A\\S-1\\M)"
166       
167        Legend
168       
169        SetDataFolder root:
170End
171
172//kill the specified wave (if possible)
173Proc A_PlotManager_Kill(ctrlName) : ButtonControl
174        String ctrlName
175       
176        String savDF=GetDataFolder(1)
177        String DF
178
179        ControlInfo popup0
180        DF=S_Value              //this will end in "i"
181
182        SetDataFolder DF
183        KillVariables/A                 //removes the dependent variables
184        SetDataFolder savDF
185       
186        //now kill the data folder
187        KillDataFolder/Z $DF
188        ControlUpdate popup0            //refresh the popup, very important if last item removed
189End
190
191//kill the specified wave (if possible)
192Proc A_PlotManager_KillAll(ctrlName) : ButtonControl
193        String ctrlName
194       
195        String savDF=GetDataFolder(1)
196        String DF
197
198        String list =  A_OneDDataInMemory()
199        Variable num=ItemsInList(list),ii
200       
201        ii=0
202        do     
203                DF=StringFromList(ii, list  ,";")
204               
205                SetDataFolder DF
206                KillVariables/A                 //removes the dependent variables first
207                SetDataFolder savDF
208       
209                //now kill the data folder
210                KillDataFolder/Z $DF
211                ii+=1
212        while(ii<num)
213        ControlUpdate popup0            //refresh the popup, very important if all items are removed
214End
215
216Proc A_Init_OneDLoader()
217        //create the data folder
218        NewDataFolder/O/S root:Packages:NIST:OneDLoader
219        //create the waves
220        Make/O/T/N=1 fileWave=""
221        Make/O/N=1 selWave=0
222        Variable/G ind=0
223        SetDataFolder root:
224End
225
226
227//prompt for a new path, and get a new listing
228Function A_OneDLoader_NewFolderButton(ctrlName) : ButtonControl
229        String ctrlName
230
231        A_PickPath()
232        A_OneDLoader_GetListButton("")
233        return(0)
234End
235
236//filters to remove only the files that are named like a raw data file, i.e. "*.SAn"
237//does not check to see if they really are RAW files though...(too tedious)
238Function A_OneDLoader_GetListButton(ctrlName) : ButtonControl
239        String ctrlName
240       
241        //make sure that path exists
242        PathInfo catPathName
243        if (V_flag == 0)
244                Abort "Folder path does not exist - use \"New Folder\" button on Main Panel"
245        Endif
246       
247        String newList = A_ReducedDataFileList("")
248        Variable num
249       
250        num=ItemsInList(newlist,";")
251        WAVE/T fileWave=$"root:Packages:NIST:OneDLoader:fileWave"
252        WAVE selWave=$"root:Packages:NIST:OneDLoader:selWave"
253        Redimension/N=(num) fileWave
254        Redimension/N=(num) selWave
255        fileWave = StringFromList(p,newlist,";")
256        Sort filewave,filewave
257End
258
259Function A_OneDLoader_LoadButton(ctrlName) : ButtonControl
260        String ctrlName
261       
262        //loop through the selected files in the list...
263        Wave/T fileWave=$"root:Packages:NIST:OneDLoader:fileWave"
264        Wave sel=$"root:Packages:NIST:OneDLoader:selWave"
265        Variable num=numpnts(sel),ii=0
266        String fname="",pathStr="",fullPath="",newFileName=""
267       
268        PathInfo catPathName                    //this is where the files are
269        pathStr=S_path
270       
271        Variable doGraph,cnt
272
273        ControlInfo check0
274        doGraph=V_Value
275        cnt=0
276        // get the current state
277        do
278                if(sel[ii] == 1)
279                        fname=pathStr + fileWave[ii]
280                        Execute "A_LoadOneDDataWithName(\""+fname+"\",1)"
281                        cnt += 1        //a file was loaded
282                endif
283                ii+=1
284        while(ii<num)
285
286        return(0)
287End
288
289
290//function called by the popups to get a file list of data that can be sorted
291// this procedure simply removes the raw data files from the string - there
292//can be lots of other junk present, but this is very fast...
293//
294// could also use the alternate procedure of keeping only file with the proper extension
295//
296// another possibility is to get a listing of the text files, but is unreliable on
297// Windows, where the data file must be .txt (and possibly OSX)
298//
299Function/S A_ReducedDataFileList(ctrlName)
300        String ctrlName
301
302        String list="",newList="",item=""
303        Variable num,ii
304       
305        //check for the path
306        PathInfo catPathName
307        if(V_Flag==0)
308                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
309                Return("")
310        Endif
311       
312        list = IndexedFile(catpathName,-1,"????")
313        num=ItemsInList(list,";")
314        //print "num = ",num
315        for(ii=(num-1);ii>=0;ii-=1)
316                item = StringFromList(ii, list  ,";")
317                //simply remove all that are not raw data files (SA1 SA2 SA3)
318                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
319                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
320                                newlist += item + ";"
321                        endif
322                endif
323        endfor
324        //sort
325        newList = SortList(newList,";",0)
326
327        return newlist
328End
Note: See TracBrowser for help on using the repository browser.