Example #1
0
int main(void) {
  int num = 16;
  float *a = createvect(num),
        *b = createvect(num),
        *c = createvect(num);
  
  setvect(NUM, a, 1);
  setvect(NUM, b, 1);
  setvect(NUM, c, 1);
  int i;
  for (i = 0; i != num; i++) {
    a[i] = i;
    b[i] = num - i - 1;
  }
 
  // given addition test
  foobar(NUM, a, b, c);
  printf("0: a = ");
  printvect(NUM, a);
  printf("\n");
  printf("   b = ");
  printvect(NUM, b);
  printf("\n");
  printf("   c = ");
  printvect(NUM, c);
  printf("\n");

  return 0;
}
Example #2
0
void snaprect(bodyptr btab, int nbody)
{
  matrix qmat, tmpm;
  bodyptr bp;
  vector frame[3], tmpv;
  static vector oldframe[3] =
    { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 0.0, }, { 0.0, 0.0, 1.0, }, };
  int i;

  snapcenter(btab, nbody, WeightField.offset);
  CLRM(qmat);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    OUTVP(tmpm, Pos(bp), Pos(bp));
    MULMS(tmpm, tmpm, Weight(bp));
    ADDM(qmat, qmat, tmpm);
  }
  eigenvect(frame[0], frame[1], frame[2], qmat);
  if (dotvp(oldframe[0], frame[0]) < 0.0)
    MULVS(frame[0], frame[0], -1.0);
  if (dotvp(oldframe[2], frame[2]) < 0.0)
    MULVS(frame[2], frame[2], -1.0);
  CROSSVP(frame[1], frame[2], frame[0]);
  printvect("e_x:", frame[0]);
  printvect("e_y:", frame[1]);
  printvect("e_z:", frame[2]);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    if (PosField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Pos(bp), frame[i]);
      SETV(Pos(bp), tmpv);
    }
    if (VelField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Vel(bp), frame[i]);
      SETV(Vel(bp), tmpv);
    }
    if (AccField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Acc(bp), frame[i]);
      SETV(Acc(bp), tmpv);
    }
    if (AuxVecField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(AuxVec(bp), frame[i]);
      SETV(AuxVec(bp), tmpv);
    }
  }
  for (i = 0; i < NDIM; i++)
    SETV(oldframe[i], frame[i]);
}    
Example #3
0
int main(void) {
  float *a = createvect(NUM);

  // assign an int
  setvect(NUM, a, 1);
  assignInt(NUM, a);
  printf("0: a = ");
  printvect(NUM, a);
  printf("\n");
  
  // assign then reassign an int
  setvect(NUM, a, 1);
  reassignInt(NUM, a);
  printf("1: a = ");
  printvect(NUM, a);
  printf("\n");
  
  // assign a foat
  setvect(NUM, a, 1);
  assignFloat(NUM, a);
  printf("2: a = ");
  printvect(NUM, a);
  printf("\n");
  
  // assign then reassign a float
  setvect(NUM, a, 1);
  reassignFloat(NUM, a);
  printf("3: a = ");
  printvect(NUM, a);
  printf("\n");
  
  // tricky example
  setvect(NUM, a, 1);
  tricky(NUM, a);
  printf("4: a = ");
  printvect(NUM, a);
  printf("\n");

  return 0;
}
Example #4
0
int main(void) {
  // Create vectors
  float *a = createvect(NUM);

  // Assign values
  setvect(NUM, a, 1);

  // and invoke the function written in the vector language
  // and read values from c
  
  // test 0
  test0(NUM, a);
  printf("0: a = ");
  printvect(NUM, a);
  printf("\n");
  
  return 0;
}
Example #5
0
void printpart(part* p)
{
  printvect(p->pos);
}
Example #6
0
int main(void) {
    float *a = createvect(NUM),
           *b = createvect(NUM);

    // incrementing up to 20
    setvect(NUM, a, 1);
    basicIncrement(NUM, a);
    printf("0: a = ");
    printvect(NUM, a);
    printf("\n");

    // nested while loop
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    nested(NUM, a, b);
    printf("1: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // nested while loop
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    nested2(NUM, a, b);
    printf("2: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // a and b changing relative to each other
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    relativeChange(NUM, a, b);
    printf("3: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // while with an if loop inside it
    setvect(NUM, a, 1);
    setvect(NUM, b, 3);
    whileIf(NUM, a, b);
    printf("4: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // if with a while loop inside it
    setvect(NUM, a, 1);
    setvect(NUM, b, 0);
    ifWhile(NUM, a, b);
    printf("5: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // else in big if else statement
    setvect(NUM, a, 1);
    setvect(NUM, b, 4);
    ifWhile(NUM, a, b);
    printf("6: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    return 0;
}