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 | //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) |
---|
56 | end |
---|
57 | |
---|
58 | // always asks for a file name |
---|
59 | Function 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) |
---|
101 | End |
---|
102 | |
---|
103 | |
---|
104 | ///////////// |
---|
105 | Proc 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 |
---|
118 | End |
---|
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.... |
---|
124 | Function 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 | Abort "It's USANS data, and I don't know what the slit height is." |
---|
181 | endif |
---|
182 | sigQ = -dQv |
---|
183 | qbar = -dQv |
---|
184 | fs = -dQv |
---|
185 | else |
---|
186 | //it's SANS |
---|
187 | sigQ = resw[p][0] |
---|
188 | qbar = resw[p][1] |
---|
189 | fs = resw[p][2] |
---|
190 | endif |
---|
191 | |
---|
192 | if(dialog) |
---|
193 | PathInfo/S catPathName |
---|
194 | fullPath = DoSaveFileDialog("Save data as",fname=baseStr+".txt") |
---|
195 | Print fullPath |
---|
196 | If(cmpstr(fullPath,"")==0) |
---|
197 | //user cancel, don't write out a file |
---|
198 | Close/A |
---|
199 | Abort "no data file was written" |
---|
200 | Endif |
---|
201 | //Print "dialog fullpath = ",fullpath |
---|
202 | Endif |
---|
203 | |
---|
204 | Open refnum as fullpath |
---|
205 | |
---|
206 | fprintf refnum,"Modified data written from folder %s on %s\r\n",baseStr,(date()+" "+time()) |
---|
207 | wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs |
---|
208 | Close refnum |
---|
209 | |
---|
210 | KillWaves/Z sigQ,qbar,fs |
---|
211 | |
---|
212 | SetDataFolder root: |
---|
213 | return(0) |
---|
214 | End |
---|