2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
15 #include "metarinfo.h"
18 static int status = 0;
21 int calculateRelativeHumidity(int temp, int dew)
24 rh = 100.0 * powf((112 - (0.1 * temp) + dew) /
25 (112 + (0.9 * temp)), 8);
29 int calculateWindChill(int temperatureC, int windKn)
31 double windKmh = knTokph(windKn);
32 return (int) (13.112 + 0.6215 * temperatureC -
35 0.3965 * temperatureC * powf(windKmh, .16));
38 int knTokph(int knSpeed)
40 return (knSpeed * 1.852);
43 const char *calculateWindDirectionString(int degree)
47 } else if (degree < 67.5) {
49 } else if (degree < 112.5) {
51 } else if (degree < 157.5) {
53 } else if (degree < 202.5) {
55 } else if (degree < 247.5) {
57 } else if (degree < 292.5) {
59 } else if (degree < 337.5) {
65 const char *calculateShortWindDirectionString(int degree)
69 } else if (degree < 67.5) {
71 } else if (degree < 112.5) {
73 } else if (degree < 157.5) {
75 } else if (degree < 202.5) {
77 } else if (degree < 247.5) {
79 } else if (degree < 292.5) {
81 } else if (degree < 337.5) {
88 void ftpData(void *userData, const char *data, int len)
91 } // do nothing to make stupid warning go away
100 extern unsigned int sleep(unsigned int);
104 // try three times if it fails
108 /* this happens too often, so i'll leave it commented fprintf(stderr, "METAR update failed for some reason, retry %i\n", tries); */
109 sleep(15); /* give it some time in case the server is busy or down */
113 if (strlen(metar_station) != 8) {
114 ERR("You didn't supply a valid METAR station code\n");
117 if (metar_server == NULL)
118 metar_server = strdup("weather.noaa.gov");
119 if (metar_path == NULL)
121 strdup("/data/observations/metar/stations");
125 res = connectFtp(metar_server, 0);
127 ERR("Couldn't connect to %s, retrying\n",
131 res = changeFtpDirectory(metar_path);
133 ERR("Metar update failed (couldn't CWD to %s)\n",
139 ERR("Metar update failed\n");
142 if (getFtp(ftpData, NULL, metar_station) < 0) {
143 ERR("Failed to get file %s\n", metar_station);
148 dcdNetMETAR(line, &data);
157 } while (ftp_ok == 0 && tries < 3);
162 static pthread_t thread1;
169 iret1 = pthread_create(&thread1, NULL, fetch_ftp, NULL);
170 } else if (status == 2) { /* thread is still running. let's kill it and start again */
171 pthread_cancel(thread1);
173 iret1 = pthread_create(&thread1, NULL, fetch_ftp, NULL);
174 } else { /* status must be 1 */
175 pthread_join(thread1, NULL);
177 iret1 = pthread_create(&thread1, NULL, fetch_ftp, NULL);