function [N,s]=baslerinfo(fn,ifn)
% vothinfo Extract information from basler image files 
% Usage: [Nimg info]=imginfo(filename). 
%
% Nimg is the number of images in the file.  info is a structure will all
% information from the file.  

% revision history:
% 04/19/96 Mark D. Shattuck <mds> dalinfo.m  
% 12/22/97 Added force type
% 01/28/98 Removed different dalsa types put into one file created imginfo
%          wrapper to parse types; added xillex type
% 09/24/02 Convert dalinfo to baslerinfo.

s.fdesc=dir(fn);

if (isempty(s.fdesc))
  disp('File does not exist!');
  return
end


s.MINPIXVAL=0;
s.MAXPIXVAL=255;
s.id='0000';
s.head=0;
s.ihead=0;
s.type='uint8';        % pixel depth

N=-1;

% parse filename
[s.path,s.fn,s.ext]=fileparts(fn);
if(isempty(s.path))
  s.path=pwd;
end
s.fullname=fullfile(s.path,[s.fn s.ext]);
s.base=s.fn;
s.rfn=sprintf('%s',s.base);
if(~strcmp(s.fn,s.rfn))
  warning('imginfo:NoParse','Problem parsing filename.\nReconstructed filename=%s ~= original filename=%s.',s.rfn,s.fn);
end

if(~exist('ifn','var') || isempty(ifn))
	ifn=sprintf('%s\\%s_info.tif',s.path,s.base);
end

s.infofn=ifn;
s.idesc=dir(s.infofn);


if (isempty(s.idesc))
  disp('Info file does not exist!');
  return
end

s.info=imfinfo(s.infofn);

s.Ny=s.info.Width;
s.Nx=s.info.Height;
s.idsize=0;

s.imgsize=s.Nx*s.Ny;
  
N=(s.fdesc.bytes-s.idsize)/s.imgsize;
s.N=N;
  
if (N~=fix(N))
  disp('File length not multiple of imgsize');
  return
end
  
