File: ParamID.cc

package info (click to toggle)
metkit 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,916 kB
  • sloc: cpp: 14,054; sh: 2,532; python: 1,699; ansic: 71; makefile: 18
file content (85 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * (C) Copyright 1996- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation nor
 * does it submit to any jurisdiction.
 */

#include "metkit/mars/ParamID.h"

#include <pthread.h>
#include <fstream>

#include "eckit/config/Resource.h"
#include "eckit/parser/YAMLParser.h"
#include "eckit/system/Library.h"
#include "eckit/utils/Tokenizer.h"

#include "metkit/config/LibMetkit.h"

using namespace eckit;

namespace metkit {

//----------------------------------------------------------------------------------------------------------------------

static std::vector<ParamID::WindFamily> windFamilies_;

static std::vector<size_t> dropTables_;

static bool fullTableDropping_;


//----------------------------------------------------------------------------------------------------------------------

static pthread_once_t once = PTHREAD_ONCE_INIT;

static void readTable() {
    eckit::PathName paramMatchingPath =
        eckit::Resource<eckit::PathName>("paramMatchingPath;$PARAM_MATCHING_PATH", LibMetkit::paramMatchingYamlFile());

    const eckit::Value paramMatching = eckit::YAMLParser::decodeFile(paramMatchingPath);
    const eckit::Value wind          = paramMatching["wind"];
    ASSERT(wind.isList());
    for (size_t i = 0; i < wind.size(); ++i) {
        const eckit::Value s = wind[i];
        ASSERT(s.isList());
        ASSERT(s.size() == 4);
        windFamilies_.push_back(ParamID::WindFamily(s[0], s[1], s[2], s[3]));
    }

    const eckit::Value dropTables = paramMatching["drop-tables"];
    ASSERT(dropTables.isList());
    for (size_t i = 0; i < dropTables.size(); ++i) {
        dropTables_.push_back(dropTables[i]);
    }

    fullTableDropping_ = false;
    if (paramMatching.contains("full-table-dropping")) {
        const eckit::Value fullTableDropping = paramMatching["full-table-dropping"];
        ASSERT(fullTableDropping.isBool());
        fullTableDropping_ = fullTableDropping;
    }
}

const std::vector<ParamID::WindFamily>& ParamID::getWindFamilies() {
    pthread_once(&once, readTable);
    return windFamilies_;
}
const std::vector<size_t>& ParamID::getDropTables() {
    pthread_once(&once, readTable);
    return dropTables_;
}

bool ParamID::fullTableDropping() {
    pthread_once(&once, readTable);
    return fullTableDropping_;
}


//----------------------------------------------------------------------------------------------------------------------

}  // namespace metkit