;+ ; ROUTINE: lenstr ; USEAGE: result=lenstr(str) ; ; input: ; str a single string or string array. ; ; output: ; result length of the string(s) in normalized units ; the number of elements of RESULT matches the number of ; elements of STRING. ; ; procedure: ; This function returns the physical length of the ; string on the output device, not the number of ; characters. This is done by first switching to 'X' ; and writing the string(s) with XYOUTS in graphics ; mode 5, which disables display to the screen but ; does not interfere with operation of XYOUTS. The ; WIDTH keyword parameter of XYOUTS is used to ; retrieve the physical length of the string(s). ; ; author: Paul Ricchiazzi 7apr93 ; Institute for Computational Earth System Science ; University of California, Santa Barbara ; ; @todo seb ; ;- FUNCTION lenstr, str ; compile_opt idl2, strictarrsubs ; dsave=!d.name thisOS = !VERSION.OS_FAMILY thisOS = STRMID(thisOS, 0, 3) thisOS = STRUPCASE(thisOS) CASE thisOS of 'MAC': SET_PLOT, thisOS 'WIN': SET_PLOT, thisOS ELSE: SET_PLOT, 'X' ENDCASE !p.BACKGROUND=(!d.n_colors-1) < 255 !p.color=0 if !d.n_colors gt 256 then !p.background='ffffff'x device,get_graphics=oldg,set_graphics=5 if keyword_set(charsize) eq 0 then charsize=1 nn=n_elements(str) case nn of 0:w=0 1:xyouts,0,0,/device,str,width=w else:begin w=fltarr(nn) for i=0,nn-1 do begin xyouts,0,0,/device,str[i],width=ww w[i]=ww endfor end endcase fac1=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device1 width device,set_graphics=oldg set_plot,dsave IF dsave EQ 'X' OR dsave EQ 'MAC' OR dsave EQ 'WIN' then BEGIN !p.BACKGROUND=(!d.n_colors-1) < 255 !p.color=0 if !d.n_colors gt 256 then !p.background='ffffff'x ENDIF fac2=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device2 width return,w*fac2/fac1 ; string width adjusted for device width end