function [imacc,imati]=imaver(imlist)

% IMAVER(imlist) Coadd the images in the file "imlist"

% This part of the code just reads in the information
% in the "imlist" file (name, x, y, int_time)

fp=fopen(imlist,'r');
ni=0;
ln=fgetl(fp);
while (length(ln)>2),
    ni=ni+1;
    fn{ni}=sscanf(ln,'%s',1);
    u=findstr(fn{ni},ln);
    s=length(fn{ni});
    xyt(ni,1:3)=sscanf(ln((s+u(1)):end),'%f',3);
    ln=fgetl(fp);
end
fclose(fp);


% This part reads in the first image, and then shifts and
% averages all the following images onto it

if ((~isempty(findstr(fn{1},'.fts')))||(~isempty(findstr(fn{1},'.fits')))),
    r=rfits(fn{1});
else
    u=load(fn{1});
    n=char(fieldnames(u));
    r.data=u.(n);
end
imacc=r.data;
imati=ones(size(imacc))*xyt(1,3);
for i=2:ni,
    xs=xyt(1,1)-xyt(i,1);
    ys=xyt(1,2)-xyt(i,2);
    if ((~isempty(findstr(fn{i},'.fts')))||(~isempty(findstr(fn{i},'.fits')))),
        f=rfits(fn{i});
    else
        u=load(fn{i});
        n=char(fieldnames(u));
        f.data=u.(n);
    end
    imr=imshift(f.data,ys,xs);
    imti=ones(size(r.data))*xyt(i,3);
    imti(imr==0)=0;
    imacc=(imacc+imr);
    imati=imati+imti;
end
