# include "astro.h"

void ralter_header (head, ref, X_O, X_X, X_Y, dX, Y_O, Y_X, Y_Y, dY, N)
char head[], ref[];
double X_O, X_X, X_Y, dX, Y_O, Y_X, Y_Y, dY;
int N;
{

  Header header;
  char tmp[200], line[500], *c;

  fits_read_header (head, &header);

  fits_modify (&header, "X_O", "%lf", 1, X_O);
  fits_modify (&header, "X_X", "%lf", 1, X_X);
  fits_modify (&header, "X_Y", "%lf", 1, X_Y);
  fits_modify (&header,  "dX", "%lf", 1,  dX);
  fits_modify (&header, "Y_O", "%lf", 1, Y_O);
  fits_modify (&header, "Y_X", "%lf", 1, Y_X);
  fits_modify (&header, "Y_Y", "%lf", 1, Y_Y);
  fits_modify (&header,  "dY", "%lf", 1,  dY);
  if ((c = strrchr (ref, '/')) != NULL) 
    fits_modify (&header, "rREF", "%s", 1, c+1);
  else
    fits_modify (&header, "rREF", "%s", 1, ref);
  fits_modify (&header, "rNSTARs", "%d", 1, N);

  fits_modify (&header, "X_O", "%C", 1, "rastro coeff");
  fits_modify (&header, "X_X", "%C", 1, "rastro coeff");
  fits_modify (&header, "X_Y", "%C", 1, "rastro coeff");
  fits_modify (&header,  "dX", "%C", 1, "error (pixels)");
  fits_modify (&header, "Y_O", "%C", 1, "rastro coeff");
  fits_modify (&header, "Y_X", "%C", 1, "rastro coeff");
  fits_modify (&header, "Y_Y", "%C", 1, "rastro coeff");
  fits_modify (&header,  "dY", "%C", 1, "error (pixels)");
  fits_modify (&header, "rREF", "%C", 1, "rastro ref file");
  fits_modify (&header, "rNSTARs", "%C", 1, "number of stars used");

  strcpy (tmp, head);
  strcat (tmp, "~");
  sprintf (line, "mv %s %s\0", head, tmp);
  system (line);

  fits_write_header (head, &header);
  fits_free_header (&header);

}
