# include <dvo.h>

/* convert panstarrs-format measures to internal measures */
Measure *MeasurePanstarrs_DEV_0_ToInternal (MeasurePanstarrs_DEV_0 *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].Mcal       = in[i].Mcal;
    out[i].Mgal       = in[i].Mgal;
    out[i].airmass    = in[i].airmass;
    out[i].az         = in[i].az;
    out[i].dt         = in[i].dt;
    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].photcode;
    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 panstarrs-format measures */
MeasurePanstarrs_DEV_0 *MeasureInternalToPanstarrs_DEV_0 (Measure *in, int Nvalues) {

  int i;
  MeasurePanstarrs_DEV_0 *out;

  ALLOCATE (out, MeasurePanstarrs_DEV_0, 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].Mcal       = in[i].Mcal;
    out[i].Mgal       = in[i].Mgal;
    out[i].airmass    = in[i].airmass;
    out[i].az         = in[i].az;
    out[i].dt         = in[i].dt;
    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].photcode;
    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 *AveragePanstarrs_DEV_0_ToInternal (AveragePanstarrs_DEV_0 *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].Xp       = in[i].Xp;     
    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;
    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].objID_hi = in[i].objID_hi;
    out[i].objID_lo = in[i].objID_lo;
  }
  return (out);
}

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

  int i;
  AveragePanstarrs_DEV_0 *out;

  ALLOCATE (out, AveragePanstarrs_DEV_0, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].R        = in[i].R;      
    out[i].D        = in[i].D;      
    out[i].Xp       = in[i].Xp;     
    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;
    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].objID_hi = in[i].objID_hi;
    out[i].objID_lo = in[i].objID_lo;
  }
  return (out);
}

/* convert panstarrs-format secfilts to internal secfilts */
SecFilt *SecFiltPanstarrs_DEV_0_ToInternal (SecFiltPanstarrs_DEV_0 *in, int Nvalues) {

  int i;
  SecFilt *out;

  ALLOCATE (out, SecFilt, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].M     = in[i].M;      
    out[i].dM    = in[i].dM;      
    out[i].Xm    = in[i].Xm;     
    out[i].Ncode = in[i].Ncode;
    out[i].Nused = in[i].Nused;
 }
  return (out);
}

/* convert internal secfilts to panstarrs-format secfilts */
SecFiltPanstarrs_DEV_0 *SecFiltInternalToPanstarrs_DEV_0 (SecFilt *in, int Nvalues) {

  int i;
  SecFiltPanstarrs_DEV_0 *out;

  ALLOCATE (out, SecFiltPanstarrs_DEV_0, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    out[i].M     = in[i].M;      
    out[i].dM    = in[i].dM;      
    out[i].Xm    = in[i].Xm;     
    out[i].Ncode = in[i].Ncode;
    out[i].Nused = in[i].Nused;
  }
  return (out);
}

