IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2015, 8:18:59 PM (11 years ago)
Author:
eugene
Message:

add support for a?[], a?[][], a[1][] a[][1]

File:
1 edited

Legend:

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

    r27491 r38002  
    11# include "opihi.h"
     2
     3// converts a[], a[4], a[2][3] to their numeric values
     4// add a?[] and a?[][] as equivalent to $?a
     5// a[][?]
    26
    37char *expand_vectors (char *line) {
     
    59  char *newline, *tmpline, strValue[128], *val;
    610  char *L, *N, *p, *q, *p2, *w;
    7   int n, I, J, size, showLength, NLINE, Noff, isBuffer, inRange;
     11  int n, I, J, size, showLength, showXsize, showYsize, checkType, NLINE, Noff, isBuffer, inRange;
    812  float *ptr;
    913  double f1;
     
    4145    val = NULL;
    4246    showLength = FALSE;
     47    showXsize  = FALSE;
     48    showYsize  = FALSE;
     49
    4350    if (n == 0) {
    4451      showLength = TRUE;
     52      showXsize  = TRUE;
    4553    } else {
    4654      tmpline = strncreate (p+1, n);
     
    6068      p2 = strchr (q + 1, ']');
    6169      if (p2 != NULL) {
    62         if (showLength) {
    63           gprint (GP_ERR, "unsupported : name[][..]\n");
    64           goto asVector;
    65         }
     70        // if (showLength) {
     71        //   gprint (GP_ERR, "unsupported : name[][..]\n");
     72        //   goto asVector;
     73        // }
    6674
    6775        isBuffer = TRUE;
     
    7179        val = NULL;
    7280        if (n == 0) {
    73           gprint (GP_ERR, "unsupported : name[..][]\n");
    74           isBuffer = FALSE;
    75           goto asVector;
    76         }
    77         tmpline = strncreate (q+2, n);
    78         val = dvomath (1, &tmpline, &size, 0);
    79         free (tmpline);
    80         if (val == NULL) {
    81           isBuffer = FALSE;
    82           goto asVector; /* not a valid vector subscript */
     81          showYsize = TRUE;
     82          // gprint (GP_ERR, "unsupported : name[..][]\n");
     83          // isBuffer = FALSE;
     84          // goto asVector;
     85        }  else {
     86          tmpline = strncreate (q+2, n);
     87          val = dvomath (1, &tmpline, &size, 0);
     88          free (tmpline);
     89          if (val == NULL) {
     90            isBuffer = FALSE;
     91            goto asVector; /* not a valid vector subscript */
     92          }
    8393        }
    8494        J = 0;
     
    93103  asVector:
    94104    /* find vector/buffer name */
     105    checkType = FALSE;
     106    if (*(p-1) == '?') {
     107      checkType = TRUE;
     108      p--;
     109    }
    95110    for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && (isalnum(*w) || (*w == ':') || (*w == '_')); w--);
    96111    w ++;
     
    99114
    100115    if (isBuffer) {
    101       if ((buf = SelectBuffer (tmpline, OLDBUFFER, TRUE)) == NULL) goto dumpline;
    102 
     116      buf = SelectBuffer (tmpline, OLDBUFFER, !checkType);
     117      if (checkType) {
     118        f1 = (buf != NULL);
     119        goto skipBuffer;
     120      }
     121      if (showXsize && showYsize) {
     122        gprint (GP_ERR, "ambiguous size option buf[][]\n");
     123        goto dumpline;
     124      }
     125      if (buf == NULL) goto dumpline;
     126      if (showXsize) {
     127        f1 = buf[0].header.Naxis[0];
     128        goto skipBuffer;
     129      }
     130      if (showYsize) {
     131        f1 = buf[0].header.Naxis[1];
     132        goto skipBuffer;
     133      }
    103134      /* find buffer element */
    104135      inRange = TRUE;
     
    116147      f1 = ptr[I + J*buf[0].header.Naxis[0]];
    117148    } else {
    118       if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
    119 
    120       /* find vector element */
    121       if (showLength) {
    122         f1 = vec[0].Nelements;
     149      vec = SelectVector (tmpline, OLDVECTOR, !checkType);
     150      if (checkType) {
     151        f1 = (vec != NULL);
    123152      } else {
    124         if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
    125           gprint (GP_ERR, "vector subscript out of range\n");
    126           goto escape;
     153        if (vec == NULL) goto dumpline;
     154
     155        /* find vector element */
     156        if (showLength) {
     157          f1 = vec[0].Nelements;
     158        } else {
     159          if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
     160            gprint (GP_ERR, "vector subscript out of range\n");
     161            goto escape;
     162          }
     163          if (I < 0) I += vec[0].Nelements;
     164          f1 = (vec[0].type == OPIHI_FLT) ? vec[0].elements.Flt[I] : vec[0].elements.Int[I];
    127165        }
    128         if (I < 0) I += vec[0].Nelements;
    129         f1 = (vec[0].type == OPIHI_FLT) ? vec[0].elements.Flt[I] : vec[0].elements.Int[I];
    130       }
    131     }
    132 
     166      }
     167    }
     168
     169  skipBuffer:
    133170    free (tmpline);
    134171    if ((int)f1 == f1)
Note: See TracChangeset for help on using the changeset viewer.