;+ ; ; @file_comments ; Convert an input in a string. ; ; @categories ; String ; ; @param INPUT {in}{required} ; input can not contain or be of the type of: ; ; Complex floating, structure, Double-precision complex, Pointer, Object ; reference, Unsigned Integer, Unsigned Longword Integer, 64-bit ; Integer, Unsigned 64-bit Integer ; ; @returns ; a string ; ; @restrictions ; If keywdvalue is an array, it will be convert in a vector. ; ; @restrictions ; Beware, this function has loops, ifs and cases everywhere. So it can ; not be used by big keywords (with a lot of elements which are big ; arrays). ; ; @examples ; IDL> help, tostr(1),tostr('a'),tostr(indgen(4)),tostr(['a','jkfjo']) ; STRING = '1' ; STRING = ''a'' ; STRING = '[0,1,2,3]' ; STRING = '['a','jkfjo']' ; IDL> print, tostr(['c''est bon','c''est bon']) ; ['c''est bon','c''est bon'] ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; 18/10/1999 ; ; @version ; $Id$ ; ;- FUNCTION tostr, input ; compile_opt idl2, strictarrsubs ; case 1 of size(input, /type) LE 5:BEGIN if size(input, /type) EQ 1 then input = long(input) if n_elements(input) EQ 1 then res = strtrim(input, 1) $ ELSE BEGIN res = '['+strtrim((input)[0], 1) for i = 1, n_elements(input)-1 do res = res+','+strtrim((input)[i], 1) res = res+']' ENDELSE END size(input, /type) eq 7:BEGIN if n_elements(input) EQ 1 then BEGIN sinput = strrepl(input, '''', '''''') res = ''''+sinput+'''' ENDIF ELSE BEGIN res = '['''+strrepl(input[0], '''', '''''')+'''' for i = 1, n_elements(input)-1 do res = res+','''+strrepl(input[i], '''', '''''')+'''' res = res+']' ENDELSE END ELSE:BEGIN ras = report('la fonction tostr ne marche pas pour input qui est de type '+size(input, /tname)) res = '' END ENDCASE return, res end