function [INV] = slurpInv(fname,varargin)
%usage: [INV] = slurpInv(fname,varargin)
%.invfile from java_run, cf .inv from the other
%display 'enter slurpInv'
fname
mu0=pi*4e-7;

if length(varargin)>=1
    acq_gui=varargin{1}
else
    acq_qui='jrun3';
end;

%CH_excluder=[2 4 6 8 10 12 14 16 18 20 22];
fid=fopen(fname,'r');
fgetl(fid);
fgetl(fid);
L3=fgetl(fid);
fclose(fid);
[txtline2,numtot]=kgrep(fname,'phi3err');

fid=fopen(fname,'r');
nskip=txtline2(2); %here we are choosing the second set of data
skip;
ddd = fscanf(fid,'%f');
fclose(fid);
numT=length(ddd)/28;
if (floor(numT) ~= numT)
    error('MATLAB:slurpInv:.inv file structure error, not divisible by 28'); 
end
ddd=reshape(ddd,28,numT);

INV.t=ddd(1,:);
INV.posn=ddd(2:4,2);
INV.posn_err=ddd(5:7,2);
INV.nrmzd_rms_offdiag=ddd(8,:);
INV.rbst_rms_res=ddd(9,:);
INV.rel_sqd_err=ddd(10,:);
INV.p1=ddd(11,:)*mu0;
INV.p2=ddd(12,:)*mu0;
INV.p3=ddd(13,:)*mu0;
INV.p1_err=ddd(14,:)*mu0;
INV.p2_err=ddd(15,:)*mu0;
INV.p3_err=ddd(16,:)*mu0;
INV.thetaV=ddd(17:19,1);
INV.theta_err=ddd(20:22,1);
INV.phiV=ddd(23:25,1);
INV.phi_err=ddd(26:28,1);

