mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Centralization for Kelvin and Standardization to milliKelvin
This centralizes all occurrences of Kelvin to dive.h and standardizes all usages to milliKelvin. [Dirk Hohndel: renamed the constant plus minor white space cleanup] Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
67d8891af5
commit
50d0391dfb
5 changed files with 15 additions and 14 deletions
19
dive.h
19
dive.h
|
@ -11,13 +11,14 @@
|
|||
#include <libxml/tree.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#define O2_IN_AIR 209 // permille
|
||||
#define N2_IN_AIR 781
|
||||
#define O2_DENSITY 1429 // mg/Liter
|
||||
#define N2_DENSITY 1251
|
||||
#define HE_DENSITY 179
|
||||
#define SURFACE_PRESSURE 1013 // mbar
|
||||
#define O2_IN_AIR 209 // permille
|
||||
#define N2_IN_AIR 781
|
||||
#define O2_DENSITY 1429 // mg/Liter
|
||||
#define N2_DENSITY 1251
|
||||
#define HE_DENSITY 179
|
||||
#define SURFACE_PRESSURE 1013 // mbar
|
||||
#define SURFACE_PRESSURE_STRING "1013"
|
||||
#define ZERO_C_IN_MKELVIN 273150 // mKelvin
|
||||
|
||||
|
||||
/*
|
||||
|
@ -161,7 +162,7 @@ static inline int to_feet(depth_t depth)
|
|||
|
||||
static inline double mkelvin_to_C(int mkelvin)
|
||||
{
|
||||
return (mkelvin - 273150) / 1000.0;
|
||||
return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0;
|
||||
}
|
||||
|
||||
static inline double mkelvin_to_F(int mkelvin)
|
||||
|
@ -171,12 +172,12 @@ static inline double mkelvin_to_F(int mkelvin)
|
|||
|
||||
static inline unsigned long F_to_mkelvin(double f)
|
||||
{
|
||||
return (f-32) * 1000 / 1.8 + 273150.5;
|
||||
return (f-32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN + 0.5;
|
||||
}
|
||||
|
||||
static inline unsigned long C_to_mkelvin(double c)
|
||||
{
|
||||
return c * 1000 + 273150.5;
|
||||
return c * 1000 + ZERO_C_IN_MKELVIN + 0.5;
|
||||
}
|
||||
|
||||
static inline double psi_to_bar(double psi)
|
||||
|
|
|
@ -214,7 +214,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
|||
sample->cylinderpressure.mbar = value.pressure.value * 1000 + 0.5;
|
||||
break;
|
||||
case DC_SAMPLE_TEMPERATURE:
|
||||
sample->temperature.mkelvin = (value.temperature + 273.15) * 1000 + 0.5;
|
||||
sample->temperature.mkelvin = value.temperature * 1000 + ZERO_C_IN_MKELVIN + 0.5;
|
||||
break;
|
||||
case DC_SAMPLE_EVENT:
|
||||
handle_event(dc, sample, value);
|
||||
|
|
|
@ -348,7 +348,7 @@ static void temperature(char *buffer, void *_temperature)
|
|||
temperature->mkelvin = val.fp * 1000;
|
||||
break;
|
||||
case CELSIUS:
|
||||
temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5;
|
||||
temperature->mkelvin = val.fp * 1000 + ZERO_C_IN_MKELVIN + 0.5;
|
||||
break;
|
||||
case FAHRENHEIT:
|
||||
temperature->mkelvin = (val.fp + 459.67) * 5000/9;
|
||||
|
|
|
@ -37,7 +37,7 @@ static void show_milli(FILE *f, const char *pre, int value, const char *unit, co
|
|||
static void show_temperature(FILE *f, temperature_t temp, const char *pre, const char *post)
|
||||
{
|
||||
if (temp.mkelvin)
|
||||
show_milli(f, pre, temp.mkelvin - 273150, " C", post);
|
||||
show_milli(f, pre, temp.mkelvin - ZERO_C_IN_MKELVIN, " C", post);
|
||||
}
|
||||
|
||||
static void show_depth(FILE *f, depth_t depth, const char *pre, const char *post)
|
||||
|
|
4
uemis.c
4
uemis.c
|
@ -297,7 +297,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) {
|
|||
|
||||
datalen = uemis_convert_base64(base64, &data);
|
||||
|
||||
dive->dc.airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150;
|
||||
dive->dc.airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + ZERO_C_IN_MKELVIN;
|
||||
dive->dc.surface_pressure.mbar = *(uint16_t *)(data + 43);
|
||||
if (*(uint8_t *)(data + 19))
|
||||
dive->dc.salinity = 10300; /* avg grams per 10l sea water */
|
||||
|
@ -355,7 +355,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) {
|
|||
sample = prepare_sample(dc);
|
||||
sample->time.seconds = u_sample->dive_time;
|
||||
sample->depth.mm = rel_mbar_to_depth(u_sample->water_pressure, dive);
|
||||
sample->temperature.mkelvin = (u_sample->dive_temperature * 100) + 273150;
|
||||
sample->temperature.mkelvin = (u_sample->dive_temperature * 100) + ZERO_C_IN_MKELVIN;
|
||||
sample->sensor = active;
|
||||
sample->cylinderpressure.mbar =
|
||||
(u_sample->tank_pressure_high * 256 + u_sample->tank_pressure_low) * 10;
|
||||
|
|
Loading…
Reference in a new issue