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