Skip to content

Commit da20263

Browse files
Add in a C++ linter (#555)
1 parent f601d0c commit da20263

File tree

8 files changed

+6544
-38
lines changed

8 files changed

+6544
-38
lines changed

.github/workflows/pynorms.yaml .github/workflows/norms.yaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Python Coding Norms
1+
name: Coding Norms
22
on: [push]
33

44
jobs:
55
check_pynorms:
66
runs-on: ubuntu-latest
7-
name: Check Python coding norms with pycodestyle
7+
name: Check coding norms with pycodestyle and cpplint
88

99
steps:
1010

@@ -20,4 +20,9 @@ jobs:
2020
- name: Run pycodestyle
2121
run: |
2222
cd $GITHUB_WORKSPACE/GDASApp
23-
pycodestyle -v --config ./.pycodestyle .
23+
pycodestyle -v --config ./.pycodestyle ./ush ./scripts ./test
24+
25+
- name: Run C++ linter on utils
26+
run: |
27+
cd $GITHUB_WORKSPACE/GDASApp/utils/test/
28+
./cpplint.py --quiet --recursive $GITHUB_WORKSPACE/GDASApp/utils

utils/CPPLINT.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set noparent
2+
linelength=100
3+
filter=+build,-legal,+readability,+runtime,+whitespace,-runtime/references,-runtime/printf,-build/include_subdir

utils/ioda_example/gdas_meanioda.h

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#pragma once
2+
13
#include <iostream>
24
#include <numeric>
5+
#include <string>
6+
#include <vector>
37
#include "eckit/config/LocalConfiguration.h"
48
#include "ioda/Group.h"
59
#include "ioda/ObsSpace.h"
@@ -26,11 +30,10 @@ namespace gdasapp {
2630
static const std::string classname() {return "gdasapp::IodaExample";}
2731

2832
int execute(const eckit::Configuration & fullConfig, bool /*validate*/) const {
29-
3033
// get the obs space configuration
3134
const eckit::LocalConfiguration obsConfig(fullConfig, "obs space");
3235
ioda::ObsTopLevelParameters obsparams;
33-
obsparams.validateAndDeserialize(obsConfig); // TODO CRM, can I remove this and then the simulated vars junk??
36+
obsparams.validateAndDeserialize(obsConfig);
3437
oops::Log::info() << "obs space: " << std::endl << obsConfig << std::endl;
3538

3639
// time window stuff
@@ -51,13 +54,16 @@ namespace gdasapp {
5154

5255
// read the obs space
5356
// Note, the below line does a lot of heavy lifting
54-
// we can probably go to a lower level function (and more of them) to accomplish the same thing
55-
ioda::ObsSpace ospace(obsparams, oops::mpi::world(), util::DateTime(winbegin), util::DateTime(winend), oops::mpi::myself());
57+
// we can probably go to a lower level function
58+
// (and more of them) to accomplish the same thing
59+
ioda::ObsSpace ospace(obsparams, oops::mpi::world(), util::DateTime(winbegin),
60+
util::DateTime(winend), oops::mpi::myself());
5661
const size_t nlocs = ospace.nlocs();
5762
oops::Log::info() << "nlocs =" << nlocs << std::endl;
5863
std::vector<float> buffer(nlocs);
5964

60-
// below is grabbing from the IODA obs space the specified group/variable and putting it into the buffer
65+
// below is grabbing from the IODA obs space
66+
// the specified group/variable and putting it into the buffer
6167
if (chan == 0) {
6268
// no channel is selected
6369
ospace.get_db(group, variable, buffer);
@@ -67,12 +73,15 @@ namespace gdasapp {
6773
}
6874

6975
// the below line computes the mean, aka sum divided by count
70-
const float mean = std::accumulate(buffer.begin(), buffer.end(), 0) / float(nlocs);
76+
const float mean = std::accumulate(buffer.begin(), buffer.end(), 0) /
77+
static_cast<float>(nlocs);
7178

7279
// write the mean out to the stdout
73-
oops::Log::info() << "mean value for " << group << "/" << variable << "=" << mean << std::endl;
80+
oops::Log::info() << "mean value for " << group << "/" << variable
81+
<< "=" << mean << std::endl;
7482

75-
// a better program should return a real exit code depending on result, but this is just an example!
83+
// a better program should return a real exit code depending on result,
84+
// but this is just an example!
7685
return 0;
7786
}
7887
// -----------------------------------------------------------------------------

utils/soca/gdas_incr_handler.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
#pragma once
2+
13
#include <netcdf>
2-
#include <iostream>
4+
35
#include <filesystem>
6+
#include <iostream>
7+
#include <string>
48

59
#include "eckit/config/LocalConfiguration.h"
610

@@ -18,7 +22,7 @@
1822
#include "soca/LinearVariableChange/LinearVariableChange.h"
1923
#include "soca/State/State.h"
2024

21-
# include "gdas_postprocincr.h"
25+
#include "gdas_postprocincr.h"
2226

2327
namespace gdasapp {
2428

@@ -29,7 +33,6 @@ namespace gdasapp {
2933
static const std::string classname() {return "gdasapp::SocaIncrHandler";}
3034

3135
int execute(const eckit::Configuration & fullConfig, bool /*validate*/) const {
32-
3336
/// Setup the soca geometry
3437
const eckit::LocalConfiguration geomConfig(fullConfig, "geometry");
3538
oops::Log::info() << "geometry: " << std::endl << geomConfig << std::endl;
@@ -39,7 +42,8 @@ namespace gdasapp {
3942
// Initialize the post processing
4043
PostProcIncr postProcIncr(fullConfig, geom, this->getComm());
4144

42-
oops::Log::info() << "soca increments: " << std::endl << postProcIncr.inputIncrConfig_ << std::endl;
45+
oops::Log::info() << "soca increments: " << std::endl
46+
<< postProcIncr.inputIncrConfig_ << std::endl;
4347

4448
// Process list of increments
4549
int result = 0;

utils/soca/gdas_postprocincr.h

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#ifndef GDAS_POSTPROCINCR_H
2-
#define GDAS_POSTPROCINCR_H
1+
#pragma once
32

4-
#include <iostream>
53
#include <filesystem>
64

5+
#include <iostream>
6+
#include <string>
7+
78
#include "eckit/config/LocalConfiguration.h"
89

910
#include "atlas/field.h"
@@ -22,7 +23,7 @@
2223
namespace gdasapp {
2324

2425
class PostProcIncr {
25-
public:
26+
public:
2627
// Constructor
2728
PostProcIncr(const eckit::Configuration & fullConfig, const soca::Geometry& geom,
2829
const eckit::mpi::Comm & comm)
@@ -33,7 +34,7 @@ class PostProcIncr {
3334
xTraj_(getTraj(fullConfig, geom)),
3435
comm_(comm),
3536
ensSize_(1),
36-
pattern_(){
37+
pattern_() {
3738

3839
oops::Log::info() << "Date: " << std::endl << dt_ << std::endl;
3940

@@ -73,18 +74,18 @@ class PostProcIncr {
7374
}
7475

7576
// Append layer thicknesses to increment
76-
// TODO: There's got to be a better way to append a variable.
77-
soca::Increment appendLayer(const int n){
77+
// TODO(guillaume): There's got to be a better way to append a variable.
78+
soca::Increment appendLayer(const int n) {
7879
oops::Log::info() << "==========================================" << std::endl;
7980
oops::Log::info() << "====== Append Layers" << std::endl;
8081

8182
// initialize the soca increment
8283
soca::Increment socaIncr(geom_, socaIncrVar_, dt_);
83-
eckit::LocalConfiguration memberConfig; //inputIncrConfig_);
84+
eckit::LocalConfiguration memberConfig; // inputIncrConfig_);
8485
memberConfig = inputIncrConfig_;
8586

8687
// replace templated string if necessary
87-
if (not pattern_.empty()) {
88+
if (!pattern_.empty()) {
8889
util::seekAndReplace(memberConfig, pattern_, std::to_string(n));
8990
oops::Log::info() << "oooooooooooooooooooooooooooooooooooo" << memberConfig << std::endl;
9091
}
@@ -124,7 +125,7 @@ class PostProcIncr {
124125
// Set specified variables to 0
125126
soca::Increment setToZero(soca::Increment socaIncr) {
126127
oops::Log::info() << "==========================================" << std::endl;
127-
if (not this->setToZero_) {
128+
if (!this->setToZero_) {
128129
oops::Log::info() << "====== no variables to set to 0.0" << std::endl;
129130
return socaIncr;
130131
}
@@ -154,7 +155,7 @@ class PostProcIncr {
154155
// Apply linear variable changes
155156
soca::Increment applyLinVarChange(soca::Increment socaIncr) {
156157
oops::Log::info() << "==========================================" << std::endl;
157-
if (not this->doLVC_) {
158+
if (!this->doLVC_) {
158159
return socaIncr;
159160
}
160161
oops::Log::info() << "====== applying specified change of variables" << std::endl;
@@ -252,8 +253,8 @@ class PostProcIncr {
252253
// Utility functions
253254
// -----------------------------------------------------------------------------
254255
// Recreate the soca filename from the configuration
255-
// TODO: Change this in soca?
256-
// TODO: Hard-coded for ocean, implement for seaice as well
256+
// TODO(guillaume): Change this in soca?
257+
// TODO(guillaume): Hard-coded for ocean, implement for seaice as well
257258
std::string socaFname() {
258259
std::string datadir;
259260
outputIncrConfig_.get("datadir", datadir);
@@ -284,7 +285,7 @@ class PostProcIncr {
284285
}
285286

286287

287-
public:
288+
public:
288289
util::DateTime dt_; // valid date of increment
289290
oops::Variables layerVar_; // layer variable
290291
const soca::Increment Layers_; // layer thicknesses
@@ -303,6 +304,4 @@ class PostProcIncr {
303304
int ensSize_;
304305
std::string pattern_;
305306
};
306-
} // namespace gdasapp
307-
308-
#endif // GDAS_POSTPROCINCR_H
307+
} // namespace gdasapp

utils/soca/gdas_socahybridweights.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
#pragma once
2+
13
#include <netcdf>
2-
#include <iostream>
4+
35
#include <filesystem>
6+
#include <iostream>
7+
#include <string>
48

59
#include "eckit/config/LocalConfiguration.h"
610

@@ -13,9 +17,9 @@
1317
#include "oops/util/Duration.h"
1418
#include "oops/util/Logger.h"
1519

16-
#include "soca/State/State.h"
1720
#include "soca/Geometry/Geometry.h"
1821
#include "soca/Increment/Increment.h"
22+
#include "soca/State/State.h"
1923

2024
namespace gdasapp {
2125

@@ -26,7 +30,6 @@ namespace gdasapp {
2630
static const std::string classname() {return "gdasapp::SocaHybridWeights";}
2731

2832
int execute(const eckit::Configuration & fullConfig, bool /*validate*/) const {
29-
3033
/// Setup the soca geometry
3134
const eckit::LocalConfiguration geomConfig(fullConfig, "geometry");
3235
oops::Log::info() << "geometry: " << std::endl << geomConfig << std::endl;
@@ -44,7 +47,7 @@ namespace gdasapp {
4447
socaVars += socaOcnVars;
4548

4649
/// Read the background
47-
// TODO: Use the ice extent to set the weights ... no clue if this is
50+
// TODO(guillaume): Use the ice extent to set the weights ... no clue if this is
4851
// possible at this level
4952
soca::State socaBkg(geom, socaVars, dt);
5053
const eckit::LocalConfiguration socaBkgConfig(fullConfig, "background");
@@ -59,7 +62,7 @@ namespace gdasapp {
5962
oops::Log::info() << "wOcean: " << wOcean << std::endl;
6063

6164
/// Create fields of weights for seaice
62-
soca::Increment socaIceHW(geom, socaVars, dt); // ocean field is mandatory for writting
65+
soca::Increment socaIceHW(geom, socaVars, dt); // ocean field is mandatory for writting
6366
socaIceHW.ones();
6467
socaIceHW *= wIce;
6568
oops::Log::info() << "socaIceHW: " << std::endl << socaIceHW << std::endl;

utils/test/CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ list( APPEND utils_test_input
66
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testinput)
77
CREATE_SYMLINK( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${utils_test_input} )
88

9+
# copy the cpp linter script
10+
execute_process( COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cpplint.py ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}_cpplint.py)
11+
12+
# add linter for the utils
13+
ecbuild_add_test( TARGET test_gdasapp_util_coding_norms
14+
TYPE SCRIPT
15+
COMMAND ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}_cpplint.py
16+
ARGS --quiet --recursive ${CMAKE_CURRENT_SOURCE_DIR}/../
17+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
18+
919
# Test example IODA utility that computes the mean of a variable
1020
ecbuild_add_test( TARGET test_gdasapp_util_ioda_example
1121
COMMAND ${CMAKE_BINARY_DIR}/bin/gdas_meanioda.x
1222
ARGS "testinput/gdas_meanioda.yaml"
13-
LIBS gdas-utils)
23+
LIBS gdas-utils)

0 commit comments

Comments
 (0)