16 #include "eckit/config/Configuration.h"
17 #include "eckit/exception/Exceptions.h"
19 #include "oops/mpi/mpi.h"
20 #include "oops/util/abor1_cpp.h"
21 #include "oops/util/Logger.h"
32 void stageFMSFiles(
const eckit::Configuration & conf,
const eckit::mpi::Comm & comm) {
34 int world_rank = oops::mpi::world().rank();
36 if (world_rank == 0) {
39 if (conf.has(
"nml_file_mpp")) {
40 oops::Log::debug() <<
"Staging input.nml" << std::endl;
41 std::string nml_file = conf.getString(
"nml_file_mpp");
42 if (symlink(nml_file.c_str(),
"./input.nml"))
43 ABORT(
"Unable to symlink input.nml");
45 ABORT(
"nml_file_mpp not in configuration");
49 oops::mpi::world().barrier();
53 void stageFv3Files(
const eckit::Configuration &conf,
const eckit::mpi::Comm & comm) {
55 int world_rank = oops::mpi::world().rank();
59 if (world_rank == 0) {
62 if (conf.has(
"nml_file")) {
63 oops::Log::debug() <<
"Staging input.nml" << std::endl;
64 std::string nml_file = conf.getString(
"nml_file");
67 std::ifstream startNml(nml_file);
68 std::ofstream finalNml(
"./input.nml");
70 std::string startStr(
"layout = $LAYOUTX,$LAYOUTY");
71 std::string finalStr(
"layout = 1,1");
74 std::size_t len = startStr.length();
75 while (getline(startNml, line))
79 size_t pos = line.find(startStr);
80 if (pos != std::string::npos)
81 line.replace(pos, len, finalStr);
86 finalNml << line <<
'\n';
97 if (conf.has(
"trc_file")) {
98 oops::Log::debug() <<
"Staging field_table" << std::endl;
99 std::string trc_file = conf.getString(
"trc_file");
100 if (symlink(trc_file.c_str(),
"./field_table"))
101 ABORT(
"Unable to symlink field_table");
106 if (conf.has(
"nml_file_pert")) {
107 oops::Log::debug() <<
"Staging inputpert.nml" << std::endl;
108 std::string nml_file_pert = conf.getString(
"nml_file_pert");
109 if (symlink(nml_file_pert.c_str(),
"./inputpert.nml"))
110 ABORT(
"Unable to symlink inputpert.nml");
115 if (conf.has(
"fv3_input_dir")) {
116 oops::Log::debug() <<
"Staging INPUT directory" << std::endl;
117 std::string fv3_input_dir = conf.getString(
"fv3_input_dir");
118 oops::Log::debug() <<
"INPUT/ --> " << fv3_input_dir << std::endl;
119 if (symlink(fv3_input_dir.c_str(),
"./INPUT"))
120 ABORT(
"Unable to symlink INPUT");
125 oops::mpi::world().barrier();
132 int world_rank = oops::mpi::world().rank();
135 oops::mpi::world().barrier();
138 if (world_rank == 0) {
144 oops::mpi::world().barrier();
151 std::ifstream infile(fileName);
153 oops::Log::debug() <<
"Removing: " << fileName << std::endl;
154 std::remove(fileName);
163 oops::Log::trace() <<
"generateGeomFv3Conf starting" << std::endl;
167 oops::mpi::world().barrier();
171 if (oops::mpi::world().rank() == 0) {
178 std::vector<std::string> layout = conf.getStringVector(
"layout", {
"1",
"1"});
179 std::vector<std::string> io_layout = conf.getStringVector(
"io_layout", {
"1",
"1"});
180 std::string npx = conf.getString(
"npx");
181 std::string npy = conf.getString(
"npy", npx);
182 std::string npz = conf.getString(
"npz");
183 std::string ntiles = conf.getString(
"ntiles",
"6");
187 std::vector<std::string> inputnml;
189 inputnml.push_back(
"&fv_core_nml\n");
190 inputnml.push_back(
"\tlayout = "+layout[0]+
","+layout[1]+
"\n");
191 inputnml.push_back(
"\tio_layout = "+io_layout[0]+
","+io_layout[1]+
"\n");
192 inputnml.push_back(
"\tnpx = "+npx+
"\n");
193 inputnml.push_back(
"\tnpy = "+npy+
"\n");
194 inputnml.push_back(
"\tnpz = "+npz+
"\n");
195 inputnml.push_back(
"\tntiles = "+ntiles+
"\n");
199 if (conf.has(
"regional")) {
200 bool regional = conf.getBool(
"regional");
202 inputnml.push_back(
"\tregional = .T.\n");
206 if (conf.has(
"nested")) {
207 bool nested = conf.getBool(
"nested");
209 inputnml.push_back(
"\tnested = .T.\n");
213 if (conf.has(
"do_schmidt")) {
214 bool do_schmidt = conf.getBool(
"do_schmidt");
216 inputnml.push_back(
"\tdo_schmidt = .T.\n");
220 if (conf.has(
"target_lat")) {
221 std::string target_lat = conf.getString(
"target_lat");
222 inputnml.push_back(
"\ttarget_lat = "+target_lat+
"\n");
225 if (conf.has(
"target_lon")) {
226 std::string target_lon = conf.getString(
"target_lon");
227 inputnml.push_back(
"\ttarget_lon = "+target_lon+
"\n");
230 if (conf.has(
"stretch_fac")) {
231 std::string stretch_fac = conf.getString(
"stretch_fac");
232 inputnml.push_back(
"\tstretch_fac = "+stretch_fac+
"\n");
235 if (conf.has(
"hydrostatic")) {
236 bool hydrostatic = conf.getBool(
"hydrostatic");
238 inputnml.push_back(
"\thydrostatic = .false.\n");
242 if (conf.has(
"nwat")) {
243 std::string nwat = conf.getString(
"nwat");
244 inputnml.push_back(
"\tnwat = "+nwat+
"\n");
249 inputnml.push_back(
"/");
253 std::string file =
"input.nml";
254 std::ofstream out(file);
255 for (
int km = 0; km < static_cast<int>(inputnml.size()); ++km) {
263 oops::mpi::world().barrier();
267 oops::Log::trace() <<
"generateGeomFv3Conf done" << std::endl;