# include <dvo.h>

/* convert elixir-format measures to internal measures */
Measure *MeasureElixirToInternal (MeasureElixir *in, int Nvalues) {

  int i;
  Measure *out;

  ALLOCATE (out, Measure, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].dR         = in[i].dR;
    out[i].dD         = in[i].dD;
    out[i].M          = in[i].M;
    out[i].dM         = in[i].dM;
    out[i].dt         = in[i].dt;
    out[i].Mcal       = in[i].Mcal;
    out[i].Mgal       = in[i].Mgal;
    out[i].airmass    = in[i].airmass;
    out[i].FWx 	      = in[i].FWx;
    out[i].FWy 	      = in[i].FWy;
    out[i].theta      = in[i].theta;
    out[i].dophot     = in[i].dophot;
    out[i].photcode   = in[i].source;
    out[i].t          = in[i].t;
    out[i].averef     = in[i].averef;
    out[i].flags      = in[i].flags;

    out[i].Xccd       = in[i].Xccd;
    out[i].Yccd       = in[i].Yccd;
    out[i].dXccd      = in[i].dXccd;
    out[i].dYccd      = in[i].dYccd;
					    
    out[i].stargal    = in[i].stargal;
    out[i].Sky        = in[i].Sky;
    out[i].dSky       = in[i].dSky;
    out[i].qPSF       = in[i].qPSF;
					    
    out[i].detID_hi   = in[i].detID_hi;
    out[i].detID_lo   = in[i].detID_lo;
    out[i].imageID_hi = in[i].imageID_hi;
    out[i].imageID_lo = in[i].imageID_lo;
  }
  return (out);
}

/* convert internal measures to elixir-format measures */
MeasureElixir *MeasureInternalToElixir (Measure *in, int Nvalues) {

  int i;
  MeasureElixir *out;

  ALLOCATE (out, MeasureElixir, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].dR         = in[i].dR;
    out[i].dD         = in[i].dD;
    out[i].M          = in[i].M;
    out[i].dM         = in[i].dM;
    out[i].dt         = in[i].dt;
    out[i].Mcal       = in[i].Mcal;
    out[i].Mgal       = in[i].Mgal;
    out[i].airmass    = in[i].airmass;
    out[i].FWx 	      = in[i].FWx;
    out[i].FWy 	      = in[i].FWy;
    out[i].theta      = in[i].theta;
    out[i].dophot     = in[i].dophot;
    out[i].photcode   = in[i].source;
    out[i].t          = in[i].t;
    out[i].averef     = in[i].averef;
    out[i].flags      = in[i].flags;

    out[i].Xccd       = in[i].Xccd;
    out[i].Yccd       = in[i].Yccd;
    out[i].dXccd      = in[i].dXccd;
    out[i].dYccd      = in[i].dYccd;
					    
    out[i].stargal    = in[i].stargal;
    out[i].Sky        = in[i].Sky;
    out[i].dSky       = in[i].dSky;
    out[i].qPSF       = in[i].qPSF;
					    
    out[i].detID_hi   = in[i].detID_hi;
    out[i].detID_lo   = in[i].detID_lo;
    out[i].imageID_hi = in[i].imageID_hi;
    out[i].imageID_lo = in[i].imageID_lo;
  }
  return (out);
}

/* convert panstarrs-format averages to internal averages */
Average *AveragePMtestToInternal (AveragePMtest *in, int Nvalues) {

  int i;
  Average *out;

  ALLOCATE (out, Average, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].R       = in[i].R;      
    out[i].D       = in[i].D;      
    out[i].dR      = in[i].dR;      
    out[i].dD      = in[i].dD;      

    out[i].uR      = in[i].uR;      
    out[i].uD      = in[i].uD;      
    out[i].duR     = in[i].duR;      
    out[i].duD     = in[i].duD;      
    out[i].P       = in[i].P;      
    out[i].dP      = in[i].dP;      

    out[i].M       = in[i].M;      
    out[i].dM      = in[i].dM;
    out[i].Xp      = in[i].Xp;     
    out[i].Xm      = in[i].Xm;     
    out[i].Xg      = in[i].Xg;
    out[i].Nm      = in[i].Nm;     
    out[i].Nn      = in[i].Nn;     
    out[i].code    = in[i].code;   
    out[i].offset  = in[i].offset; 
    out[i].missing = in[i].missing;
  }
  return (out);
}

/* convert internal averages to panstarrs-format averages */
AveragePMtest *AverageInternalToPMtest (Average *in, int Nvalues) {

  int i;
  AveragePMtest *out;

  ALLOCATE (out, AveragePMtest, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].R       = in[i].R;      
    out[i].D       = in[i].D;      
    out[i].dR      = in[i].dR;      
    out[i].dD      = in[i].dD;      

    out[i].uR      = in[i].uR;      
    out[i].uD      = in[i].uD;      
    out[i].duR     = in[i].duR;      
    out[i].duD     = in[i].duD;      
    out[i].P       = in[i].P;      
    out[i].dP      = in[i].dP;      

    out[i].M       = in[i].M;      
    out[i].dM      = in[i].dM;
    out[i].Xp      = in[i].Xp;     
    out[i].Xm      = in[i].Xm;     
    out[i].Xg      = in[i].Xg;
    out[i].Nm      = in[i].Nm;     
    out[i].Nn      = in[i].Nn;     
    out[i].code    = in[i].code;   
    out[i].offset  = in[i].offset; 
    out[i].missing = in[i].missing;
  }
  return (out);
}

