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

Last change on this file since 573 was 570, checked in by srkline, 13 years ago

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

File size: 4.5 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        fReWrite1DData(folderStr,delim,term)
112       
113End
114
115
116// always asks for a file name
117// - and right now, always expect 6-column data, either SANS or USANS (re-writes -dQv)
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.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g"
128        else
129                //use 3 spaces
130                formatStr="%15.8g   %15.8g   %15.8g   %15.8g   %15.8g   %15.8g"
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        if(dimsize(resW,1) > 4)
164                //it's USANS put -dQv back in the last 3 columns
165                NVAR/Z dQv = USANS_dQv
166                if(NVAR_Exists(dQv) == 0)
167                        Abort "It's USANS data, and I don't know what the slit height is."
168                endif
169                sigQ = -dQv
170                qbar = -dQv
171                fs = -dQv
172        else
173                //it's SANS
174                sigQ = resw[p][0]
175                qbar = resw[p][1]
176                fs = resw[p][2]
177        endif
178       
179        if(dialog)
180                PathInfo/S catPathName
181                fullPath = DoSaveFileDialog("Save data as",fname=folderStr+".txt")
182                If(cmpstr(fullPath,"")==0)
183                        //user cancel, don't write out a file
184                        Close/A
185                        Abort "no data file was written"
186                Endif
187                //Print "dialog fullpath = ",fullpath
188        Endif
189       
190        Open refnum as fullpath
191       
192        fprintf refnum,"Modified data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
193        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
194        Close refnum
195       
196        KillWaves/Z sigQ,qbar,fs
197       
198        SetDataFolder root:
199        return(0)
200End
Note: See TracBrowser for help on using the repository browser.