-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan2d__define.pro
2457 lines (2194 loc) · 66.6 KB
/
scan2d__define.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.
;*************************************************************************
;
; scan2d__define.pro
;
@u_read.pro
@scan_colorbar.pro
@scan2d_overlay.pro
@scan2d_convert.pro
@scan2d_roi.pro
PRO scan2d::ROIpick,no,picke
if n_elements(no) eq 0 then no = self.seqno
self->point_lun,no-1
self->read,im=im,x=x,y=y,/view
roifile = self.outpath+self.name+'_'
multiroi_pick,im,class=roifile
END
PRO fileSeqString,no,suf0
suf0 = '0000'
suf = strtrim(no,2)
ln = strlen(suf)
strput,suf0,suf,4-ln
if no gt 9999 then suf0=suf
END
PRO parse_num0,instring,ids,sep=sep
Keysepar = '-'
if keyword_set(sep) then Keysepar = sep
res = strpos(instring,keysepar)
if res ne -1 then begin
str = str_sep(instring,keysepar,/trim)
no = fix(str(1)) - fix(str(0)) + 1
ids = indgen(no) + fix(str(0))
endif else begin
com = strpos(instring,',')
if com ne -1 then begin
str = str_sep(instring,',')
ids = fix(str)
endif else begin
str = str_sep(instring,' ')
ids = fix(str)
end
end
END
; parse by sep1 first then by sep2
; default sep1=',' sep2='-'
; instring = '1,2:5,7'
; instring = '1,2-5,7'
PRO parse_num,instring,res,sep1=sep1,sep2=sep2
d_sep1 = ','
d_sep2 = '-'
if keyword_set(sep1) then d_sep1 = sep1
if keyword_set(sep2) then d_sep2 = sep2
str = str_sep(instring,d_sep1,/trim)
res = fix(str(0))
for i=0,n_elements(str)-1 do begin
newstr = strtrim(str(i),2)
if strlen(newstr) gt 0 then begin
parse_num0,newstr,ids,sep=d_sep2
if i eq 0 then begin
if n_elements(ids) gt 1 then res = ids
end
if i gt 0 then res = [res,ids]
end
end
END
PRO scan2d::NewPos,pos_id, outfile=outfile
;+
; NAME:
; scan2d::NEWPOS
;
; PURPOSE:
; This method allows the user generate a new 2D image file with
; new postioner selected instead of default positioner P1
;
; ARGUMENTS:
; POS_ID: New positioner # selected (must > 1 and < 5)
; default is positioner 2.
;
; KEYWORD:
; OUTFILE: Specifies the output image file, default is the
; temporary file name 'tmp.image' is used.
;
; RESTRICTION:
; The positioner id entered must be defined for the scan1 record.
;
; EXAMPLES
; In this example the orignal 1D and 2D scan data are stored in 'junk2'
; and 'junk2.image'. The purpose is to create a new image file with
; positioner2 values as the X vector, the new image file will be saved
; as 'junk2.image_2'. The v3 object is used to varify the new image file.
;
; v2 = obj_new('scan2d',file='junk2.image')
; v2->newPos,2
;
; v3 = obj_new('scan2d',file='junk2.image_2')
; v3->view,1
;-
if n_elements(pos_id) eq 0 then pos_id=2
if pos_id lt 2 then return
len = strpos(self.name,'.image')
if len gt 0 then file1 = strmid(self.name,0,len)
if self.path ne '' then file1 = self.path+!os.file_sep+ file1
v1 = obj_new('scan1d',file=file1)
if obj_valid(v1) eq 0 then begin
str = ['Usage: v2->newPos, pos_id, outfile="new.image"', $
'where', $
'V2 must be an "scan2d" object', $
'pos_id specifies position #', $
'** 1D scan file not found **']
r = dialog_message(str,/error)
return
end
nfile = 'tmp.image' ;self.name+'_2'
if keyword_set(outfile) then nfile=outfile
u_openw,unit2,nfile,/XDR
unit = self.unit
self->point_lun,0
FOR seqno = 1,self.maxno DO BEGIN
u_read,unit,pvs
u_read,unit,nos
u_read,unit,x
u_read,unit,y
u_read,unit,im
scan1d = nos(0)-nos(2)
v1->read,scan1d,pa=pa,da=da,np=np,nd=nd,x_names=x_names, $
x_descs=x_descs,x_engus=x_engus
; output new image file
sz = size(pa)
if sz(0) eq 1 then pos_id = 1
if sz(0) eq 2 and pos_id gt sz(2) then begin
x = indgen(sz(1))
xlabel = 'P'+strtrim(pos_id,2)
endif else begin
xlabel = x_descs(pos_id-1) +'(' + x_engus(pos_id-1) +')'
x = pa(*,pos_id-1)
end
pvs(*,3) = 0
pvs(0,3) = byte(xlabel)
u_write,unit2,pvs
u_write,unit2,nos
u_write,unit2,x
u_write,unit2,y
u_write,unit2,im
END
u_close,unit2
obj_destroy,v1
u_close,unit
if keyword_set(outfile) then return
str = !os.mv + ' ' + nfile +' '+self.path
spawn,str
END
PRO scan2d::ASCII1D,lineno,endno=endno,all=all,nowin=nowin,format=format,group=group
;+
; NAME:
; scan2d::ASCII1D
;
; PURPOSE:
; This method allows the user to extract all detectors data
; from a 2D scan. The name convention of ASCII file will be the
; image file suffixed with its corresponding 1D scan sequence number.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]ASCII1D [,Lineno] [,Endno=endno] [,/ALL] $
; [,/NOWIN] [,FORMAT=format] [,GROUP=group]
;
; ARGUMENTS:
; Lineno: Specifies the 1D line scan # to be extracted from a
; given 2D scan.
;
; KEYWORDS:
; ENDNO: If specified, ASCII files from the 1D scan lineno to the
; endno will be created
; ALL: If specified, ASCII files for all 1D scan lines from a
; given 2D scan will be created.
; NOWIN: If specified, only the ASCII files will be created but the
; xdisplayfile window will not be shown.
; FORMAT: If specified, override the default output format
; GROUP: Specifies the parent group ID, the destroy of parent window
; results the destroy of this child window
;
; EXAMPLE:
; Example 1 extracts the 10th scan line from the current 2D scan.
; Example 2 generates all the 1D scan data file without displaying window.
; Example 3 extracts the 1D scan 3 to 5 from the current 2D scan.
;
; v2->ASCII1D,10
; v2->ASCII1D,/ALL,/NOWIN
; v2->ASCII1D,3,endno=5
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Feb 18, 2000.
; xx-xx-xxxx xxx comment
;-
scanno = self.scanno_current
self->Images,scanno,image_array,def,vmax,vmin,zdesc=zdesc,panimage=panimage,print=print
if n_elements(lineno) eq 0 then lineno=1
if lineno gt self.height then begin
r = dialog_message(['v->ascii1d, lineno', $
'Lineno can not exceeds '+string(self.height)],/error)
return
end
w = self.width
h = self.height
px = self.xarr(0:w-1)
py = self.yarr(0:h-1)
fmt = 'F18.8'
ifmt = strmid(fmt,1,strpos(fmt,'.')-1)
wd = fix(ifmt)
nd = ceil(total(def))
st0 = string(replicate(32b,(2+nd)*wd))
sthd = st0
sthd2 = st0
strput,sthd,';',0
strput,sthd,'I',6
strput,sthd,'P1',wd
strput,sthd2,';',0
strput,sthd2,self.x_desc,wd
ip = 10 + wd
ji = 0
for j=0,nd-1 do begin
if def(j) gt 0 then begin
dip = ip + ji*wd
st1 = 'D'+strtrim(j+1,2)
st2 = zdesc(j)
strput,sthd,st1,dip
strput,sthd2,st2,dip
ji = ji+ 1
end
end
dir = self.outpath + 'ASCII' + !os.file_sep
startno = lineno
if n_elements(endno) eq 0 then endno = lineno
if keyword_set(all) then begin
startno=1
endno = self.height
end
for lineno = startno,endno do begin
seqno = self.scanno-self.height+lineno
fileSeqString,seqno,suf0
outfile = dir+self.name+'.S'+suf0
openw,unit,outfile,/get_lun
printf,unit,'; 1D ASCII detector data extracted from the image arrays'
printf,unit,'; 2D Scan # :',strtrim(scanno,2), $
', width='+strtrim(w,2), $
', height='+strtrim(h,2), $
', 1D Scan Line # :',lineno
printf,unit,'; 1D scan Line # @ y(',strtrim(lineno-1,2),') = ',py(lineno-1)
printf,unit,'; Equivalent 1D Scan # :',seqno
printf,unit,sthd
printf,unit,sthd2
for i=0,w-1 do begin
st = st0
strput,st,string(i),0
strput,st,strtrim(px(i),2),10
ip = 10 + wd
ji = 0
for j=0,n_elements(def)-1 do begin
if def(j) gt 0 then begin
dip = ip + wd*ji
st1 = strtrim(image_array(i,lineno-1,j),2)
strput,st,st1,dip
ji = ji+1
end
end
printf,unit,st
end
free_lun,unit
close,unit
if keyword_set(nowin) eq 0 then $
xdisplayfile,outfile,group=group
end
END
PRO scan2d::DetListString,detno=detno,list
; return the list strin
; if detno specified find from every scan
; if nothing found return ''
;
i = self.scanno_current
if i lt 1 then i = 1
list = ''
if keyword_set(detno) then begin
if detno lt 1 then detno = 1
i1 = 1
i2 = self.scanno_2d_last
for i=i1,i2 do begin
no = self.image_no(i-1)+detno
if no le self.image_no(i) then begin
if i eq 1 then list=strtrim(no,2) else $
list = list+','+strtrim(no,2)
end
end
endif else $
list = strtrim(self.image_no(i-1)+1,2)+'-'+strtrim(self.image_no(i),2)
END
PRO scan2d::ASCII2D,detno,pick=pick,all=all,whole=whole,nowin=nowin,format=format,group=group
;+
; NAME:
; scan2d::ASCII2D
;
; PURPOSE:
; This method allows the user to create the 2D ASCII data file(s)
; for the selected detector number. The ASCII file created will be
; automatically suffixed with its 4 digit image sequence number and
; '.txt'
;
; CALLING SEQUENCE:
; Obj->[scan2d::]ASCII2D, Detno [,/ALL] [,/NOWIN] [,FORMAT=format]
; [,/WHOLE] [,GROUP=group]
;
; ARGUMENTS:
; Detno: Specify the detector number desired for current opened
; 2D scan, default 1.
;
; KEYWORDS:
; WHOLE: If specified, pick all detectors from the current 2D scan #
; ALL: If specified, pick all images from the 2D image file
; PICK: If specified, pick the same detno out of every 2D scan
; NOWIN: If specified, only the ASCII files will be created but the
; xdisplayfile window will not be shown.
; FORMAT: If specified, override the default output format
; GROUP: Specifies the parent group ID, the destroy of parent window
; results the destroy of this child window
;
; EXAMPLE:
; Example 1 generates ASCII report for detector 5 for the current 2D scan #
;
; v2->ascii2d,5
;
; Example 2 generates ASCII report for detector 5 for every 2D scan
; contained in the image file.
;
; v2->ascii2d,5,/PICK
;
;-
begin_no = 1
end_no = self.scanno_2d_last
detector = 1
if n_elements(detno) then detector = detno
if keyword_set(pick) then begin
self->detliststring,detno=detector,lists
if lists eq '' then begin
r = dialog_message('Detector'+strtrim(detector,2)+' not found!',/Info)
return
end
self->ascii,lists,format=format,nowin=nowin,GROUP=group
return
end
if keyword_set(all) then begin
for i=begin_no,end_no do begin
for j=self.image_no(i-1),self.image_no(i)-1 do begin
list = j+1
self->ascii,list,format=format,nowin=nowin,GROUP=group
end
end
return
end
if keyword_set(whole) then self->detliststring,list
self->ascii,list,format=format,nowin=nowin,GROUP=group
END
PRO scan2d::ASCII,list,nowin=nowin,format=format,GROUP=group
;+
; NAME:
; scan2d::ASCII
;
; PURPOSE:
; This method allows the user to create a list of ASCII data files
; based on the user specified list of image numbers. The name convention
; of each ASCII file will be the image file suffixed with its 4 digit
; image number.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]ASCII, List, /NOWIN [,FORMAT=format]
;
; ARGUMENTS:
; List: List is used to specify the sequence of image files to be
; generated. It can be a list of short integers which
; explicitly specify the desired images or it can be
; string variable. If it is a string, it will be parsed
; into a list of image number first by this method.
; The user has to insure that the number entered is valid
; for normal operation of this method.
;
; KEYWORDS:
; NOWIN: If specified, only the ASCII files will be created but the
; xdisplayfile window will not be shown.
; FORMAT: If specified, override the default output format
; GROUP: Specifies the parent group ID, the destroy of parent window
; results the destroy of this child window
;
; EXAMPLE:
; Example 1 creates the ASCII data files for the image [10,20,30] from the
; 'junk2.image', and each file will be displayed automatically.
; The object v2 need to be defined only if it is not yet defined.
;
; v2 = obj_new('scan2d',file='junk2.image')
; v2->ASCII,[10,20,30]
;
; Example 2 creates the ASCII data files for the images 10, 20 to 30, and
; 40 from the 'junk2.image', and no ASCII file will be displayed.
;
; v2->ASCII,'10,20-30,40',/NOWIN
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jan 19, 1998.
; 01-21-2000 Use current image # of the defined object
;-
if n_elements(list) lt 1 then list = self.seqno
; parse the string list
sz = size(list)
if sz(n_elements(sz)-2) eq 7 then begin
sep1=','
if strpos(list,sep1) lt 0 then sep1=' '
if strpos(list,':') gt 0 then parse_num,string(list),res,sep1=sep1,sep2=':' else $
parse_num,string(list),res,sep1=sep1
print,'Image #:',res
list = res
end
; integer list
for i=0,n_elements(list)-1 do begin
self->point_lun,list(i)-1
self->read
if keyword_set(nowin) then self->datatotext,/outfile,/nowin,Group=group else $
self->datatotext,/outfile,Group=group
end
END
;
; bind two 2D scans into one 2D scan images
;
PRO scan2d::bindImage,file1=file1,file2=file2, outfile=outfile, h1s=h1s, h2s=h2s, h1e=h1e, h2e=h2e, im1=im1, im2=im2, s1=s1,s2=s2
;+
; NAME:
; scan2d::bindImage
;
; PURPOSE:
; This method combines images from two different 2D scan object and
; create a new 2D image and saved the combined images into a new file.
; The output file inheritates the scan number and detector number
; from the FILE1 for the combined images.
;
; If the 2D image file1 and file2 are same then 2 scans from the same
; file is combined into one scan.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]bindImage,File1=file1, im1=im1,
; File2=file2, im2=im2, outfile='...'
;
; ARGUMENTS:
; None.
;
; KEYWORDS:
; OUTFILE: Specifies the output file for combined 2D images
; FILE1: Specifies the 2D image file1
; Im1: Specifies the starting image seq # of the first scan
; Im2: Specifies the starting image seq # of the second scan
; FILE2: If specified, the Im2 is from a different 2D image file2
; S1: If specified, it returns the 2D scan # for Im1
; S2: If specified, it returns the 2D scan # for Im2
; h1s: Optional, specifies the y1 start index, defaults 0
; h1e: Optional, specifies the y1 end index, defaults height
; h2s: Optional, specifies the y2 start index, defaults 0
; h2e: Optional, specifies the y2 end index, defaults height
;
; RESTRICTION:
; The number of detectors must be exactly same in both files.
; The obj variable names internally used by this routine are
; cv1,cv2,cv3, a user have to avoid to use these name.
;
; EXAMPLE:
; Following example binds the images of 2D # 31 with
; images of 2D scan # 33 from the same file. The starting image #
; of scan # 31 is 205. The starting image # of scan # 33 is 217.
; We want to bind these two scans into one new 2D scan. The new 2D
; scan for each detector will be saved in 'new.image'.
; The new scan will inherit the scan description from the 2D scan # 31.
;
; The object v2 need to be defined only if it is not yet defined.
;
; filename1='/home/sricat/CHA/user/s2idd/15nov98_data.01.image'
;
; v2 = obj_new('scan2d',file=filename1)
; v2->view,205,/noplot
; v2->point_lun,204
; v2->bindimage,file1=filename1, im1=205, im2=217, $
; outfile='new.image'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, April 16, 1999
; xx-xx-xxxx comment
;-
if keyword_set(file1) * keyword_set(im1) *keyword_set(im2)* keyword_set(outfile) eq 0 then begin
print,"Usage: Obj->bindImage,file1='...',im1=im1, $"
print," file2='...',im2=im2,outfile='new.image'"
return
end
image1=0
image2=0
if keyword_set(outfile) then newname=strtrim(outfile,2)
if keyword_set(file1) then filename1 = file1
filename2=file1
if keyword_set(file2) then filename2 = file2
if keyword_set(IM1) then image1=im1-1
if keyword_set(IM2) then image2=im2-1
if keyword_set(h1s) then y1s=h1s
if keyword_set(h1e) then y1e=h1e
cv1 = obj_new('scan2d',file=filename1)
cv2 = obj_new('scan2d',file=filename2)
cv1->point_lun,image1
cv1->read,scanno_2d=scan1
cv1->panimage,scan1
ij1 = cv1.image_no(scan1-1)
t_det = cv1.image_no(scan1) - ij1
if t_det gt 0 and t_det lt 15 then numdetector = t_det-1
cv2->point_lun,image2
cv2->read,scanno_2d=scan2
cv2->panimage,scan2
ij2=cv2.image_no(scan2-1)
s1=scan1
s2=scan2
det1=0
det2=numdetector
for i=det1,det2 do begin
cv1->point_lun,ij1 + i
cv1->read,width=w1,height=h1,detector=d1,x=x1,y=y1,im=im1
cv2->point_lun,ij2 + i
cv2->read,width=w2,height=h2,detector=d2,x=x2,y=y2,im=im2
h11 = 0
h12 = h1-1
if keyword_set(y1s) then h11=y1s-1
if keyword_set(y1e) then h12=y1e-1
if h11 lt 0 then h11=0
if h12 ge h1 then h12=h1-1
h21 = 0
h22 = h2-1
if keyword_set(y2s) then h21=y2s-1
if keyword_set(y2e) then h22=y2e-1
if h21 lt 0 then h21=0
if h22 ge h2 then h22=h1-1
th1 = h12-h11+1
th2 = h22-h21+1
w3 = w1
h3 = th1+th2
im3 = make_array(w1,h3)
y3 = [y1(h11:h12),y2(h21:h22)]
im3(0,0) = im1(*,h11:h12)
im3(0,th1) = im2(*,h21:h22)
x3 = x1
;print,total(im3(*,h12)-im1(*,h12))
self->read
pvs = make_array(60,6,/byte)
pvs(0,0) = byte(self.x_pv)
pvs(0,1) = byte(self.y_pv)
pvs(0,2) = byte(newname)
pvs(0,3) = byte(self.x_desc)
pvs(0,4) = byte(self.y_desc)
pvs(0,5) = byte(self.z_desc)
const = make_array(6,/int)
const(0) = self.scanno
const(1) = w3
const(2) = h3
const(3) = self.detector - 1
const(4) = self.scanno_current
const(5) = h3
self.width = w3
self.height = h3
self.y_req_npts = h3
self.xarr = x3
self.yarr = y3
self.image = im3
; window,1,xsize=500,ysize=500
; tvscl,congrid(im3,400,400),50,50
if i eq 0 then u_openw,unit,newname else $
u_openw,unit,newname,/append
u_write,unit,pvs
u_write,unit,const
u_write,unit,x3
u_write,unit,y3
u_write,unit,im3
u_close,unit
end
free_lun,cv1.unit
free_lun,cv2.unit
obj_destroy,cv1
obj_destroy,cv2
cv3 = obj_new('scan2d',file=newname)
cv3->read
cv3->point_lun,0
cv3->panimage
free_lun,cv3.unit
obj_destroy,cv3
END
PRO scan2d::dataToText,data,px,py,title=title,unit=unit,outfile=outfile,nowin=nowin,format=format,GROUP=group
;+
; NAME:
; scan2d::DataToText
;
; PURPOSE:
; For the current scan2d object, this method creates its tabulated 2D
; image data in a disk file and uses the xdisplayfile command to
; show the contents of the created ASCII file.
;
; If the outfile is not specified it will try to create the ASCII
; file in the following order: try the data directory first,
; if failed then try the user starting directory, if still failed
; then try the user home directory.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]DataToText, Data, Px, Py, OUTFILE='outfile', /NOWIN
;
; ARGUMENTS:
; Data: Optional output variable, gives the output image data array.
; Px: Optional output variable, gives the X positioner vector.
; Py: Optional output variable, gives the Y positioner vector.
;
; KEYWORDS:
; OUTFILE: If not specified, the default outfile text file name with
; 'view2d_data.txt' will be used.
;
; If OUTFILE=1 is specified, then the outfile name will be
; generated from the image file name suffixed with 4 digit
; image number plus '.txt'.
;
; If OUTFILE='anyname' then the outfile name suffixed with
; '.txt' will be used by the text file.
;
; NOWIN: If specified, the xdisplayfile window will not be shown.
; FORMAT: If specified, override the default F17.7 format.
; GROUP: Specifies the parent group widget ID.
;
; EXAMPLE:
; Following example reads and plots the 135th image from file 'junk2.image'
; and generates an ASCII outfile with file name 'junk2.image.0135'.
; The object v2 need to be defined only if it is not yet defined.
;
; v2 = obj_new('scan2d',file='junk2.image')
; v2->View,135
; v2->datatotext,/OUTFILE
;
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jan 19, 1998.
; 05-15-1998 bkc Catch error for openw
; 05-11-1998 bkc Add fileSeqString routine, add suffix '.txt' to seqno
; If outfile specified, no directory check will be done.
; 02-17-2000 bkc Add format keyword, default suffix use scan # and
; detector# '.S#D#'
;-
w = self.width
h = self.height
data = make_array(w,h)
ln = 1L * w * h
data(0:w-1,0:h-1) = self.image(0:ln-1)
px = self.xarr(0:w-1)
py = self.yarr(0:h-1)
no = self.image_no(self.scanno_current-1) + self.detector
title = '2D Scan # '+string(self.scanno_current) + $
', Image seqno ' + string(no) + ', Detector ='+ $
string(self.detector) + ', '
if keyword_set(outfile) then begin
sz = size(outfile)
if sz(n_elements(sz)-2) ne 7 then begin
suf0 = ''
fileSeqString,no,suf0
file = self.name+'.'+ suf0+ '.txt'
endif else file = outfile+ '.txt'
end
if n_elements(data) eq 0 then begin
res = dialog_message('Error: no SDS data available!',/info)
return
end
filename = 'view2d_data.txt'
if n_elements(file) ne 0 then filename = file
s = size(data)
no = s(0)
dim = make_array(no)
dim = s(1:no)
type = s(n_elements(s)-2)
T1='' & T2=''
if n_elements(title) ne 0 then T1 = title
if n_elements(unit) ne 0 then T2 = unit
s1 = '; data('+strtrim(dim(0),2)
for i=1,no-1 do begin
s1 = s1 + ',' + strtrim(dim(i),2)
end
s1 = s1 + ')'
st = ['; ' + T1 + T2 ]
r = strpos(filename,!os.file_sep)
if r lt 0 then begin
dir = self.outpath + 'ASCII' + !os.file_sep
found = findfile(dir,count=ct)
if ct eq 0 then spawn,!os.mkdir + ' '+dir
report = dir+filename
endif else report = filename
openw,fw,report,/get_lun
printf,fw,st
printf,fw,s1
printf,fw, '; ------------------------------'
;
; BYTE type data
;
if type eq 1 then begin
if no eq 1 then begin
BytesToStrings,data,outdata,lrecl=80
printf,fw,outdata
endif else begin
newdata = string(data)
for i=0,dim(1)-1 do printf,fw,newdata(i)
end
free_lun,fw
if keyword_set(nowin) then return
xdisplayfile,dir+filename
; id = CW_TERM(widget_ids.textdata,filename=filename,/reset)
return
end
;
; other type
;
fmt = 'F17.7'
if keyword_set(format) then fmt = format
ifmt = 'I'+strmid(fmt,1,strpos(fmt,'.')-1)
if no eq 1 then begin
f1 = '(I,'+fmt+')' ; f1 = '(I,'+fmt+')'
for j=0,dim(0)-1 do begin
printf,fw,format=f1,j,data(j)
end
free_lun,fw
if keyword_set(nowin) then return
xdisplayfile,report ;dir+filename
; id = CW_TERM(widget_ids.textdata,filename=filename,/reset)
return
end
if no eq 2 then begin
f0 = '("; (yvalues)",'+ '5000('+fmt+',:))'
if n_elements(py) gt 0 then printf,fw,format=f0,py
if n_elements(py) gt 0 then begin
f1 = '('+fmt+',I,'+strtrim(dim(1),2)+'('+fmt+'))'
f0 = '("; \ Y",'+strtrim(dim(1),2)+ifmt+',/,"; X \",/,"; (xvalues)")'
endif else begin
f0 = '("; \ Y",'+strtrim(dim(1),2)+ifmt+',/,"; X \",/)'
f1 = '(I,'+strtrim(dim(1),2)+'('+fmt+'))'
end
printf,fw,format=f0,indgen(dim(1))
newdata = transpose(data)
d1 = dim(1)
d2 = dim(0)
temp = make_array(dim(1))
for j=0,d2-1 do begin
temp = newdata(0:d1-1,j)
if n_elements(px) gt 0 then printf,fw,format=f1,px(j),j,temp else $
printf,fw,format=f1,j,temp
end
free_lun,fw
if keyword_set(nowin) then return
xdisplayfile,report ;dir+filename
; id = CW_TERM(widget_ids.textdata,filename=filename,/reset)
return
end
if no eq 3 then begin
f0 = '("J = ",'+strtrim(dim(1),2)+'I10,/)'
f1 = '(I,'+strtrim(dim(1),2)+''+fmt+')'
ij=dim(0)*dim(1)
newdata = make_array(dim(0),dim(1))
for k=0,dim(2)-1 do begin
printf,fw,''
printf,fw,'K = ',strtrim(k+1,2)
printf,fw,format=f0,indgen(dim(1))
k1 = ij * k
k2 = ij - 1 + k1
d1=dim(0)-1
d2=dim(1)-1
newdata(0:d1,0:d2)=data(k1:k2)
new = transpose(newdata)
d1 = dim(1)
d2 = dim(0)
for j=0,d2-1 do begin
j1=j*d1
j2 = j1+d1-1
x1 = new(j1:j2)
printf,fw,format=f1,j,x1
end
end
free_lun,fw
if keyword_set(nowin) then return
xdisplayfile,report ;dir+filename
; id = CW_TERM(widget_ids.textdata,filename=filename,/reset)
return
end
END
PRO scan2d::Open,filename,wid
;+
; NAME:
; scan2d::Open
;
; PURPOSE:
; This method opens the 2D image file according to the data binary type.
; It supports both native binary type and XDR binary type.
;
; This method is automatically called by the object creation method.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]Open, Filename [,Wid]
;
; ARGUMENTS:
; FILENAME: Specifies the 2D image file (generated by the data catcher)
; WID: Optional input, specifies the input droplist widget ID to
; reflect the binary TYPE in an existing widget program
;
; KEYWORDS:
; None.
;
; EXAMPLE:
; Following example shows how to explicitly open the 2D image file with
; name 'junk2.image', and the file pointer is positioned at the beginning
; of the file.
; The object v2 need to be defined only if it is not yet defined.
;
; v2 = obj_new('scan2d')
; v2->open, 'junk2.image'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Jan 19, 1998.
; xx-xx-xxxx comment
;-
; check for XDR format
if n_params() eq 0 then begin
st = ['Usage: obj->Open, Filename','', ' Input image filename is required']
res = widget_message(st,/Error)
return
end
if !d.name eq 'X' then begin
type = 0
u_openr,unit,filename
u_read,unit,pvs
if string(byte(pvs(*,0))) eq '' then begin
u_close,unit
u_openr,unit,filename,/XDR
type = 1
end
endif else begin
u_openr,unit,filename,/XDR
type = 1
end
if n_params() eq 2 then $
WIDGET_CONTROL,wid,set_droplist_select=type
; get path
self.name = filename
pos = rstrpos(filename, !os.file_sep)
if pos gt 0 then begin
self.path = strmid(filename,0,pos)
self.name = strmid(filename,pos+1,strlen(filename))
endif else begin
self.path = self.home
end
self.unit = unit
self.type = type
self.XDR = self.type
self.opened = self.unit
END
PRO scan2d::Index,filename
;+
; NAME:
; scan2d::Index
;
; PURPOSE:
; This method explicitly reads in the whole 2D image file and creates
; the index structure for the image file. It then moves the file pointer
; at the beginning of the file.
;
; This method is automatcally called by the obj_new creation if the file
; keyword is specified on the object creation.
;
; CALLING SEQUENCE:
; Obj->[scan2d::]Index, Filename
;
; ARGUMENTS:
; FILENAME: Specifies name of the 2D image file (generated by the data catcher)
;
; KEYWORDS:
; None.
;
; EXAMPLE: