#include "Bdef.h"

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

   int msgid;
   int rdest, cdest;

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

      msgid = Maid(ctxt);
      Ssend2d00(ctxt, rdest, cdest, msgid);
      break;
   default:
      return(BADSCP);
   }
   return(0);
}
