IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 4, 2008, 11:24:32 AM (19 years ago)
Author:
eugene
Message:

added A[][] for matrix set / get

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/expand_vectors.c

    r15878 r16003  
    44
    55  char *newline, *tmpline, strValue[128], *val;
    6   char *L, *N, *p, *q, *w;
    7   int n, I, size, showLength, NLINE, Noff;
     6  char *L, *N, *p, *q, *p2, *w;
     7  int n, I, J, size, showLength, NLINE, Noff, isBuffer, inRange;
     8  float *ptr;
    89  double f1;
    910  Vector *vec;
     11  Buffer *buf;
    1012
    1113  if (line == NULL) return (NULL);
     
    2628  N = newline + n;
    2729  while (1) {
    28     /* find vector subscript */
     30    /* find square-bracket pair [..] */
    2931    p = strchr (L, '[');
    3032    q = strchr (L, ']');
     
    3335    if ((p == NULL) && (q == NULL)) goto dumpline;
    3436    if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */
     37
     38    /* find vector subscript */
    3539    n = (int) (q - p - 1);
    3640    val = NULL;
     
    5054    }     
    5155
    52     /* find vector name */
     56    /* if a second [..] immediately follows, we are a buffer, not a vector */
     57    isBuffer = FALSE;
     58    if (*(q + 1) == '[') {
     59      p2 = strchr (q + 1, ']');
     60      if (p2 != NULL) {
     61        if (showLength) {
     62          gprint (GP_ERR, "unsupported : name[][..]\n");
     63          goto asVector;
     64        }
     65
     66        isBuffer = TRUE;
     67
     68        /* find buffer second subscript */
     69        n = (int) (p2 - q - 2);
     70        val = NULL;
     71        if (n == 0) {
     72          gprint (GP_ERR, "unsupported : name[..][]\n");
     73          isBuffer = FALSE;
     74          goto asVector;
     75        }
     76        tmpline = strncreate (q+2, n);
     77        val = dvomath (1, &tmpline, &size, 0);
     78        free (tmpline);
     79        if (val == NULL) {
     80          isBuffer = FALSE;
     81          goto asVector; /* not a valid vector subscript */
     82        }
     83        J = 0;
     84        if (val != NULL) {
     85          J = atoi (val);
     86          free (val);
     87        }     
     88      }
     89      q = p2;
     90    }
     91
     92  asVector:
     93    /* find vector/buffer name */
    5394    for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && (isalnum(*w) || (*w == ':') || (*w == '_')); w--);
    5495    w ++;
    5596    n = (int)(p - w);
    5697    tmpline = strncreate (w, n);
    57     if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
    58     free (tmpline);
    5998
    60     /* find vector element */
    61     if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
    62       gprint (GP_ERR, "vector subscript out of range\n");
    63       goto escape;
    64     }
    65     if (showLength) {
    66       f1 = vec[0].Nelements;
     99    if (isBuffer) {
     100      if ((buf = SelectBuffer (tmpline, OLDBUFFER, TRUE)) == NULL) goto dumpline;
     101
     102      /* find buffer element */
     103      inRange = TRUE;
     104      inRange &= (I <  +1*buf[0].header.Naxis[0]);
     105      inRange &= (I >= -1*buf[0].header.Naxis[0]);
     106      inRange &= (J <  +1*buf[0].header.Naxis[1]);
     107      inRange &= (J >= -1*buf[0].header.Naxis[1]);
     108      if (!inRange) {
     109        gprint (GP_ERR, "buffer subscript out of range\n");
     110        goto escape;
     111      }
     112      if (I < 0) I += buf[0].header.Naxis[0];
     113      if (J < 0) J += buf[0].header.Naxis[1];
     114      ptr = (float *) buf[0].matrix.buffer;
     115      f1 = ptr[I + J*buf[0].header.Naxis[1]];
    67116    } else {
    68       if (I < 0) {
    69         f1 = vec[0].elements[vec[0].Nelements+I];
     117      if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
     118
     119      /* find vector element */
     120      if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
     121        gprint (GP_ERR, "vector subscript out of range\n");
     122        goto escape;
     123      }
     124      if (showLength) {
     125        f1 = vec[0].Nelements;
    70126      } else {
     127        if (I < 0) I += vec[0].Nelements;
    71128        f1 = vec[0].elements[I];
    72129      }
    73130    }
     131
     132    free (tmpline);
    74133    if ((int)f1 == f1)
    75134      snprintf (strValue, 128, "%.0f", f1);
Note: See TracChangeset for help on using the changeset viewer.