/* convert panstarrs-format images to internal images */
Image *ImagePanstarrs_DEV_0_ToInternal (ImagePanstarrs_DEV_0 *in, int Nvalues) {

  int i;
  Image *out;

  ALLOCATE (out, Image, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    strcpy (out[i].name, in[i].name);

    out[i].tzero    	    = in[i].tzero;
    out[i].nstar    	    = in[i].nstar;
    out[i].secz	    	    = in[i].secz;
    out[i].NX	    	    = in[i].NX;
    out[i].NY	    	    = in[i].NY;
    out[i].apmifit  	    = in[i].apmifit;
    out[i].dapmifit 	    = in[i].dapmifit;
    out[i].Mcal	    	    = in[i].Mcal;
    out[i].dMcal    	    = in[i].dMcal;
    out[i].Xm	    	    = in[i].Xm;
    out[i].photcode   	    = in[i].photcode;
    out[i].exptime  	    = in[i].exptime;
    out[i].sidtime  	    = in[i].sidtime;
    out[i].latitude  	    = in[i].latitude;
    out[i].detection_limit  = in[i].detection_limit;
    out[i].saturation_limit = in[i].saturation_limit;
    out[i].cerror	    = in[i].cerror;
    out[i].fwhm_x	    = in[i].fwhm_x;
    out[i].fwhm_y	    = in[i].fwhm_y;
    out[i].trate	    = in[i].trate;
    out[i].code		    = in[i].code;
    out[i].ccdnum	    = in[i].ccdnum;
    out[i].imageID_hi	    = in[i].imageID_hi;
    out[i].imageID_lo	    = in[i].imageID_lo;

    out[i].order	    = in[i].order;
    out[i].Mx		    = in[i].Mx;
    out[i].My		    = in[i].My;
    out[i].Mxx		    = in[i].Mxx;
    out[i].Mxy		    = in[i].Mxy;
    out[i].Myy		    = in[i].Myy;
    out[i].Mxxx		    = in[i].Mxxx;
    out[i].Mxxy		    = in[i].Mxxy;
    out[i].Mxyy		    = in[i].Mxyy;
    out[i].Myyy		    = in[i].Myyy;
    out[i].Mxxxx	    = in[i].Mxxxx;
    out[i].Mxxxy	    = in[i].Mxxxy;
    out[i].Mxxyy	    = in[i].Mxxyy;
    out[i].Mxyyy	    = in[i].Mxyyy;
    out[i].Myyyy	    = in[i].Myyyy;
  }
  return (out);
}

/* convert internal images to panstarrs-format images */
ImagePanstarrs_DEV_0 *ImageInternalToPanstarrs_DEV_0 (Image *in, int Nvalues) {

  int i;
  ImagePanstarrs_DEV_0 *out;

  ALLOCATE (out, ImagePanstarrs_DEV_0, Nvalues);

  for (i = 0; i < Nvalues; i++) {
    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    strcpy (out[i].name, in[i].name);

    out[i].tzero    	    = in[i].tzero;
    out[i].nstar    	    = in[i].nstar;
    out[i].secz	    	    = in[i].secz;
    out[i].NX	    	    = in[i].NX;
    out[i].NY	    	    = in[i].NY;
    out[i].apmifit  	    = in[i].apmifit;
    out[i].dapmifit 	    = in[i].dapmifit;
    out[i].Mcal	    	    = in[i].Mcal;
    out[i].dMcal    	    = in[i].dMcal;
    out[i].Xm	    	    = in[i].Xm;
    out[i].photcode   	    = in[i].photcode;
    out[i].exptime  	    = in[i].exptime;
    out[i].sidtime  	    = in[i].sidtime;
    out[i].latitude  	    = in[i].latitude;
    out[i].detection_limit  = in[i].detection_limit;
    out[i].saturation_limit = in[i].saturation_limit;
    out[i].cerror	    = in[i].cerror;
    out[i].fwhm_x	    = in[i].fwhm_x;
    out[i].fwhm_y	    = in[i].fwhm_y;
    out[i].trate	    = in[i].trate;
    out[i].code		    = in[i].code;
    out[i].ccdnum	    = in[i].ccdnum;
    out[i].imageID_hi	    = in[i].imageID_hi;
    out[i].imageID_lo	    = in[i].imageID_lo;

    out[i].order	    = in[i].order;
    out[i].Mx		    = in[i].Mx;
    out[i].My		    = in[i].My;
    out[i].Mxx		    = in[i].Mxx;
    out[i].Mxy		    = in[i].Mxy;
    out[i].Myy		    = in[i].Myy;
    out[i].Mxxx		    = in[i].Mxxx;
    out[i].Mxxy		    = in[i].Mxxy;
    out[i].Mxyy		    = in[i].Mxyy;
    out[i].Myyy		    = in[i].Myyy;
    out[i].Mxxxx	    = in[i].Mxxxx;
    out[i].Mxxxy	    = in[i].Mxxxy;
    out[i].Mxxyy	    = in[i].Mxxyy;
    out[i].Mxyyy	    = in[i].Mxyyy;
    out[i].Myyyy	    = in[i].Myyyy;
  }
  return (out);
}
