Commit e9e40394 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Changed function names in the unit system to follow the SWFIT policy.

parent cbb63ff2
......@@ -232,7 +232,7 @@ int main(int argc, char *argv[]) {
/* Initialize unit system */
struct UnitSystem us;
initUnitSystem(&us, &params);
units_init(&us, &params);
if (myrank == 0) {
message("Unit system: U_M = %e g.", us.UnitMass_in_cgs);
message("Unit system: U_L = %e cm.", us.UnitLength_in_cgs);
......
......@@ -282,15 +282,15 @@ void writeUnitSystem(hid_t h_file, struct UnitSystem* us) {
if (h_grpunit < 0) error("Error while creating Unit System group");
writeAttribute_d(h_grpunit, "Unit mass in cgs (U_M)",
getBaseUnit(us, UNIT_MASS));
units_get_base_unit(us, UNIT_MASS));
writeAttribute_d(h_grpunit, "Unit length in cgs (U_L)",
getBaseUnit(us, UNIT_LENGTH));
units_get_base_unit(us, UNIT_LENGTH));
writeAttribute_d(h_grpunit, "Unit time in cgs (U_t)",
getBaseUnit(us, UNIT_TIME));
units_get_base_unit(us, UNIT_TIME));
writeAttribute_d(h_grpunit, "Unit current in cgs (U_I)",
getBaseUnit(us, UNIT_CURRENT));
units_get_base_unit(us, UNIT_CURRENT));
writeAttribute_d(h_grpunit, "Unit temperature in cgs (U_T)",
getBaseUnit(us, UNIT_TEMPERATURE));
units_get_base_unit(us, UNIT_TEMPERATURE));
H5Gclose(h_grpunit);
}
......
......@@ -274,11 +274,11 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
type);
/* Write unit conversion factors for this data set */
conversionString(buffer, us, convFactor);
units_conversion_string(buffer, us, convFactor);
writeAttribute_d(h_data, "CGS conversion factor",
conversionFactor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", hFactor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", aFactor(us, convFactor));
units_conversion_factor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", units_h_factor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", units_a_factor(us, convFactor));
writeAttribute_s(h_data, "Conversion factor", buffer);
/* Free and close everything */
......
......@@ -237,11 +237,11 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile,
writeXMFline(xmfFile, fileName, partTypeGroupName, name, N_total, dim, type);
/* Write unit conversion factors for this data set */
conversionString(buffer, us, convFactor);
units_conversion_string(buffer, us, convFactor);
writeAttribute_d(h_data, "CGS conversion factor",
conversionFactor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", hFactor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", aFactor(us, convFactor));
units_conversion_factor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", units_h_factor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", units_a_factor(us, convFactor));
writeAttribute_s(h_data, "Conversion factor", buffer);
H5Pclose(h_prop);
......
......@@ -241,11 +241,11 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
writeXMFline(xmfFile, fileName, partTypeGroupName, name, N, dim, type);
/* Write unit conversion factors for this data set */
conversionString(buffer, us, convFactor);
units_conversion_string(buffer, us, convFactor);
writeAttribute_d(h_data, "CGS conversion factor",
conversionFactor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", hFactor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", aFactor(us, convFactor));
units_conversion_factor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", units_h_factor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", units_a_factor(us, convFactor));
writeAttribute_s(h_data, "Conversion factor", buffer);
/* Free and close everything */
......
......@@ -48,7 +48,7 @@
* @param us The UnitSystem to initialize.
* @param params The parsed parameter file.
*/
void initUnitSystem(struct UnitSystem* us, const struct swift_params* params) {
void units_init(struct UnitSystem* us, const struct swift_params* params) {
us->UnitMass_in_cgs =
parser_get_param_double(params, "UnitSystem:UnitMass_in_cgs");
......@@ -68,7 +68,8 @@ void initUnitSystem(struct UnitSystem* us, const struct swift_params* params) {
* @param us The UnitSystem used
* @param baseUnit The base unit
*/
double getBaseUnit(const struct UnitSystem* us, enum BaseUnits baseUnit) {
double units_get_base_unit(const struct UnitSystem* us,
enum BaseUnits baseUnit) {
switch (baseUnit) {
case UNIT_MASS:
return us->UnitMass_in_cgs;
......@@ -90,7 +91,7 @@ double getBaseUnit(const struct UnitSystem* us, enum BaseUnits baseUnit) {
* @brief Returns the base unit symbol
* @param baseUnit The base unit
*/
const char* getBaseUnitSymbol(enum BaseUnits baseUnit) {
const char* units_get_base_unit_symbol(enum BaseUnits baseUnit) {
switch (baseUnit) {
case UNIT_MASS:
return "U_M";
......@@ -112,7 +113,7 @@ const char* getBaseUnitSymbol(enum BaseUnits baseUnit) {
* @brief Returns the base unit symbol in the cgs system
* @param baseUnit The base unit
*/
const char* getBaseUnitCGSSymbol(enum BaseUnits baseUnit) {
const char* units_get_base_unit_CGS_symbol(enum BaseUnits baseUnit) {
switch (baseUnit) {
case UNIT_MASS:
return "g";
......@@ -130,8 +131,8 @@ const char* getBaseUnitCGSSymbol(enum BaseUnits baseUnit) {
return "";
}
void getBaseUnitExponantsArray(float baseUnitsExp[5],
enum UnitConversionFactor unit) {
void units_get_base_unit_exponants_array(float baseUnitsExp[5],
enum UnitConversionFactor unit) {
switch (unit) {
case UNIT_CONV_NO_UNITS:
break;
......@@ -272,13 +273,13 @@ void getBaseUnitExponantsArray(float baseUnitsExp[5],
* @param us The system of units in use
* @param unit The unit to convert
*/
double conversionFactor(const struct UnitSystem* us,
enum UnitConversionFactor unit) {
double units_conversion_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
units_get_base_unit_exponants_array(baseUnitsExp, unit);
return generalConversionFactor(us, baseUnitsExp);
return units_general_conversion_factor(us, baseUnitsExp);
}
/**
......@@ -286,12 +287,13 @@ double conversionFactor(const struct UnitSystem* us,
* @param us The system of units in use
* @param unit The unit to convert
*/
float hFactor(const struct UnitSystem* us, enum UnitConversionFactor unit) {
float units_h_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
units_get_base_unit_exponants_array(baseUnitsExp, unit);
return generalhFactor(us, baseUnitsExp);
return units_general_h_factor(us, baseUnitsExp);
}
/**
......@@ -299,25 +301,26 @@ float hFactor(const struct UnitSystem* us, enum UnitConversionFactor unit) {
* @param us The system of units in use
* @param unit The unit to convert
*/
float aFactor(const struct UnitSystem* us, enum UnitConversionFactor unit) {
float units_a_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
units_get_base_unit_exponants_array(baseUnitsExp, unit);
return generalaFactor(us, baseUnitsExp);
return units_general_a_factor(us, baseUnitsExp);
}
/**
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors
*/
void conversionString(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit) {
void units_conversion_string(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
units_get_base_unit_exponants_array(baseUnitsExp, unit);
generalConversionString(buffer, us, baseUnitsExp);
units_general_conversion_string(buffer, us, baseUnitsExp);
}
/**
......@@ -327,14 +330,14 @@ void conversionString(char* buffer, const struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
double generalConversionFactor(const struct UnitSystem* us,
float baseUnitsExponants[5]) {
double units_general_conversion_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]) {
double factor = 1.;
int i;
for (i = 0; i < 5; ++i)
if (baseUnitsExponants[i] != 0)
factor *= pow(getBaseUnit(us, i), baseUnitsExponants[i]);
factor *= pow(units_get_base_unit(us, i), baseUnitsExponants[i]);
return factor;
}
......@@ -345,7 +348,8 @@ double generalConversionFactor(const struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float generalhFactor(const struct UnitSystem* us, float baseUnitsExponants[5]) {
float units_general_h_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]) {
float factor_exp = 0.f;
factor_exp += -baseUnitsExponants[UNIT_MASS];
......@@ -362,7 +366,8 @@ float generalhFactor(const struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float generalaFactor(const struct UnitSystem* us, float baseUnitsExponants[5]) {
float units_general_a_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]) {
float factor_exp = 0.f;
factor_exp += baseUnitsExponants[UNIT_LENGTH];
......@@ -379,11 +384,11 @@ float generalaFactor(const struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
void generalConversionString(char* buffer, const struct UnitSystem* us,
float baseUnitsExponants[5]) {
void units_general_conversion_string(char* buffer, const struct UnitSystem* us,
float baseUnitsExponants[5]) {
char temp[14];
double a_exp = generalaFactor(us, baseUnitsExponants);
double h_exp = generalhFactor(us, baseUnitsExponants);
double a_exp = units_general_a_factor(us, baseUnitsExponants);
double h_exp = units_general_h_factor(us, baseUnitsExponants);
int i;
/* Check whether we are unitless or not */
......@@ -423,12 +428,13 @@ void generalConversionString(char* buffer, const struct UnitSystem* us,
if (baseUnitsExponants[i] == 0.)
sprintf(temp, " ");
else if (baseUnitsExponants[i] == 1.)
sprintf(temp, "%s ", getBaseUnitSymbol(i));
sprintf(temp, "%s ", units_get_base_unit_symbol(i));
else if (remainder(baseUnitsExponants[i], 1.) == 0)
sprintf(temp, "%s^%d ", getBaseUnitSymbol(i),
sprintf(temp, "%s^%d ", units_get_base_unit_symbol(i),
(int)baseUnitsExponants[i]);
else
sprintf(temp, "%s^%7.4f ", getBaseUnitSymbol(i), baseUnitsExponants[i]);
sprintf(temp, "%s^%7.4f ", units_get_base_unit_symbol(i),
baseUnitsExponants[i]);
strncat(buffer, temp, 12);
}
......@@ -440,12 +446,12 @@ void generalConversionString(char* buffer, const struct UnitSystem* us,
if (baseUnitsExponants[i] == 0.)
continue;
else if (baseUnitsExponants[i] == 1.)
sprintf(temp, "%s ", getBaseUnitCGSSymbol(i));
sprintf(temp, "%s ", units_get_base_unit_CGS_symbol(i));
else if (remainder(baseUnitsExponants[i], 1.) == 0)
sprintf(temp, "%s^%d ", getBaseUnitCGSSymbol(i),
sprintf(temp, "%s^%d ", units_get_base_unit_CGS_symbol(i),
(int)baseUnitsExponants[i]);
else
sprintf(temp, "%s^%7.4f ", getBaseUnitCGSSymbol(i),
sprintf(temp, "%s^%7.4f ", units_get_base_unit_CGS_symbol(i),
baseUnitsExponants[i]);
strncat(buffer, temp, 12);
}
......
......@@ -92,21 +92,25 @@ enum UnitConversionFactor {
UNIT_CONV_TEMPERATURE
};
void initUnitSystem(struct UnitSystem*, const struct swift_params*);
double getBaseUnit(const struct UnitSystem*, enum BaseUnits);
const char* getBaseUnitSymbol(enum BaseUnits);
const char* getBaseUnitCGSSymbol(enum BaseUnits);
double generalConversionFactor(const struct UnitSystem* us,
float baseUnitsExponants[5]);
double conversionFactor(const struct UnitSystem* us,
enum UnitConversionFactor unit);
float generalhFactor(const struct UnitSystem* us, float baseUnitsExponants[5]);
float hFactor(const struct UnitSystem* us, enum UnitConversionFactor unit);
float generalaFactor(const struct UnitSystem* us, float baseUnitsExponants[5]);
float aFactor(const struct UnitSystem* us, enum UnitConversionFactor unit);
void generalConversionString(char* buffer, const struct UnitSystem* us,
void units_init(struct UnitSystem*, const struct swift_params*);
double units_get_base_unit(const struct UnitSystem*, enum BaseUnits);
const char* units_get_base_unit_symbol(enum BaseUnits);
const char* units_get_base_unit_CGS_symbol(enum BaseUnits);
double units_general_conversion_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]);
double units_conversion_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit);
float units_general_h_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]);
void conversionString(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit);
float units_h_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit);
float units_general_a_factor(const struct UnitSystem* us,
float baseUnitsExponants[5]);
float units_a_factor(const struct UnitSystem* us,
enum UnitConversionFactor unit);
void units_general_conversion_string(char* buffer, const struct UnitSystem* us,
float baseUnitsExponants[5]);
void units_conversion_string(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit);
#endif /* SWIFT_UNITS_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment