source: trunk/SRC/ToBeReviewed/STRING/tostr.pro @ 280

Last change on this file since 280 was 232, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1;+
2;
3; @file_comments
4; Convert an input in a string.
5;
6; @categories
7; String
8;
9; @param INPUT {in}{required}
10; input can not contain or be of the type of:
11;
12;   Complex floating, structure, Double-precision complex, Pointer, Object
13;   reference, Unsigned Integer, Unsigned Longword Integer, 64-bit
14;   Integer, Unsigned 64-bit Integer   
15;
16; @returns
17; a string
18;
19; @restrictions
20; If keywdvalue is an array, it will be convert in a vector.
21;
22; @restrictions
23; Beware, this function has loops, ifs ad cases everywhere. So it can
24; not be used by big keywords (with a lot of elements which are big
25; arrays).
26;
27; @examples
28;    IDL> help, tostr(1),tostr('a'),tostr(indgen(4)),tostr(['a','jkfjo'])
29;    <Expression>    STRING    = '1'
30;    <Expression>    STRING    = ''a''
31;    <Expression>    STRING    = '[0,1,2,3]'
32;    <Expression>    STRING    = '['a','jkfjo']'
33;    IDL> print, tostr(['c''est bon','c''est bon'])
34;    ['c''est bon','c''est bon']
35;
36; @history
37; Sebastien Masson (smasson\@lodyc.jussieu.fr)
38;                      18/10/1999
39;
40; @version
41; $Id$
42;
43;-
44;
45FUNCTION tostr, input
46;
47  compile_opt idl2, strictarrsubs
48;
49
50   case 1 of
51      size(input, /type) LE 5:BEGIN
52         if size(input, /type) EQ 1 then input = long(input)
53         if n_elements(input) EQ 1 then res = strtrim(input, 1) $
54         ELSE BEGIN
55            res = '['+strtrim((input)[0], 1)
56            for i = 1,  n_elements(input)-1 do res = res+','+strtrim((input)[i], 1)
57            res = res+']'
58         ENDELSE
59      END
60      size(input, /type) eq 7:BEGIN
61         if n_elements(input) EQ 1 then BEGIN
62            sinput = strrepl(input, '''', '''''')
63            res = ''''+sinput+''''
64         ENDIF ELSE BEGIN
65            res = '['''+strrepl(input[0], '''', '''''')+''''
66            for i = 1,  n_elements(input)-1 do res = res+','''+strrepl(input[i], '''', '''''')+''''
67            res = res+']'
68         ENDELSE
69      END
70      ELSE:BEGIN
71         ras = report('la fonction tostr ne marche pas pour input qui est de type '+size(input, /tname))
72         res = ''
73      END
74   ENDCASE
75
76   return, res
77end
Note: See TracBrowser for help on using the repository browser.