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