another_file='y';
cd (['C:\Documents and Settings\lorsolo\My Documents\research\frances\data\original\PPI\'])
while another_file=='y'
    Vny_abs=input('Enter absolute Nyquist velocity \n');
    [sweepfile,pathname] = uigetfile('*.dat','Select the sweepfile'); 
    keep_editing='y';
    mod_EV=load(['C:\Documents and Settings\lorsolo\My Documents\research\frances\data\original\PPI\',sweepfile]);
    mod_az=mod_EV(length(mod_EV),:);
    mod_az=mod_az';
    mod_EV=mod_EV(1:length(mod_EV)-1,:);
    
    mod_SW=load(['C:\Documents and Settings\lorsolo\My Documents\research\frances\data\original\PPI\',sweepfile]);
    mod_SW=mod_SW(1:length(mod_SW)-1,:);
    

    [th,r]=meshgrid(deg2rad(mod_az),0:67:67*length(mod_EV)-1);
    [x,y]=pol2cart(th,r);
   %subplot(2,1,1)
   figure(1)
    h=pcolor(x,y,mod_EV);
    shading flat
    set(gcf, 'Renderer', 'zbuffer');
    hold on
    v=[-Vny_abs Vny_abs];
    caxis(v)
    axis equal
    velcolor=load(['C:\Documents and Settings\lorsolo\My Documents\research\programs\carbon43.dat']);
    colormap(velcolor);
    colorbar
    %subplot(2,1,2)
    figure(2)
     h=pcolor(x,y,mod_SW);
    shading flat
    set(gcf, 'Renderer', 'zbuffer');
    hold on
    axis equal
    
    
    mod_az=mod_az';
    
    EV_edit=mod_EV;
    while keep_editing=='y'
        button=1;
        xv=[];
        yv=[];
        
        while button==1
            pause
            [x0,y0,button] = ginput;
            xv=[xv;x0];
            yv=[yv;y0];
            %subplot(1,2,1)
            figure(1)
            plot(xv,yv,'r')
            %subplot(1,2,2)
            figure(2)
            plot(xv,yv,'r')
        end
        
        xv = [xv ; xv(1)];
        yv = [yv ; yv(1)];
        figure(1)
        plot(xv,yv,'r')
        
        figure(2)
        plot(xv,yv,'r')
        
        
        
        in = inpolygon(x,y,xv,yv);
        u_ed=find(in==1 | in==0.5);
        temp1=EV_edit;
        temp2=temp1(u_ed);
        expression=input('enter you condition of editing \n');
        v_ed=find(expression);
        temp2(v_ed)=NaN;
        temp1(u_ed)=temp2;
        figure(1)
        hold off
        h=pcolor(x,y,temp1);
        shading flat
        hold on
        v=[-20 20];
        caxis(v)
        axis equal
        colormap(velcolor);
        colorbar
        pause
        good_editing=input('Is this ok? \n','s');
        
       
        
        if good_editing=='y'
            EV_edit(u_ed)=temp2;
            save(['C:\Documents and Settings\lorsolo\My Documents\research\frances\data\modified\unfold\',sweepfile],'EV_edit','mod_az','-ascii')
        else
            figure(1)
            hold off
            h=pcolor(x,y,EV_edit);
            shading flat
            hold on
            v=[-20 20];
            caxis(v)
            axis equal
            colormap(velcolor);
            colorbar
        end
        
        keep_editing=input('Do you want to keep editing? \n','s');
    end
    another_file=input('doyou want to process another file? \n','s');
end

cd (['C:\Documents and Settings\lorsolo\My Documents\research\programs'])
