Skip to content

Commit

Permalink
Finished removing all instances of stcpy, strcat, and sprintf. Code c…
Browse files Browse the repository at this point in the history
…ompiles but is untested.
  • Loading branch information
Rory Barnes committed Aug 6, 2024
1 parent 31e2e24 commit 33272aa
Show file tree
Hide file tree
Showing 17 changed files with 415 additions and 361 deletions.
156 changes: 100 additions & 56 deletions src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,34 +1013,57 @@ void fsUnitsAngMom(UNITS *units, char **cUnit) {
free(cUnitMass);
free(cUnitLength);
free(cUnitTime);

}

void fsUnitsDensity(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];
char *cUnitMass=NULL,*cUnitLength=NULL;

fsUnitsMass(units->iMass, cUnit);
strcat(cUnit, "/");
fsUnitsLength(units->iLength, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^3");
// fsUnitsMass(units->iMass, cUnit);
// strcat(cUnit, "/");
// fsUnitsLength(units->iLength, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^3");
fsUnitsMass(units->iMass, &cUnitMass);
fsUnitsLength(units->iLength, &cUnitLength);
fvFormattedString(cUnit,cUnitMass,"/",cUnitLength,"^3");
free(cUnitMass);
free(cUnitLength);
}

void fsUnitsVel(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];
char *cUnitLength=NULL,*cUnitTime=NULL;

fsUnitsLength(units->iLength, cUnit);
strcat(cUnit, "/");
fsUnitsTime(units->iTime, cTmp);
strcat(cUnit, cTmp);
// fsUnitsLength(units->iLength, cUnit);
// strcat(cUnit, "/");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
fsUnitsLength(units->iLength, &cUnitLength);
fsUnitsTime(units->iTime, &cUnitTime);
fvFormattedString(cUnit,cUnitLength,"/",cUnitTime);
free(cUnitTime);
free(cUnitLength);
}

void fsUnitsRate(int iType, char **cUnit) {
char cTmp[OPTLEN];
char *cUnitTime=NULL;

fvFormattedString(&cUnit, "/");
fsUnitsTime(iType, cTmp);
strcat(cUnit, cTmp);
// fvFormattedString(&cUnit, "/");
// fsUnitsTime(iType, cTmp);
// strcat(cUnit, cTmp);
fsUnitsTime(iType, &cUnitTime);
fvFormattedString(cUnit,"/",cUnitTime);
free(cUnitTime);
}

void fsUnitsRateSquared(int iType, char **cUnit) {
char *cUnitTime=NULL;

// fvFormattedString(&cUnit, "/");
// fsUnitsTime(iType, cTmp);
// strcat(cUnit, cTmp);
fsUnitsTime(iType, &cUnitTime);
fvFormattedString(cUnit,"/",cUnitTime,"^2");
free(cUnitTime);
}

