plt_loader_read.C
Go to the documentation of this file.00001 // Copyright (C) 2002-2007 Benjamin S. Kirk 00002 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License, or (at your option) any later version. 00007 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 00017 00018 // C++ includes 00019 #include <iostream> 00020 #include <fstream> 00021 #include <cstring> 00022 00023 // Local includes 00024 #include "libmesh/utility.h" 00025 #include "libmesh/plt_loader.h" 00026 00027 namespace libMesh 00028 { 00029 00030 00031 00032 //----------------------------------------------------------------------------- 00033 // PltLoader reading members 00034 void PltLoader::read (const std::string& name) 00035 { 00036 std::ifstream in (name.c_str(), std::ios::in|std::ios::binary); 00037 00038 if (!in.good()) 00039 { 00040 libMesh::err << "Error reading input file " << name 00041 << std::endl; 00042 00043 libmesh_error(); 00044 } 00045 00046 00047 if (this->verbose()) 00048 libMesh::out << std::endl 00049 << "Reading input file " << name 00050 << std::endl 00051 << "-------------------------------------------------------------------------" 00052 << std::endl; 00053 00054 this->read_header (in); 00055 this->read_data (in); 00056 00057 if (this->verbose()) 00058 libMesh::out << std::endl 00059 << "-------------------------------------------------------------------------" 00060 << std::endl; 00061 00062 } 00063 00064 00065 00066 void PltLoader::read_header (std::istream& in) 00067 { 00068 libmesh_assert (in.good()); 00069 00070 //---------------------------------------------------- 00071 // Read the TECPLOT header 00072 00073 // Read the version number 00074 { 00075 in.read (buf, 8); 00076 00077 // Using erase for GCC 2.95.3 00078 this->version().erase(); 00079 00080 for (unsigned int i=0; i<8; i++) 00081 this->version() += buf[i]; 00082 00083 if (this->verbose()) 00084 libMesh::out << "Tecplot Version: " 00085 << this->version() 00086 << std::endl; 00087 } 00088 00089 00090 //---------------------------------------------------- 00091 // Read plt files written by older versions of Tecplot 00092 if (this->version().rfind("V7") < this->version().size()) 00093 { 00094 if (this->verbose()) 00095 libMesh::out << "Reading legacy .plt format (<= v9) ..." 00096 << std::endl; 00097 00098 // Read the value of 1 to determine byte ordering 00099 { 00100 int one = 0; 00101 in.read (buf, LIBMESH_SIZEOF_INT); 00102 std::memcpy (&one, buf, LIBMESH_SIZEOF_INT); 00103 00104 if (one != 1) 00105 { 00106 if (this->verbose()) 00107 libMesh::out << "Tecplot data is Foreign!" 00108 << std::endl; 00109 this->is_foreign() = true; 00110 00111 // Make sure one reversed is one 00112 Utility::ReverseBytes rb(this->is_foreign()); 00113 libmesh_assert_equal_to (rb(one), 1); 00114 } 00115 } 00116 00117 // A byte-reverser in case the data is foreign 00118 Utility::ReverseBytes rb(this->is_foreign()); 00119 00120 // Read the title 00121 { 00122 int i=0; 00123 00124 // Using erase for GCC 2.95.3 00125 this->title().erase(); 00126 00127 do 00128 { 00129 in.read (buf, LIBMESH_SIZEOF_INT); 00130 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00131 rb(i); 00132 00133 // Don't add trailing \0 00134 if (i) 00135 this->title() += static_cast<char>(i); 00136 } 00137 while (i); 00138 } 00139 00140 // Read the number of variables in the data set 00141 { 00142 int nv; 00143 in.read (buf, LIBMESH_SIZEOF_INT); 00144 std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT); 00145 rb(nv); 00146 00147 this->set_n_vars (nv); 00148 } 00149 00150 // Read the variable names 00151 for (unsigned int v=0; v<this->n_vars(); v++) 00152 { 00153 int i=0; 00154 00155 // Using erase for GCC 2.95.3 00156 this->var_name(v).erase(); 00157 00158 do 00159 { 00160 in.read (buf, LIBMESH_SIZEOF_INT); 00161 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00162 rb(i); 00163 00164 // Don't add trailing \0 00165 if (i) 00166 this->var_name(v) += static_cast<char>(i); 00167 } 00168 while (i); 00169 } 00170 00171 00172 00173 // Read zones from the header. 00174 // Continue reading until the end-of-header 00175 // marker (357.) is found. 00176 int nz=0; 00177 std::vector<std::string> zname; 00178 std::vector<int> ztype, zimax, zjmax, zkmax; 00179 00180 { 00181 float f=0.; 00182 00183 do 00184 { 00185 // find the next Zone marker 00186 do 00187 { 00188 f = 0.; 00189 in.read (buf, LIBMESH_SIZEOF_FLOAT); 00190 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 00191 rb(f); 00192 } 00193 while ((f != 299.) && 00194 (f != 357.) && 00195 in.good()); 00196 00197 00198 // Did we overrun the file? 00199 if (!in.good()) 00200 { 00201 libMesh::err << "ERROR: Unexpected end-of-file!" 00202 << std::endl; 00203 libmesh_error(); 00204 } 00205 00206 // Found a Zone marker 00207 else if (f == 299.) 00208 { 00209 // Incriment the Zone counter 00210 nz++; 00211 00212 // Read the zone name 00213 { 00214 int i=0; 00215 std::string name; 00216 00217 do 00218 { 00219 in.read (buf, LIBMESH_SIZEOF_INT); 00220 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00221 rb(i); 00222 00223 // Don't add trailing \0 00224 if (i) 00225 name += static_cast<char>(i); 00226 } 00227 while (i); 00228 00229 zname.push_back(name); 00230 } 00231 00232 // Read the zone format 00233 { 00234 int zt; 00235 in.read (buf, LIBMESH_SIZEOF_INT); 00236 std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT); 00237 rb(zt); 00238 00239 ztype.push_back(zt); 00240 //libMesh::out << "zone type=" << ztype.back() << std::endl; 00241 } 00242 00243 // Read the zone color 00244 { 00245 int zc=0; 00246 00247 in.read (buf, LIBMESH_SIZEOF_INT); 00248 std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT); 00249 rb(zc); 00250 00251 //libMesh::out << "zone color=" << zc << std::endl; 00252 } 00253 00254 // Read in the block dimensions 00255 { 00256 int 00257 i_max=0, 00258 j_max=0, 00259 k_max=0; 00260 00261 in.read (buf, LIBMESH_SIZEOF_INT); 00262 std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT); 00263 rb(i_max); 00264 00265 in.read (buf, LIBMESH_SIZEOF_INT); 00266 std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT); 00267 rb(j_max); 00268 00269 in.read (buf, LIBMESH_SIZEOF_INT); 00270 std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT); 00271 rb(k_max); 00272 00273 zimax.push_back (i_max); 00274 zjmax.push_back (j_max); 00275 zkmax.push_back (k_max); 00276 } 00277 } // else if (f == 299.) 00278 } 00279 while ((f != 357.) && in.good()); 00280 } 00281 00282 // Set the header data 00283 this->set_n_zones (nz); 00284 00285 for (unsigned int z=0; z<this->n_zones(); z++) 00286 { 00287 this->zone_type(z) = ztype[z]; 00288 this->zone_name(z) = zname[z]; 00289 this->imax(z) = zimax[z]; 00290 this->jmax(z) = zjmax[z]; 00291 this->kmax(z) = zkmax[z]; 00292 } 00293 } 00294 00295 00296 //---------------------------------------------------- 00297 // Read plt files written by newer versions of Tecplot 00298 else if (this->version().rfind("V1") < this->version().size()) 00299 { 00300 if (this->verbose()) 00301 libMesh::out << "Reading new .plt format (>= v10)..." 00302 << std::endl; 00303 00304 // Read the value of 1 to determine byte ordering 00305 { 00306 int one = 0; 00307 00308 in.read (buf, LIBMESH_SIZEOF_INT); 00309 std::memcpy (&one, buf, LIBMESH_SIZEOF_INT); 00310 00311 if (one != 1) 00312 { 00313 if (this->verbose()) 00314 libMesh::err << "Tecplot data is Foreign!" 00315 << std::endl; 00316 this->is_foreign() = true; 00317 00318 // Make sure one reversed is one 00319 Utility::ReverseBytes rb(this->is_foreign()); 00320 libmesh_assert_equal_to (rb(one), 1); 00321 } 00322 } 00323 00324 // A byte-reverser in case the data is foreign 00325 Utility::ReverseBytes rb(this->is_foreign()); 00326 00327 // Read the title 00328 { 00329 int i=0; 00330 00331 // Using erase() for GCC 2.95.3 00332 this->title().erase(); 00333 do 00334 { 00335 in.read (buf, LIBMESH_SIZEOF_INT); 00336 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00337 rb(i); 00338 00339 // Don't add trailing \0 00340 if (i) 00341 this->title() += static_cast<char>(i); 00342 } 00343 while (i); 00344 } 00345 00346 // Read the number of variables in the data set 00347 { 00348 int nv; 00349 in.read (buf, LIBMESH_SIZEOF_INT); 00350 std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT); 00351 rb(nv); 00352 00353 this->set_n_vars (nv); 00354 } 00355 00356 // Read the variable names 00357 for (unsigned int v=0; v<this->n_vars(); v++) 00358 { 00359 int i=0; 00360 00361 // Using erase() for GCC 2.95.3 00362 this->var_name(v).erase(); 00363 00364 do 00365 { 00366 in.read (buf, LIBMESH_SIZEOF_INT); 00367 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00368 rb(i); 00369 00370 // Don't add trailing \0 00371 if (i) 00372 this->var_name(v) += static_cast<char>(i); 00373 } 00374 while (i); 00375 } 00376 00377 00378 00379 // Read zones from the header. 00380 // Continue reading until the end-of-header 00381 // marker (357.) is found. 00382 int nz=0; 00383 std::vector<std::string> zname; 00384 std::vector<int> zpack, ztype, zimax, zjmax, zkmax, znelem, znnodes; 00385 00386 { 00387 float f=0.; 00388 00389 do 00390 { 00391 // find the next Zone marker 00392 do 00393 { 00394 f = 0.; 00395 in.read (buf, LIBMESH_SIZEOF_FLOAT); 00396 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 00397 rb(f); 00398 } 00399 while ((f != 299.) && 00400 (f != 357.) && 00401 in.good()); 00402 00403 00404 // Did we overrun the file? 00405 if (!in.good()) 00406 { 00407 libMesh::err << "ERROR: Unexpected end-of-file!" 00408 << std::endl; 00409 libmesh_error(); 00410 } 00411 00412 // Found a Zone marker 00413 else if (f == 299.) 00414 { 00415 // Incriment the Zone counter 00416 nz++; 00417 00418 // Read the zone name 00419 { 00420 int i=0; 00421 std::string name; 00422 00423 do 00424 { 00425 in.read (buf, LIBMESH_SIZEOF_INT); 00426 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT); 00427 rb(i); 00428 00429 // Don't add trailing \0 00430 if (i) 00431 name += static_cast<char>(i); 00432 } 00433 while (i); 00434 00435 zname.push_back(name); 00436 } 00437 00438 // Read the zone color 00439 { 00440 int zc=0; 00441 in.read (buf, LIBMESH_SIZEOF_INT); 00442 std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT); 00443 rb(zc); 00444 } 00445 00446 // Read the zone format 00447 { 00448 int zt; 00449 in.read (buf, LIBMESH_SIZEOF_INT); 00450 std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT); 00451 rb(zt); 00452 00453 ztype.push_back(zt); 00454 } 00455 00456 // Read the data packing flag 00457 { 00458 int dp=0; 00459 in.read (buf, LIBMESH_SIZEOF_INT); 00460 std::memcpy (&dp, buf, LIBMESH_SIZEOF_INT); 00461 rb(dp); 00462 00463 zpack.push_back (dp); 00464 } 00465 00466 // Will we specify the variable location? 00467 { 00468 int svl=0; 00469 int vl=0; 00470 in.read (buf, LIBMESH_SIZEOF_INT); 00471 std::memcpy (&svl, buf, LIBMESH_SIZEOF_INT); 00472 rb(svl); 00473 00474 if (svl) 00475 for (unsigned int v=0; v<this->n_vars(); v++) 00476 { 00477 in.read (buf, LIBMESH_SIZEOF_INT); 00478 std::memcpy (&vl, buf, LIBMESH_SIZEOF_INT); 00479 rb(vl); 00480 libmesh_assert_equal_to (vl, 0); // Only know about node-based data 00481 // right now 00482 } 00483 00484 } 00485 00486 // Get the number of user-defined face-neighbors 00487 { 00488 int fn=0; 00489 in.read (buf, LIBMESH_SIZEOF_INT); 00490 std::memcpy (&fn, buf, LIBMESH_SIZEOF_INT); 00491 rb(fn); 00492 } 00493 00494 // Read in the block dimensions 00495 { 00496 if (ztype.back() != ORDERED) 00497 { 00498 int np=0, ne=0; 00499 00500 in.read (buf, LIBMESH_SIZEOF_INT); 00501 std::memcpy (&np, buf, LIBMESH_SIZEOF_INT); 00502 rb(np); 00503 00504 in.read (buf, LIBMESH_SIZEOF_INT); 00505 std::memcpy (&ne, buf, LIBMESH_SIZEOF_INT); 00506 rb(ne); 00507 00508 zimax.push_back (np); 00509 zjmax.push_back (ne); 00510 zjmax.push_back (0); 00511 } 00512 00513 int 00514 i_max=0, 00515 j_max=0, 00516 k_max=0; 00517 00518 in.read (buf, LIBMESH_SIZEOF_INT); 00519 std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT); 00520 rb(i_max); 00521 00522 in.read (buf, LIBMESH_SIZEOF_INT); 00523 std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT); 00524 rb(j_max); 00525 00526 in.read (buf, LIBMESH_SIZEOF_INT); 00527 std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT); 00528 rb(k_max); 00529 00530 // These are only useful for orderd data. Otherwise 00531 // we grabbed the relevant values above. 00532 if (ztype.back() != ORDERED) 00533 { 00534 zimax.push_back (i_max); 00535 zjmax.push_back (j_max); 00536 zkmax.push_back (k_max); 00537 } 00538 } 00539 } // else if (f == 299.) 00540 } 00541 while ((f != 357.) && in.good()); 00542 } 00543 00544 // Set the header data 00545 this->set_n_zones (nz); 00546 00547 for (unsigned int z=0; z<this->n_zones(); z++) 00548 { 00549 this->zone_type(z) = ztype[z]; 00550 this->zone_name(z) = zname[z]; 00551 this->zone_pack(z) = zpack[z]; 00552 this->imax(z) = zimax[z]; 00553 this->jmax(z) = zjmax[z]; 00554 this->kmax(z) = zkmax[z]; 00555 } 00556 } 00557 00558 00559 00560 //---------------------------------------------------- 00561 // Unrecognized Tecplot Version! 00562 else 00563 { 00564 libMesh::err << "ERROR: This plot file was written by an unrecognized version of Tecplot!:" 00565 << std::endl 00566 << this->version() 00567 << std::endl; 00568 libmesh_error(); 00569 } 00570 00571 00572 00573 00574 00575 00576 00577 00578 // Print the data to the screen. 00579 if (this->verbose()) 00580 { 00581 libMesh::out << "Tecplot Header: " 00582 << this->title() << std::endl; 00583 00584 libMesh::out << "Variables: "; 00585 for (unsigned int v=0; v<this->n_vars(); v++) 00586 libMesh::out << "\"" << this->var_name (v) << "\"" << " "; 00587 libMesh::out << std::endl; 00588 00589 libMesh::out << "Variable Types: "; 00590 for (unsigned int v=0; v<this->n_vars(); v++) 00591 libMesh::out << this->var_type (v) << " "; 00592 libMesh::out << std::endl; 00593 00594 libMesh::out << "Zone Names: "; 00595 for (unsigned int z=0; z<this->n_zones(); z++) 00596 libMesh::out << "\"" << this->zone_name (z) << "\"" << " "; 00597 libMesh::out << std::endl; 00598 00599 libMesh::out << "Zone Types: "; 00600 for (unsigned int z=0; z<this->n_zones(); z++) 00601 { 00602 libMesh::out << this->zone_type (z) << " "; 00603 00604 if (this->zone_type (z) != ORDERED) 00605 libMesh::out << "(" << this->n_nodes(z) << "," << this->n_elem(z) << ") "; 00606 } 00607 libMesh::out << std::endl; 00608 00609 libMesh::out << "Zone Dimensions: " << std::endl; 00610 for (unsigned int z=0; z<this->n_zones(); z++) 00611 libMesh::out << " (" 00612 << this->imax(z) << "," 00613 << this->jmax(z) << "," 00614 << this->kmax(z) << ")" 00615 << std::endl; 00616 } 00617 } 00618 00619 00620 00621 void PltLoader::read_data (std::istream& in) 00622 { 00623 libmesh_assert (in.good()); 00624 00625 // A byte-reverser in case the data is foreign 00626 Utility::ReverseBytes rb(this->is_foreign()); 00627 00628 //---------------------------------------------------- 00629 // Read the TECPLOT data for each zone 00630 if (this->verbose()) 00631 { 00632 libMesh::out << "Reading Zones"; 00633 libMesh::out.flush(); 00634 } 00635 00636 00637 for (unsigned int zone=0; zone<this->n_zones(); zone++) 00638 { 00639 if (this->verbose()) 00640 { 00641 libMesh::out << "."; 00642 libMesh::out.flush(); 00643 } 00644 00645 00646 //---------------------------------------------------- 00647 // Read plt files written by older versions of Tecplot 00648 if (this->version().rfind("V7") < this->version().size()) 00649 { 00650 float f = 0.; 00651 00652 // Find the next Zone marker. 00653 do 00654 { 00655 f = 0.; 00656 in.read (buf, LIBMESH_SIZEOF_FLOAT); 00657 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 00658 rb(f); 00659 } 00660 while ((f != 299.) && in.good()); 00661 00662 // Did we overrun the file? 00663 if (!in.good()) 00664 { 00665 libMesh::err << "ERROR: Unexpected end-of-file!" 00666 << std::endl; 00667 libmesh_error(); 00668 } 00669 00670 // Get the number of repeated vars. 00671 unsigned int n_rep_vars=0; 00672 std::vector<int> rep_vars; 00673 00674 { 00675 in.read (buf, LIBMESH_SIZEOF_INT); 00676 std::memcpy (&n_rep_vars, buf, LIBMESH_SIZEOF_INT); 00677 rb(n_rep_vars); 00678 00679 rep_vars.resize (n_rep_vars); 00680 00681 // Get the repeated variables number. 00682 for (unsigned int v=0; v<n_rep_vars; v++) 00683 { 00684 libMesh::err << "ERROR: I don't understand repeated variables yet!" 00685 << std::endl; 00686 libmesh_error(); 00687 00688 in.read (buf, LIBMESH_SIZEOF_INT); 00689 std::memcpy (&rep_vars[v], buf, LIBMESH_SIZEOF_INT); 00690 rb(rep_vars[v]); 00691 } 00692 } 00693 00694 // Get the variable data type 00695 //libMesh::out << "var_types="; 00696 for (unsigned int v=0; v<this->n_vars(); v++) 00697 { 00698 in.read (buf, LIBMESH_SIZEOF_INT); 00699 std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT); 00700 rb(this->var_type(v)); 00701 00702 //libMesh::out << this->var_type(v) << " "; 00703 } 00704 //libMesh::out << std::endl; 00705 00706 00707 00708 // Read the data. 00709 switch (this->zone_type(zone) ) 00710 { 00711 // Block-based data. Structured meshes. 00712 case BLOCK: 00713 { 00714 this->read_block_data (in, zone); 00715 break; 00716 } 00717 00718 // Point-based data. Structured meshes. 00719 case POINT: 00720 { 00721 this->read_point_data (in, zone); 00722 break; 00723 } 00724 00725 // FE block data. Unstructured meshes. 00726 case FEBLOCK: 00727 { 00728 this->read_feblock_data (in, zone); 00729 00730 if (this->verbose()) 00731 00732 libMesh::out << "Zone " << zone << ":" << std::endl 00733 << " nnodes =" << this->imax(zone) << std::endl 00734 << " nelem =" << this->jmax(zone) << std::endl 00735 << " elem_type=" << this->kmax(zone) << std::endl 00736 << std::endl; 00737 break; 00738 } 00739 00740 // FE point data. Unstructured meshes. 00741 case FEPOINT: 00742 { 00743 this->read_fepoint_data (in, zone); 00744 break; 00745 } 00746 00747 default: 00748 { 00749 libMesh::err << "ERROR: Unsupported Zone type: " 00750 << this->zone_type(zone) 00751 << std::endl; 00752 libmesh_error(); 00753 } 00754 } // end switch on zone type 00755 } 00756 00757 00758 //---------------------------------------------------- 00759 // Read plt files written by newer versions of Tecplot 00760 else if (this->version().rfind("V1") < this->version().size()) 00761 { 00762 float f = 0.; 00763 00764 // Find the next Zone marker. 00765 do 00766 { 00767 f = 0.; 00768 in.read (buf, LIBMESH_SIZEOF_FLOAT); 00769 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 00770 rb(f); 00771 } 00772 while ((f != 299.) && in.good()); 00773 00774 // Did we overrun the file? 00775 if (!in.good()) 00776 { 00777 libMesh::err << "ERROR: Unexpected end-of-file!" 00778 << std::endl; 00779 libmesh_error(); 00780 } 00781 00782 // Get the variable data type 00783 for (unsigned int v=0; v<this->n_vars(); v++) 00784 { 00785 in.read (buf, LIBMESH_SIZEOF_INT); 00786 std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT); 00787 rb(this->var_type(v)); 00788 00789 //libMesh::out << this->var_type(v) << " "; 00790 } 00791 00792 // Get the variable sharing flag 00793 { 00794 int vs=0; 00795 int sv=0; 00796 00797 in.read (buf, LIBMESH_SIZEOF_INT); 00798 std::memcpy (&vs, buf, LIBMESH_SIZEOF_INT); 00799 rb(vs); 00800 00801 if (vs) 00802 { 00803 for (unsigned int v=0; v<this->n_vars(); v++) 00804 { 00805 in.read (buf, LIBMESH_SIZEOF_INT); 00806 std::memcpy (&sv, buf, LIBMESH_SIZEOF_INT); 00807 rb(sv); 00808 00809 if (sv != -1) 00810 { 00811 libMesh::err << "ERROR: I don't understand variable sharing!" 00812 << std::endl; 00813 libmesh_error(); 00814 } 00815 } 00816 } 00817 } 00818 00819 // Get zone to share connectivity with 00820 { 00821 int sc=0; 00822 in.read (buf, LIBMESH_SIZEOF_INT); 00823 std::memcpy (&sc, buf, LIBMESH_SIZEOF_INT); 00824 rb(sc); 00825 00826 libmesh_assert_equal_to (sc, -1); 00827 } 00828 00829 00830 // Read the data. 00831 if (this->zone_type(zone) == ORDERED) 00832 { 00833 // Block-based data. Structured meshes. 00834 if (this->zone_pack(zone) == 0) 00835 this->read_block_data (in, zone); 00836 00837 // Point-based data. Structured meshes. 00838 else if (this->zone_pack(zone) == 1) 00839 this->read_point_data (in, zone); 00840 00841 else 00842 libmesh_error(); 00843 } 00844 else 00845 { 00846 // Block-based data. Unstructured meshes. 00847 if (this->zone_pack(zone) == 0) 00848 this->read_feblock_data (in, zone); 00849 00850 // Point-based data. Unstructured meshes. 00851 else if (this->zone_pack(zone) == 1) 00852 this->read_fepoint_data (in, zone); 00853 00854 else 00855 libmesh_error(); 00856 } 00857 } 00858 00859 00860 00861 //---------------------------------------------------- 00862 // Unrecognized Tecplot Version! 00863 else 00864 { 00865 libMesh::err << "ERROR: This plot file was written by an unrecognized version of Tecplot!:" 00866 << std::endl 00867 << this->version() 00868 << std::endl; 00869 libmesh_error(); 00870 } 00871 00872 } // end loop on zones 00873 } 00874 00875 00876 00877 void PltLoader::read_block_data (std::istream& in, const unsigned int zone) 00878 { 00879 libmesh_assert (in.good()); 00880 00881 00882 // A byte-reverser in case the data is foreign 00883 Utility::ReverseBytes rb(this->is_foreign()); 00884 00885 00886 for (unsigned int var=0; var<this->n_vars(); var++) 00887 { 00888 00889 switch (this->var_type(var)) 00890 { 00891 00892 // Read a single-precision variable 00893 case FLOAT: 00894 { 00895 std::vector<float> & data = _data[zone][var]; 00896 00897 data.clear(); 00898 data.resize (this->imax(zone)* 00899 this->jmax(zone)* 00900 this->kmax(zone)); 00901 00902 in.read ((char*) &data[0], LIBMESH_SIZEOF_FLOAT*data.size()); 00903 00904 for (unsigned int i=0; i<data.size(); i++) 00905 rb(data[i]); 00906 00907 break; 00908 } 00909 00910 // Read a double-precision variable 00911 case DOUBLE: 00912 { 00913 std::vector<double> ddata; 00914 std::vector<float> & data = _data[zone][var]; 00915 00916 data.clear(); 00917 data.resize (this->imax(zone)* 00918 this->jmax(zone)* 00919 this->kmax(zone)); 00920 00921 ddata.resize (this->imax(zone)* 00922 this->jmax(zone)* 00923 this->kmax(zone)); 00924 00925 in.read ((char*) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size()); 00926 00927 for (unsigned int i=0; i<data.size(); i++) 00928 data[i] = rb(ddata[i]); 00929 00930 break; 00931 } 00932 00933 default: 00934 { 00935 libMesh::err << "ERROR: Unsupported data type: " 00936 << this->var_type(var) 00937 << std::endl; 00938 libmesh_error(); 00939 } 00940 } 00941 } 00942 } 00943 00944 00945 00946 void PltLoader::read_point_data (std::istream& in, const unsigned int zone) 00947 { 00948 libmesh_assert (in.good()); 00949 00950 // A byte-reverser in case the data is foreign 00951 Utility::ReverseBytes rb(this->is_foreign()); 00952 00953 // First allocate space 00954 for (unsigned int var=0; var<this->n_vars(); var++) 00955 { 00956 std::vector<float> & data = _data[zone][var]; 00957 00958 data.clear(); 00959 data.reserve (this->imax(zone)* 00960 this->jmax(zone)* 00961 this->kmax(zone)); 00962 } 00963 00964 00965 for (unsigned int k=0; k<this->kmax(zone); k++) 00966 for (unsigned int j=0; j<this->jmax(zone); j++) 00967 for (unsigned int i=0; i<this->imax(zone); i++) 00968 for (unsigned int var=0; var<this->n_vars(); var++) 00969 if (this->var_type(var) == FLOAT) 00970 { 00971 float f = 0.; 00972 00973 libmesh_assert (in.good()); 00974 00975 in.read (buf, LIBMESH_SIZEOF_FLOAT); 00976 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 00977 rb(f); 00978 00979 _data[zone][var].push_back(f); 00980 } 00981 else if (this->var_type(var) == DOUBLE) 00982 { 00983 double d = 0.; 00984 00985 libmesh_assert (in.good()); 00986 00987 in.read (buf, LIBMESH_SIZEOF_DOUBLE); 00988 std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE); 00989 rb(d); 00990 00991 _data[zone][var].push_back(d); 00992 } 00993 else 00994 { 00995 libMesh::err << "ERROR: unsupported data type: " 00996 << this->var_type(var) 00997 << std::endl; 00998 libmesh_error(); 00999 } 01000 } 01001 01002 01003 01004 void PltLoader::read_feblock_data (std::istream& in, const unsigned int zone) 01005 { 01006 libmesh_assert (in.good()); 01007 01008 // A byte-reverser in case the data is foreign 01009 Utility::ReverseBytes rb(this->is_foreign()); 01010 01011 // Read the variable values at each node. 01012 for (unsigned int var=0; var<this->n_vars(); var++) 01013 { 01014 switch (this->var_type(var)) 01015 { 01016 01017 // Read a single-precision variable 01018 case FLOAT: 01019 { 01020 std::vector<float> & data = _data[zone][var]; 01021 01022 data.clear(); 01023 data.resize (this->imax(zone)); 01024 01025 in.read ((char*) &data[0], LIBMESH_SIZEOF_FLOAT*data.size()); 01026 01027 for (unsigned int i=0; i<data.size(); i++) 01028 rb(data[i]); 01029 01030 break; 01031 } 01032 01033 // Read a double-precision variable 01034 case DOUBLE: 01035 { 01036 std::vector<double> ddata; 01037 std::vector<float> & data = _data[zone][var]; 01038 01039 data.clear(); 01040 data.resize (this->imax(zone)); 01041 ddata.resize (this->imax(zone)); 01042 01043 in.read ((char*) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size()); 01044 01045 for (unsigned int i=0; i<data.size(); i++) 01046 data[i] = rb(ddata[i]); 01047 01048 break; 01049 } 01050 01051 default: 01052 { 01053 libMesh::err << "ERROR: Unsupported data type: " 01054 << this->var_type(var) 01055 << std::endl; 01056 libmesh_error(); 01057 } 01058 } 01059 } 01060 01061 // Read the connectivity 01062 { 01063 // Get the connectivity repetition flag 01064 int rep=0; 01065 in.read ((char*) &rep, LIBMESH_SIZEOF_INT); 01066 rb(rep); 01067 01068 if (rep == 1 && this->n_zones() > 1) 01069 { 01070 libMesh::err << "ERROR: Repeated connectivity not supported!" 01071 << std::endl; 01072 libmesh_error(); 01073 } 01074 01075 // Read the connectivity 01076 else 01077 { 01078 libmesh_assert_less (zone, _conn.size()); 01079 libmesh_assert_less (this->kmax(zone), 4); 01080 01081 _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]); 01082 01083 in.read ((char*) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size()); 01084 01085 for (unsigned int i=0; i<_conn[zone].size(); i++) 01086 rb(_conn[zone][i]); 01087 } 01088 } 01089 } 01090 01091 01092 01093 void PltLoader::read_fepoint_data (std::istream& in, const unsigned int zone) 01094 { 01095 libmesh_assert (in.good()); 01096 01097 // A byte-reverser in case the data is foreign 01098 Utility::ReverseBytes rb(this->is_foreign()); 01099 01100 // First allocate space 01101 for (unsigned int var=0; var<this->n_vars(); var++) 01102 { 01103 std::vector<float> & data = _data[zone][var]; 01104 01105 data.clear(); 01106 data.reserve (this->imax(zone)); 01107 } 01108 01109 01110 for (unsigned int i=0; i<this->imax(zone); i++) 01111 for (unsigned int var=0; var<this->n_vars(); var++) 01112 if (this->var_type(var) == FLOAT) 01113 { 01114 float f = 0.; 01115 01116 libmesh_assert (in.good()); 01117 01118 in.read (buf, LIBMESH_SIZEOF_FLOAT); 01119 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT); 01120 rb(f); 01121 01122 _data[zone][var].push_back(f); 01123 } 01124 else if (this->var_type(var) == DOUBLE) 01125 { 01126 double d = 0.; 01127 01128 libmesh_assert (in.good()); 01129 01130 in.read (buf, LIBMESH_SIZEOF_DOUBLE); 01131 std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE); 01132 rb(d); 01133 01134 _data[zone][var].push_back(d); 01135 } 01136 else 01137 { 01138 libMesh::err << "ERROR: unsupported data type: " 01139 << this->var_type(var) 01140 << std::endl; 01141 libmesh_error(); 01142 } 01143 01144 // Read the connectivity 01145 { 01146 // Get the connectivity repetition flag 01147 int rep=0; 01148 01149 in.read ((char*) &rep, LIBMESH_SIZEOF_INT); 01150 rb(rep); 01151 01152 if (rep == 1) 01153 { 01154 libMesh::err << "ERROR: Repeated connectivity not supported!" 01155 << std::endl; 01156 libmesh_error(); 01157 } 01158 01159 // Read the connectivity 01160 else 01161 { 01162 libmesh_assert_less (zone, _conn.size()); 01163 libmesh_assert_less (this->kmax(zone), 4); 01164 01165 _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]); 01166 01167 in.read ((char*) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size()); 01168 01169 for (unsigned int i=0; i<_conn[zone].size(); i++) 01170 rb(_conn[zone][i]); 01171 } 01172 } 01173 } 01174 01175 } // namespace libMesh
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: