Changeset 1325 for trunk/packages/vizservers/nanovis/dxReader.cpp
- Timestamp:
- Mar 14, 2009 4:20:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/dxReader.cpp
r1312 r1325 47 47 * Load a 3D vector field from a dx-format file 48 48 */ 49 void 50 load_vector_stream2( int volindex, std::istream& fin)49 bool 50 load_vector_stream2(Rappture::Outcome &result, int volindex, std::istream& fin) 51 51 { 52 52 int dummy, nx, ny, nz, npts; … … 59 59 fin.getline(line, sizeof(line) - 1); 60 60 if (fin.fail()) { 61 //return result.error("error in data stream");62 return ;61 result.addError("error in data stream"); 62 return false; 63 63 } 64 64 for (start=&line[0]; *start == ' ' || *start == '\t'; start++) … … 83 83 printf("point %d\n", npts); 84 84 if (npts != nx*ny*nz) { 85 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl; 86 return; 85 result.addError("inconsistent data: expected %d points" 86 " but found %d points", nx*ny*nz, npts); 87 return false; 87 88 } 88 89 break; 89 90 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) { 90 91 if (npts != nx*ny*nz) { 91 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl; 92 return; 92 result.addError("inconsistent data: expected %d points" 93 " but found %d points", nx*ny*nz, npts); 94 return false; 93 95 } 94 96 break; … … 101 103 if (!fin.eof()) { 102 104 double vx, vy, vz, vm; 105 #ifdef notdef 103 106 double max_x = -1e21, min_x = 1e21; 104 107 double max_y = -1e21, min_y = 1e21; 105 108 double max_z = -1e21, min_z = 1e21; 109 #endif 106 110 double max_mag = -1e21, min_mag = 1e21; 107 111 int nread = 0; … … 145 149 // make sure that we read all of the expected points 146 150 if (nread != nx*ny*nz) { 147 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl; 148 return; 151 result.addError("inconsistent data: expected %d points" 152 " but found %d points", nx*ny*nz, npts); 153 return false; 149 154 } 150 155 … … 155 160 156 161 // generate the uniformly sampled data that we need for a volume 162 #ifdef notdef 157 163 double nzero_min = 0.0; 164 #endif 158 165 int ngen = 0; 159 166 int nindex = 0; … … 178 185 179 186 Volume *volPtr; 180 volPtr = NanoVis::load_volume(volindex, nx, ny, nz, 4, data, min_mag, max_mag,181 187 volPtr = NanoVis::load_volume(volindex, nx, ny, nz, 4, data, 188 min_mag, max_mag, 0); 182 189 183 190 volPtr->xAxis.SetRange(x0, x0 + nx); … … 190 197 std::cerr << "WARNING: data not found in stream" << std::endl; 191 198 } 199 return true; 192 200 } 193 void 194 load_vector_stream(int index, std::istream& fin) 201 202 bool 203 load_vector_stream(Rappture::Outcome result, int index, std::istream& fin) 195 204 { 196 205 int dummy, nx, ny, nz, npts; … … 203 212 fin.getline(line, sizeof(line) - 1); 204 213 if (fin.fail()) { 205 //return result.error("error in data stream");206 return ;214 result.addError("error in data stream"); 215 return false; 207 216 } 208 217 for (start=&line[0]; *start == ' ' || *start == '\t'; start++) … … 227 236 printf("point %d\n", npts); 228 237 if (npts != nx*ny*nz) { 229 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl; 230 return; 238 result.addError("inconsistent data: expected %d points" 239 " but found %d points", nx*ny*nz, npts); 240 return false; 231 241 } 232 242 break; 233 243 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) { 234 244 if (npts != nx*ny*nz) { 235 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl; 236 return; 245 result.addError("inconsistent data: expected %d points" 246 " but found %d points", nx*ny*nz, npts); 247 return false; 237 248 } 238 249 break; … … 272 283 // make sure that we read all of the expected points 273 284 if (nread != nx*ny*nz) { 274 std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl; 275 return; 285 result.addError("inconsistent data: expected %d points" 286 " but found %d points", nx*ny*nz, npts); 287 return false; 276 288 } 277 289 … … 355 367 delete [] data; 356 368 } else { 357 std::cerr << "WARNING: data not found in stream" << std::endl; 369 result.addError("WARNING: data not found in stream"); 370 return false; 358 371 } 372 return true; 359 373 } 360 361 374 362 375 /* Load a 3D volume from a dx-format file 363 376 */ 364 Rappture::Outcome 365 load_volume_stream2( int index, std::iostream& fin)377 bool 378 load_volume_stream2(Rappture::Outcome &result, int index, std::iostream& fin) 366 379 { 367 380 printf("load_volume_stream2\n"); 368 Rappture::Outcome result;369 370 381 Rappture::MeshTri2D xymesh; 371 382 int dummy, nx, ny, nz, nxy, npts; … … 382 393 383 394 if (*start != '#') { // skip comment lines 384 if (sscanf(start, "object %d class gridpositions counts %d %d %d", &dummy, &nx, &ny, &nz) == 4) { 395 if (sscanf(start, "object %d class gridpositions counts %d %d %d", 396 &dummy, &nx, &ny, &nz) == 4) { 385 397 // found grid size 386 398 isrect = 1; … … 432 444 ftri.close(); 433 445 } else { 434 return result.error("triangularization failed"); 435 } 436 437 sprintf(cmdstr, "rm -f %s %s", fpts, fcells); 438 system(cmdstr); 446 result.error("triangularization failed"); 447 return false; 448 } 449 unlink(fpts), unlink(fcells); 439 450 } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) { 440 451 // found z-grid … … 457 468 } 458 469 if (count > 1) { 459 return result.error( 460 "don't know how to handle multiple non-zero delta values"); 470 result.addError("don't know how to handle multiple non-zero" 471 " delta values"); 472 return false; 461 473 } 462 474 } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { 463 475 if (isrect && (npts != nx*ny*nz)) { 464 char mesg[256];465 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);466 return result.error(mesg);476 result.addError("inconsistent data: expected %d points " 477 " but found %d points", nx*ny*nz, npts); 478 return false; 467 479 } else if (!isrect && (npts != nxy*nz)) { 468 char mesg[256];469 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nxy*nz, npts);470 return result.error(mesg);480 result.addError("inconsistent data: expected %d points " 481 " but found %d points", nxy*nz, npts); 482 return false; 471 483 } 472 484 break; 473 485 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) { 474 486 if (npts != nx*ny*nz) { 475 char mesg[256];476 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);477 return result.error(mesg);487 result.addError("inconsistent data: expected %d points " 488 " but found %d points", nx*ny*nz, npts); 489 return false; 478 490 } 479 491 break; … … 527 539 // make sure that we read all of the expected points 528 540 if (nread != nx*ny*nz) { 529 char mesg[256]; 530 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread); 531 result.error(mesg); 532 return result; 541 result.addError("inconsistent data: expected %d points " 542 " but found %d points", nx*ny*nz, nread); 543 return false; 533 544 } 534 545 … … 578 589 fin >> dval; 579 590 if (fin.fail()) { 580 char mesg[256]; 581 sprintf(mesg,"after %d of %d points: can't read number", 582 nread, npts); 583 return result.error(mesg); 591 result.addError("after %d of %d points: can't read number", 592 nread, npts); 593 return false; 584 594 } else { 585 595 int nid = nxy*iz + ixy; … … 596 606 // make sure that we read all of the expected points 597 607 if (nread != nxy*nz) { 598 char mesg[256];599 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nxy*nz, nread);600 return result.error(mesg);608 result.addError("inconsistent data: expected %d points " 609 "but found %d points", nxy*nz, nread); 610 return false; 601 611 } 602 612 … … 714 724 } 715 725 } else { 716 return result.error("data not found in stream"); 726 result.addError("data not found in stream"); 727 return false; 717 728 } 718 729 … … 724 735 float dz0 = -0.5*dz/dx; 725 736 NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0)); 726 727 return result; 737 return true; 728 738 } 729 739 … … 806 816 return result.error("triangularization failed"); 807 817 } 808 809 sprintf(cmdstr, "rm -f %s %s", fpts, fcells); 810 system(cmdstr); 818 unlink(fpts); 819 unlink(fcells); 811 820 } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) { 812 821 // found z-grid … … 820 829 } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { 821 830 if (isrect && (npts != nx*ny*nz)) { 822 char mesg[256];823 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);824 return result.error(mesg);831 result.addError("inconsistent data: expected %d points" 832 " but found %d points", nx*ny*nz, npts); 833 return false; 825 834 } else if (!isrect && (npts != nxy*nz)) { 826 char mesg[256];827 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, npts);828 return result.error(mesg);835 result.addError("inconsistent data: expected %d points" 836 " but found %d points", nx*ny*nz, npts); 837 return false; 829 838 } 830 839 break; 831 840 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) { 832 841 if (npts != nx*ny*nz) { 833 char mesg[256];834 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);835 return result.error(mesg);842 result.addError("inconsistent data: expected %d points" 843 " but found %d points", nx*ny*nz, npts); 844 return false; 836 845 } 837 846 break; … … 879 888 // make sure that we read all of the expected points 880 889 if (nread != nx*ny*nz) { 881 char mesg[256]; 882 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread); 883 result.error(mesg); 884 return result; 890 result.addError("inconsistent data: expected %d points" 891 " but found %d points", nx*ny*nz, npts); 892 return false; 885 893 } 886 894 … … 1025 1033 // make sure that we read all of the expected points 1026 1034 if (nread != nxy*nz) { 1027 char mesg[256]; 1028 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, nread);1029 return result.error(mesg);1035 result.addError("inconsistent data: expected %d points" 1036 " but found %d points", nx*ny*nz, npts); 1037 return false; 1030 1038 } 1031 1039 … … 1237 1245 return result.error("triangularization failed"); 1238 1246 } 1239 1240 sprintf(cmdstr, "rm -f %s %s", fpts, fcells); 1241 system(cmdstr); 1247 unlink(fpts), unlink(fcells); 1242 1248 } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) { 1243 1249 // found z-grid … … 1251 1257 } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { 1252 1258 if (isrect && (npts != nx*ny*nz)) { 1253 char mesg[256];1254 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);1255 return result.error(mesg);1259 result.addError("inconsistent data: expected %d points" 1260 " but found %d points", nx*ny*nz, npts); 1261 return false; 1256 1262 } else if (!isrect && (npts != nxy*nz)) { 1257 char mesg[256];1258 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, npts);1259 return result.error(mesg);1263 result.addError("inconsistent data: expected %d points" 1264 " but found %d points", nx*ny*nz, npts); 1265 return false; 1260 1266 } 1261 1267 break; 1262 1268 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) { 1263 1269 if (npts != nx*ny*nz) { 1264 char mesg[256];1265 sprintf(mesg,"inconsistent data: expected %d pointsbut found %d points", nx*ny*nz, npts);1266 return result.error(mesg);1270 result.addError("inconsistent data: expected %d points" 1271 " but found %d points", nx*ny*nz, npts); 1272 return false; 1267 1273 } 1268 1274 break; … … 1310 1316 // make sure that we read all of the expected points 1311 1317 if (nread != nx*ny*nz) { 1312 char mesg[256]; 1313 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread); 1314 result.error(mesg); 1315 return result; 1318 result.addError("inconsistent data: expected %d points" 1319 " but found %d points", nx*ny*nz, npts); 1320 return false; 1316 1321 } 1317 1322 … … 1497 1502 // make sure that we read all of the expected points 1498 1503 if (nread != nxy*nz) { 1499 char mesg[256]; 1500 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, nread);1501 return result.error(mesg);1504 result.addError("inconsistent data: expected %d points" 1505 " but found %d points", nx*ny*nz, npts); 1506 return false; 1502 1507 } 1503 1508
Note: See TracChangeset
for help on using the changeset viewer.