source: trunk/SRC/ToBeReviewed/STRING/lenstr.pro @ 325

Last change on this file since 325 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
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
26;
27; @todo seb
28;
29;-
30FUNCTION lenstr, str
31;
32  compile_opt idl2, strictarrsubs
33;
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
61            xyouts,0,0,/device,str[i],width=ww
62            w[i]=ww
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
80end
81
Note: See TracBrowser for help on using the repository browser.