/* array02 - tests for MathArray from libMathArray

   Copyright (C) 1995, Adam Fedor

*/

#ifdef NEXT_FOUNDATION
#include <foundation/NSValue.h>
#else
#include <Foundation/NSValue.h>
#endif
#include <stdio.h>
#include <math.h>
#include "MathArray/MathArray.h"
#include "MathArray/MaskedException.h"
#include "MathArray/MAValue.h"
#include "MathArray/MAValueData.h"

/* Replace value by the exponent of it's index */
id <NSNumber,ComplexNumber>
exp_array(id <NSNumber,ComplexNumber>number, unsigned *index, void *info)
{
    return [MANumber numberWithDouble:index[0]*index[1]];
}

int
main()
{
  MathArray *array;
  unsigned  index[2];
  double *data;

  [MaskedException bodysnatchNSException];
  [MaskedException setMaskForAllExceptions:AbortException];


  /* Matrices */
  printf("Create 64X64 matrix...\n");
  array = [MathArray maMatrixWithCols:64 rows:64 objCType:NULL];

  printf("Perform user function...\n");
  [array maPerformFunction:exp_array userInfo:NULL];


  printf("Perform fft with origin in center...\n");
  index[0] = 32;
  index[1] = 32;
  data = [[array mathData] mutableBytes];
  [array maShift:index];
  [array maFFt:-1];
  [array maShift:index];
  data = [[array mathData] mutableBytes];

  index[0] = 32;
  index[1] = 32;
  printf("Value at (32,32) is %g (should be 992.250)\n", 
	[[array arrayValueAtIndex:index] doubleValue]);
  printf("Total is %g (should be 1024.00)\n", [[array maTotal] doubleValue]);

  return 0;
}
