IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16003


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

added A[][] for matrix set / get

Location:
trunk/Ohana/src/opihi/lib.shell
Files:
2 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);
  • trunk/Ohana/src/opihi/lib.shell/parse.c

    r15878 r16003  
    44
    55  double fval;
     6  float *fptr;
    67  char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
    7   int Nval, Nbytes, status, size, NLINE;
     8  int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;
    89  FILE *f;
    910  Vector *vec;
     11  Buffer *buf;
    1012
    1113  val = V0 = NULL;
     
    101103  }
    102104
    103   /* case 2: vect[N] = value */
     105  /* case 2: vect[N] = value or buff[N][M] = value */
    104106  V0 = thiscomm (line);
    105107  if (strchr(V0, '[') != (char *) NULL) {
     
    111113    L = strchr (V0, ']');
    112114    if (L == (char *) NULL) goto error;
    113     if (L != V0 + strlen (V0) - 1) goto error;
    114115
    115116    *N = 0;
     
    122123      goto error;
    123124    }
    124     Nval = atoi (val);
     125    Nx = atoi (val);
    125126    free (val); val = NULL;
    126127    free (V);
    127128
    128     /* find vector */
    129     if ((vec = SelectVector (V0, OLDVECTOR, TRUE)) == NULL) goto error;
    130     free (V0); V0 = (char *) NULL;
    131     if (Nval >= vec[0].Nelements) {
    132       gprint (GP_ERR, "no element %d\n", Nval);
    133       goto escape;
     129    isBuffer = FALSE;
     130    N = L + 1;
     131    if (*N == '[') {
     132      isBuffer = TRUE;
     133      L = strchr (N, ']');
     134
     135      V = strncreate (N+1, L - N - 1);
     136
     137      /* expand value in brackets */
     138      val = dvomath (1, &V, &size, 0);
     139      if (val == NULL) {
     140        print_error ();
     141        goto error;
     142      }
     143      Ny = atoi (val);
     144      free (val); val = NULL;
     145      free (V);
    134146    }
    135147
     
    146158      goto error;
    147159    }
    148     vec[0].elements[Nval] = atof (val);
     160
     161    /* find vector */
     162    if (isBuffer) {
     163      if ((buf = SelectBuffer (V0, OLDBUFFER, TRUE)) == NULL) goto error;
     164      free (V0); V0 = (char *) NULL;
     165
     166      inRange = TRUE;
     167      inRange &= (Nx <  +1*buf[0].header.Naxis[0]);
     168      inRange &= (Nx >= -1*buf[0].header.Naxis[0]);
     169      inRange &= (Ny <  +1*buf[0].header.Naxis[1]);
     170      inRange &= (Ny >= -1*buf[0].header.Naxis[1]);
     171      if (!inRange) {
     172        gprint (GP_ERR, "no element %d,%d\n", Nx, Ny);
     173        goto escape;
     174      }
     175      if (Nx < 0) Nx += buf[0].header.Naxis[0];
     176      if (Ny < 0) Ny += buf[0].header.Naxis[1];
     177
     178      fptr = (float *) buf[0].matrix.buffer;
     179      fptr[Nx + Ny*buf[0].header.Naxis[1]] = atof (val);
     180    } else {
     181      if ((vec = SelectVector (V0, OLDVECTOR, TRUE)) == NULL) goto error;
     182      free (V0); V0 = (char *) NULL;
     183
     184      inRange = TRUE;
     185      inRange &= (Nx <  +1*vec[0].Nelements);
     186      inRange &= (Nx >= -1*vec[0].Nelements);
     187      if (!inRange) {
     188        gprint (GP_ERR, "no element %d\n", Nx);
     189        goto escape;
     190      }
     191      if (Nx < 0) Nx += vec[0].Nelements;
     192      vec[0].elements[Nx] = atof (val);
     193    }
     194
    149195    goto escape;
    150196  }
Note: See TracChangeset for help on using the changeset viewer.