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
00027 #include <winstd.H>
00028
00029 #if defined(BL_OLD_STL)
00030 #include <stdio.h>
00031 #else
00032 #include <cstdio>
00033 #endif
00034
00035 #include <fstream>
00036
00037
00038
00039
00040 #ifdef BL_USE_SETBUF
00041 #define pubsetbuf setbuf
00042 #endif
00043
00044 #include <ccse-mpi.H>
00045 #include <Utility.H>
00046 #include <VisMF.H>
00047
00048 const std::string VisMF::FabFileSuffix("_D_");
00049 const std::string VisMF::MultiFabHdrFileSuffix("_H");
00050 const std::string VisMF::FabOnDisk::Prefix("FabOnDisk:");
00051
00052 std::ostream&
00053 operator<< (std::ostream& os,
00054 const VisMF::FabOnDisk& fod)
00055 {
00056 os << VisMF::FabOnDisk::Prefix << ' ' << fod.m_name << ' ' << fod.m_head;
00057
00058 if (!os.good())
00059 BoxLib::Error("Write of VisMF::FabOnDisk failed");
00060
00061 return os;
00062 }
00063
00064 std::istream&
00065 operator>> (std::istream& is,
00066 VisMF::FabOnDisk& fod)
00067 {
00068 std::string str;
00069 is >> str;
00070
00071 BL_ASSERT(str == VisMF::FabOnDisk::Prefix);
00072
00073 is >> fod.m_name;
00074 is >> fod.m_head;
00075
00076 if (!is.good())
00077 BoxLib::Error("Read of VisMF::FabOnDisk failed");
00078
00079 return is;
00080 }
00081
00082 std::ostream&
00083 operator<< (std::ostream& os,
00084 const Array<VisMF::FabOnDisk>& fa)
00085 {
00086 long i = 0, N = fa.size();
00087
00088 os << N << '\n';
00089
00090 for ( ; i < N; i++)
00091 {
00092 os << fa[i] << '\n';
00093 }
00094
00095 if (!os.good())
00096 BoxLib::Error("Write of Array<VisMF::FabOnDisk> failed");
00097
00098 return os;
00099 }
00100
00101 std::istream&
00102 operator>> (std::istream& is,
00103 Array<VisMF::FabOnDisk>& fa)
00104 {
00105 long i = 0, N;
00106
00107 is >> N;
00108 BL_ASSERT(N >= 0);
00109
00110 fa.resize(N);
00111
00112 for ( ; i < N; i++)
00113 {
00114 is >> fa[i];
00115 }
00116
00117 if (!is.good())
00118 BoxLib::Error("Read of Array<VisMF::FabOnDisk> failed");
00119
00120 return is;
00121 }
00122
00123 static
00124 std::ostream&
00125 operator<< (std::ostream& os,
00126 const Array< Array<Real> >& ar)
00127 {
00128 long i = 0, N = ar.size(), M = (N == 0) ? 0 : ar[0].size();
00129
00130 os << N << ',' << M << '\n';
00131
00132 for ( ; i < N; i++)
00133 {
00134 BL_ASSERT(ar[i].size() == M);
00135
00136 for (long j = 0; j < M; j++)
00137 {
00138 os << ar[i][j] << ',';
00139 }
00140 os << '\n';
00141 }
00142
00143 if (!os.good())
00144 BoxLib::Error("Write of Array<Array<Real>> failed");
00145
00146 return os;
00147 }
00148
00149 static
00150 std::istream&
00151 operator>> (std::istream& is,
00152 Array< Array<Real> >& ar)
00153 {
00154 char ch;
00155 long i = 0, N, M;
00156
00157 is >> N >> ch >> M;
00158
00159 BL_ASSERT(N >= 0);
00160 BL_ASSERT(ch == ',');
00161 BL_ASSERT(M >= 0);
00162
00163 ar.resize(N);
00164
00165 for ( ; i < N; i++)
00166 {
00167 ar[i].resize(M);
00168
00169 for (long j = 0; j < M; j++)
00170 {
00171 is >> ar[i][j] >> ch;
00172 BL_ASSERT(ch == ',');
00173 }
00174 }
00175
00176 if (!is.good())
00177 BoxLib::Error("Read of Array<Array<Real>> failed");
00178
00179 return is;
00180 }
00181
00182 std::ostream&
00183 operator<< (std::ostream& os,
00184 const VisMF::Header& hd)
00185 {
00186
00187
00188
00189 int old_prec = os.precision(15);
00190
00191 os << hd.m_vers << '\n';
00192 os << int(hd.m_how) << '\n';
00193 os << hd.m_ncomp << '\n';
00194 os << hd.m_ngrow << '\n';
00195
00196 hd.m_ba.writeOn(os); os << '\n';
00197
00198 os << hd.m_fod << '\n';
00199 os << hd.m_min << '\n';
00200 os << hd.m_max << '\n';
00201
00202 os.precision(old_prec);
00203
00204 if (!os.good())
00205 BoxLib::Error("Write of VisMF::Header failed");
00206
00207 return os;
00208 }
00209
00210 std::istream&
00211 operator>> (std::istream& is,
00212 VisMF::Header& hd)
00213 {
00214 is >> hd.m_vers;
00215 BL_ASSERT(hd.m_vers == VisMF::Header::Version);
00216
00217 int how;
00218 is >> how;
00219 switch (how)
00220 {
00221 case VisMF::OneFilePerCPU:
00222 hd.m_how = VisMF::OneFilePerCPU; break;
00223 default:
00224 BoxLib::Error("Bad case in switch");
00225 }
00226
00227 is >> hd.m_ncomp;
00228 BL_ASSERT(hd.m_ncomp >= 0);
00229
00230 is >> hd.m_ngrow;
00231 BL_ASSERT(hd.m_ngrow >= 0);
00232
00233 hd.m_ba.readFrom(is);
00234
00235 is >> hd.m_fod;
00236 BL_ASSERT(hd.m_ba.size() == hd.m_fod.size());
00237
00238 is >> hd.m_min;
00239 is >> hd.m_max;
00240
00241 BL_ASSERT(hd.m_ba.size() == hd.m_min.size());
00242 BL_ASSERT(hd.m_ba.size() == hd.m_max.size());
00243
00244 if (!is.good())
00245 BoxLib::Error("Read of VisMF::Header failed");
00246
00247 return is;
00248 }
00249
00250 VisMF::FabOnDisk::FabOnDisk () {}
00251
00252 VisMF::FabOnDisk::FabOnDisk (const std::string& name, long offset)
00253 :
00254 m_name(name),
00255 m_head(offset)
00256 {}
00257
00258 int
00259 VisMF::nComp () const
00260 {
00261 return m_hdr.m_ncomp;
00262 }
00263
00264 int
00265 VisMF::nGrow () const
00266 {
00267 return m_hdr.m_ngrow;
00268 }
00269
00270 int
00271 VisMF::size () const
00272 {
00273 return m_hdr.m_ba.size();
00274 }
00275
00276 const BoxArray&
00277 VisMF::boxArray () const
00278 {
00279 return m_hdr.m_ba;
00280 }
00281
00282 Real
00283 VisMF::min (int fabIndex,
00284 int nComp) const
00285 {
00286 BL_ASSERT(0 <= fabIndex && fabIndex < m_hdr.m_ba.size());
00287 BL_ASSERT(0 <= nComp && nComp < m_hdr.m_ncomp);
00288 return m_hdr.m_min[fabIndex][nComp];
00289 }
00290
00291 Real
00292 VisMF::max (int fabIndex,
00293 int nComp) const
00294 {
00295 BL_ASSERT(0 <= fabIndex && fabIndex < m_hdr.m_ba.size());
00296 BL_ASSERT(0 <= nComp && nComp < m_hdr.m_ncomp);
00297 return m_hdr.m_max[fabIndex][nComp];
00298 }
00299
00300 const FArrayBox&
00301 VisMF::GetFab (int fabIndex,
00302 int ncomp) const
00303 {
00304 if (m_pa[ncomp][fabIndex] == 0)
00305 {
00306 m_pa[ncomp][fabIndex] = VisMF::readFAB(fabIndex,m_mfname,m_hdr,ncomp);
00307 }
00308 return *m_pa[ncomp][fabIndex];
00309 }
00310
00311 void
00312 VisMF::clear (int fabIndex,
00313 int compIndex)
00314 {
00315 delete m_pa[compIndex][fabIndex];
00316 }
00317
00318 long
00319 VisMF::FileOffset (std::ostream& os)
00320 {
00321 return
00322 #if defined(__KCC)
00323 #if ((BL_KCC_MAJOR_VERSION >= 4) || (BL_KCC_MAJOR_VERSION == 3 && BL_KCC_MINOR_VERSION > 3))
00324 os.tellp();
00325 #else
00326 os.tellp().offset();
00327 #endif
00328 #else
00329 os.tellp();
00330 #endif
00331 }
00332
00333 FArrayBox*
00334 VisMF::readFAB (int idx,
00335 const std::string& mf_name)
00336 {
00337 return VisMF::readFAB(idx,mf_name,m_hdr,-1);
00338 }
00339
00340 FArrayBox*
00341 VisMF::readFAB (int idx,
00342 int ncomp)
00343 {
00344 return VisMF::readFAB(idx,m_mfname,m_hdr,ncomp);
00345 }
00346
00347 std::string
00348 VisMF::BaseName (const std::string& filename)
00349 {
00350 char slashchar='/';
00351 BL_ASSERT(filename[filename.length() - 1] != slashchar);
00352
00353 const char* slash=strrchr(filename.c_str(), slashchar);
00354 if (slash)
00355 {
00356
00357
00358
00359 return std::string(slash + 1);
00360 }
00361 else
00362 {
00363
00364
00365
00366 return filename;
00367 }
00368 }
00369
00370 std::string
00371 VisMF::DirName (const std::string& filename)
00372 {
00373 char slashchar='/';
00374 BL_ASSERT(filename[filename.length() - 1] != slashchar);
00375
00376 static const std::string TheNullString("");
00377
00378 const char* str = filename.c_str();
00379
00380 const char* slash = strrchr(str, slashchar);
00381 if (slash)
00382 {
00383
00384
00385
00386 int len = (slash - str) + 1;
00387
00388 char* buf = new char[len+1];
00389
00390 strncpy(buf, str, len);
00391
00392 buf[len] = 0;
00393
00394 std::string dirname = buf;
00395
00396 delete [] buf;
00397
00398 return dirname;
00399 }
00400 else
00401 {
00402
00403
00404
00405 return TheNullString;
00406 }
00407 }
00408
00409 VisMF::FabOnDisk
00410 VisMF::Write (const FArrayBox& fab,
00411 const std::string& filename,
00412 std::ostream& os,
00413 long& bytes)
00414 {
00415 VisMF::FabOnDisk fab_on_disk(filename, VisMF::FileOffset(os));
00416
00417 fab.writeOn(os);
00418
00419
00420
00421 bytes += (VisMF::FileOffset(os) - fab_on_disk.m_head);
00422
00423 return fab_on_disk;
00424 }
00425
00426
00427
00428
00429
00430 VisMF::Header::Header ()
00431 :
00432 m_vers(0)
00433 {}
00434
00435
00436
00437
00438
00439 VisMF::Header::Header (const MultiFab& mf,
00440 VisMF::How how)
00441 :
00442 m_vers(VisMF::Header::Version),
00443 m_how(how),
00444 m_ncomp(mf.nComp()),
00445 m_ngrow(mf.nGrow()),
00446 m_ba(mf.boxArray()),
00447 m_fod(m_ba.size()),
00448 m_min(m_ba.size()),
00449 m_max(m_ba.size())
00450 {
00451 #ifdef BL_USE_MPI
00452
00453
00454
00455
00456 const int SeqNo = ParallelDescriptor::SeqNum();
00457 const int NProcs = ParallelDescriptor::NProcs();
00458 const int IOProc = ParallelDescriptor::IOProcessorNumber();
00459
00460 int nFabs = 0;
00461
00462 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00463 {
00464 nFabs++;
00465
00466 const int idx = mfi.index();
00467
00468 m_min[idx].resize(m_ncomp);
00469 m_max[idx].resize(m_ncomp);
00470
00471 BL_ASSERT(mf[mfi].box().contains(m_ba[idx]));
00472
00473 for (long j = 0; j < m_ncomp; j++)
00474 {
00475 m_min[idx][j] = mf[mfi].min(m_ba[idx],j);
00476 m_max[idx][j] = mf[mfi].max(m_ba[idx],j);
00477 }
00478 }
00479
00480 if (!ParallelDescriptor::IOProcessor())
00481 {
00482 if (nFabs)
00483 {
00484 Array<Real> senddata(2*m_ncomp*nFabs);
00485
00486 int offset = 0;
00487
00488 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00489 {
00490 const int idx = mfi.index();
00491
00492 for (int i = 0; i < m_ncomp; i++)
00493 {
00494 senddata[offset+i] = m_min[idx][i];
00495 senddata[offset+m_ncomp+i] = m_max[idx][i];
00496 }
00497
00498 offset += 2*m_ncomp;
00499 }
00500
00501 BL_ASSERT(offset == 2*m_ncomp*nFabs);
00502
00503 BL_MPI_REQUIRE( MPI_Send(senddata.dataPtr(),
00504 2*m_ncomp*nFabs,
00505 ParallelDescriptor::Mpi_typemap<Real>::type(),
00506 IOProc,
00507 SeqNo,
00508 ParallelDescriptor::Communicator()) );
00509
00510 BL_ASSERT(offset == 2*m_ncomp*nFabs);
00511 }
00512 }
00513 else
00514 {
00515 const Array<int>& procmap = mf.DistributionMap().ProcessorMap();
00516
00517 Array<int> fabs(NProcs,0);
00518 Array<int> indx(NProcs);
00519 Array<MPI_Request> reqs(NProcs,MPI_REQUEST_NULL);
00520 Array<MPI_Status> status(NProcs);
00521 Array< Array<Real> > data(NProcs);
00522
00523 for (int i = 0, N = procmap.size(); i < N; i++)
00524 fabs[procmap[i]]++;
00525
00526 fabs[IOProc] = 0;
00527
00528 int NWaits = 0;
00529
00530 for (int i = 0; i < NProcs; i++)
00531 {
00532 if (fabs[i])
00533 {
00534 NWaits++;
00535
00536 data[i].resize(2*m_ncomp*fabs[i]);
00537
00538 BL_MPI_REQUIRE( MPI_Irecv(data[i].dataPtr(),
00539 2*m_ncomp*fabs[i],
00540 ParallelDescriptor::Mpi_typemap<Real>::type(),
00541 i,
00542 SeqNo,
00543 ParallelDescriptor::Communicator(),
00544 &reqs[i]) );
00545 }
00546 }
00547
00548 for (int completed; NWaits > 0; NWaits -= completed)
00549 {
00550 BL_MPI_REQUIRE( MPI_Waitsome(NProcs,
00551 reqs.dataPtr(),
00552 &completed,
00553 indx.dataPtr(),
00554 status.dataPtr()) );
00555
00556 for (int k = 0; k < completed; k++)
00557 {
00558 int Ncpu = indx[k], offset = 0;
00559
00560 for (int idx = 0, N = procmap.size(); idx < N; idx++)
00561 {
00562 if (procmap[idx] == Ncpu)
00563 {
00564 m_min[idx].resize(m_ncomp);
00565 m_max[idx].resize(m_ncomp);
00566
00567 for (int i = 0; i < m_ncomp; i++)
00568 {
00569 m_min[idx][i] = data[Ncpu][offset+i];
00570 m_max[idx][i] = data[Ncpu][offset+m_ncomp+i];
00571 }
00572
00573 offset += 2*m_ncomp;
00574 }
00575 }
00576
00577 BL_ASSERT(offset == 2*m_ncomp*fabs[Ncpu]);
00578 }
00579 }
00580 }
00581 #else
00582 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00583 {
00584 const int idx = mfi.index();
00585
00586 m_min[idx].resize(m_ncomp);
00587 m_max[idx].resize(m_ncomp);
00588
00589 BL_ASSERT(mf[mfi].box().contains(m_ba[idx]));
00590
00591 for (long j = 0; j < m_ncomp; j++)
00592 {
00593 m_min[idx][j] = mf[mfi].min(m_ba[idx],j);
00594 m_max[idx][j] = mf[mfi].max(m_ba[idx],j);
00595 }
00596 }
00597 #endif
00598 }
00599
00600 long
00601 VisMF::WriteHeader (const std::string& mf_name,
00602 VisMF::Header& hdr)
00603 {
00604 long bytes = 0;
00605
00606
00607
00608 if (ParallelDescriptor::IOProcessor())
00609 {
00610 std::string MFHdrFileName = mf_name;
00611
00612 MFHdrFileName += VisMF::MultiFabHdrFileSuffix;
00613
00614 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
00615
00616 std::ofstream MFHdrFile;
00617
00618 MFHdrFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
00619
00620 MFHdrFile.open(MFHdrFileName.c_str(), std::ios::out|std::ios::trunc);
00621
00622 if (!MFHdrFile.good())
00623 BoxLib::FileOpenFailed(MFHdrFileName);
00624
00625 MFHdrFile << hdr;
00626
00627
00628
00629 bytes += VisMF::FileOffset(MFHdrFile);
00630 }
00631 return bytes;
00632 }
00633
00634 long
00635 VisMF::Write (const MultiFab& mf,
00636 const std::string& mf_name,
00637 VisMF::How how,
00638 bool set_ghost)
00639 {
00640 BL_ASSERT(mf_name[mf_name.length() - 1] != '/');
00641
00642 const int MyProc = ParallelDescriptor::MyProc();
00643
00644 long bytes = 0;
00645
00646 VisMF::Header hdr(mf, how);
00647
00648 if (set_ghost)
00649 {
00650 MultiFab* the_mf = const_cast<MultiFab*>(&mf);
00651
00652 BL_ASSERT(!(the_mf == 0));
00653 BL_ASSERT(hdr.m_ba == mf.boxArray());
00654 BL_ASSERT(hdr.m_ncomp == mf.nComp());
00655
00656 for (MFIter mfi(*the_mf); mfi.isValid(); ++mfi)
00657 {
00658 const int idx = mfi.index();
00659
00660 for (int j = 0; j < hdr.m_ncomp; j++)
00661 {
00662 const Real val = (hdr.m_min[idx][j] + hdr.m_max[idx][j]) / 2;
00663
00664 the_mf->get(mfi).setComplement(val, hdr.m_ba[idx], j, 1);
00665 }
00666 }
00667 }
00668
00669 char buf[sizeof(int) + 1];
00670
00671 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
00672
00673 std::string FullFileName = mf_name;
00674
00675 FullFileName += VisMF::FabFileSuffix;
00676 sprintf(buf, "%04d", MyProc);
00677 FullFileName += buf;
00678
00679 std::ofstream FabFile;
00680
00681 FabFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
00682
00683 FabFile.open(FullFileName.c_str(), std::ios::out|std::ios::trunc|std::ios::binary);
00684
00685 if (!FabFile.good())
00686 BoxLib::FileOpenFailed(FullFileName);
00687
00688 std::string basename = VisMF::BaseName(FullFileName);
00689
00690 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00691 hdr.m_fod[mfi.index()] = VisMF::Write(mf[mfi],basename,FabFile,bytes);
00692
00693 #ifdef BL_USE_MPI
00694 const int SeqNo = ParallelDescriptor::SeqNum();
00695 const int NProcs = ParallelDescriptor::NProcs();
00696 const int IOProc = ParallelDescriptor::IOProcessorNumber();
00697
00698 if (!ParallelDescriptor::IOProcessor())
00699 {
00700 int nFabs = 0, idx = 0;
00701
00702 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00703 nFabs++;
00704
00705 if (nFabs)
00706 {
00707 Array<long> senddata(nFabs);
00708
00709 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00710 senddata[idx++] = hdr.m_fod[mfi.index()].m_head;
00711
00712 BL_MPI_REQUIRE( MPI_Send(senddata.dataPtr(),
00713 nFabs,
00714 MPI_LONG,
00715 IOProc,
00716 SeqNo,
00717 ParallelDescriptor::Communicator()));
00718 }
00719
00720 BL_ASSERT(idx == nFabs);
00721 }
00722 else
00723 {
00724 const Array<int>& procmap = mf.DistributionMap().ProcessorMap();
00725
00726 Array<int> fabs(NProcs,0);
00727 Array<int> indx(NProcs);
00728 Array<MPI_Request> reqs(NProcs,MPI_REQUEST_NULL);
00729 Array<MPI_Status> status(NProcs);
00730 Array< Array<long> > data(NProcs);
00731
00732 for (int i = 0, N = procmap.size(); i < N; i++)
00733 fabs[procmap[i]]++;
00734
00735 fabs[IOProc] = 0;
00736
00737 int NWaits = 0;
00738
00739 for (int i = 0; i < NProcs; i++)
00740 {
00741 if (fabs[i])
00742 {
00743 NWaits++;
00744
00745 data[i].resize(fabs[i]);
00746
00747 BL_MPI_REQUIRE( MPI_Irecv(data[i].dataPtr(),
00748 fabs[i],
00749 MPI_LONG,
00750 i,
00751 SeqNo,
00752 ParallelDescriptor::Communicator(),
00753 &reqs[i]));
00754 }
00755 }
00756
00757 for (int completed; NWaits > 0; NWaits -= completed)
00758 {
00759 BL_MPI_REQUIRE( MPI_Waitsome(NProcs,
00760 reqs.dataPtr(),
00761 &completed,
00762 indx.dataPtr(),
00763 status.dataPtr()));
00764
00765 for (int k = 0; k < completed; k++)
00766 {
00767 int Ncpu = indx[k], offset = 0;
00768
00769 for (int idx = 0, N = procmap.size(); idx < N; idx++)
00770 {
00771 if (procmap[idx] == Ncpu)
00772 {
00773 hdr.m_fod[idx].m_head = data[Ncpu][offset++];
00774
00775 std::string name = mf_name;
00776
00777 name += VisMF::FabFileSuffix;
00778 sprintf(buf, "%04d", Ncpu);
00779 name += buf;
00780
00781 hdr.m_fod[idx].m_name = VisMF::BaseName(name);
00782 }
00783 }
00784
00785 BL_ASSERT(offset == fabs[Ncpu]);
00786 }
00787 }
00788 }
00789 #endif
00790
00791 if (VisMF::FileOffset(FabFile) <= 0)
00792 BoxLib::UnlinkFile(FullFileName);
00793
00794 bytes += VisMF::WriteHeader(mf_name, hdr);
00795
00796 return bytes;
00797 }
00798
00799 VisMF::VisMF (const std::string& mf_name)
00800 :
00801 m_mfname(mf_name)
00802 {
00803 std::string FullHdrFileName = m_mfname;
00804
00805 FullHdrFileName += VisMF::MultiFabHdrFileSuffix;
00806
00807 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
00808
00809 std::ifstream ifs;
00810
00811 ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
00812
00813 ifs.open(FullHdrFileName.c_str(), std::ios::in);
00814
00815 if (!ifs.good())
00816 BoxLib::FileOpenFailed(FullHdrFileName);
00817
00818 ifs >> m_hdr;
00819
00820 m_pa.resize(m_hdr.m_ncomp);
00821
00822 for (int nComp = 0; nComp < m_pa.size(); ++nComp)
00823 {
00824 m_pa[nComp].resize(m_hdr.m_ba.size());
00825
00826 for (int ii = 0; ii < m_pa[nComp].size(); ++ii)
00827 {
00828 m_pa[nComp][ii] = 0;
00829 }
00830 }
00831 }
00832
00833 FArrayBox*
00834 VisMF::readFAB (int idx,
00835 const std::string& mf_name,
00836 const VisMF::Header& hdr,
00837 int ncomp)
00838 {
00839 Box fab_box = hdr.m_ba[idx];
00840
00841 if (hdr.m_ngrow)
00842 fab_box.grow(hdr.m_ngrow);
00843
00844 FArrayBox* fab = new FArrayBox(fab_box, ncomp == -1 ? hdr.m_ncomp : 1);
00845
00846 std::string FullFileName = VisMF::DirName(mf_name);
00847
00848 FullFileName += hdr.m_fod[idx].m_name;
00849
00850 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
00851
00852 std::ifstream ifs;
00853
00854 ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
00855
00856 ifs.open(FullFileName.c_str(), std::ios::in|std::ios::binary);
00857
00858 if (!ifs.good())
00859 BoxLib::FileOpenFailed(FullFileName);
00860
00861 if (hdr.m_fod[idx].m_head)
00862 ifs.seekg(hdr.m_fod[idx].m_head, std::ios::beg);
00863
00864 if (ncomp == -1)
00865 {
00866 fab->readFrom(ifs);
00867 }
00868 else
00869 {
00870 fab->readFrom(ifs, ncomp);
00871 }
00872
00873 return fab;
00874 }
00875
00876 void
00877 VisMF::Read (MultiFab& mf,
00878 const std::string& mf_name)
00879 {
00880 VisMF::Header hdr;
00881
00882 std::string FullHdrFileName = mf_name;
00883
00884 FullHdrFileName += VisMF::MultiFabHdrFileSuffix;
00885 {
00886 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
00887
00888 std::ifstream ifs;
00889
00890 ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
00891
00892 ifs.open(FullHdrFileName.c_str(), std::ios::in);
00893
00894 if (!ifs.good())
00895 BoxLib::FileOpenFailed(FullHdrFileName);
00896
00897 ifs >> hdr;
00898 }
00899 mf.define(hdr.m_ba, hdr.m_ncomp, hdr.m_ngrow, Fab_noallocate);
00900
00901 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
00902 {
00903 mf.setFab(mfi.index(), VisMF::readFAB(mfi.index(), mf_name, hdr));
00904 }
00905
00906 BL_ASSERT(mf.ok());
00907 }
00908
00909 void
00910 VisMF::clear (int fabIndex)
00911 {
00912 for (int ncomp = 0; ncomp < m_pa.size(); ++ncomp)
00913 {
00914 clear(ncomp, fabIndex);
00915 }
00916 }
00917
00918 void
00919 VisMF::clear ()
00920 {
00921 for (int ncomp = 0; ncomp < m_pa.size(); ++ncomp)
00922 {
00923 for (int fabIndex = 0; fabIndex < m_pa[ncomp].size(); ++fabIndex)
00924 {
00925 clear(ncomp, fabIndex);
00926 }
00927 }
00928 }
00929