filename = 'SNG_200528400_U3.DAT'; % Could be an SNG or ELS file
% Get number of records
D = dir(filename);
n = D.bytes/40;  % Assumes 40 bytes per record
%
fid_i = fopen(filename,'r','ieee-be'); % Open the Big Endian input file
fid_o = fopen('output_matlab.txt','w'); % output file
% loop through binary file and write out text file
for z=1:n
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % B_CYCLE_NUMBER
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % A_CYCLE_NUMBER
    fprintf(fid_o,'%f\t', fread(fid_i,1,'double') ); % TIME
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint8' ) ); % TELEMETRY_MODE
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint8' ) ); % SPARE if SNG, COLLAPSE_FLAG if ELS
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % OFFSET_TIME
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % FIRST_ENERGY_STEP
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % LAST_ENERGY_STEP
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % FIRST_AZIMUTH_VALUE
    fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % LAST_AZIMUTH_VALUE
    for zz=1:8
        fprintf(fid_o,'%u\t', fread(fid_i,1,'uint16') ); % DATA
    end
    fprintf(fid_o,'\n');
end
% close files
fclose(fid_i);
fclose(fid_o);
