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

Last change on this file since 157 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

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