#include "Bdef.h"

int Ssring_bs(ctxt, scope)
BLACSCONTEXT  *ctxt;
char  scope;
{
   void Ssend2d00();

   int msgid;
   int rdest, cdest, i;

   scope = Mlowcase(scope);
   switch(scope)
   {
   case 'r':
      if (ctxt->npcol < 2) return(NORV);
      msgid = Mrid(ctxt);
      Ssend2d00(ctxt, ctxt->myrow, (ctxt->mycol+1)%ctxt->npcol,
                msgid);
      if (ctxt->npcol > 2)
         Ssend2d00(ctxt, ctxt->myrow, (ctxt->npcol+ctxt->mycol-1)
                   % ctxt->npcol, msgid);
      break;
   case 'c':
      if (ctxt->nprow < 2) return(NORV);
      msgid = Mcid(ctxt);
      Ssend2d00(ctxt, (ctxt->myrow+1)%ctxt->nprow, ctxt->mycol,
                msgid);
      if (ctxt->nprow > 2)
         Ssend2d00(ctxt, (ctxt->nprow+ctxt->myrow-1)%ctxt->nprow,
                   ctxt->mycol, msgid);
      break;
   case 'a':
      if (ctxt->Ng < 2) return(NORV);
      msgid = Maid(ctxt);
      i = (ctxt->vIam+1) % ctxt->Ng;
      Mvpcoord(ctxt, i, rdest, cdest);

      Ssend2d00(ctxt, rdest, cdest, msgid);
      if (ctxt->Ng > 2)
      {
         i = (ctxt->Ng+ctxt->vIam-1) % ctxt->Ng;
	 Mvpcoord(ctxt, i, rdest, cdest);
         Ssend2d00(ctxt, rdest, cdest, msgid);
      }
      break;
   default:
      return(BADSCP);
   }
   return(0);
}
