Skip to content

Commit

Permalink
Regularized the utilities in Resources/Utils so that their usage is m…
Browse files Browse the repository at this point in the history
…ore uniform. E.g. called via the command line with a configuration file specified, where needed.
  • Loading branch information
U-ADRICE\sb28 authored and U-ADRICE\sb28 committed Jan 4, 2023
1 parent 5c8b5f4 commit 0d10714
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 86 deletions.
4 changes: 3 additions & 1 deletion Resources/Utils/calculateDEM/config.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Results
40
0.1
4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0
1
0 0
0 600

// Results directory
// Number of temperature bins
// Width of temperature bin (dex)
// Temperature bins
Expand Down
34 changes: 18 additions & 16 deletions Resources/Utils/calculateDEM/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// *
// * (c) Dr. Stephen J. Bradshaw
// *
// * Date last modified: 10/20/2021
// * Date last modified: 01/04/2023
// *
// ****

Expand All @@ -22,8 +22,8 @@

int main( int argc, char **argv )
{
FILE *pCONFIGFile, *pAMRFile, *pPHYFile, *pDEMFile;
char szAMRFilename[256], szPHYFilename[256], szDEMFilename[256];
FILE *pCFGFile, *pAMRFile, *pPHYFile, *pDEMFile;
char szResultsDirectory[256], szAMRFilename[256], szPHYFilename[256], szDEMFilename[256];
double *pflog10T, *pfDEM;
double fdexStep, fds, fne, fTe, flog10Te;
double fBuffer;
Expand All @@ -33,31 +33,33 @@ int i, j, k, m;
int iBuffer;

if( argc == 1 ) {
printf( "\nERROR! No configuration file specified.\n" );
exit(EXIT_SUCCESS);
printf( "\nA configuration file must be specified. E.g. calculateDEM config.cfg\n");
exit( EXIT_SUCCESS );
}

// Open the configuration file
printf( "\nUsing: %s\n", argv[1] );
pCONFIGFile = fopen( argv[1], "r" );
pCFGFile = fopen( argv[1], "r" );
// Get the directory containing the numerical results
fscanf( pCFGFile, "%s", szResultsDirectory );
// Get the number of temperature bins
fscanf( pCONFIGFile, "%i", &iNumBins );
fscanf( pCFGFile, "%i", &iNumBins );
// Get the bin width (dex)
ReadDouble( pCONFIGFile, &fdexStep );
ReadDouble( pCFGFile, &fdexStep );
// Allocate memory for the temperature intervals which define each bin
pflog10T = (double*)malloc( sizeof(double*) * ( iNumBins + 1 ) );
// Read the temperature intervals from the configuration file
for( i=0; i<(iNumBins+1); i++ ) {
ReadDouble( pCONFIGFile, &(pflog10T[i]) );
ReadDouble( pCFGFile, &(pflog10T[i]) );
}
// Get the number of output files to write
// (the specified range is split into this number and summed over to calculate each DEM(T))
fscanf( pCONFIGFile, "%i", &iNumOutputFiles );
fscanf( pCFGFile, "%i", &iNumOutputFiles );
// Get the input file range
fscanf( pCONFIGFile, "%i", &iFileRangeStart );
fscanf( pCONFIGFile, "%i", &iFileRangeEnd );
fscanf( pCFGFile, "%i", &iFileRangeStart );
fscanf( pCFGFile, "%i", &iFileRangeEnd );
// Close the configuration file
fclose( pCONFIGFile );
fclose( pCFGFile );

// Split the input file range to produce the specified number of output files
iSubRangeStep = ( iFileRangeEnd - iFileRangeStart ) / iNumOutputFiles;
Expand Down Expand Up @@ -100,8 +102,8 @@ for( i=0; i<iNumOutputFiles; i++ ) {
memset( pfDEM, '\0', iNumBins*sizeof(double) );
for( j=ppiFileSubRange[LOWER][i]; j<=ppiFileSubRange[UPPER][i]; j++ ) {
// Construct the .amr and .phy filenames
sprintf( szAMRFilename, "profile%i.amr", j );
sprintf( szPHYFilename, "profile%i.phy", j );
sprintf( szAMRFilename, "%s/profile%i.amr", szResultsDirectory, j );
sprintf( szPHYFilename, "%s/profile%i.phy", szResultsDirectory, j );
// Open the .amr file and read the header information
pAMRFile = fopen( szAMRFilename, "r" );
// Read the header
Expand Down Expand Up @@ -155,7 +157,7 @@ for( i=0; i<iNumOutputFiles; i++ ) {
fclose( pAMRFile );
}
// Construct the output filename
sprintf( szDEMFilename, "DEM(%ito%i).txt", ppiFileSubRange[LOWER][i], ppiFileSubRange[UPPER][i] );
sprintf( szDEMFilename, "%s/DEM(%ito%i).txt", szResultsDirectory, ppiFileSubRange[LOWER][i], ppiFileSubRange[UPPER][i] );
// Write the DEM(T) profile to the output file
pDEMFile = fopen( szDEMFilename, "w" );
fprintf( pDEMFile, "%i\n", iNumBins );
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
g++ -O3 -flto -Wall ../source/main.cpp ../../../../Radiation_Model/source/ionfrac.cpp ../../../../Radiation_Model/source/radiation.cpp ../../../../Radiation_Model/source/element.cpp ../../../source/fitpoly.cpp ../../../source/file.cpp -o ../../../../calculateIonizationTemperature.exe
g++ -O3 -flto -Wall ../source/main.cpp ../../../../Radiation_Model/source/ionfrac.cpp ../../../../Radiation_Model/source/radiation.cpp ../../../../Radiation_Model/source/element.cpp ../../../source/fitpoly.cpp ../../../source/file.cpp -o ../calculateIonizationTemperature.exe
2 changes: 1 addition & 1 deletion Resources/Utils/calculateIonizationTemperature/config.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Results
4.0 8.0 0.01
0 0
0 600

// Results directory
// (log10) temperature range and increment (dex)
Expand Down
28 changes: 14 additions & 14 deletions Resources/Utils/calculateIonizationTemperature/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// *
// * (c) Dr. Stephen J. Bradshaw
// *
// * Date last modified: 01/03/2023
// * Date last modified: 01/04/2023
// *
// ****

Expand All @@ -29,23 +29,23 @@ double fBuffer;
int iFrom, iTo, iNumCells;
int iBuffer, i, j;

if( argc > 1 ) {
// Open and read the configuration file
pCFGFile = fopen( argv[1], "r" );
// Get the directory containing the numerical results
fscanf( pCFGFile, "%s", szResultsDirectory );
// Get the (log) temperature range and increment (dex) over which to calculate the (effective) ionization temperature
for( i=0; i<3; i++ )
ReadDouble( pCFGFile, &(flogTRange[i]) );
// Get the range of output files over which to calculate the (effective) ionization temperature
fscanf( pCFGFile, "%i", &iFrom );
fscanf( pCFGFile, "%i", &iTo );
fclose( pCFGFile );
} else {
if( argc == 1 ) {
printf( "\nA configuration file must be specified. E.g. calculateIonizationTemperature config.cfg\n");
exit( EXIT_SUCCESS );
}

// Open and read the configuration file
pCFGFile = fopen( argv[1], "r" );
// Get the directory containing the numerical results
fscanf( pCFGFile, "%s", szResultsDirectory );
// Get the (log) temperature range and increment (dex) over which to calculate the (effective) ionization temperature
for( i=0; i<3; i++ )
ReadDouble( pCFGFile, &(flogTRange[i]) );
// Get the range of output files over which to calculate the (effective) ionization temperature
fscanf( pCFGFile, "%i", &iFrom );
fscanf( pCFGFile, "%i", &iTo );
fclose( pCFGFile );

pRadiation = new CRadiation( (char *)"Radiation_Model/config/elements_neq.cfg" );
pIonFrac = new CIonFrac( NULL, (char *)"Radiation_Model/config/elements_neq.cfg", pRadiation );

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
g++ -O3 -flto -Wall ../source/main.cpp ../../../../Radiation_Model/source/radiation.cpp ../../../../Radiation_Model/source/element.cpp ../../../../Radiation_Model/source/OpticallyThick/OpticallyThickIon.cpp ../../../source/fitpoly.cpp ../../../source/file.cpp -o ../../../../calculateVALheating.exe
g++ -O3 -flto -Wall ../source/main.cpp ../../../../Radiation_Model/source/radiation.cpp ../../../../Radiation_Model/source/element.cpp ../../../../Radiation_Model/source/OpticallyThick/OpticallyThickIon.cpp ../../../source/fitpoly.cpp ../../../source/file.cpp -o ../calculateVALheating.exe
12 changes: 6 additions & 6 deletions Resources/Utils/calculateVALheating/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// updateVAL.cpp
// main.cpp
//
// Updates the VAL heating profile in the case that the initial
// density profile has been altered.
//
// Created by Jeffrey Reep on 7/27/15.
// Created by Jeffrey Reep on 07/27/2015
//
//

Expand All @@ -21,10 +21,10 @@

using namespace std;

int main()
int main( void )
{

/*ifstream fin("Radiation_Model/atomic_data/OpticallyThick/VAL_atmospheres/VAL.heat");
/*
ifstream fin("Radiation_Model/atomic_data/OpticallyThick/VAL_atmospheres/VAL.heat");
int heat_num_lines,i;
double **heat_rows;
fin >> heat_num_lines;
Expand Down Expand Up @@ -198,4 +198,4 @@ int main()
outfile.close();

return 0;
}
}
Empty file.
1 change: 1 addition & 0 deletions Resources/Utils/extractQuantities/config.cfg
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Results
profile ine
2
1 f
Expand Down
28 changes: 17 additions & 11 deletions Resources/Utils/extractQuantities/source/main.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,36 @@
// *
// * (c) Dr. Stephen J. Bradshaw
// *
// * Date last modified: 01/21/2021
// * Date last modified: 01/04/2023
// *
// ****

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#include "../../../source/file.h"


int main(void)
int main( int argc, char **argv )
{
FILE *pCONFIGFile, *pINPUTFile, *pOUTPUTFile;
char **ppcDataType;
char szRoot[256], szExtension[32], szINPUTFilename[256], szOUTPUTFilename[256];
char szResultsDirectory[256], szRoot[256], szExtension[32], szINPUTFilename[256], szOUTPUTFilename[256];
char cBuffer;
double fBuffer;
int *piNumColumns, *piRow, *piColumn, iRange[2];
int iNumRows, iNumEntries, iEntry, iNumRecords;
int i, j, m, n;
int iBuffer;

if( argc == 1 ) {
printf( "\nA configuration file must be specified. E.g. extractQuantities config.cfg\n");
exit( EXIT_SUCCESS );
}

// Open the configuration file
pCONFIGFile = fopen( "config.cfg", "r" );
pCONFIGFile = fopen( argv[1], "r" );
// Get the directory containing the numerical results
fscanf( pCONFIGFile, "%s", szResultsDirectory );
// Get the filename structure of the files containing the data to be extracted
fscanf(pCONFIGFile, "%s", szRoot );
fscanf(pCONFIGFile, "%s", szExtension );
Expand All @@ -48,7 +54,7 @@ pCONFIGFile = fopen( "config.cfg", "r" );
}
}
// Get the number of entries to extract from each record
fscanf(pCONFIGFile, "%i", &iNumEntries );
fscanf( pCONFIGFile, "%i", &iNumEntries );
// Allocate memory to store the row and column number for each entry
piRow = (int*)malloc( sizeof(int) * iNumEntries );
piColumn = (int*)malloc( sizeof(int) * iNumEntries );
Expand All @@ -63,7 +69,7 @@ pCONFIGFile = fopen( "config.cfg", "r" );
// Close the configuration file
fclose( pCONFIGFile );

printf( "\n%s.%s\n", szRoot, szExtension );
printf( "\n%s/%s.%s\n", szResultsDirectory, szRoot, szExtension );
printf( "\niNumber of Rows = %i\n", iNumRows );
for( i=0; i<iNumRows; i++ ) {
printf( "Number of Columns in Row %i = %i\n", i+1, piNumColumns[i] );
Expand All @@ -86,7 +92,7 @@ for( i=iRange[0]; i<=iRange[1]; i++ ) {

// Get the number of records from the .amr file
// Construct the .amr filename and open the file
sprintf( szINPUTFilename, "profile%i.amr", i );
sprintf( szINPUTFilename, "%s/profile%i.amr", szResultsDirectory, i );
pINPUTFile = fopen( szINPUTFilename, "r" );
// Get the timestamp from the .amr file
ReadDouble( pINPUTFile, &fBuffer );
Expand All @@ -99,10 +105,10 @@ for( i=iRange[0]; i<=iRange[1]; i++ ) {
fclose( pINPUTFile );

// Construct the output filename and open the file
sprintf( szOUTPUTFilename, "profile%i.qts", i );
sprintf( szOUTPUTFilename, "%s/profile%i.qts", szResultsDirectory, i );
pOUTPUTFile = fopen( szOUTPUTFilename, "w" );
// Construct the input filename and open the file
sprintf( szINPUTFilename, "%s%i.%s", szRoot, i, szExtension );
sprintf( szINPUTFilename, "%s/%s%i.%s", szResultsDirectory, szRoot, i, szExtension );
pINPUTFile = fopen( szINPUTFilename, "r" );
// Extract the specified entries from each record and write them to a new file
for( j=0; j<iNumRecords; j++ ) {
Expand Down
2 changes: 2 additions & 0 deletions Resources/Utils/extractSpatialAverages/config.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Results
profile phy
11
3
Expand All @@ -7,6 +8,7 @@ profile phy
1
0 600

// Results directory
// Filename and Extension
// # Columns
// # Columns to Average
Expand Down
30 changes: 17 additions & 13 deletions Resources/Utils/extractSpatialAverages/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
// *
// * (c) Dr. Stephen J. Bradshaw
// *
// * Date last modified: 01/21/2021
// * Date last modified: 01/04/2023
// *
// ****

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#include "../../../../HYDRAD/source/config.h"
#include "../../../source/file.h"


// #define READ_ELECTRON_MASS_DENSITY // Required for runs using the optically-thick chromosphere model


int main(void)
int main( int argc, char **argv )
{
FILE *pCONFIGFile, *pAMRFile, *pEXTFile, *pOUTPUTFile;
char szRoot[256], szExtension[32], szAMRFilename[256], szEXTFilename[256], szOUTPUTFilename[256];
char szResultsDirectory[256], szRoot[256], szExtension[32], szAMRFilename[256], szEXTFilename[256], szOUTPUTFilename[256];
double *pfSum;
double fLLp, fULp, fLL, fUL;
double fTimeStamp, fL, fs, fds;
Expand All @@ -32,9 +30,15 @@ int iNumColumns, iNumAverages, iNumFiles, iNumCells;
int i, j, k, l, m, n;
int iBuffer;

// Open the configuration file
pCONFIGFile = fopen( "config.cfg", "r" );
if( argc == 1 ) {
printf( "\nA configuration file must be specified. E.g. extractSpatialAverages config.cfg\n");
exit( EXIT_SUCCESS );
}

// Open the configuration file
pCONFIGFile = fopen( argv[1], "r" );
// Get the directory containing the numerical results
fscanf( pCONFIGFile, "%s", szResultsDirectory );
// Get the filename structure of the files containing the data to be spatially averaged
fscanf(pCONFIGFile, "%s", szRoot );
fscanf(pCONFIGFile, "%s", szExtension );
Expand All @@ -55,9 +59,9 @@ pCONFIGFile = fopen( "config.cfg", "r" );
fLLp /= 100.0; fULp /= 100.0;

// Get the number of spatial average files to write
fscanf(pCONFIGFile, "%i", &iNumFiles );
fscanf( pCONFIGFile, "%i", &iNumFiles );

printf( "\n%s.%s\n", szRoot, szExtension );
printf( "\n%s/%s.%s\n", szResultsDirectory, szRoot, szExtension );
printf( "\nNumber of Columns = %i\n", iNumColumns );
printf( "\nNumber of Columns to Average = %i\n", iNumAverages );
printf( "\tColumns:");
Expand All @@ -78,7 +82,7 @@ pCONFIGFile = fopen( "config.cfg", "r" );
printf( " [%i,%i]", iRange[0], iRange[1] );

// Construct the output filename and open the file
sprintf( szOUTPUTFilename, "f(t)(%ito%i).txt", iRange[0], iRange[1] );
sprintf( szOUTPUTFilename, "%s/f(t)(%ito%i).txt", szResultsDirectory, iRange[0], iRange[1] );
pOUTPUTFile = fopen( szOUTPUTFilename, "w" );
// Write the number of rows to the output file
fprintf( pOUTPUTFile, "%i\n", (iRange[1]-iRange[0])+1 );
Expand All @@ -89,7 +93,7 @@ pCONFIGFile = fopen( "config.cfg", "r" );
pfSum[k] = 0.0;

// Construct the .amr filename and open the file
sprintf( szAMRFilename, "profile%i.amr", j );
sprintf( szAMRFilename, "%s/profile%i.amr", szResultsDirectory, j );
pAMRFile = fopen( szAMRFilename, "r" );
// Get the timestamp from the .amr file
ReadDouble( pAMRFile, &fTimeStamp );
Expand All @@ -102,7 +106,7 @@ pCONFIGFile = fopen( "config.cfg", "r" );
fscanf( pAMRFile, "%i", &iNumCells );

// Construct the .ext filename and open the file
sprintf( szEXTFilename, "%s%i.%s", szRoot, j, szExtension );
sprintf( szEXTFilename, "%s/%s%i.%s", szResultsDirectory, szRoot, j, szExtension );
pEXTFile = fopen( szEXTFilename, "r" );
for( k=0; k<iNumCells; k++ )
{
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions Resources/Utils/generatePieceWiseFit/fits/B(closed).txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@
0.98 26.91035506
0.99 28.13762816
1 29.40254167

// Order of polynomial fit
// Number of domains to fit
// Domain boundaries. E.g. 0 1 (one domain) or 0 0.5 1 (two domains)
// Number of tabulated data points
// Normalized spatial coordinate [0,1] and quantity to fit to
Loading

0 comments on commit 0d10714

Please sign in to comment.