Debian Codegraph @

src/atlas/field/FieldCreatorIFS.cc

raw
1 /*
2 * (C) Copyright 2013 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
8 * nor does it submit to any jurisdiction.
9 */
10
11 #include "atlas/field/FieldCreatorIFS.h"
12
13 #include <cmath>
14 #include <sstream>
15
16 #include "eckit/config/Parametrisation.h"
17
18 #include "atlas/array/ArrayDataStore.h"
19 #include "atlas/array/DataType.h"
20 #include "atlas/field/detail/FieldImpl.h"
21 #include "atlas/grid/Grid.h"
22 #include "atlas/runtime/Exception.h"
23 #include "atlas/runtime/Log.h"
24
25 namespace atlas {
26 namespace field {
27
28 FieldImpl* FieldCreatorIFS::createField(const eckit::Parametrisation& params) const {
29 size_t ngptot;
30 size_t nblk;
31 size_t nvar = 1;
32 size_t nproma = 1;
33 size_t nlev = 1;
34
35 if (!params.get("ngptot", ngptot)) {
36 throw_Exception("Could not find parameter 'ngptot' in Parametrisation");
37 }
38 params.get("nproma", nproma);
39 params.get("nlev", nlev);
40 params.get("nvar", nvar);
41
42 array::DataType datatype = array::DataType::create<double>();
43 std::string datatype_str;
44 if (params.get("datatype", datatype_str)) {
45 datatype = array::DataType(datatype_str);
46 }
47 else {
48 array::DataType::kind_t kind(array::DataType::kind<double>());
49 params.get("kind", kind);
50 if (!array::DataType::kind_valid(kind)) {
51 std::stringstream msg;
52 msg << "Could not create field. kind parameter unrecognized";
53 throw_Exception(msg.str());
54 }
55 datatype = array::DataType(kind);
56 }
57
58 nblk = std::ceil(static_cast<double>(ngptot) / static_cast<double>(nproma));
59
60 array::ArrayShape s;
61 bool fortran(false);
62 params.get("fortran", fortran);
63 if (fortran) {
64 s = array::make_shape(nproma, nlev, nvar, nblk);
65 }
66 else {
67 s = array::make_shape(nblk, nvar, nlev, nproma);
68 }
69
70 std::string name;
71 params.get("name", name);
72 Log::debug() << "Creating IFS " << datatype.str() << " field: " << name << "[nblk=" << nblk << "][nvar=" << nvar
73 << "][nlev=" << nlev << "][nproma=" << nproma << "]\n";
74
75 return FieldImpl::create(name, datatype, s);
76 }
77
78 namespace {
79 static FieldCreatorBuilder<FieldCreatorIFS> __IFS("IFS");
80 }
81
82 // ------------------------------------------------------------------
83
84 } // namespace field
85 } // namespace atlas