
void getdevs(short mbox[], int mnum, float med, float *stdev)
{
  int i,j,cnum;
  float rrr,rrc;
  float diff;

  rrr=0.0;
  for (i=0; i<mnum; i++){
    rrr = rrr + (mbox[i] - med)*(mbox[i] - med);
  }
  rrr=sqrt(rrr/mnum);

  for(j=0; j<5; j++){
    rrc=0;
    cnum=0;
    for (i=0; i<mnum; i++){
      diff=mbox[i]-med;
      if(fabs(diff)<3*rrr){
        rrc = rrc + diff*diff;
        cnum++;
      }
    }
    rrc=sqrt(rrc/cnum);
    rrr=rrc;
  }

  *stdev=rrc;
  
}

