From 205a8159768409035c55e8df1ac10afe0d30ab5b Mon Sep 17 00:00:00 2001 From: Alan Divittorio Date: Thu, 18 Jul 2024 10:58:17 -0500 Subject: [PATCH] Fixed calcScalers segmentation fault bug Was trying to access beyond end of array for copying ELM area. --- cpl/source/carbon_scalers.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cpl/source/carbon_scalers.cpp b/cpl/source/carbon_scalers.cpp index 0baf2c2caa..7203a23cec 100644 --- a/cpl/source/carbon_scalers.cpp +++ b/cpl/source/carbon_scalers.cpp @@ -157,15 +157,22 @@ void CarbonScalers::calcScalers(int aGCAMYear, double *aELMArea, double *aELMPFT std::vector& aYears, std::vector& aRegions, std::vector& aLandTechs, std::vector& aAboveScalers, std::vector& aBelowScalers, std::string aBaseNPPFileName, std::string aBaseHRFileName, std::string aBasePFTWtFileName, int& aNumScalars) { + + // Open the coupling log + ILogger& coupleLog = ILogger::getLogger( "coupling_log" ); + coupleLog.setLevel( ILogger::NOTICE ); + + coupleLog << "In calcScalers" << endl; + // First, read spatial data readBaseYearData(aBaseNPPFileName, aBaseHRFileName, aBasePFTWtFileName); - + // first copy the area into the local array, expanded to all pfts // this is because the area needs to be zeroed out also for outliers // an outlier may be for one pft in a cell, but not for another for (int z=0; z < mNumPFT; z++) { for (int i=0; i < (mNumLat*mNumLon); i++) { - mELMArea[(z*mNumLat*mNumLon)+i] = aELMArea[(z*mNumLat*mNumLon)+i]; + mELMArea[(z*mNumLat*mNumLon)+i] = aELMArea[i]; } } @@ -515,7 +522,7 @@ void CarbonScalers::excludeOutliers( double *aELMNPP, double *aELMHR) { int length = mNumLat * mNumLon * mNumPFT; std::vector scaledNPP(aELMNPP+0, aELMNPP+length); std::vector scaledHR(aELMHR+0, aELMHR+length); - + // Calculate raw scalars std::transform(scaledNPP.begin(), scaledNPP.end(), mBaseNPPVector.begin(), scaledNPP.begin(), std::divides()); std::transform(scaledHR.begin(), scaledHR.end(), mBaseHRVector.begin(), scaledHR.begin(), std::divides());