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

Last change on this file since 477 was 477, checked in by srkline, 14 years ago

Added save/restore buttons to SimpleGlobal? fit to be able to restore the state of the checkboxes if possible. Checkboxes are reset when new data sets are selected.

Typos in SANSRedn help file have been corrected.

Error bar styles have been changed to /T=0, a vertical line with no horizontal bar. My preference - I got tired of seeing more of the horizontal bar than the actual data.

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