Efficient IDL programming [message #1508] |
Thu, 02 December 1993 15:08  |
dean
Messages: 55 Registered: March 1993
|
Member |
|
|
I would like to thank everbody who responded to my request for help in
"extracting bits from bytes". Below is a test PRO that I made to read in
the graphic file. It reads, converts, expands, enhances, and reverses my
file (from (512,64) to (512,512)) in about 30 seconds.
I started with DEC2BIN.PRO posted by Bill Thompson. This worked, but it
took awhile to go thru 32,768 calculations. Both Chris Chase and Dr. Marty
Ryba suggested "masks" which speed things up considerably.
I just wanted to check to see if anyone would know if I can illiminated
the FOR DO BEGIN loops to make this PRO a little more efficient.
Thanks again guys,
Kelly Dean
============================================================ ===================
pro test
head = bytarr(56)
premature_EOF = 1
ON_IOERROR, SHORT_GRF
;
; Read "in house" graphic file.
;
OPENR, unit, 'dtopo:gms512.grf', /GET_LUN
READU, unit, head
chead = STRING(head)
ck_imx = STRMID(chead,0,6)
;
; Verify that it is an IMX graphic file before proceeding
;
IF ( ck_imx EQ '%IMAGE' ) THEN BEGIN $
head_lgth = STRMID(chead,28,7)
IF ( head_lgth GT 56 ) THEN BEGIN $
rem_head = bytarr(head_lgth-56)
READU, unit, rem_head
ENDIF
xsize = strmid(chead,36,6)
ysize = strmid(chead,43,6)
imxgrf = bytarr(xsize,ysize/8)
graphic = bytarr(xsize,ysize)
readu, unit, imxgrf
premature_EOF = 0
SHORT_GRF: IF premature_EOF THEN PRINT, 'Short graphic'
close, unit
;
; Create mask.
;
tmp = lindgen(8)
mask = 2L^tmp
;
; Expand array(xsize,ysize/8) to array(xsize,ysize).
;
yyy = 0
FOR y = 0,(ysize/8)-1 DO BEGIN
xxx = 0
FOR x = 0,xsize-1 DO BEGIN
IF ( xxx EQ xsize ) THEN BEGIN $
xxx = 0
yyy = yyy + 1
ENDIF
; Perform the conversion ( Dr. Marty Ryba (MIT) suggestion).
graphic(xxx,yyy) = (imxgrf(x,y) and mask) ne 0
xxx = xxx + 8
ENDFOR
yyy = yyy + 1
ENDFOR
;
; Enhance value so you can see it and reverse image, then display.
;
graphic(Where(graphic EQ 001b )) = 244b
graphic = rotate(graphic,7) ; Transpose 270 deg, (Xo,-Yo)
tv, graphic
ENDIF
END
|
|
|