IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2013, 2:09:57 PM (13 years ago)
Author:
eugene
Message:

add more options to dvo purge.temp; add czcplot function; deprecate KiiClose; add where conditions to czplot and czcplot

Location:
trunk/Ohana/src/opihi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi

  • trunk/Ohana/src/opihi/cmd.astro

  • trunk/Ohana/src/opihi/cmd.astro/czplot.c

    r34584 r35757  
    33int czplot (int argc, char **argv) {
    44 
    5   int i, kapa, Npts, status;
     5  char *outname = NULL;
     6  int i, kapa, valid, size;
     7  int Npts, status;
    68  double min, range, Rmin, Rmax;
    79  opihi_flt *out, *r, *d, *x, *y;
     
    1113  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1214
    13   if (argc != 6) {
     15  valid  = (argc == 6);
     16  valid |= (argc > 7) && !strcmp (argv[6], "where");
     17  if (!valid) {
    1418    gprint (GP_ERR, "USAGE: czplot <x> <y> <z> min max\n");
     19    gprint (GP_ERR, "   OR: czplot <x> <y> <z> min max where (condition)\n");
    1520    return (FALSE);
    1621  }
     
    2126  Rmax = graphmode.coords.crval1 + 182.0;
    2227
     28  // tvec is used for logical test (truth vector)
     29  Vector *tvec = NULL;
     30  char *mask = NULL;
     31  if (argc > 7) {
     32    outname = dvomath (argc - 7, &argv[7], &size, 1);
     33    if (outname == NULL) {
     34      print_error ();
     35      return FALSE;
     36    }
     37    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
     38      gprint (GP_ERR, " invalid logic result\n");
     39      DeleteNamedVector (outname);
     40      free (outname);
     41      return (FALSE);
     42    }
     43  }
     44
    2345  /* find vectors */
    2446  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     
    3860    return (FALSE);
    3961  }
     62  if (tvec && (xvec[0].Nelements != tvec[0].Nelements)) {
     63    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     64    return (FALSE);
     65  }
     66
    4067  SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
    4168  SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
    4269  SetVector (&Zvec, OPIHI_FLT, xvec[0].Nelements);
    4370 
     71  if (tvec) {
     72    ALLOCATE (mask, char, tvec->Nelements);
     73  }
     74
    4475  r   = xvec[0].elements.Flt;
    4576  d   = yvec[0].elements.Flt;
     
    6495      *out = MIN (1.0, MAX (0.01, (in[i] - min) / range));
    6596    }
     97
     98    if (mask) {
     99      // NOTE: the X,Y,Z sequence is not (necessarily) the same as the RA,DEC,zvec seq
     100      // I only set the mask for points sent to kapa...
     101      mask[Npts] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     102    }
     103
    66104    x++;
    67105    y++;
     
    76114  graphmode.size = -1; /* point size determined by Zvec */
    77115  graphmode.etype = 0;
    78   PlotVectorTriplet (kapa, &Xvec, &Yvec, &Zvec, NULL, &graphmode);
     116  PlotVectorTriplet (kapa, &Xvec, &Yvec, &Zvec, mask, &graphmode);
    79117
    80118  free (Xvec.elements.Flt);
     
    82120  free (Zvec.elements.Flt);
    83121
     122  if (mask) free (mask);
     123
    84124  return (TRUE);
    85125
    86126}
     127
     128int czcplot (int argc, char **argv) {
     129 
     130  char *outname = NULL;
     131  int i, kapa, valid, size;
     132  int Npts, status;
     133  double min, range, Rmin, Rmax;
     134  opihi_flt *out, *r, *d, *x, *y;
     135  Vector Xvec, Yvec, Zvec, *xvec, *yvec, *zvec;
     136  Graphdata graphmode;
     137
     138  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
     139
     140  valid  = (argc == 6);
     141  valid |= (argc > 7) && !strcmp (argv[6], "where");
     142  if (!valid) {
     143    gprint (GP_ERR, "USAGE: czcplot <x> <y> <z> min max\n");
     144    gprint (GP_ERR, "   OR: czcplot <x> <y> <z> min max where (condition)\n");
     145    return (FALSE);
     146  }
     147
     148  min = atof(argv[4]);
     149  range = atof(argv[5]) - min;
     150  Rmin = graphmode.coords.crval1 - 182.0;
     151  Rmax = graphmode.coords.crval1 + 182.0;
     152
     153  // tvec is used for logical test (truth vector)
     154  Vector *tvec = NULL;
     155  char *mask = NULL;
     156  if (argc > 7) {
     157    outname = dvomath (argc - 7, &argv[7], &size, 1);
     158    if (outname == NULL) {
     159      print_error ();
     160      return FALSE;
     161    }
     162    if ((tvec = SelectVector (outname, OLDVECTOR, TRUE)) == NULL) {
     163      gprint (GP_ERR, " invalid logic result\n");
     164      DeleteNamedVector (outname);
     165      free (outname);
     166      return (FALSE);
     167    }
     168  }
     169
     170  /* find vectors */
     171  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     172  if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     173  if ((zvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     174
     175  REQUIRE_VECTOR_FLT (xvec, FALSE);
     176  REQUIRE_VECTOR_FLT (yvec, FALSE);
     177  REQUIRE_VECTOR_FLT (zvec, FALSE);
     178
     179  if (xvec[0].Nelements != yvec[0].Nelements) {
     180    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[2]);
     181    return (FALSE);
     182  }
     183  if (xvec[0].Nelements != zvec[0].Nelements) {
     184    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
     185    return (FALSE);
     186  }
     187  if (tvec && (xvec[0].Nelements != tvec[0].Nelements)) {
     188    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
     189    return (FALSE);
     190  }
     191
     192  SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
     193  SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
     194  SetVector (&Zvec, OPIHI_FLT, xvec[0].Nelements);
     195 
     196  if (tvec) {
     197    ALLOCATE (mask, char, tvec->Nelements);
     198  }
     199
     200  r   = xvec[0].elements.Flt;
     201  d   = yvec[0].elements.Flt;
     202  x   = Xvec.elements.Flt;
     203  y   = Yvec.elements.Flt;
     204  out = Zvec.elements.Flt;
     205
     206  Npts = 0;
     207  for (i = 0; i < xvec[0].Nelements; i++, r++, d++) {
     208    *r = ohana_normalize_angle (*r);
     209    while (*r < Rmin) *r += 360.0;
     210    while (*r > Rmax) *r -= 360.0;
     211
     212    status = RD_to_XY (x, y, *r, *d, &graphmode.coords);
     213    if (!status) continue;
     214
     215    if (zvec->type == OPIHI_FLT) {
     216      opihi_flt *in  = zvec[0].elements.Flt;
     217      *out = MIN (1.0, MAX (0.01, (in[i] - min) / range));
     218    } else {
     219      opihi_int *in  = zvec[0].elements.Int;
     220      *out = MIN (1.0, MAX (0.01, (in[i] - min) / range));
     221    }
     222
     223    if (mask) {
     224      // NOTE: the X,Y,Z sequence is not (necessarily) the same as the RA,DEC,zvec seq
     225      // I only set the mask for points sent to kapa...
     226      mask[Npts] = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
     227    }
     228
     229    x++;
     230    y++;
     231    out++;
     232    Npts++;
     233  }
     234  Xvec.Nelements = Npts;
     235  Yvec.Nelements = Npts;
     236  Zvec.Nelements = Npts;
     237
     238  graphmode.style = 2;
     239  graphmode.color = -1; /* point color determined by Zvec */
     240  graphmode.etype = 0;
     241  PlotVectorTriplet (kapa, &Xvec, &Yvec, &Zvec, mask, &graphmode);
     242
     243  free (Xvec.elements.Flt);
     244  free (Yvec.elements.Flt);
     245  free (Zvec.elements.Flt);
     246
     247  if (mask) free (mask);
     248
     249  return (TRUE);
     250
     251}
Note: See TracChangeset for help on using the changeset viewer.