| 144 | } |
| 145 | |
| 146 | static |
| 147 | void |
| 148 | Write (AmrData& amrData, |
| 149 | const std::string& iFile_name, |
| 150 | const std::list<std::string> plot_vars) |
| 151 | { |
| 152 | int finest_level = amrData.FinestLevel(); |
| 153 | |
| 154 | VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size); |
| 155 | |
| 156 | char buf[128]; |
| 157 | |
| 158 | for (int icomp = 0; icomp < amrData.NComp(); icomp++) |
| 159 | { |
| 160 | // |
| 161 | // Write one component per file. |
| 162 | // |
| 163 | const std::string& CompName = amrData.PlotVarNames()[icomp]; |
| 164 | if (isPlotVar(CompName)) |
| 165 | { |
| 166 | |
| 167 | std::string file = iFile_name; |
| 168 | file += '_'; |
| 169 | file += CompName; |
| 170 | file += ".mat"; |
| 171 | |
| 172 | std::ofstream os; |
| 173 | |
| 174 | os.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size()); |
| 175 | |
| 176 | os.open(file.c_str(), std::ios::out|std::ios::binary); |
| 177 | |
| 178 | if (os.fail()) { |
| 179 | amrex::FileOpenFailed(file); |
| 180 | } |
| 181 | |
| 182 | int dim = BL_SPACEDIM; |
| 183 | os.write((char*)&dim,sizeof(int)); |
| 184 | |
| 185 | int num_levels = finest_level+1; |
| 186 | os.write((char*)&num_levels,sizeof(int)); |
| 187 | |
| 188 | // Write the number of grids at each level |
| 189 | for (int iLevel = 0; iLevel <= finest_level; ++iLevel) |
| 190 | { |
| 191 | MultiFab& mf = amrData.GetGrids(iLevel,icomp); |
| 192 | const BoxArray& ba = mf.boxArray(); |
| 193 | int num_grids = ba.size(); |
| 194 | os.write((char*)&num_grids,sizeof(int)); |
| 195 | } |
| 196 | |
| 197 | // Write the (Real) physical locations of each grid at each level |
| 198 | for (int iLevel = 0; iLevel <= finest_level; ++iLevel) |
| 199 | { |
| 200 | MultiFab& mf = amrData.GetGrids(iLevel,icomp); |
| 201 | const BoxArray& ba = mf.boxArray(); |
| 202 | int num_grids = ba.size(); |
| 203 | for (int i = 0; i < num_grids; ++i) |