Skip to content

Commit 4184c95

Browse files
authored
Removes or fixes several unused variables or expressions
Fixes many unused variables and expressions and a missing default switch clause that were found via compiler warnings.
2 parents 51bd02c + 80f247d commit 4184c95

File tree

10 files changed

+124
-121
lines changed

10 files changed

+124
-121
lines changed

components/omega/src/base/Decomp.cpp

Lines changed: 85 additions & 73 deletions
Large diffs are not rendered by default.

components/omega/src/infra/Config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ Error Config::get(const std::string &VarName, // [in] name of variable to get
485485
std::vector<std::string> &List // [out] string list retrieved
486486
) {
487487
Error Err; // success error code
488-
int VecSize = 0;
489488

490489
// Extract variable from config
491490
// First check if it exists and verify that it is a sequence node

components/omega/src/infra/Dimension.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "Dimension.h"
1616
#include "DataTypes.h"
17+
#include "Error.h"
1718
#include "Logging.h"
1819
#include "OmegaKokkos.h"
1920
#include <map>
@@ -246,16 +247,15 @@ HostArray1DI4
246247
Dimension::getDimOffset(const std::string &Name // [in] name of dimension
247248
) {
248249

249-
// Make sure dimension exists
250-
if (exists(Name)) {
251-
std::shared_ptr<Dimension> ThisDim = AllDims[Name];
252-
return ThisDim->Offset;
250+
// Abort if the dimension does not exist
251+
if (!exists(Name))
252+
ABORT_ERROR("Cannot get offset array for dimension {}: "
253+
"dimension does not exist or has not been defined",
254+
Name);
253255

254-
} else {
255-
LOG_ERROR("Cannot get offset array for dimension {}: "
256-
"dimension does not exist or has not been defined",
257-
Name);
258-
}
256+
// Retrieve offset
257+
std::shared_ptr<Dimension> ThisDim = AllDims[Name];
258+
return ThisDim->Offset;
259259

260260
} // end getDimOffset
261261

components/omega/src/infra/Error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Error::Error(ErrorCode ErrCode, // [in] error code to assign
135135

136136
// Strip pathname from file argument
137137
std::string Filename;
138-
int Pos = FileWPath.find_last_of("\\/");
138+
auto Pos = FileWPath.find_last_of("\\/");
139139
if (Pos != std::string::npos) {
140140
Filename = FileWPath.substr(Pos + 1);
141141
} else {

components/omega/src/infra/Field.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ int Field::init(const Clock *ModelClock // [in] default model clock
5454
std::string UnitString = "seconds since " + StartTimeStr;
5555
CalendarKind CalKind = Calendar::getKind();
5656
std::string CalName = CalendarCFName[CalKind];
57-
std::vector<std::string> DimNames; // empty dim names vector
57+
std::vector<std::string> DimNamesTmp; // empty dim names vector
5858
std::shared_ptr<Field> TimeField =
5959
create("time", "time", UnitString, "time", 0.0, 1.e20, -9.99e30, 0,
60-
DimNames, true, true);
60+
DimNamesTmp, true, true);
6161
TimeField->addMetadata("calendar", CalName);
6262

6363
return Err;
@@ -110,9 +110,6 @@ Field::create(const std::string &FieldName, // [in] Name of variable/field
110110
// Add field name to the instance (also added as metadata below)
111111
ThisField->FldName = FieldName;
112112

113-
// Create empty metadata map: (name, value) pairs
114-
ThisField->FieldMeta;
115-
116113
// Add standard metadata. For some CF standard attributes, we
117114
// also duplicate the metadata under the CF standard attribute name
118115
ThisField->FieldMeta["Name"] = FieldName;
@@ -145,7 +142,6 @@ Field::create(const std::string &FieldName, // [in] Name of variable/field
145142
// Also determine whether this is a distributed field - true if any of
146143
// the dimensions are distributed.
147144
ThisField->Distributed = false;
148-
ThisField->DimNames;
149145
if (NumDims > 0) {
150146
ThisField->DimNames.resize(NumDims);
151147
for (int I = 0; I < NumDims; ++I) {
@@ -191,15 +187,9 @@ Field::create(const std::string &FieldName // [in] Name of field
191187
// Field name
192188
ThisField->FldName = FieldName;
193189

194-
// Metadata (name, value) pairs for descriptive metadata
195-
ThisField->FieldMeta;
196-
197-
/// Number of dimensions is 0 for this field
190+
// Number of dimensions is 0 for this field
198191
ThisField->NDims = 0;
199192

200-
// Dimension name vector is empty
201-
ThisField->DimNames;
202-
203193
// Initialize to Unknown or null - no data is attached
204194
ThisField->DataType = ArrayDataType::Unknown;
205195
ThisField->MemLoc = ArrayMemLoc::Unknown;

components/omega/src/infra/IOStream.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ int IOStream::writeFieldMeta(
909909

910910
} else if (MetaVal.type() == typeid(bool)) {
911911
bool MetaValBool = std::any_cast<bool>(MetaVal);
912+
// bool is coerced to int in write
912913
Err = IO::writeMeta(MetaName, MetaValBool, FileID, FieldID);
913914

914915
} else if (MetaVal.type() == typeid(std::string)) {
@@ -1696,15 +1697,23 @@ int IOStream::readFieldData(
16961697
case ArrayDataType::I4:
16971698
DataI4.resize(LocSize);
16981699
DataPtr = DataI4.data();
1700+
break;
16991701
case ArrayDataType::I8:
17001702
DataI8.resize(LocSize);
17011703
DataPtr = DataI8.data();
1704+
break;
17021705
case ArrayDataType::R4:
17031706
DataR4.resize(LocSize);
17041707
DataPtr = DataR4.data();
1708+
break;
17051709
case ArrayDataType::R8:
17061710
DataR8.resize(LocSize);
17071711
DataPtr = DataR8.data();
1712+
break;
1713+
case ArrayDataType::Unknown:
1714+
ABORT_ERROR("Unknown data array type");
1715+
default:
1716+
ABORT_ERROR("Invalid data array type");
17081717
}
17091718

17101719
// read data into vector
@@ -2388,6 +2397,15 @@ int IOStream::readStream(
23882397
} else if (MetaTmp.type() == typeid(R4)) {
23892398
ErrRead = IO::readMeta(MetaName, MetaValR4, InFileID, IO::GlobalID);
23902399
ReqMetadata[MetaName] = MetaValR4;
2400+
} else if (MetaTmp.type() == typeid(bool)) {
2401+
// bool must be read as int
2402+
ErrRead = IO::readMeta(MetaName, MetaValI4, InFileID, IO::GlobalID);
2403+
if (MetaValI4 == 0) {
2404+
MetaValBool = false;
2405+
} else {
2406+
MetaValBool = true;
2407+
}
2408+
ReqMetadata[MetaName] = MetaValBool;
23912409
} else if (MetaTmp.type() == typeid(std::string)) {
23922410
ErrRead = IO::readMeta(MetaName, MetaValStr, InFileID, IO::GlobalID);
23932411
ReqMetadata[MetaName] = MetaValStr;

components/omega/src/timeStepping/TimeStepper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ TimeStepper *TimeStepper::create(
114114
NewTimeStepper =
115115
new RungeKutta2Stepper(InName, InStartTime, InStopTime, InTimeStep);
116116
break;
117+
case TimeStepperType::Invalid:
118+
ABORT_ERROR("Invalid time stepping method");
119+
default:
120+
ABORT_ERROR("Unknown time stepping method");
117121
}
118122

119123
// Attach data pointers
@@ -161,6 +165,10 @@ TimeStepper *TimeStepper::create(
161165
NewTimeStepper =
162166
new RungeKutta2Stepper(InName, InStartTime, InStopTime, InTimeStep);
163167
break;
168+
case TimeStepperType::Invalid:
169+
ABORT_ERROR("Invalid time stepping method");
170+
default:
171+
ABORT_ERROR("Unknown time stepping method");
164172
}
165173

166174
// Store instance

components/omega/test/base/MachEnvTest.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ int main(int argc, char *argv[]) {
6969
MPI_Comm_rank(MPI_COMM_WORLD, &WorldTask);
7070
MPI_Comm_size(MPI_COMM_WORLD, &WorldSize);
7171
int WorldMaster = 0;
72-
bool IsWorldMaster;
73-
if (WorldTask == WorldMaster) {
74-
IsWorldMaster = true;
75-
} else {
76-
IsWorldMaster = false;
77-
}
7872

7973
// The subset environments create 4-task sub-environments so
8074
// make sure the unit test is run with at least 8 to adequately

components/omega/test/infra/FieldTest.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,6 @@ int main(int argc, char **argv) {
782782
if (Data1DI4H(Cell) != RefI4 + Cell)
783783
++DataCount1;
784784
for (int K = 0; K < NVertLevels; ++K) {
785-
I4 I4Ref = RefI4 + Cell + K;
786-
R8 R8Ref = RefR8 + Cell + K;
787785
if (Data2DI4H(Cell, K) != RefI4 + Cell + K)
788786
++DataCount2;
789787
if (Data2DR8H(Cell, K) != RefR8 + Cell + K)
@@ -852,15 +850,10 @@ int main(int argc, char **argv) {
852850
if (Data3DI4(Cell, K, Trcr) != RefI4 + Cell + K + Trcr)
853851
++LCount;
854852
for (int TimeLvl = 0; TimeLvl < NTime; ++TimeLvl) {
855-
int Add4 =
856-
TimeLvl * NTracers * NCellsSize * NVertLevels + Add3;
857853
if (Data4DI8(Cell, K, Trcr, TimeLvl) !=
858854
RefI8 + Cell + K + Trcr + TimeLvl)
859855
++LCount;
860856
for (int Stf = 0; Stf < NStuff; ++Stf) {
861-
int Add5 =
862-
Stf * NTime * NTracers * NCellsSize * NVertLevels +
863-
Add4;
864857
if (Data5DR4(Cell, K, Trcr, TimeLvl, Stf) !=
865858
RefR4 + Cell + K + Trcr + TimeLvl + Stf)
866859
++LCount;
@@ -879,7 +872,6 @@ int main(int argc, char **argv) {
879872
if (Data1DI8(Edge) != RefI8 + Edge)
880873
++LCount;
881874
for (int K = 0; K < NVertLevels; ++K) {
882-
int Add = Edge * NVertLevels + K;
883875
if (Data2DI8(Edge, K) != RefI8 + Edge + K)
884876
++LCount;
885877
if (Data2DR8(Edge, K) != RefR8 + Edge + K)
@@ -896,7 +888,6 @@ int main(int argc, char **argv) {
896888
if (Data1DR4(Vrtx) != RefR4 + Vrtx)
897889
++LCount;
898890
for (int K = 0; K < NVertLevels; ++K) {
899-
int Add = Vrtx * NVertLevels + K;
900891
if (Data2DR4(Vrtx, K) != RefR4 + Vrtx + K)
901892
++LCount;
902893
}

components/omega/test/infra/IOStreamTest.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434

3535
using namespace OMEGA;
3636

37-
//------------------------------------------------------------------------------
38-
// Set some constant reference values for simplicity
39-
const I4 RefI4 = 3;
40-
const I8 RefI8 = 400000000;
41-
const R4 RefR4 = 5.1;
42-
const R8 RefR8 = 6.123456789;
43-
const std::string RefStr = "Reference String";
44-
4537
//------------------------------------------------------------------------------
4638
// A simple test evaluation function
4739
template <typename T>
@@ -106,7 +98,6 @@ int initIOStreamTest(Clock *&ModelClock // Model clock
10698
// Initialize HorzMesh - this should read Mesh stream
10799
HorzMesh::init();
108100
HorzMesh *DefMesh = HorzMesh::getDefault();
109-
I4 NCellsSize = DefMesh->NCellsSize;
110101

111102
// Set vertical levels and time levels
112103
I4 NVertLevels = 60;

0 commit comments

Comments
 (0)