/* double fdUnitsRate(int iTime) {
Expand All @@ -1049,25 +1072,38 @@ void fsUnitsRate(int iType, char **cUnit) {


void fsUnitsAngRate(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];
char *cUnitAngle=NULL,*cUnitTime=NULL;

fsUnitsAngle(units->iAngle, cUnit);
strcat(cUnit, "/");
fsUnitsTime(units->iTime, cTmp);
strcat(cUnit, cTmp);
// fsUnitsAngle(units->iAngle, cUnit);
// strcat(cUnit, "/");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
fsUnitsAngle(units->iAngle, &cUnitAngle);
fsUnitsTime(units->iTime, &cUnitTime);
fvFormattedString(cUnit,cUnitAngle,"/",cUnitTime);
free(cUnitTime);
free(cUnitAngle);
}

void fsUnitsEnergy(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];

fsUnitsMass(units->iMass, cUnit);
strcat(cUnit, "*");
fsUnitsLength(units->iLength, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^2/");
fsUnitsTime(units->iTime, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^2");
char *cUnitMass=NULL,*cUnitLength=NULL,*cUnitTime=NULL;

fsUnitsMass(units->iMass, &cUnitMass);
fsUnitsLength(units->iLength, &cUnitLength);
fsUnitsTime(units->iTime, &cUnitTime);

// fsUnitsMass(units->iMass, cUnit);
// strcat(cUnit, "*");
// fsUnitsLength(units->iLength, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^2/");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^2");
fvFormattedString(cUnit,cUnitMass,"*",cUnitLength,"^2/",cUnitTime,"^2");
free(cUnitMass);
free(cUnitLength);
free(cUnitTime);
}

double fdUnitsEnergy(int iTime, int iMass, int iLength) {
Expand All @@ -1077,16 +1113,24 @@ double fdUnitsEnergy(int iTime, int iMass, int iLength) {
}

void fsUnitsPower(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];

fsUnitsMass(units->iMass, cUnit);
strcat(cUnit, "*");
fsUnitsLength(units->iLength, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^2/");
fsUnitsTime(units->iTime, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^3");
char *cUnitMass=NULL,*cUnitLength=NULL,*cUnitTime=NULL;

fsUnitsMass(units->iMass, &cUnitMass);
fsUnitsLength(units->iLength, &cUnitLength);
fsUnitsTime(units->iTime, &cUnitTime);

// fsUnitsMass(units->iMass, cUnit);
// strcat(cUnit, "*");
// fsUnitsLength(units->iLength, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^2/");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^3");
fvFormattedString(cUnit,cUnitMass,"*",cUnitLength,"^2/",cUnitTime,"^3");
free(cUnitMass);
free(cUnitLength);
free(cUnitTime);
}

double fdUnitsPower(int iTime, int iMass, int iLength) {
Expand All @@ -1095,16 +1139,21 @@ double fdUnitsPower(int iTime, int iMass, int iLength) {
}

void fsUnitsEnergyFlux(UNITS *units, char **cUnit) {
char cTmp[OPTLEN];

fsUnitsEnergy(units, cUnit);
strcat(cUnit, "/(");
fsUnitsLength(units->iLength, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, "^2*");
fsUnitsTime(units->iTime, cTmp);
strcat(cUnit, cTmp);
strcat(cUnit, ")");
char *cUnitMass=NULL,*cUnitLength=NULL,*cUnitTime=NULL;

fsUnitsMass(units->iMass, &cUnitMass);
fsUnitsLength(units->iLength, &cUnitLength);
fsUnitsTime(units->iTime, &cUnitTime);

// fsUnitsEnergy(units, cUnit);
// strcat(cUnit, "/(");
// fsUnitsLength(units->iLength, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, "^2*");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
// strcat(cUnit, ")");
fvFormattedString(cUnit,cUnitMass,"/",cUnitTime,"^3");
}

double fdUnitsEnergyFlux(int iTime, int iMass, int iLength) {
Expand Down Expand Up @@ -1198,9 +1247,4 @@ void InfileCopy(INFILE *dest, INFILE *src) {
for (iLine = 0; iLine < src->iNumLines; iLine++) {
dest->bLineOK[iLine] = src->bLineOK[iLine];
}

/* PHOTOCHEM fields
strcpy(dest->cSpecies,src->cSpecies);
strcpy(dest->cReactions,src->cReactions);
*/
}
1 change: 1 addition & 0 deletions src/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ double fdUnitsAngle(int);
double fdUnitsPower(int, int, int);
double fdUnitsEnergy(int, int, int);
double fdUnitsEnergyFlux(int, int, int);
void fsUnitsRateSquared(int, char **);
// double fdUnitsRate(int);

void fsUnitsLength(int, char**);
Expand Down
2 changes: 1 addition & 1 deletion src/distorb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ else if (body[iBody].bGalHabit) { *dTmp = body[iBody].dLongA;
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit,output->cNeg);
fvFormattedString(cUnit,output->cNeg);
} else {
*dTmp /= fdUnitsAngle(units->iAngle);
fsUnitsAngle(units->iAngle,cUnit);
Expand Down
32 changes: 15 additions & 17 deletions src/eqtide.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ void ReadTidePerts(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
int iBody, iNumIndices = 0, iNumLines = 0;
int *lTmp;
char saTmp[MAXARRAY][OPTLEN];
char **saTmp;

lTmp = malloc(MAXLINES * sizeof(int));

AddOptionStringArray(files->Infile[iFile].cIn, options->cName, saTmp,
AddOptionStringArray(files->Infile[iFile].cIn, options->cName, &saTmp,
&iNumIndices, &iNumLines, lTmp, control->Io.iVerbose);
if (lTmp[0] >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp[0],
Expand Down Expand Up @@ -2294,7 +2294,7 @@ void WriteBodyDsemiDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit,output->cNeg);
fvFormattedString(cUnit,output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime)/fdUnitsLength(units->iLength);
fsUnitsVel(units,cUnit);
Expand Down Expand Up @@ -2326,7 +2326,7 @@ void WriteBodyDeccDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit,output->cNeg);
fvFormattedString(cUnit,output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime);
fsUnitsRate(units->iTime,cUnit);
Expand Down Expand Up @@ -2461,8 +2461,7 @@ void WriteDMeanMotionDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,
fvFormattedString(cUnit, output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime) / fdUnitsLength(units->iLength);
fsUnitsRate(units->iTime, cUnit);
strcat(cUnit, "^2");
fsUnitsRateSquared(units->iTime, cUnit);
}
}

