- Timestamp:
- Sep 21, 2013, 5:48:43 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/src/RpDxToVtk.c
r3882 r3944 73 73 74 74 if (p >= endPtr) { 75 Tcl_AppendResult(interp, "unexpected EOF in reading points", 76 (char *)NULL); 75 Tcl_AppendResult(interp, "unexpected EOF in reading field values", 76 (char *)NULL); 77 free(array); 77 78 return TCL_ERROR; 78 79 } 79 80 value = strtod(p, &nextPtr); 80 81 if (nextPtr == p) { 81 Tcl_AppendResult(interp, "bad value found in reading points", 82 (char *)NULL); 82 Tcl_AppendResult(interp, "bad value found in reading field values", 83 (char *)NULL); 84 free(array); 83 85 return TCL_ERROR; 84 86 } … … 122 124 123 125 if (p >= endPtr) { 124 Tcl_AppendResult(interp, "unexpected EOF in reading points", 125 (char *)NULL); 126 Tcl_AppendResult(interp, "unexpected EOF in reading field values", 127 (char *)NULL); 128 free(array); 126 129 return TCL_ERROR; 127 130 } 128 131 value = strtod(p, &nextPtr); 129 132 if (nextPtr == p) { 130 Tcl_AppendResult(interp, "bad value found in reading points", 131 (char *)NULL); 133 Tcl_AppendResult(interp, "bad value found in reading field values", 134 (char *)NULL); 135 free(array); 132 136 return TCL_ERROR; 133 137 } … … 169 173 170 174 if (p >= endPtr) { 171 Tcl_AppendResult(interp, "unexpected EOF in reading points", 172 (char *)NULL); 175 Tcl_AppendResult(interp, "unexpected EOF in reading field values", 176 (char *)NULL); 177 free(array); 173 178 return TCL_ERROR; 174 179 } 175 180 value = strtod(p, &nextPtr); 176 181 if (nextPtr == p) { 177 Tcl_AppendResult(interp, "bad value found in reading points", 178 (char *)NULL); 182 Tcl_AppendResult(interp, "bad value found in reading field values", 183 (char *)NULL); 184 free(array); 179 185 return TCL_ERROR; 180 186 } … … 246 252 return TCL_OK; 247 253 } 254 255 static int 256 GetUniformFieldVectors(Tcl_Interp *interp, int nPoints, int *counts, 257 char **stringPtr, const char *endPtr, Tcl_Obj *objPtr) 258 { 259 int i; 260 const char *p; 261 char mesg[2000]; 262 double *array; 263 int iX, iY, iZ; 264 265 p = *stringPtr; 266 array = malloc(sizeof(double) * nPoints * 3); 267 if (array == NULL) { 268 return TCL_ERROR; 269 } 270 iX = iY = iZ = 0; 271 for (i = 0; i < nPoints; i++) { 272 double x, y, z; 273 char *nextPtr; 274 int loc; 275 276 if (p >= endPtr) { 277 Tcl_AppendResult(interp, "unexpected EOF in reading vectors", 278 (char *)NULL); 279 free(array); 280 return TCL_ERROR; 281 } 282 x = strtod(p, &nextPtr); 283 if (nextPtr == p) { 284 Tcl_AppendResult(interp, "bad value found in reading vectors", 285 (char *)NULL); 286 free(array); 287 return TCL_ERROR; 288 } 289 p = nextPtr; 290 y = strtod(p, &nextPtr); 291 if (nextPtr == p) { 292 Tcl_AppendResult(interp, "bad value found in reading vectors", 293 (char *)NULL); 294 free(array); 295 return TCL_ERROR; 296 } 297 p = nextPtr; 298 z = strtod(p, &nextPtr); 299 if (nextPtr == p) { 300 Tcl_AppendResult(interp, "bad value found in reading vectors", 301 (char *)NULL); 302 free(array); 303 return TCL_ERROR; 304 } 305 p = nextPtr; 306 loc = iZ*counts[0]*counts[1] + iY*counts[0] + iX; 307 if (++iZ >= counts[2]) { 308 iZ = 0; 309 if (++iY >= counts[1]) { 310 iY = 0; 311 ++iX; 312 } 313 } 314 array[loc*3 ] = x; 315 array[loc*3+1] = y; 316 array[loc*3+2] = z; 317 } 318 for (i = 0; i < nPoints; i++) { 319 sprintf(mesg, "%g %g %g\n", array[i*3], array[i*3+1], array[i*3+2]); 320 Tcl_AppendToObj(objPtr, mesg, -1); 321 } 322 free(array); 323 *stringPtr = (char *)p; 324 return TCL_OK; 325 } 326 248 327 #if defined(DO_WEDGES) && defined(CHECK_WINDINGS) 249 328 static void … … 301 380 int isUniform; 302 381 int isStructuredGrid; 382 int hasVectors; 303 383 int i, ix, iy, iz; 304 384 … … 312 392 dv2[0] = dv2[1] = dv2[2] = 0.0; 313 393 count[0] = count[1] = count[2] = 0; /* Suppress compiler warning. */ 314 isUniform = 1; /* Default to expecting uniform grid */394 isUniform = 0; 315 395 isStructuredGrid = 0; 396 hasVectors = 0; 316 397 317 398 if (objc != 2) { … … 414 495 &count[2]) == 1) { 415 496 // Z grid 497 isUniform = 0; 498 } else if (sscanf(line, "object %*d class array type %*s shape 3 rank 1" 499 " items %d data follows", &nPoints) == 1) { 500 #ifdef notdef 501 fprintf(stderr, "found class array type shape 3 nPoints=%d\n", 502 nPoints); 503 #endif 504 if (isUniform) { 505 hasVectors = 1; 506 if (GetUniformFieldVectors(interp, nPoints, count, &p, pend, fieldObjPtr) 507 != TCL_OK) { 508 return TCL_ERROR; 509 } 510 } else { 511 // This is a 2D point cloud in xy with a uniform zgrid 512 isUniform = 0; 513 nXYPoints = nPoints; 514 if (nXYPoints < 0) { 515 sprintf(mesg, "bad # points %d", nXYPoints); 516 Tcl_AppendResult(interp, mesg, (char *)NULL); 517 return TCL_ERROR; 518 } 519 points = malloc(sizeof(double) * nXYPoints * 2); 520 if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) { 521 return TCL_ERROR; 522 } 523 } 416 524 } else if (sscanf(line, "object %*d class array type %*s rank 1 shape 3" 417 " items %d data follows", &nXYPoints) == 1) { 418 // This is a 2D point cloud in xy with a uniform zgrid 419 isUniform = 0; 525 " items %d data follows", &nPoints) == 1) { 420 526 #ifdef notdef 421 fprintf(stderr, "found class array type shape 3 nPoints=%d\n", 422 nPoints); 423 #endif 424 if (nXYPoints < 0) { 425 sprintf(mesg, "bad # points %d", nXYPoints); 426 Tcl_AppendResult(interp, mesg, (char *)NULL); 427 return TCL_ERROR; 428 } 429 points = malloc(sizeof(double) * nXYPoints * 2); 430 if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) { 431 return TCL_ERROR; 527 fprintf(stderr, "found class array type shape 3 nPoints=%d\n", 528 nPoints); 529 #endif 530 if (isUniform) { 531 hasVectors = 1; 532 if (GetUniformFieldVectors(interp, nPoints, count, &p, pend, fieldObjPtr) 533 != TCL_OK) { 534 return TCL_ERROR; 535 } 536 } else { 537 // This is a 2D point cloud in xy with a uniform zgrid 538 isUniform = 0; 539 nXYPoints = nPoints; 540 if (nXYPoints < 0) { 541 sprintf(mesg, "bad # points %d", nXYPoints); 542 Tcl_AppendResult(interp, mesg, (char *)NULL); 543 return TCL_ERROR; 544 } 545 points = malloc(sizeof(double) * nXYPoints * 2); 546 if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) { 547 return TCL_ERROR; 548 } 432 549 } 433 550 } else if (sscanf(line, "object %*d class array type %*s rank 0" … … 488 605 sprintf(mesg, "POINT_DATA %d\n", nPoints); 489 606 Tcl_AppendToObj(objPtr, mesg, -1); 490 sprintf(mesg, "SCALARS %s double 1\n", name); 491 Tcl_AppendToObj(objPtr, mesg, -1); 492 sprintf(mesg, "LOOKUP_TABLE default\n"); 493 Tcl_AppendToObj(objPtr, mesg, -1); 607 if (hasVectors) { 608 sprintf(mesg, "VECTORS %s double\n", name); 609 Tcl_AppendToObj(objPtr, mesg, -1); 610 } else { 611 sprintf(mesg, "SCALARS %s double 1\n", name); 612 Tcl_AppendToObj(objPtr, mesg, -1); 613 sprintf(mesg, "LOOKUP_TABLE default\n"); 614 Tcl_AppendToObj(objPtr, mesg, -1); 615 } 494 616 Tcl_AppendObjToObj(objPtr, fieldObjPtr); 495 617 } else if (isStructuredGrid) {
Note: See TracChangeset
for help on using the changeset viewer.