function vmpMat = readVMP(path, vmp);
% syntax: vmpMat = readVMP(path, vmp)
% 
% this func prints the vmp header of the file [path vmp '.vmp'] 
% to the screen and returns the vmpMat
% 
% This function was written by:
% Hagar Gelbard
% Rafi Malach's Lab
% Weizmann Institute of Science
% Rehovot, Israel
% hagar.gelbard@weizmann.ac.il

fclose('all');

% open the vmp file for reading
fid = fopen([path vmp '.vmp'],'r');

% READ HEADER

ver = fread(fid,1,'short');
NrOfMaps = fread(fid,1,'short');
MapType = fread(fid,1,'short');
NrOfLags = fread(fid,1,'short');
ClusterSize = fread(fid,1,'short');
CritThreshold = fread(fid,1,'float');
MaxThreshold = fread(fid,1,'float');
df1 = fread(fid,1,'short');
df2 = fread(fid,1,'short');

MapName = [];
a = 'a';
while a ~= 0
  a = fread(fid,1,'char');
  MapName = [MapName a];
end
char(MapName);

DimX = fread(fid,1,'short');
DimY = fread(fid,1,'short');
DimZ = fread(fid,1,'short');
XStart = fread(fid,1,'short');
XEnd = fread(fid,1,'short');
YStart = fread(fid,1,'short');
YEnd = fread(fid,1,'short');
ZStart = fread(fid,1,'short');
ZEnd = fread(fid,1,'short');
resolution = fread(fid,1,'short');
 

cols = (XEnd-XStart+1)/resolution;
rows = (YEnd-YStart+1)/resolution;
slices = (ZEnd-ZStart+1)/resolution;
voxelsNo = cols*rows*slices;

fseek(fid, 0, 'cof');


% for z=1:slices
% 	for y=1:rows
%         for x=1:cols
%             vmpMat(x,y,z)=fread(fid, 1, 'float');
%         end
%     end
% end



% vmpMat = fread(fid,voxelsNo,'float');
vmpMat = zeros(voxelsNo,1);
for i=1:voxelsNo
    vmpMat(i)=fread(fid, 1, 'float');
end

fclose('all');