; This functino allows you to control the string output of a number ; by specifying the number of decimal places displayed (so that zeroes ; are not truncated) and the number of digits before the decimal ; (using FRONT) ; ; K. Bundy 5/25/02 ; ; KBundy 4/29/04 - If keyword set /SPACE, then empty space goes in front instead of zeros. function dplace, arg, place, front = front, space = space ;; Get in the habit of using format codes instead print print, ' STOP USING DPLACE: Use a format code like this instead: ' print, ' - zero padding, with 7 digits in front and 4 after the decimal point: string(agument, format = "(F012.4)") ' print ; Error Checking if n_params() LT 2 then begin message, 'USAGE: dplace, arg, place' endif if keyword_set(SPACE) then padchar = ' ' else padchar = '0' arg_rnd = strcompress(round(arg*10.^place)/10D^place, /remove_all) d_pos = strpos(arg_rnd, '.') d_pos_arr = lonarr(1, n_elements(d_pos)) ; We do this so strmid delivers d_pos_arr[0, *] = d_pos ; 1-D array if place NE 0 then arg_crop = strmid(arg_rnd, 0, d_pos_arr+place+1) if place EQ 0 then arg_crop = strmid(arg_rnd, 0, d_pos_arr+place) result = arg_crop if keyword_set(front) then begin for i = 0, n_elements(arg)-1 do begin if front GT d_pos[i] then begin if place NE 0 then $ result[i] = strn(arg_crop[i], length = 1+place+front, padtype = 1, padchar = padchar) if place EQ 0 then $ result[i] = strn(arg_crop[i], length = front, padtype = 1, padchar = padchar) endif endfor endif return, result end