# include "astro.h"

void stats (head, RA, DEC, dRA, dDEC, ASEC_PIX)
char head[];
double *RA, *DEC;
double *dRA, *dDEC;
double  ASEC_PIX;
{

  int j, status;
  Header header;
  char ra[100], dec[100];
  double epoch;
  
  status = fits_read_header (head, &header);

  if (!status) {
    fprintf (stderr, "file %s not found\n", head);
    exit (0);
  }

  if (!FORCE) {
    fits_scan (&header, "RA", "%s", 1, ra);
    *RA = 15*dms_to_deg (ra, ':');
    
    fits_scan (&header, "DEC", "%s", 1, dec);
    *DEC = dms_to_deg (dec, ':');

    /* FITS uses either EPOCH or EQUINOX.  EPOCH is supposed to be
       outmoded, but you can't tell,right?  fits_scan will not alter the
       value if it fails, so 2000.0 will act as a default, and EQUINOX
       will override EPOCH if both exist */
    epoch = 2000.0;
    fits_scan (&header, "EPOCH", "%lf", 1, &epoch);
    fits_scan (&header, "EQUINOX", "%lf", 1, &epoch);

    fprintf (stderr, "%s -> %lf %s -> %lf, %lf\n", ra, *RA, dec, *DEC, epoch);

    precess (RA, DEC, epoch, 2000.0);  /* I want only 2000.0 here! */
    
    fprintf (stderr, "%s -> %lf %s -> %lf, %lf\n", ra, *RA, dec, *DEC, 2000.0);
  }

  *dRA  = header.Naxis[0] * ASEC_PIX / 3600.0;
  *dDEC = header.Naxis[1] * ASEC_PIX / 3600.0;
}

double dms_to_deg (string, sep) 
char *string;
int  sep;  
{
  
  char C[20];
  int c, d;
  double h, flag;
  
  d = h = 0;
  if (strchr (string, sep) == NULL)
    return (HUGE_VAL);
  c = strlen(string) - strlen(strchr(string, sep));
  strncpy (C, string, c);
  C[c] = 0;
  h = atof(C);
  if (strchr(C, '-') != NULL) 
    flag = -1.0;
  else
    flag = 1.0;
  h *= flag;

  d += c + 1;
  c = strlen(&string[d]) - strlen(strchr(&string[d], sep));
  strncpy (C, &string[d], c);
  C[c] = 0;
  h += atof(C)/60.0;

  d += c + 1;
  strcpy (C, &string[d]);
  h += atof(C)/3600.;

  h *= flag;
  return (h);
}
