Skip to content

Commit

Permalink
More replacing of NULL with nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
perwin committed Jun 24, 2024
1 parent a7decb2 commit b7e093a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions core/bootstrap_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* nonlinfit (imfit's conceptual predecessor), so yay for reuse!
*/

// Copyright 2013-2019 by Peter Erwin.
// Copyright 2013-2019,2024 by Peter Erwin.
//
// This file is part of Imfit.
//
Expand Down Expand Up @@ -108,7 +108,7 @@ int BootstrapErrors( const double *bestfitParams, vector<mp_par> parameterLimits
// bestfitParams_offsetCorrected = (double *) calloc(nParams, sizeof(double));

// write column header info to file, if user requested saving to file
if (outputFile_ptr != NULL) {
if (outputFile_ptr != nullptr) {
string headerLine = theModel->GetParamHeader();
fprintf(outputFile_ptr, "#\n# Bootstrap resampling output (%d iterations requested):\n%s\n",
nIterations, headerLine.c_str());
Expand Down Expand Up @@ -169,7 +169,7 @@ int BootstrapErrorsBase( const double *bestfitParams, vector<mp_par> parameterLi
bool saveToFile = false;
string outputLine, iterTemplate;

if (outputFile_ptr != NULL)
if (outputFile_ptr != nullptr)
saveToFile = true;

if (rngSeed > 0)
Expand Down
34 changes: 17 additions & 17 deletions core/imageparams_file_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2020 by Peter Erwin.
// Copyright 2017-2020,2024 by Peter Erwin.
//
// This file is part of Imfit.
//
Expand Down Expand Up @@ -310,7 +310,7 @@ std::tuple<double, mp_par, int> GetParameterAndLimits( const string theLine )
stringPieces.clear();
SplitString(theLine, stringPieces);
// first piece is parameter name, which we ignore; second piece is initial value
paramVal = strtod(stringPieces[1].c_str(), NULL);
paramVal = strtod(stringPieces[1].c_str(), nullptr);

// OK, now we create a new mp_par structure and check for possible parameter limits
// bzero(&newParamLimit, sizeof(mp_par));
Expand All @@ -328,8 +328,8 @@ std::tuple<double, mp_par, int> GetParameterAndLimits( const string theLine )
SplitString(extraPiece, newPieces, ",");
newParamLimit.limited[0] = 1;
newParamLimit.limited[1] = 1;
lowerLimit = strtod(newPieces[0].c_str(), NULL);
upperLimit = strtod(newPieces[1].c_str(), NULL);
lowerLimit = strtod(newPieces[0].c_str(), nullptr);
upperLimit = strtod(newPieces[1].c_str(), nullptr);
if (lowerLimit >= upperLimit) {
fprintf(stderr, "*** WARNING: first parameter limit for \"%s\" (%g) must be < second limit (%g)!\n",
stringPieces[0].c_str(), lowerLimit, upperLimit);
Expand Down Expand Up @@ -372,19 +372,19 @@ int StoreInfoFromLine( const string theLine, ImageInfo& imageInfo )

// floating-point values
if (parameterName == PARAMETER_NAME_GAIN)
imageInfo.gain = strtod(stringPieces[1].c_str(), NULL);
imageInfo.gain = strtod(stringPieces[1].c_str(), nullptr);

else if (parameterName == PARAMETER_NAME_READNOISE)
imageInfo.readNoise = strtod(stringPieces[1].c_str(), NULL);
imageInfo.readNoise = strtod(stringPieces[1].c_str(), nullptr);

else if (parameterName == PARAMETER_NAME_ORIGINAL_SKY)
imageInfo.originalSky = strtod(stringPieces[1].c_str(), NULL);
imageInfo.originalSky = strtod(stringPieces[1].c_str(), nullptr);

else if (parameterName == PARAMETER_NAME_EXPTIME)
imageInfo.expTime = strtod(stringPieces[1].c_str(), NULL);
imageInfo.expTime = strtod(stringPieces[1].c_str(), nullptr);

else if (parameterName == PARAMETER_NAME_WEIGHT)
imageInfo.weight = strtod(stringPieces[1].c_str(), NULL);
imageInfo.weight = strtod(stringPieces[1].c_str(), nullptr);


// Special cases of parameters with optional limits or fixed status
Expand Down Expand Up @@ -430,27 +430,27 @@ int StoreInfoFromLine( const string theLine, ImageInfo& imageInfo )

// integer values
else if (parameterName == PARAMETER_NAME_NCOLS)
imageInfo.nColumns = (int)strtol(stringPieces[1].c_str(), NULL, 0);
imageInfo.nColumns = (int)strtol(stringPieces[1].c_str(), nullptr, 0);

else if (parameterName == PARAMETER_NAME_NROWS)
imageInfo.nRows = (int)strtol(stringPieces[1].c_str(), NULL, 0);
imageInfo.nRows = (int)strtol(stringPieces[1].c_str(), nullptr, 0);

else if (parameterName == PARAMETER_NAME_NROWS_NCOLS) {
vector<string> subPieces;
SplitString(stringPieces[1], subPieces, ",");
imageInfo.nRows = (int)strtol(subPieces[0].c_str(), NULL, 0);
imageInfo.nColumns = (int)strtol(subPieces[1].c_str(), NULL, 0);
imageInfo.nRows = (int)strtol(subPieces[0].c_str(), nullptr, 0);
imageInfo.nColumns = (int)strtol(subPieces[1].c_str(), nullptr, 0);
}

else if (parameterName == PARAMETER_NAME_NCOLS_NROWS) {
vector<string> subPieces;
SplitString(stringPieces[1], subPieces, ",");
imageInfo.nColumns = (int)strtol(subPieces[0].c_str(), NULL, 0);
imageInfo.nRows = (int)strtol(subPieces[1].c_str(), NULL, 0);
imageInfo.nColumns = (int)strtol(subPieces[0].c_str(), nullptr, 0);
imageInfo.nRows = (int)strtol(subPieces[1].c_str(), nullptr, 0);
}

else if (parameterName == PARAMETER_NAME_NCOMBINED)
imageInfo.nCombined = (int)strtol(stringPieces[1].c_str(), NULL, 0);
imageInfo.nCombined = (int)strtol(stringPieces[1].c_str(), nullptr, 0);


// string values
Expand All @@ -476,7 +476,7 @@ int StoreInfoFromLine( const string theLine, ImageInfo& imageInfo )

// Special cases of oversampled PSF specifications
else if (parameterName == PARAMETER_NAME_OVERPSF_SCALE) {
int osampleScale = (int)strtol(stringPieces[1].c_str(), NULL, 0);
int osampleScale = (int)strtol(stringPieces[1].c_str(), nullptr, 0);
imageInfo.psfOversamplingScales.push_back(osampleScale);
imageInfo.nOversamplingScales += 1;
}
Expand Down
12 changes: 6 additions & 6 deletions core/model_object_multimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* March 2017: Created as variation of model_object.cpp
*/

// Copyright 2010--2022 by Peter Erwin.
// Copyright 2010--2024 by Peter Erwin.
//
// This file is part of Imfit.
//
Expand Down Expand Up @@ -467,9 +467,9 @@ void ModelObjectMultImage::PrintDescription( )
/// Basic function which prints to a vector of strings a summary of the
/// best-fitting model, in form suitable for future use as an input config file.
///
/// If errs != NULL, then +/- errors are printed as well
/// If errs != nullptr, then +/- errors are printed as well
///
/// If prefix != NULL, then the specified character (e.g., '#') is prepended to
/// If prefix != nullptr, then the specified character (e.g., '#') is prepended to
/// each output line.
///
/// Note that this version (in ModelObjectMultImage) prints the image-description
Expand Down Expand Up @@ -521,7 +521,7 @@ int ModelObjectMultImage::PrintModelParamsToStrings( vector<string> &stringVecto
std::tie(offsetX0, offsetY0) = modelObjectsVect[i]->GetImageOffsets();
imageX0 += offsetX0;
imageY0 += offsetY0;
if (errs != NULL) {
if (errs != nullptr) {
ExtractImageParams(errs, i, err_pixScale, err_rot, err_iScale, err_imageX0, err_imageY0);
stringVector.push_back(PrintToString(PARAM_FORMAT_WITH_ERRS, prefix, "PIXEL_SCALE",
pixScale, err_pixScale) + "\n");
Expand Down Expand Up @@ -558,7 +558,7 @@ int ModelObjectMultImage::PrintModelParamsToStrings( vector<string> &stringVecto
void ModelObjectMultImage::GetParameterStringsForOneImage( vector<string> &strings,
double params[], int imageNumber, double errors[] )
{
double *paramErrors = NULL;
double *paramErrors = nullptr;

if (! parameterHolderSet)
SetupParamHolder();
Expand All @@ -578,7 +578,7 @@ void ModelObjectMultImage::GetParameterStringsForOneImage( vector<string> &strin
// If errors were supplied, compute offset into the error vector so we skip over
// the image-description-parameter errors and get just the function-parameter errors,
// not the image-description-parameter errors
if (errors != NULL) {
if (errors != nullptr) {
int nImageParams = (nModelObjects - 1)*N_IMAGE_PARAMS;
paramErrors = errors + nImageParams;
}
Expand Down
4 changes: 2 additions & 2 deletions core/model_object_multimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class ModelObjectMultImage : public ModelObject
void SetupParamHolder( );

void GetParameterStringsForOneImage( vector<string> &strings, double params[],
int imageNumber, double errors[]=NULL );
int imageNumber, double errors[]=nullptr );

void GetPerImageFuncStrings( vector<string> &strings, double params[],
int imageNumber, double errors[]=NULL );
int imageNumber, double errors[]=nullptr );

void GetAllImageDescriptionParameters( double params[], double outputImageParams[] );

Expand Down
6 changes: 3 additions & 3 deletions core/print_results_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void SaveImageInfoParameters( double *params, ModelObjectMultImage *multModel,
int whichSolver;
double *imageDescriptionParams = (double *)calloc((size_t)nImages*N_IMAGE_PARAMS,
sizeof(double));
double *imageDescriptionParams_errs = NULL;
double *paramErrs = NULL;
double *imageDescriptionParams_errs = nullptr;
double *paramErrs = nullptr;

multModel->GetAllImageDescriptionParameters(params, imageDescriptionParams);

Expand Down Expand Up @@ -195,7 +195,7 @@ void PrintSingleImageInfoToStrings( const ImageInfo& imInfo, vector<string>& str

if (! refImageFlag) {
// save pixel_scale, image_pa, flux_scale, and initial X0,Y0
if (imageDescParams_errs == NULL) {
if (imageDescParams_errs == nullptr) {
// no errors on these parameters from the fitting process
// note that we have to add line-feed at end of each PARAM_FORMAT-based string
strings.push_back(PrintToString(PARAM_FORMAT, "","PIXEL_SCALE", imageDescParams[0 + offset]) + "\n");
Expand Down
10 changes: 5 additions & 5 deletions core/read_simple_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ long CountDataLines( string& fileName )
char buf[MAXLINE];
long counter = 0;

if ((file_ptr = fopen(fileName.c_str(), "r")) == NULL) {
if ((file_ptr = fopen(fileName.c_str(), "r")) == nullptr) {
fprintf(stderr, FILE_OPEN_ERR_STRING, fileName.c_str());
exit(-1);
}

// First, count how many data lines there are:
while ( !feof(file_ptr) ) {
if ( fgets(buf, MAXLINE - 1, file_ptr) != NULL ) {
if ( fgets(buf, MAXLINE - 1, file_ptr) != nullptr ) {
// Count line if it does *not* starts with "#":
if ( strncmp(buf, "#", 1) != 0 )
counter++;
Expand Down Expand Up @@ -96,14 +96,14 @@ long ReadSimpleParameterFile( string& fileName, long startDataRow, long endDataR
long i = -1; // counts which (input) *data* row we are on
long j = -1; // counts which data row we are storing

if ((file_ptr = fopen(fileName.c_str(), "r")) == NULL) {
if ((file_ptr = fopen(fileName.c_str(), "r")) == nullptr) {
fprintf(stderr, FILE_OPEN_ERR_STRING, fileName.c_str());
exit(-1);
}

while ( !feof(file_ptr) ) {
nRow++;
if ( fgets(buf, MAXLINE - 1, file_ptr) != NULL ) {
if ( fgets(buf, MAXLINE - 1, file_ptr) != nullptr ) {
currentLine = buf;
// Process line if it does *not* starts with "#":
if ( currentLine[0] != '#' ) {
Expand All @@ -122,7 +122,7 @@ long ReadSimpleParameterFile( string& fileName, long startDataRow, long endDataR
exit(-1);
}

xVals[j] = strtod(stringPieces[0].c_str(), (char **)NULL);
xVals[j] = strtod(stringPieces[0].c_str(), (char **)nullptr);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions notes/c++-upgrade_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ NOTES FOR FURTHER C++-11 REWRITES/REFACTORING:


NOTES FOR POSSIBLE C+-17 REWRITES/REFACTORING:
-std=c++17

* How to compile things for C++-17 (i.e., how we ensure compiler gets a
"-std=c++17" flag):
* How to compile imfit, etc. for C++-17 (i.e., how we pass the "-std=c++17" flag
to whatever compiler we're using):
$ scons --modern-cpp <target>


Expand All @@ -16,7 +17,6 @@ wrong compiler.

[] std::optional ? (C++-17 equiv. of Haskell Maybe)
https://www.bfilipek.com/2018/05/using-optional.html
[x]clang++ -std=c++17

"It is recommended to use optional<T> in situations where there
is exactly one, clear (to all parties) reason for having no
Expand Down Expand Up @@ -49,7 +49,7 @@ wrong compiler.



NOTES FOR HYPOTHETICAL C+-20 REWRITES:
NOTES FOR HYPOTHETICAL C++-20 REWRITES:

std::span = simple wrapper for an array that includes its size
NOTE that we could use the ISO C++ Guidelines Support Library (GSL)
Expand Down

0 comments on commit b7e093a

Please sign in to comment.