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

Last change on this file since 1154 was 1153, checked in by srkline, 4 years ago

test commit (no changes) after upgrading to SVN 1.12.0 and a new computer

File size: 7.0 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
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        // TODO -- need to switch on "type"
173        //  == velocity_selector || ?? for white beam || graphite
174//      monoType = V_getMonochromatorType(fname)
175
176        monoType = V_DeduceMonochromatorType(fname)
177        print monoType
178
179        // set a fake wavelength for the interpolation or get out
180        strswitch(monoType)     // string switch
181                case "velocity_selector":       // execute if case matches expression
182                        // use lambda as-is
183                        break           // exit from switch
184                case "white_beam":      // execute if case matches expression
185                        lambda *= 1e3
186                        break
187                case "crystal":
188
189//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
190
191                        break
192                default:                        // optional default expression executed
193                        Abort "Monochromator type could not be determined in V_CalculateAttenuationFactor"              // when no case matches
194        endswitch
195       
196       
197        Wave w = V_getAttenIndex_table(fname)           // N=(x,17)
198        Variable num = DimSize(w,0)
199        Make/O/D/N=(num) tmpVal,tmpLam                                         
200       
201        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
202        tmpLam = w[p][0]
203        val = interp(lambda, tmpLam, tmpVal )
204        Print "Calculated Atten = ",val
205       
206        //killwaves/Z tmpVal,tmpLam
207        return(val)
208       
209End
210
211//////////////////////
212//
213// function to calculate the attenuation error from the table in the file
214//
215// fill in a "dummy" wavelength for White Beam and graphite
216// *= 1e3 for White Beam
217// *= 1e6 for graphite (***NO***) Per John, we can use the VS calibration for HOPG
218// use these dummy values just for the lookup table
219//
220// TODO -- need the enumerated values for the monochromator type
221// TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE
222//
223//
224Function V_CalculateAttenuationError(fname)
225        String fname
226       
227        Variable val,lambda,numAtt
228        String monoType
229       
230        numAtt = V_getAtten_number(fname)
231        lambda = V_getWavelength(fname)
232       
233        // TODO -- need to switch on "type"
234        //  == velocity_selector || ?? for white beam || crystal
235//      monoType = V_getMonochromatorType(fname)
236       
237        monoType = V_DeduceMonochromatorType(fname)
238        print monoType
239        // set a fake wavelength for the interpolation or get out
240        strswitch(monoType)     // string switch
241                case "velocity_selector":       // execute if case matches expression
242                        // use lambda as-is
243                        break           // exit from switch
244                case "white_beam":      // execute if case matches expression
245                        lambda *= 1e3
246                        break
247                case "crystal":
248
249//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
250
251                        break
252                default:                        // optional default expression executed
253                        Abort "Monochromator type could not be determined in V_CalculateAttenuationError"               // when no case matches
254        endswitch       
255       
256        Wave w = V_getAttenIndex_error_table(fname)             // N=(x,17)
257        Variable num = DimSize(w,0)
258        Make/O/D/N=(num) tmpVal,tmpLam
259       
260        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
261        tmpLam = w[p][0]
262        val = interp(lambda, tmpLam, tmpVal )
263       
264        //killwaves/Z tmpVal,tmpLam
265        return(val)
266       
267End
268
Note: See TracBrowser for help on using the repository browser.