diff --git a/src/control.c b/src/control.c index 032e46fb..e7a7e01e 100644 --- a/src/control.c +++ b/src/control.c @@ -60,7 +60,7 @@ void sort_options(OPTIONS *options, int sorted[]) { SORTED_OPTIONS sorted_options[MODULEOPTEND]; for (iOpt = 0; iOpt < MODULEOPTEND; iOpt++) { sorted_options[iOpt].index = iOpt; - sorted_options[iOpt].name = NULL; + sorted_options[iOpt].name = NULL; fvFormattedString(&sorted_options[iOpt].name, options[iOpt].cName); } qsort(sorted_options, MODULEOPTEND, sizeof(sorted_options[0]), @@ -79,7 +79,7 @@ void sort_output(OUTPUT *output, int sorted[]) { SORTED_OUTPUT sorted_output[MODULEOUTEND]; for (iOpt = 0; iOpt < MODULEOUTEND; iOpt++) { sorted_output[iOpt].index = iOpt; - sorted_output[iOpt].name=NULL; + sorted_output[iOpt].name = NULL; fvFormattedString(&sorted_output[iOpt].name, output[iOpt].cName); } qsort(sorted_output, MODULEOUTEND, sizeof(sorted_output[0]), @@ -94,31 +94,27 @@ void sort_output(OUTPUT *output, int sorted[]) { * Struct Initialization */ -void InitializeFilesOptions(FILES *files,OPTIONS *options) { - int iFile,iOption; +void InitializeFilesOptions(FILES *files, OPTIONS *options) { + int iFile, iOption; - for (iOption=0;iOptioniNumInputs*sizeof(char*)); + for (iOption = 0; iOption < MODULEOPTEND; iOption++) { + options[iOption].cFile = malloc(files->iNumInputs * sizeof(char *)); for (iFile = 0; iFile < files->iNumInputs; iFile++) { options[iOption].iLine[iFile] = -1; options[iOption].cFile[iFile] = NULL; - fvFormattedString(&options[iOption].cFile[iFile], "null"); - if (iFile > 0) { - files->Outfile[iFile-1].caGrid[iOption] = NULL; - files->Outfile[iFile-1].caCol[iOption] = NULL; - } + fvFormattedString(&options[iOption].cFile[iFile], "null"); } } } -void InitializeFiles(FILES *files, OPTIONS *options, char *sPrimaryFile, char **saBodyFiles, int iNumBodies) { +void InitializeFiles(FILES *files, OPTIONS *options, char *sPrimaryFile, + char **saBodyFiles, int iNumBodies) { int iFile; files->iNumInputs = iNumBodies + 1; - files->cLog = NULL; - files->cExe = NULL; - files->Infile = malloc(files->iNumInputs * sizeof(INFILE)); - files->Outfile = malloc(iNumBodies * sizeof(OUTFILE)); + files->cLog = NULL; + files->Infile = malloc(files->iNumInputs * sizeof(INFILE)); + files->Outfile = malloc(iNumBodies * sizeof(OUTFILE)); for (iFile = 0; iFile < files->iNumInputs; iFile++) { files->Infile[iFile].cIn = NULL; @@ -126,17 +122,17 @@ void InitializeFiles(FILES *files, OPTIONS *options, char *sPrimaryFile, char ** files->Infile[0].iNumLines = iGetNumLines(sPrimaryFile); fvFormattedString(&files->Infile[0].cIn, sPrimaryFile); } else { - CheckFileExists(saBodyFiles[iFile-1]); - files->Infile[iFile].iNumLines = iGetNumLines(saBodyFiles[iFile-1]); - fvFormattedString(&files->Infile[iFile].cIn, saBodyFiles[iFile-1]); + CheckFileExists(saBodyFiles[iFile - 1]); + files->Infile[iFile].iNumLines = iGetNumLines(saBodyFiles[iFile - 1]); + fvFormattedString(&files->Infile[iFile].cIn, saBodyFiles[iFile - 1]); - files->Outfile[iFile-1].cOut = NULL; + files->Outfile[iFile - 1].cOut = NULL; // Outfile names assigned after reading in output file names } RecordCommentsAndWhiteSpace(&files->Infile[iFile]); } - InitializeFilesOptions(files,options); + InitializeFilesOptions(files, options); } void InitializePropsAux(CONTROL *control, MODULE *module) { @@ -161,7 +157,6 @@ void InitializePropsAux(CONTROL *control, MODULE *module) { malloc(2 * module->iNumModules[iBody] * sizeof(fnPropsAuxModule *)); } } - } void InitilizeForceBehavior(CONTROL *control, MODULE *module) { @@ -336,8 +331,8 @@ void WriteDescription(char cLongDescr[], char cDescr[], int iMaxChars) { char **cLine; cLine = malloc(MAXARRAY * sizeof(char *)); - for (iWord=0;iWordiLength, &cUnitLength); fsUnitsTime(units->iTime, &cUnitTime); - fvFormattedString(cUnit, "%s^2/%s",cUnitLength,cUnitTime); + fvFormattedString(cUnit, "%s^2/%s", cUnitLength, cUnitTime); free(cUnitLength); free(cUnitTime); } @@ -1098,7 +1094,7 @@ void fsUnitsDensity(UNITS *units, char **cUnit) { fsUnitsMass(units->iMass, &cUnitMass); fsUnitsLength(units->iLength, &cUnitLength); - fvFormattedString(cUnit, "%s/%s^3",cUnitMass, cUnitLength); + fvFormattedString(cUnit, "%s/%s^3", cUnitMass, cUnitLength); free(cUnitMass); free(cUnitLength); } @@ -1179,7 +1175,7 @@ double fdUnitsPower(int iTime, int iMass, int iLength) { } void fsUnitsEnergyFlux(UNITS *units, char **cUnit) { - char *cUnitMass = NULL,*cUnitTime = NULL; + char *cUnitMass = NULL, *cUnitTime = NULL; fsUnitsMass(units->iMass, &cUnitMass); fsUnitsTime(units->iTime, &cUnitTime); diff --git a/src/options.c b/src/options.c index d4fc8e10..09ccee1a 100644 --- a/src/options.c +++ b/src/options.c @@ -269,7 +269,7 @@ void AddOptionStringArray(char *cFile, char *cOption, char ***saInput, GetLine(cFile, cOption, &cLine, &iLine[0], iVerbose); GetWords(cLine, cTmp, &iNumWords, &bContinue); - *iNumLines = 1; + *iNumLines = 1; saInputCopy = (char **)malloc(MAXARRAY * sizeof(char *)); for (iWord = 0; iWord < MAXARRAY; iWord++) { @@ -344,9 +344,10 @@ void AddOptionDouble(char *cFile, char *cOption, double *dInput, int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { int iNumOptionsRead = sscanf(cLine, "%s %lf", cTmp, dInput); - if (iNumOptionsRead != 2) { - printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); - printf("\tcLine=%s, cTmp=%s, dInput=%lf\n", cLine, cTmp, *dInput ); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n", iNumOptionsRead, + cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%lf\n", cLine, cTmp, *dInput); exit(EXIT_INPUT); } } @@ -360,11 +361,12 @@ void AddOptionInt(char *cFile, char *cOption, int *iInput, int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { int iNumOptionsRead = sscanf(cLine, "%s %d", cTmp, iInput); - if (iNumOptionsRead != 2) { - printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); - printf("\tcLine=%s, cTmp=%s, dInput=%d\n", cLine, cTmp, *iInput ); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n", iNumOptionsRead, + cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%d\n", cLine, cTmp, *iInput); exit(EXIT_INPUT); - } + } } free(cLine); } @@ -395,11 +397,12 @@ void AddOptionString(char *cFile, char *cOption, char cInput[], int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { int iNumOptionsRead = sscanf(cLine, "%s %s", cTmp, cInput); - if (iNumOptionsRead != 2) { - printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); - printf("\tcLine=%s, cTmp=%s, dInput=%s\n", cLine, cTmp, cInput ); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n", iNumOptionsRead, + cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%s\n", cLine, cTmp, cInput); exit(EXIT_INPUT); - } + } } free(cLine); } @@ -465,8 +468,8 @@ void CheckFileExists(char *cFile) { fclose(fp); } -int fbBlankLine(char *cLine,int iLineLength) { - int iPos,bBlank = 1; +int fbBlankLine(char *cLine, int iLineLength) { + int iPos, bBlank = 1; for (iPos = 0; iPos < LINE; iPos++) { if (!isspace(cLine[iPos]) && cLine[iPos] != '\0') { bBlank = 0; @@ -480,8 +483,8 @@ void RecordCommentsAndWhiteSpace(INFILE *infile) { char cLine[LINE]; FILE *fp; - fp = fopen(infile->cIn, "r"); - infile->bLineOK = malloc(infile->iNumLines * sizeof(int)); + fp = fopen(infile->cIn, "r"); + infile->bLineOK = malloc(infile->iNumLines * sizeof(int)); for (iLine = 0; iLine < infile->iNumLines; iLine++) { infile->bLineOK[iLine] = 0; @@ -492,7 +495,7 @@ void RecordCommentsAndWhiteSpace(INFILE *infile) { fprintf(stderr, "ERROR: Unable to open %s.\n", infile->cIn); exit(EXIT_INPUT); } - if (fbCommentedLine(cLine, LINE) || fbBlankLine(cLine,LINE)) { + if (fbCommentedLine(cLine, LINE) || fbBlankLine(cLine, LINE)) { infile->bLineOK[iLine] = 1; } } @@ -1089,8 +1092,9 @@ void ReadSystemName(CONTROL *control, FILES *files, OPTIONS *options, } } -void ReadBodyFileNames(BODY **body,CONTROL *control, FILES *files, OPTIONS *options, - char *cFile, char ***saBodyFiles, int *iNumLines, int *iaLines) { +void ReadBodyFileNames(BODY **body, CONTROL *control, FILES *files, + OPTIONS *options, char *cFile, char ***saBodyFiles, + int *iNumLines, int *iaLines) { int iNumIndices; AddOptionStringArray(cFile, options->cName, saBodyFiles, &iNumIndices, @@ -1132,16 +1136,19 @@ void ReadBodyFileNames(BODY **body,CONTROL *control, FILES *files, OPTIONS *opti void ReadInitialOptions(BODY **body, CONTROL *control, FILES *files, MODULE *module, OPTIONS *options, OUTPUT *output, SYSTEM *system, char *sPrimaryFile) { - int iFile, iBody, iModule,iNumBodyFileLines,*iaLines; + int iFile, iBody, iModule, iNumBodyFileLines, *iaLines; char **saBodyFiles; - iaLines=malloc(MAXLINES*sizeof(int)); + iaLines = malloc(MAXLINES * sizeof(int)); - ReadBodyFileNames(body, control, files, &options[OPT_BODYFILES], sPrimaryFile, &saBodyFiles, &iNumBodyFileLines, iaLines); + ReadBodyFileNames(body, control, files, &options[OPT_BODYFILES], sPrimaryFile, + &saBodyFiles, &iNumBodyFileLines, iaLines); - InitializeFiles(files, options, sPrimaryFile, saBodyFiles, control->Evolve.iNumBodies); + InitializeFiles(files, options, sPrimaryFile, saBodyFiles, + control->Evolve.iNumBodies); - UpdateFoundOptionMulti(&files->Infile[0], &options[OPT_BODYFILES], iaLines, iNumBodyFileLines, 0); + UpdateFoundOptionMulti(&files->Infile[0], &options[OPT_BODYFILES], iaLines, + iNumBodyFileLines, 0); /* Initialize functions in the module struct */ InitializeModule(*body, control, module); @@ -1525,7 +1532,7 @@ void ReadBodyName(BODY *body, CONTROL *control, FILES *files, OPTIONS *options, /* Cannot exist in primary input file -- Each body has an output file */ NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp, control->Io.iVerbose); - body[iFile-1].cName=NULL; + body[iFile - 1].cName = NULL; if (strlen(cTmp) > 0) { fvFormattedString(&body[iFile - 1].cName, cTmp); } else { @@ -1533,7 +1540,7 @@ void ReadBodyName(BODY *body, CONTROL *control, FILES *files, OPTIONS *options, } UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile); } else if (iFile > 0) { - body[iFile-1].cName=NULL; + body[iFile - 1].cName = NULL; fvFormattedString(&body[iFile - 1].cName, "%d", iFile); } } @@ -1550,11 +1557,11 @@ void ReadColor(BODY *body, CONTROL *control, FILES *files, OPTIONS *options, if (lTmp >= 0) { NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp, control->Io.iVerbose); - body[iFile-1].sColor = NULL; + body[iFile - 1].sColor = NULL; fvFormattedString(&body[iFile - 1].sColor, cTmp); UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile); } else if (iFile > 0) { - body[iFile-1].sColor = NULL; + body[iFile - 1].sColor = NULL; fvFormattedString(&body[iFile - 1].sColor, options->cDefault); } } @@ -2594,368 +2601,438 @@ void ReadCosObl(BODY *body, CONTROL *control, FILES *files, OPTIONS *options, } /* - * Output Order -- This one is special and takes different arguments + * OutputOrder and GridOutput Functions */ - -void ReadOutputOrder(FILES *files, MODULE *module, OPTIONS *options, - OUTPUT *output, int iFile, int iVerbose) { - int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 1, iNumGrid = 0,iOption; - int k, iOut = -1, *lTmp, iCol, jCol; - char **saTmp, *cTmp = NULL, **cOption, *cOut = NULL; - int iLen1, iLen2; - - lTmp = malloc(MAXLINES * sizeof(int)); - cOption = malloc(MAXARRAY * sizeof(char *)); - for (iOption=0;iOptionInfile[iFile].cIn, options[OPT_OUTPUTORDER].cName, - &saTmp, &iNumIndices, &files->Infile[iFile].iNumLines, - lTmp, iVerbose); +void fvCheckTooManyOutputs(FILES *files, int iFile, int iNumArgs, + int iVerbose) { + if (iNumArgs >= MAXARRAY) { + if (iVerbose >= VERBERR) { + fprintf(stderr, + "ERROR: Too many output options in file %s. Either reduce, or " + "increase MAXARRAY in vplanet.h.\n", + files->Infile[iFile].cIn); + } + exit(EXIT_INPUT); + } +} - if (lTmp[0] >= 0) { - NotPrimaryInput(iFile, options[OPT_OUTPUTORDER].cName, - files->Infile[iFile].cIn, lTmp[0], iVerbose); +void fvRecordAndRemoveOutputNegativeSigns(char **saArguments, int *baNeg, + int iNumArgs) { + int iArg, iPos; - if (iNumIndices >= MAXARRAY) { - if (iVerbose >= VERBERR) { - fprintf(stderr, - "ERROR: Too many output options in file %s. Either reduce, or " - "increase MAXARRAY in vplanet.h.\n", - files->Infile[iFile].cIn); + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (saArguments[iArg][0] == 45) { + baNeg[iArg] = 1; + for (iPos = 0; iPos < strlen(saArguments[iArg]); iPos++) { + saArguments[iArg][iPos] = saArguments[iArg][iPos + 1]; } - exit(EXIT_INPUT); + saArguments[iArg][strlen(saArguments[iArg])] = 0; + } else { + baNeg[iArg] = 0; } + } +} - /* First remove and record negative signs */ - for (i = 0; i < iNumIndices; i++) { - if (saTmp[i][0] == 45) { - /* Option is negative */ - bNeg[i] = 1; - /* Now remove negative sign */ - for (j = 0; j < strlen(saTmp[i]); j++) { - saTmp[i][j] = saTmp[i][j + 1]; - } - saTmp[i][strlen(saTmp[i])] = 0; +void fvAssignOutputMatchData(char ***saMatch, char *sOut, int *iaMatch, + int *iaNumMatches, int iArg, int iOut) { + fvFormattedString(&saMatch[iArg][iaNumMatches[iArg]], sOut); + iaNumMatches[iArg]++; + iaMatch[iArg] = iOut; +} + +void fvCheckUnambiguousMatch(OUTPUT *output, char ***saMatch, char *sArg, + char *sOut, int *iaMatch, int *iaNumMatches, + int iLen1, int iLen2, int iOut, int iArg) { + int iLen; + + if (iLen1 < iLen2) { + iLen = iLen1; + } else { + iLen = iLen2; + } + if (memcmp(sLower(sArg), sLower(sOut), iLen) == 0 && iLen1 > iLen2) { + fvAssignOutputMatchData(saMatch, output[iOut].cName, iaMatch, iaNumMatches, + iArg, iOut); + } +} + +void fvCountAndRecordOutputMatches(OUTPUT *output, char **saArguments, + char ***saMatch, int *iaMatch, + int *iaNumMatches, int iNumArgs) { + int iArg, iLen, iLen1, iLen2, iOut, iMatch, iPerfectMatch; + char *sArg = NULL, *sOut = NULL; + + for (iArg = 0; iArg < iNumArgs; iArg++) { + iaNumMatches[iArg] = 0; + iPerfectMatch = -1; + fvFormattedString(&sArg, saArguments[iArg]); + + for (iOut = 0; iOut < MODULEOUTEND; iOut++) { + fvFormattedString(&sOut, output[iOut].cName); + iLen1 = strlen(sOut); + iLen2 = strlen(sArg); + + if ((iLen1 == iLen2) && + (memcmp(sLower(sArg), sLower(sOut), strlen(sOut)) == 0)) { + fvAssignOutputMatchData(saMatch, output[iOut].cName, iaMatch, + iaNumMatches, iArg, iOut); + iPerfectMatch = iOut; } else { - bNeg[i] = 0; + fvCheckUnambiguousMatch(output, saMatch, sArg, sOut, iaMatch, + iaNumMatches, iLen1, iLen2, iOut, iArg); } } + if (iPerfectMatch > -1) { + for (iMatch = 0; iMatch < iaNumMatches[iArg]; iMatch++) { + saMatch[iArg][iMatch] = NULL; + } + iaNumMatches[iArg] = 0; + fvAssignOutputMatchData(saMatch, output[iPerfectMatch].cName, iaMatch, + iaNumMatches, iArg, iPerfectMatch); + } + } +} - /* Check for ambiguity */ - for (i = 0; i < iNumIndices; i++) { - count = 0; /* Number of possibilities */ - // for (j = 0; j < OPTLEN; j++) { - // cTmp[j] = 0; - // } - fvFormattedString(&cTmp, saTmp[i]); - for (j = 0; j < MODULEOUTEND; j++) { - // for (k = 0; k < OPTLEN; k++) { - // cOut[k] = 0; - // } - fvFormattedString(&cOut, output[j].cName); - iLen1 = strlen(cOut); - iLen2 = strlen(cTmp); - /* Check for perfect match */ - if ((iLen1 == iLen2) && - (memcmp(sLower(cTmp), sLower(cOut), strlen(cOut)) == 0)) { - /* Output option found! */ - fvFormattedString(&cOption[count], output[j].cName); - count = 1; - iOut = j; - if (output[j].bGrid == 1) { - // Exit! - iNumGrid += 1; - } - j = MODULEOUTEND; /* Poor man's break! */ - } else { - if (iLen1 < iLen2) { - iLen = iLen1; - } else { - iLen = iLen2; - } +void fvCheckNoOutputMatch(FILES *files, char **saArguments, int *lTmp, + int *iaNumMatches, int iNumArgs, int iFile, + int iVerbose) { + int bExit, iArg; - if (memcmp(sLower(cTmp), sLower(cOut), iLen) == 0 && iLen1 > iLen2) { - /* Output option found! */ - fvFormattedString(&cOption[count], output[j].cName); - count++; - iOut = j; - if (output[j].bGrid == 1) { - // Exit! - iNumGrid += 1; - } - } - } + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (iaNumMatches[iArg] == 0) { + if (iVerbose >= VERBERR) { + fprintf(stderr, "ERROR: Unknown output option \"%s\".\n", + saArguments[iArg]); } + bExit = 1; + } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} - if (count > 1) { - /* More than one possibility */ - if (iVerbose >= VERBERR) { - fprintf(stderr, - "ERROR: Output option \"%s\" is ambiguous. Options are ", - saTmp[i]); - for (j = 0; j < count; j++) { - fprintf(stderr, "%s", cOption[j]); - if (j < count - 1) { - fprintf(stderr, ", "); - } +void fvCheckOutputAmbiguity(FILES *files, char **saArguments, char ***saMatch, + int *lTmp, int *iaNumMatches, int iNumArgs, + int iFile, int iVerbose) { + int bExit, iArg, iMatch; + + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (iaNumMatches[iArg] > 1) { + if (iVerbose >= VERBERR) { + fprintf(stderr, + "ERROR: Output option \"%s\" is ambiguous. Options are ", + saArguments[iArg]); + for (iMatch = 0; iMatch < iaNumMatches[iArg]; iMatch++) { + fprintf(stderr, "%s", saMatch[iArg][iMatch]); + if (iMatch < iaNumMatches[iArg] - 1) { + fprintf(stderr, ", "); } - fprintf(stderr, ".\n"); } - LineExit(files->Infile[iFile].cIn, lTmp[0]); + fprintf(stderr, ".\n"); } + bExit = 1; + } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} - if (!count) { - /* Option not found */ +void fvCheckOutputNegativesAllowed(FILES *files, OUTPUT *output, + char **saArguments, char ***saMatch, + int *lTmp, int *baNeg, int *iaMatch, + int *iaNumMatches, int iNumArgs, int iFile, + int iVerbose) { + int bExit, iArg; + + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (baNeg[iArg] == 1) { + if (output[iaMatch[iArg]].bNeg == 0) { if (iVerbose >= VERBERR) { - fprintf(stderr, "ERROR: Unknown output option \"%s\".\n", saTmp[i]); - } - LineExit(files->Infile[iFile].cIn, lTmp[0]); - } - - if (count == 1) { - /* Unique option */ - - /* Verify and record negative options */ - if (bNeg[i]) { - // Is the negative option allowed? - if (!output[iOut].bNeg) { /* No */ - if (iVerbose >= VERBERR) { - fprintf(stderr, "ERROR: Output option %s ", saTmp[i]); - if (strlen(saTmp[i]) < strlen(output[iOut].cName)) { - fprintf(stderr, "(= %s) ", output[iOut].cName); - } - fprintf(stderr, "cannot be negative.\n"); - } - LineExit(files->Infile[iFile].cIn, lTmp[0]); - } else { // Yes, initialize bDoNeg to true - output[iOut].bDoNeg[iFile - 1] = 1; + fprintf(stderr, "ERROR: Output option %s ", saArguments[iArg]); + if (strlen(saArguments[iArg]) < strlen(output[iaMatch[iArg]].cName)) { + fprintf(stderr, "(= %s) ", output[iaMatch[iArg]].cName); } - } else { // Negative option not set, initialize bDoNeg to false - output[iOut].bDoNeg[iFile - 1] = 0; - } - if (output[iOut].bGrid == 0 || output[iOut].bGrid == 2) { - fvFormattedString(&files->Outfile[iFile - 1].caCol[i], - output[iOut].cName); - } else { - memset(files->Outfile[iFile - 1].caGrid[iNumGrid - 1], '\0', OPTLEN); - fvFormattedString(&files->Outfile[iFile - 1].caGrid[iNumGrid - 1], - output[iOut].cName); - } - // Is option part of selected modules? - if (module->iBitSum[iFile - 1] & output[iOut].iModuleBit) { - // Parameter is part of selected modules - } else { - fprintf(stderr, "ERROR: Output parameter %s requires module(s): ", - output[iOut].cName); - PrintModuleList(stderr, output[iOut].iModuleBit, 0); - fprintf(stderr, "\n"); - ok = 0; + fprintf(stderr, "cannot be negative.\n"); } + bExit = 1; } } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} + +void fvCheckOutputModuleCompatibility(FILES *files, MODULE *module, + OPTIONS *options, OUTPUT *output, + int *lTmp, int *iaMatch, int iNumArgs, + int iFile, int iVerbose) { + int bExit, iArg; - if (!ok) { - DoubleLineExit(files->Infile[iFile].cIn, files->Infile[iFile].cIn, - lTmp[0], options[OPT_MODULES].iLine[iFile]); + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (!(module->iBitSum[iFile - 1] & output[iaMatch[iArg]].iModuleBit)) { + if (iVerbose >= VERBERR) { + fprintf(stderr, "ERROR: Output parameter %s requires module(s): ", + output[iaMatch[iArg]].cName); + PrintModuleList(stderr, output[iaMatch[iArg]].iModuleBit, 0); + fprintf(stderr, "\n"); + } + bExit = 1; } + } + if (bExit) { + DoubleLineExit(files->Infile[iFile].cIn, files->Infile[iFile].cIn, lTmp[0], + options[OPT_MODULES].iLine[iFile]); + } +} - /* Check for duplicate columns, which is not allowed becaue it would be - incompatible with BigPlanet's employment of Pandas data frames. */ - if (iNumIndices > 0) { - ok = 1; - for (iCol = 0; iCol < iNumIndices; iCol++) { - for (jCol = iCol + 1; jCol < iNumIndices; jCol++) { - iLen1 = strlen(files->Outfile[iFile - 1].caCol[iCol]); - iLen2 = strlen(files->Outfile[iFile - 1].caCol[jCol]); - /* Check for perfect match */ - if ((iLen1 == iLen2) && - (memcmp(files->Outfile[iFile - 1].caCol[iCol], - files->Outfile[iFile - 1].caCol[jCol], - strlen(files->Outfile[iFile - 1].caCol[iCol])) == 0)) { - fprintf(stderr, - "ERROR: Output option %s selected twice, which is " - "not allowed.\n", - files->Outfile[iFile - 1].caCol[iCol]); - ok = 0; - } +/* Check for duplicate columns, which is not allowed becaue it would be + incompatible with BigPlanet's employment of Pandas data frames. */ +void fvCheckOutputDuplication(FILES *files, char ***saMatch, int *lTmp, + int iNumArgs, int iFile, int iVerbose) { + int bExit, iArg, jArg, iLen1, iLen2; + + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + for (jArg = iArg + 1; jArg < iNumArgs; jArg++) { + iLen1 = strlen(saMatch[iArg][0]); + iLen2 = strlen(saMatch[jArg][0]); + if ((iLen1 == iLen2) && + memcmp(saMatch[iArg][0], saMatch[jArg][0], iLen1) == 0) { + if (iVerbose >= VERBINPUT) { + fprintf(stderr, + "ERROR: Output option %s requested more than once, which is " + "not allowed.\n", + saMatch[iArg][0]); } + bExit = 1; } + } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} - if (!ok) { - LineExit(files->Infile[iFile].cIn, lTmp[0]); +void fvCheckNotGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, + char ***saMatch, int *iaMatch, int *lTmp, + int iNumArgs, int iFile, int iVerbose) { + int bExit, iArg; + + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (output[iaMatch[iArg]].bGrid == 1) { + if (iVerbose >= VERBINPUT) { + fprintf(stderr, + "ERROR: Output option %s can only be an argument for option " + "%s.\n", + saMatch[iArg][0], options[OPT_GRIDOUTPUT].cName); } + bExit = 1; } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} - // All checks pass, update structs - files->Outfile[iFile - 1].iNumCols = iNumIndices; - /* - files->Outfile[iFile-1].iNumCols = iNumIndices-iNumGrid; - files->Outfile[iFile-1].iNumGrid = iNumGrid; - */ - UpdateFoundOptionMulti(&files->Infile[iFile], &options[OPT_OUTPUTORDER], - lTmp, files->Infile[iFile].iNumLines, iFile); - } else { - files->Outfile[iFile - 1].iNumCols = 0; +void fvAssignOutputData(FILES *files, OUTPUT *output, char **saOutput, + int *baNeg, int *iaMatch, int *iNumOut, int iNumArgs, + int iFile) { + int iArg; + + for (iArg = 0; iArg < iNumArgs; iArg++) { + saOutput[iArg] = NULL; + fvFormattedString(&saOutput[iArg], output[iaMatch[iArg]].cName); + *iNumOut = iNumArgs; + if (baNeg[iArg]) { + output[iaMatch[iArg]].bDoNeg[iFile - 1] = 1; + } else { + output[iaMatch[iArg]].bDoNeg[iFile - 1] = 0; + } } +} - free(lTmp); - free(cTmp); - free(cOption); - free(saTmp); - free(cOut); +void fvFreeOuputArrays(char ***saMatch, int *baNeg, int *iaNumMatches, + int *iaMatch) { + free(baNeg); + free(iaNumMatches); + free(iaMatch); + free(saMatch); } -void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile, - int iVerbose) { - int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 0, iNumGrid = 0,iOption; - int k, iOut = -1, *lTmp; - char **saTmp, *cTmp=NULL, **cOption, *cOut=NULL; - int iLen1, iLen2; +void fvGeneralOutputChecks(FILES *files, MODULE *module, OPTIONS *options, + OUTPUT *output, char ***saOutput, char **saArguments, + char ****saMatch, int **baNeg, int *lTmp, + int **iaMatch, int **iaNumMatches, int iNumArgs, + int iFile, int iOption, int iVerbose) { + + NotPrimaryInput(iFile, options[iOption].cName, files->Infile[iFile].cIn, + lTmp[0], iVerbose); + fvCheckTooManyOutputs(files, iFile, iNumArgs, iVerbose); + fvAllocateOutputArrays(saMatch, saOutput, baNeg, iaMatch, iaNumMatches, + iNumArgs, iFile); + fvRecordAndRemoveOutputNegativeSigns(saArguments, *baNeg, iNumArgs); + fvCountAndRecordOutputMatches(output, saArguments, *saMatch, *iaMatch, + *iaNumMatches, iNumArgs); + fvCheckNoOutputMatch(files, saArguments, lTmp, *iaNumMatches, iNumArgs, iFile, + iVerbose); + fvCheckOutputAmbiguity(files, saArguments, *saMatch, lTmp, *iaNumMatches, + iNumArgs, iFile, iVerbose); + fvCheckOutputNegativesAllowed(files, output, saArguments, *saMatch, lTmp, + *baNeg, *iaMatch, *iaNumMatches, iNumArgs, + iFile, iVerbose); + fvCheckOutputModuleCompatibility(files, module, options, output, lTmp, + *iaMatch, iNumArgs, iFile, iVerbose); + fvCheckOutputDuplication(files, *saMatch, lTmp, iNumArgs, iFile, iVerbose); +} - lTmp = malloc(MAXLINES * sizeof(int)); - cOption = malloc(MAXARRAY * sizeof(char *)); - for (iOption=0;iOptionInfile[iFile], &options[iOption], lTmp, + files->Infile[iFile].iNumLines, iFile); + fvFreeOuputArrays(saMatch, baNeg, iaNumMatches, iaMatch); +} - AddOptionStringArray(files->Infile[iFile].cIn, options[OPT_GRIDOUTPUT].cName, - &saTmp, &iNumIndices, &files->Infile[iFile].iNumLines, +void fvAssignOutputOrder(FILES *files, MODULE *module, OPTIONS *options, + OUTPUT *output, char **saArguments, char ***saOutput, + int *lTmp, int iNumArgs, int iFile, int iVerbose) { + int *baNeg; + int *iaNumMatches, *iaMatch; + char ***saMatch; + + fvGeneralOutputChecks(files, module, options, output, saOutput, saArguments, + &saMatch, &baNeg, lTmp, &iaMatch, &iaNumMatches, + iNumArgs, iFile, OPT_OUTPUTORDER, iVerbose); + fvCheckNotGridOutput(files, options, output, saMatch, iaMatch, lTmp, iNumArgs, + iFile, iVerbose); + fvfinalizeOutput(files, module, options, output, saArguments, saMatch, + files->Outfile[iFile - 1].caCol, + &(files->Outfile[iFile - 1].iNumCols), baNeg, lTmp, iaMatch, + iaNumMatches, iNumArgs, iFile, OPT_OUTPUTORDER, iVerbose); +} + +void ReadOutputOrder(FILES *files, MODULE *module, OPTIONS *options, + OUTPUT *output, int iFile, int iVerbose) { + char **saArguments; + int *lTmp, iNumArgs; + + lTmp = malloc(MAXLINES * sizeof(int)); + AddOptionStringArray(files->Infile[iFile].cIn, options[OPT_OUTPUTORDER].cName, + &saArguments, &iNumArgs, &files->Infile[iFile].iNumLines, lTmp, iVerbose); if (lTmp[0] >= 0) { - NotPrimaryInput(iFile, options[OPT_GRIDOUTPUT].cName, - files->Infile[iFile].cIn, lTmp[0], iVerbose); - - /* First remove and record negative signs */ - for (i = 0; i < iNumIndices; i++) { - if (saTmp[i][0] == 45) { - /* Option is negative */ - bNeg[i] = 1; - /* Now remove negative sign */ - for (j = 0; j < strlen(saTmp[i]); j++) { - saTmp[i][j] = saTmp[i][j + 1]; - } - saTmp[i][strlen(saTmp[i])] = 0; - } else { - bNeg[i] = 0; - } - } + fvAssignOutputOrder(files, module, options, output, saArguments, + &files->Outfile[iFile - 1].caCol, lTmp, iNumArgs, iFile, + iVerbose); + } else { + files->Outfile[iFile - 1].iNumCols = 0; + } - /* Check for ambiguity */ - for (i = 0; i < iNumIndices; i++) { - count = 0; /* Number of possibilities */ - // for (j = 0; j < OPTLEN; j++) { - // cTmp[j] = 0; - // } - fvFormattedString(&cTmp, saTmp[i]); - for (j = 0; j < MODULEOUTEND; j++) { - // for (k = 0; k < OPTLEN; k++) { - // cOut[k] = 0; - // } - fvFormattedString(&cOut, output[j].cName); - iLen1 = strlen(cOut); - iLen2 = strlen(cTmp); - /* Check for perfect match */ - if ((iLen1 == iLen2) && - (memcmp(sLower(cTmp), sLower(cOut), strlen(cOut)) == 0)) { - /* Output option found! */ - fvFormattedString(&cOption[count], output[j].cName); - count = 1; - iOut = j; - if (output[j].bGrid == 1 || output[j].bGrid == 2) { - iNumGrid += 1; - } - j = MODULEOUTEND; /* Break! */ - } else { - if (iLen1 < iLen2) { - iLen = iLen1; - } else { - iLen = iLen2; - } + free(lTmp); + free(saArguments); +} - if (memcmp(sLower(cTmp), sLower(cOut), iLen) == 0 && iLen1 > iLen2) { - /* Output option found! */ - fvFormattedString(&cOption[count], output[j].cName); - count++; - iOut = j; - if (output[j].bGrid == 1 || output[j].bGrid == 2) { - iNumGrid += 1; - } - } - } - } +void fvCheckNotOutputOrder(FILES *files, OPTIONS *options, OUTPUT *output, + char ***saMatch, int *iaMatch, int *lTmp, + int iNumArgs, int iFile, int iVerbose) { + int bExit, iArg; - if (count > 1) { - /* More than one possibility */ - if (iVerbose >= VERBERR) { - fprintf(stderr, - "ERROR: Output option \"%s\" is ambiguous. Options are ", - saTmp[i]); - for (j = 0; j < count; j++) { - fprintf(stderr, "%s", cOption[j]); - if (j < count - 1) { - fprintf(stderr, ", "); - } - } - fprintf(stderr, ".\n"); - } - LineExit(files->Infile[iFile].cIn, lTmp[0]); + bExit = 0; + for (iArg = 0; iArg < iNumArgs; iArg++) { + if (output[iaMatch[iArg]].bGrid == 0) { + if (iVerbose >= VERBINPUT) { + fprintf(stderr, + "ERROR: Output option %s can only be an argument for option " + "%s.\n", + saMatch[iArg][0], options[OPT_OUTPUTORDER].cName); } + bExit = 1; + } + } + if (bExit) { + LineExit(files->Infile[iFile].cIn, lTmp[0]); + } +} - if (!count) { - /* Option not found */ - if (iVerbose >= VERBERR) { - fprintf(stderr, "ERROR: Unknown output option \"%s\".\n", saTmp[i]); - } - LineExit(files->Infile[iFile].cIn, lTmp[0]); - } +void fvAssignGridOutput(FILES *files, MODULE *module, OPTIONS *options, + OUTPUT *output, char **saArguments, char ***saOutput, + int *lTmp, int iNumArgs, int iFile, int iVerbose) { + int *baNeg; + int *iaNumMatches, *iaMatch; + char ***saMatch; + + fvGeneralOutputChecks(files, module, options, output, saOutput, saArguments, + &saMatch, &baNeg, lTmp, &iaMatch, &iaNumMatches, + iNumArgs, iFile, OPT_GRIDOUTPUT, iVerbose); + fvCheckNotOutputOrder(files, options, output, saMatch, iaMatch, lTmp, + iNumArgs, iFile, iVerbose); + fvfinalizeOutput(files, module, options, output, saArguments, saMatch, + files->Outfile[iFile - 1].caGrid, + &files->Outfile[iFile - 1].iNumGrid, baNeg, lTmp, iaMatch, + iaNumMatches, iNumArgs, iFile, OPT_GRIDOUTPUT, iVerbose); +} - if (count == 1) { - /* Unique option */ - - /* Verify and record negative options */ - if (bNeg[i]) { - // Is the negative option allowed? - if (!output[iOut].bNeg) { /* No */ - if (iVerbose >= VERBERR) { - fprintf(stderr, "ERROR: Output option %s ", saTmp[i]); - if (strlen(saTmp[i]) < strlen(output[iOut].cName)) { - fprintf(stderr, "(= %s) ", output[iOut].cName); - } - fprintf(stderr, "cannot be negative.\n"); - } - LineExit(files->Infile[iFile].cIn, lTmp[0]); - } else { // Yes, initialize bDoNeg to true - output[iOut].bDoNeg[iFile - 1] = 1; - } - } else { // Negative option not set, initialize bDoNeg to false - output[iOut].bDoNeg[iFile - 1] = 0; - } - if (output[iOut].bGrid == 0) { - memset(files->Outfile[iFile - 1].caCol[i], '\0', OPTLEN); - fvFormattedString(&files->Outfile[iFile - 1].caCol[i], - output[iOut].cName); - } else { - fvFormattedString(&files->Outfile[iFile - 1].caGrid[iNumGrid - 1], - output[iOut].cName); - } - } - } +void ReadGridOutput(FILES *files, MODULE *module, OPTIONS *options, + OUTPUT *output, int iFile, int iVerbose) { + char **saArguments; + int *lTmp, iNumArgs; - UpdateFoundOptionMulti(&files->Infile[iFile], &options[OPT_GRIDOUTPUT], - lTmp, files->Infile[iFile].iNumLines, iFile); - } + lTmp = malloc(MAXLINES * sizeof(int)); + AddOptionStringArray(files->Infile[iFile].cIn, options[OPT_GRIDOUTPUT].cName, + &saArguments, &iNumArgs, &files->Infile[iFile].iNumLines, + lTmp, iVerbose); - files->Outfile[iFile - 1].iNumGrid = iNumGrid; + if (lTmp[0] >= 0) { + fvAssignGridOutput(files, module, options, output, saArguments, + &files->Outfile[iFile - 1].caGrid, lTmp, iNumArgs, iFile, + iVerbose); + } else { + files->Outfile[iFile - 1].iNumGrid = 0; + } free(lTmp); - free(cTmp); - free(cOption); + free(saArguments); } +/* + * End Output functions + */ + void ReadOverwrite(BODY *body, CONTROL *control, FILES *files, OPTIONS *options, SYSTEM *system, int iFile) { /* This parameter can exist in any file, but only once */ @@ -3446,7 +3523,8 @@ void ReadOptionsGeneral(BODY *body, CONTROL *control, FILES *files, ReadOutputOrder(files, module, options, output, iFile, control->Io.iVerbose); if (body[iFile - 1].bPoise) { - ReadGridOutput(files, options, output, iFile, control->Io.iVerbose); + ReadGridOutput(files, module, options, output, iFile, + control->Io.iVerbose); } else { // Initialize iNumGrid to 0 so no memory issues files->Outfile[iFile - 1].iNumGrid = 0; @@ -3586,7 +3664,7 @@ void ReadOptions(BODY **body, CONTROL *control, FILES *files, MODULE *module, ReadInitialOptions(body, control, files, module, options, output, system, infile); - InitializeSystem(*body, control,system); + InitializeSystem(*body, control, system); /* Now that we know how many bodies there are, initialize more features */ *update = malloc(control->Evolve.iNumBodies * sizeof(UPDATE)); @@ -4646,12 +4724,12 @@ void InitializeOptions(OPTIONS *options, fnReadOption *fnRead) { /* Initialize all parameters describing the option's location */ for (iOpt = 0; iOpt < MODULEOPTEND; iOpt++) { - options[iOpt].cName = NULL; - options[iOpt].cDescr = NULL; + options[iOpt].cName = NULL; + options[iOpt].cDescr = NULL; options[iOpt].cLongDescr = NULL; - options[iOpt].cDefault = NULL; - options[iOpt].cValues = NULL; - options[iOpt].cNeg = NULL; + options[iOpt].cDefault = NULL; + options[iOpt].cValues = NULL; + options[iOpt].cNeg = NULL; options[iOpt].cDimension = NULL; fvFormattedString(&options[iOpt].cName, "null"); diff --git a/src/output.c b/src/output.c index 86312637..846d5a82 100644 --- a/src/output.c +++ b/src/output.c @@ -676,7 +676,8 @@ void WriteLostEng(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system, *dTmp *= output->dNeg; fvFormattedString(cUnit, output->cNeg); } else { - double dConversion = fdUnitsEnergy(units->iTime, units->iMass, units->iLength); + double dConversion = + fdUnitsEnergy(units->iTime, units->iMass, units->iLength); *dTmp /= dConversion; fsUnitsEnergy(units, cUnit); } @@ -1253,36 +1254,40 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { */ fvFormattedString(&output[OUT_COPP].cName, "COPP"); - fvFormattedString(&output[OUT_COPP].cDescr, "Climate Obliquity Precession Parameter"); + fvFormattedString(&output[OUT_COPP].cDescr, + "Climate Obliquity Precession Parameter"); output[OUT_COPP].bNeg = 0; output[OUT_COPP].iNum = 1; output[OUT_COPP].iModuleBit = BINARY + EQTIDE + DISTROT + POISE + SPINBODY; fnWrite[OUT_COPP] = &WriteCOPP; - fvFormattedString(&output[OUT_COPP].cLongDescr, - "eccentriciy * sin(longitude of pericenter + precession angle) * " - "sin(obliquity)"); + fvFormattedString( + &output[OUT_COPP].cLongDescr, + "eccentriciy * sin(longitude of pericenter + precession angle) * " + "sin(obliquity)"); fvFormattedString(&output[OUT_CRITSEMI].cName, "CriticalSemiMajorAxis"); fvFormattedString(&output[OUT_CRITSEMI].cDescr, - "Holman & Wiegert (1999) P-type Critical Semi-major Axis"); + "Holman & Wiegert (1999) P-type Critical Semi-major Axis"); fvFormattedString(&output[OUT_CRITSEMI].cNeg, "AU"); output[OUT_CRITSEMI].bNeg = 1; output[OUT_CRITSEMI].dNeg = 1. / AUM; output[OUT_CRITSEMI].iNum = 1; output[OUT_CRITSEMI].iModuleBit = BINARY + EQTIDE + STELLAR; fnWrite[OUT_CRITSEMI] = &WriteCriticalSemi; - fvFormattedString(&output[OUT_CRITSEMI].cLongDescr, - "For a circumbinary planet, semi-major axes below a critical value " - "result\n" - "in unstable orbits. This output parameter prints the instantaneous\n" - "value of that critical distance."); + fvFormattedString( + &output[OUT_CRITSEMI].cLongDescr, + "For a circumbinary planet, semi-major axes below a critical value " + "result\n" + "in unstable orbits. This output parameter prints the instantaneous\n" + "value of that critical distance."); /* * D */ fvFormattedString(&output[OUT_DT].cName, "DeltaTime"); - fvFormattedString(&output[OUT_DT].cDescr, "Average Timestep Over Last Output Interval"); + fvFormattedString(&output[OUT_DT].cDescr, + "Average Timestep Over Last Output Interval"); fvFormattedString(&output[OUT_DT].cNeg, "years"); output[OUT_DT].bNeg = 1; output[OUT_DT].dNeg = 1. / YEARSEC; @@ -1313,17 +1318,18 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fvFormattedString(&output[OUT_HZLIMDRYRUNAWAY].cName, "HZLimitDryRunaway"); fvFormattedString(&output[OUT_HZLIMDRYRUNAWAY].cDescr, - "Semi-major axis of Dry Runaway HZ Limit"); + "Semi-major axis of Dry Runaway HZ Limit"); fvFormattedString(&output[OUT_HZLIMDRYRUNAWAY].cNeg, "AU"); output[OUT_HZLIMDRYRUNAWAY].bNeg = 1; output[OUT_HZLIMDRYRUNAWAY].dNeg = 1 / AUM; output[OUT_HZLIMDRYRUNAWAY].iNum = 1; output[OUT_HZLIMDRYRUNAWAY].iModuleBit = 1; fnWrite[OUT_HZLIMDRYRUNAWAY] = &WriteHZLimitDryRunaway; - fvFormattedString(&output[OUT_HZLIMDRYRUNAWAY].cLongDescr, - "Minimum distance where a \"dry\" planet can be habitable, following " - "Abe\n" - "et al. (2011), or ~415 W/m^2 net instellation."); + fvFormattedString( + &output[OUT_HZLIMDRYRUNAWAY].cLongDescr, + "Minimum distance where a \"dry\" planet can be habitable, following " + "Abe\n" + "et al. (2011), or ~415 W/m^2 net instellation."); fvFormattedString(&output[OUT_HZLIMRECVENUS].cName, "HZLimRecVenus"); fvFormattedString(&output[OUT_HZLIMRECVENUS].cDescr, "Recent Venus HZ Limit"); @@ -1333,30 +1339,34 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { output[OUT_HZLIMRECVENUS].iNum = 1; output[OUT_HZLIMRECVENUS].iModuleBit = 1; fnWrite[OUT_HZLIMRECVENUS] = &WriteHZLimitRecentVenus; - fvFormattedString(&output[OUT_HZLIMRECVENUS].cLongDescr, - "Recent Venus habitable zone limit from Kopparapu et al. (2013). The " - "value\n" - "is determined by the total luminosity and average effective " - "temperature\n" - "of all interior bodies."); + fvFormattedString( + &output[OUT_HZLIMRECVENUS].cLongDescr, + "Recent Venus habitable zone limit from Kopparapu et al. (2013). The " + "value\n" + "is determined by the total luminosity and average effective " + "temperature\n" + "of all interior bodies."); fvFormattedString(&output[OUT_HZLIMRUNAWAY].cName, "HZLimRunaway"); - fvFormattedString(&output[OUT_HZLIMRUNAWAY].cDescr, "Runaway Greenhouse HZ Limit"); + fvFormattedString(&output[OUT_HZLIMRUNAWAY].cDescr, + "Runaway Greenhouse HZ Limit"); fvFormattedString(&output[OUT_HZLIMRUNAWAY].cNeg, "AU"); output[OUT_HZLIMRUNAWAY].bNeg = 1; output[OUT_HZLIMRUNAWAY].dNeg = 1. / AUM; output[OUT_HZLIMRUNAWAY].iNum = 1; output[OUT_HZLIMRUNAWAY].iModuleBit = 1; fnWrite[OUT_HZLIMRUNAWAY] = &WriteHZLimitRunawayGreenhouse; - fvFormattedString(&output[OUT_HZLIMRUNAWAY].cLongDescr, - "Runaway greenhouse habitable zone limit from Kopparapu et al. " - "(2013).\n" - "The value is determined by the total luminosity and average " - "effective\n" - "temperature of all interior bodies."); + fvFormattedString( + &output[OUT_HZLIMRUNAWAY].cLongDescr, + "Runaway greenhouse habitable zone limit from Kopparapu et al. " + "(2013).\n" + "The value is determined by the total luminosity and average " + "effective\n" + "temperature of all interior bodies."); fvFormattedString(&output[OUT_HZLIMMOIST].cName, "HZLimMoistGreenhouse"); - fvFormattedString(&output[OUT_HZLIMMOIST].cDescr, "Moist Greenhouse HZ Limit"); + fvFormattedString(&output[OUT_HZLIMMOIST].cDescr, + "Moist Greenhouse HZ Limit"); fvFormattedString(&output[OUT_HZLIMMOIST].cNeg, "AU"); output[OUT_HZLIMMOIST].bNeg = 1; output[OUT_HZLIMMOIST].dNeg = 1. / AUM; @@ -1371,19 +1381,21 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { "temperature of all interior bodies."); fvFormattedString(&output[OUT_HZLIMMAX].cName, "HZLimMaxGreenhouse"); - fvFormattedString(&output[OUT_HZLIMMAX].cDescr, "Maximum Greenhouse HZ Limit"); + fvFormattedString(&output[OUT_HZLIMMAX].cDescr, + "Maximum Greenhouse HZ Limit"); fvFormattedString(&output[OUT_HZLIMMAX].cNeg, "AU"); output[OUT_HZLIMMAX].bNeg = 1; output[OUT_HZLIMMAX].dNeg = 1. / AUM; output[OUT_HZLIMMAX].iNum = 1; output[OUT_HZLIMMAX].iModuleBit = 1; fnWrite[OUT_HZLIMMAX] = &WriteHZLimitMaxGreenhouse; - fvFormattedString(&output[OUT_HZLIMMAX].cLongDescr, - "Maximum greenhouse habitable zone limit from Kopparapu et al. " - "(2013).\n" - "The value is determined by the total luminosity and average " - "effective\n" - "temperature of all interior bodies."); + fvFormattedString( + &output[OUT_HZLIMMAX].cLongDescr, + "Maximum greenhouse habitable zone limit from Kopparapu et al. " + "(2013).\n" + "The value is determined by the total luminosity and average " + "effective\n" + "temperature of all interior bodies."); fvFormattedString(&output[OUT_HZLIMEARLYMARS].cName, "HZLimEarlyMars"); fvFormattedString(&output[OUT_HZLIMEARLYMARS].cDescr, "Early Mars HZ Limit"); @@ -1393,12 +1405,13 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { output[OUT_HZLIMEARLYMARS].iNum = 1; output[OUT_HZLIMEARLYMARS].iModuleBit = 1; fnWrite[OUT_HZLIMEARLYMARS] = &WriteHZLimitEarlyMars; - fvFormattedString(&output[OUT_HZLIMEARLYMARS].cLongDescr, - "Early Mars habitable zone limit from Kopparapu et al. (2013). The " - "value\n" - "is determined by the total luminosity and average effective " - "temperature\n" - "of all interior bodies."); + fvFormattedString( + &output[OUT_HZLIMEARLYMARS].cLongDescr, + "Early Mars habitable zone limit from Kopparapu et al. (2013). The " + "value\n" + "is determined by the total luminosity and average effective " + "temperature\n" + "of all interior bodies."); /* * I @@ -1406,7 +1419,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { /* Imk2Man */ fvFormattedString(&output[OUT_IMK2MAN].cName, "Imk2Man"); - fvFormattedString(&output[OUT_IMK2MAN].cDescr, "Imaginary Love Number k2 Mantle"); + fvFormattedString(&output[OUT_IMK2MAN].cDescr, + "Imaginary Love Number k2 Mantle"); fvFormattedString(&output[OUT_IMK2MAN].cNeg, "nd"); output[OUT_IMK2MAN].bNeg = 1; output[OUT_IMK2MAN].dNeg = 1; @@ -1426,15 +1440,16 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fvFormattedString(&output[OUT_INSTELLATION].cName, "Instellation"); fvFormattedString(&output[OUT_INSTELLATION].cDescr, - "Orbit-averaged INcident STELLar radiATION"); + "Orbit-averaged INcident STELLar radiATION"); fvFormattedString(&output[OUT_INSTELLATION].cNeg, "W/m^2"); output[OUT_INSTELLATION].bNeg = 1; output[OUT_INSTELLATION].dNeg = 1; output[OUT_INSTELLATION].iNum = 1; output[OUT_INSTELLATION].iModuleBit = 1; fnWrite[OUT_INSTELLATION] = &WriteInstellation; - fvFormattedString(&output[OUT_INSTELLATION].cLongDescr, - "Total instellation on a planet from all luminous, interior bodies."); + fvFormattedString( + &output[OUT_INSTELLATION].cLongDescr, + "Total instellation on a planet from all luminous, interior bodies."); /* * K @@ -1462,7 +1477,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { */ fvFormattedString(&output[OUT_LONGA].cName, "LongA"); - fvFormattedString(&output[OUT_LONGA].cDescr, "Body's Longitude of ascending node"); + fvFormattedString(&output[OUT_LONGA].cDescr, + "Body's Longitude of ascending node"); fvFormattedString(&output[OUT_LONGA].cNeg, "Deg"); output[OUT_LONGA].bNeg = 1; output[OUT_LONGA].dNeg = 1. / DEGRAD; @@ -1471,7 +1487,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_LONGA] = &WriteBodyLongA; fvFormattedString(&output[OUT_LONGP].cName, "LongP"); - fvFormattedString(&output[OUT_LONGP].cDescr, "Body's Longitude of pericenter"); + fvFormattedString(&output[OUT_LONGP].cDescr, + "Body's Longitude of pericenter"); fvFormattedString(&output[OUT_LONGP].cNeg, "Deg"); output[OUT_LONGP].bNeg = 1; output[OUT_LONGP].dNeg = 1. / DEGRAD; @@ -1534,12 +1551,13 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { output[OUT_PRECA].iNum = 1; output[OUT_PRECA].iModuleBit = EQTIDE + DISTROT + POISE; fnWrite[OUT_PRECA] = &WriteBodyPrecA; - fvFormattedString(&output[OUT_PRECA].cLongDescr, - "The precession angle is orthogonal to the obliquity and is measured " - "from\n" - "the vernal equinox. This angle is a \"dog-leg\" angle as shown in " - "Fig. 30\n" - "of Barnes et al. (2020)."); + fvFormattedString( + &output[OUT_PRECA].cLongDescr, + "The precession angle is orthogonal to the obliquity and is measured " + "from\n" + "the vernal equinox. This angle is a \"dog-leg\" angle as shown in " + "Fig. 30\n" + "of Barnes et al. (2020)."); fvFormattedString(&output[OUT_ORBANGMOM].cName, "OrbAngMom"); fvFormattedString(&output[OUT_ORBANGMOM].cDescr, "Orbital Angular Momentum"); @@ -1594,7 +1612,7 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fvFormattedString(&output[OUT_LOSTANGMOM].cName, "LostAngMom"); fvFormattedString(&output[OUT_LOSTANGMOM].cDescr, - "Lost Angular Momentum due to Magnetic Braking"); + "Lost Angular Momentum due to Magnetic Braking"); fvFormattedString(&output[OUT_LOSTANGMOM].cNeg, "kg*m^2/s"); output[OUT_LOSTANGMOM].bNeg = 1; output[OUT_LOSTANGMOM].iNum = 1; @@ -1647,14 +1665,15 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fvFormattedString(&output[OUT_RADGYRA].cName, "RadGyra"); fvFormattedString(&output[OUT_RADGYRA].cDescr, - "Radius of Gyration/Moment of Inertia Constant"); + "Radius of Gyration/Moment of Inertia Constant"); output[OUT_RADGYRA].bNeg = 0; output[OUT_RADGYRA].iNum = 1; output[OUT_RADGYRA].iModuleBit = 1; fnWrite[OUT_RADGYRA] = &WriteRadGyra; fvFormattedString(&output[OUT_ROTANGMOM].cName, "RotAngMom"); - fvFormattedString(&output[OUT_ROTANGMOM].cDescr, "Rotational Angular Momentum"); + fvFormattedString(&output[OUT_ROTANGMOM].cDescr, + "Rotational Angular Momentum"); fvFormattedString(&output[OUT_ROTANGMOM].cNeg, "kg*m^2/s"); output[OUT_ROTANGMOM].bNeg = 1; output[OUT_ROTANGMOM].iNum = 1; @@ -1663,7 +1682,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_ROTANGMOM] = &WriteRotAngMom; fvFormattedString(&output[OUT_ROTKINENERGY].cName, "RotKinEnergy"); - fvFormattedString(&output[OUT_ROTKINENERGY].cDescr, "Body's Rotational Energy"); + fvFormattedString(&output[OUT_ROTKINENERGY].cDescr, + "Body's Rotational Energy"); fvFormattedString(&output[OUT_ROTKINENERGY].cNeg, "ergs"); output[OUT_ROTKINENERGY].iNum = 1; output[OUT_ROTKINENERGY].iModuleBit = EQTIDE + DISTORB; @@ -1703,7 +1723,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { */ fvFormattedString(&output[OUT_SURFENFLUX].cName, "SurfEnFluxTotal"); - fvFormattedString(&output[OUT_SURFENFLUX].cDescr, "Total Surface Energy Flux"); + fvFormattedString(&output[OUT_SURFENFLUX].cDescr, + "Total Surface Energy Flux"); fvFormattedString(&output[OUT_SURFENFLUX].cNeg, "W/m^2"); output[OUT_SURFENFLUX].bNeg = 1; output[OUT_SURFENFLUX].dNeg = 1; @@ -1741,7 +1762,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_TOTENERGY] = &WriteTotEnergy; fvFormattedString(&output[OUT_POTENERGY].cName, "PotEnergy"); - fvFormattedString(&output[OUT_POTENERGY].cDescr, "Body's non-orbital Potential Energy"); + fvFormattedString(&output[OUT_POTENERGY].cDescr, + "Body's non-orbital Potential Energy"); fvFormattedString(&output[OUT_POTENERGY].cNeg, "ergs"); output[OUT_POTENERGY].bNeg = 1; output[OUT_POTENERGY].dNeg = 1; @@ -1750,7 +1772,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_POTENERGY] = &WritePotEnergy; fvFormattedString(&output[OUT_KINENERGY].cName, "KinEnergy"); - fvFormattedString(&output[OUT_KINENERGY].cDescr, "Body's non-orbital Kinetic Energy"); + fvFormattedString(&output[OUT_KINENERGY].cDescr, + "Body's non-orbital Kinetic Energy"); fvFormattedString(&output[OUT_KINENERGY].cNeg, "ergs"); output[OUT_KINENERGY].bNeg = 1; output[OUT_KINENERGY].dNeg = 1; @@ -1759,7 +1782,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_KINENERGY] = &WriteKinEnergy; fvFormattedString(&output[OUT_ORBKINENERGY].cName, "OrbKinEnergy"); - fvFormattedString(&output[OUT_ORBKINENERGY].cDescr, "Body's Orbital Kinetic Energy"); + fvFormattedString(&output[OUT_ORBKINENERGY].cDescr, + "Body's Orbital Kinetic Energy"); fvFormattedString(&output[OUT_ORBKINENERGY].cNeg, "ergs"); output[OUT_ORBKINENERGY].bNeg = 1; output[OUT_ORBKINENERGY].dNeg = 1; @@ -1768,7 +1792,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_ORBKINENERGY] = &WriteOrbKinEnergy; fvFormattedString(&output[OUT_ORBKINENERGY].cName, "TotOrbEnergy"); - fvFormattedString(&output[OUT_ORBKINENERGY].cDescr, "System's Total Orbital Energy"); + fvFormattedString(&output[OUT_ORBKINENERGY].cDescr, + "System's Total Orbital Energy"); fvFormattedString(&output[OUT_ORBKINENERGY].cNeg, "ergs"); output[OUT_ORBKINENERGY].bNeg = 1; output[OUT_ORBKINENERGY].dNeg = 1; @@ -1777,7 +1802,8 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fnWrite[OUT_ORBKINENERGY] = &WriteTotOrbEnergy; fvFormattedString(&output[OUT_ORBPOTENERGY].cName, "OrbPotEnergy"); - fvFormattedString(&output[OUT_ORBPOTENERGY].cDescr, "Body's Orbital Potential Energy"); + fvFormattedString(&output[OUT_ORBPOTENERGY].cDescr, + "Body's Orbital Potential Energy"); fvFormattedString(&output[OUT_ORBPOTENERGY].cNeg, "ergs"); output[OUT_ORBPOTENERGY].bNeg = 1; output[OUT_ORBPOTENERGY].dNeg = 1; @@ -1815,14 +1841,14 @@ void InitializeOutputGeneral(OUTPUT *output, fnWriteOutput fnWrite[]) { fvFormattedString(&output[OUT_XOBL].cName, "Xobl"); fvFormattedString(&output[OUT_XOBL].cDescr, - "Body's sin(obliquity)*cos(precession angle)"); + "Body's sin(obliquity)*cos(precession angle)"); output[OUT_XOBL].iNum = 1; output[OUT_XOBL].iModuleBit = EQTIDE + DISTROT; fnWrite[OUT_XOBL] = &WriteXobl; fvFormattedString(&output[OUT_YOBL].cName, "Yobl"); fvFormattedString(&output[OUT_YOBL].cDescr, - "Body's sin(obliquity)*sin(precession angle)"); + "Body's sin(obliquity)*sin(precession angle)"); output[OUT_YOBL].iNum = 1; output[OUT_YOBL].iModuleBit = EQTIDE + DISTROT; fnWrite[OUT_YOBL] = &WriteYobl; @@ -1846,13 +1872,13 @@ void UnitsSI(UNITS *units) { void WriteLogEntry(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system, UPDATE *update, fnWriteOutput fnWrite, FILE *fp, int iBody) { double *dTmp; - char *cUnit=NULL; + char *cUnit = NULL; UNITS units; int i, j, iNumIndices; - //cUnit[0] = '\0'; - dTmp = malloc(output->iNum * sizeof(double)); + // cUnit[0] = '\0'; + dTmp = malloc(output->iNum * sizeof(double)); UnitsSI(&units); fnWrite(body, control, output, system, &units, update, iBody, dTmp, &cUnit); @@ -2008,26 +2034,21 @@ void LogOutputOrder(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, SYSTEM *system, UPDATE *update, fnWriteOutput fnWrite[], FILE *fp, int iBody) { int iCol, iOut, iSubOut, iExtra = 0; - char **cCol; + char **cCol; double *dTmp; - char *cUnit=NULL, *cTmp=NULL; + char *cUnit = NULL; - cCol=malloc(MODULEOUTEND*sizeof(char*)); + cCol = malloc(MODULEOUTEND * sizeof(char *)); for (iCol = 0; iCol < files->Outfile[iBody].iNumCols; iCol++) { for (iOut = 0; iOut < MODULEOUTEND; iOut++) { - // if (memcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName, - // strlen(output[iOut].cName)) == 0) { - if (strcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName) == 0) { - /* Match! */ + if (strcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName) == 0) { dTmp = malloc(output[iOut].iNum * sizeof(double)); fnWrite[iOut](body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); for (iSubOut = 0; iSubOut < output[iOut].iNum; iSubOut++) { - cCol[iCol + iSubOut + iExtra]=NULL; - fvFormattedString(&cCol[iCol + iSubOut + iExtra], - files->Outfile[iBody].caCol[iCol]); - fvFormattedString(&cTmp, "[%s]", cUnit); - fvFormattedString(&cCol[iCol + iSubOut + iExtra], cTmp); + cCol[iCol + iSubOut + iExtra] = NULL; + fvFormattedString(&cCol[iCol + iSubOut + iExtra], "%s [%s]", + files->Outfile[iBody].caCol[iCol], cUnit); } iExtra += (output[iOut].iNum - 1); free(dTmp); @@ -2035,40 +2056,34 @@ void LogOutputOrder(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, } } - fprintf(fp, "Output Order:"); + fprintf(fp, "\nOutput Order:"); for (iCol = 0; iCol < (files->Outfile[iBody].iNumCols + iExtra); iCol++) { fprintf(fp, " %s", cCol[iCol]); } fprintf(fp, "\n"); free(cCol); free(cUnit); - free(cTmp); } void LogGridOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, SYSTEM *system, UPDATE *update, fnWriteOutput fnWrite[], FILE *fp, int iBody) { int iCol, iOut, iSubOut, iExtra = 0; - char **cCol; // +2 for brackets + char **cCol; double *dTmp; - char *cUnit=NULL, *cTmp=NULL; + char *cUnit = NULL, *cTmp = NULL; - cCol=malloc(MODULEOUTEND*sizeof(char*)); + cCol = malloc(MODULEOUTEND * sizeof(char *)); for (iCol = 0; iCol < files->Outfile[iBody].iNumGrid; iCol++) { for (iOut = 0; iOut < MODULEOUTEND; iOut++) { - // if (memcmp(files->Outfile[iBody].caGrid[iCol], output[iOut].cName, - // strlen(output[iOut].cName)) == 0) { if (strcmp(files->Outfile[iBody].caGrid[iCol], output[iOut].cName) == 0) { - /* Match! */ dTmp = malloc(output[iOut].iNum * sizeof(double)); fnWrite[iOut](body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); for (iSubOut = 0; iSubOut < output[iOut].iNum; iSubOut++) { - cCol[iCol + iSubOut + iExtra]=NULL; - fvFormattedString(&cCol[iCol + iSubOut + iExtra], - files->Outfile[iBody].caGrid[iCol]); - fvFormattedString(&cTmp, "[%s]", cUnit); - fvFormattedString(&cCol[iCol + iSubOut + iExtra], cTmp); + cCol[iCol + iSubOut + iExtra] = NULL; + fvFormattedString(&cCol[iCol + iSubOut + iExtra], "%s [%s]", + files->Outfile[iBody].caGrid[iCol], cUnit); } iExtra += (output[iOut].iNum - 1); free(dTmp); @@ -2153,7 +2168,7 @@ void LogBody(BODY *body, CONTROL *control, FILES *files, MODULE *module, if (output[iOut].iNum > 0) { if (module->iBitSum[iBody] & output[iOut].iModuleBit) { // Useful for debugging - //fprintf(stderr,"%d %d\n",iBody,iOut); + // fprintf(stderr,"%d %d\n",iBody,iOut); WriteLogEntry(body, control, &output[iOut], system, update, fnWrite[iOut], fp, iBody); } @@ -2181,8 +2196,8 @@ void WriteLog(BODY *body, CONTROL *control, FILES *files, MODULE *module, /* Get derivatives */ PropertiesAuxiliary(body, control, system, update); - /* XXX The fdGetTimeStep function is not single-purpose. The function sets - members of the UPDATE struct, so those value should probably be set in + /* XXX The fdGetTimeStep function is not single-purpose. The function sets + members of the UPDATE struct, so those value should probably be set in one function, and then the timestep calculated in another. */ double dDt = fdGetTimeStep(body, control, system, update, fnUpdate); @@ -2218,7 +2233,7 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, int iBody, iCol, iOut, iSubOut, iExtra = 0, iGrid, iLat, jBody, j; double dCol[NUMOPT], *dTmp, dGrid[NUMOPT]; FILE *fp; - char *cUnit, *cPoiseGrid=NULL, *cLaplaceFunc=NULL; + char *cUnit, *cPoiseGrid = NULL, *cLaplaceFunc = NULL; /* Write out all data columns for each body. As some data may span more than 1 column, we search the input list sequentially, adding iExtra to the @@ -2237,11 +2252,12 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, for (iOut = 0; iOut < MODULEOUTEND; iOut++) { if (output[iOut].bGrid == 0 || output[iOut].bGrid == 2) { // if (memcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName, - // strlen(output[iOut].cName)) == 0) { - if (strcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName) == 0) { + // strlen(output[iOut].cName)) == 0) { + if (strcmp(files->Outfile[iBody].caCol[iCol], output[iOut].cName) == + 0) { /* Match! */ - dTmp = malloc(output[iOut].iNum * sizeof(double)); - cUnit=NULL; + dTmp = malloc(output[iOut].iNum * sizeof(double)); + cUnit = NULL; fnWrite[iOut](body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); for (iSubOut = 0; iSubOut < output[iOut].iNum; iSubOut++) { @@ -2276,10 +2292,12 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, for (iOut = 0; iOut < MODULEOUTEND; iOut++) { if (output[iOut].bGrid == 1 || output[iOut].bGrid == 2) { // if (memcmp(files->Outfile[iBody].caGrid[iGrid], - // output[iOut].cName, strlen(output[iOut].cName)) == 0) { - if (strcmp(files->Outfile[iBody].caGrid[iGrid],output[iOut].cName) == 0) { + // output[iOut].cName, strlen(output[iOut].cName)) == + // 0) { + if (strcmp(files->Outfile[iBody].caGrid[iGrid], + output[iOut].cName) == 0) { body[iBody].iWriteLat = iLat; - cUnit=NULL; + cUnit = NULL; fnWrite[iOut](body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); @@ -2290,12 +2308,14 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, } /* Now write the columns */ - fvFormattedString(&cPoiseGrid, "%s.%s.Climate", system->cName, body[iBody].cName); + fvFormattedString(&cPoiseGrid, "%s.%s.Climate", system->cName, + body[iBody].cName); if (control->Evolve.dTime == 0 && iLat == 0) { if (body[iBody].iClimateModel == SEA) { WriteDailyInsol(body, control, &output[iOut], system, - &control->Units[iBody], update, iBody, dTmp, &cUnit); + &control->Units[iBody], update, iBody, dTmp, + &cUnit); WriteSeasonalTemp(body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); @@ -2321,7 +2341,8 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, if (control->Evolve.dTime >= body[iBody].dSeasNextOutput && iLat == 0) { WriteDailyInsol(body, control, &output[iOut], system, - &control->Units[iBody], update, iBody, dTmp, &cUnit); + &control->Units[iBody], update, iBody, dTmp, + &cUnit); WriteSeasonalTemp(body, control, &output[iOut], system, &control->Units[iBody], update, iBody, dTmp, &cUnit); @@ -2359,7 +2380,7 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, /* open body file to write laplace functions and related */ for (jBody = iBody + 1; jBody < control->Evolve.iNumBodies; jBody++) { fvFormattedString(&cLaplaceFunc, "%s.%s.Laplace", body[iBody].cName, - body[jBody].cName); + body[jBody].cName); if (control->Evolve.dTime == 0) { fp = fopen(cLaplaceFunc, "w"); } else { @@ -2403,8 +2424,8 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output, /* open body file to write laplace functions and related */ for (jBody = iBody + 1; jBody < control->Evolve.iNumBodies; jBody++) { - fvFormattedString(&cLaplaceFunc, "%s.%s.Laplace", body[iBody].cName, - body[jBody].cName); + fvFormattedString(&cLaplaceFunc, "%s.%s.Laplace", + body[iBody].cName, body[jBody].cName); fp = fopen(cLaplaceFunc, "w"); if (body[iBody].dSemi < body[jBody].dSemi) { for (j = 0; j < LAPLNUM; j++) { @@ -2467,10 +2488,10 @@ void InitializeOutput(FILES *files, OUTPUT *output, fnWriteOutput fnWrite[]) { int iOut, iBody, iModule; for (iOut = 0; iOut < MODULEOUTEND; iOut++) { - output[iOut].cName = NULL; - output[iOut].cDescr = NULL; + output[iOut].cName = NULL; + output[iOut].cDescr = NULL; output[iOut].cLongDescr = NULL; - output[iOut].cNeg = NULL; + output[iOut].cNeg = NULL; fvFormattedString(&output[iOut].cName, "null"); output[iOut].bGrid = 0; diff --git a/src/vplanet.c b/src/vplanet.c index 3c6709c4..2eb56066 100644 --- a/src/vplanet.c +++ b/src/vplanet.c @@ -28,17 +28,17 @@ We need this wrapper so we can call `main_impl` from Python. */ int main_impl(int argc, char *argv[]) { #ifdef DEBUG - #ifdef __x86_64__ - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW); - _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_DIV_ZERO); - //_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_UNDERFLOW); - fprintf(stderr, "INFO: Floating point trapping enabled.\n"); - #else - fprintf(stderr, - "WARNING: Floating point trapping only enabled for x86 " - "architectures.\n"); - #endif +#ifdef __x86_64__ + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW); + _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_DIV_ZERO); + //_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_UNDERFLOW); + fprintf(stderr, "INFO: Floating point trapping enabled.\n"); +#else + fprintf(stderr, + "WARNING: Floating point trapping only enabled for x86 " + "architectures.\n"); +#endif #endif // struct timeval start, end; @@ -65,14 +65,14 @@ int main_impl(int argc, char *argv[]) { fnUpdateVariable ***fnUpdate; fnIntegrate fnOneStep; - control.sGitVersion=NULL; + control.sGitVersion = NULL; #ifdef GITVERSION fvFormattedString(&control.sGitVersion, GITVERSION); #else fvFormattedString(&control.sGitVersion, "Unknown"); #endif - system.cName=NULL; + system.cName = NULL; /** Must initialize all options and outputs for all modules independent of what is selected. This allows a complete @@ -91,8 +91,8 @@ int main_impl(int argc, char *argv[]) { control.Evolve.iOneStep = 0; /* Copy executable file name to the files struct. */ - files.cExe=NULL; - fvFormattedString(&files.cExe, argv[0]); + files.cExe = NULL; + fvFormattedString(&files.cExe, argv[0]); // XXX This isn't working! if (argc == 1) { fprintf(stderr, diff --git a/src/vplanet.h b/src/vplanet.h index 309341c5..de3ed339 100644 --- a/src/vplanet.h +++ b/src/vplanet.h @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -180,7 +180,7 @@ typedef struct VERIFY VERIFY; */ struct BODY { /* Body Properties */ - char *cName; /**< Body's Name */ + char *cName; /**< Body's Name */ char *sColor; /**< Body color (for plotting) */ int bMantle; /**< Is there a mantle? */ @@ -366,22 +366,22 @@ struct BODY { double dPrecRate; /**< Value to set fixed precession rate to */ int bCalcDynEllip; /**< Calc dyn ellipticity from spin, radius, mass, inertia? */ - int bRelaxDynEllip; /**< shape of planet relaxes when spun down */ - int bReadOrbitData; /**< Use orbit data from file rather than distorb */ - char *cFileOrbitData; /**< read orbital data from this file - (distorb=0) */ - double *daTimeSeries; /**< time series for orbital data */ - double *daSemiSeries; /**< time series for orbital data */ - double *daEccSeries; /**< time series for orbital data */ - double *daIncSeries; /**< time series for orbital data */ - double *daArgPSeries; /**< time series for orbital data */ - double *daLongASeries; /**< time series for orbital data */ - double *daMeanASeries; /**< time series for orbital data */ - int iCurrentStep; /**< index for time series arrays */ - double *daHeccSeries; /**< time series for orbital data */ - double *daKeccSeries; /**< time series for orbital data */ - double *daPincSeries; /**< time series for orbital data */ - double *daQincSeries; /**< time series for orbital data */ + int bRelaxDynEllip; /**< shape of planet relaxes when spun down */ + int bReadOrbitData; /**< Use orbit data from file rather than distorb */ + char *cFileOrbitData; /**< read orbital data from this file + (distorb=0) */ + double *daTimeSeries; /**< time series for orbital data */ + double *daSemiSeries; /**< time series for orbital data */ + double *daEccSeries; /**< time series for orbital data */ + double *daIncSeries; /**< time series for orbital data */ + double *daArgPSeries; /**< time series for orbital data */ + double *daLongASeries; /**< time series for orbital data */ + double *daMeanASeries; /**< time series for orbital data */ + int iCurrentStep; /**< index for time series arrays */ + double *daHeccSeries; /**< time series for orbital data */ + double *daKeccSeries; /**< time series for orbital data */ + double *daPincSeries; /**< time series for orbital data */ + double *daQincSeries; /**< time series for orbital data */ double dPdot; /**< inclination derivative used for obliquity evol */ double dQdot; /**< inclination derivative used for obliquity evol */ int iNLines; /**< Number of lines of orbital data file */ @@ -399,14 +399,14 @@ struct BODY { int iTidePerts; /**< Number of Tidal Perturbers */ int *iaTidePerts; /**< Body #'s of Tidal Perturbers */ char *saTidePerts[MAXARRAY]; /**< Names of Tidal Perturbers */ - double dK2Man; /**< Mantle k2 love number */ - double dK2Ocean; /**< Ocean's Love Number */ - double dK2Env; /**< Envelope's Love Number */ - double dTidalQMan; /**< Tidal Q of the Mantle */ - double dTidalQOcean; /**< Body's Ocean Component to Tidal Q */ - double dTidalQEnv; /**< Body's Envelope Component to Tidal Q */ - double dImK2Man; /**< Mantle Im(k2) love number */ - double dImK2ManOrbModel; /**< Mantle Im(k2) model for DB15 orbital eqns */ + double dK2Man; /**< Mantle k2 love number */ + double dK2Ocean; /**< Ocean's Love Number */ + double dK2Env; /**< Envelope's Love Number */ + double dTidalQMan; /**< Tidal Q of the Mantle */ + double dTidalQOcean; /**< Body's Ocean Component to Tidal Q */ + double dTidalQEnv; /**< Body's Envelope Component to Tidal Q */ + double dImK2Man; /**< Mantle Im(k2) love number */ + double dImK2ManOrbModel; /**< Mantle Im(k2) model for DB15 orbital eqns */ double dImK2Ocean; /**< Envelope Component to Imaginary part of Love's K_2 */ double dImK2Env; /**< Envelope Component to Imaginary part of Love's K_2 */ double dTidalQ; /**< Body's Tidal Q */ @@ -615,7 +615,7 @@ struct BODY { Ro>ROSSBYCRIT */ int bEvolveRG; /**< Whether or not to evolve radius of gyration? Defaults to 0 */ - double dLuminosityInitial; + double dLuminosityInitial; double dLuminosityAmplitude; double dLuminosityFrequency; double dLuminosityPhase; @@ -684,21 +684,21 @@ struct BODY { double dPlanckA; /**< Constant term in Blackbody linear approximation */ double dPlanckB; /**< Linear coeff in Blackbody linear approx (sensitivity) */ double dPrecA0; /**< Initial pA value used when distrot is not called */ - int bReadOrbitOblData; /**< Use orbit and obliquity data from file rather - than distrot */ + int bReadOrbitOblData; /**< Use orbit and obliquity data from file rather + than distrot */ char *sFileOrbitOblData; /**< read orbital and obliquity data from this file (distorb=0) */ - double *daOblSeries; /**< time series for obliquity data */ - double *daPrecASeries; /**< time series for obliquity data */ - double dRefHeight; /**< Ref height of "surface" in elevation feedback */ - int iReRunSeas; /**< When to rerun EBM in ice sheet model */ - double dSeaIceConduct; /**< Conductivity of sea ice */ - int bSeaIceModel; /**< Use sea ice model? */ - double dSeasDeltat; /**< Time step of seasonal model */ - double dSeasDeltax; /**< Spacing of grid points in seasonal model */ - double dSeasOutputTime; /**< When to output seasonal data */ - double dSeasNextOutput; /**< Next time step to output seasonal data */ - int bSkipSeas; /**< Ann model will be used if in snowball state */ + double *daOblSeries; /**< time series for obliquity data */ + double *daPrecASeries; /**< time series for obliquity data */ + double dRefHeight; /**< Ref height of "surface" in elevation feedback */ + int iReRunSeas; /**< When to rerun EBM in ice sheet model */ + double dSeaIceConduct; /**< Conductivity of sea ice */ + int bSeaIceModel; /**< Use sea ice model? */ + double dSeasDeltat; /**< Time step of seasonal model */ + double dSeasDeltax; /**< Spacing of grid points in seasonal model */ + double dSeasOutputTime; /**< When to output seasonal data */ + double dSeasNextOutput; /**< Next time step to output seasonal data */ + int bSkipSeas; /**< Ann model will be used if in snowball state */ int bSkipSeasEnabled; /**< Allow ann model to be used if in snowball state? */ int bSnowball; /**< Is planet in snowball state (oceans are frozen)? */ double @@ -1902,13 +1902,13 @@ depends on the total number of modules available. */ * regarding the files that read in. */ struct INFILE { - char *cIn; /**< File Name */ - int *bLineOK; /**< Line number Format OK? */ - int iNumLines; /**< Number of Input Lines */ + char *cIn; /**< File Name */ + int *bLineOK; /**< Line number Format OK? */ + int iNumLines; /**< Number of Input Lines */ /* Species file for PHOTOCHEM */ - //char cSpecies[NAMELEN]; /**< Name of Chemical Species N/I */ + // char cSpecies[NAMELEN]; /**< Name of Chemical Species N/I */ /* Reaction file for PHOTOCHEM */ - //char cReactions[NAMELEN]; /**< Names of Chemical Reactions N/I */ + // char cReactions[NAMELEN]; /**< Names of Chemical Reactions N/I */ /* Aerosol scattering files */ /* Aqueous file -- add to SpeciesFile? */ @@ -1919,13 +1919,13 @@ struct INFILE { * regarding the output files. */ struct OUTFILE { - char *cOut; /**< Output File Name */ - int iNumCols; /**< Number of Columns in Output File - (system.planet+.forward/backward) */ - char *caCol[MODULEOUTEND]; /**< Output Value Name */ - int bNeg[MODULEOUTEND]; /**< Use Negative Option Units? */ - int iNumGrid; /**< Number of grid outputs */ - char *caGrid[MODULEOUTEND]; /**< Gridded output name */ + char *cOut; /**< Output File Name */ + int iNumCols; /**< Number of Columns in Output File + (system.planet+.forward/backward) */ + char **caCol; /**< Output Value Name */ + int bNeg[MODULEOUTEND]; /**< Use Negative Option Units? */ + int iNumGrid; /**< Number of grid outputs */ + char **caGrid; /**< Gridded output name */ }; @@ -1933,9 +1933,9 @@ struct OUTFILE { * regarding every file. */ struct FILES { - char *cExe; /**< Name of Executable */ - OUTFILE *Outfile; /**< Output File Name for Forward Integration */ - char *cLog; /**< Log File Name (+4 to allow for ".log" suffix) */ + char *cExe; /**< Name of Executable */ + OUTFILE *Outfile; /**< Output File Name for Forward Integration */ + char *cLog; /**< Log File Name (+4 to allow for ".log" suffix) */ INFILE *Infile; int iNumInputs; /**< Number of Input Files */ }; @@ -1944,12 +1944,12 @@ struct FILES { * regarding the options, including their file data. */ struct OPTIONS { - char *cName; /**< Option Name */ - char *cDescr; /**< Brief Description of Option */ + char *cName; /**< Option Name */ + char *cDescr; /**< Brief Description of Option */ char *cLongDescr; /**< Long Description of Option */ - char *cValues; /**< Description of permitted values / ranges */ - int iType; /**< Cast of input. 0=bool; 1=int; 2=double; 3=string; +10 for - array. */ + char *cValues; /**< Description of permitted values / ranges */ + int iType; /**< Cast of input. 0=bool; 1=int; 2=double; 3=string; +10 for + array. */ char *cDefault; /**< Description of Default Value */ /** Qualitative description of the option, included for connection wtih bigplanet. Options are: time, length, mass, angle, energy, pressure, @@ -1963,9 +1963,9 @@ struct OPTIONS { int iMultiIn; int *iLine; /**< Option's Line number in Input File */ char *iFile; - char **cFile; /**< File Name Where Set */ - int bNeg; /**< Is There a Negative Option? */ - char *cNeg; /**< Description of Negative Unit Conversion */ + char **cFile; /**< File Name Where Set */ + int bNeg; /**< Is There a Negative Option? */ + char *cNeg; /**< Description of Negative Unit Conversion */ int iFileType; /**< What type of file can option be in? 0 = primary only, 1 = body file only, 2 = any file */ double dNeg; /**< Conversion Factor to System Units */ @@ -1974,15 +1974,15 @@ struct OPTIONS { /* OUTPUT contains the data regarding every output parameters */ struct OUTPUT { - char *cName; /**< Output Name */ - char *cDescr; /**< Output Description */ + char *cName; /**< Output Name */ + char *cDescr; /**< Output Description */ char *cLongDescr; /**< Output Long Description */ - int bNeg; /**< Is There a Negative Option? */ - int iModuleBit; /**< Bit flag for module to check output parameters */ - int *bDoNeg; /**< Should the Output use "Negative" Units? */ - char *cNeg; /**< Units of Negative Option */ - double dNeg; /**< Conversion Factor for Negative Option */ - int iNum; /**< Number of Columns for Output */ + int bNeg; /**< Is There a Negative Option? */ + int iModuleBit; /**< Bit flag for module to check output parameters */ + int *bDoNeg; /**< Should the Output use "Negative" Units? */ + char *cNeg; /**< Units of Negative Option */ + double dNeg; /**< Conversion Factor for Negative Option */ + int iNum; /**< Number of Columns for Output */ int bGrid; /**< Is output quantity gridded (e.g. a function of latitude)? */ // GRIDOUTPUT *GridOutput; /**< Output for latitudinal climate params, @@ -1992,7 +1992,7 @@ struct OUTPUT { typedef void (*fnReadOption)(BODY *, CONTROL *, FILES *, OPTIONS *, SYSTEM *, int); typedef void (*fnWriteOutput)(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UNITS *, - UPDATE *, int, double *, char**); + UPDATE *, int, double *, char **); /*