1 | #pragma TextEncoding = "MacRoman" |
---|
2 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
3 | |
---|
4 | |
---|
5 | // functions to calculate attenuator values from the tables |
---|
6 | // |
---|
7 | // V_CalculateAttenuationFactor(fname) |
---|
8 | // V_CalculateAttenuationError(fname) |
---|
9 | // |
---|
10 | // interpolate if necessary |
---|
11 | |
---|
12 | |
---|
13 | // |
---|
14 | // patch entire tables if necessary |
---|
15 | // |
---|
16 | // |
---|
17 | // |
---|
18 | |
---|
19 | |
---|
20 | // attenuator tables are currently /N=(8,17) |
---|
21 | |
---|
22 | |
---|
23 | Proc V_LoadCSVAttenTable() |
---|
24 | |
---|
25 | // this load command will: |
---|
26 | // load CSV data into a matrix |
---|
27 | // skip a one-line header |
---|
28 | // name it "atten0" |
---|
29 | // prompt for file |
---|
30 | LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0} //will prompt for the file, auto name |
---|
31 | |
---|
32 | Rename atten0, atten_values |
---|
33 | |
---|
34 | End |
---|
35 | |
---|
36 | Proc V_LoadCSVAttenErrTable() |
---|
37 | |
---|
38 | // this load command will: |
---|
39 | // load CSV data into a matrix |
---|
40 | // skip a one-line header |
---|
41 | // name it "atten0" |
---|
42 | // prompt for file |
---|
43 | LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0} //will prompt for the file, auto name |
---|
44 | |
---|
45 | Rename atten0, atten_err |
---|
46 | |
---|
47 | End |
---|
48 | |
---|
49 | // V_writeAttenIndex_table(fname,inW) |
---|
50 | // |
---|
51 | // V_writeAttenIndex_table_err(fname,inW) |
---|
52 | // |
---|
53 | |
---|
54 | Proc V_WriteCSVAttenTable(lo,hi,atten_values) |
---|
55 | Variable lo,hi |
---|
56 | String atten_values |
---|
57 | |
---|
58 | V_fPatchAttenValueTable(lo,hi,$atten_values) |
---|
59 | End |
---|
60 | |
---|
61 | Proc V_WriteCSVAttenErrTable(lo,hi,atten_err) |
---|
62 | Variable lo,hi |
---|
63 | String atten_err |
---|
64 | |
---|
65 | V_fPatchAttenErrTable(lo,hi,$atten_err) |
---|
66 | End |
---|
67 | |
---|
68 | |
---|
69 | // simple utility to patch the attenuator table wave in the file headers |
---|
70 | // lo is the first file number |
---|
71 | // hi is the last file number (inclusive) |
---|
72 | // |
---|
73 | Function V_fPatchAttenValueTable(lo,hi,attenW) |
---|
74 | Variable lo,hi |
---|
75 | Wave attenW |
---|
76 | |
---|
77 | Variable ii |
---|
78 | String fname |
---|
79 | |
---|
80 | // check the dimensions of the attenW (8,17) |
---|
81 | if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 ) |
---|
82 | Abort "attenuator wave is not of proper dimension (8,17)" |
---|
83 | endif |
---|
84 | |
---|
85 | //loop over all files |
---|
86 | for(ii=lo;ii<=hi;ii+=1) |
---|
87 | fname = V_FindFileFromRunNumber(ii) |
---|
88 | if(strlen(fname) != 0) |
---|
89 | V_writeAttenIndex_table(fname,attenW) |
---|
90 | else |
---|
91 | printf "run number %d not found\r",ii |
---|
92 | endif |
---|
93 | endfor |
---|
94 | |
---|
95 | return(0) |
---|
96 | End |
---|
97 | |
---|
98 | // simple utility to patch the attenuator error (std dev) wave in the file headers |
---|
99 | // lo is the first file number |
---|
100 | // hi is the last file number (inclusive) |
---|
101 | // |
---|
102 | Function V_fPatchAttenErrTable(lo,hi,attenW) |
---|
103 | Variable lo,hi |
---|
104 | Wave attenW |
---|
105 | |
---|
106 | Variable ii |
---|
107 | String fname |
---|
108 | |
---|
109 | // check the dimensions of the attenW (8,17) |
---|
110 | if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 ) |
---|
111 | Abort "attenuator wave is not of proper dimension (8,17)" |
---|
112 | endif |
---|
113 | |
---|
114 | //loop over all files |
---|
115 | for(ii=lo;ii<=hi;ii+=1) |
---|
116 | fname = V_FindFileFromRunNumber(ii) |
---|
117 | if(strlen(fname) != 0) |
---|
118 | V_writeAttenIndex_table_err(fname,attenW) |
---|
119 | else |
---|
120 | printf "run number %d not found\r",ii |
---|
121 | endif |
---|
122 | endfor |
---|
123 | |
---|
124 | return(0) |
---|
125 | End |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | ////////////////////// |
---|
130 | // |
---|
131 | // function to calculate the attenuation factor from the table in the file |
---|
132 | // |
---|
133 | // fill in a "dummy" wavelength for White Beam and graphite |
---|
134 | // == 100 for White Beam |
---|
135 | // == 1000 for graphite |
---|
136 | // use these dummy values just for the lookup table |
---|
137 | // |
---|
138 | // TODO -- need the enumerated values for the monochromator type |
---|
139 | // TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE |
---|
140 | // |
---|
141 | // |
---|
142 | Function V_CalculateAttenuationFactor(fname) |
---|
143 | String fname |
---|
144 | |
---|
145 | Variable val,lambda,numAtt |
---|
146 | String monoType |
---|
147 | |
---|
148 | numAtt = V_getAtten_number(fname) |
---|
149 | lambda = V_getWavelength(fname) |
---|
150 | |
---|
151 | // TODO -- need to switch on "type" |
---|
152 | // == velocity_selector || ?? for white beam || graphite |
---|
153 | // monoType = V_getMonochromatorType(fname) |
---|
154 | |
---|
155 | monoType = V_DeduceMonochromatorType(fname) |
---|
156 | print monoType |
---|
157 | |
---|
158 | // set a fake wavelength for the interpolation or get out |
---|
159 | strswitch(monoType) // string switch |
---|
160 | case "velocity_selector": // execute if case matches expression |
---|
161 | // use lambda as-is |
---|
162 | break // exit from switch |
---|
163 | case "white_beam": // execute if case matches expression |
---|
164 | lambda = 100 |
---|
165 | break |
---|
166 | case "crystal": |
---|
167 | lambda = 1000 |
---|
168 | break |
---|
169 | default: // optional default expression executed |
---|
170 | Abort "Monochromator type could not be determined in V_CalculateAttenuationFactor" // when no case matches |
---|
171 | endswitch |
---|
172 | |
---|
173 | |
---|
174 | Wave w = V_getAttenIndex_table(fname) // N=(8,17) |
---|
175 | Make/O/D/N=8 tmpVal,tmpLam |
---|
176 | |
---|
177 | tmpVal = w[p][numAtt+1] // offset by one, 1st column is wavelength |
---|
178 | tmpLam = w[p][0] |
---|
179 | val = interp(lambda, tmpLam, tmpVal ) |
---|
180 | |
---|
181 | //killwaves/Z tmpVal,tmpLam |
---|
182 | return(val) |
---|
183 | |
---|
184 | End |
---|
185 | |
---|
186 | ////////////////////// |
---|
187 | // |
---|
188 | // function to calculate the attenuation error from the table in the file |
---|
189 | // |
---|
190 | // fill in a "dummy" wavelength for White Beam and graphite |
---|
191 | // == 100 for White Beam |
---|
192 | // == 1000 for graphite |
---|
193 | // use these dummy values just for the lookup table |
---|
194 | // |
---|
195 | // TODO -- need the enumerated values for the monochromator type |
---|
196 | // TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE |
---|
197 | // |
---|
198 | Function V_CalculateAttenuationError(fname) |
---|
199 | String fname |
---|
200 | |
---|
201 | Variable val,lambda,numAtt |
---|
202 | String monoType |
---|
203 | |
---|
204 | numAtt = V_getAtten_number(fname) |
---|
205 | lambda = V_getWavelength(fname) |
---|
206 | |
---|
207 | // TODO -- need to switch on "type" |
---|
208 | // == velocity_selector || ?? for white beam || graphite |
---|
209 | // monoType = V_getMonochromatorType(fname) |
---|
210 | |
---|
211 | monoType = V_DeduceMonochromatorType(fname) |
---|
212 | print monoType |
---|
213 | // set a fake wavelength for the interpolation or get out |
---|
214 | strswitch(monoType) // string switch |
---|
215 | case "velocity_selector": // execute if case matches expression |
---|
216 | // use lambda as-is |
---|
217 | break // exit from switch |
---|
218 | case "white_beam": // execute if case matches expression |
---|
219 | lambda = 100 |
---|
220 | break |
---|
221 | case "crystal": |
---|
222 | lambda = 1000 |
---|
223 | break |
---|
224 | default: // optional default expression executed |
---|
225 | Abort "Monochromator type could not be determined in V_CalculateAttenuationError" // when no case matches |
---|
226 | endswitch |
---|
227 | |
---|
228 | Wave w = V_getAttenIndex_error_table(fname) // N=(8,17) |
---|
229 | Make/O/D/N=8 tmpVal,tmpLam |
---|
230 | |
---|
231 | tmpVal = w[p][numAtt+1] // offset by one, 1st column is wavelength |
---|
232 | tmpLam = w[p][0] |
---|
233 | val = interp(lambda, tmpLam, tmpVal ) |
---|
234 | |
---|
235 | //killwaves/Z tmpVal,tmpLam |
---|
236 | return(val) |
---|
237 | |
---|
238 | End |
---|
239 | |
---|
240 | // TODO -- this may not correctly mimic the enumerated type of the file |
---|
241 | // but I need to fudge this somehow |
---|
242 | // |
---|
243 | // returns null string if the type cannot be deduced, calling procedure is responsible |
---|
244 | // for properly handling this error condition |
---|
245 | // |
---|
246 | Function/S V_DeduceMonochromatorType(fname) |
---|
247 | String fname |
---|
248 | |
---|
249 | String typeStr="" |
---|
250 | |
---|
251 | if(cmpstr(V_getVelSelStatus(fname),"IN") == 0) |
---|
252 | typeStr = "velocity_selector" |
---|
253 | endif |
---|
254 | |
---|
255 | if(cmpstr(V_getWhiteBeamStatus(fname),"IN") == 0) |
---|
256 | typeStr = "white_beam" |
---|
257 | endif |
---|
258 | |
---|
259 | if(cmpstr(V_getCrystalStatus(fname),"IN") == 0) |
---|
260 | typeStr = "crystal" |
---|
261 | endif |
---|
262 | |
---|
263 | return(typeStr) |
---|
264 | End |
---|