IODA
IodaIOfactory.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 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 
8 #include "ioda/io/IodaIOfactory.h"
9 
10 #include <string>
11 
12 #include "oops/util/abor1_cpp.h"
13 #include "oops/util/Logger.h"
14 
15 #include "ioda/io/NetcdfIO.h"
16 
17 namespace ioda {
18 
19 //-------------------------------------------------------------------------------------
20 /*!
21  * \brief Instantiate a IodaIO object
22  *
23  * \param[in] FileName Path to the obs file
24  * \param[in] FileMode Mode in which to open the obs file, "r" for read, "w" for overwrite
25  * and existing file and "W" for create and write to a new file
26  * \param[in] MaxFrameSize Maximum number of "rows" in a frame
27  */
28 
29 IodaIO* IodaIOfactory::Create(const std::string & FileName, const std::string & FileMode,
30  const std::size_t MaxFrameSize) {
31  std::size_t Spos;
32  std::string FileSuffix;
33 
34  // Form the suffix by chopping off the string after the last "." in the file name.
35  Spos = FileName.find_last_of(".");
36  if (Spos == FileName.npos) {
37  FileSuffix = "";
38  } else {
39  FileSuffix = FileName.substr(Spos+1);
40  }
41 
42  // Create the appropriate object depending on the file suffix
43  std::string FileSuffixList = ".nc4, .nc";
44 
45  if ((FileSuffix == "nc4") || (FileSuffix == "nc")) {
46  return new ioda::NetcdfIO(FileName, FileMode, MaxFrameSize);
47  } else {
48  oops::Log::error() << "IodaIO::Create: Unrecognized file suffix: "
49  << FileName << std::endl;
50  oops::Log::error() << "IodaIO::Create: suffix must be one of: " << FileSuffixList
51  << std::endl;
52  ABORT("IodaIO::Create: Unrecognized file suffix");
53  return NULL;
54  }
55 }
56 
57 } // namespace ioda
ioda::IodaIOfactory::Create
static ioda::IodaIO * Create(const std::string &FileName, const std::string &FileMode, const std::size_t MaxFrameSize)
Instantiate a IodaIO object.
Definition: IodaIOfactory.cc:29
ioda::NetcdfIO
Implementation of IodaIO for netcdf.
Definition: NetcdfIO.h:39
ioda
Definition: IodaUtils.cc:13
ioda::IodaIO
File access class for IODA.
Definition: src/io/IodaIO.h:116