MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / main

Function main

Tools/Postprocessing/C_Src/MultiFabToMatLab.cpp:72–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70
71
72int main(int argc, char* argv[])
73{
74 amrex::Initialize(argc, argv);
75 {
76 if(argc == 1)
77 PrintUsage(argv[0]);
78
79 if (ParallelDescriptor::NProcs() > 1){
80 amrex::Error("This is an inherently serial program!");
81 }
82 ParmParse pp;
83
84 std::string name;
85 pp.get("infile", name);
86
87 //
88 // MatLab expects native floating-point format.
89 //
90 FArrayBox::setFormat(FABio::FAB_NATIVE);
91
92 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
93 char buf[128];
94 std::string file = name;
95 file += ".mat";
96 std::ofstream os;
97
98 os.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
99
100 os.open(file.c_str(), std::ios::out|std::ios::binary);
101
102 if(os.fail()) {
103 amrex::FileOpenFailed(file);
104 }
105
106
107 MultiFab in;
108 VisMF::Read(in, name);
109 const BoxArray ba = in.boxArray();
110
111 //Fake a xlo to xhi
112 for(int i = 0; i < ba.size(); ++i)
113 {
114 const Box& b = ba[i];
115 Real xlo[BL_SPACEDIM], xhi[BL_SPACEDIM];
116 for(int d = 0; d <BL_SPACEDIM; ++d)
117 {
118 xlo[d] = b.loVect()[d];
119 xhi[d] = b.hiVect()[d];
120 os.write((char*)&xlo,sizeof(Real));
121 os.write((char*)&xhi,sizeof(Real));
122 }
123 }
124 //Write the Fab Data
125 for(int i = 0; i < ba.size(); ++i)
126 {
127 WriteFab(os, in[i], buf);
128 }
129 os.close();

Callers

nothing calls this directly

Calls 13

ReadFunction · 0.85
loVectMethod · 0.80
hiVectMethod · 0.80
PrintUsageFunction · 0.70
WriteFabFunction · 0.70
InitializeFunction · 0.50
NProcsFunction · 0.50
FinalizeFunction · 0.50
getMethod · 0.45
dataPtrMethod · 0.45
sizeMethod · 0.45
boxArrayMethod · 0.45

Tested by

no test coverage detected