-
Notifications
You must be signed in to change notification settings - Fork 0
/
sb2rpt.pro
584 lines (504 loc) · 13.5 KB
/
sb2rpt.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
@PS_open.pro
PRO SB2RPT_1D,SSD,option=option,format=format
if n_elements(*SSD.da(SSD.rank-1)) eq 0 then return
if keyword_set(option) eq 0 then option=0
if keyword_set(format) eq 0 then format='G18.8'
if keyword_set(xaxis) eq 0 then xaxis=0
def = SSD.id_def(*,SSD.rank-1)
nip = SSD.nb_pos(SSD.rank-1)
nid = SSD.nb_det(SSD.rank-1)
t_column = nip+nid
ip = def(0:3)
id_def = def(4:88)
pa = *SSD.pa(SSD.rank-1)
da1d = *SSD.da(SSD.rank-1)
HD_D=SSD.HD_D(*,SSD.rank-1)
HD_P=SSD.HD_P(*,SSD.rank-1)
sz = size(da1d)
id = where(id_def > 0)
no = n_elements(id)
format = format
; output ascii data array
fmt = strmid(format,1,10)
t_format = '('+format +')'
t_digit = fix(fmt)
twd = t_digit*(t_column+1)
s0 = string(replicate(32b,twd))
CD,current=p
path = p + !os.file_sep + 'ASCII' + !os.file_sep
report = path+SSD.class+'_1d.txt'
openw,1,report
if SSD.rank eq 3 then $
printf,1,"; 1D Array from 3D Scan #:",SSD.scanno
if SSD.rank eq 2 then $
printf,1,"; 1D Array from 2D Scan #:",SSD.scanno
printf,1,'; SCAN Record Name: ',SSD.pv[SSD.rank-1]
printf,1,';'
printf,1,"; MDA file: ",SSD.file
if SSD.rank gt 1 then ts = (*SSD.ts2)[0] else ts = SSD.ts1
printf,1,"; Time Stamp: ",ts
printf,1,"; Comment: ", ''
printf,1,'; '
printf,1,'; SCAN Data:'
printf,1,'; '
SB2RPT_header_dump,SSD,nip,ip,sz,id_def,HD_P,HD_D,t_digit,s0,option=option
SB2RPT_short_dump,pa,ip,sz,da1d,id_def,t_format,t_digit,s0
close,1
xdisplayfile,report
END
PRO SB2RPT_header_dump,SSD,nip,ip,sz,id_def,HD_P,HD_D,t_digit,s0,option=option
if option eq 2 then return
vers = SSD.vers
DI = [ 'D1','D2','D3','D4','D5','D6','D7','D8','D9', $
'DA','DB','DC','DD','DE','DF', $
'D01', 'D02', 'D03', 'D04', 'D05', 'D06', 'D07', 'D08', 'D09', 'D10' ]
DI = [DI,'D'+strtrim(indgen(60)+11,2)]
if SSD.vers then DI = D[15:84]
ypvs = HD_D.DXPV
ydescs = HD_D.DXDS
yengus = HD_D.DXEU
xpvs = HD_P.PXPV
xdescs = HD_P.PXDS
xengus = HD_P.PXEU
l1 = intarr(nip+sz(2))
st = s0
strput,st,'; (DIS) ',0 & ij=t_digit
if nip gt 0 then begin
for i=0,3 do begin
if ip(i) then begin
pn = 'P'+strtrim(i+1,2)
strput,st,pn,ij
; l = max(strlen([xpvs[i],xdescs[i],xengus[i]]))
; if l gt t_digit then l1[i] = l else l1[i]=t_digit
; ij = ij + l1[i] + 1
ij = ij+t_digit
end
end
end
for i=0,sz(2)-1 do begin
if id_def(i) then begin
strput,st,DI(i),ij
; l = max(strlen([ypvs[i],ydescs[i],yengus[i]]))
; if l gt t_digit then l1[i+nip]=l else l1[i+nip]=t_digit
; ij = ij + l1[nip+i] + 1
ij = ij+t_digit
end
end
printf,1,st
st = s0
strput,st,'; (PVS) ',0 & ij=t_digit
if nip gt 0 then begin
for i=0,3 do begin
if ip(i) then begin
strput,st,strmid(xpvs(i),0,t_digit-1),ij
; ij = ij + l1[i] + 1
ij = ij+t_digit
end
end
end
for i=0,sz(2)-1 do begin
if id_def(i) then begin
strput,st,strmid(ypvs(i),0,t_digit-1),ij
; ij = ij + l1[nip+i] + 1
ij = ij+t_digit
end
end
printf,1,st
st = s0
strput,st,'; (DESCS) ',0 & ij=t_digit
if nip gt 0 then begin
for i=0,3 do begin
if ip(i) then begin
strput,st,strmid(xdescs(i),0,t_digit-1),ij
; ij = ij + l1[i] + 1
ij = ij+t_digit
end
end
end
for i=0,sz(2)-1 do begin
if id_def(i) then begin
strput,st,strmid(ydescs(i),0,t_digit-1),ij
; ij = ij + l1[nip+i] + 1
ij = ij+t_digit
end
end
printf,1,st
st = s0
strput,st,'; (UNITS) ',0 & ij=t_digit
if nip gt 0 then begin
for i=0,3 do begin
if ip(i) then begin
strput,st,strmid(xengus(i),0,t_digit-1),ij
; ij = ij + l1[i] + 1
ij = ij+t_digit
end
end
end
for i=0,sz(2)-1 do begin
if id_def(i) then begin
strput,st,strmid(yengus(i),0,t_digit-1),ij
; ij = ij + l1[nip+i] + 1
ij = ij+t_digit
end
end
printf,1,st
END
PRO SB2RPT_data_dump,sb2rpt_data,y_seqno,scanH=scanH
; scanH = sb2rpt_data.scanH
SSD = sb2rpt_data.SSD
if n_elements(scanH) eq 0 then scanH = 0
if SSD.rank ge 2 then begin
if SSD.rank eq 2 and scanH gt 0 then begin
def = SSD.id_def(*,1)
nip = SSD.nb_pos(1)
nid = SSD.nb_det(1)
endif else begin
def = SSD.id_def(*,SSD.rank-2)
nip = SSD.nb_pos(SSD.rank-2)
nid = SSD.nb_det(SSD.rank-2)
end
endif else begin
def = SSD.id_def(*,0)
nip = SSD.nb_pos(0)
nid = SSD.nb_det(0)
end
t_column = nip+nid
ip = def(0:3)
id_def = def(4:88)
if SSD.rank ge 2 then begin
if SSD.rank eq 2 and scanH gt 0 then begin
pa = *SSD.pa(1)
da1d = *SSD.da(1)
endif else begin
pa = *SSD.pa(SSD.rank-2)
da1d = *SSD.da(SSD.rank-2)
da1d = da1d(*,y_seqno-1,*)
sz = size(da1d)
da1d = reform(da1d,sz(1),sz(3))
end
end
if SSD.rank eq 1 then begin
pa = *SSD.pa(0)
da1d = *SSD.da(0)
end
sz = size(da1d)
id = where(id_def > 0)
no = n_elements(id)
HD_D = SSD.HD_D(*,0)
if SSD.rank ge 2 then begin
HD_D=SSD.HD_D(*,SSD.rank-2)
if SSD.rank eq 2 and scanH gt 0 then HD_D=SSD.HD_D(*,1)
end
HD_P = SSD.HD_P(*,0)
if SSD.rank ge 2 then begin
HD_P=SSD.HD_P(*,SSD.rank-2)
if SSD.rank eq 2 and scanH gt 0 then HD_D=SSD.HD_P(*,1)
end
format = sb2rpt_data.format
; output ascii data array
fmt = strmid(format,1,10)
t_format = '('+format +')'
t_digit = fix(fmt)
twd = t_digit*(t_column+1)
s0 = string(replicate(32b,twd))
st = s0
SB2RPT_header_dump,SSD,nip,ip,sz,id_def,HD_P,HD_D,t_digit,s0,option=sb2rpt_data.option
SB2RPT_short_dump,pa,ip,sz,da1d,id_def,t_format,t_digit,s0
END
PRO SB2RPT_short_dump,pa,ip,sz,da1d,id_def,t_format,t_digit,s0
for i=0,sz(1)-1 do begin
st = s0
strput,st,i,0 & ij=10
; may need nb_pos info
for j=0,3 do begin
if ip(j) then begin
strput,st,string(pa(i,j),format=t_format),ij
ij = ij+t_digit
end
end
; detectors
for j=0,sz(2)-1 do begin
if id_def(j) then begin
strput,st,string(da1d(i,j),format=t_format),ij
ij = ij+t_digit
end
end
printf,1,st
end
printf,1,''
END
PRO SB2RPT_full_dump,sb2rpt_data
SSD = sb2rpt_data.SSD
rank = SSD.rank
for y_seqno=sb2rpt_data.startid,sb2rpt_data.endid do begin
; get new file name
if sb2rpt_data.separate eq 0 then SB2RPT_outfile,sb2rpt_data else $
SB2RPT_outfile,sb2rpt_data , seqno=y_seqno
str = '; 2D SCAN #: '
if rank eq 3 then str = '; 3D SCAN #: '
if sb2rpt_data.separate eq 1 then openw,1,sb2rpt_data.outfile else begin
if y_seqno eq sb2rpt_data.startid then openw,1,sb2rpt_data.outfile
end
; abrivated header
if sb2rpt_data.option lt 2 then begin
if rank gt 1 then begin
printf,1,str,SSD.scanno,", Y INDEX #:",y_seqno
end
pvs = SSD.pv
if rank gt 1 then pv = pvs[rank-2] else pv = pvs[0]
if rank gt 2 then printf,1,"; 2D SCAN #: ",y_seqno else $
printf,1,"; 1D SCAN #: ",y_seqno
printf,1,"; SCAN Record Name: ", pv
end
; full header
if sb2rpt_data.option eq 0 then begin
printf,1,'; '
printf,1,"; MDA file: ",SSD.file
if rank gt 1 then ts = (*SSD.ts2)[y_seqno-1] else ts = SSD.ts1
printf,1,"; Time Stamp: ",ts
printf,1,"; Comment: ", ''
printf,1,'; '
printf,1,'; SCAN Data:'
printf,1,'; '
end
scanH = sb2rpt_data.scanH
SB2RPT_data_dump,sb2rpt_data,y_seqno,scanH=scanH
if sb2rpt_data.separate then close,1 else begin
if y_seqno eq sb2rpt_data.endid then close,1
end
end
END
PRO SB2RPT_outfile,sb2rpt_data , seqno=seqno
if sb2rpt_data.scanH gt 0 then begin
outfile = sb2rpt_data.path + sb2rpt_data.class + '.1d.txt'
endif else begin
str = '0000'
sss = str
if keyword_set(seqno) then begin
s1 = strtrim(seqno,2)
len = strlen(s1)
strput,sss,s1,4-len
outfile = sb2rpt_data.path + sb2rpt_data.class + '.' + sss
sb2rpt_data.outfile = outfile
return
end
s1 = strtrim(sb2rpt_data.startid,2)
len = strlen(s1)
strput,sss,s1,4-len
outfile = sb2rpt_data.path + sb2rpt_data.class + '.' + sss
if sb2rpt_data.startid ne sb2rpt_data.endid then begin
if sb2rpt_data.separate eq 0 then begin
SSD = sb2rpt_data.SSD
if SSD.rank gt 1 then begin
eee = str
s1 = strtrim(sb2rpt_data.endid,2)
len = strlen(s1)
strput,eee,s1,4-len
outfile = outfile + '_'+eee
end
end
end
end
sb2rpt_data.outfile= outfile
widget_control,sb2rpt_data.WIDoutfile,set_value=outfile
END
PRO SB2RPT_Event, Event
widget_control,Event.top,get_uvalue= sb2rpt_data,/no_copy
SSD = sb2rpt_data.SSD
rank = SSD.rank
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'SB2_RPT_OPTION': BEGIN
sb2rpt_data.option = Event.Value
END
'SB2_RPT_FORMAT': BEGIN
widget_control,Event.Id,get_value=fmt
sb2rpt_data.format = fmt
END
'SB2_RPT_INFILE': BEGIN
; widget_control,Event.Id,get_value=fmt
; sb2rpt_data.infile = fmt
END
'SB2_RPT_START': BEGIN
widget_control,Event.Id,get_value=fmt
sb2rpt_data.startid = fmt
if fmt le 0 then sb2rpt_data.startid = 1
if rank eq 1 then sb2rpt_data.startid = 1
if rank gt 1 then begin
top = SSD.cpt(rank-1)
if fmt ge top then sb2rpt_data.startid = top
widget_control,Event.ID,set_value=sb2rpt_data.startid
end
SB2RPT_outfile,sb2rpt_data
END
'SB2_RPT_END': BEGIN
widget_control,Event.Id,get_value=fmt
sb2rpt_data.endid = fmt
if fmt le 0 then sb2rpt_data.endid = 1
if rank eq 1 then sb2rpt_data.endid = 1
if rank gt 1 then begin
top = SSD.cpt(rank-1)
if sb2rpt_data.scanH gt 0 then top=1
if fmt ge top then sb2rpt_data.endid = top
widget_control,Event.ID,set_value=sb2rpt_data.endid
end
SB2RPT_outfile,sb2rpt_data
END
'SB2_RPT_SEPARATE': BEGIN
sb2rpt_data.separate = Event.Value
END
'SB2_RPT_OUTFILE': BEGIN
widget_control,Event.Id,get_value=fmt
sb2rpt_data.outfile = fmt
END
'SB2_RPT_GENERATE': BEGIN
widget_control,sb2rpt_data.WIDstart,get_value=st
sb2rpt_data.startid = st
if st le 0 then sb2rpt_data.startid = 1
if rank eq 1 then sb2rpt_data.startid = 1
if rank gt 1 then begin
top = SSD.cpt(rank-1)
if st ge top then sb2rpt_data.startid = top
widget_control,sb2rpt_data.WIDstart,set_value=sb2rpt_data.startid
end
widget_control,sb2rpt_data.WIDend,get_value=st
sb2rpt_data.endid = st
if st le 0 then sb2rpt_data.endid = 1
if rank eq 1 then sb2rpt_data.endid = 1
if rank gt 1 then begin
top = SSD.cpt(rank-1)
if st ge top then sb2rpt_data.endid = top
widget_control,sb2rpt_data.WIDend,set_value=sb2rpt_data.endid
end
SB2RPT_outfile,sb2rpt_data
SB2RPT_full_dump,sb2rpt_data
END
'SB2_RPT_VIEW': BEGIN
xdisplayfile,sb2rpt_data.outfile,title=sb2rpt_data.outfile,width=100
END
'SB2_RPT_CLOSE': BEGIN
widget_control,Event.top,/destroy
return
END
'SB2_RPT_PRINT': BEGIN
PS_enscript,sb2rpt_data.outfile
END
ENDCASE
widget_control,Event.top,set_uvalue= sb2rpt_data,/no_copy
END
PRO SB2RPT,SSD,GROUP=Group,scanH=scanH
if n_elements(SSD) eq 0 then return
if n_elements(scanH) eq 0 then scanH=0
file = SSD.file
class = SSD.class
cl = strsplit(class,'.',/extract)
class = cl[0]
CD,current=p
path = p + !os.file_sep + 'ASCII' + !os.file_sep
fd = findfile(path,count=ct)
if ct eq 0 then spawn,!os.mkdir + ' ' +path
outfile = path+class+'.0001'
if scanH gt 0 then outfile = path + class + '.1d.txt'
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
junk = { CW_PDMENU_S, flags:0, name:'' }
title = 'Report from 2D Array'
if scanH gt 0 or SSD.rank eq 1 then title = 'Report from 1D Array'
SB2RPT = WIDGET_BASE(GROUP_LEADER=Group, $
ROW=1, $
MAP=1, title=title, $
UVALUE='SB2RPT')
BASE2 = WIDGET_BASE(SB2RPT, $
COLUMN=1, $
MAP=1, $
TITLE='Report ...', $
UVALUE='BASE2')
BASE3 = WIDGET_BASE(BASE2, $
ROW=1, $
MAP=1, $
UVALUE='BASE3')
Btns958 = [ $
'Full', $
'Abbreviated', $
'None' ]
BGROUP14 = CW_BGROUP( BASE3, Btns958, $
ROW=1, $
EXCLUSIVE=1, $
LABEL_LEFT='Header options:', $
UVALUE='SB2_RPT_OPTION')
widget_control,BGROUP14,set_value=0
FieldVal1170 = [ $
'G18.8' ]
FIELD9 = CW_FIELD( BASE2,VALUE=FieldVal1170, $
ROW=1, $
STRING=1, /return_events, $
TITLE='Output Data Format:', $
UVALUE='SB2_RPT_FORMAT')
FIELD11 = CW_FIELD( BASE2,VALUE=File, $
ROW=1, xsize=70, $
STRING=1, /NOEDIT, $ ;/return_events, $
TITLE='Data file name:', $
UVALUE='SB2_RPT_INFILE')
FieldVal1315 = [ $
'1' ]
FIELD12 = CW_FIELD( BASE2,VALUE=FieldVal1315, $
ROW=1, $
INTEGER=1, /return_events, $
TITLE='Start Scan #', $
UVALUE='SB2_RPT_START')
FieldVal1380 = [ $
'1' ]
FIELD13 = CW_FIELD( BASE2,VALUE=FieldVal1380, $
ROW=1, $
INTEGER=1, /return_events, $
TITLE='End Scan # ', $
UVALUE='SB2_RPT_END')
Btns1708 = [ $
'No', $
'Yes' ]
BGROUP17 = CW_BGROUP( BASE2, Btns1708, $
ROW=1, $
EXCLUSIVE=1, $
LABEL_LEFT='Save Selected Scans as Separate ASCII files:', $
UVALUE='SB2_RPT_SEPARATE')
widget_control,BGROUP17,set_value=1
FIELD19 = CW_FIELD( BASE2,VALUE=outfile, $
ROW=1, xsize=70, $
STRING=1, /return_events, $
TITLE='Output file Name: ', $
UVALUE='SB2_RPT_OUTFILE')
BASE20 = WIDGET_BASE(BASE2, $
ROW=1, $
MAP=1, $
UVALUE='BASE20')
BUTTON21 = WIDGET_BUTTON( BASE20, $
UVALUE='SB2_RPT_GENERATE', $
VALUE='Generate Report')
BUTTON22 = WIDGET_BUTTON( BASE20, $
UVALUE='SB2_RPT_VIEW', $
VALUE='View Report ...')
BUTTON28 = WIDGET_BUTTON( BASE20, $
UVALUE='SB2_RPT_PRINT', $
VALUE='Print Report')
BUTTON23 = WIDGET_BUTTON( BASE20, $
UVALUE='SB2_RPT_CLOSE', $
VALUE='Close')
sb2rpt_data = { $
WIDstart: FIELD12, $
WIDend: FIELD13, $
WIDoutfile: FIELD19, $
option: 0, $
scanH : scanH, $
format: 'G18.8', $
infile: file, $
path: path, $
class: class, $
startid : 1, $
endid : 1, $
separate: 1, $
outfile: outfile, $
SSD : SSD $
}
widget_control,SB2RPT,set_uvalue= sb2rpt_data
WIDGET_CONTROL, SB2RPT, /REALIZE
XMANAGER, 'SB2RPT', SB2RPT
END