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

Last change on this file since 744 was 744, checked in by ajj, 12 years ago

Put back the check box in PlotManager? to choose whether or not to plot on load.

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