% pipro_version.m
function [piProVer] = pipro_version;

% To release a new build of PiPro (load_pi.exe) set releaseBuild to 1, and
% update the version numbers. 

releaseBuild = 1;

if ( exist( 'tmpVersion.txt') == 2 )
  delete tmpVersion.txt;
end

diary tmpVersion.txt;

piProVer.piproVersion = 'PIPRO_V208_18DEC2008';
piProVer.pilineVersion = 'PILINE_V426_BETA_18DEC2008';

% Number of "dummy" variables should be equal to d_OUT_ARGUMENTS defined
% in PiLine/pi_line.c
[ dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy, ...
  dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy, ...
  dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy, ...
  dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy ] = ... 
  piLineMex( '-v' );

if (releaseBuild == 1)
  piProVer.buildType = 'Release';
else
  piProVer.buildType = 'Test';
end

diary off; 

%% Compare expected version to actual version
pilineExpectedVersion = piProVer.pilineVersion(9:11);
pilineExpectedVersion = str2num ( pilineExpectedVersion ) / 100; 

verMatch = 0; 
needVer = 1; 
pilineVersion = 0; 

fid = fopen('tmpVersion.txt', 'r');

while ( needVer )
  
  curLine = fgetl(fid);
  if ( isempty ( curLine ) )
    continue;
  end
  
  if ( curLine == -1 )
    needVer = 0; 
    break;
  end
  
  if ( strncmp ( curLine, 'Version', 7 ) )
    [t1, t2] = strtok ( curLine );
    pilineVersion = strtok( t2, [' ','-']  ); 
    pilineVersion = str2num ( pilineVersion );

    verMatch = ( pilineVersion - pilineExpectedVersion ) < 0.001;
    
    break;
  end
end

fclose( fid ); 
delete ('tmpVersion.txt');

if ( verMatch )
  disp('Expected and Actual PiLine Versions match.');
  disp(' ');
else
  fprintf('Piline Version = %f\n', pilineVersion);
  fprintf('Piline Expected Version = %f\n', pilineExpectedVersion);  
  if ( releaseBuild )
    error( 'Expected and Actual PiLine Versions don''t match ');
  else
    warning( 'Expected and Actual PiLine Versions don''t match ');
    disp('Just a warning because this is a test build.');
  end
    
end

return;
