function [df]=ddiff(f,dim,dn)
% ddiff Second order accurrate finite difference derivative.
% usage::  [df]=ddiff[f,dim]
%
% Second order accurrate diff(f,1,dim).  size(df)==size(f) 

% revision history:
% 09/12/97 Mark D. Shattuck <mds>   ddiff.m


perm = [dim:max(ndims(f),dim) 1:dim-1];
f = permute(f,perm);
        
siz = size(f);

df=ipermute(reshape([-f(3,:)+4*f(2,:)-3*f(1,:);...
                        f(3:siz(1),:)-f(1:siz(1)-2,:);...
                        f(siz(1)-2,:)-4*f(siz(1)-1,:)+3*f(siz(1),:)]/2,siz),...
              perm); 
