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

Last change on this file since 1247 was 1247, checked in by srkline, 2 years ago

more changes to panel scaling so that they are viewed properly on a small-screen laptop

File size: 10.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=4.00
3#pragma IgorVersion=6.1
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()
27
28        Variable sc = 1         //default
29        if(exists("root:Packages:NIST:VSANS:Globals:gLaptopMode")==2)   //NVAR does exist
30                if(root:Packages:NIST:VSANS:Globals:gLaptopMode == 1)   //then is the value 1
31                        sc = 0.7
32                endif
33        endif
34
35        PauseUpdate; Silent 1           // building window...
36        NewPanel /W=(658*sc,347*sc,1018*sc,737*sc)/N=Plot_Manager/K=2 as "Plot Manager"
37        ModifyPanel cbRGB=(37265,65535,32896)
38        ModifyPanel fixedSize=1
39       
40        Button button0,pos={sc*165,353*sc},size={sc*50,20*sc},proc=A_PlotManager_Done,title="Done"
41        PopupMenu popup0,pos={sc*15,225*sc},size={sc*233,20*sc},title="Data in Memory"
42        PopupMenu popup0,mode=1,value= #"A_OneDDataInMemory()"
43        Button button2,pos={sc*122,259*sc},size={sc*100,20*sc},proc=A_PlotManager_Append,title="Append Data"
44        Button button3,pos={sc*15,259*sc},size={sc*80,20*sc},proc=A_PlotManager_newGraph,title="New Graph"
45        Button button4,pos={sc*15,293*sc},size={sc*220,20*sc},proc=A_PlotManager_Kill,title="Remove Selection From Memory"
46        Button button5,pos={sc*15,323*sc},size={sc*220,20*sc},proc=A_PlotManager_KillAll,title="Remove All Data From Memory"
47        ListBox fileList,pos={sc*13,11*sc},size={sc*206,179*sc}
48        ListBox fileList,listWave=root:Packages:NIST:OneDLoader:fileWave
49        ListBox fileList,selWave=root:Packages:NIST:OneDLoader:selWave,mode= 4
50        Button button6,pos={sc*238,165*sc},size={sc*100,20*sc},proc=A_OneDLoader_LoadButton,title="Load File(s)"
51        Button button6,help={"Loads the selected files into memory and will graph them if that option is checked"}
52        Button button7,pos={sc*238,20*sc},size={sc*100,20*sc},proc=A_OneDLoader_NewFolderButton,title="New Folder"
53        Button button7,help={"Select a new data folder"}
54        Checkbox check0,pos={sc*240,190*sc},title="Plot data on loading?",noproc,value=1
55        GroupBox group0,pos={sc*222,127*sc},size={sc*50,4*sc},title="Shift-click to load"
56        GroupBox group0_1,pos={sc*222,143*sc},size={sc*50,4*sc},title="multiple files"
57        GroupBox group1,pos={sc*7,207*sc},size={sc*350,4*sc}
58        Button button8,pos={sc*238,76*sc},size={sc*100,20*sc},proc=A_OneDLoader_HelpButton,title="Help"
59        Button button9,pos={sc*238,48*sc},size={sc*100,20*sc},proc=A_PlotManager_Refresh,title="Refresh List"
60EndMacro
61
62//open the Help file for the Fit Manager
63Function A_OneDLoader_HelpButton(ba) : ButtonControl
64        STRUCT WMButtonAction &ba
65
66        switch( ba.eventCode )
67                case 2: // mouse up
68                        // click code here
69                        DisplayHelpTopic/K=1/Z "Plot Manager"
70                        if(V_flag !=0)
71                                DoAlert 0,"The Plot Manager Help file could not be found"
72                        endif
73                        break
74        endswitch
75
76        return 0
77End
78
79//uses the same data folder listing as the wrapper
80// if it's right there, it's right here
81Function/S A_OneDDataInMemory()
82        //AJJ Oct 2008
83        //To make this general for both analysis and reduction this code must be a duplicate
84        //W_DataPopupList rather than a call to it as IGOR doesn't like assignment to function
85        //that doesn't exists even if you've done a if(exists... to check first.
86        //Grrr
87        String list = GetAList(4)
88        if (strlen(list) == 0)
89                list = "No data loaded"
90        endif
91        list = SortList(list)
92       
93        return(list)
94end
95
96
97Function A_PlotManager_Done(ctrlName) : ButtonControl
98        String ctrlName
99        DoWindow/K Plot_Manager
100End
101
102Function A_PlotManager_Append(ctrlName) : ButtonControl
103        String ctrlName
104        //appends data set from memory
105       
106        //get the current selection
107        ControlInfo popup0
108        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
109                Abort "You must load data from a file into memory before appending the data"
110        Endif
111       
112        A_PM_doAppend(S_Value)
113       
114        DoWindow/F Plot_Manager
115End
116
117//actually does the appending
118//pass it the name of the wave, find the q-i-s waves
119Function A_PM_doAppend(DF)
120        String DF
121        //appends data set from memory
122        String qStr,eStr,istr
123        Variable rr,gg,bb
124       
125        if(cmpstr(WinList("*", ";","WIN:1"),"") == 0 )
126                DoAlert 0,"There are no open graphs. Please use the New Graph button"
127                return(0)
128        endif
129       
130        SetDataFolder $("root:"+DF)
131        //iStr will end in "i"
132        qStr = DF+"_q"
133        eStr = DF+"_s"
134        iStr = DF+"_i"
135       
136        rr = abs(trunc(enoise(65535)))
137        gg = abs(trunc(enoise(65535)))
138        bb = abs(trunc(enoise(65535)))
139       
140        // append to whatever is top-most graph
141        AppendToGraph $iStr vs $qStr
142        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb($iStr)=(rr,gg,bb)
143        ErrorBars/T=0 $iStr Y,wave=($eStr,$eStr)
144
145        SetDataFolder root:
146End
147
148Proc A_PlotManager_newGraph(ctrlName) : ButtonControl
149        String ctrlName
150       
151        //get the current selection
152        ControlInfo popup0
153        if(strlen(S_Value)==0 || cmpstr(S_Value,"No data loaded")==0)
154                Abort "You must load data from a file into memory before plotting the data"
155        Endif
156       
157        A_PM_doNewGraph(S_Value)
158        DoWindow/F Plot_Manager
159End
160
161Function A_PM_doNewGraph(DF)
162        String DF
163
164        String qStr,eStr,iStr
165        Variable rr,gg,bb
166       
167        SVAR/Z angst = root:Packages:NIST:gAngstStr
168       
169        SetDataFolder $("root:"+DF)
170        //iStr will end in "i"
171        qStr = DF+"_q"
172        eStr = DF+"_s"
173        iStr = DF+"_i"
174       
175        rr = abs(trunc(enoise(65535)))
176        gg = abs(trunc(enoise(65535)))
177        bb = abs(trunc(enoise(65535)))
178       
179        // always make a new graph
180        Display $iStr vs $qStr
181        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb=(rr,gg,bb)
182        ModifyGraph grid=1,mirror=2,standoff=0
183        ErrorBars/T=0 $iStr Y,wave=($eStr,$eStr)
184        ModifyGraph tickUnit=1
185                               
186        Label left "I(q)"
187//      Label bottom "q (A\\S-1\\M)"
188        Label bottom "q ("+angst+"\\S-1\\M)"   
189        Legend
190       
191        SetDataFolder root:
192End
193
194//kill the specified wave (if possible)
195Proc A_PlotManager_Kill(ctrlName) : ButtonControl
196        String ctrlName
197       
198        String savDF=GetDataFolder(1)
199        String DF
200
201        ControlInfo popup0
202        DF=S_Value              //this will end in "i"
203
204        SetDataFolder DF
205        KillVariables/A                 //removes the dependent variables
206        SetDataFolder savDF
207               
208        //now kill the data folder
209        KillDataFolder/Z $DF
210        ControlUpdate popup0            //refresh the popup, very important if last item removed
211End
212
213//kill the specified wave (if possible)
214Proc A_PlotManager_KillAll(ctrlName) : ButtonControl
215        String ctrlName
216       
217        String savDF=GetDataFolder(1)
218        String DF
219
220        String list =  A_OneDDataInMemory()
221        Variable num=ItemsInList(list),ii
222       
223        ii=0
224        do     
225                DF=StringFromList(ii, list  ,";")
226               
227                SetDataFolder DF
228                KillVariables/A                 //removes the dependent variables first
229                SetDataFolder savDF
230       
231                //now kill the data folder
232                KillDataFolder/Z $DF
233                ii+=1
234        while(ii<num)
235        ControlUpdate popup0            //refresh the popup, very important if all items are removed
236End
237
238Proc A_Init_OneDLoader()
239        //create the data folder
240        NewDataFolder/O/S root:Packages:NIST:OneDLoader
241        //create the waves
242        Make/O/T/N=1 fileWave=""
243        Make/O/N=1 selWave=0
244        Variable/G ind=0
245        SetDataFolder root:
246End
247
248
249//prompt for a new path, and get a new listing
250Function A_OneDLoader_NewFolderButton(ctrlName) : ButtonControl
251        String ctrlName
252
253        A_PickPath()
254        A_OneDLoader_GetListButton("")
255        return(0)
256End
257
258//refresh the listing
259Function A_PlotManager_Refresh(ctrlName) : ButtonControl
260        String ctrlName
261
262        A_OneDLoader_GetListButton("")
263        return(0)
264End
265
266//filters to remove only the files that are named like a raw data file, i.e. "*.SAn"
267//does not check to see if they really are RAW files though...(too tedious)
268Function A_OneDLoader_GetListButton(ctrlName) : ButtonControl
269        String ctrlName
270       
271        //make sure that path exists
272        PathInfo catPathName
273        if (V_flag == 0)
274                Abort "Folder path does not exist - use \"New Folder\" button on Main Panel"
275        Endif
276       
277        String newList = A_ReducedDataFileList("")
278        Variable num
279       
280        num=ItemsInList(newlist,";")
281        WAVE/T fileWave=$"root:Packages:NIST:OneDLoader:fileWave"
282        WAVE selWave=$"root:Packages:NIST:OneDLoader:selWave"
283        Redimension/N=(num) fileWave
284        Redimension/N=(num) selWave
285        fileWave = StringFromList(p,newlist,";")
286        Sort filewave,filewave
287End
288
289Function A_OneDLoader_LoadButton(ctrlName) : ButtonControl
290        String ctrlName
291       
292        //loop through the selected files in the list...
293        Wave/T fileWave=$"root:Packages:NIST:OneDLoader:fileWave"
294        Wave sel=$"root:Packages:NIST:OneDLoader:selWave"
295        Variable num=numpnts(sel),ii=0
296        String fname="",pathStr="",fullPath="",newFileName=""
297       
298        PathInfo catPathName                    //this is where the files are
299        pathStr=S_path
300       
301        Variable doGraph,cnt
302
303        ControlInfo check0
304        doGraph=V_Value
305        cnt=0
306        // get the current state
307        do
308                if(sel[ii] == 1)
309                        fname=pathStr + fileWave[ii]
310                        Execute "A_LoadOneDDataWithName(\""+fname+"\","+num2str(doGraph)+")"
311                        cnt += 1        //a file was loaded
312                endif
313                ii+=1
314        while(ii<num)
315
316        ControlUpdate/W=Plot_Manager popup0
317
318        return(0)
319End
320
321
322//function called by the popups to get a file list of data that can be sorted
323// this procedure simply removes the raw data files from the string - there
324//can be lots of other junk present, but this is very fast...
325//
326// could also use the alternate procedure of keeping only file with the proper extension
327//
328// another possibility is to get a listing of the text files, but is unreliable on
329// Windows, where the data file must be .txt (and possibly OSX)
330//
331// TODO: this is a duplicated procedure. See the equivalent in NCNR_Utils and which one to keep?
332Function/S A_ReducedDataFileList(ctrlName)
333        String ctrlName
334
335        String list="",newList="",item=""
336        Variable num,ii
337       
338        //check for the path
339        PathInfo catPathName
340        if(V_Flag==0)
341                DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel"
342                Return("")
343        Endif
344       
345        list = IndexedFile(catpathName,-1,"????")
346       
347        list = RemoveFromList(ListMatch(list,"*.SA1*",";"), list, ";", 0)
348        list = RemoveFromList(ListMatch(list,"*.SA2*",";"), list, ";", 0)
349        list = RemoveFromList(ListMatch(list,"*.SA3*",";"), list, ";", 0)
350        list = RemoveFromList(ListMatch(list,"*.SA4*",";"), list, ";", 0)               // added JAN 2013 for new guide hall
351        list = RemoveFromList(ListMatch(list,"*.SA5*",";"), list, ";", 0)
352        list = RemoveFromList(ListMatch(list,".*",";"), list, ";", 0)
353        list = RemoveFromList(ListMatch(list,"*.pxp",";"), list, ";", 0)
354        list = RemoveFromList(ListMatch(list,"*.DIV",";"), list, ";", 0)
355        list = RemoveFromList(ListMatch(list,"*.GSP",";"), list, ";", 0)
356        list = RemoveFromList(ListMatch(list,"*.MASK",";"), list, ";", 0)
357#if(exists("QUOKKA") == 6)
358        list = RemoveFromList(ListMatch(list,"*.nx.hdf",";"), list, ";", 0)     
359        list = RemoveFromList(ListMatch(list,"*.bin",";"), list, ";", 0)       
360#endif
361       
362
363        //sort
364        newList = SortList(List,";",0)
365
366        return newlist
367End
Note: See TracBrowser for help on using the repository browser.