IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 25, 2012, 10:26:16 AM (14 years ago)
Author:
eugene
Message:

dvo/opihi updates from gene (add 1D splines, where conditions on plots)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/plot.c

    r32346 r34584  
    33int plot (int argc, char **argv) {
    44 
    5   int kapa, N, Npts;
     5  char *out;
     6  int kapa, N, Npts, valid, size, i;
    67  Graphdata graphmode;
    78  Vector *xvec, *yvec, *dxmvec, *dxpvec, *dymvec, *dypvec;
     
    3233  }
    3334
    34   if (argc != 3) {
     35  valid  = (argc == 3);
     36  valid |= (argc > 4) && !strcmp (argv[3], "where");
     37  if (!valid) {
    3538    gprint (GP_ERR, "USAGE: plot <x> <y> [style]\n");
     39    gprint (GP_ERR, "   OR: plot <x> <y> [style] where (condition)\n");
    3640    return (FALSE);
     41  }
     42
     43  // tvec is used for logical test (truth vector)
     44  Vector *tvec = NULL;
     45  char *mask = NULL;
     46  if (argc > 4) {
     47    out = dvomath (argc - 4, &argv[4], &size, 1);
     48    if (out == NULL) {
     49      print_error ();
     50      return FALSE;
     51    }
     52    if ((tvec = SelectVector (out, OLDVECTOR, TRUE)) == NULL) {
     53      gprint (GP_ERR, " invalid logic result\n");
     54      DeleteNamedVector (out);
     55      free (out);
     56      return (FALSE);
     57    }
    3758  }
    3859
     
    5374    return (FALSE);
    5475  }
     76  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
     77    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     78    return (FALSE);
     79  }
    5580  if (dypvec && (dypvec->Nelements != xvec->Nelements)) goto mismatch;
    5681  if (dymvec && (dymvec->Nelements != xvec->Nelements)) goto mismatch;
     
    5984
    6085  Npts = xvec[0].Nelements;
    61   if (Npts == 0) return (TRUE);
     86  if (Npts == 0) {
     87    if (tvec) DeleteVector (tvec);
     88    return (TRUE);
     89  }
     90
     91  if (tvec) {
     92    Npts = 0;
     93    ALLOCATE (mask, char, tvec->Nelements);
     94    for (i = 0; i < tvec->Nelements; i++) {
     95      mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     96      if (!mask[i]) Npts ++;
     97    }
     98    if (Npts == 0) {
     99      DeleteVector (tvec);
     100      free (mask);
     101      return TRUE;
     102    }
     103  }
    62104
    63105  if (!KapaPrepPlot (kapa, Npts, &graphmode)) return (FALSE);
    64106 
    65   PlotVectorSingle (kapa, xvec, "x");
    66   PlotVectorSingle (kapa, yvec, "y");
     107  PlotVectorSingle (kapa, xvec, mask, "x");
     108  PlotVectorSingle (kapa, yvec, mask, "y");
    67109  if (graphmode.etype & 0x01) {
    68     PlotVectorSingle (kapa, dymvec, "dym");
    69     PlotVectorSingle (kapa, dypvec, "dyp");
     110    PlotVectorSingle (kapa, dymvec, mask, "dym");
     111    PlotVectorSingle (kapa, dypvec, mask, "dyp");
    70112  }
    71113  if (graphmode.etype & 0x02) {
    72     PlotVectorSingle (kapa, dxmvec, "dxm");
    73     PlotVectorSingle (kapa, dxpvec, "dxp");
     114    PlotVectorSingle (kapa, dxmvec, mask, "dxm");
     115    PlotVectorSingle (kapa, dxpvec, mask, "dxp");
     116  }
     117
     118  if (tvec) {
     119    free (mask);
     120    DeleteVector (tvec);
    74121  }
    75122  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.