Expand All @@ -2478,7 +2477,7 @@ void WriteDOrbPerDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,

if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
fvFormattedString(&cUnit, output->cNeg);
fvFormattedString(cUnit, output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime) / fdUnitsLength(units->iLength);
fvFormattedString(cUnit, "%s", "");
Expand All @@ -2503,7 +2502,7 @@ void WriteDRotPerDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,
*dTmp *= output->dNeg;
fvFormattedString(cUnit, output->cNeg);
} else {
fvFormattedString(&cUnit, "");
fvFormattedString(cUnit, "");
}
}

Expand All @@ -2526,8 +2525,7 @@ void WriteDRotRateDtEqtide(BODY *body, CONTROL *control, OUTPUT *output,
fvFormattedString(cUnit, output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime) * fdUnitsTime(units->iTime);
fsUnitsRate(units->iTime, cUnit);
strcat(cUnit, "^2");
fsUnitsRateSquared(units->iTime, cUnit);
}
}

Expand Down Expand Up @@ -2833,7 +2831,7 @@ void WriteGammaOrb(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
*dTmp = -1;

/* Negative option? */
strcat(cUnit, "sec");
fsUnitsTime(units->iTime,cUnit);
}

void WriteGammaRot(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
Expand All @@ -2849,7 +2847,7 @@ void WriteGammaRot(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
*dTmp = -1;

/* Negative option? */
strcat(cUnit, "sec");
fsUnitsTime(units->iTime,cUnit);
}

void WriteK2Ocean(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
Expand All @@ -2858,7 +2856,7 @@ void WriteK2Ocean(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,

*dTmp = body[iBody].dK2Ocean;

fvFormattedString(&cUnit, "");
fvFormattedString(cUnit, "");
}

void WriteK2Env(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
Expand All @@ -2867,7 +2865,7 @@ void WriteK2Env(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,

*dTmp = body[iBody].dK2Env;

fvFormattedString(&cUnit, "");
fvFormattedString(cUnit, "");
}

void WriteOblTimescaleEqtide(BODY *body, CONTROL *control, OUTPUT *output,
Expand All @@ -2883,14 +2881,14 @@ void WriteOblTimescaleEqtide(BODY *body, CONTROL *control, OUTPUT *output,
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit,output->cNeg);
fvFormattedString(cUnit,output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime);
fsUnitsTime(units->iTime,cUnit);
}
*/
*dTmp = -1;
fvFormattedString(&cUnit, "");
fvFormattedString(cUnit, "");
}

void WriteRotTimescaleEqtide(BODY *body, CONTROL *control, OUTPUT *output,
Expand Down Expand Up @@ -2992,7 +2990,7 @@ void WriteTideLock(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
char **cUnit) {

*dTmp = control->Evolve.bForceEqSpin[iBody];
strcat(cUnit, "");
fvFormattedString(cUnit, "");
}

void InitializeOutputEqtide(OUTPUT *output, fnWriteOutput fnWrite[]) {
Expand Down
4 changes: 2 additions & 2 deletions src/flare.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ void WriteLXUVFlareUpper(BODY *body,
*dTmp = body[iBody].dLXUVFlareUpper;
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit, output->cNeg);
fvFormattedString(cUnit, output->cNeg);
} else {
*dTmp /= fdUnitsEnergyFlux(units->iTime, units->iMass, units->iLength);
fsUnitsEnergyFlux(units, cUnit);
Expand All @@ -1038,7 +1038,7 @@ void WriteLXUVFlareLower(BODY *body,
*dTmp = body[iBody].dLXUVFlareLower;
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit, output->cNeg);
fvFormattedString(cUnit, output->cNeg);
} else {
*dTmp /= fdUnitsEnergyFlux(units->iTime, units->iMass, units->iLength);
fsUnitsEnergyFlux(units, cUnit);
Expand Down
4 changes: 2 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,11 @@ void ReadModules(BODY *body, CONTROL *control, FILES *files, MODULE *module,
OPTIONS *options, int iFile) {
int iNumIndices = 0, iNumLines = 0, iModule;
int *lTmp;
char saTmp[MAXARRAY][OPTLEN];
char **saTmp;

lTmp = malloc(MAXLINES * sizeof(int));

AddOptionStringArray(files->Infile[iFile].cIn, options->cName, saTmp,
AddOptionStringArray(files->Infile[iFile].cIn, options->cName, &saTmp,
&iNumIndices, &iNumLines, lTmp, control->Io.iVerbose);
if (lTmp[0] >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp[0],
Expand Down
Loading

0 comments on commit 33272aa

Please sign in to comment.