-
Notifications
You must be signed in to change notification settings - Fork 0
/
sscan.pro
2122 lines (1843 loc) · 53.6 KB
/
sscan.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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
@image2d.pro
@panimage.pro
@sb2rpt.pro
@view4d.pro
PRO rix2DC,Scan,gData
; ON_ERROR,0 ;,1
*gData.scanno = Scan.scanno
*gData.dim = Scan.rank
*gData.num_pts = Scan.npts
*gData.cpt = Scan.cpt
*gData.id_def = Scan.id_def
*gData.pv = Scan.pv
*gData.labels = Scan.labels
if Scan.rank gt 1 then *gData.ts = *Scan.ts2 else *gData.ts = Scan.ts1
rank = Scan.rank
IF rank EQ 1 THEN BEGIN
*gData.pa1D = *Scan.pa[0]
*gData.da1D = *Scan.da[0]
*gData.pa2D = 0 ;ptr_new(/ALLOCATE_HEAP)
*gData.da2D = 0
*gData.pa3D = 0
*gData.da3D = 0
ENDIF
IF rank EQ 2 THEN BEGIN
*gData.pa1D = *Scan.pa[1]
*gData.da1D = *Scan.da[1]
*gData.pa2D = *Scan.pa[0]
if n_elements(*Scan.da[0]) gt 1 then $
*gData.da2D = *Scan.da[0] else *gData.da2D = 0
*gData.pa3D = 0
*gData.da3D = 0
ENDIF
IF rank EQ 3 THEN BEGIN
*gData.pa1D = *Scan.pa[2]
*gData.da1D = *Scan.da[2]
*gData.pa2D = *Scan.pa[1]
*gData.da2D = *Scan.da[1]
*gData.pa3D = *Scan.pa[0]
;if ptr_valid(gData.da3D) eq 0 then *gData.da3D = ptr_new(/ALLOCATE_HEAP)
if n_elements(*Scan.da[0]) then *gData.da3D = *Scan.da[0]
ENDIF
IF rank EQ 4 THEN BEGIN
*gData.pa1D = *Scan.pa[3]
*gData.pa2D = *Scan.pa[2]
*gData.pa3D = *Scan.pa[1]
*gData.pa4D = *Scan.pa[0]
*gData.da1D = *Scan.da[3]
*gData.da2D = *Scan.da[2]
*gData.da3D = *Scan.da[1]
*gData.da4D = *Scan.da[0]
;;if ptr_valid(gData.da3D) eq 0 then *gData.da3D = ptr_new(/ALLOCATE_HEAP)
;if n_elements(*Scan.da[0]) then *gData.da4D = *Scan.da[0]
;if ptr_valid(gData.da4D) eq 0 then *gData.da4D = ptr_new(/ALLOCATE_HEAP)
ENDIF
free_lun,Scan.lun
scanSee_free,Scan
END
FUNCTION read_scan,filename, Scan, dump=dump, lastDet=lastDet,pickDet=pickDet,header=header
; Normallly if lastDet is specified only detectOR 1 to lastDet is extracted
; But if pickDet>=1 if specified only the specified detector is extracted
; it is target for big 3D scan
; if pickDet <0 then no 3D array is returned for 3D scan
;
;+
; NAME:
; READ_SCAN
;
; PURPOSE:
; This function reads any 1D/2D/3D scan file and returns a scan pointer
; paramenter which consists of few heap pointers to point to the data
; extracted from the MDA scan file.
;
; If succeeds, it returns the scan number, otherwise it returns -1.
;
; CATEGORY:
; Function.
;
; CALLING SEQUENCE:
;
; scanno = READ_SCAN(Filename,Scan, ...)
;
; INPUTS:
; Filename: Input XDR scan filename
;
; KEYWORD PARAMETERS:
; DUMP : Set this keyword to specify the plot title string.
;
; PICKDET: Specify the detector # , if specified only the 3D array
; for the specified detector is returned
; If -1 is specified, no 3D data array is returned for
; the 3D scan
; LASTDET: [1,1,1] set the initial temp detector numbers for
; 3D scan record, it returns the last detector #
; defined in each scan record
; If pickDet is defined, then the lastDet[0]=1 will be
; returned for 3D scan
; HEADER: Set this keyword to specify the xtitle string.
;
; OUTPUTS:
; SCAN: The scan data structure composed of heap data pointers.
;
; scanno - integer pointer of scan number
; dim - integer pointer of scan dimension
; npts - pointer of requested data point vector (dim)
; cpt - pointer of current data point vector (dim)
; id_def - pointer of defined Pi & Di integer array (85,dim)
; pv - pointer of PV names string array (85,dim)
; labels - pointer to PV labels string array (85*3,dim)
; pa - pointer to positioner array pointer (dim)
; da - pointer to detecor array pointer (dim)
;
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; RESTRICTIONS: Required scan filename which is automatically saved
; by the scan record by IOC. The filename follows the
; special sequential rule which is ended with '.scan' type.
;
; EXAMPLES:
; filename = '/home/beams/CHA/data/xxx/cha:_0001.scan'
; scanno = read_scan(filename,Scan)
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, July 27, 2004.
;
;-
debug = 0
IF keyword_set(dump) THEN debug = dump
ON_ERROR,0 ;,1
ON_IOERROR,BAD
res=0
ndet = 85 ; 15
ntot = ndet+4
; SSD->Scan
reread:
sscan_read,Scan,file=filename,/header,error=error,pick3d=pickDet
if n_elements(Scan) eq 0 then goto,BAD
if error eq -1 then begin
; scanSee_free,Scan
goto,BAD ;reread
end
npts = Scan.npts
if keyword_set(pickDet) then begin
if Scan.rank lt 3 then pickDet=0
end
IF keyword_set(header) THEN GOTO,DONE
case Scan.rank of
3: begin
if n_elements(pickDet) then begin
if pickDet lt 0 then begin
Scan.pick3d = 0
sscan_read3D,Scan,da2D,/only2d
if Scan.im_filled(Scan.rank-2) eq 0 then $
scanSee_fillImage,Scan,da2D ;,/echo
endif else begin
dpick = where(Scan.id_def(4:88,0) gt 0)
pick3d = where((dpick-pickDet+1) eq 0)
if pick3d ge -1 then begin
Scan.pick3d = 1
sscan_read3DPick,Scan,da2D,idet=pick3d
if Scan.im_filled(Scan.rank-2) eq 0 then $
scanSee_fillImage,Scan,da2D ;,/echo
end
end
endif else begin
msg = ['Error: pick3D Detector # '+string(pickDet) + ' not defined!']
r = dialog_message(msg,/error)
return,-1
end
end
1: sscan_read,Scan,file=filename,/data
2: sscan_read,Scan,file=filename,/data
4: begin
if n_elements(pickDet) then begin
sscan_read4dPick,Scan,pda4d ;,idet=0
end
end
endcase
; extract the first DetMax detectORs only
DetMax = Scan.detMax
IF keyword_set(lastDet) THEN DetMax = lastDet
; fill pos array for Scan structure
for i=0,Scan.rank-1 do begin
if npts(0) le 0 then goto,BAD
p = dblarr(npts(i),4)
v = *Scan.pa(i)
np = Scan.nb_pos(i)
if np gt 0 then begin
jj = 0
for j=0,3 do begin
if Scan.id_def(j,i) then begin
p(*,j) = v(jj:jj+npts(i)-1)
jj = jj + npts(i)
end
end
end
*scan.pa[i] = p
end
; fill det array for Scan structure
res= Scan.scanno
lastDet = DetMax
if debug then begin
print,'pickDet=',pickDet
help,*Scan.da[0],*Scan.da[1],*Scan.da[2]
help,*Scan.pa[0],*Scan.pa[1],*Scan.pa[2]
end
GOTO,DONE
BAD:
res= -1
print, !ERR_STRING
scanSee_free,Scan
DONE:
RETURN, res
END
PRO sscan_readConfig,fn
fn =''
catch,error_status
if error_status ne 0 then begin
close,1
return
end
openr,1,'scanSee.config'
readf,1,fn
close,1
END
PRO scanSee_writeConfig,SSD
catch,error_status
if error_status ne 0 then begin
close,1
return
end
openw,1,'scanSee.config'
printf,1,SSD.file
printf,1,SSD.path
close,1
END
PRO scanSee_image2d,SSD,axis1,axis2,vers=vers
if SSD.rank eq 1 then return
xarr = *SSD.pa(SSD.rank-2)
yarr = *SSD.pa(SSD.rank-1)
sscan_getDescs,SSD,xdescs,ydescs,zdescs
sz = size(xarr)
if axis1 lt 4 then xd = xdescs(axis1) else xd = 'step #'
if sz(0) eq 2 then begin
if axis1 lt sz(2) then xarr = xarr(*,axis1) $
else xarr = indgen(sz(1))
end
if sz(0) eq 1 and axis1 gt 0 then xarr = indgen(sz(1))
sz = size(yarr)
if axis2 lt 4 then yd = ydescs(axis2) else yd = 'step #'
if sz(0) eq 2 then begin
if axis2 lt sz(2) then yarr = yarr(*,axis2) $
else yarr = indgen(sz(1))
end
if sz(0) eq 1 and axis2 gt 0 then yarr = indgen(sz(1))
id_def = SSD.id_def(*,SSD.rank-2)
id_def = id_def(4:4+SSD.detMax(SSD.rank-2)-1)
; da2d = *SSD.da(SSD.rank-2)
; if axis2 ge 4 or axis1 ge 4 then image2d,da2d,id_def=id_def else $
title=SSD.file
image2d,*SSD.da(SSD.rank-2),xarr,yarr,id_def=id_def,title=title, $
xdescs=xd,ydescs=yd,zdescs=zdescs,vers=vers
END
PRO sscan_getDescs,SSD,xdescs,ydescs,zdescs
; for rank 1 only xdescs,ydescs returned
if SSD.rank eq 1 then begin
HD_P = SSD.HD_P
xd = HD_P(*,0)
xdescs = xd.PXDS
for i=0,3 do begin
if strtrim(xd(i).RXEU,2) ne '' then xdescs(i) = xdescs(i) + ' ('+xd(i).RXEU+')'
end
HD_D = SSD.HD_D
if ssd.detMax(0) eq 0 then return
yd = HD_D(0:SSD.detMax(0)-1,0)
ydescs = yd.DXDS
return
end
; for rank 2 or 3
; x desc
HD_P = SSD.HD_P
xd = HD_P(*,SSD.rank-2)
xdescs = xd.PXDS
for i=0,3 do begin
if strtrim(xd(i).RXEU,2) ne '' then xdescs(i) = xdescs(i) + ' ('+xd(i).RXEU+')'
end
; y desc
yd = HD_P(*,SSD.rank-1)
ydescs = yd.PXDS
for i=0,3 do begin
if strtrim(yd(i).RXEU,2) ne '' then ydescs(i) = ydescs(i) + ' ('+yd(i).RXEU+')'
end
; detector desc
HD_D = SSD.HD_D
if ssd.detmax(ssd.rank-2) eq 0 then return
zd = HD_D(0:SSD.detMax(SSD.rank-2)-1,SSD.rank-2)
zdescs = zd.DXDS
pvs = zd.DXPV
for i=0,n_elements(zdescs)-1 do begin
if strtrim(zdescs(i),2) eq '' then zdescs(i) = pvs(i)
end
END
PRO scanSee_plot1d,SSD,xaxis,x=x,da=da
rank = SSD.rank
; plot against the xaxis picked
if n_elements(*SSD.da(rank-1)) eq 0 then return
pa1d = *SSD.pa(rank-1)
if xaxis lt SSD.nb_pos(rank-1) then x = pa1d(*,xaxis) else $
xaxis = 4 ; step #
title='1D Array from '+strtrim(rank,2)+'D Scan # '+strtrim(SSD.scanno,2)
HD_P = SSD.HD_P
xd = HD_P(*,rank-1)
xdescs = xd.PXDS
for i=0,3 do begin
if strtrim(xd(i).RXEU,2) ne '' then xdescs(i) = xdescs(i) + ' ('+xd(i).RXEU+')'
end
; detector desc
id_def = SSD.id_def(4:88,rank-1)
if total(id_def) eq 0.0 then begin
print,'*** Bad MDA scan file detected'
return
end
HD_D = SSD.HD_D
zd = HD_D(0:SSD.detMax(rank-1)-1,rank-1)
pvs = zd.DXPV
zdescs = pvs(where (id_def > 0))
da1d = *SSD.da(rank-1)
sz = size(da1d)
no = n_elements(zdescs)
da = make_array(sz(1),no)
ii=0
for i=0,sz(2)-1 do begin
if id_def(i) gt 0 then begin
da(*,ii) = da1d(*,i)
ii = ii+1
end
end
if xaxis eq 4 then plot1d,da,/data,title=title else $
plot1d,x,da,/data,title=title,xtitle=xdescs(xaxis),legend=zdescs
END
PRO scanSee_pickXaxis,Event
axis = widget_info(Event.id,/droplist_select)
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
scanSee_data.pick1d = axis
SSD = *scanSee_data.SSD
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
if ssd.nb_det(ssd.rank-1) eq 0 then return
scanSee_plot1d,SSD,axis
END
PRO scanSee_pickYaxis,Event
axis = widget_info(Event.id,/droplist_select)
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
vers = scanSee_data.vers
scanSee_data.pick2d = axis
axis1 = scanSee_data.pick1d
SSD = *scanSee_data.SSD
SSD.vers = vers
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
if ssd.nb_det(ssd.rank-2) eq 0 then return
scanSee_image2d,SSD,axis1,axis,vers=vers
END
PRO scanSee_version,Event
vs = widget_info(Event.id,/droplist_select)
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
scanSee_data.vers = vs
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO SSCAN_DLISTPICK4D_Event, Event
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'SSCAN_DLISTPICK4D': BEGIN
idet = widget_info(Event.Id,/list_select)
widget_control,Event.Top,get_uvalue=da4d_state
SSD = da4d_state.SSD
widget_control,Event.Top,set_uvalue=da4d_state
sscan_read4dPick,SSD,pda4d,idet=idet
view4d,pda4d,group=Event.top,SSD=SSD ,title='4D: Detector # '+strtrim(idet,2)
END
'SSCAN_DLISTDONE': BEGIN
widget_control,event.top,/destroy
END
ENDCASE
END
PRO sscan_dlistpick4d,GROUP=Group,SSD=SSD
if SSD.rank lt 4 then return
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
junk = { CW_PDMENU_S, flags:0, name:'' }
SSCAN_DLIST = WIDGET_BASE(GROUP_LEADER=Group, $
COLUMN=1, $
MAP=1, $
TITLE='Pick 4D Det', $
UVALUE='SSCAN_DLIST')
BASE2 = WIDGET_BASE(SSCAN_DLIST, $
COLUMN=1, $
MAP=1, $
UVALUE='BASE2')
lastDet = SSD.nb_det(SSD.rank-4)
ListVal1026 = '4D Array Seq # '+ strtrim(indgen(lastDet)+1,2)
LIST3 = WIDGET_LIST( BASE2,VALUE=ListVal1026, $
FRAME=5, $
UVALUE='SSCAN_DLISTPICK4D', $
YSIZE=15)
BUTTON4 = WIDGET_BUTTON( BASE2, $
UVALUE='SSCAN_DLISTDONE', $
VALUE='Close')
WIDGET_CONTROL, SSCAN_DLIST, /REALIZE
da4d_state = { SSD:SSD }
widget_control,SSCAN_DLIST,set_uvalue=da4d_state
XMANAGER, 'SSCAN_DLISTPICK4D', SSCAN_DLIST
END
PRO scanSee_pick4d_det,Event
idet = widget_info(Event.id,/droplist_select)
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
scanSee_data.pick4d = idet
if n_elements(*scanSee_data.SSD) then SSD = *scanSee_data.SSD
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
sscan_read4dPick,ssd,pda4d,idet=idet
view4d,pda4d,group=Event.top,SSD=SSD ,title='4D: Detector # '+strtrim(idet,2)
END
PRO scanSee_pick3d_det,Event
idet = widget_info(Event.id,/droplist_select)
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
scanSee_data.pick3d = idet
if n_elements(*scanSee_data.SSD) then SSD = *scanSee_data.SSD
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
if ssd.rank eq 3 then begin
sscan_read3DPick,SSD,da2D,idet=idet
nd = where(SSD.id_def(4:88,0) gt 0)
title=SSD.class+' : 3D Seq # :D_'+strtrim(nd(idet)+1,2)
xv = *ssd.pa[ssd.rank-3]
yv = *ssd.pa[ssd.rank-2]
zv = *ssd.pa[ssd.rank-1]
; if n_elements(ssd.cal_array) eq 0 then $
catch,error_status
if error_status ne 0 then begin
print,!error_state
print,'***Incomplete 3D file***'
goto,bypass
end
sscan_readENV,ssd
cal = *ssd.cal_array
for i=0,ssd.npts(0)-1 do begin
xv(i) = cal(idet).cal_offset+cal(idet).cal_slope*i+cal(idet).cal_quad*i*i
end
bypass:
view3d_2d,*SSD.da[0],0,xv,yv,zv,kmax=SSD.cpt(ssd.rank-1),title=title,group=Event.top,class=SSD.class
end
if ssd.rank eq 4 then begin
; pda3D = *ssd.da(1)
nd = where(SSD.id_def(4:88,1) gt 0)
title=SSD.class+' : 3D Seq # :D_'+strtrim(nd(idet)+1,2)
view3d_2d,(*ssd.da(1))(*,*,*,idet),kmax=SSD.cpt(ssd.rank-1),title=title,group=Event.top,class=SSD.class
end
END
PRO scanSee_checkrank,scanSee_data
SSD = *scanSee_data.SSD
WIDGET_CONTROL, scanSee_data.type_wid, set_value= strtrim(SSD.rank,2)+'D'
if SSD.rank lt 3 then begin
WIDGET_CONTROL,scanSee_data.p4d_wid,SENSITIVE=0
WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
return
end
if SSD.rank eq 3 then begin
WIDGET_CONTROL,scanSee_data.p4d_wid,SENSITIVE=0
if ssd.nb_det(0) gt 0 then $
WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1
if SSD.nb_det(0) gt 0 then $
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
return
end
if SSD.rank eq 4 then begin
if ssd.nb_det(1) gt 0 then begin
WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(1))+1,2)
endif else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
if ssd.nb_det(0) gt 0 then begin
widget_control,scanSee_data.p4d_wid,set_value='Pick4D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
WIDGET_CONTROL,scanSee_data.p4d_wid,SENSITIVE=1
endif else WIDGET_CONTROL,scanSee_data.p4d_wid,SENSITIVE=0
end
END
PRO scanSee_field,Event
widget_control,Event.id,get_value=file
found = findfile(file,count=ct)
if ct eq 0 then begin
r = dialog_message('File: "'+file+ '" not found!')
return
end
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
catch,error_status
if error_status ne 0 then begin
print,!error_state
endif else begin
sscan_read,SSD,file=file,/echo,error=error,pick3d=-1
if error eq 0 then begin
scanSee_writeConfig,SSD
*scanSee_data.SSD = SSD
WIDGET_CONTROL, scanSee_data.btns_wid, SENSITIVE=1
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
if SSD.rank eq 3 then WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1 $
else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
scanSee_checkrank,scanSee_data
end
end
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO scanSee_first,Event
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
SSD = *scanSee_data.SSD
path = SSD.path
ll = findfile(path+!os.file_sep+'*.mda',count=ct)
if ct gt 1 then begin
file= ll(0)
catch,error_status
if error_status ne 0 then begin
close,1
r = dialog_message('File: "'+file+ '" read failed!')
endif else begin
openr,1,file
close,1
sscan_read,SSD,file=file,/echo,error=error,pick3d=-1
if error eq 0 then begin
scanSee_writeConfig,SSD
*scanSee_data.SSD = SSD
widget_control,scanSee_data.file_wid,set_value=SSD.file
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
if SSD.rank eq 3 then WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1 $
else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
scanSee_checkrank,scanSee_data
end
end
end
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO scanSee_next,Event
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
if size(scanSee_data,/type) eq 8 then begin
SSD = *scanSee_data.SSD
if size(SSD,/type) eq 8 then begin
SSD = *scanSee_data.SSD
path = SSD.path
ll = findfile(path+!os.file_sep+'*.mda',count=ct)
if ct gt 1 then begin
id = where(ll eq SSD.file)
file= ll(id+1)
catch,error_status
if error_status ne 0 then begin
close,1
r = dialog_message('File: "'+file+ '" read failed!')
endif else begin
openr,1,file
close,1
sscan_read,SSD,file=file,/echo,error=error,pick3d=-1
if error eq 0 then begin
scanSee_writeConfig,SSD
*scanSee_data.SSD = SSD
widget_control,scanSee_data.file_wid,set_value=SSD.file
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
if SSD.rank eq 3 then WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1 $
else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
scanSee_checkrank,scanSee_data
end
end
end
end
end
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO scanSee_prev,Event
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
SSD = *scanSee_data.SSD
path = SSD.path
ll = findfile(path+!os.file_sep+'*.mda',count=ct)
if ct gt 1 then begin
id = where(ll eq SSD.file)
file= ll(id-1)
catch,error_status
if error_status ne 0 then begin
close,1
r = dialog_message('File: "'+file+ '" read failed!')
endif else begin
openr,1,file
close,1
sscan_read,SSD,file=file,/echo,error=error,pick3d=-1
if error eq 0 then begin
scanSee_writeConfig,SSD
*scanSee_data.SSD = SSD
widget_control,scanSee_data.file_wid,set_value=SSD.file
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
if SSD.rank eq 3 then WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1 $
else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
scanSee_checkrank,scanSee_data
end
end
end
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO scanSee_last,Event
widget_control,Event.top,get_uvalue=scanSee_data,/no_copy
SSD = *scanSee_data.SSD
path = SSD.path
ll = findfile(path+!os.file_sep+'*.mda',count=ct)
if ct gt 1 then begin
id = where(ll eq SSD.file)
file= ll(ct-1)
catch,error_status
if error_status ne 0 then begin
close,1
r = dialog_message('File: "'+file+ '" read failed!')
endif else begin
openr,1,file
close,1
sscan_read,SSD,file=file,/echo,error=error,pick3d=-1
if error eq 0 then begin
scanSee_writeConfig,SSD
*scanSee_data.SSD = SSD
widget_control,scanSee_data.file_wid,set_value=SSD.file
widget_control,scanSee_data.p3d_wid,set_value='Pick3D Seq # '+strtrim(indgen(SSD.nb_det(0))+1,2)
if SSD.rank eq 3 then WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=1 $
else WIDGET_CONTROL,scanSee_data.p3d_wid,SENSITIVE=0
scanSee_checkrank,scanSee_data
end
end
end
widget_control,Event.top,set_uvalue=scanSee_data,/no_copy
END
PRO SCANSEE_READ_PICK3D_Event, Event
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'SCANSEE_READ_PICK3D': BEGIN
i = widget_info(Event.Id,/list_select)
widget_control,Event.Top,get_uvalue=da3d_state
da3d = da3d_state.da3d
detID = da3d_state.detID
widget_control,Event.Top,set_uvalue=da3d_state
; da = da3d(*,*,*,i)
view3d_2d,da3d(*,*,*,i),kmax=SSD.cpt(ssd.rank-1),group=Event.top,title='3D Array Seq # '+': D_'+strtrim(i+1,2),class=SSD.class
END
'SCANSEE_READ_DONE': BEGIN
widget_control,event.top,/destroy
END
ENDCASE
END
PRO sscan_read_pick3d,da3D,detID=detID,GROUP=Group
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
junk = { CW_PDMENU_S, flags:0, name:'' }
SCANSEE_READ = WIDGET_BASE(GROUP_LEADER=Group, $
COLUMN=1, $
MAP=1, $
TITLE='Pick 3D Det', $
UVALUE='SCANSEE_READ')
BASE2 = WIDGET_BASE(SCANSEE_READ, $
COLUMN=1, $
MAP=1, $
UVALUE='BASE2')
ListVal1026= '3D Array Seq # D_'+ strtrim(indgen(detID),2)
LIST3 = WIDGET_LIST( BASE2,VALUE=ListVal1026, $
FRAME=5, $
UVALUE='SCANSEE_READ_PICK3D', $
YSIZE=15)
BUTTON4 = WIDGET_BUTTON( BASE2, $
UVALUE='SCANSEE_READ_DONE', $
VALUE='Close')
WIDGET_CONTROL, SCANSEE_READ, /REALIZE
da3d_state = { pick: 0, da3d:da3d, detID:detID }
widget_control,SCANSEE_READ,set_uvalue=da3d_state
XMANAGER, 'SCANSEE_READ_PICK3D', SCANSEE_READ
END
PRO scanSee_free,SSD
if n_elements(SSD) gt 0 then begin
if n_elements(SSD) gt 1 then begin
free_lun,SSD.lun
close,SSD.lun,/all
for i=0,2 do begin
ptr_free,SSD.da(i)
ptr_free,SSD.pa(i)
end
for i=0,1 do begin
ptr_free,SSD.sub_scan_ptr(i)
end
ptr_free,SSD.EH
if ptr_valid(SSD.ts2) then ptr_free,SSD.ts2
end
end
SSD = 0
heap_gc
; print,ptr_valid()
END
PRO sscan_readHeader,file=file,SSD,echo=echo,error=error,pick3d=pick3d
; this routine closes the old lun and frees the pointer
; then open the file set create the data pointer and
; leave the file lun open until next call of this routine
;
if n_elements(pick3d) eq 0 then pick3d=-1
error=0
catch,error_status
if error_status ne 0 then begin
scanSee_free,SSD
error=-1
return
end
scanSee_free,SSD
; i need to check 106.mda
pos_info= { $
pxpv:'', $
pxds:'', $
pxsm:'', $
pxeu:'', $
rxpv:'', $
rxds:'', $
rxeu:'' }
det_info= { $
dxpv:'', $
dxds:'', $
dxeu:'' }
trg_info= { $
txpv:'', $
txcd: 1.0 }
ntot = 85+4
dflt = [0,0,0,0,0]
mdim = 5
HD_P = make_array(4,mdim,value=pos_info)
HD_D = make_array(85,mdim,value=det_info)
HD_T = make_array(4,mdim,value=trg_info)
DetMax = dflt
id_def = intarr(ntot,mdim)
cd,current=p
SSD = { file : '', $
class : '', $
path : p, $
lun : -1, $
vers : 0, $ ; 0 - 85 detecors, 1 - 70 detectors
mdim : mdim, $
rank : 0, $
scanno : 0, $
npts : dflt, $
cpt : dflt, $
nb_pos : dflt, $
nb_det : dflt, $
nb_trg : dflt, $
id_def : id_def, $
HD_P : HD_P, $
HD_D : HD_D, $
HD_T : HD_T, $
lrecl : 0L, $ 1D scan lrecl
offset : 0L, $ 1D scan offset for detector data
dlen : 0L, $ 1D scan detector data length
pick3d : 0, $ 1 - pick 3D array, 0 - whole 3D array
pick4d : 0, $ 1 - pick 4D array, 0 - whole 4D array
labels : strarr(3*ntot,mdim), $
detMax : dflt, $
pv : ['','','','',''], $
ts1 : '', $
im_filled : dflt, $
noenv : 0, $
envPtr : 0L, $
ts2 : ptr_new(/allocate_heap), $
cal_array : ptr_new(/allocate_heap), $
EH : ptr_new(/allocate_heap), $
da : ptrarr(mdim,/allocate_heap), $
pa : ptrarr(mdim,/allocate_heap), $
; da0 : ptrarr(mdim,/allocate_heap), $
sub_scan_ptr : ptrarr(mdim-1,/aLLOCATE_HEAP) $
}
SSD.file = file
len = strpos(SSD.file,!os.file_sep,/reverse_search)
if len gt 0 then SSD.path = strmid(SSD.file,0,len)
SSD.class = strmid(SSD.file,len+1,strlen(file)-len)
labels = SSD.labels
get_lun,lun
openr,/XDR,lun,file
SSD.lun = lun
tmp= {$
version: 0.0, $
scanno : 0L , $
rank : 0L }
readu,lun, tmp
SSD.rank = tmp.rank
SSD.scanno = tmp.scanno
npts= intarr(tmp.rank)
readu,lun, npts
dim = reverse(npts)
isRegular=0
readu,lun, isRegular
env_fptr=0L
readu,lun, env_fptr
SSD.envPtr = env_fptr
for ir=1,tmp.rank do begin
rank=0
npts=0
cpt=0
readu,lun,rank,npts,cpt
SSD.npts(rank-1) = npts
SSD.cpt(rank-1) = cpt
IF(rank GT 1) THEN BEGIN
sub_scan_ptr=lonarr(npts)
readu,lun,sub_scan_ptr
*SSD.sub_scan_ptr[ir-1] = sub_scan_ptr ; exist only rank > 1
if keyword_set(echo) then print,'sub_scan_ptr:',*SSD.sub_scan_ptr[ir-1]
ENDIF
if keyword_set(echo) then print,'rank,npts,cpt:',rank,npts,cpt
if keyword_set(echo) then print,'ssd.npts=',ssd.npts
; read the pvname
name=''
time=''
readu,lun,name
if keyword_set(echo) then print,'pvname=',name
if strtrim(name,2) eq '' then begin
error = -1
print,'Bad file...',file
return
end
readu,lun,time
if strlen(time) eq 0 or strlen(time) gt 31 then begin
error = -1
print,'Bad file...',file
return
end
if keyword_set(echo) then print,'time=',time
SSD.pv(rank-1) = name
SSD.ts1 = time
if rank gt 1 and rank eq tmp.rank then begin
ts2 = make_array(SSD.npts(rank-1)+1,value=' ',/string)
ts2(SSD.npts(rank-1)) = SSD.ts1
*SSD.ts2 = ts2
end
nb_pos=0
nb_det=0
nb_trg=0
readu,lun,nb_pos,nb_det,nb_trg
SSD.nb_pos(rank-1) = nb_pos
SSD.nb_det(rank-1) = nb_det
SSD.nb_trg(rank-1) = nb_trg
if keyword_set(echo) then print,nb_pos,nb_det,nb_trg
; read header
num=0
FOR i=0,nb_pos-1 DO BEGIN
readu,lun, num
readu,lun,pos_info
HD_P(num,rank-1) = pos_info
id_def(num,rank-1) = 1
if keyword_set(echo) then print,'position:',i,rank,num,pos_info
if (pos_info.rxpv ne '') then begin
labels(num,rank-1) = pos_info.rxpv
labels(ntot+num,rank-1) = pos_info.rxds
labels(ntot*2+num,rank-1) = pos_info.rxeu
endif else begin
labels(num,rank-1) = pos_info.pxpv
labels(ntot+num,rank-1) = pos_info.pxds
labels(ntot*2+num,rank-1) = pos_info.pxeu
end
END