source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/WriteModelData_v40.ipf @ 1117

Last change on this file since 1117 was 873, checked in by srkline, 10 years ago

Adding procedures by Matt Wasbrough that allow the data and model fit to be rescaled to different axis scalings both for viewing and export. It is accessed through a check box on the wrapper panel and works on the top window, reascaling whatever is there. Works for a fit, must manually rescale for a coefficient change. Seems right now to be too much work forsetting a dependency.

Help file still needs to be written.

File size: 9.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
3
4Proc WriteModelData(xwave,ywave,delim,term)
5        String xwave,ywave,delim,term
6        Prompt xwave,"X data",popup,PossibleModelWaves("x*")
7        Prompt ywave,"Y data",popup,PossibleModelWaves("y*")
8        Prompt delim,"delimeter",popup,"tab;space;"
9        Prompt term,"line termination",popup,"CR;LF;CRLF;"
10
11        //Print xwave, ywave, delim, term
12       
13        fWriteModelData($xwave,$ywave,delim,term)
14       
15End
16
17
18// 10/22/2012 - MJW
19// Added suffixes ending in _q_RA, _qvals, _qvals_RA to list of possible x-waves to allow writing of rescaled model data
20// Added removal of qvals, _qvals_RA and _q_RA from the list of possible y-waves
21Function/S PossibleModelWaves(filterStr)
22        String filterStr
23       
24        String list,tmplist,tmplist2,DF,newList=""
25        Variable ii,num
26       
27        //waves in root
28        list = WaveList(filterStr,";","")
29       
30        // get the real-space model waves, if present
31        if(cmpstr(filterStr,"x*")==0)
32                list += WaveList("qBin*",";","")
33        else
34                list += WaveList("iBin*",";","")
35        endif
36       
37        //add possble smeared models that are housed in data folders
38        ControlInfo/W=WrapperPanel popup_0
39        if(V_flag==0 || cmpstr(S_Value,"No data loaded")==0)
40                return(list)
41        else
42                DF="root:"+S_Value
43                SetDataFolder $DF
44                if(cmpstr(filterStr,"x*")==0)
45                        tmplist = WaveList("*_q",";","")
46                        tmplist += WaveList("*_q_RA",";","")
47                        tmplist += WaveList("*_qvals",";","")
48                        tmplist += WaveList("*_qvals_RA",";","")
49                        tmpList += WaveList("GFitX_*",";","")
50                else
51                        tmplist = WaveList("smea*",";","")
52                        tmpList += WaveList("GFit_*",";","")
53                        tmplist2 = WaveList("*_qvals",";","")
54                        tmpList = RemoveFromList(tmplist2,tmplist,";")
55                        tmplist2 = WaveList("*_qvals_RA",";","")
56                        tmpList = RemoveFromList(tmplist2,tmplist,";")
57                        tmplist2 = WaveList("*_q_RA",";","")
58                        tmpList = RemoveFromList(tmplist2,tmplist,";")
59                endif
60                //prepend these list items with the folder
61                num=itemsinlist(tmplist)
62                if(num > 0)
63                        ii=0
64                        do
65                                newList += DF+":"+StringFromList(ii, tmpList, ";") + ";"
66                                ii+=1
67                        while(ii<num)
68                       
69                        //then add to the list
70                        list += newList
71                endif
72        endif
73       
74        SetDataFolder root:
75        return(list)
76end
77
78// always asks for a file name
79Function fWriteModelData(xwave,ywave,delim,term)
80        Wave xwave,ywave
81        String delim,term
82       
83        String formatStr="",fullpath=""
84        Variable refnum,dialog=1
85       
86        //setup delimeter and terminator choices
87        If(cmpstr(delim,"tab")==0)
88                //tab-delimeted
89                formatStr="%15.4g\t%15.4g"
90        else
91                //use 3 spaces
92                formatStr="%15.4g   %15.4g"
93        Endif
94        If(cmpstr(term,"CR")==0)
95                formatStr += "\r"
96        Endif
97        If(cmpstr(term,"LF")==0)
98                formatStr += "\n"
99        Endif
100        If(cmpstr(term,"CRLF")==0)
101                formatStr += "\r\n"
102        Endif
103       
104        if(dialog)
105                PathInfo/S catPathName
106                fullPath = DoSaveFileDialog("Save data as",fname=NameofWave(ywave)+".txt")
107                If(cmpstr(fullPath,"")==0)
108                        //user cancel, don't write out a file
109                        Close/A
110                        Abort "no data file was written"
111                Endif
112                //Print "dialog fullpath = ",fullpath
113        Endif
114       
115        Open refnum as fullpath
116       
117        fprintf refnum,"Model data created %s\r\n",(date()+" "+time())
118        wfprintf refnum,formatStr,xwave,ywave
119        Close refnum
120        return(0)
121End
122
123
124/////////////
125Proc ReWrite1DData(folderStr,delim,term)
126        String folderStr,delim,term
127        Prompt folderStr,"Data Set",popup,W_DataSetPopupList()
128        Prompt delim,"delimeter",popup,"tab;space;"
129        Prompt term,"line termination",popup,"CR;LF;CRLF;"
130       
131        if (root:Packages:NIST:gXML_Write == 1)
132                SetDataFolder root:
133                ReWrite1DXMLData(folderStr)
134        else
135                SetDataFolder root:
136                fReWrite1DData(folderStr,delim,term)
137        endif   
138End
139
140
141// always asks for a file name
142// - and right now, always expect 6-column data, either SANS or USANS (re-writes -dQv)
143// - AJJ Nov 2009 : better make sure we always fake 6 columns on reading then....
144Function fReWrite1DData(folderStr,delim,term)
145        String folderStr,delim,term
146       
147        String formatStr="",fullpath=""
148        Variable refnum,dialog=1
149       
150        String dataSetFolderParent,basestr
151       
152        //setup delimeter and terminator choices
153        If(cmpstr(delim,"tab")==0)
154                //tab-delimeted
155                formatStr="%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g"
156        else
157                //use 3 spaces
158                formatStr="%15.8g   %15.8g   %15.8g   %15.8g   %15.8g   %15.8g"
159        Endif
160        If(cmpstr(term,"CR")==0)
161                formatStr += "\r"
162        Endif
163        If(cmpstr(term,"LF")==0)
164                formatStr += "\n"
165        Endif
166        If(cmpstr(term,"CRLF")==0)
167                formatStr += "\r\n"
168        Endif
169       
170        //Abuse ParseFilePath to get path without folder name
171        dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
172        //Abuse ParseFilePath to get basestr
173        basestr = ParseFilePath(0,folderStr,":",1,0)
174       
175        //make sure the waves exist
176        SetDataFolder $(dataSetFolderParent+basestr)
177        WAVE/Z qw = $(baseStr+"_q")
178        WAVE/Z iw = $(baseStr+"_i")
179        WAVE/Z sw = $(baseStr+"_s")
180        WAVE/Z resw = $(baseStr+"_res")
181       
182        if(WaveExists(qw) == 0)
183                Abort "q is missing"
184        endif
185        if(WaveExists(iw) == 0)
186                Abort "i is missing"
187        endif
188        if(WaveExists(sw) == 0)
189                Abort "s is missing"
190        endif
191        if(WaveExists(resw) == 0)
192                Abort "Resolution information is missing."
193        endif
194       
195        Duplicate/O qw qbar,sigQ,fs
196        if(dimsize(resW,1) > 4)
197                //it's USANS put -dQv back in the last 3 columns
198                NVAR/Z dQv = USANS_dQv
199                if(NVAR_Exists(dQv) == 0)
200                        SetDataFolder root:
201                        Abort "It's USANS data, and I don't know what the slit height is."
202                endif
203                sigQ = -dQv
204                qbar = -dQv
205                fs = -dQv
206        else
207                //it's SANS
208                sigQ = resw[p][0]
209                qbar = resw[p][1]
210                fs = resw[p][2]
211        endif
212       
213        if(dialog)
214                PathInfo/S catPathName
215                fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".txt")
216                Print fullPath
217                If(cmpstr(fullPath,"")==0)
218                        //user cancel, don't write out a file
219                        Close/A
220                        Abort "no data file was written"
221                Endif
222                //Print "dialog fullpath = ",fullpath
223        Endif
224
225        Open refnum as fullpath
226       
227        fprintf refnum,"Modified data written from folder %s on %s\r\n",baseStr,(date()+" "+time())
228        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
229        Close refnum
230       
231        KillWaves/Z sigQ,qbar,fs
232       
233        SetDataFolder root:
234        return(0)
235End
236
237//MJW 24 Oct 2012
238//Included WriteRescaledData and fWriteRescaledData to write data from the RescaledAxis Panel.
239Function WriteRescaledData()
240
241        string xwavelist ="", ywavelist ="", swavelist="None"
242
243        SetDataFolder root:
244        String topGraph= WinName(0,1)   //this is the topmost graph
245                if(strlen(topGraph)==0)
246                Abort "There is no graph"
247        endif
248
249        DoWindow/F $topGraph
250        GetWindow/Z $topGraph, wavelist
251        wave/t W_Wavelist
252        SetDataFolder root:Packages:NIST:RescaleAxis
253        if (exists("W_WaveList")==1)
254                KillWaves/Z root:Packages:NIST:RescaleAxis:W_WaveList
255        endif
256        MoveWave root:W_WaveList, root:Packages:NIST:RescaleAxis:W_WaveList
257        SetDataFolder root:Packages:NIST:RescaleAxis
258
259        variable i
260        string temp
261        for(i=0; i < numpnts(W_Wavelist)/3; i+=1)
262                temp = W_Wavelist[i][0]
263                if(stringmatch(temp,"*_q") || stringmatch(temp,"*_q_RA") || stringmatch(temp,"*_qvals") || stringmatch(temp,"*_qvals_RA") || stringmatch(temp,"*xwave*"))
264                        if(strlen(xwavelist)==0)
265                                xwavelist = temp
266                        else
267                                xwavelist =xwavelist +";"+temp
268                        endif
269                elseif (stringmatch(temp, "*_i") || stringmatch(temp, "*_i_RA") || stringmatch(temp,"*FitYW*") || stringmatch(temp,"*ywave*") || stringmatch(temp,"*smeared*"))
270                        if(strlen(ywavelist)==0)
271                                ywavelist = temp
272                        else
273                                ywavelist =ywavelist +";"+temp
274                        endif
275                elseif (stringmatch(temp,"*_s") || stringmatch(temp,"*_s_RA"))
276                                swavelist =swavelist +";"+temp
277                endif
278        endfor
279
280        string xwave,ywave,swave,delim, term
281        Prompt ywave,"Y data",popup,ywavelist
282        Prompt xwave,"X data",popup,xwavelist
283        Prompt swave,"Error data",popup,swavelist
284        Prompt delim,"delimeter",popup,"tab;space;"
285        Prompt term,"line termination",popup,"CR;LF;CRLF;"
286        DoPrompt/help="" "Choose the Data to Save",ywave,xwave,swave,delim,term
287       
288        if(V_flag==1)
289                Abort "Cancel was clicked therefore no data was exported"
290        endif
291
292        print xwave, ywave, swave
293               
294        for(i=0; i < numpnts(W_Wavelist)/3; i+=1)
295                temp = W_Wavelist[i][0]
296                if(stringmatch(temp,ywave))
297                ywave = W_Wavelist[i][1]
298                elseif (stringmatch(temp, xwave))
299                xwave = W_Wavelist[i][1]
300                elseif (stringmatch(temp,swave))
301                swave = W_Wavelist[i][1]
302                endif
303        endfor
304       
305        fWriteRescaledData(xwave,ywave,swave,delim,term)
306End
307
308Function fWriteRescaledData(xwavestr,ywavestr,swavestr,delim,term)
309        String xwavestr,ywavestr,swavestr,delim,term
310       
311        SetDataFolder root:
312        wave xwave = $xwavestr
313        wave ywave = $ywavestr
314        wave swave = $swavestr
315        String formatStr="",fullpath=""
316        Variable refnum,dialog=1
317       
318        //setup delimeter and terminator choices
319        if(stringmatch(swavestr,"None"))
320                If(cmpstr(delim,"tab")==0)
321                        //tab-delimeted
322                        formatStr="%15.4g\t%15.4g"
323                else
324                        //use 3 spaces
325                        formatStr="%15.4g   %15.4g"
326                Endif
327        else
328                If(cmpstr(delim,"tab")==0)
329                        //tab-delimeted
330                        formatStr="%15.4g\t%15.4g\t%15.4g"
331                else
332                        //use 3 spaces
333                        formatStr="%15.4g   %15.4g   %15.4g"
334                Endif
335        Endif
336
337        If(cmpstr(term,"CR")==0)
338                formatStr += "\r"
339        Endif
340        If(cmpstr(term,"LF")==0)
341                formatStr += "\n"
342        Endif
343        If(cmpstr(term,"CRLF")==0)
344                formatStr += "\r\n"
345        Endif
346       
347        if(dialog)
348                PathInfo/S catPathName
349                fullPath = DoSaveFileDialog("Save data as",fname=NameofWave(ywave)+".txt")
350                If(cmpstr(fullPath,"")==0)
351                        //user cancel, don't write out a file
352                        Close/A
353                        Abort "no data file was written"
354                Endif
355                //Print "dialog fullpath = ",fullpath
356        Endif
357       
358        Open refnum as fullpath
359       
360        fprintf refnum,"Model data created %s\r\n",(date()+" "+time())
361        if(stringmatch(swavestr,"None"))
362                wfprintf refnum,formatStr,xwave,ywave
363        else
364                wfprintf refnum,formatStr,xwave,ywave,swave
365        endif
366        Close refnum
367        return(0)
368End
Note: See TracBrowser for help on using the repository browser.