source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_VSANS_Event_Testing.ipf @ 1042

Last change on this file since 1042 was 1042, checked in by srkline, 5 years ago

moved dead time correction to before the solid angle correction, so that the dead time would be correcting counts, not counts per solid angle

added a routine to kill all of the waves and folders possible, if the overall DF kill failed. This is to prevent stray folders and waves from being present if different data files are loaded - since different data blocks are present for say, 3He data, data with temperature logging, etc.
This kill routine is used every time, before raw data is loaded, DIV or MASK loaded, or data is converted to WORK.

changed the "Save I(q)" button on the data display panel to save as ITX format, since the data has not been processed, and data can more easily be used for trimming input.

picking protocols in dialogs now excludes/includes appropriate waves

menus are consolidated

Fixed bug in SANS macros where the DRK[] item in the protocol could be null, and force the read of a DRK file, even if it was not desired.

File size: 7.8 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6// for the event mode data with the proposed 64 bit structure, I may be able to use Igor for everything.
7//
8// Skipping the appropriate bits of the header (after I read them in) may be possible with
9// either LoadWave (treating the entire wave as 64 bit, unsigned), loading chunks from clipboard?
10// -- see in LoadWave, the suggestions for "Loading Large Waves"
11//
12// or using FBinRead, again, filling a wave, or a chunk of the data, as needed
13//
14// Then - since the data has sequential timing, not dependent on rollovers, I can
15// chunk the data for parallel processing, and piece it back together
16// after all of the decoding is done.
17//
18//
19// I don't know if it's possible to use a STRUCT  definition for each 64 bit word so that I could address
20// the bytes directly - since that may not work properly in Igor, and I'm not sure how to address the 6 byte section
21// -possibly with a uchar(6) definition?
22//
23//
24//      (from WM help) You can define an array of structures as a field in a structure:
25//              Structure mystruct
26//                      STRUCT Point pt[100]                    // Allowed as a sub-structure
27//              EndStructure
28//
29// -- which may be of use to read "blocks" of datq from a file using FBinRead
30//
31// -- right now, I'm having issues with being able to "cast" or convert uint64 values to STRUCT
32// (I don't know how to read from the struct if I can't fill it??)
33//
34// TODO:
35//
36// (5/2017)
37// The basic bits of reading work, but will need to be customized to be able to accomodate file names in/out
38// and especially the number of disabled tubes (although as long as I have the offset, it shouldn't be that
39// big of an issue.
40//
41// -- don't see the struct idea working out. only in read c-code if needed
42//
43// -- need to add detector binning to the decoding, to place the counts within the correct panels
44// -- not sure how this will work with JointHistogram Operation
45// (split to separate "streams" of values for each detector panel?
46//
47//
48// -- can I efficiently use "sort" (on the tube index) to block the data into groups that can be split
49//  into 4 sets of waves
50//  that can then be binned per panel, using the usual Joint histogram procedures? Works only if the
51// tube indexing is orderly. if it's a mess, Ill need to try something else (indexed sort?) (replace?)
52// (manually? ugh.)
53//
54
55
56//
57Structure eventWord
58        uchar eventTime[6]
59        uchar location
60        uchar tube
61endStructure
62
63
64
65//
66//
67Function V_testBitShift()
68
69//      // /l=64 bit, /U=unsigned
70//      Make/L/U/N=100 eventWave
71//      eventWave = 0
72       
73        // for each 64-bit value:
74        // byte 1: tube index [0,191]
75        // byte 2: pixel value [0,127]
76        // bytes 3-8 (= 6 bytes): time stamp in resolution unit
77       
78        int64 i64_num,b1,b2,b3,b4,b5,b6,b7,b8
79        int64 i64_ticks,i64_start
80       
81        b1=255
82        b3=255
83        b5=255
84        b7=255
85        b2=0
86        b4=0
87        b6=0
88        b8=0
89       
90        b7 = b7 << 8
91        b6 = b6 << 16
92        b5 = b5 << 24
93        b4 = b4 << 32
94        b3 = b3 << 40
95        b2 = b2 << 48
96        b1 = b1 << 56
97       
98        i64_num = b1+b2+b3+b4+b5+b6+b7+b8
99        printf "%64b\r",i64_num
100       
101        return(0)
102End
103
104Function V_MakeFakeEvents()
105
106//      // /l=64 bit, /U=unsigned
107        Make/O/L/U/N=10 smallEventWave
108        smallEventWave = 0
109       
110        // for each 64-bit value:
111        // byte 1: tube index [0,191]
112        // byte 2: pixel value [0,127]
113        // bytes 3-8 (= 6 bytes): time stamp in resolution unit
114       
115        uint64 i64_num,b1,b2,b3,b4,b5,b6,b7,b8
116        uint64 i64_ticks,i64_start
117       
118        b1 = 47
119        b2 = 123
120        i64_ticks = 123456789
121
122
123        b2 = b2 << 48
124        b1 = b1 << 56
125       
126        i64_num = b1+b2+i64_ticks
127        printf "%64b\r",i64_num
128        print i64_num
129       
130        smallEventWave[0] = i64_num
131       
132        return(0)
133End
134
135Function V_decodeFakeEvent()
136
137        WAVE w = smallEventWave
138        uint64 val,b1,b2,btime
139        val = w[0]
140       
141//      printf "%64b\r",w[0]            //wrong (drops the last Å 9 bits)
142        printf "%64b\r",val                     //correct, assign value to 64bit variable
143//      print w[0]                              //wrong
144        print val                               // correct
145       
146        b1 = (val >> 56 ) & 0xFF                        // = 255, last byte, after shifting
147        b2 = (val >> 48 ) & 0xFF
148       
149        btime = val & 0xFFFFFFFFFFFF    // = really big number, last 6 bytes
150       
151        print b1
152        print b2
153        print btime
154
155
156//      //test as struct
157//      Print "as STRUCT"
158//     
159//      STRUCT eventWord s
160//     
161//      s = w[0]
162//     
163//      print s.tube
164//      print s.location
165//      print s.eventTime
166       
167
168               
169        return(0)
170End
171
172/
173// tested up to num=1e8 successfully
174//
175Function V_MakeFakeEventWave()
176
177        Variable num,ii
178
179
180        num = 1e3
181       
182//      // /l=64 bit, /U=unsigned
183        Make/O/L/U/N=(num) eventWave
184        eventWave = 0
185       
186        // for each 64-bit value:
187        // byte 1: tube index [0,191]
188        // byte 2: pixel value [0,127]
189        // bytes 3-8 (= 6 bytes): time stamp in resolution unit
190       
191        uint64 i64_num,b1,b2,b3,b4,b5,b6,b7,b8
192        uint64 i64_ticks,i64_start
193       
194        i64_start = ticks
195        for(ii=0;ii<num;ii+=1)
196//              sleep/T/C=-1 1                  // 6 ticks, approx 0.1 s (without the delay, the loop is too fast)
197                b1 = trunc(abs(enoise(192)))            //since truncated, need 192 as highest random to give 191 after trunc
198                b2 = trunc(abs(enoise(128)))            // same here, to get results [0,127]
199               
200//              i64_ticks = ticks-i64_start
201                i64_ticks = ii+1
202               
203                b2 = b2 << 48
204                b1 = b1 << 56
205       
206                i64_num = b1+b2+i64_ticks
207                eventWave[ii] = i64_num
208        endfor
209
210
211        return(0)
212End
213
214
215Function V_decodeFakeEventWave(w)
216        Wave w
217
218s_tic()
219//      WAVE w = eventWave
220        uint64 val,b1,b2,btime
221        val = w[0]
222       
223//      printf "%64b\r",w[0]            //wrong (drops the last Å 9 bits)
224//      printf "%64b\r",val                     //correct, assign value to 64bit variable
225//      print w[0]                              //wrong
226//      print val                               // correct
227       
228        Variable num,ii
229        num=numpnts(w)
230       
231        Make/O/L/U/N=(num) eventTime
232        Make/O/U/B/N=(num) tube,location                //8 bit unsigned
233       
234        for(ii=0;ii<num;ii+=1)
235                val = w[ii]
236               
237                b1 = (val >> 56 ) & 0xFF                        // = 255, last two bytes, after shifting
238                b2 = (val >> 48 ) & 0xFF
239       
240                btime = val & 0xFFFFFFFFFFFF    // = really big number, last 6 bytes
241
242                tube[ii] = b1
243                location[ii] = b2
244                eventTime[ii] = btime
245               
246        endfor
247
248s_toc()
249               
250        return(0)
251End
252
253
254Function V_writeFakeEventFile(fname)
255        String fname
256
257        WAVE w = eventWave
258        Variable refnum
259       
260        String vsansStr="VSANS"
261        Variable revision = 11
262        Variable offset = 22            // no disabled tubes
263        Variable time1 = 2017
264        Variable time2 = 0525
265        Variable time3 = 1122
266        Variable time4 = 3344           // these 4 time pieces are supposed to be 8 bytes total
267        String detStr = "M"
268        Variable volt = 1500
269        Variable resol = 1000
270       
271       
272        Open refnum as fname
273
274        FBinWrite refnum, vsansStr
275        FBinWrite/F=2/U refnum, revision
276        FBinWrite/F=2/U refnum, offset
277        FBinWrite/F=2/U refnum, time1
278        FBinWrite/F=2/U refnum, time2
279        FBinWrite/F=2/U refnum, time3
280        FBinWrite/F=2/U refnum, time4
281        FBinWrite refnum, detStr
282        FBinWrite/F=2/U refnum, volt
283        FBinWrite/F=2/U refnum, resol
284
285        FGetPos refnum
286        Print V_filePos
287       
288        FBinWrite refnum, w
289       
290        close refnum
291       
292        return(0)
293End
294
295//
296// use GBLoadWave to do the reading, then I can do the decoding
297//
298Function V_readFakeEventFile()
299
300        String fname
301// this reads in uint64 data, to a unit64 wave, skipping 22 bytes       
302//      GBLoadWave/B/T={192,192}/W=1/S=22
303        Variable num,refnum
304       
305
306// so to read:
307//
308// - get the file name
309//      - read the header (all of it, since I need parts of it) (maybe read as a struct? but I don't know the size!)
310// - move to EOF and close
311//
312// - Use GBLoadWave to read it in
313
314        String vsansStr=""
315        Variable revision
316        Variable offset         // no disabled tubes
317        Variable time1
318        Variable time2
319        Variable time3
320        Variable time4          // these 4 time pieces are supposed to be 8 bytes total
321        String detStr=""
322        Variable volt
323        Variable resol
324
325        vsansStr = PadString(vsansStr,5,0x20)           //pad to 5 bytes
326        detStr = PadString(detStr,1,0x20)                               //pad to 1 byte
327
328        Open/R refnum
329        fname = S_fileName
330
331s_tic()
332
333        FBinRead refnum, vsansStr
334        FBinRead/F=2/U refnum, revision
335        FBinRead/F=2/U refnum, offset
336        FBinRead/F=2/U refnum, time1
337        FBinRead/F=2/U refnum, time2
338        FBinRead/F=2/U refnum, time3
339        FBinRead/F=2/U refnum, time4
340        FBinRead refnum, detStr
341        FBinRead/F=2/U refnum, volt
342        FBinRead/F=2/U refnum, resol
343
344        FStatus refnum
345        FSetPos refnum, V_logEOF
346       
347        Close refnum
348       
349// number of data bytes
350        num = V_logEOF-offset
351        Print num/8
352       
353        GBLoadWave/B/T={192,192}/W=1/S=22 fname
354       
355s_toc()
356       
357        return(0)
358End
Note: See TracBrowser for help on using the repository browser.