FV3 Bundle
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 <string>
9 
10 #include "oops/util/abor1_cpp.h"
11 #include "oops/util/Logger.h"
12 
13 #include "fileio/IodaIOfactory.h"
14 #include "fileio/NetcdfIO.h"
15 
16 #ifdef HAVE_ODB_API
17 #include "fileio/OdbApiIO.h"
18 #endif
19 
20 namespace ioda {
21 
22 //-------------------------------------------------------------------------------------
23 /*!
24  * \brief Instantiate a IodaIO object in read mode
25  *
26  * \details This method will instantiate an object of a IodaIO subclass. This method is
27  * intended to be used when opening a file in a read mode. The Nlocs, Nobs, Nrecs
28  * and Nvars parameters are set to zero which is okay since these will be set
29  * by reading metadata from the input file.
30  */
31 
32 IodaIO* IodaIOfactory::Create(const std::string & FileName, const std::string & FileMode) {
33  return Create(FileName, FileMode, 0, 0, 0, 0);
34 }
35 
36 //-------------------------------------------------------------------------------------
37 /*!
38  * \brief Instantiate a IodaIO object in write mode
39  *
40  * \details This method will instantiate an object of a IodaIO subclass. This method is
41  * intended to be used when opening a file in a write mode. The Nlocs, Nobs, Nrecs
42  * and Nvars parameters are set by the caller in this case. These parameters will
43  * subsequently be used to set metadata in the output file.
44  */
45 
46 IodaIO* IodaIOfactory::Create(const std::string & FileName, const std::string & FileMode,
47  const std::size_t & Nlocs, const std::size_t & Nobs,
48  const std::size_t & Nrecs, const std::size_t & Nvars) {
49  std::size_t Spos;
50  std::string FileSuffix;
51 
52  // Form the suffix by chopping off the string after the last "." in the file name.
53  Spos = FileName.find_last_of(".");
54  if (Spos == FileName.npos) {
55  FileSuffix = "";
56  } else {
57  FileSuffix = FileName.substr(Spos+1);
58  }
59 
60  // Create the appropriate object depending on the file suffix
61  if ((FileSuffix == "nc4") || (FileSuffix == "nc")) {
62  return new ioda::NetcdfIO(FileName, FileMode, Nlocs, Nobs, Nrecs, Nvars);
63  } else if (FileSuffix == "odb") {
64 #ifdef HAVE_ODB_API
65  return new ioda::OdbApiIO(FileName, FileMode, Nlocs, Nobs, Nrecs, Nvars);
66 #else
67  oops::Log::error() << "ioda::IodaIO::Create: ODB API not implemented: "
68  << FileName << std::endl;
69  oops::Log::error() << "ioda::IodaIO::Create: Try re-runing ecbuild with "
70  << " -DENABLE_ODB_API=1 and -DODB_API_PATH=path_to_odb options"
71  << std::endl;
72  ABORT("ioda::Ioda::Create: Rebuild with ODB API enabled");
73 #endif
74  } else {
75  oops::Log::error() << "ioda::IodaIO::Create: Unrecognized file suffix: "
76  << FileName << std::endl;
77  oops::Log::error() << "ioda::IodaIO::Create: suffix must be one of: .nc4, .nc"
78  << std::endl;
79  ABORT("ioda::Ioda::Create: Unrecognized file suffix");
80  return NULL;
81  }
82 }
83 
84 } // namespace ioda
File access class for IODA.
Implementation of IodaIO for netcdf.
Definition: NetcdfIO.h:36
*f90 *************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************! this routine is used to retrieve scalar boundary data for symmetric domain. subroutine MPP_GET_BOUNDARY_2D_(field, domain, ebuffer, sbuffer, wbuffer, nbuffer, flags, &position, complete, tile_count) type(domain2D), intent(in) ::domain MPP_TYPE_, intent(in) ::field(:,:) MPP_TYPE_, intent(inout), optional ::ebuffer(:), sbuffer(:), wbuffer(:), nbuffer(:) integer, intent(in), optional ::flags, position, tile_count logical, intent(in), optional ::complete MPP_TYPE_ ::field3D(size(field, 1), size(field, 2), 1) MPP_TYPE_, allocatable, dimension(:,:) ::ebuffer2D, sbuffer2D, wbuffer2D, nbuffer2D integer ::xcount, ycount integer ::ntile logical ::need_ebuffer, need_sbuffer, need_wbuffer, need_nbuffer integer(LONG_KIND), dimension(MAX_DOMAIN_FIELDS, MAX_TILES), save ::f_addrs=-9999 integer(LONG_KIND), dimension(4, MAX_DOMAIN_FIELDS, MAX_TILES), save ::b_addrs=-9999 integer, save ::bsize(4)=0, isize=0, jsize=0, ksize=0, pos, list=0, l_size=0, upflags integer ::buffer_size(4) integer ::max_ntile, tile, update_position, ishift, jshift logical ::do_update, is_complete, set_mismatch character(len=3) ::text MPP_TYPE_ ::d_type type(overlapSpec), pointer ::bound=> NULL() ntile
integer error
Definition: mpp.F90:1310
static ioda::IodaIO * Create(const std::string &FileName, const std::string &FileMode)
Instantiate a IodaIO object in read mode.
Implementation of IodaIO for ODB API.
Definition: OdbApiIO.h:37