function scan=scangen_ccny2020(lidar,ScanType)

[azspeed,elspeed]=scanspeed_2(lidar);

%setting stationary motor speed value

mstill=0.05; % deg/sec
mon=.1;
sweep=1;
scan=[];
switch lower(ScanType)
    case{'stare'}
        % determine indexs for beam stare
        ind=find(abs(azspeed)<=mstill & abs(elspeed)<=mstill);

        if ~isempty(ind)
            scan(sweep).ind=ind;
            scan(sweep).type='STARE';
            sweep=sweep+1;
        end
    case{'rhi'}
        % determine RHI scans

        ind=find(abs(azspeed)<mstill & elspeed>mon);
        if ~isempty(ind)  %potential candidates for positive RHI Sweep
            poss=find(diff(ind)~=1); %scan must be incremental
            if ~isempty(poss)
                npos=length(poss);
                indlow=ind(1);
                for j=1:npos
                    numpts=ind(poss(j))-indlow;
                    if numpts>10
                        scan(sweep).ind=[indlow:ind(poss(j))];
                        scan(sweep).type='RHI';
                        sweep=sweep+1;
                        indlow=ind(poss(j)+1);
                    end
                end
            else
                if length(ind)>10
                    scan(sweep).ind=ind;
                    scan(sweep).type='RHI';
                    sweep=sweep+1;
                end
            end
        end

        ind=find(abs(azspeed)<mstill & elspeed<-mon);
        if ~isempty(ind)  %potential candidates for negative RHI Sweep
            poss=find(diff(ind)~=1); %scan must be incremental
            if ~isempty(poss)
                npos=length(poss);
                indlow=ind(1);
                for j=1:npos
                    numpts=ind(poss(j))-indlow;
                    if numpts>10
                        scan(sweep).ind=[indlow:ind(poss(j))];
                        scan(sweep).type='RHI';
                        sweep=sweep+1;
                        indlow=ind(poss(j)+1);
                    end
                end
            else
                if length(ind)>10
                    scan(sweep).ind=ind;
                    scan(sweep).type='RHI';
                    sweep=sweep+1;
                end
            end
        end
    case{'ppi'}
        % determine PPI scans

        ind=find(azspeed>mon & abs(elspeed)<=mstill);
        if ~isempty(ind)  %potential candidates for positive PPI Sweep
            poss=find(diff(ind)~=1); %scan must be incremental
            if ~isempty(poss)
                npos=length(poss);
                indlow=ind(1);
                for j=1:npos
                    numpts=ind(poss(j))-indlow;
                    if numpts>10
                        scan(sweep).ind=[indlow:ind(poss(j))];
                        scan(sweep).fixed_angle=mean(lidar.elevation(scan(sweep).ind,1));
                        scan(sweep).type='PPI';
                        sweep=sweep+1;
                        indlow=ind(poss(j)+1);
                    end
                end
            else
                if length(ind)>10
                    scan(sweep).ind=ind;
                    scan(sweep).fixed_angle=mean(lidar.elevation(scan(sweep).ind,1));
                    scan(sweep).type='PPI';
                    sweep=sweep+1;
                end
            end
        end

        ind=find(azspeed<-mon & abs(elspeed)<=mstill);
        if ~isempty(ind)  %potential candidates for negative PPI Sweep
            poss=find(diff(ind)~=1); %scan must be incremental
            if ~isempty(poss)
                npos=length(poss);
                indlow=ind(1);
                for j=1:npos
                    numpts=ind(poss(j))-indlow;
                    if numpts>10
                        scan(sweep).ind=[indlow:ind(poss(j))];
                        scan(sweep).fixed_angle=mean(lidar.elevation(scan(sweep).ind,1));
                        scan(sweep).type='PPI';
                        sweep=sweep+1;
                        indlow=ind(poss(j)+1);
                    end
                end
            else
                if length(ind)>10
                    scan(sweep).ind=ind;
                    scan(sweep).fixed_angle=mean(lidar.elevation(scan(sweep).ind,1));
                    scan(sweep).type='PPI';
                    sweep=sweep+1;
                end
            end
        end
end
nscans=length(scan);
if ~isempty(scan)
    for j=1:nscans
        meantime(j)=mean(lidar.timestamp(scan(j).ind));
    end
    [mt,ind2]=sort(meantime,'ascend');
    for j=1:nscans
        scan2(j).ind=scan(ind2(j)).ind;
        scan2(j).type=scan(ind2(j)).type;
        scan2(j).scantime=mt(j);
    end
    scan=scan2;
end


return
end