function [data names]=readmercs(fullfilename)
%Reads Mechwarrior 2 Mercenaries's weapons data
%
%[data names]=readmercs(fullfilename)
%
% fullfilename is filename including full path
%     if filename is not specified, will open dialog to select file
%
% data is 66 x 24 array of in32, each row is a weapon
% names is 66 cell array of corresponding weapon names

%% locate the file
if (~exist('fullfilename','var') ||isempty(fullfilename))
    fprintf('Select mw2.exe\n');
    [filename,pathname]=uigetfile('mw2.exe','Open MW2.EXE');
    fullfilename=[pathname filename];
end
%% open file, read weapons data
fid=fopen(fullfilename,'r');
startoffset=913420;
fseek(fid,startoffset,-1);
names={};
data=zeros(66,24,'int32');
for i=1:66
    vals=fread(fid,24,'int32');%read 24 values of int32
    wname=fread(fid,8,'uchar');%read 8 byte short weapon name;
    wname(8)=0;
    data(i,:)=vals;
    names{i}=sprintf('%s',wname);
    %fprintf('%d: %s: ',i,wname);
    %fprintf('%d ',vals);
    %homing: vals(11), continuous: vals(9)
    %fprintf('Shots %d  Ammo %d  ',vals(12),vals(13));
    %fprintf('Spd %d  Dam %d  Heat %0.0f  ',vals(16),vals(17),vals(18)/32768);
    %fprintf('RangeI %0.0f  RangeA %0.0f  Reload %0.1f  Delay %0.1f\n',vals(21)/100,vals(24)/100*vals(16),vals(22)/100,vals(23)/100);   
end
fclose(fid);
checkdata(data,names);