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

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

Various ANSTO related fixes.

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