# include "Ximage.h"

int Center (Graphic *graphic, Layout *layout) {

  char buffer[1024];
  int status, zoom, Nbytes;
  double X, Y;

  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
  status = read (layout[0].Ximage, buffer, 16); 
  buffer[16] = 0; 
  sscanf (buffer, "%*s %d", &Nbytes); 
  status = read (layout[0].Ximage, buffer, Nbytes); 
  buffer[status] = 0; /* make the string easy to parse */ 
  sscanf (buffer, "%lf %lf %d", &X,  &Y, &zoom);

  layout[0].X = 0.5*layout[0].matrix.Naxis[0] - X;
  layout[0].Y = 0.5*layout[0].matrix.Naxis[1] - Y;
  if ((zoom != 0) && (zoom != -1)) {
    layout[0].expand = zoom;
  }

  if (USE_XWINDOW) {
    Remap (graphic, layout, &layout[0].matrix);
    Refresh (graphic, layout, 0);
    XFlush (graphic[0].display);
  }

  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
  return (TRUE);
}

