Closed ikegami-t closed 2 weeks ago
Thanks!
I think we should do this differently. Instead adding a new command line option, we should consult the locale settings as we do in other places already.
The locale settings look not clear to map the temperature scales.
What's wrong with something like this?
#include <locale.h>
#include <stdio.h>
#include <string.h>
const char *guess_temperature_unit(const char *country)
{
const char* fahrenheit_countries[] = {"US", "BS", "BZ", "KY", "PW", NULL};
int i;
for (i = 0; fahrenheit_countries[i]; i++) {
if (!strcmp(country, fahrenheit_countries[i]) )
return "Fahrenheit";
}
return "Celsius";
}
int main(int argc, char *argv[])
{
const char* temperature_unit;
const char *locale, *tmp;
char country[3];
char *underscore;
setlocale(LC_ALL, "");
tmp = locale = setlocale(LC_ALL, NULL);
underscore = strchr(locale, '_');
if (underscore != NULL && strlen(underscore) > 1)
tmp += 3;
strncpy(country, tmp, 2);
country[2] = '\0';
temperature_unit = guess_temperature_unit(country);
printf("Locale: %s\n", locale);
printf("Country: %s\n", country);
printf("Temperature Unit: %s\n", temperature_unit);
return 0;
}
We could also look at the language settings if needed. I really don't see a problem with this.
In general with science it seems everyone is using metric. So maybe with this specific feature what we can do for fahrenheit_countries[] is to add in parenthesis the fahrenheit value: Temeperature : Value_In_Celsius (Value_In_fahrenheit )
Currently already both degrees celsius and kelvin values are output by the smart-log command and the -f option added outputs degrees fahrenheit and kelvin values.
tokunori@tokunori-desktop:~/nvme-cli$ nvme-build smart-log /dev/nvme0
...
temperature : 43 °C (316 K)
...
Temperature Sensor 1 : 43 °C (316 K)
Temperature Sensor 2 : 51 °C (324 K)
...
tokunori@tokunori-desktop:~/nvme-cli$ nvme-build smart-log /dev/nvme0 -f
...
temperature : 109 °F (316 K)
...
Critical Composite Temperature Time : 0
Temperature Sensor 1 : 109 °F (316 K)
Temperature Sensor 2 : 125 °F (325 K)
...
About the fahrenheit countries is it enough as the following countries but just checked other countries for example "AS", "AQ" and "CY" etc. also seem the fahrenheit countries?
const char* fahrenheit_countries[] = {"US", "BS", "BZ", "KY", "PW", NULL};
My search says that US is the only country which uses Fahrenheit as official temperature measurement.
Fahrenheit is used in the United States, its territories and associated states (all served by the U.S. National Weather Service), as well as the (British) Cayman Islands and Liberia for everyday applications. For example, U.S. weather forecasts, food cooking, and freezing temperatures are typically given in degrees Fahrenheit. Scientists, including meteorologists, use degrees Celsius or kelvin in all countries.
There are a few more countries which seems to use Fahrenheit. I'd say the above list looks okay. The last sentence from Wikipdia indicates that everyone else is able to deal with Celsius.
And if someone is unhappy that a specific country is missing we can still add it.
edit: unless you find the full list of territories of the associated states of US, feel free to add them :)
Yes I also searched the page so will do add the 19 countries into the list. Thank you.
Show temperatures in degrees fahrenheit by the option.