%PENG8.8
%Jeannette Spuhler for the exercise 2012/10/26

clear all, clc,
file = input('Which file should be read in? ', 's');
[fid_in, message] = fopen(file, 'r');

while fid_in == -1
    disp(message);
    output = ['This file does not exist, please give in a correct filename: ' ];
    file = input(output, 's');
    [fid_in, message] = fopen(file, 'r');
end

output = input('In which file would you like to write your data? ', 's');
[fid_out, message_out] = fopen(output, 'r'); 

while fid_out > 0
    output = ['This file exists already, please give another filename: ' ];
    file = input(output, 's');
    fid_out= fopen(file, 'r');
end
[fid_out, message] = fopen(output, 'w');

format = input('In which format is this file written in (binary or formatted)?', 's');

if strcmp(format,'binary')
    [array, count] = fread(fid_in, 5, 'float64');
    array_out = round(array);
    count = fwrite(fid_out,array_out, 'float64');
    
elseif  strcmp(format,'formatted')
    [array, count] = fscanf(fid_in, '%f', 5);
    array_out = round(array);
    count = fprintf(fid_out, '%f \t',array_out);
end
status = fclose('all');

    