;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: tostr (to string) ; ; PURPOSE: convertit un input en un string. ; ; CATEGORY: ; ; CALLING SEQUENCE: res=tostr(input) ; ; INPUTS: input ne peut pas contenir ou etre de type: ; ; Complex floating, structure, Double-precision complex, Pointer, Object ; reference, Unsigned Integer, Unsigned Longword Integer, 64-bit ; Integer, Unsigned 64-bit Integer ; ; KEYWORD PARAMETERS: none ; ; OUTPUTS: un string ; ; COMMON BLOCKS: ; ; SIDE EFFECTS: ; ; Si un element de input contient un tableau, il sera ; convertit en vecteur. ; ; RESTRICTIONS: ; ; attention cette fonction comporte des boucles, des if et des cases ; ds tous les sens. Elle ne doit donc pas etre utilisee avec des ; inputs de grosse taille (avec bcp d''elements et avec des ; elements etant de gros tableaux). ; EXAMPLE: ; 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'] ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; 18/10/1999 ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION tostr, input 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