function changePar(fname,par,val)

n = length(par);

fid = fopen(fname);

cul = fgetl(fid);
ind = 0;
npar = [0 0];
nl = 0;
while cul > -1 
    ind = ind+1;
    if ~isempty(strfind(cul,'begin parameters'))
        npar(1) = ind;
    end
    if ~isempty(strfind(cul,'end parameters'))
        npar(2) = ind;
    end
    cul = fgetl(fid);
    if isempty(cul)
        cul = 0;
    end
    nl = nl +1;
end
fclose(fid);

parl = zeros(n,1);
plin = cell(nl,1);

fid = fopen(fname,'r');
for j = 1:nl
    plin{j} = fgetl(fid);
    if j > npar(1)&&j < npar(2)
        cuc = strfind(plin{j},'#');
        for i = 1:n
            cui = strfind(plin{j},par{i});
            if ~isempty(cui)
                if cui(1) < cuc 
                    parl(i) = j;
                elseif isempty(cuc)
                    parl(i) = j;
                end
            end
        end
    end
end
fclose(fid);
parl

[parls,paris] = sort(parl);
paris(parls == 0) = [];
parls(parls == 0) = [];
fid = fopen(fname,'w');
cup = 1;

for j = 1:nl%parls(end) - 1
    if j == parls(cup)
        fseek(fid,0,'cof');
        culn = regexprep(plin{j},'(\s)[\d,.,e,-,*,+,/]+',[' ',num2str(val(paris(cup)),15)],'once');
        
        fprintf(fid,[culn,'\n']);
        cup = min(cup + 1,length(parls)); 
    else
        fprintf(fid,[plin{j},'\n']);
    end
end


fclose(fid);

