Changeset 16003 for trunk/Ohana/src/opihi/lib.shell/parse.c
- Timestamp:
- Jan 4, 2008, 11:24:32 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/parse.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
