1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | //Functions to deal with TISANE data |
---|
7 | |
---|
8 | Constant ATXY = 0 |
---|
9 | Constant ATXYM = 2 |
---|
10 | Constant ATMIR = 1 |
---|
11 | Constant ATMAR = 3 |
---|
12 | |
---|
13 | Constant USECSPERTICK=0.1 // microseconds |
---|
14 | Constant TICKSPERUSEC=10 |
---|
15 | Constant XBINS=128 |
---|
16 | Constant YBINS=128 |
---|
17 | |
---|
18 | Proc Show_TISANE_Panel() |
---|
19 | DoWindow/F TISANE |
---|
20 | if(V_flag ==0) |
---|
21 | Init_TISANE() |
---|
22 | TISANE() |
---|
23 | EndIf |
---|
24 | End |
---|
25 | |
---|
26 | |
---|
27 | Function Init_TISANE() |
---|
28 | String/G root:Packages:NIST:gTISANE_logfile |
---|
29 | Variable/G root:Packages:NIST:AIMTYPE_XY=0 // XY Event |
---|
30 | Variable/G root:Packages:NIST:AIMTYPE_XYM=2 // XY Minor event |
---|
31 | Variable/G root:Packages:NIST:AIMTYPE_MIR=1 // Minor rollover event |
---|
32 | Variable/G root:Packages:NIST:AIMTYPE_MAR=3 // Major rollover event |
---|
33 | |
---|
34 | Variable/G root:Packages:NIST:gTISANE_time_msw = 0 |
---|
35 | Variable/G root:Packages:NIST:gTISANE_time_lsw = 0 |
---|
36 | Variable/G root:Packages:NIST:gTISANE_t_longest = 0 |
---|
37 | |
---|
38 | Variable/G root:Packages:NIST:gTISANE_tsdisp //Displayed slice |
---|
39 | Variable/G root:Packages:NIST:gTISANE_nslices = 10 //Number of time slices |
---|
40 | Variable/G root:Packages:NIST:gTISANE_slicewidth = 1000 //Slicewidth in us |
---|
41 | |
---|
42 | Variable/G root:Packages:NIST:gTISANE_prescan // Do we prescan the file? |
---|
43 | Variable/G root:Packages:NIST:gTISANE_logint = 1 |
---|
44 | |
---|
45 | NVAR nslices = root:Packages:NIST:gTISANE_nslices |
---|
46 | |
---|
47 | SetDataFolder root: |
---|
48 | NewDataFolder/O/S root:Packages:NIST:TISANE |
---|
49 | |
---|
50 | Make/O/N=(XBINS,YBINS,nslices) slicedData |
---|
51 | Duplicate/O slicedData logslicedData |
---|
52 | Duplicate/O slicedData dispsliceData |
---|
53 | |
---|
54 | SetDataFolder root: |
---|
55 | End |
---|
56 | |
---|
57 | Proc TISANE() |
---|
58 | PauseUpdate; Silent 1 // building window... |
---|
59 | NewPanel/K=2 /W=(100,50,600,680)/N=TISANE |
---|
60 | DoWindow/C TISANE |
---|
61 | ModifyPanel fixedSize=1,noEdit =1 |
---|
62 | //ShowTools/A |
---|
63 | SetDrawLayer UserBack |
---|
64 | Button button0,pos = {10,10}, size={150,20},title="Load TISANE Log File",fSize=12 |
---|
65 | Button button0,proc=LoadTISANELog_Proc |
---|
66 | SetVariable setvar3,pos= {20,590},size={460,20},title=" ",fSize=12 |
---|
67 | SetVariable setvar3,disable=2,variable=root:Packages:NIST:gTISANE_logfile |
---|
68 | CheckBox chkbox1,pos={170,15},title="Prescan file? (increases load time)" |
---|
69 | CheckBox chkbox1,variable = root:Packages:NIST:gTISANE_prescan |
---|
70 | Button doneButton,pos={400,10}, size={50,20},title="Done",fSize=12 |
---|
71 | Button doneButton,proc=TISANEDone_Proc |
---|
72 | |
---|
73 | //DrawLine 10,35,490,35 |
---|
74 | Button button1,pos = {10,50}, size={150,20},title="Process Data",fSize=12 |
---|
75 | Button button1,proc=ProcessLog_Proc |
---|
76 | SetVariable setvar1,pos={170,50},size={160,20},title="Number of slices",fSize=12 |
---|
77 | SetVariable setvar1,value=root:Packages:NIST:gTISANE_nslices |
---|
78 | SetVariable setvar2,pos={330,50},size={160,20},title="Slice Width (us)",fSize=12 |
---|
79 | SetVariable setvar2,value=root:Packages:NIST:gTISANE_slicewidth |
---|
80 | //DrawLine 10,65,490,65 |
---|
81 | |
---|
82 | CheckBox chkbox2,pos={20,95},title="Log Intensity",value=1 |
---|
83 | CheckBox chkbox2,variable=root:Packages:NIST:gTISANE_logint,proc=LogInt_Proc |
---|
84 | SetVariable setvar0,pos={320,90},size={160,20},title="Display Time Slice",fSize=12 |
---|
85 | SetVariable setvar0,value= root:Packages:NIST:gTISANE_tsdisp |
---|
86 | SetVariable setvar0,proc=sliceSelect_Proc |
---|
87 | Display/W=(20,120,480,580)/HOST=TISANE/N=TISANE_slicegraph |
---|
88 | AppendImage/W=TISANE#TISANE_slicegraph/T root:Packages:NIST:TISANE:dispsliceData |
---|
89 | ModifyImage/W=TISANE#TISANE_slicegraph ''#0 ctab= {*,*,Rainbow,0} |
---|
90 | ModifyImage/W=TISANE#TISANE_slicegraph ''#0 ctabAutoscale=3 |
---|
91 | ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14 |
---|
92 | ModifyGraph mirror=2 |
---|
93 | ModifyGraph nticks=4 |
---|
94 | ModifyGraph minor=1 |
---|
95 | ModifyGraph fSize=9 |
---|
96 | ModifyGraph standoff=0 |
---|
97 | ModifyGraph tkLblRot(left)=90 |
---|
98 | ModifyGraph btLen=3 |
---|
99 | ModifyGraph tlOffset=-2 |
---|
100 | SetAxis/A/R left |
---|
101 | SetActiveSubwindow ## |
---|
102 | EndMacro |
---|
103 | |
---|
104 | Function LoadTISANELog_Proc(ctrlName) : ButtonControl |
---|
105 | String ctrlName |
---|
106 | |
---|
107 | Variable fileref |
---|
108 | SVAR filename = root:Packages:NIST:gTISANE_logfile |
---|
109 | NVAR prescan = root:Packages:NIST:gTISANE_prescan |
---|
110 | NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth |
---|
111 | NVAR nslices = root:Packages:NIST:gTISANE_nslices |
---|
112 | NVAR t_longest = root:Packages:NIST:gTISANE_t_longest |
---|
113 | |
---|
114 | Open/R/D fileref |
---|
115 | filename = S_filename |
---|
116 | |
---|
117 | if(prescan ) |
---|
118 | PreProcessLog() |
---|
119 | slicewidth = trunc(t_longest/nslices) |
---|
120 | DoUpdate |
---|
121 | endif |
---|
122 | |
---|
123 | End |
---|
124 | |
---|
125 | Function TISANEDone_Proc(ba) : ButtonControl |
---|
126 | STRUCT WMButtonAction &ba |
---|
127 | |
---|
128 | String win = ba.win |
---|
129 | switch (ba.eventCode) |
---|
130 | case 2: |
---|
131 | DoWindow/K TISANE |
---|
132 | break |
---|
133 | endswitch |
---|
134 | |
---|
135 | End |
---|
136 | |
---|
137 | Function ProcessLog_Proc(ctrlName) : ButtonControl |
---|
138 | String ctrlName |
---|
139 | |
---|
140 | NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth |
---|
141 | NVAR nslices = root:Packages:NIST:gTISANE_nslices |
---|
142 | |
---|
143 | ProcessLog(nslices,slicewidth) |
---|
144 | |
---|
145 | End |
---|
146 | |
---|
147 | Function LogInt_Proc(ctrlName,checked) : CheckBoxControl |
---|
148 | String ctrlName |
---|
149 | Variable checked |
---|
150 | |
---|
151 | SetDataFolder root:Packages:NIST:TISANE |
---|
152 | if(checked) |
---|
153 | Duplicate/O logslicedData dispsliceData |
---|
154 | else |
---|
155 | Duplicate/O slicedData dispsliceData |
---|
156 | endif |
---|
157 | |
---|
158 | SetDataFolder root: |
---|
159 | End |
---|
160 | |
---|
161 | Function sliceSelect_Proc(ctrlName, varNum, varStr, varName) : SetVariableControl |
---|
162 | String ctrlName |
---|
163 | Variable varNum |
---|
164 | String varStr |
---|
165 | String varName |
---|
166 | |
---|
167 | NVAR nslices = root:Packages:NIST:gTISANE_nslices |
---|
168 | NVAR selectedslice = root:Packages:NIST:gTISANE_tsdisp |
---|
169 | |
---|
170 | if(varNum < 0) |
---|
171 | selectedslice = 0 |
---|
172 | DoUpdate |
---|
173 | elseif (varNum > nslices-1) |
---|
174 | selectedslice = nslices-1 |
---|
175 | DoUpdate |
---|
176 | else |
---|
177 | ModifyImage/W=TISANE#TISANE_slicegraph ''#0 plane = varNum |
---|
178 | endif |
---|
179 | |
---|
180 | End |
---|
181 | |
---|
182 | Function ProcessLog(nslices,slicewidth) |
---|
183 | Variable nslices,slicewidth |
---|
184 | |
---|
185 | NVAR time_msw = root:Packages:NIST:gTISANE_time_msw |
---|
186 | NVAR time_lsw = root:Packages:NIST:gTISANE_time_lsw |
---|
187 | NVAR t_longest = root:Packages:NIST:gTISANE_t_longest |
---|
188 | |
---|
189 | NVAR logint = root:Packages:NIST:gTISANE_logint |
---|
190 | |
---|
191 | SVAR filepathstr = root:Packages:NIST:gTISANE_logfile |
---|
192 | SetDataFolder root:Packages:NIST:TISANE |
---|
193 | |
---|
194 | //Create bin lookup |
---|
195 | Variable tickwidth, i ,boundary |
---|
196 | Variable fileref |
---|
197 | |
---|
198 | Make/O/N = (nslices) t_lookup |
---|
199 | tickwidth = floor(slicewidth/USECSPERTICK) |
---|
200 | boundary = 0 |
---|
201 | for (i = 0 ; i < nslices; i += 1) |
---|
202 | t_lookup[i] = boundary |
---|
203 | boundary += tickwidth |
---|
204 | endfor |
---|
205 | |
---|
206 | Make/O/N=(XBINS,YBINS,nslices) slicedData |
---|
207 | Open/R fileref as filepathstr |
---|
208 | |
---|
209 | String buffer |
---|
210 | Variable dataval,b,tmp |
---|
211 | |
---|
212 | Variable xval,tyval,yval,timeval,ppto,type |
---|
213 | |
---|
214 | do |
---|
215 | FReadLine fileref, buffer |
---|
216 | if (strlen(buffer) == 0) |
---|
217 | break |
---|
218 | endif |
---|
219 | sscanf buffer,"%x",dataval |
---|
220 | |
---|
221 | //print (dataval) |
---|
222 | |
---|
223 | //This is hideous, but that is what you get for IGOR not doing structs like C |
---|
224 | type = (dataval & ~(2^32 - 2^30 -1))/2^30 |
---|
225 | |
---|
226 | switch(type) |
---|
227 | case ATXY: |
---|
228 | //printf "XY : " |
---|
229 | xval = ~(dataval & ~(2^32 - 2^8)) & 127 |
---|
230 | yval = ((dataval & ~(2^32 - 2^16 ))/2^8) & 127 |
---|
231 | time_lsw = (dataval & ~(2^32 - 2^29))/2^16 |
---|
232 | timeval = (time_msw * (2^13)) + time_lsw |
---|
233 | if (timeval > t_longest) |
---|
234 | t_longest = timeval |
---|
235 | endif |
---|
236 | //printf "%u : %u : %u : %u\r",dataval,time_lsw,time_msw,timeval |
---|
237 | b = FindBin(timeval,nslices) |
---|
238 | slicedData[xval][yval][b] += 1 |
---|
239 | break |
---|
240 | case ATXYM: |
---|
241 | //printf "XYM : " |
---|
242 | xval = ~(dataval & ~(2^32 - 2^8)) & 127 |
---|
243 | yval = ((dataval & ~(2^32 - 2^16 ))/2^8) & 127 |
---|
244 | time_lsw = (dataval & ~(2^32 - 2^29 ))/2^16 |
---|
245 | break |
---|
246 | case ATMIR: |
---|
247 | //printf "MIR : " |
---|
248 | time_msw = (dataval & ~(2^32 - 2^29 ))/2^16 |
---|
249 | timeval = (time_msw * (2^13)) + time_lsw |
---|
250 | if (timeval > t_longest) |
---|
251 | t_longest = timeval |
---|
252 | endif |
---|
253 | //printf "%u : %u : %u : %u\r",dataval,time_lsw,time_msw,timeval |
---|
254 | b = FindBin(timeval,nslices) |
---|
255 | slicedData[xval][yval][b] += 1 |
---|
256 | break |
---|
257 | case ATMAR: |
---|
258 | //printf "MAR : \r" |
---|
259 | break |
---|
260 | endswitch |
---|
261 | while(1) |
---|
262 | |
---|
263 | Close fileref |
---|
264 | |
---|
265 | Duplicate/O slicedData logslicedData |
---|
266 | logslicedData[][][] = log(slicedData[p][q][r]) |
---|
267 | if(logint) |
---|
268 | Duplicate/O logslicedData dispsliceData |
---|
269 | else |
---|
270 | Duplicate/O slicedData dispsliceData |
---|
271 | endif |
---|
272 | |
---|
273 | SetDataFolder root: |
---|
274 | End |
---|
275 | |
---|
276 | |
---|
277 | Function FindBin(nticks,nslices) |
---|
278 | Variable nticks,nslices |
---|
279 | |
---|
280 | WAVE t_lookup = root:Packages:NIST:TISANE:t_lookup |
---|
281 | |
---|
282 | Variable i |
---|
283 | Variable whichbin = nslices -1 |
---|
284 | for (i= 0; i < nslices; i+=1) |
---|
285 | if (nticks > t_lookup[i]) |
---|
286 | whichbin = i |
---|
287 | else |
---|
288 | break |
---|
289 | endif |
---|
290 | endfor |
---|
291 | return whichbin |
---|
292 | End |
---|
293 | |
---|
294 | |
---|
295 | Function PreProcessLog() |
---|
296 | |
---|
297 | NVAR time_msw = root:Packages:NIST:gTISANE_time_msw |
---|
298 | NVAR time_lsw = root:Packages:NIST:gTISANE_time_lsw |
---|
299 | NVAR t_longest = root:Packages:NIST:gTISANE_t_longest |
---|
300 | |
---|
301 | SVAR filepathstr = root:Packages:NIST:gTISANE_logfile |
---|
302 | SetDataFolder root:Packages:NIST:TISANE |
---|
303 | |
---|
304 | Variable fileref |
---|
305 | |
---|
306 | Open/R fileref as filepathstr |
---|
307 | |
---|
308 | String buffer |
---|
309 | Variable dataval,timeval,type |
---|
310 | |
---|
311 | do |
---|
312 | FReadLine fileref, buffer |
---|
313 | if (strlen(buffer) == 0) |
---|
314 | break |
---|
315 | endif |
---|
316 | sscanf buffer,"%x",dataval |
---|
317 | |
---|
318 | //This is hideous, but that is what you get for IGOR not doing structs like C |
---|
319 | type = (dataval & ~(2^32 - 2^30 -1))/2^30 |
---|
320 | |
---|
321 | switch(type) |
---|
322 | case ATXY: |
---|
323 | time_lsw = (dataval & ~(2^32 - 2^29))/2^16 |
---|
324 | timeval = (time_msw * (2^13)) + time_lsw |
---|
325 | if (timeval > t_longest) |
---|
326 | t_longest = timeval |
---|
327 | endif |
---|
328 | break |
---|
329 | case ATXYM: |
---|
330 | time_lsw = (dataval & ~(2^32 - 2^29 ))/2^16 |
---|
331 | break |
---|
332 | case ATMIR: |
---|
333 | time_msw = (dataval & ~(2^32 - 2^29 ))/2^16 |
---|
334 | timeval = (time_msw * (2^13)) + time_lsw |
---|
335 | if (timeval > t_longest) |
---|
336 | t_longest = timeval |
---|
337 | endif |
---|
338 | break |
---|
339 | case ATMAR: |
---|
340 | break |
---|
341 | endswitch |
---|
342 | while(1) |
---|
343 | |
---|
344 | Close fileref |
---|
345 | |
---|
346 | SetDataFolder root: |
---|
347 | End |
---|