IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40406 for trunk


Ignore:
Timestamp:
Apr 25, 2018, 10:29:37 AM (8 years ago)
Author:
eugene
Message:

fix segfault due to missing mask vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c

    r40291 r40406  
    1212    if ((mvec = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);
    1313    remove_argument (N, &argc, argv);
    14     CastVector (mvec, OPIHI_INT);
    1514  }
    1615
     
    8180  double *dD = dDvec->elements.Flt;
    8281
    83   opihi_int *mask = NULL;
    84   if (mvec) {
    85     mask = mvec->elements.Int;
    86   }
    87 
    8882  // Ntotal : all points supplied by user
    8983  // Nsubset : unmasked points
    9084  int Ntotal = tvec->Nelements; // XXX check other lengths
    91  
     85
     86  if (rvec->Nelements  != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs ra)  = (%d vs %d)\n", rvec->Nelements, Ntotal);
     87  if (dvec->Nelements  != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dec) = (%d vs %d)\n", dvec->Nelements, Ntotal);
     88  if (dRvec->Nelements != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dR)  = (%d vs %d)\n", dRvec->Nelements, Ntotal);
     89  if (dDvec->Nelements != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dD)  = (%d vs %d)\n", dDvec->Nelements, Ntotal);
     90 
     91  opihi_int *mask = NULL;
     92  if (mvec) {
     93    ResetVector (mvec, OPIHI_INT, Ntotal);
     94    mask = mvec->elements.Int;
     95    for (i = 0; i < Ntotal; i++) { mask[i] = 1; }
     96  }
     97
     98
    9299  double Rmean, Dmean, Tmean;
    93100  PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
     
    135142
    136143  // update the mask based on the input mask and the outlier limits.
    137   double Sum_Wx = 0;
    138   double Sum_Wy = 0;
    139   mask = mvec->elements.Int;
    140   for (i = 0; i < fitdata.Npts; i++) {
    141     Sum_Wx += fitdata.Wx[i];
    142     Sum_Wy += fitdata.Wy[i];
    143   }
    144   for (i = 0; i < fitdata.Npts; i++) {
    145     // fitdata only includes the previously unmasked points
    146     if ((fitdata.Wx[i] < outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))||
    147         (fitdata.Wy[i] < outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) {
    148       int n = fitdata.index[i];
    149       mask[n] = 0;
     144  if (mask) {
     145    double Sum_Wx = 0;
     146    double Sum_Wy = 0;
     147   
     148    // calculate the total weight
     149    for (i = 0; i < fitdata.Npts; i++) {
     150      Sum_Wx += fitdata.Wx[i];
     151      Sum_Wy += fitdata.Wy[i];
     152    }
     153    for (i = 0; i < fitdata.Npts; i++) {
     154      // fitdata only includes the previously unmasked points
     155      if ((fitdata.Wx[i] < outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))||
     156          (fitdata.Wy[i] < outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) {
     157        int n = fitdata.index[i];
     158        mask[n] = 0;
    150159     
    151       if (VERBOSE == 2) {
     160        if (VERBOSE == 2) {
    152161          fprintf (stderr, "%f %f : %f "OPIHI_INT_FMT" : %f %f %f : %f %f %f %f\n", R[n], D[n], T[n], mask[n], fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.Wx[i], fitdata.Wy[i], Sum_Wx, Sum_Wy);
    153       }
    154     }
    155   }
    156 
    157   if (Nresample){
    158     // now that the mask has been updated, we need to recalculate mean epoch and positions
    159     // XXX make this conditional on actually masking unmasked points above
    160     // PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
    161     // PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
     162        }
     163      }
     164    }
     165  }
     166
     167  if (Nresample) {
     168    // if the mask has been updated, we need to recalculate mean epoch and positions
     169    if (mask) {
     170      PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
     171      PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
     172    }
    162173
    163174    PlxFitData sample;
     
    218229  // fprintf (stderr, "%f +/- %f | %f %f\n", fit.p, fit.dp, fit.uR, fit.uD);
    219230
    220   Vector *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
     231  Vector *dRresPOS, *dDresPOS, *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
    221232
    222233  // save fit residuals (with only pm removed, and pm and plx removed)
     234  if ((dRresPOS = SelectVector ("dRresPOS", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPOS");
     235  if ((dDresPOS = SelectVector ("dDresPOS", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPOS");
    223236  if ((dRresPMP = SelectVector ("dRresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPMP");
    224237  if ((dDresPMP = SelectVector ("dDresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPMP");
     
    226239  if ((dDresPLX = SelectVector ("dDresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPLX");
    227240   
     241  ResetVector (dRresPOS, OPIHI_FLT, Ntotal);
     242  ResetVector (dDresPOS, OPIHI_FLT, Ntotal);
    228243  ResetVector (dRresPMP, OPIHI_FLT, Ntotal);
    229244  ResetVector (dDresPMP, OPIHI_FLT, Ntotal);
     
    246261    double Yplx = fit.Do + fit.uD*t0;
    247262
     263    dRresPOS->elements.Flt[i] = x0;
     264    dDresPOS->elements.Flt[i] = y0;
    248265    dRresPMP->elements.Flt[i] = x0 - Xpmp;
    249266    dDresPMP->elements.Flt[i] = y0 - Ypmp;
Note: See TracChangeset for help on using the changeset viewer.