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 | FUNCTION tostr, input |
---|
45 | ; |
---|
46 | compile_opt idl2, strictarrsubs |
---|
47 | ; |
---|
48 | |
---|
49 | case 1 of |
---|
50 | size(input, /type) LE 5:BEGIN |
---|
51 | if size(input, /type) EQ 1 then input = long(input) |
---|
52 | if n_elements(input) EQ 1 then res = strtrim(input, 1) $ |
---|
53 | ELSE BEGIN |
---|
54 | res = '['+strtrim((input)[0], 1) |
---|
55 | for i = 1, n_elements(input)-1 do res = res+','+strtrim((input)[i], 1) |
---|
56 | res = res+']' |
---|
57 | ENDELSE |
---|
58 | END |
---|
59 | size(input, /type) eq 7:BEGIN |
---|
60 | if n_elements(input) EQ 1 then BEGIN |
---|
61 | sinput = strrepl(input, '''', '''''') |
---|
62 | res = ''''+sinput+'''' |
---|
63 | ENDIF ELSE BEGIN |
---|
64 | res = '['''+strrepl(input[0], '''', '''''')+'''' |
---|
65 | for i = 1, n_elements(input)-1 do res = res+','''+strrepl(input[i], '''', '''''')+'''' |
---|
66 | res = res+']' |
---|
67 | ENDELSE |
---|
68 | END |
---|
69 | ELSE:BEGIN |
---|
70 | ras = report('la fonction tostr ne marche pas pour input qui est de type '+size(input, /tname)) |
---|
71 | res = '' |
---|
72 | END |
---|
73 | ENDCASE |
---|
74 | |
---|
75 | return, res |
---|
76 | end |
---|