function radar=readdata()

% pick data file for reading
FilterSpec='D:\uscg\Raw Data\*.bin';

[file_name,file_dir,tz] = uigetfile(FilterSpec,''Pick Data file for Processing');
datafile_name=fullfile(file_dir,file_name);

fid1=fopen(char(datafile_name),'r');
c=3.e8;
dodo=1;
while dodo>=1
    try
        [data,beamsz] = read_MPDR_beam(fid1,datafile_name,0);
        data.ch0DataPwr = (abs(data.iqDataCh0)).^2;
        data.ch1DataPwr = (abs(data.iqDataCh1)).^2;

        data.ch0DataPwrdB = 10.*log10(data.ch0DataPwr);
        data.ch1DataPwrdB = 10.*log10(data.ch1DataPwr);
        data.ch0dopplerMap = fft(data.iqDataCh0-mean(data.iqDataCh0));
        [pulses,samples] = size(data.ch0dopplerMap);
        data.freqVect = (-data.prf/2: data.prf/pulses: data.prf/2- data.prf/pulses);
        data.rangeVect = (1:samples) .* c/(2*data.sampleRate) ./ 1000 ;

        data.ch1dopplerMap = fft(data.iqDataCh1-mean(data.iqDataCh1));
        [~,samples2] = size(data.ch1dopplerMap);
        data.rangeVect2 = (1:samples2) .* c/(2*data.sampleRate) ./ 1000 ;
        ddd(dodo)=data;
        dodo=dodo+1;
        clear data
    catch ME1
        idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
        disp(idSegLast)
        dodo=0;
    end
end
fclose(fid1);
header.sampleRate=ddd(1).sampleRate;
header.filename=ddd(1).filename;
header.header.messageVersion=ddd(1).messageVersion;
header.header.messageId=ddd(1).messageId;
header.messageSize=ddd(1).messageSize;
header.scanId=ddd(1).scanId;

header.waveformId=ddd(1).waveformId;
header.transceiverType=ddd(1).transceiverType;
header.numPulses=ddd(1).numPulses;
header.latitude=ddd(1).latitude;
header.longitude=ddd(1).longitude;
header.pitch=ddd(1).pitch;
header.roll=ddd(1).roll;
header.yaw=ddd(1).yaw;
header.numBeams=length(ddd);
header.prf=ddd(1).prf;
header.sampleRate = 1.5625e6;
header.ch0numSamples=ddd(1).ch0numSamples;
header.ch1numSamples=ddd(1).ch1numSamples;
header.freq=ddd(1).freqVect;
header.ch0Range=ddd(1).rangeVect;
header.ch1Range=ddd(1).rangeVect2;
for j=1:header.numBeams
    header.beamPositionId(j,1)=ddd(j).beamPositionId;
    header.az(j,1)=ddd(j).azCh0;
    header.el(j,1)=ddd(j).elCh0;
    header.timestamp(j,1)=ddd(1).timestamp;

    rawIQ.iqDataCh0(:,:,j)=ddd(j).iqDataCh0;
    rawIQ.iqDataCh1(:,:,j)=ddd(j).iqDataCh1;
    power.ch0Pwr(:,:,j)=ddd(j).ch0DataPwr;
    power.ch1Pwr(:,:,j)=ddd(j).ch1DataPwr;
    power.ch0PwrdB(:,:,j)=ddd(j).ch0DataPwrdB;
    power.ch1PwrdB(:,:,j)=ddd(j).ch1DataPwrdB;
    doppler.ch0dopplerMap(:,:,j)=ddd(j).ch0dopplerMap;
    doppler.ch1dopplerMap(:,:,j)=ddd(j).ch1dopplerMap;
end
clear ddd
radar.header=header;
radar.rawIQ=rawIQ;
radar.power=power;
radar.doppler=doppler;
end


