dirs= dir;

clear bulkperms;
bulkperms = struct( 'modelname', [], 'permeability', [], 'mass_balance_error', []);
counter = 1;

for idxaam =   3: length( dirs),
    if dirs(idxaam).isdir,
       cd( dirs(idxaam).name );
       try 
          mf_analyze; ca;
          mergemapandlegend;
          bulkperms(counter).modelname = dirs(idxaam).name;
          bulkperms(counter).permeability = bulkpermeability;
          bulkperms(counter).mass_balance_error = mass_balance_error;
          counter = counter + 1;
          close all;
       catch
           bulkperms(counter).modelname = [ 'ERROR!  ', dirs(idxaam).name ];
           bulkperms(counter).permeability = nan;
           bulkperms(counter).mass_balance_error = nan;
       end
       cd ..;
    end
end

M = [ {'name', bulkperms.modelname}'  {'permeability', bulkperms.permeability}' {'mass balance error (%)', bulkperms.mass_balance_error}' ];
xlswrite( [ 'bulkpermeabilities ', datestr(now, 'yyyy_mm_dd HH_MM_SS')] , M);
