function [A info] = arcgis_asc2mat(file, format)

if exist(file, 'file')
    
    [pathstr, name, ext, versn] = fileparts(file);

    fid = fopen(file);

    wb = waitbar(0);
    wc = get(wb, 'children');
    wt = get(wc, 'title');
    set(wt, 'Interpreter', 'none');
    waitbar(0, wb, ['Reading ' file '...']);

    info = struct();

    i = 1; j = 1; ni = 0;
    while ~feof(fid)
        L = fgetl(fid);
        L = strrep(L, ',', '.');

        if i <= 6
            n = strtrim(L(1:14));
            v = str2num(L(15:end));
            info.(upper(n)) = v;

            i = i + 1;
        else
            Ai = sscanf(L, format);
            Ai(Ai == info.NODATA_VALUE) = nan;

            if j == 1
                A = nan([info.NROWS*info.NCOLS/length(Ai) length(Ai)]);
                disp(info);
            end

            A(size(A,1)-j+1,:) = Ai;

            if mod(j, round(size(A,1)/100)) == 0
                waitbar(j/size(A,1), wb);
            end

            j = j + 1;
        end
    end

    fclose(fid);

    waitbar(100, wb, 'Reshaping matrix...');
    A = reshape(A, info.NROWS, info.NCOLS);

    waitbar(100, wb, 'Saving matrix...');
    save([pathstr '/' name '.mat'], 'A', 'info');

    close(wb);
else
    disp(['ERROR: file does not exist [' file ']']);
end
