Skip to content

Commit 205a815

Browse files
author
Alan Divittorio
committed
Fixed calcScalers segmentation fault bug
Was trying to access beyond end of array for copying ELM area.
1 parent 38812d0 commit 205a815

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cpl/source/carbon_scalers.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,22 @@ void CarbonScalers::calcScalers(int aGCAMYear, double *aELMArea, double *aELMPFT
157157
std::vector<int>& aYears, std::vector<std::string>& aRegions, std::vector<std::string>& aLandTechs, std::vector<double>& aAboveScalers,
158158
std::vector<double>& aBelowScalers, std::string aBaseNPPFileName, std::string aBaseHRFileName, std::string aBasePFTWtFileName,
159159
int& aNumScalars) {
160+
161+
// Open the coupling log
162+
ILogger& coupleLog = ILogger::getLogger( "coupling_log" );
163+
coupleLog.setLevel( ILogger::NOTICE );
164+
165+
coupleLog << "In calcScalers" << endl;
166+
160167
// First, read spatial data
161168
readBaseYearData(aBaseNPPFileName, aBaseHRFileName, aBasePFTWtFileName);
162-
169+
163170
// first copy the area into the local array, expanded to all pfts
164171
// this is because the area needs to be zeroed out also for outliers
165172
// an outlier may be for one pft in a cell, but not for another
166173
for (int z=0; z < mNumPFT; z++) {
167174
for (int i=0; i < (mNumLat*mNumLon); i++) {
168-
mELMArea[(z*mNumLat*mNumLon)+i] = aELMArea[(z*mNumLat*mNumLon)+i];
175+
mELMArea[(z*mNumLat*mNumLon)+i] = aELMArea[i];
169176
}
170177
}
171178

@@ -515,7 +522,7 @@ void CarbonScalers::excludeOutliers( double *aELMNPP, double *aELMHR) {
515522
int length = mNumLat * mNumLon * mNumPFT;
516523
std::vector<double> scaledNPP(aELMNPP+0, aELMNPP+length);
517524
std::vector<double> scaledHR(aELMHR+0, aELMHR+length);
518-
525+
519526
// Calculate raw scalars
520527
std::transform(scaledNPP.begin(), scaledNPP.end(), mBaseNPPVector.begin(), scaledNPP.begin(), std::divides<double>());
521528
std::transform(scaledHR.begin(), scaledHR.end(), mBaseHRVector.begin(), scaledHR.begin(), std::divides<double>());

0 commit comments

Comments
 (0)