[2] | 1 | function lenstr,str |
---|
| 2 | ;+ |
---|
| 3 | ; ROUTINE: lenstr |
---|
| 4 | ; USEAGE: result=lenstr(str) |
---|
| 5 | ; |
---|
| 6 | ; input: |
---|
| 7 | ; str a single string or string array. |
---|
| 8 | ; |
---|
| 9 | ; output: |
---|
| 10 | ; result length of the string(s) in normalized units |
---|
| 11 | ; the number of elements of RESULT matches the number of |
---|
| 12 | ; elements of STRING. |
---|
| 13 | ; |
---|
| 14 | ; procedure: |
---|
| 15 | ; This function returns the physical length of the |
---|
| 16 | ; string on the output device, not the number of |
---|
| 17 | ; characters. This is done by first switching to 'X' |
---|
| 18 | ; and writing the string(s) with XYOUTS in graphics |
---|
| 19 | ; mode 5, which disables display to the screen but |
---|
| 20 | ; does not interfere with operation of XYOUTS. The |
---|
| 21 | ; WIDTH keyword parameter of XYOUTS is used to |
---|
| 22 | ; retrieve the physical length of the string(s). |
---|
| 23 | ; |
---|
| 24 | ; author: Paul Ricchiazzi 7apr93 |
---|
| 25 | ; Institute for Computational Earth System Science |
---|
| 26 | ; University of California, Santa Barbara |
---|
| 27 | ;- |
---|
| 28 | |
---|
| 29 | dsave=!d.name |
---|
| 30 | |
---|
| 31 | thisOS = !VERSION.OS_FAMILY |
---|
| 32 | thisOS = STRMID(thisOS, 0, 3) |
---|
| 33 | thisOS = STRUPCASE(thisOS) |
---|
| 34 | CASE thisOS of |
---|
| 35 | 'MAC': SET_PLOT, thisOS |
---|
| 36 | 'WIN': SET_PLOT, thisOS |
---|
| 37 | ELSE: SET_PLOT, 'X' |
---|
| 38 | ENDCASE |
---|
| 39 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
| 40 | !p.color=0 |
---|
| 41 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
| 42 | |
---|
| 43 | device,get_graphics=oldg,set_graphics=5 |
---|
| 44 | if keyword_set(charsize) eq 0 then charsize=1 |
---|
| 45 | nn=n_elements(str) |
---|
| 46 | |
---|
| 47 | case nn of |
---|
| 48 | |
---|
| 49 | 0:w=0 |
---|
| 50 | |
---|
| 51 | 1:xyouts,0,0,/device,str,width=w |
---|
| 52 | |
---|
| 53 | else:begin |
---|
| 54 | w=fltarr(nn) |
---|
| 55 | for i=0,nn-1 do begin |
---|
| 56 | xyouts,0,0,/device,str(i),width=ww |
---|
| 57 | w(i)=ww |
---|
| 58 | endfor |
---|
| 59 | end |
---|
| 60 | endcase |
---|
| 61 | |
---|
| 62 | fac1=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device1 width |
---|
| 63 | |
---|
| 64 | device,set_graphics=oldg |
---|
| 65 | set_plot,dsave |
---|
| 66 | IF dsave EQ 'X' OR dsave EQ 'MAC' OR dsave EQ 'WIN' then BEGIN |
---|
| 67 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
| 68 | !p.color=0 |
---|
| 69 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
| 70 | ENDIF |
---|
| 71 | |
---|
| 72 | fac2=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device2 width |
---|
| 73 | |
---|
| 74 | return,w*fac2/fac1 ; string width adjusted for device width |
---|
| 75 | end |
---|
| 76 | |
---|