IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

added A[][] for matrix set / get

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.