function writeoutfiles(fhn, mondescr, scalings, ref, values)

n = length(mondescr);
nmeas = length(scalings);
[vnr,vnc]  = size(values);

fh=fopen(fhn,'w');

fprintf(fh,'NAME\t0.0\t');

for i=1:nmeas
  fprintf(fh,'%f\t',scalings(i));
end
fprintf(fh,'\n');

i = 0;
for k=1:n
  if (mondescr(k).faulty)
    continue;
  end
  i = i + 1;
  fprintf(fh,'%s\t%f\t',mondescr(i).name, ref(i));
  for j=1:nmeas
    fprintf(fh,'%f\t',values(i,j));
  end
  fprintf(fh,'\n');
end


fclose(fh);

