[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[142] | 3 | ; @file_comments |
---|
| 4 | ; Convert an input in a string. |
---|
[2] | 5 | ; |
---|
[142] | 6 | ; @categories |
---|
[157] | 7 | ; String |
---|
[2] | 8 | ; |
---|
[142] | 9 | ; @param INPUT {in}{required} |
---|
| 10 | ; input can not contain or be of the type of: |
---|
[2] | 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 | ; |
---|
[142] | 16 | ; @returns |
---|
| 17 | ; a string |
---|
[2] | 18 | ; |
---|
[142] | 19 | ; @restrictions |
---|
| 20 | ; If keywdvalue is an array, it will be convert in a vector. |
---|
[2] | 21 | ; |
---|
[142] | 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 |
---|
[2] | 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 | ; |
---|
[142] | 36 | ; @history |
---|
[157] | 37 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 38 | ; 18/10/1999 |
---|
[142] | 39 | ; |
---|
| 40 | ; @version |
---|
| 41 | ; $Id$ |
---|
| 42 | ; |
---|
[2] | 43 | ;- |
---|
[232] | 44 | ; |
---|
[2] | 45 | FUNCTION tostr, input |
---|
[114] | 46 | ; |
---|
| 47 | compile_opt idl2, strictarrsubs |
---|
| 48 | ; |
---|
[2] | 49 | |
---|
| 50 | case 1 of |
---|
| 51 | size(input, /type) LE 5:BEGIN |
---|
| 52 | if size(input, /type) EQ 1 then input = long(input) |
---|
| 53 | if n_elements(input) EQ 1 then res = strtrim(input, 1) $ |
---|
| 54 | ELSE BEGIN |
---|
| 55 | res = '['+strtrim((input)[0], 1) |
---|
| 56 | for i = 1, n_elements(input)-1 do res = res+','+strtrim((input)[i], 1) |
---|
| 57 | res = res+']' |
---|
| 58 | ENDELSE |
---|
| 59 | END |
---|
| 60 | size(input, /type) eq 7:BEGIN |
---|
| 61 | if n_elements(input) EQ 1 then BEGIN |
---|
| 62 | sinput = strrepl(input, '''', '''''') |
---|
| 63 | res = ''''+sinput+'''' |
---|
| 64 | ENDIF ELSE BEGIN |
---|
| 65 | res = '['''+strrepl(input[0], '''', '''''')+'''' |
---|
| 66 | for i = 1, n_elements(input)-1 do res = res+','''+strrepl(input[i], '''', '''''')+'''' |
---|
| 67 | res = res+']' |
---|
| 68 | ENDELSE |
---|
| 69 | END |
---|
| 70 | ELSE:BEGIN |
---|
| 71 | ras = report('la fonction tostr ne marche pas pour input qui est de type '+size(input, /tname)) |
---|
| 72 | res = '' |
---|
| 73 | END |
---|
| 74 | ENDCASE |
---|
| 75 | |
---|
| 76 | return, res |
---|
| 77 | end |
---|