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

Last change on this file since 838 was 734, checked in by srkline, 12 years ago

Fixed bug in maunUSANS panel where clicking in white space in the file list threw up an open file dialog.

ticket #292: 1D arithmetic panel now properly writes out USANS data, switching to fill in the USANS fields if the USANS_dQv variable is found. Otherwise it is treated as SANS data.

File size: 5.0 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
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        if (root:Packages:NIST:gXML_Write == 1)
112                SetDataFolder root:
113                ReWrite1DXMLData(folderStr)
114        else
115                SetDataFolder root:
116                fReWrite1DData(folderStr,delim,term)
117        endif   
118End
119
120
121// always asks for a file name
122// - and right now, always expect 6-column data, either SANS or USANS (re-writes -dQv)
123// - AJJ Nov 2009 : better make sure we always fake 6 columns on reading then....
124Function fReWrite1DData(folderStr,delim,term)
125        String folderStr,delim,term
126       
127        String formatStr="",fullpath=""
128        Variable refnum,dialog=1
129       
130        String dataSetFolderParent,basestr
131       
132        //setup delimeter and terminator choices
133        If(cmpstr(delim,"tab")==0)
134                //tab-delimeted
135                formatStr="%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g"
136        else
137                //use 3 spaces
138                formatStr="%15.8g   %15.8g   %15.8g   %15.8g   %15.8g   %15.8g"
139        Endif
140        If(cmpstr(term,"CR")==0)
141                formatStr += "\r"
142        Endif
143        If(cmpstr(term,"LF")==0)
144                formatStr += "\n"
145        Endif
146        If(cmpstr(term,"CRLF")==0)
147                formatStr += "\r\n"
148        Endif
149       
150        //Abuse ParseFilePath to get path without folder name
151        dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
152        //Abuse ParseFilePath to get basestr
153        basestr = ParseFilePath(0,folderStr,":",1,0)
154       
155        //make sure the waves exist
156        SetDataFolder $(dataSetFolderParent+basestr)
157        WAVE/Z qw = $(baseStr+"_q")
158        WAVE/Z iw = $(baseStr+"_i")
159        WAVE/Z sw = $(baseStr+"_s")
160        WAVE/Z resw = $(baseStr+"_res")
161       
162        if(WaveExists(qw) == 0)
163                Abort "q is missing"
164        endif
165        if(WaveExists(iw) == 0)
166                Abort "i is missing"
167        endif
168        if(WaveExists(sw) == 0)
169                Abort "s is missing"
170        endif
171        if(WaveExists(resw) == 0)
172                Abort "Resolution information is missing."
173        endif
174       
175        Duplicate/O qw qbar,sigQ,fs
176        if(dimsize(resW,1) > 4)
177                //it's USANS put -dQv back in the last 3 columns
178                NVAR/Z dQv = USANS_dQv
179                if(NVAR_Exists(dQv) == 0)
180                        SetDataFolder root:
181                        Abort "It's USANS data, and I don't know what the slit height is."
182                endif
183                sigQ = -dQv
184                qbar = -dQv
185                fs = -dQv
186        else
187                //it's SANS
188                sigQ = resw[p][0]
189                qbar = resw[p][1]
190                fs = resw[p][2]
191        endif
192       
193        if(dialog)
194                PathInfo/S catPathName
195                fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".txt")
196                Print fullPath
197                If(cmpstr(fullPath,"")==0)
198                        //user cancel, don't write out a file
199                        Close/A
200                        Abort "no data file was written"
201                Endif
202                //Print "dialog fullpath = ",fullpath
203        Endif
204
205        Open refnum as fullpath
206       
207        fprintf refnum,"Modified data written from folder %s on %s\r\n",baseStr,(date()+" "+time())
208        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
209        Close refnum
210       
211        KillWaves/Z sigQ,qbar,fs
212       
213        SetDataFolder root:
214        return(0)
215End
Note: See TracBrowser for help on using the repository browser.