SOCA
FmsInput.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020-2021 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
9 
10 // -----------------------------------------------------------------------------
11 namespace soca {
12  // -----------------------------------------------------------------------------
13  FmsInput::FmsInput(const eckit::mpi::Comm & comm,
14  const eckit::Configuration & conf)
15  : comm_(comm), conf_(conf) {
16 
17  // Get the file name of the fms namelist
18  inputnml_orig_ = conf_.getString("mom6_input_nml");
19 
20  // "input.nml" is protected
21  ASSERT(inputnml_orig_ != "input.nml");
22 
23  if ( comm_.rank() == 0 ) {
24  // Get serial # of original file
26  }
27  comm_.broadcast(inputnml_sn_, 0);
28  }
29  // -----------------------------------------------------------------------------
31  : comm_(other.comm_),
32  conf_(other.conf_),
33  inputnml_sn_(other.inputnml_sn_) {
34  }
35  // -----------------------------------------------------------------------------
37  inputnml_sn_ = -1;
38  }
39 
40  // -----------------------------------------------------------------------------
42  int testlink = -1;
43  if ( comm_.rank() == 0 ) {
44  // Get serial # of current input.nml
45  int inputnml_current_sn = getFileSN("input.nml");
46 
47  // If the file's serial # don't match, update the input.nml link
48  if ( inputnml_sn_ != inputnml_current_sn ) {
49  // Remove input.nml (link or file) if it exist
50  struct stat buffer;
51  int status = stat("input.nml", &buffer);
52  if ( status == 0 ) { remove("input.nml"); }
53 
54  // Create new symbolic link
55  char* target = const_cast<char*>(inputnml_orig_.c_str());
56  char linkname[] = "input.nml";
57  testlink = symlink(target, linkname);
58  if ( testlink != 0 ) { comm_.abort(); }
59  }
60  }
61  comm_.barrier();
62  }
63  // -----------------------------------------------------------------------------
64  int FmsInput::getFileSN(const std::string & filename) {
65  // Get serial # of file
66  struct stat buffer;
67  char* filename_char = const_cast<char*>(filename.c_str());
68  int status = stat(filename_char, &buffer);
69  if ( status == 0 ) {
70  return buffer.st_ino;
71  } else {
72  return -1;
73  }
74  }
75 } // namespace soca
FmsInput handles the hard-coded fms input.nml file.
Definition: FmsInput.h:28
std::string inputnml_orig_
Definition: FmsInput.h:39
const eckit::Configuration & conf_
Definition: FmsInput.h:37
int getFileSN(const std::string &)
Definition: FmsInput.cc:64
const eckit::mpi::Comm & comm_
Definition: FmsInput.h:36
void updateNameList()
Definition: FmsInput.cc:41
int inputnml_sn_
Definition: FmsInput.h:38
FmsInput(const eckit::mpi::Comm &, const eckit::Configuration &conf)
Definition: FmsInput.cc:13