ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_PlotfileToNetCDF.cpp File Reference
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <AMReX_PlotFileUtil.H>
#include <AMReX_Utility.H>
#include <AMReX_MultiFab.H>
#include "ERF_NCInterface.H"
#include "ERF_NCPlotFile.H"
Include dependency graph for ERF_PlotfileToNetCDF.cpp:

Functions

static void PrintUsage ()
 
int main_main ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
142 {
143  amrex::SetVerbose(0);
144  amrex::Initialize(argc, argv, false);
145  int status = main_main();
146  amrex::Finalize();
147  return status;
148 }
int main_main()
Definition: ERF_PlotfileToNetCDF.cpp:49
Here is the call graph for this function:

◆ main_main()

int main_main ( )
50 {
51  const int narg = amrex::command_argument_count();
52 
53  if (narg == 0) {
54  PrintUsage();
55  }
56 
57  bool verbose = false;
58 
59  std::string iFile;
60  int farg = 1;
61  while (farg <= narg) {
62  const std::string fname = amrex::get_command_argument(farg);
63  if (fname == "-h" || fname == "--help") {
64  PrintUsage();
65  } else if (fname == "-v") {
66  verbose = true;
67  } else {
68  iFile = fname;
69  }
70  ++farg;
71  }
72 
73  if (iFile.empty()) {
74  amrex::Print() << "No plotfilename specified " << std::endl;
75  return 1;
76  } else {
77  // Remove trailing backslash if present
78  if (iFile.back() == '/') {
79  iFile.pop_back();
80  }
81  if (verbose) {
82  amrex::Print() << "Reading " << iFile << std::endl;
83  }
84  }
85 
86  PlotFileData pf_data(iFile);
87 
88  int finest_level = pf_data.finestLevel();
89 
90  int ncomp = pf_data.nComp();
91 
92  if (verbose) {
93  amrex::Print() << "Finished defining pf with finest level " << finest_level << " and ncomp " << ncomp << std::endl;
94  }
95 
96  const Vector<std::string>& varnames = pf_data.varNames();
97 
98  Vector<int> istep{3};
99  double time = pf_data.time();
100 
101  int max_grid_size = 64;
102 
103  Vector<MultiFab> mfvec(finest_level+1);
104  Vector<Geometry> geom(finest_level+1);
105 
106  double start_bdy_time = time;
107 
108  // A plotfile does not carry the solver configuration, and the only thing
109  // writeNCPlotFile takes from it is the mesh type. A plotfile also does not
110  // record the staggered z levels needed for a stretched mesh, so we can only
111  // write the (x,y,z) grid for a constant-dz mesh -- which is the default.
112  SolverChoice solverChoice;
113  Vector<Real> zlevels_stag;
114 
115  for (int lev = 0; lev <= finest_level; lev++)
116  {
117  mfvec[lev].define(pf_data.boxArray(lev), pf_data.DistributionMap(lev), ncomp, 0);
118 
119  for (int icomp = 0; icomp < ncomp; icomp++) {
120  MultiFab tmp_data = pf_data.get(lev, varnames[icomp]);
121  MultiFab::Copy(mfvec[lev],tmp_data,0,icomp,1,0);
122  }
123 
124  // We assume only one "subdomain" at each level that holds all the grids
125  BoxArray ba(pf_data.boxArray(lev));
126  Box bounding_region = (lev == 0) ? pf_data.probDomain(lev) : ba.minimalBox();
127 
128  // We assume only one "subdomain" at each level
129  int which = 0;
130 
131  writeNCPlotFile(lev, which, iFile, GetVecOfConstPtrs(mfvec), varnames, istep,
132  pf_data.probLo(), pf_data.probHi(), pf_data.cellSize(lev), bounding_region,
133  time, start_bdy_time, solverChoice, zlevels_stag);
134  }
135 
136  return 0;
137 }
void writeNCPlotFile(int lev, int which_subdomain, const std::string &dir, const Vector< const MultiFab * > &plotMF, const Vector< std::string > &plot_var_names, const Vector< int > &, Array< Real, AMREX_SPACEDIM > prob_lo, Array< Real, AMREX_SPACEDIM > prob_hi, Array< Real, AMREX_SPACEDIM > dx_in, const Box &subdomain, const double &time, const double &start_bdy_time, const SolverChoice &solverChoice, const Vector< Real > &zlevels_stag)
Definition: ERF_NCPlotFile.cpp:20
static void PrintUsage()
Definition: ERF_PlotfileToNetCDF.cpp:34
Definition: ERF_DataStruct.H:241

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintUsage()

static void PrintUsage ( )
static
35 {
36  amrex::Print()
37  << "\n"
38  << " Convert a multilevel AMReX-formatted plotfile into one netcdf file per level \n"
39  << "\n"
40  << " usage:\n"
41  << " main*exe [-v] plotfilename\n"
42  << "\n"
43  << " optional arguments:\n"
44  << " -v verbosity : verbose if set, otherwise silent \n";
45  exit(1);
46 }

Referenced by main_main().

Here is the caller graph for this function: