function [Qtempx,Qtempy]=bc8_compact(Q,JM,KM,jmax,kmax,M_inf)

%These are the boundary conditions to be used in the compact scheme
%The returned array should only contain information on the boundaries
%and zeros on the interior
Qtempx=zeros(size(Q));
Qtempy=zeros(size(Q));

%At inflow (x=-1), fix pu=M_inf,pv=0, and set dp/dx=0       *LEFT
Qtempx(1,KM,1)=Q(2,KM,1);
Qtempx(1,KM,2)=M_inf;
Qtempx(1,KM,3)=0;

%At right dQ/dx=0.  Therefore Q(:,kmax,:)=Q(:,kmax-1,:);    *RIGHT
Qtempx(jmax,KM,:) = Q(jmax-1,KM,:);

%At the top (y=2) fix all the variables p=1, u=M_inf,v=0    *TOP
Qtempy(JM,kmax,1)=1;
Qtempy(JM,kmax,2)=M_inf;
Qtempy(JM,kmax,3)=0;

% At k=1 Extrap rho, u, fix rho v                           *BOTTOM
RHO = Q(JM,1,1);
Qtempy(JM,1,1) = Q(JM,2,1);
Qtempy(JM,1,2) = Q(JM,2,2)./Q(JM,2,1).*Q(JM,1,1);
Qtempy(JM,1,3) = Q(JM,1,3)./RHO.*Q(JM,1,1);
