;----------------------------------------------------------------------- function rnd, val,rval,dir=dir ; ; Round val to the nearest rval (there must be a better way...) ; if dir == 0 (or dir not defined) then find nearest rval ; if dir > 0 then round up, if dir < 0 round down ; ival = round(val) & irval = round(rval) ivalp = ival while ivalp mod irval ne 0 do ivalp = ivalp+1 ivalm = ival while ivalm mod irval ne 0 do ivalm = ivalm-1 ans = ivalp if n_elements(dir) > 0 then begin if dir lt 0 then ans = ivalm else return,ans endif else begin if ival-ivalm lt ivalp-ival then ans = ivalm endelse return,ans end ;-----------------------------------------------------------------------