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

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

english and nicer header (2a)

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