FV3 Bundle
OdbApiIO.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018 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 #ifndef FILEIO_ODBAPIIO_H_
9 #define FILEIO_ODBAPIIO_H_
10 
11 #include <string>
12 
13 #include "odb_api/odbql.h"
14 
15 #include "oops/util/ObjectCounter.h"
16 
17 #include "fileio/IodaIO.h"
18 
19 ////////////////////////////////////////////////////////////////////////
20 // Implementation of IodaIO for ODB API.
21 ////////////////////////////////////////////////////////////////////////
22 
23 // Forward declarations
24 namespace eckit {
25  class Configuration;
26 }
27 
28 namespace ioda {
29 
30 /*! \brief Implementation of IodaIO for ODB API.
31  *
32  * \details The OdbOpiIO class defines the constructor and methods for
33  * the abstract class IodaIO.
34  *
35  * \author Steven Vahl (NCAR)
36  */
37 class OdbApiIO : public IodaIO,
38  private util::ObjectCounter<OdbApiIO> {
39  public:
40  /*!
41  * \brief classname method for object counter
42  *
43  * \details This method is supplied for the ObjectCounter base class.
44  * It defines a name to identify an object of this class
45  * for reporting by OOPS.
46  */
47  static const std::string classname() {return "ioda::OdbApiIO";}
48 
49  OdbApiIO(const std::string & FileName, const std::string & FileMode,
50  const std::size_t & Nlocs, const std::size_t & Nobs,
51  const std::size_t & Nrecs, const std::size_t & Nvars);
52  ~OdbApiIO();
53 
54  void ReadVar(const std::string & VarName, int* VarData);
55  void ReadVar(const std::string & VarName, float* VarData);
56  void ReadVar(const std::string & VarName, double* VarData);
57 
58  void WriteVar(const std::string & VarName, int* VarData);
59  void WriteVar(const std::string & VarName, float* VarData);
60  void WriteVar(const std::string & VarName, double* VarData);
61 
62  void ReadDateTime(int* VarDate, int* VarTime);
63 
64  private:
65  // For the oops::Printable base class
66  void print(std::ostream & os) const;
67 
68  // int CreateReadVarSQL(const std::string & VarName, int expectedType, odbql_stmt **res);
69  // int RetrieveColValPtr(odbql_stmt* res, int col, odbql_value **ppv);
70  template <class T>
71  void ReadVarTemplate(const std::string & VarName, T* VarData);
72 
73 
74  // Data members
75  /*!
76  * \brief pointer to odbql object
77  *
78  * \details This data member is a pointer to a odbql type. The
79  * odbql type is returned by the odbql_open function and
80  * is used by all following odb api functions to interact with
81  * the odb api file.
82  */
83  odbql *db_ = nullptr;
84  // TODO(sv) Maybe better to use unique_ptr, but causes compiler error of
85  // "incomplete type 'odbql'"
86  // std::unique_ptr<odbql> db_;
87 
88  /*!
89  * \brief pointer to odbql_stmt object used for selecting a single variable
90  *
91  * \details Rather than create a new odbql_stmt for every call to one of the
92  * ReadVar methods, we create a parameterized statement once for
93  * the OdbApiIO object. It is finalized in the class destructor.
94  *
95  * On second thought, not sure about thread-safety of this approach. TABLE FOR NOW
96  */
97  // odbql_stmt *readvar_sql_ = nullptr;
98 };
99 
100 } // namespace ioda
101 
102 #endif // FILEIO_ODBAPIIO_H_
odbql * db_
pointer to odbql object
Definition: OdbApiIO.h:83
OdbApiIO(const std::string &FileName, const std::string &FileMode, const std::size_t &Nlocs, const std::size_t &Nobs, const std::size_t &Nrecs, const std::size_t &Nvars)
Definition: OdbApiIO.cc:51
File access class for IODA.
void WriteVar(const std::string &VarName, int *VarData)
Definition: OdbApiIO.cc:287
static const std::string classname()
classname method for object counter
Definition: OdbApiIO.h:47
************************************************************************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:! ***********************************************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! MPP_TRANSMIT !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine MPP_TRANSMIT_(put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, recv_request, send_request)!a message-passing routine intended to be reminiscent equally of both MPI and SHMEM!put_data and get_data are contiguous MPP_TYPE_ arrays!at each call, your put_data array is put to to_pe 's get_data! your get_data array is got from from_pe 's put_data!i.e we assume that typically(e.g updating halo regions) each PE performs a put _and_ a get!special PE designations:! NULL_PE:to disable a put or a get(e.g at boundaries)! ANY_PE:if remote PE for the put or get is to be unspecific! ALL_PES:broadcast and collect operations(collect not yet implemented)!ideally we would not pass length, but this f77-style call performs better(arrays passed by address, not descriptor)!further, this permits< length > contiguous words from an array of any rank to be passed(avoiding f90 rank conformance check)!caller is responsible for completion checks(mpp_sync_self) before and after integer, intent(in) ::put_len, to_pe, get_len, from_pe MPP_TYPE_, intent(in) ::put_data(*) MPP_TYPE_, intent(out) ::get_data(*) logical, intent(in), optional ::block integer, intent(in), optional ::tag integer, intent(out), optional ::recv_request, send_request logical ::block_comm integer ::i MPP_TYPE_, allocatable, save ::local_data(:) !local copy used by non-parallel code(no SHMEM or MPI) integer ::comm_tag integer ::rsize if(.NOT.module_is_initialized) call mpp_error(FATAL, 'MPP_TRANSMIT:You must first call mpp_init.') if(to_pe.EQ.NULL_PE .AND. from_pe.EQ.NULL_PE) return block_comm=.true. if(PRESENT(block)) block_comm=block if(debug) then call SYSTEM_CLOCK(tick) write(stdout_unit,'(a, i18, a, i6, a, 2i6, 2i8)')&'T=', tick, ' PE=', pe, ' MPP_TRANSMIT begin:to_pe, from_pe, put_len, get_len=', to_pe, from_pe, put_len, get_len end if comm_tag=DEFAULT_TAG if(present(tag)) comm_tag=tag!do put first and then get if(to_pe.GE.0 .AND. to_pe.LT.npes) then!use non-blocking sends if(debug .and.(current_clock.NE.0)) call SYSTEM_CLOCK(start_tick)!z1l:truly non-blocking send.! if(request(to_pe).NE.MPI_REQUEST_NULL) then !only one message from pe-> to_pe in queue *PE waiting for to_pe ! call error else get_len so only do gets but you cannot have a pure get with MPI call a get means do a wait to ensure put on remote PE is complete error call increase mpp_nml request_multiply call MPP_TRANSMIT get_len end if return end subroutine MPP_TRANSMIT_ ! MPP_BROADCAST ! subroutine but that doesn t allow !broadcast to a subset of PEs This version and mpp_transmit will remain !backward compatible intent(inout) & T
void ReadVar(const std::string &VarName, int *VarData)
Definition: OdbApiIO.cc:266
void ReadDateTime(int *VarDate, int *VarTime)
Definition: OdbApiIO.cc:326
void ReadVarTemplate(const std::string &VarName, T *VarData)
Definition: OdbApiIO.cc:186
void print(std::ostream &os) const
Definition: OdbApiIO.cc:339
Implementation of IodaIO for ODB API.
Definition: OdbApiIO.h:37