function radar=readdata_v2()

% 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');
power=zeros(10000,1);
doppler=zeros(10000,1);
c=3.e8;
dodo=1;
beams=0;
while dodo>=1
    try

        [data,beamsz] = read_MPDR_beam(fid1,datafile_name,0);
        power(dodo).ch0pwr= mean((abs(data.iqDataCh0)).^2);
        power(dodo).ch1pwr = mean((abs(data.iqDataCh1)).^2);
        power(dodo).ch0owrdB=10.*mean(log10(data.ch0DataPwr));
        power(dodo).ch1pwrdB = 10.*mean(log10(data.ch1DataPwr));
        doppler(dodo).ch0map = fft(data.iqDataCh0);
        [pulses,samples] = size(data.ch0dopplerMap);
        radar.freq= (-data.prf/2: data.prf/pulses: data.prf/2- data.prf/pulses);
        radar.range0 = (1:samples) .* c/(2*data.sampleRate) ./ 1000 ;
        doppler(dodo).ch1map = fft(data.iqDataCh1);
        [~,samples2] = size(data.ch1dopplerMap);

        radar.range1 = (1:samples2) .* c/(2*data.sampleRate) ./ 1000 ;
        radar.pitch=data.pitch;
        radar.roll=data.roll;
        radar.yaw=data.yaw;
        radar.longitude=data.longitude;
        radar.latitude=data.latitude;
        radar.az(dodo,1)=data.azCh0;
        radar.el(dodo,1)=data.elCh0;
        radar.power=power;
        radar.doppler=doppler;
        disp(num2str(dodo))
       % ddd(dodo)=data;
        beams=beams+1;
        dodo=dodo+1;
        clear data power doppler;
    catch ME1
        idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
        disp(idSegLast)
        dodo=0;
    end
end
        radar.power=power;
        radar.doppler=doppler;
disp(['read',num2str(beams),' beams *****'])
fclose(fid1);
end


