Changeset 16003
- Timestamp:
- Jan 4, 2008, 11:24:32 AM (18 years ago)
- Location:
- trunk/Ohana/src/opihi/lib.shell
- Files:
-
- 2 edited
-
expand_vectors.c (modified) (4 diffs)
-
parse.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
r15878 r16003 4 4 5 5 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; 8 9 double f1; 9 10 Vector *vec; 11 Buffer *buf; 10 12 11 13 if (line == NULL) return (NULL); … … 26 28 N = newline + n; 27 29 while (1) { 28 /* find vector subscript*/30 /* find square-bracket pair [..] */ 29 31 p = strchr (L, '['); 30 32 q = strchr (L, ']'); … … 33 35 if ((p == NULL) && (q == NULL)) goto dumpline; 34 36 if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */ 37 38 /* find vector subscript */ 35 39 n = (int) (q - p - 1); 36 40 val = NULL; … … 50 54 } 51 55 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 */ 53 94 for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && (isalnum(*w) || (*w == ':') || (*w == '_')); w--); 54 95 w ++; 55 96 n = (int)(p - w); 56 97 tmpline = strncreate (w, n); 57 if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;58 free (tmpline);59 98 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]]; 67 116 } 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; 70 126 } else { 127 if (I < 0) I += vec[0].Nelements; 71 128 f1 = vec[0].elements[I]; 72 129 } 73 130 } 131 132 free (tmpline); 74 133 if ((int)f1 == f1) 75 134 snprintf (strValue, 128, "%.0f", f1); -
trunk/Ohana/src/opihi/lib.shell/parse.c
r15878 r16003 4 4 5 5 double fval; 6 float *fptr; 6 7 char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p; 7 int N val, Nbytes, status, size, NLINE;8 int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange; 8 9 FILE *f; 9 10 Vector *vec; 11 Buffer *buf; 10 12 11 13 val = V0 = NULL; … … 101 103 } 102 104 103 /* case 2: vect[N] = value */105 /* case 2: vect[N] = value or buff[N][M] = value */ 104 106 V0 = thiscomm (line); 105 107 if (strchr(V0, '[') != (char *) NULL) { … … 111 113 L = strchr (V0, ']'); 112 114 if (L == (char *) NULL) goto error; 113 if (L != V0 + strlen (V0) - 1) goto error;114 115 115 116 *N = 0; … … 122 123 goto error; 123 124 } 124 N val= atoi (val);125 Nx = atoi (val); 125 126 free (val); val = NULL; 126 127 free (V); 127 128 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); 134 146 } 135 147 … … 146 158 goto error; 147 159 } 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 149 195 goto escape; 150 196 }
Note:
See TracChangeset
for help on using the changeset viewer.
