FV3 Bundle
test/lorenz95/ObsTable.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <boost/scoped_ptr.hpp>
12 #include <boost/test/unit_test.hpp>
13 
14 #include "./TestConfig.h"
15 #include "eckit/config/LocalConfiguration.h"
16 #include "lorenz95/LocsL95.h"
17 #include "lorenz95/ObsTable.h"
18 #include "test/TestFixture.h"
19 
20 namespace test {
21 
22 // -----------------------------------------------------------------------------
24  public:
26  obsconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "Observations"));
27  bgn_.reset(new util::DateTime(obsconf_->getString("window_begin")));
28  end_.reset(new util::DateTime(obsconf_->getString("window_end")));
29  testconf_.reset(new eckit::LocalConfiguration(*obsconf_, "Observation"));
30  }
32  boost::scoped_ptr<const eckit::LocalConfiguration> obsconf_;
33  boost::scoped_ptr<const eckit::LocalConfiguration> testconf_;
34  boost::scoped_ptr<const util::DateTime> bgn_;
35  boost::scoped_ptr<const util::DateTime> end_;
36 };
37 // -----------------------------------------------------------------------------
38 
39 // -----------------------------------------------------------------------------
40 BOOST_FIXTURE_TEST_SUITE(test_ObsTable, ObsTableTestFixture)
41 // -----------------------------------------------------------------------------
42  BOOST_AUTO_TEST_CASE(test_ObsTable_constructor) {
43  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(*testconf_, *bgn_, *end_));
44  BOOST_CHECK(ot.get() != NULL);
45  }
46 // -----------------------------------------------------------------------------
47  BOOST_AUTO_TEST_CASE(test_ObsTable_nobs) {
48  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(*testconf_, *bgn_, *end_));
49  const unsigned int nobs = 160;
50  BOOST_CHECK_EQUAL(ot->nobs(), nobs);
51  }
52 // -----------------------------------------------------------------------------
53  BOOST_AUTO_TEST_CASE(test_observationL95_put_get) {
54  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(*testconf_, *bgn_, *end_));
55 
56  unsigned int nn = ot->nobs();
57  std::vector<double> v1(nn);
58  for (unsigned int jj = 0; jj < nn; ++jj) {
59  v1[jj] = 3.14*jj;
60  }
61  ot->putdb("ObsTest", v1);
62 
63  std::vector<double> v2;
64  ot->getdb("ObsTest", v2);
65 
66  BOOST_CHECK_EQUAL(v2.size(), nn);
67  for (unsigned int jj = 0; jj < nn; ++jj) {
68  BOOST_CHECK_EQUAL(v2[jj], v1[jj]);
69  }
70  }
71 // -----------------------------------------------------------------------------
72  BOOST_AUTO_TEST_CASE(test_observationL95_timeSelect) {
73  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(*testconf_, *bgn_, *end_));
74  util::DateTime t1("2010-01-01T09:00:00Z");
75  util::DateTime t2("2010-01-01T21:00:00Z");
76  std::vector<int> mask = ot->timeSelect(t1, t2); // t1 not includede, t2 is
77  const unsigned int size = 80;
78  BOOST_CHECK_EQUAL(mask.size(), size);
79  BOOST_CHECK_EQUAL(mask[0], 40);
80  BOOST_CHECK_EQUAL(mask[79], 119);
81  }
82 // -----------------------------------------------------------------------------
83  BOOST_AUTO_TEST_CASE(test_observationL95_locations) {
84  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(*testconf_, *bgn_, *end_));
85  util::DateTime t1("2010-01-01T09:00:00Z");
86  util::DateTime t2("2010-01-01T21:00:00Z");
87  lorenz95::LocsL95 * locs = ot->locations(t1, t2);
88  const size_t size = 80;
89  BOOST_CHECK_EQUAL(locs->size(), size);
90  }
91 // -----------------------------------------------------------------------------
92  BOOST_AUTO_TEST_CASE(test_observationL95_distribute) {
93  eckit::LocalConfiguration otconf;
94  util::DateTime t1("2010-01-01T00:00:00Z");
95  util::DateTime t2("2010-01-02T23:59:59Z");
96  boost::scoped_ptr<lorenz95::ObsTable> ot(new lorenz95::ObsTable(otconf, t1, t2));
97 
98  // More complete test in makeobs* tests.
99  eckit::LocalConfiguration genconf(*obsconf_, "Generate");
100 
101  ot->generateDistribution(genconf);
102  }
103 // -----------------------------------------------------------------------------
104 BOOST_AUTO_TEST_SUITE_END()
105 // -----------------------------------------------------------------------------
106 } // namespace test
boost::scoped_ptr< const util::DateTime > end_
boost::scoped_ptr< const util::DateTime > bgn_
*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
real, parameter t2
LocsL95 class to handle locations for L95 model.
Definition: LocsL95.h:28
boost::scoped_ptr< const eckit::LocalConfiguration > testconf_
real, parameter t1
A Simple Observation Data Handler.
Definition: ObsTable.h:39
************************************************************************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:! ***********************************************************************subroutine READ_RECORD_CORE_(unit, field, nwords, data, start, axsiz) integer, intent(in) ::unit type(fieldtype), intent(in) ::field integer, intent(in) ::nwords MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in) ::start(:), axsiz(:) integer(SHORT_KIND) ::i2vals(nwords)!rab used in conjunction with transfer intrinsic to determine size of a variable integer(KIND=1) ::one_byte(8) integer ::word_sz!#ifdef __sgi integer(INT_KIND) ::ivals(nwords) real(FLOAT_KIND) ::rvals(nwords)!#else! integer ::ivals(nwords)! real ::rvals(nwords)!#endif real(DOUBLE_KIND) ::r8vals(nwords) pointer(ptr1, i2vals) pointer(ptr2, ivals) pointer(ptr3, rvals) pointer(ptr4, r8vals) if(mpp_io_stack_size< nwords) call mpp_io_set_stack_size(nwords) call mpp_error(FATAL, 'MPP_READ currently requires use_netCDF option') end subroutine READ_RECORD_CORE_ subroutine READ_RECORD_(unit, field, nwords, data, time_level, domain, position, tile_count, start_in, axsiz_in)!routine that is finally called by all mpp_read routines to perform the read!a non-netCDF record contains:! field ID! a set of 4 coordinates(is:ie, js:je) giving the data subdomain! a timelevel and a timestamp(=NULLTIME if field is static)! 3D real data(stored as 1D)!if you are using direct access I/O, the RECL argument to OPEN must be large enough for the above!in a global direct access file, record position on PE is given by %record.!Treatment of timestamp:! We assume that static fields have been passed without a timestamp.! Here that is converted into a timestamp of NULLTIME.! For non-netCDF fields, field is treated no differently, but is written! with a timestamp of NULLTIME. There is no check in the code to prevent! the user from repeatedly writing a static field. integer, intent(in) ::unit, nwords type(fieldtype), intent(in) ::field MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in), optional ::time_level type(domain2D), intent(in), optional ::domain integer, intent(in), optional ::position, tile_count integer, intent(in), optional ::start_in(:), axsiz_in(:) integer, dimension(size(field%axes(:))) ::start, axsiz integer ::tlevel !, subdomain(4) integer ::i, error, is, ie, js, je, isg, ieg, jsg, jeg type(domain2d), pointer ::io_domain=> tlevel if(PRESENT(start_in) .AND. PRESENT(axsiz_in)) then if(size(start(! the data domain and compute domain must refer to the subdomain being passed ! In this ! since that attempts to gather all data on PE size(field%axes(:)) axsiz(i)
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
Definition: TestConfig.h:30
boost::scoped_ptr< const eckit::LocalConfiguration > obsconf_
size_t size() const
Definition: LocsL95.h:37