00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <winstd.H>
00027
00028 #if defined(BL_OLD_STL)
00029 #include <stdlib.h>
00030 #include <float.h>
00031 #include <math.h>
00032 #include <string.h>
00033 #else
00034 #include <cstdlib>
00035 #include <cfloat>
00036 #include <cmath>
00037 #include <cstring>
00038 #endif
00039
00040 #include <iostream>
00041 #include <iomanip>
00042 #include <limits>
00043
00044 #include <FArrayBox.H>
00045 #include <FabConv.H>
00046 #include <ParmParse.H>
00047 #include <FabConv.H>
00048 #include <FPC.H>
00049
00050 #include <BLassert.H>
00051 #include <BoxLib.H>
00052 #include <Looping.H>
00053
00054 #if defined(BL_ARCH_CRAY)
00055 static const char sys_name[] = "CRAY";
00056 #else
00057 static const char sys_name[] = "IEEE";
00058 #endif
00059
00060
00061
00062
00063 FABio::Ordering FArrayBox::ordering = FABio::FAB_NORMAL_ORDER;
00064
00065
00066
00067
00068 class FABio_8bit
00069 :
00070 public FABio
00071 {
00072 public:
00073 virtual void read (std::istream& is,
00074 FArrayBox& fb) const;
00075
00076 virtual void write (std::ostream& os,
00077 const FArrayBox& fb,
00078 int comp,
00079 int num_comp) const;
00080
00081 virtual void skip (std::istream& is,
00082 FArrayBox& f) const;
00083
00084 virtual void skip (std::istream& is,
00085 FArrayBox& f,
00086 int nCompToSkip) const;
00087 protected:
00088 virtual void write_header (std::ostream& os,
00089 const FArrayBox& f,
00090 int nvar) const;
00091 };
00092
00093
00094
00095
00096 class FABio_ascii
00097 :
00098 public FABio
00099 {
00100 public:
00101 virtual void read (std::istream& is,
00102 FArrayBox& fb) const;
00103
00104 virtual void write (std::ostream& os,
00105 const FArrayBox& fb,
00106 int comp,
00107 int num_comp) const;
00108
00109 virtual void skip (std::istream& is,
00110 FArrayBox& f) const;
00111
00112 virtual void skip (std::istream& is,
00113 FArrayBox& f,
00114 int nCompToSkip) const;
00115 protected:
00116 virtual void write_header (std::ostream& os,
00117 const FArrayBox& f,
00118 int nvar) const;
00119 };
00120
00121
00122
00123
00124 class FABio_binary
00125 :
00126 public FABio
00127 {
00128 public:
00129 FABio_binary (RealDescriptor* rd_);
00130
00131 virtual void read (std::istream& is,
00132 FArrayBox& fb) const;
00133
00134 virtual void write (std::ostream& os,
00135 const FArrayBox& fb,
00136 int comp,
00137 int num_comp) const;
00138
00139 virtual void skip (std::istream& is,
00140 FArrayBox& f) const;
00141
00142 virtual void skip (std::istream& is,
00143 FArrayBox& f,
00144 int nCompToSkip) const;
00145
00146 protected:
00147 virtual void write_header (std::ostream& os,
00148 const FArrayBox& f,
00149 int nvar) const;
00150
00151 CpClassPtr<RealDescriptor> rd;
00152 };
00153
00154
00155
00156
00157
00158 FABio::~FABio () {}
00159
00160 void
00161 FABio::write_header (std::ostream& os,
00162 const FArrayBox& f,
00163 int nvar) const
00164 {
00165 BL_ASSERT(nvar <= f.nComp());
00166 os << f.box() << ' ' << nvar << '\n';
00167 if (os.fail())
00168 BoxLib::Error("FABio::write_header() failed");
00169 }
00170
00171
00172
00173
00174
00175
00176 FABio::Format FArrayBox::format = FABio::FAB_NATIVE;
00177
00178 FABio* FArrayBox::fabio = new FABio_binary(FPC::NativeRealDescriptor().clone());
00179
00180 FArrayBox::FArrayBox ()
00181 {}
00182
00183 FArrayBox::FArrayBox (const FArrayBox& fab)
00184 :
00185 BaseFab<Real>(fab)
00186 {}
00187
00188 FArrayBox&
00189 FArrayBox::operator= (const FArrayBox& fab)
00190 {
00191 BaseFab<Real>::operator=(fab);
00192 return *this;
00193 }
00194
00195 FArrayBox&
00196 FArrayBox::operator= (const Real& v)
00197 {
00198 BaseFab<Real>::operator=(v);
00199 return *this;
00200 }
00201
00202 FArrayBox::FArrayBox (const Box& b,
00203 int n)
00204 :
00205 BaseFab<Real>(b,n)
00206 {
00207
00208
00209
00210 if ( do_initval )
00211 setVal(initval);
00212 }
00213
00214 void
00215 FArrayBox::resize (const Box& b,
00216 int N)
00217 {
00218 BaseFab<Real>::resize(b,N);
00219
00220
00221
00222 if ( do_initval )
00223 setVal(initval);
00224 }
00225
00226 FABio::Format
00227 FArrayBox::getFormat ()
00228 {
00229 return format;
00230 }
00231
00232 const FABio&
00233 FArrayBox::getFABio ()
00234 {
00235 return *fabio;
00236 }
00237
00238 void
00239 FArrayBox::setFABio (FABio* rd)
00240 {
00241 BL_ASSERT(rd != 0);
00242 delete fabio;
00243 fabio = rd;
00244 }
00245
00246 Real
00247 FArrayBox::norm (int p,
00248 int comp,
00249 int numcomp) const
00250 {
00251 return norm(domain,p,comp,numcomp);
00252 }
00253
00254 void
00255 FArrayBox::writeOn (std::ostream& os) const
00256 {
00257 writeOn(os,0,nComp());
00258 }
00259
00260 void
00261 FArrayBox::skipFAB (std::istream& is)
00262 {
00263 int ignore = 0;
00264 skipFAB(is, ignore);
00265 }
00266
00267 FArrayBox::~FArrayBox () {}
00268
00269 void
00270 FArrayBox::setFormat (FABio::Format fmt)
00271 {
00272 FABio* fio = 0;
00273 RealDescriptor* rd = 0;
00274
00275 switch (fmt)
00276 {
00277 case FABio::FAB_ASCII:
00278 fio = new FABio_ascii;
00279 break;
00280 case FABio::FAB_8BIT:
00281 fio = new FABio_8bit;
00282 break;
00283 case FABio::FAB_NATIVE:
00284 rd = FPC::NativeRealDescriptor().clone();
00285 fio = new FABio_binary(rd);
00286 break;
00287 case FABio::FAB_IEEE:
00288
00289
00290
00291
00292 case FABio::FAB_IEEE_32:
00293 rd = FPC::Ieee32NormalRealDescriptor().clone();
00294 fio = new FABio_binary(rd);
00295 break;
00296 default:
00297 std::cerr << "FArrayBox::setFormat(): Bad FABio::Format = " << fmt;
00298 BoxLib::Abort();
00299 }
00300
00301 FArrayBox::format = fmt;
00302
00303 setFABio(fio);
00304 }
00305
00306 void
00307 FArrayBox::setOrdering (FABio::Ordering ordering_)
00308 {
00309
00310 ordering = ordering_;
00311 }
00312
00313 FABio::Ordering
00314 FArrayBox::getOrdering ()
00315 {
00316
00317 return ordering;
00318 }
00319
00320 void
00321 FArrayBox::setPrecision (FABio::Precision)
00322 {
00323
00324 }
00325
00326 FABio::Precision
00327 FArrayBox::getPrecision ()
00328 {
00329
00330 return FABio::FAB_FLOAT;
00331 }
00332
00333 #if !defined(NDEBUG)
00334 bool FArrayBox::do_initval = true;
00335 #else
00336 bool FArrayBox::do_initval = false;
00337 #endif
00338 Real FArrayBox::initval =
00339 std::numeric_limits<Real>::has_quiet_NaN
00340 ? std::numeric_limits<Real>::quiet_NaN()
00341 : std::numeric_limits<Real>::max();
00342
00343 bool
00344 FArrayBox::set_do_initval (bool tf)
00345 {
00346 bool o_tf = do_initval;
00347 do_initval = tf;
00348 return o_tf;
00349 }
00350
00351 bool
00352 FArrayBox::get_do_initval ()
00353 {
00354 return do_initval;
00355 }
00356
00357 Real
00358 FArrayBox::set_initval (Real iv)
00359 {
00360 Real o_iv = initval;
00361 initval = iv;
00362 return o_iv;
00363 }
00364
00365 Real
00366 FArrayBox::get_initval ()
00367 {
00368 return initval;
00369 }
00370
00371 void
00372 FArrayBox::Initialize ()
00373 {
00374 ParmParse pp("fab");
00375
00376 std::string fmt;
00377
00378
00379
00380 if (pp.query("format", fmt))
00381 {
00382 FABio* fio = 0;
00383 RealDescriptor* rd = 0;
00384
00385 if (fmt == "ASCII")
00386 {
00387 FArrayBox::format = FABio::FAB_ASCII;
00388 fio = new FABio_ascii;
00389 }
00390 else if (fmt == "8BIT")
00391 {
00392 FArrayBox::format = FABio::FAB_8BIT;
00393 fio = new FABio_8bit;
00394 }
00395 else if (fmt == "NATIVE")
00396 {
00397 FArrayBox::format = FABio::FAB_NATIVE;
00398 rd = FPC::NativeRealDescriptor().clone();
00399 fio = new FABio_binary(rd);
00400 }
00401 else if (fmt == "IEEE" || fmt == "IEEE32")
00402 {
00403 if (fmt == "IEEE")
00404 {
00405 FArrayBox::format = FABio::FAB_IEEE;
00406
00407 }
00408 else
00409 {
00410 FArrayBox::format = FABio::FAB_IEEE_32;
00411 }
00412 rd = FPC::Ieee32NormalRealDescriptor().clone();
00413
00414 fio = new FABio_binary(rd);
00415 }
00416 else
00417 {
00418 std::cerr << "FArrayBox::init(): Bad FABio::Format = " << fmt;
00419 BoxLib::Abort();
00420 }
00421
00422 setFABio(fio);
00423 }
00424
00425
00426
00427
00428 std::string ord;
00429 if (pp.query("ordering", ord))
00430 {
00431 if (ord == "NORMAL_ORDER")
00432 FArrayBox::setOrdering(FABio::FAB_NORMAL_ORDER);
00433 else if (ord == "REVERSE_ORDER")
00434 FArrayBox::setOrdering(FABio::FAB_REVERSE_ORDER);
00435 else if (ord == "REVERSE_ORDER_2")
00436 FArrayBox::setOrdering(FABio::FAB_REVERSE_ORDER_2);
00437 else
00438 {
00439 std::cerr << "FArrayBox::init(): Bad FABio::Ordering = " << ord;
00440 BoxLib::Abort();
00441 }
00442 }
00443 pp.query("initval", initval);
00444 pp.query("do_initval", do_initval);
00445 }
00446
00447 void
00448 FArrayBox::Finalize ()
00449 {}
00450
00451
00452 Real
00453 FArrayBox::norm (const Box& subbox,
00454 int p,
00455 int comp,
00456 int ncomp) const
00457 {
00458 BL_ASSERT(p >= 0);
00459 BL_ASSERT(comp >= 0 && comp+ncomp <= nComp());
00460
00461 Real nrm = 0;
00462 Real* tmp = 0;
00463 int tmplen = 0;
00464
00465 if (p == 0 || p == 1)
00466 {
00467 nrm = BaseFab<Real>::norm(subbox,p,comp,ncomp);
00468 }
00469 else if (p == 2)
00470 {
00471 ForAllThisCPencil(Real,subbox,comp,ncomp)
00472 {
00473 const Real* row = &thisR;
00474 if (tmp == 0)
00475 {
00476 tmp = new Real[thisLen];
00477 tmplen = thisLen;
00478 for (int i = 0; i < thisLen; i++)
00479 tmp[i] = row[i]*row[i];
00480 }
00481 else
00482 {
00483 for (int i = 0; i < thisLen; i++)
00484 tmp[i] += row[i]*row[i];
00485 }
00486 } EndForPencil
00487 nrm = tmp[0];
00488 for (int i = 1; i < tmplen; i++)
00489 nrm += tmp[i];
00490 nrm = sqrt(nrm);
00491 }
00492 else
00493 {
00494 Real pwr = Real(p);
00495 ForAllThisCPencil(Real,subbox,comp,ncomp)
00496 {
00497 const Real* row = &thisR;
00498 if (tmp == 0)
00499 {
00500 tmp = new Real[thisLen];
00501 tmplen = thisLen;
00502 for (int i = 0; i < thisLen; i++)
00503 tmp[i] = pow(row[i],pwr);
00504 }
00505 else
00506 {
00507 for (int i = 0; i < thisLen; i++)
00508 tmp[i] += pow(row[i],pwr);
00509 }
00510 } EndForPencil
00511 nrm = tmp[0];
00512 for (int i = 1; i < tmplen; i++)
00513 nrm += tmp[i];
00514 Real invpwr = 1.0/pwr;
00515 nrm = pow(nrm,invpwr);
00516 }
00517
00518 delete [] tmp;
00519
00520 return nrm;
00521 }
00522
00523
00524
00525
00526 #define BL_IGNORE_MAX 100000
00527
00528
00529
00530
00531
00532 FABio*
00533 FABio::read_header (std::istream& is,
00534 FArrayBox& f)
00535 {
00536 int nvar;
00537 Box bx;
00538 FABio* fio = 0;
00539 RealDescriptor* rd = 0;
00540 char c;
00541
00542 is >> c;
00543 if (c != 'F') BoxLib::Error("FABio::read_header(): expected \'F\'");
00544 is >> c;
00545 if (c != 'A') BoxLib::Error("FABio::read_header(): expected \'A\'");
00546 is >> c;
00547 if (c != 'B') BoxLib::Error("FABio::read_header(): expected \'B\'");
00548
00549 is >> c;
00550 if (c == ':')
00551 {
00552
00553
00554
00555 int typ_in, wrd_in;
00556 is >> typ_in;
00557 is >> wrd_in;
00558
00559 char machine[128];
00560 is >> machine;
00561 is >> bx;
00562 is >> nvar;
00563
00564
00565
00566 f.resize(bx,nvar);
00567 is.ignore(BL_IGNORE_MAX, '\n');
00568 switch (typ_in)
00569 {
00570 case FABio::FAB_ASCII: fio = new FABio_ascii; break;
00571 case FABio::FAB_8BIT: fio = new FABio_8bit; break;
00572 case FABio::FAB_NATIVE:
00573 case FABio::FAB_IEEE:
00574 rd = RealDescriptor::newRealDescriptor(typ_in,
00575 wrd_in,
00576 machine,
00577 FArrayBox::ordering);
00578 fio = new FABio_binary(rd);
00579 break;
00580 default:
00581 BoxLib::Error("FABio::read_header(): Unrecognized FABio header");
00582 }
00583 }
00584 else
00585 {
00586
00587
00588
00589 is.putback(c);
00590 rd = new RealDescriptor;
00591 is >> *rd;
00592 is >> bx;
00593 is >> nvar;
00594
00595
00596
00597 f.resize(bx,nvar);
00598 is.ignore(BL_IGNORE_MAX, '\n');
00599 fio = new FABio_binary(rd);
00600 }
00601
00602 if (is.fail())
00603 BoxLib::Error("FABio::read_header() failed");
00604
00605 return fio;
00606 }
00607
00608
00609 FABio*
00610 FABio::read_header (std::istream& is,
00611 FArrayBox& f,
00612 int compIndex,
00613 int& nCompAvailable)
00614 {
00615 int nvar;
00616 Box bx;
00617 FABio* fio = 0;
00618 RealDescriptor* rd = 0;
00619 char c;
00620
00621 is >> c;
00622 if (c != 'F') BoxLib::Error("FABio::read_header(): expected \'F\'");
00623 is >> c;
00624 if (c != 'A') BoxLib::Error("FABio::read_header(): expected \'A\'");
00625 is >> c;
00626 if (c != 'B') BoxLib::Error("FABio::read_header(): expected \'B\'");
00627
00628 is >> c;
00629 if (c == ':')
00630 {
00631
00632
00633
00634 int typ_in, wrd_in;
00635 is >> typ_in;
00636 is >> wrd_in;
00637
00638 char machine[128];
00639 is >> machine;
00640 is >> bx;
00641 is >> nvar;
00642 nCompAvailable = nvar;
00643 nvar = 1;
00644
00645
00646
00647 f.resize(bx,nvar);
00648 is.ignore(BL_IGNORE_MAX, '\n');
00649 switch (typ_in)
00650 {
00651 case FABio::FAB_ASCII: fio = new FABio_ascii; break;
00652 case FABio::FAB_8BIT: fio = new FABio_8bit; break;
00653 case FABio::FAB_NATIVE:
00654 case FABio::FAB_IEEE:
00655 rd = RealDescriptor::newRealDescriptor(typ_in,
00656 wrd_in,
00657 machine,
00658 FArrayBox::ordering);
00659 fio = new FABio_binary(rd);
00660 break;
00661 default:
00662 BoxLib::Error("FABio::read_header(): Unrecognized FABio header");
00663 }
00664 }
00665 else
00666 {
00667
00668
00669
00670 is.putback(c);
00671 rd = new RealDescriptor;
00672 is >> *rd;
00673 is >> bx;
00674 is >> nvar;
00675 nCompAvailable = nvar;
00676 nvar = 1;
00677
00678
00679
00680 f.resize(bx,nvar);
00681 is.ignore(BL_IGNORE_MAX, '\n');
00682 fio = new FABio_binary(rd);
00683 }
00684
00685 if (is.fail())
00686 BoxLib::Error("FABio::read_header() failed");
00687
00688 return fio;
00689 }
00690
00691 void
00692 FArrayBox::writeOn (std::ostream& os,
00693 int comp,
00694 int num_comp) const
00695 {
00696 BL_ASSERT(comp >= 0 && num_comp >= 1 && (comp+num_comp) <= nComp());
00697 fabio->write_header(os, *this, num_comp);
00698 fabio->write(os, *this, comp, num_comp);
00699 }
00700
00701 void
00702 FArrayBox::readFrom (std::istream& is)
00703 {
00704 FABio* fabrd = FABio::read_header(is, *this);
00705 fabrd->read(is, *this);
00706 delete fabrd;
00707 }
00708
00709
00710 int
00711 FArrayBox::readFrom (std::istream& is, int compIndex)
00712 {
00713 int nCompAvailable;
00714 FABio* fabrd = FABio::read_header(is, *this, compIndex, nCompAvailable);
00715 BL_ASSERT(compIndex >= 0 && compIndex < nCompAvailable);
00716
00717 fabrd->skip(is, *this, compIndex);
00718 fabrd->read(is, *this);
00719 int remainingComponents = nCompAvailable - compIndex - 1;
00720 fabrd->skip(is, *this, remainingComponents);
00721
00722 delete fabrd;
00723 return nCompAvailable;
00724 }
00725
00726
00727 Box
00728 FArrayBox::skipFAB (std::istream& is,
00729 int& num_comp)
00730 {
00731 FArrayBox f;
00732 FABio* fabrd = FABio::read_header(is, f);
00733 fabrd->skip(is, f);
00734 delete fabrd;
00735 num_comp = f.nComp();
00736 return f.box();
00737 }
00738
00739 void
00740 FABio_ascii::write (std::ostream& os,
00741 const FArrayBox& f,
00742 int comp,
00743 int num_comp) const
00744 {
00745 BL_ASSERT(comp >= 0 && num_comp >= 1 && (comp+num_comp) <= f.nComp());
00746
00747 const Box& bx = f.box();
00748
00749 IntVect sm = bx.smallEnd();
00750 IntVect bg = bx.bigEnd();
00751
00752 for (IntVect p = sm; p <= bg; bx.next(p))
00753 {
00754 os << p;
00755 for (int k=0; k < num_comp; k++)
00756 os << " " << f(p,k+comp);
00757 os << '\n';
00758 }
00759 os << '\n';
00760
00761 if (os.fail())
00762 BoxLib::Error("FABio_ascii::write() failed");
00763 }
00764
00765 void
00766 FABio_ascii::read (std::istream& is,
00767 FArrayBox& f) const
00768 {
00769 const Box& bx = f.box();
00770
00771 IntVect sm = bx.smallEnd();
00772 IntVect bg = bx.bigEnd();
00773 IntVect p, q;
00774 for (p = sm; p <= bg; bx.next(p))
00775 {
00776 is >> q;
00777 if (p != q)
00778 {
00779 std::cerr << "Error: read IntVect "
00780 << q
00781 << " should be "
00782 << p
00783 << '\n';
00784 BoxLib::Error("FABio_ascii::read() bad IntVect");
00785 }
00786 for (int k = 0; k < f.nComp(); k++)
00787 is >> f(p, k);
00788 }
00789
00790 if (is.fail())
00791 BoxLib::Error("FABio_ascii::read() failed");
00792 }
00793
00794 void
00795 FABio_ascii::skip (std::istream& is,
00796 FArrayBox& f) const
00797 {
00798 FABio_ascii::read(is, f);
00799 }
00800
00801 void
00802 FABio_ascii::skip (std::istream& is,
00803 FArrayBox& f,
00804 int nCompToSkip) const
00805 {
00806 BoxLib::Error("FABio_ascii::skip(..., int nCompToSkip) not implemented");
00807 }
00808
00809 void
00810 FABio_ascii::write_header (std::ostream& os,
00811 const FArrayBox& f,
00812 int nvar) const
00813 {
00814 os << "FAB: "
00815 << FABio::FAB_ASCII
00816 << ' '
00817 << 0
00818 << ' '
00819 << sys_name
00820 << '\n';
00821 FABio::write_header(os, f, nvar);
00822 }
00823
00824 void
00825 FABio_8bit::write (std::ostream& os,
00826 const FArrayBox& f,
00827 int comp,
00828 int num_comp) const
00829 {
00830 BL_ASSERT(comp >= 0 && num_comp >= 1 && (comp+num_comp) <= f.nComp());
00831
00832 const Real eps = Real(1.0e-8);
00833 const long siz = f.box().numPts();
00834
00835 unsigned char* c = new unsigned char[siz];
00836
00837 for (int k = 0; k < num_comp; k++)
00838 {
00839 const Real mn = f.min(k+comp);
00840 const Real mx = f.max(k+comp);
00841 const Real* dat = f.dataPtr(k+comp);
00842 Real rng = std::abs(mx-mn);
00843 rng = (rng < eps) ? 0.0 : 255.0/(mx-mn);
00844 for (long i = 0; i < siz; i++)
00845 {
00846 Real v = rng*(dat[i]-mn);
00847 int iv = (int) v;
00848 c[i] = (unsigned char) iv;
00849 }
00850 os << mn << " " << mx << '\n' << siz << '\n';
00851 os.write((char*)c,siz);
00852 }
00853
00854 delete [] c;
00855
00856 if (os.fail())
00857 BoxLib::Error("FABio_8bit::write() failed");
00858 }
00859
00860 void
00861 FABio_8bit::read (std::istream& is,
00862 FArrayBox& f) const
00863 {
00864 long siz = f.box().numPts();
00865 unsigned char* c = new unsigned char[siz];
00866
00867 Real mn, mx;
00868 for (int nbytes, k = 0; k < f.nComp(); k++)
00869 {
00870 is >> mn >> mx >> nbytes;
00871 BL_ASSERT(nbytes == siz);
00872 while (is.get() != '\n')
00873 ;
00874 is.read((char*)c,siz);
00875 Real* dat = f.dataPtr(k);
00876 const Real rng = (mx-mn)/255.0;
00877 for (long i = 0; i < siz; i++)
00878 {
00879 int iv = (int) c[i];
00880 Real v = (Real) iv;
00881 dat[i] = mn + rng*v;
00882 }
00883 }
00884 if (is.fail())
00885 BoxLib::Error("FABio_8bit::read() failed");
00886
00887 delete [] c;
00888 }
00889
00890 void
00891 FABio_8bit::skip (std::istream& is,
00892 FArrayBox& f) const
00893 {
00894 const Box& bx = f.box();
00895 long siz = bx.numPts();
00896 Real mn, mx;
00897 for (int nbytes, k = 0; k < f.nComp(); k++)
00898 {
00899 is >> mn >> mx >> nbytes;
00900 BL_ASSERT(nbytes == siz);
00901 while (is.get() != '\n')
00902 ;
00903 is.seekg(siz, std::ios::cur);
00904 }
00905
00906 if (is.fail())
00907 BoxLib::Error("FABio_8bit::skip() failed");
00908 }
00909
00910 void
00911 FABio_8bit::skip (std::istream& is,
00912 FArrayBox& f,
00913 int nCompToSkip) const
00914 {
00915 const Box& bx = f.box();
00916 long siz = bx.numPts();
00917 Real mn, mx;
00918 for (int nbytes, k = 0; k < nCompToSkip; k++)
00919 {
00920 is >> mn >> mx >> nbytes;
00921 BL_ASSERT(nbytes == siz);
00922 while (is.get() != '\n')
00923 ;
00924 is.seekg(siz, std::ios::cur);
00925 }
00926
00927 if (is.fail())
00928 BoxLib::Error("FABio_8bit::skip() failed");
00929 }
00930
00931 void
00932 FABio_8bit::write_header (std::ostream& os,
00933 const FArrayBox& f,
00934 int nvar) const
00935 {
00936 os << "FAB: " << FABio::FAB_8BIT << ' ' << 0 << ' ' << sys_name << '\n';
00937 FABio::write_header(os, f, nvar);
00938 }
00939
00940 FABio_binary::FABio_binary (RealDescriptor* rd_)
00941 :
00942 rd(rd_)
00943 {}
00944
00945 void
00946 FABio_binary::write_header (std::ostream& os,
00947 const FArrayBox& f,
00948 int nvar) const
00949 {
00950 os << "FAB " << *rd;
00951 FABio::write_header(os, f, nvar);
00952 }
00953
00954 void
00955 FABio_binary::read (std::istream& is,
00956 FArrayBox& f) const
00957 {
00958 const long base_siz = f.box().numPts();
00959 Real* comp_ptr = f.dataPtr(0);
00960 const long siz = base_siz*f.nComp();
00961 RealDescriptor::convertToNativeFormat(comp_ptr, siz, is, *rd);
00962 if (is.fail())
00963 BoxLib::Error("FABio_binary::read() failed");
00964 }
00965
00966 void
00967 FABio_binary::write (std::ostream& os,
00968 const FArrayBox& f,
00969 int comp,
00970 int num_comp) const
00971 {
00972 BL_ASSERT(comp >= 0 && num_comp >= 1 && (comp+num_comp) <= f.nComp());
00973
00974 const long base_siz = f.box().numPts();
00975 const Real* comp_ptr = f.dataPtr(comp);
00976 const long siz = base_siz*num_comp;
00977 RealDescriptor::convertFromNativeFormat(os, siz, comp_ptr, *rd);
00978
00979 if (os.fail())
00980 BoxLib::Error("FABio_binary::write() failed");
00981 }
00982
00983 void
00984 FABio_binary::skip (std::istream& is,
00985 FArrayBox& f) const
00986 {
00987 const Box& bx = f.box();
00988 long base_siz = bx.numPts();
00989 long siz = base_siz * f.nComp();
00990 is.seekg(siz*rd->numBytes(), std::ios::cur);
00991 if (is.fail())
00992 BoxLib::Error("FABio_binary::skip() failed");
00993 }
00994
00995 void
00996 FABio_binary::skip (std::istream& is,
00997 FArrayBox& f,
00998 int nCompToSkip) const
00999 {
01000 const Box& bx = f.box();
01001 long base_siz = bx.numPts();
01002 long siz = base_siz * nCompToSkip;
01003 is.seekg(siz*rd->numBytes(), std::ios::cur);
01004 if (is.fail())
01005 BoxLib::Error("FABio_binary::skip(..., int nCompToSkip) failed");
01006 }
01007
01008 std::ostream&
01009 operator<< (std::ostream& os,
01010 const FArrayBox& f)
01011 {
01012 static FABio_ascii fabio_ascii;
01013 fabio_ascii.write(os,f,0,f.nComp());
01014 return os;
01015 }
01016
01017 std::istream&
01018 operator>> (std::istream& is,
01019 FArrayBox& f)
01020 {
01021 FABio* fabrd = FABio::read_header(is,f);
01022 fabrd->read(is,f);
01023 delete fabrd;
01024 return is;
01025 }
01026