source: trunk/STRING/tostr.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME: tostr (to string)
6;
7; PURPOSE: convertit un input en un string.
8;
9; CATEGORY:
10;
11; CALLING SEQUENCE: res=tostr(input)
12;
13; INPUTS: input ne peut pas contenir ou etre de type:
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; KEYWORD PARAMETERS: none
20;
21; OUTPUTS: un string
22;
23; COMMON BLOCKS:
24;
25; SIDE EFFECTS:
26;
27;   Si un element de input contient un tableau, il sera
28;   convertit en vecteur.
29;
30; RESTRICTIONS:
31;
32;   attention cette fonction comporte des boucles, des if et des cases
33;   ds tous les sens. Elle ne doit donc pas etre utilisee avec des
34;   inputs de grosse taille (avec bcp d''elements et avec des
35;   elements etant de gros tableaux).
36; EXAMPLE:
37;    IDL> help, tostr(1),tostr('a'),tostr(indgen(4)),tostr(['a','jkfjo'])
38;    <Expression>    STRING    = '1'
39;    <Expression>    STRING    = ''a''
40;    <Expression>    STRING    = '[0,1,2,3]'
41;    <Expression>    STRING    = '['a','jkfjo']'
42;    IDL> print, tostr(['c''est bon','c''est bon'])
43;    ['c''est bon','c''est bon']
44;
45; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
46;                      18/10/1999
47;-
48;------------------------------------------------------------
49;------------------------------------------------------------
50;------------------------------------------------------------
51FUNCTION tostr, input
52
53   case 1 of
54      size(input, /type) LE 5:BEGIN
55         if size(input, /type) EQ 1 then input = long(input)
56         if n_elements(input) EQ 1 then res = strtrim(input, 1) $
57         ELSE BEGIN
58            res = '['+strtrim((input)[0], 1)
59            for i = 1,  n_elements(input)-1 do res = res+','+strtrim((input)[i], 1)
60            res = res+']'
61         ENDELSE
62      END
63      size(input, /type) eq 7:BEGIN
64         if n_elements(input) EQ 1 then BEGIN
65            sinput = strrepl(input, '''', '''''')
66            res = ''''+sinput+''''
67         ENDIF ELSE BEGIN
68            res = '['''+strrepl(input[0], '''', '''''')+''''
69            for i = 1,  n_elements(input)-1 do res = res+','''+strrepl(input[i], '''', '''''')+''''
70            res = res+']'
71         ENDELSE
72      END
73      ELSE:BEGIN
74         ras = report('la fonction tostr ne marche pas pour input qui est de type '+size(input, /tname))
75         res = ''
76      END
77   ENDCASE
78
79   return, res
80end
Note: See TracBrowser for help on using the repository browser.