function [df]=ddiff2(f,dim,dn)
% ddiff First order accurrate finite difference second derivative.
% usage::  [df]=ddiff2[f,dim]
%
% first order accurrate diff(f,2,dim).  size(df)==size(f) 

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


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

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