function [h] = load_dat_file(filename,encoding);
fid = fopen(filename(1,:),'r',encoding);
type = fread(fid, 1,'int32');
zmin = fread(fid, 1,'int32');
zbeg = fread(fid, 1,'int32');
zend = fread(fid, 1,'int32');
zmax = fread(fid, 1,'int32');
ymin = fread(fid, 1,'int32');
ybeg = fread(fid, 1,'int32');
yend = fread(fid, 1,'int32');
ymax = fread(fid, 1,'int32');
xmin = fread(fid, 1,'int32');
xbeg = fread(fid, 1,'int32');
xend = fread(fid, 1,'int32');
xmax = fread(fid, 1,'int32');
zdim = zend-zbeg+1;
ydim = yend-ybeg+1;
xdim = xend-xbeg+1;

h=fread(fid,[xdim*ydim*zdim],'double');
h = reshape(h,xdim,ydim,zdim);   % Column major
for i=1:zdim,
    h(:,:,i) = h(:,:,i)';        % Shift to Row major 
end
return;