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