function [rc,raw,defn]=loadmri(fn,defn)
% loadmri <Load MRI data.>
% Usage:: [rc,raw,defn]=loadmri(fn,defn)
%

% revision history:
% 06/07/02 Mark D. Shattuck <mds> loadmri.m

%% Main

if(nargin==0)
  fn='data';
  defn='defn';
elseif(nargin==1)
  defn='defn';
end

defn=load('defn');
dim=defn(3:defn(1)+2);
dimcell=num2cell(defn(3:defn(1)+2)');
if(defn(2)/prod(dim)==1) % magnitude data
  raw=0;
  rc=readraw(fn,defn(2),'float');
  rc=reshape(rc,dimcell{:});
elseif (defn(2)/prod(dim)==2) % complex data
  raw=readraw(fn,defn(2),'int32');
  raw=raw(1:2:end)+i*raw(2:2:end);
  raw=reshape(raw,dimcell{:});
  for m=1:12
    rc(:,:,m)=abs(fftshift(ifft2(fftshift(squeeze(sum(raw(:,:,:,m),2))))));
    rc(end/2+1,end/2+1,m)=0;
    rc(end/2+1,end/2+1,m)=sum(flat(rc(end/2+1+(-1:1),end/2+1+(-1:1),m)))/8;
  end
else
  error('Unknown Data Type');
end
  


