function status=writefpv(img,filename)

ndim=length(size(img));
vdim=(1-isreal(img(:)))+1;

fid=fopen(filename,'w');
fwrite(fid,[ndim vdim size(img)],'int');
if vdim==2
  fwrite(fid,[real(img(:)) imag(img(:))]','float');
else
  fwrite(fid,img,'float');
end

fclose(fid);