1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | Proc 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 | |
---|
15 | End |
---|
16 | |
---|
17 | Function/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 | // get the real-space model waves, if present |
---|
27 | if(cmpstr(filterStr,"x*")==0) |
---|
28 | list += WaveList("qBin*",";","") |
---|
29 | else |
---|
30 | list += WaveList("iBin*",";","") |
---|
31 | endif |
---|
32 | |
---|
33 | //add possble smeared models that are housed in data folders |
---|
34 | ControlInfo/W=WrapperPanel popup_0 |
---|
35 | if(V_flag==0 || cmpstr(S_Value,"No data loaded")==0) |
---|
36 | return(list) |
---|
37 | else |
---|
38 | DF="root:"+S_Value |
---|
39 | SetDataFolder $DF |
---|
40 | if(cmpstr(filterStr,"x*")==0) |
---|
41 | tmplist = WaveList("*_q",";","") |
---|
42 | tmpList += WaveList("GFitX_*",";","") |
---|
43 | else |
---|
44 | tmplist = WaveList("smea*",";","") |
---|
45 | tmpList += WaveList("GFit_*",";","") |
---|
46 | endif |
---|
47 | //prepend these list items with the folder |
---|
48 | num=itemsinlist(tmplist) |
---|
49 | if(num > 0) |
---|
50 | ii=0 |
---|
51 | do |
---|
52 | newList += DF+":"+StringFromList(ii, tmpList, ";") + ";" |
---|
53 | ii+=1 |
---|
54 | while(ii<num) |
---|
55 | |
---|
56 | //then add to the list |
---|
57 | list += newList |
---|
58 | endif |
---|
59 | endif |
---|
60 | |
---|
61 | SetDataFolder root: |
---|
62 | return(list) |
---|
63 | end |
---|
64 | |
---|
65 | // always asks for a file name |
---|
66 | Function fWriteModelData(xwave,ywave,delim,term) |
---|
67 | Wave xwave,ywave |
---|
68 | String delim,term |
---|
69 | |
---|
70 | String formatStr="",fullpath="" |
---|
71 | Variable refnum,dialog=1 |
---|
72 | |
---|
73 | //setup delimeter and terminator choices |
---|
74 | If(cmpstr(delim,"tab")==0) |
---|
75 | //tab-delimeted |
---|
76 | formatStr="%15.4g\t%15.4g" |
---|
77 | else |
---|
78 | //use 3 spaces |
---|
79 | formatStr="%15.4g %15.4g" |
---|
80 | Endif |
---|
81 | If(cmpstr(term,"CR")==0) |
---|
82 | formatStr += "\r" |
---|
83 | Endif |
---|
84 | If(cmpstr(term,"LF")==0) |
---|
85 | formatStr += "\n" |
---|
86 | Endif |
---|
87 | If(cmpstr(term,"CRLF")==0) |
---|
88 | formatStr += "\r\n" |
---|
89 | Endif |
---|
90 | |
---|
91 | if(dialog) |
---|
92 | PathInfo/S catPathName |
---|
93 | fullPath = DoSaveFileDialog("Save data as",fname=NameofWave(ywave)+".txt") |
---|
94 | If(cmpstr(fullPath,"")==0) |
---|
95 | //user cancel, don't write out a file |
---|
96 | Close/A |
---|
97 | Abort "no data file was written" |
---|
98 | Endif |
---|
99 | //Print "dialog fullpath = ",fullpath |
---|
100 | Endif |
---|
101 | |
---|
102 | Open refnum as fullpath |
---|
103 | |
---|
104 | fprintf refnum,"Model data created %s\r\n",(date()+" "+time()) |
---|
105 | wfprintf refnum,formatStr,xwave,ywave |
---|
106 | Close refnum |
---|
107 | return(0) |
---|
108 | End |
---|
109 | |
---|
110 | |
---|
111 | ///////////// |
---|
112 | Proc ReWrite1DData(folderStr,delim,term) |
---|
113 | String folderStr,delim,term |
---|
114 | Prompt folderStr,"Data Set",popup,W_DataSetPopupList() |
---|
115 | Prompt delim,"delimeter",popup,"tab;space;" |
---|
116 | Prompt term,"line termination",popup,"CR;LF;CRLF;" |
---|
117 | |
---|
118 | if (root:Packages:NIST:gXML_Write == 1) |
---|
119 | SetDataFolder root: |
---|
120 | ReWrite1DXMLData(folderStr) |
---|
121 | else |
---|
122 | SetDataFolder root: |
---|
123 | fReWrite1DData(folderStr,delim,term) |
---|
124 | endif |
---|
125 | End |
---|
126 | |
---|
127 | |
---|
128 | // always asks for a file name |
---|
129 | // - and right now, always expect 6-column data, either SANS or USANS (re-writes -dQv) |
---|
130 | // - AJJ Nov 2009 : better make sure we always fake 6 columns on reading then.... |
---|
131 | Function fReWrite1DData(folderStr,delim,term) |
---|
132 | String folderStr,delim,term |
---|
133 | |
---|
134 | String formatStr="",fullpath="" |
---|
135 | Variable refnum,dialog=1 |
---|
136 | |
---|
137 | String dataSetFolderParent,basestr |
---|
138 | |
---|
139 | //setup delimeter and terminator choices |
---|
140 | If(cmpstr(delim,"tab")==0) |
---|
141 | //tab-delimeted |
---|
142 | formatStr="%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g\t%15.8g" |
---|
143 | else |
---|
144 | //use 3 spaces |
---|
145 | formatStr="%15.8g %15.8g %15.8g %15.8g %15.8g %15.8g" |
---|
146 | Endif |
---|
147 | If(cmpstr(term,"CR")==0) |
---|
148 | formatStr += "\r" |
---|
149 | Endif |
---|
150 | If(cmpstr(term,"LF")==0) |
---|
151 | formatStr += "\n" |
---|
152 | Endif |
---|
153 | If(cmpstr(term,"CRLF")==0) |
---|
154 | formatStr += "\r\n" |
---|
155 | Endif |
---|
156 | |
---|
157 | //Abuse ParseFilePath to get path without folder name |
---|
158 | dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0) |
---|
159 | //Abuse ParseFilePath to get basestr |
---|
160 | basestr = ParseFilePath(0,folderStr,":",1,0) |
---|
161 | |
---|
162 | //make sure the waves exist |
---|
163 | SetDataFolder $(dataSetFolderParent+basestr) |
---|
164 | WAVE/Z qw = $(baseStr+"_q") |
---|
165 | WAVE/Z iw = $(baseStr+"_i") |
---|
166 | WAVE/Z sw = $(baseStr+"_s") |
---|
167 | WAVE/Z resw = $(baseStr+"_res") |
---|
168 | |
---|
169 | if(WaveExists(qw) == 0) |
---|
170 | Abort "q is missing" |
---|
171 | endif |
---|
172 | if(WaveExists(iw) == 0) |
---|
173 | Abort "i is missing" |
---|
174 | endif |
---|
175 | if(WaveExists(sw) == 0) |
---|
176 | Abort "s is missing" |
---|
177 | endif |
---|
178 | if(WaveExists(resw) == 0) |
---|
179 | Abort "Resolution information is missing." |
---|
180 | endif |
---|
181 | |
---|
182 | Duplicate/O qw qbar,sigQ,fs |
---|
183 | if(dimsize(resW,1) > 4) |
---|
184 | //it's USANS put -dQv back in the last 3 columns |
---|
185 | NVAR/Z dQv = USANS_dQv |
---|
186 | if(NVAR_Exists(dQv) == 0) |
---|
187 | SetDataFolder root: |
---|
188 | Abort "It's USANS data, and I don't know what the slit height is." |
---|
189 | endif |
---|
190 | sigQ = -dQv |
---|
191 | qbar = -dQv |
---|
192 | fs = -dQv |
---|
193 | else |
---|
194 | //it's SANS |
---|
195 | sigQ = resw[p][0] |
---|
196 | qbar = resw[p][1] |
---|
197 | fs = resw[p][2] |
---|
198 | endif |
---|
199 | |
---|
200 | if(dialog) |
---|
201 | PathInfo/S catPathName |
---|
202 | fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".txt") |
---|
203 | Print fullPath |
---|
204 | If(cmpstr(fullPath,"")==0) |
---|
205 | //user cancel, don't write out a file |
---|
206 | Close/A |
---|
207 | Abort "no data file was written" |
---|
208 | Endif |
---|
209 | //Print "dialog fullpath = ",fullpath |
---|
210 | Endif |
---|
211 | |
---|
212 | Open refnum as fullpath |
---|
213 | |
---|
214 | fprintf refnum,"Modified data written from folder %s on %s\r\n",baseStr,(date()+" "+time()) |
---|
215 | wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs |
---|
216 | Close refnum |
---|
217 | |
---|
218 | KillWaves/Z sigQ,qbar,fs |
---|
219 | |
---|
220 | SetDataFolder root: |
---|
221 | return(0) |
---|
222 | End |
---|