%% Federico Lombardi

clear
%% Import directory
fileList = dir('*.DTA');

for i = 1:length(fileList)
    filename = fileList(i).name;
    [t,spc] = eprload(filename);
    spc = real(spc);
    spc = spc/max(spc);
    if (i>3 && i<9)
        T = str2double(filename(5));
    else
        T = str2double(filename(5:6));
    end
    B = [t spc];
    filename1 = [filename(1:end-4) '.tsv'];
    fileID = fopen(filename1,'w');
    fprintf(fileID,'%1s\t%15s\n','t','Echo Intensity');
    fprintf(fileID,'%2s\t%2s\n','ns','');
    fprintf(fileID,'%20s\t%3s\n','DFB1 Powder', num2str(T));
    fclose(fileID);
    dlmwrite(filename1, B,'delimiter','\t','-append');
end
