function [N,s]=cininfo(fn)
% cininfo Extract size and original head and tail information. usage::
% [Nimg info]=dalinfo(filename). 
%
% Extract size and original head and tail information from a cin file
% produced by the Phantom v7.2. info is a structure.

% revision history: 08/02/07 Mark D. Shattuck <mds>   cininfo.m adapted
% from dalinfo

s.fdesc=dir(fn);       % File exists?
if (isempty(s.fdesc))
  disp('File does not exist!');
  N=-1;
  s=0;
  return
end

sig=hex2dec('2c4943'); % Cine magic number

s.MINPIXVAL=0;         
s.MAXPIXVAL=255;
s.id='0000';           % id for compatibility

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

%parse header
fid=fopen(fn);
s.sig=fread(fid,1,'uint32');
if (s.sig~=sig)
  disp('Not cine file');
  return
end

fseek(fid,12,'bof');
s.Nr=fread(fid,1,'uint32');  %Frames take
fseek(fid,20,'bof');
s.N=fread(fid,1,'uint32');   %Frames saved

N=s.N;

fseek(fid,48,'bof');
s.Nx=fread(fid,1,'uint32');
s.Ny=fread(fid,1,'uint32');
s.ihead=8;
s.fixhead=5800;
s.varheadfac=36;
s.varhead=s.varheadfac*s.Nr;
s.head=s.fixhead+s.varhead;

fseek(fid,5789,'bof');

s.t=fread(fid,s.N,'uint64'); %Frame timing

s.imgsize=s.Nx*s.Ny;
s.idsize=0;


fclose(fid);

end  
