# include "dvoImageOverlaps.h"

// examine the PHU of this file and determine the file mode
int GetFileMode (Header *header) {

  char ctype[80];
  int Naxis, Nx, Ny;
  int simple, extend, haveNaxis, haveNx, haveNy, haveCTYPE;

  gfits_scan (header, "SIMPLE", "%t", 1, &simple);
  haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
  haveNx    = gfits_scan (header, "NAXIS1", "%d", 1, &Nx);
  haveNy    = gfits_scan (header, "NAXIS2", "%d", 1, &Ny);
  haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);

  gfits_scan (header, "EXTEND", "%t", 1, &extend);
    
  if ((Naxis == 2) || !simple) {
    if (!strcmp (&ctype[4], "-WRP")) {
      return MOSAIC_CMP;
    }
    return SIMPLE_CMP;
  }

  if (!extend && strcmp (&ctype[4], "-DIS")) {
    if (!strcmp (&ctype[4], "-WRP")) {
      return MOSAIC_CMF;
    }
    return SIMPLE_CMF;
  }

  if (!extend && !strcmp (&ctype[4], "-DIS")) {
    return MOSAIC_PHU;
  }

  if (extend && strcmp (&ctype[4], "-DIS")) {
    return SIMPLE_MEF;
  }

  if (extend && !strcmp (&ctype[4], "-DIS")) {
    return MOSAIC_MEF;
  }

  return (NONE);
}
