# include "fits.h"

/*********************** fits insert array ***********************************/
void fits_add_matrix (matrix, array, x, y) 
Matrix *matrix, *array; 
int x, y;
{

  /* there is no check here to match BITPIX, BZERO, or BSCALE */

  int i, j;
  double V;

  if ((x + array[0].Naxis[0] > matrix[0].Naxis[0]) ||
      (y + array[0].Naxis[1] > matrix[0].Naxis[1])) {
    fprintf (stderr, "can't add array here: (%d,%d) - (%d,%d) vs (%d,%d)\n",
	     x, y, x + array[0].Naxis[0], y + array[0].Naxis[1],
	     matrix[0].Naxis[0], matrix[0].Naxis[1]);
    return;
  }

  for (i = 0; i < array[0].Naxis[0]; i++) {
    for (j = 0; j < array[0].Naxis[1]; j++) {
      V = fits_get_matrix_value (array, i, j);
      V += fits_get_matrix_value (matrix, x + i, y + j);
      fits_set_matrix_value (matrix, x + i, y + j, V);
    }
  }
}

