function [p1,p2,p3,p4,p5,p6] = FixPositionsForScreen(p1,p2,p3,p4,p5,p6)

p1 = FixCoord(p1);
p2 = FixCoord(p2);
p3 = FixCoord(p3);
p4 = FixCoord(p4);
p5 = FixCoord(p5);
p6 = FixCoord(p6);



function p = FixCoord(p)
set(0,'Units','characters') %This is how all the GUIs are set here

scrsz = get(0,'ScreenSize');
scrsz(3)=scrsz(3)-4;
scrsz(4)=scrsz(4)-4;


if p(1)+p(3) > scrsz(3)
    p(1)=scrsz(3)-p(3);
end
if p(2)+p(4) > scrsz(4)
    p(2)=scrsz(4)-p(4);
end




if p(1)<1
    p(1)=1;
end
if p(2)<1
    p(2)=1;
end

