source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Attenuation.ipf @ 1248

Last change on this file since 1248 was 1242, checked in by srkline, 3 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

File size: 7.5 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3#pragma IgorVersion = 7.00
4
5
6
7//
8// 7-NOV-2017
9//
10// The attenuator tables are more complex now - since there are more ways to select wavelength
11// - there is the standard velocity selector (no tilt)
12// - a white beam mode (with a non-symmetric distribution)
13// - a graphite monochromator, allowing wavelength selection
14//
15// To accomodate this, I have chosen to alter the table to allow all of the wavelength "modes"
16// to be in the same table for interpolation, by use of the "correct" input wavelength
17// velocity_selector lambda is input as is
18// white beam lambda = (lambda * 1e3)
19// graphite crystal lambda = (lambda * 1e6)
20//
21// in this way, the interpolation will work just fine. Otherwise, the only solution I could see was to
22// have separate tables stored in the header for each of the "modes".
23//
24//
25
26//
27// functions to calculate attenuator values from the tables
28//
29// V_CalculateAttenuationFactor(fname)
30// V_CalculateAttenuationError(fname)
31//
32// interpolate if necessary
33//
34
35//
36// patch entire tables if necessary
37//
38//
39// attenuator tables are currently /N=(n,17)
40
41
42Proc V_LoadCSVAttenTable()
43
44        // this load command will:
45        // load CSV data into a matrix
46        // skip a one-line header
47        // name it "atten0"
48        // prompt for file
49        LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0}                            //will prompt for the file, auto name
50       
51        Rename atten0, atten_values
52
53End
54
55Proc V_LoadCSVAttenErrTable()
56
57        // this load command will:
58        // load CSV data into a matrix
59        // skip a one-line header
60        // name it "atten0"
61        // prompt for file
62        LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0}                            //will prompt for the file, auto name
63       
64        Rename atten0, atten_err
65
66End
67
68// V_writeAttenIndex_table(fname,inW)
69//
70// V_writeAttenIndex_table_err(fname,inW)
71//
72
73Proc V_WriteCSVAttenTable(lo,hi,atten_values)
74        Variable lo,hi
75        String atten_values="atten_values"
76
77        V_fPatchAttenValueTable(lo,hi,$atten_values)
78End
79
80Proc V_WriteCSVAttenErrTable(lo,hi,atten_err)
81        Variable lo,hi
82        String atten_err="atten_err"
83
84        V_fPatchAttenErrTable(lo,hi,$atten_err)
85End
86
87
88// simple utility to patch the attenuator table wave in the file headers
89// lo is the first file number
90// hi is the last file number (inclusive)
91//
92Function V_fPatchAttenValueTable(lo,hi,attenW)
93        Variable lo,hi
94        Wave attenW
95       
96        Variable ii
97        String fname
98       
99//      // check the dimensions of the attenW (8,17)
100//      if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 )
101//              Abort "attenuator wave is not of proper dimension (8,17)"
102//      endif
103       
104        //loop over all files
105        for(ii=lo;ii<=hi;ii+=1)
106                fname = V_FindFileFromRunNumber(ii)
107                if(strlen(fname) != 0)
108                        V_writeAttenIndex_table(fname,attenW)                   
109                else
110                        printf "run number %d not found\r",ii
111                endif
112        endfor
113       
114        return(0)
115End
116
117// simple utility to patch the attenuator error (std dev) wave in the file headers
118// lo is the first file number
119// hi is the last file number (inclusive)
120//
121Function V_fPatchAttenErrTable(lo,hi,attenW)
122        Variable lo,hi
123        Wave attenW
124       
125        Variable ii
126        String fname
127       
128//      // check the dimensions of the attenW (8,17)
129//      if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 )
130//              Abort "attenuator wave is not of proper dimension (8,17)"
131//      endif
132       
133        //loop over all files
134        for(ii=lo;ii<=hi;ii+=1)
135                fname = V_FindFileFromRunNumber(ii)
136                if(strlen(fname) != 0)
137                        V_writeAttenIndex_table_err(fname,attenW)                       
138                else
139                        printf "run number %d not found\r",ii
140                endif
141        endfor
142       
143        return(0)
144End
145
146
147
148//////////////////////
149//
150// function to calculate the attenuation factor from the table in the file
151//
152// fill in a "dummy" wavelength for White Beam and graphite
153// *= 1e3 for White Beam
154// *= 1e6 for graphite (***NO***) Per John, we can use the VS calibration for HOPG
155// use these dummy values just for the lookup table
156//
157// TODO -- need the enumerated values for the monochromator type
158// TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE
159// TODO -- determine the dimensions of the wave, don't hard-wire
160// TODO -- update to use separate tables for each monochromator mode
161// TODO -- (same updates for the error table)
162//
163Function V_CalculateAttenuationFactor(fname)
164        String fname
165       
166        Variable val,lambda,numAtt
167        String monoType
168       
169        numAtt = V_getAtten_number(fname)
170        lambda = V_getWavelength(fname)
171
172        if(lambda < 4.52 || lambda > 19)
173                Abort "Wavelength out of range for attenuation table"
174        endif
175               
176        // TODO -- need to switch on "type"
177        //  == velocity_selector || ?? for white beam || graphite
178//      monoType = V_getMonochromatorType(fname)
179
180        monoType = V_IdentifyMonochromatorType(fname)
181        print monoType
182
183        // set a fake wavelength for the interpolation or get out
184        strswitch(monoType)     // string switch
185                case "super_white_beam":                // TODO: this is not written into NICE
186                        lambda = 6.2e6          //just for the interpolation
187                        break
188                case "velocity_selector":       // execute if case matches expression
189                        // use lambda as-is
190                        break           // exit from switch
191                case "white_beam":      // execute if case matches expression
192                        lambda *= 1e3
193                        break
194                case "crystal":
195
196//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
197
198                        break
199                default:                        // optional default expression executed
200                        Abort "Monochromator type could not be determined in V_CalculateAttenuationFactor"              // when no case matches
201        endswitch
202       
203        Wave w = V_getAttenIndex_table(fname)           // N=(x,17)
204        Variable num = DimSize(w,0)
205        Make/O/D/N=(num) tmpVal,tmpLam                                         
206       
207        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
208        tmpLam = w[p][0]
209        val = interp(lambda, tmpLam, tmpVal )
210        Print "Calculated Atten = ",val
211       
212        //killwaves/Z tmpVal,tmpLam
213        return(val)
214       
215End
216
217//////////////////////
218//
219// function to calculate the attenuation error from the table in the file
220//
221// fill in a "dummy" wavelength for White Beam and graphite
222// *= 1e3 for White Beam
223// *= 1e6 for graphite (***NO***) Per John, we can use the VS calibration for HOPG
224// use these dummy values just for the lookup table
225//
226// TODO -- need the enumerated values for the monochromator type
227// TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE
228//
229//
230Function V_CalculateAttenuationError(fname)
231        String fname
232       
233        Variable val,lambda,numAtt
234        String monoType
235       
236        numAtt = V_getAtten_number(fname)
237        lambda = V_getWavelength(fname)
238
239        if(lambda < 4.52 || lambda > 19)
240                Abort "Wavelength out of range for attenuation error table"
241        endif
242               
243        // TODO -- need to switch on "type"
244        //  == velocity_selector || ?? for white beam || crystal
245//      monoType = V_getMonochromatorType(fname)
246       
247        monoType = V_IdentifyMonochromatorType(fname)
248        print monoType
249        // set a fake wavelength for the interpolation or get out
250        strswitch(monoType)     // string switch
251                case "super_white_beam":                // TODO: this is not written into NICE
252                        lambda = 6.2e6          //just for the interpolation
253                        break
254                case "velocity_selector":       // execute if case matches expression
255                        // use lambda as-is
256                        break           // exit from switch
257                case "white_beam":      // execute if case matches expression
258                        lambda *= 1e3
259                        break
260                case "crystal":
261
262//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
263
264                        break
265                default:                        // optional default expression executed
266                        Abort "Monochromator type could not be determined in V_CalculateAttenuationError"               // when no case matches
267        endswitch       
268       
269        Wave w = V_getAttenIndex_error_table(fname)             // N=(x,17)
270        Variable num = DimSize(w,0)
271        Make/O/D/N=(num) tmpVal,tmpLam
272       
273        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
274        tmpLam = w[p][0]
275        val = interp(lambda, tmpLam, tmpVal )
276       
277        //killwaves/Z tmpVal,tmpLam
278        return(val)
279       
280End
281
Note: See TracBrowser for help on using the repository browser.