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/zplot.c

    r31667 r34584  
    33int zplot (int argc, char **argv) {
    44 
    5   int i, kapa;
     5  char *outname;
     6  int i, kapa, valid, size;
    67  opihi_flt *out;
    78  double min, range;
     
    1112  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    1213
    13   if (argc != 6) {
     14  valid  = (argc == 6);
     15  valid |= (argc > 7) && !strcmp (argv[6], "where");
     16  if (!valid) {
    1417    gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
     18    gprint (GP_ERR, "   OR: zplot <x> <y> <z> min max where (condition)\n");
    1519    return (FALSE);
    1620  }
     
    1822  min = atof(argv[4]);
    1923  range = atof(argv[5]) - min;
     24
     25  // tvec is used for logical test (truth vector)
     26  Vector *tvec = NULL;
     27  char *mask = NULL;
     28  if (argc > 7) {
     29    outname = dvomath (argc - 7, &argv[7], &size, 1);
     30    if (outname == NULL) {
     31      print_error ();
     32      return FALSE;
     33    }
     34    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
     35      gprint (GP_ERR, " invalid logic result\n");
     36      DeleteNamedVector (outname);
     37      free (outname);
     38      return (FALSE);
     39    }
     40  }
    2041
    2142  /* find vectors */
     
    2950  if (xvec[0].Nelements != zvec[0].Nelements) {
    3051    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
     52    return (FALSE);
     53  }
     54  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
     55    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
    3156    return (FALSE);
    3257  }
     
    4671  }
    4772
     73  if (tvec) {
     74    ALLOCATE (mask, char, tvec->Nelements);
     75    for (i = 0; i < tvec->Nelements; i++) {
     76      mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     77    }
     78  }
     79
    4880  /* point size determined by Zvec */
    4981  graphmode.style = 2; /* plot points */
    5082  graphmode.size = -1; /* point size determined by Zvec */
    5183  graphmode.etype = 0; /* no errorbars */
    52   PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
     84  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode);
    5385
    5486  free (Zvec.elements.Ptr);
     87  if (mask) free (mask);
     88  DeleteNamedVector (outname);
    5589
    5690  return (TRUE);
     
    6094int zcplot (int argc, char **argv) {
    6195 
    62   int i, kapa;
     96  char *outname;
     97  int i, kapa, valid, size;
    6398  opihi_flt *out;
    6499  double min, range;
     
    68103  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    69104
    70   if (argc != 6) {
    71     gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
     105  valid  = (argc == 6);
     106  valid |= (argc > 7) && !strcmp (argv[6], "where");
     107  if (!valid) {
     108    gprint (GP_ERR, "USAGE: zcplot <x> <y> <z> min max\n");
     109    gprint (GP_ERR, "   OR: zcplot <x> <y> <z> min max where (condition)\n");
    72110    return (FALSE);
    73111  }
     
    75113  min = atof(argv[4]);
    76114  range = atof(argv[5]) - min;
     115
     116  // tvec is used for logical test (truth vector)
     117  Vector *tvec = NULL;
     118  char *mask = NULL;
     119  if (argc > 7) {
     120    outname = dvomath (argc - 7, &argv[7], &size, 1);
     121    if (outname == NULL) {
     122      print_error ();
     123      return FALSE;
     124    }
     125    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
     126      gprint (GP_ERR, " invalid logic result\n");
     127      DeleteNamedVector (outname);
     128      free (outname);
     129      return (FALSE);
     130    }
     131  }
    77132
    78133  /* find vectors */
     
    86141  if (xvec[0].Nelements != zvec[0].Nelements) {
    87142    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
     143    return (FALSE);
     144  }
     145  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
     146    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
    88147    return (FALSE);
    89148  }
     
    103162  }
    104163
     164  if (tvec) {
     165    ALLOCATE (mask, char, tvec->Nelements);
     166    for (i = 0; i < tvec->Nelements; i++) {
     167      mask[i] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     168    }
     169  }
     170
    105171  /* point size determined by Zvec */
    106172  graphmode.style = 2; /* plot points */
    107173  graphmode.color = -1; /* point color determined by Zvec */
    108174  graphmode.etype = 0; /* no errorbars */
    109   PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
     175  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode);
    110176
    111177  free (Zvec.elements.Ptr);
     178  if (mask) free (mask);
     179  DeleteNamedVector (outname);
    112180
    113181  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.