# include "relastro.h"

float GetAstromError (Measure *measure, int mode) {

  PhotCode *code;
  float dPobs, dPsys, dPtotal, dM, AS, MS;

  switch (mode) {
    case ERROR_MODE_RA:
      dPobs = measure[0].dXccd / 100.0;  // need to redefine this as RAerr
      break;
    case ERROR_MODE_DEC:
      dPobs = measure[0].dYccd / 100.0;  // need to redefine this as RAerr
      break;
    case ERROR_MODE_POS:
      dPobs = hypot (measure[0].dXccd, measure[0].dYccd) / 100.0;  // need to redefine this as RAerr
      break;
    default:
      abort();
  }

  /* the astrometric errors are not being carried yet (but should be!) */
  /* we use the photometric mag error as a weighting term */

  code 	= GetPhotcodebyCode (measure[0].photcode);
  AS   	= code[0].astromErrScale;
  MS   	= code[0].astromErrMagScale;
  dPsys = code[0].astromErrSys;
  dM    = measure[0].dM;
  
  dPtotal = sqrt(SQ(dPsys) + AS*SQ(dPobs) + MS*SQ(dM));

  //XXX dXccd, dYccd are now working correctly
  //dPtotal = AS * dPobs;

  dPtotal = MAX (dPtotal, MIN_ERROR);

  return (dPtotal);
}

