function m = readmodelparams(handle,size)
%function countwriten = readmodelparams(handle)
% code to read in the modelparameters from a given file handle which
% has been opened for binary reading and
% must not be null and has already been positioned for the correct location
% does not close the file afterwards

%Daniel Fraser Oct 2000

if size ==22
   m.NumPhotons = fread(handle,1,'double');
   m.source = fread(handle,1,'double');
   m.mua = fread(handle,1,'double');
   m.mus = fread(handle,1,'double');
   m.g = fread(handle,1,'double');
   m.BoundaryShape = fread(handle,1,'double');
   m.radial_size = fread(handle,1,'double');
   m.BoundaryReflect = fread(handle,1,'double');
   m.BoundaryRefType = fread(handle,1,'double');
   m.Iwantcutboundary = fread(handle,1,'double');
   m.CutSizeAngle = fread(handle,1,'double');

   m.NumBins = fread(handle,1,'double');
   m.dr = fread(handle,1,'double');

   m.GridBinsz        = fread(handle,1,'double');
   m.GridRange1       = fread(handle,1,'double');
   m.GridRange2       = fread(handle,1,'double');
   m.dgz              = fread(handle,1,'double');
   m.GridBinsx        = fread(handle,1,'double');
   m.GridWidth        = fread(handle,1,'double');
   m.dgx              = fread(handle,1,'double');

   m.Diameter = fread(handle,1,'double');
   m.AcceptanceAngle = fread(handle,1,'double');

elseif size ==21
   m.NumPhotons = fread(handle,1,'double');
   m.source = fread(handle,1,'double');
   m.mua = fread(handle,1,'double');
   m.mus = fread(handle,1,'double');
   m.g = fread(handle,1,'double');
   m.radial_size = fread(handle,1,'double');
   m.BoundaryReflect = fread(handle,1,'double');
   m.BoundaryRefType = fread(handle,1,'double');
   m.Iwantcutboundary = fread(handle,1,'double');
   m.CutSizeAngle = fread(handle,1,'double');

   m.NumBins = fread(handle,1,'double');
   m.dr = fread(handle,1,'double');

   m.GridBinsz        = fread(handle,1,'double');
   m.GridRange1       = fread(handle,1,'double');
   m.GridRange2       = fread(handle,1,'double');
   m.dgz              = fread(handle,1,'double');
   m.GridBinsx        = fread(handle,1,'double');
   m.GridWidth        = fread(handle,1,'double');
   m.dgx              = fread(handle,1,'double');

   m.Diameter = fread(handle,1,'double');
   m.AcceptanceAngle = fread(handle,1,'double');
elseif size ==14
   m.NumPhotons = fread(handle,1,'double');
   m.source = fread(handle,1,'double');
   m.mua = fread(handle,1,'double');
   m.mus = fread(handle,1,'double');
   m.g = fread(handle,1,'double');
   m.radial_size = fread(handle,1,'double');
   m.BoundaryReflect = fread(handle,1,'double');
   m.BoundaryRefType = fread(handle,1,'double');
   m.Iwantcutboundary = fread(handle,1,'double');
   m.CutSizeAngle = fread(handle,1,'double');

   m.NumBins = fread(handle,1,'double');
   m.dr = fread(handle,1,'double');

   m.Diameter = fread(handle,1,'double');
   m.AcceptanceAngle = fread(handle,1,'double');

else
   error('Don''t recongise the size of the model parameters');
end


      
     