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

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

Added feature to re-save 1-d data from its data folder, presumably after someone has modified it by say, manually subtracting background or rescaling. (Danilo, ticket #156). There is now a SANS Models menu item for this, rather clumsily na,ed. Changes were put into WriteModelData_v40.ipf.

Currently only handles 6-column datasets. Logic for others would be straightforward if needed.

File size: 4.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
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
17Function/S PossibleModelWaves(filterStr)
18        String filterStr
19       
20        String list,tmplist,DF,newList=""
21        Variable ii,num
22       
23        //waves in root
24        list = WaveList(filterStr,";","")
25       
26        //add possble smeared models that are housed in data folders
27        ControlInfo/W=WrapperPanel popup_0
28        if(V_flag==0 || cmpstr(S_Value,"No data loaded")==0)
29                return(list)
30        else
31                DF="root:"+S_Value
32                SetDataFolder $DF
33                if(cmpstr(filterStr,"x*")==0)
34                        tmplist = WaveList("*_q",";","")
35                        tmpList += WaveList("GFitX_*",";","")
36                else
37                        tmplist = WaveList("smea*",";","")
38                        tmpList += WaveList("GFit_*",";","")
39                endif
40                //prepend these list items with the folder
41                num=itemsinlist(tmplist)
42                if(num > 0)
43                        ii=0
44                        do
45                                newList += DF+":"+StringFromList(ii, tmpList, ";") + ";"
46                                ii+=1
47                        while(ii<num)
48                       
49                        //then add to the list
50                        list += newList
51                endif
52        endif
53       
54        SetDataFolder root:
55        return(list)
56end
57
58// always asks for a file name
59Function fWriteModelData(xwave,ywave,delim,term)
60        Wave xwave,ywave
61        String delim,term
62       
63        String formatStr="",fullpath=""
64        Variable refnum,dialog=1
65       
66        //setup delimeter and terminator choices
67        If(cmpstr(delim,"tab")==0)
68                //tab-delimeted
69                formatStr="%15.4g\t%15.4g"
70        else
71                //use 3 spaces
72                formatStr="%15.4g   %15.4g"
73        Endif
74        If(cmpstr(term,"CR")==0)
75                formatStr += "\r"
76        Endif
77        If(cmpstr(term,"LF")==0)
78                formatStr += "\n"
79        Endif
80        If(cmpstr(term,"CRLF")==0)
81                formatStr += "\r\n"
82        Endif
83       
84        if(dialog)
85                PathInfo/S catPathName
86                fullPath = DoSaveFileDialog("Save data as",fname=NameofWave(ywave)+".txt")
87                If(cmpstr(fullPath,"")==0)
88                        //user cancel, don't write out a file
89                        Close/A
90                        Abort "no data file was written"
91                Endif
92                //Print "dialog fullpath = ",fullpath
93        Endif
94       
95        Open refnum as fullpath
96       
97        fprintf refnum,"Model data created %s\r\n",(date()+" "+time())
98        wfprintf refnum,formatStr,xwave,ywave
99        Close refnum
100        return(0)
101End
102
103
104/////////////
105Proc ReWrite1DData(folderStr,delim,term)
106        String folderStr,delim,term
107        Prompt folderStr,"Data Set",popup,W_DataSetPopupList()
108        Prompt delim,"delimeter",popup,"tab;space;"
109        Prompt term,"line termination",popup,"CR;LF;CRLF;"
110               
111        fReWrite1DData(folderStr,delim,term)
112       
113End
114
115
116// always asks for a file name
117// - and right now, always expect 6-column data!
118Function fReWrite1DData(folderStr,delim,term)
119        String folderStr,delim,term
120       
121        String formatStr="",fullpath=""
122        Variable refnum,dialog=1
123       
124        //setup delimeter and terminator choices
125        If(cmpstr(delim,"tab")==0)
126                //tab-delimeted
127                formatStr="%15.4g\t%15.4g\t%15.4g\t%15.4g\t%15.4g\t%15.4g"
128        else
129                //use 3 spaces
130                formatStr="%15.4g   %15.4g   %15.4g   %15.4g   %15.4g   %15.4g"
131        Endif
132        If(cmpstr(term,"CR")==0)
133                formatStr += "\r"
134        Endif
135        If(cmpstr(term,"LF")==0)
136                formatStr += "\n"
137        Endif
138        If(cmpstr(term,"CRLF")==0)
139                formatStr += "\r\n"
140        Endif
141       
142        //make sure the waves exist
143        SetDataFolder $("root:"+folderStr)
144        WAVE/Z qw = $(folderStr+"_q")
145        WAVE/Z iw = $(folderStr+"_i")
146        WAVE/Z sw = $(folderStr+"_s")
147        WAVE/Z resw = $(folderStr+"_res")
148       
149        if(WaveExists(qw) == 0)
150                Abort "q is missing"
151        endif
152        if(WaveExists(iw) == 0)
153                Abort "i is missing"
154        endif
155        if(WaveExists(sw) == 0)
156                Abort "s is missing"
157        endif
158        if(WaveExists(resw) == 0)
159                Abort "Resolution information is missing."
160        endif
161       
162        Duplicate/O qw qbar,sigQ,fs
163        sigQ = resw[p][0]
164        qbar = resw[p][1]
165        fs = resw[p][2]
166       
167        if(dialog)
168                PathInfo/S catPathName
169                fullPath = DoSaveFileDialog("Save data as",fname=folderStr+".txt")
170                If(cmpstr(fullPath,"")==0)
171                        //user cancel, don't write out a file
172                        Close/A
173                        Abort "no data file was written"
174                Endif
175                //Print "dialog fullpath = ",fullpath
176        Endif
177       
178        Open refnum as fullpath
179       
180        fprintf refnum,"Modified data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
181        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
182        Close refnum
183       
184        KillWaves/Z sigQ,qbar,fs
185       
186        SetDataFolder root:
187        return(0)
188End
Note: See TracBrowser for help on using the repository browser.