[Pkg-wmaker-commits] [wmfrog] 48/145: Many updates/fixes 0.3.0
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Sun Aug 23 05:46:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmfrog.
commit faa1a5f084f4f4158b66b7c9aebcd27242bdfc4b
Author: tcolar <devnull at localhost>
Date: Tue Nov 30 16:26:29 2010 -0800
Many updates/fixes
0.3.0
---
wmfrog/Src/Makefile | 2 +-
wmfrog/Src/weather.pl | 213 ++++----
wmfrog/Src/wmFrog.c | 1318 ++++++++++++++++++++++--------------------------
wmfrog/dist/weather.pl | 213 ++++----
wmfrog/dist/wmfrog | Bin 192497 -> 219724 bytes
5 files changed, 851 insertions(+), 895 deletions(-)
diff --git a/wmfrog/Src/Makefile b/wmfrog/Src/Makefile
index eb89f57..97a16f4 100644
--- a/wmfrog/Src/Makefile
+++ b/wmfrog/Src/Makefile
@@ -1,5 +1,5 @@
CC = gcc
-CFLAGS = -O2 -Wall
+CFLAGS = -g #-O2 -Wall
INCDIR = -I/usr/X11R6/include/X11 -I/usr/X11R6/include
LIBDIR = -L/usr/X11R6/lib
# for linux
diff --git a/wmfrog/Src/weather.pl b/wmfrog/Src/weather.pl
index f6b4a7c..5ceeccd 100755
--- a/wmfrog/Src/weather.pl
+++ b/wmfrog/Src/weather.pl
@@ -5,13 +5,18 @@
#The Weather data can be retrieved through http of ftp.
#Http is faster, however this might get broken if NOAA change their webpage layout
#in wich case you should choose ftp.
+
$mode="http"; # html || ftp
+$debug = 0; # turn On/Off debugging
+
########################################
# Start:
########################################
($station,$tmpfolder)=@ARGV;
+debug("station: $station ; tmpfolder: $tmpfolder");
+
mkdir($tmpfolder);
$html="http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=${station}";
@@ -32,25 +37,25 @@ if($mode eq "http")
{
while((! ($line=~m/START BODY OF TEXT HERE/)) && !eof(DATA))
{
-#print ".";
- $line=<DATA>;
+ $line=<DATA>;
}
$i=0;
while($i!=12 && !eof(DATA))
{
-#print "*";
- $line=<DATA>;
- $i++;
+ $line=<DATA>;
+ $i++;
}
}
+
if(eof(DATA))
{
-#print "Unreadable HTML source, no point going any further, stopping\n";
-exit(0);
+ debug("Unreadable HTML source, no point going any further, stopping\n");
+ exit(0);
}
+
$line=<DATA>;
chomp $line;
-($crap,$time)=split(/\ /,$line);
+($junk,$time)=split(/\ /,$line);
($hour,$minute)=split(/:/,$time);
$line="";
if($mode eq "http")
@@ -71,14 +76,11 @@ close DATA;
chomp $line;
@args=split(/\ /,$line);
-#print "line: $line";
-#print "args: @args";
-if(debug)
-{
- #print "@args\n";
-}
-#print "line: $line";
+debug("line: $line");
+debug("args: @args");
+debug("line: $line");
+
$i=0;
$station=@args[$i];
if(($station eq 'METAR') or ($station eq 'SPECI'))
@@ -96,28 +98,28 @@ if($wind eq 'AUTO')
$wind=@args[$i+1];
$i++;
}
-#print "wind: $wind";
+debug("wind: $wind");
+
$i++;
$visibility=@args[$i];
$i++;#Visibility
-if( ! ($visibility=~m/SM/ || ($visibility eq "CAVOK")) )
-{
- #print "Visibility fraction\n";
- $i++; # visibility with fractions, ignoring
-}
-$next=@args[$i];
-if($next=~m/FT/)
-{
- #print "Visibility feet\n";
- $i++; # visibility in feet, ignoring
-}
+debug("vis: $visibility");
+
+#if( ! ($visibility=~m/SM/ || ($visibility eq "CAVOK") || ($visibility eq "9999") ))
+#{
+# $i++; # visibility with fractions, not using
+#}
+#$next=@args[$i];
+#if($next=~m/FT/)
+#{
+# $i++; # visibility in feet, not using
+#}
$tmp="";
$weather="";
$clouds="";
while((! (@args[$i]=~/\//)) && ($i<@args))
{
-
$intensity="";
$desc="";
$precip="";
@@ -125,67 +127,70 @@ while((! (@args[$i]=~/\//)) && ($i<@args))
$misc="";
$j=0;
$curent=@args[$i];
+
+ debug("cur : $curent");
+
$wasCloud="no";
if($curent=~/^CAVOK/)
- {
+ {
$clouds.="CAVOK,0;";
$wasCloud="yes";
- }
+ }
if($curent=~/^VV/)
{
- $clouds.="VV,".substr($curent,2,3).";";
- $wasNotCloud="yes";
+ $clouds.="VV,".substr($curent,2,3).";";
+ $wasNotCloud="yes";
}
if(($curent=~/^CLR/) or ($curent=~/^SCK/) or ($curent=~/^FEW/) or ($curent=~/^SCT/) or ($curent=~/^BKN/) or ($curent=~/^OVC/))
- {
+ {
$clouds.=substr($curent,0,3).",".substr($curent,3,3).";";
$wasCloud="yes";
- }
-
-if(($wasCloud ne "yes"))
-{
- if(length($curent)>0)
- {
-# Should be weather
- if($curent=~/^\-/)
- {
- $intensity="-";
- $j=1;
- }
- if($curent=~/^\+/)
- {
- $intensity="+";
- $j=1;
- }
- if($curent=~/^VC/)
- {
- $j=2;
- }
- $curent=substr($curent,$j);
- if(($curent=~/^MI/) or ($curent=~/^PR/) or ($curent=~/^BC/) or ($curent=~/^DR/) or ($curent=~/^BL/) or ($curent=~/^SH/) or ($curent=~/^TS/) or ($curent=~/^FZ/) )
- {
- $desc=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^DZ/) or ($curent=~/^RA/) or ($curent=~/^SN/) or ($curent=~/^SG/) or ($curent=~/^IC/) or ($curent=~/^PE/) or ($curent=~/^GR/) or ($curent=~/^GX/) or ($curent=~/^UP/))
- {
- $precip=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^BR/) or ($curent=~/^FG/) or ($curent=~/^FU/) or ($curent=~/^VA/) or ($curent=~/^DU/) or ($curent=~/^SA/) or ($curent=~/^HZ/) or ($curent=~/^PY/))
- {
- $obsc=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^PO/) or ($curent=~/^SQ/) or ($curent=~/^FC/) or ($curent=~/^SS/))
- {
- $misc=substr($curent,0,2);
- }
- $weather.="$intensity,$desc,$precip,$obsc,$misc;";
}
-}
+ if(($wasCloud ne "yes"))
+ {
+ if(length($curent)>0)
+ {
+ # Should be weather
+ if($curent=~/^\-/)
+ {
+ $intensity="-";
+ $j=1;
+ }
+ if($curent=~/^\+/)
+ {
+ $intensity="+";
+ $j=1;
+ }
+ if($curent=~/^VC/)
+ {
+ $j=2;
+ }
+ $curent=substr($curent,$j);
+ if(($curent=~/^MI/) or ($curent=~/^PR/) or ($curent=~/^BC/) or ($curent=~/^DR/) or ($curent=~/^BL/) or ($curent=~/^SH/) or ($curent=~/^TS/) or ($curent=~/^FZ/) )
+ {
+ $desc=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^DZ/) or ($curent=~/^RA/) or ($curent=~/^SN/) or ($curent=~/^SG/) or ($curent=~/^IC/) or ($curent=~/^PE/) or ($curent=~/^GR/) or ($curent=~/^GX/) or ($curent=~/^UP/))
+ {
+ $precip=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^BR/) or ($curent=~/^FG/) or ($curent=~/^FU/) or ($curent=~/^VA/) or ($curent=~/^DU/) or ($curent=~/^SA/) or ($curent=~/^HZ/) or ($curent=~/^PY/))
+ {
+ $obsc=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^PO/) or ($curent=~/^SQ/) or ($curent=~/^FC/) or ($curent=~/^SS/))
+ {
+ $misc=substr($curent,0,2);
+ }
+ $weather.="$intensity,$desc,$precip,$obsc,$misc;";
+ }
+
+ }
$i++;
}
($temp,$dew)=split(/\//, at args[$i]);
@@ -246,6 +251,18 @@ if($dew eq "")
$station="";
}
+debug("Hour:$hour");
+debug("Minute:$minute");
+debug("Station:$station");
+debug("WindDir:$dir");
+debug("WindSpeed:$speed");
+debug("WindGust:$gust");
+debug("Weather:$weather");
+debug("Clouds:$clouds");
+debug("Temp:$temp");
+debug("Dew:$dew");
+
+
#check for ok temperature
open(GREP, "grep Temp $tmpfolder/${station} | ");
$templine=<GREP>;
@@ -268,31 +285,41 @@ $templine=~m/^Temp:(.*)$/;
}
else
{
- #invalid
- $station="";
+ $station="";
}
}
close GREP;
-#print "$$station\n";
+debug("Station: $station");
+
if(length($station)==4)
{
-#print "OK\n";
-open(FILE,"> $tmpfolder/${station}");
-print FILE "Hour:$hour\n";
-print FILE "Minute:$minute\n";
-print FILE "Station:$station\n";
-print FILE "WindDir:$dir\n";
-print FILE "WindSpeed:$speed\n";
-print FILE "WindGust:$gust\n";
-print FILE "Weather:$weather\n";
-print FILE "Clouds:$clouds\n";
-print FILE "Temp:$temp\n";
-print FILE "Dew:$dew\n";
-close FILE
+ debug("Data OK");
+ open(FILE,"> $tmpfolder/${station}");
+ print FILE "Hour:$hour\n";
+ print FILE "Minute:$minute\n";
+ print FILE "Station:$station\n";
+ print FILE "WindDir:$dir\n";
+ print FILE "WindSpeed:$speed\n";
+ print FILE "WindGust:$gust\n";
+ print FILE "Weather:$weather\n";
+ print FILE "Clouds:$clouds\n";
+ print FILE "Temp:$temp\n";
+ print FILE "Dew:$dew\n";
+ close FILE
}
else
{
-#print "Invalid data, not writing to file, stopping\n";
+ debug("Invalid data, not writing to file, stopping\n");
}
+# end main
+
+sub debug()
+{
+ my($str) = @_;
+ if($debug)
+ {
+ print "$str\n";
+ }
+}
diff --git a/wmfrog/Src/wmFrog.c b/wmfrog/Src/wmFrog.c
index 8efb55c..c5d3e01 100644
--- a/wmfrog/Src/wmFrog.c
+++ b/wmfrog/Src/wmFrog.c
@@ -3,12 +3,14 @@
This is a dockapp wich shows you the weather at a specific location
from it's METAR code.
If this program blew up your computer it isn't my fault :-)
- This use a bit of code borrowed from the wmWeather application.
+ This use a bit of code borrowed from the wmWeather application(originally).
+
+ To build from src needs libxpm-dev, libx11-dev, libext-dev
*/
-/*
- * Includes
+/*
+ * Includes
*/
#include <stdio.h>
#include <math.h>
@@ -26,680 +28,601 @@
-/*
- * Delay between refreshes (in microseconds)
+/*
+ * Delay between refreshes (in microseconds)
*/
-#define DELAY 100000L
-#define VERSION "0.1.6"
-// 5 mn
-#define DEFAULT_UPDATEDELAY 900L
+#define DEBUG 0
+#define VERSION "0.3.0"
+// 5 mn in seconds
+#define DEFAULT_UPDATEDELAY 300L
// max wind in KNOTS
#define MAX_WIND 50
#define TIME_OFFSET 0
#define METRIC 0
-void ParseCMDLine(int argc, char *argv[]);
-void ButtonPressEvent(XButtonEvent *);
-void KeyPressEvent(XKeyEvent *);
-char *StringToUpper(char *);
-char *mystrsep(char **stringp, char *delim);
-char *GetTempDir(char *suffix);
+void ParseCMDLine(int argc, char *argv[]);
+void ButtonPressEvent(XButtonEvent *);
+void KeyPressEvent(XKeyEvent *);
+char *StringToUpper(char *);
+char *mystrsep(char **stringp, char *delim);
+char *GetTempDir(char *suffix);
-char StationID[10];
-char Label[20];
-int UpToDate = 0;
+char StationID[10];
+char Label[20];
int Metric = METRIC;
int ForceUpdate = 1;
-int ForceDownload = 1;
-int maxWind=MAX_WIND;
-int timeOffset=TIME_OFFSET;
-long UpdateDelay;
-int GotFirstClick1, GotDoubleClick1;
-int GotFirstClick2, GotDoubleClick2;
-int GotFirstClick3, GotDoubleClick3;
-int DblClkDelay;
-char* folder;
-
-/*
- * main
+int maxWind=MAX_WIND;
+int timeOffset=TIME_OFFSET;
+long UpdateDelay;
+int GotFirstClick1, GotDoubleClick1;
+int GotFirstClick2, GotDoubleClick2;
+int GotFirstClick3, GotDoubleClick3;
+int DblClkDelay;
+char* folder;
+/*
+ * main
*/
-int main(int argc, char *argv[]) {
-int n, s, m, i, dt1, dt2, dt3 ;
-XEvent event;
-char command[1024], Line[512], FileName[128];
-FILE *fp;
- char* Weather = NULL;
- char* Clouds = NULL;
- char* tmp1 = NULL;
- char* tmp2 = NULL;
- int intensity=0;
- char* precip;
- char* desc;
- char* obsc;
- char* misc;
- char* coverage;
- int keepgoing=0;
- int weatherFound=0;
- int cloudsFound=0;
- char chr;
- int temp=0;
- int dew=0;
- float humidity=0;
- float z;
- int y;
- int wind=0;
- int gust=0;
- int min=0;
- int hour=0;
- int dir=-1;
- int q;
-
- folder=GetTempDir(".wmapps");
- //fprintf(stderr,"User dir: %s\n",folder);
+int main(int argc, char *argv[])
+{
+ int n, s, m, i, dt1, dt2, dt3 ;
+ XEvent event;
+ char command[1024], Line[512], FileName[128];
+ FILE *fp;
+ char* Weather;
+ char* Clouds;
+ char* tmp1 = NULL;
+ char* tmp2 = NULL;
+ int intensity=0;
+ char* precip;
+ char* desc;
+ char* obsc;
+ char* misc;
+ char* coverage;
+ int keepgoing=0;
+ int weatherFound=0;
+ int cloudsFound=0;
+ char chr;
+ int temp=0;
+ int dew=0;
+ float humidity=0;
+ float z;
+ int y;
+ int wind=0;
+ int gust=0;
+ int min=0;
+ int hour=0;
+ int dir=-1;
+ int q;
+ int ign;
+ char* igns;
+ char* wtr;
+ char* clds;
+ int passes = 0;
+
+ Weather = (char*)malloc(512);
+ Clouds = (char*)malloc(512);
+ igns = (char*)malloc(512);
+
+ folder=GetTempDir(".wmapps");
/*
* Parse any command line arguments.
*/
ParseCMDLine(argc, argv);
-
+
initXwindow(argc, argv);
- openXwindow(argc, argv, frog_xpm, frog_bits, frog_width,
- frog_height, "#181818", "#79bdbf", "#ff0000", "#ffbf50", "#c5a6ff");
-
+ openXwindow(argc, argv, frog_xpm, frog_bits, frog_width,
+ frog_height, "#181818", "#79bdbf", "#ff0000", "#ffbf50", "#c5a6ff");
+
/*
* Loop until we die
*/
- n = 32000;
- s = 32000;
- m = 32000;
- dt1 = 32000;
- dt2 = 32000;
- dt3 = 32000;
- DblClkDelay = 32000;
- UpToDate = 0;
- while(1) {
-
-
-
-
- /*
- * Keep track of # of seconds
- */
- if (m > 1000000/DELAY){
-
- m = 0;
- ++dt1;
- ++dt2;
- ++dt3;
-
- } else {
-
- /*
- * Increment counter
- */
- ++m;
-
- }
+ while (1)
+ {
+ /*
+ * Check the Current Conditions file every (approx.) several seconds.
+ */
+ intensity=0;
+ desc="";
+ precip="";
+ obsc="";
+ misc="";
+ coverage="";
+ dir=-1;
+ /*
+ * Execute Perl script to grab the Latest METAR Report
+ */
+ snprintf(command, 1024, "/usr/lib/wmfrog/weather.pl %s %s", StationID, folder);
+ //printf("Retrieveing data\n");
+ ign = system(command);
+
+ snprintf(FileName, 128, "%s/%s", folder, StationID);
+ //fprintf(stderr,"%s\n\n",FileName);
+ if ((fp = fopen(FileName, "r")) != NULL)
+ {
+ ign = fscanf(fp, "Hour:%d", &hour);
+ igns = fgets(Line, 512, fp);//h
+ ign = fscanf(fp, "Minute:%d", &min);
+ igns = fgets(Line, 512, fp);//mn
+ igns = fgets(igns, 512, fp);//station -> ignored
+ ign = fscanf(fp, "WindDir:%d", &dir);
+ igns = fgets(Line, 512, fp);//dir
+ ign = fscanf(fp, "WindSpeed:%d", &wind);
+ igns = fgets(Line, 512, fp);//wind
+ ign = fscanf(fp, "WindGust:%d", &gust);
+ igns = fgets(Line, 512, fp);//gust
+ igns = fgets(Weather, 512, fp);//weather
+ weatherFound = (*igns != '\0');
+ igns = fgets(Clouds, 512, fp);//clouds
+ cloudsFound = (*igns != '\0');
+ ign = fscanf(fp, "Temp:%d", &temp);
+ igns = fgets(Line, 512, fp);//temp
+ ign = fscanf(fp,"Dew:%d", &dew);
+ igns = fgets(Line, 512, fp);//dew
+
+ if (DEBUG)
+ {
+ printf("hr: %d\n", hour);
+ printf("mn: %d\n", min);
+ printf("wd: %d\n", dir);
+ printf("ws: %d\n", wind);
+ printf("wg: %d\n", gust);
+ printf("temp: %d\n", temp);
+ printf("dew: %d\n", dew);
+ printf("w: %s\n", Weather);
+ printf("c: %s\n", Clouds);
+ }
+ fclose(fp);
+
+ keepgoing=1;
+
+ if (weatherFound)
+ {
+ wtr = strchr(Weather,':') + 1; // get the part after "Weather:"
+ if (DEBUG) printf("weatherLine: %s\n", wtr);
+ do
+ {
+ tmp1=mystrsep(&wtr,";");
+ if (tmp1 && strlen(tmp1) > 2)
+ {
+ if (DEBUG) printf("tmp1: %s\n",tmp1);
+ tmp2=mystrsep(&tmp1,",");
+
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ if (strcmp("-",tmp2)==0)
+ {
+ intensity=-1;
+ }
+ else if (strcmp("+",tmp2)==0)
+ {
+ intensity=+1;
+ }
+ }
+ tmp2=mystrsep(&tmp1,",");
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ desc=tmp2;
+ }
+ tmp2=mystrsep(&tmp1,",");
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ precip=tmp2;
+ }
+ tmp2=mystrsep(&tmp1,",");
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ obsc=tmp2;
+ }
+ tmp2=mystrsep(&tmp1,",");
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ misc=tmp2;
+ }
+ }
+ else
+ {
+ keepgoing=0;
+ }
+ if (DEBUG) printf("Intensity: %d \n",intensity);
+ }
+ while (keepgoing);
+ }
+ if (cloudsFound)
+ {
+ clds = strchr(Clouds,':') + 1;// get the part after "Clouds:"
+ if (DEBUG) printf("cloudsLine: %s\n", clds);
+ do
+ {
+ tmp1=mystrsep(&clds,";");
+ if (DEBUG) printf("tmp1: %s\n",tmp1);
+ if (tmp1 && strlen(tmp1) > 2)
+ {
+ tmp2=mystrsep(&tmp1,",");
+
+ if (tmp2 && strcmp(tmp2,"")!=0)
+ {
+ coverage=tmp2;
+ }
+ }
+ if (DEBUG) printf("Coverage: |%s|\n",coverage);
+ }
+ while (tmp1);
+ }
+ humidity=((112.0-0.1*temp+dew)/(112.0+0.9*temp));
+ z=humidity;
+ for (i=0; i!=8; i++)
+ humidity*=z;
+ humidity*=100;
+ if (humidity>100)
+ humidity=100;
+ if (humidity<0)
+ humidity=0;
+
+ hour=hour+timeOffset;
+ if (hour<0)
+ hour=24+hour;
+ if (hour>24)
+ hour=hour-24;
+
+ if (!Metric)
+ temp=(temp*9)/5+32;
+ }
/*
- * Double Click Delays
- * Keep track of click events. If Delay too long, set GotFirstClick's to False.
+ * Draw window.
+ */
+ /*
+ * Clear window.
*/
- if (DblClkDelay > 15) {
+ copyXPMArea(0,64,56,56,4,4);
- DblClkDelay = 0;
- GotFirstClick1 = 0; GotDoubleClick1 = 0;
- GotFirstClick2 = 0; GotDoubleClick2 = 0;
- GotFirstClick3 = 0; GotDoubleClick3 = 0;
+ //clouds
+ if (strcmp(coverage,"FEW")==0)
+ {
+ copyXPMArea(0, 183, 56, 15, 4, 4);
+ }
+ if (strcmp(coverage,"SCT")==0)
+ {
+ copyXPMArea(56, 183, 56, 15, 4, 4);
+ }
+ if (strcmp(coverage,"BKN")==0)
+ {
+ copyXPMArea(112, 183, 56, 15, 4, 4);
+ }
+ if (strcmp(coverage,"OVC")==0 || strcmp(coverage,"VV")==0)
+ {
+ copyXPMArea(168, 183, 56, 15, 4, 4);
+ }
- } else {
+ //obstruction
+ if (strcmp(obsc,"")!=0)
+ { //fog
+ if (strcmp(desc,"BL")==0)
+ copyXPMArea(56, 90, 56, 26, 4, 34);
+ else if (strcmp(desc,"FZ")==0)
+ copyXPMArea(112, 90, 56, 26, 4, 34);
+ else
+ copyXPMArea(168, 64, 56, 26, 4, 34);
+ }
- ++DblClkDelay;
+ //precipitation
+ if (strcmp(precip,"DZ")==0)
+ {
+ copyXPMArea(112, 120, 56, 15, 4, 18);
+ }
+ if (strcmp(precip,"RA")==0)
+ {
+ if (intensity==0)
+ copyXPMArea(56, 150, 56, 15, 4, 18);
+ if (intensity<0)
+ copyXPMArea(0, 150, 56, 15, 4, 18);
+ if (intensity>0)
+ copyXPMArea(112, 150, 56, 15, 4, 18);
+ }
+ if (strcmp(precip,"SN")==0 || strcmp(precip,"SG")==0)
+ {
+ if (intensity==0)
+ copyXPMArea(56, 135, 56, 15, 4, 18);
+ if (intensity>0)
+ copyXPMArea(112, 135, 56, 15, 4, 18);
+ if (intensity<0)
+ copyXPMArea(0, 135, 56, 15, 4, 18);
}
+ if (strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0)
+ {
+ if (intensity==0)
+ copyXPMArea(56, 166, 56, 16, 4, 18);
+ if (intensity>0)
+ copyXPMArea(112, 166, 56, 16, 4, 18);
+ if (intensity<0)
+ copyXPMArea(0, 166, 56, 16, 4, 18);
+ }
+ //descriptor
+ if (strcmp(desc,"BL")==0 && strcmp(obsc,"")==0)
+ {
+ copyXPMArea(56, 64, 56, 26, 4, 34);
+ }
+ if (strcmp(desc,"FZ")==0 && strcmp(obsc,"")==0)
+ {
+ copyXPMArea(112, 64, 56, 26, 4, 34);
+ }
+ if (strcmp(desc,"TS")==0)
+ {
+ if (strcmp(precip,"")!=0)
+ copyXPMArea(164, 150, 56, 15, 4, 18);
+ else
+ copyXPMArea(56, 120, 56, 15, 4, 18);
+ }
- /*
- * Process any pending X events.
- */
- while(XPending(display)){
- XNextEvent(display, &event);
- switch(event.type){
- case Expose:
- RedrawWindow();
- break;
- case ButtonPress:
- ButtonPressEvent(&event.xbutton);
- break;
- case KeyPress:
- KeyPressEvent(&event.xkey);
- break;
- case ButtonRelease:
- break;
- case EnterNotify:
- XSetInputFocus(display, PointerRoot, RevertToParent, CurrentTime);
- break;
- case LeaveNotify:
- XSetInputFocus(display, PointerRoot, RevertToParent, CurrentTime);
- break;
+ //special
+ if (strcmp(misc,"")!=0)
+ {
+ copyXPMArea(168, 90, 56, 26, 4, 34);
+ copyXPMArea(0, 120, 56, 15, 4, 18);
+ copyXPMArea(168, 183, 56, 16, 4, 4);
- }
}
-
-
-
- /*
- * Check the Current Conditions file every (approx.) several seconds.
- * Can significantly reduce this frequency later. But its
- * easier to debug this way...
- * Do this before trying to download again! The file may be there and it
- * may be Up-To-Date!
- */
- intensity=0;
- desc="";
- precip="";
- obsc="";
- misc="";
- coverage="";
- dir=-1;
-
- if ((dt2 > 15)||(ForceUpdate)){
-
- dt2 = 0;
-
- snprintf(FileName, 128, "%s/%s", folder, StationID);
- fprintf(stderr,"%s\n\n",FileName);
- if ((fp = fopen(FileName, "r")) != NULL){
- fscanf(fp, "Hour:%d", &hour);
- fgets(Line, 512, fp);//h
- fscanf(fp, "Minute:%d", &min);
- fgets(Line, 512 , fp);//station
- fgets(Line, 512, fp);//wdir
- fscanf(fp, "WindDir:%d", &dir);
- fgets(Line, 512, fp);//wspeed
- fscanf(fp, "WindSpeed:%d", &wind);
- fgets(Line, 512, fp);//wgust
- fscanf(fp, "WindGust:%d", &gust);
- fgets(Line, 512, fp);//weat
- weatherFound=fscanf(fp, "Weather:%as", &Weather);
- fgets(Line, 512, fp);//cld
- cloudsFound=fscanf(fp, "Clouds:%as", &Clouds);
- fgets(Line, 512, fp);//temp
- fscanf(fp, "Temp:%d", &temp);
- fgets(Line, 512, fp);//dew
- fscanf(fp,"Dew:%d", &dew);
- fclose(fp);
- keepgoing=1;
- {
-
- if(weatherFound) do {
- tmp1=mystrsep(&Weather,";");
- if(tmp1)
- {
-
- tmp2=mystrsep(&tmp1,",");
-
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- if(strcmp("-",tmp2)==0)
- {
- intensity=-1;
- }
- else if(strcmp("+",tmp2)==0)
- {
- intensity=+1;
- }
- }
- tmp2=mystrsep(&tmp1,",");
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- desc=tmp2;
- }
- tmp2=mystrsep(&tmp1,",");
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- precip=tmp2;
- }
- tmp2=mystrsep(&tmp1,",");
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- obsc=tmp2;
- }
- tmp2=mystrsep(&tmp1,",");
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- misc=tmp2;
- }
-
- }
- else
- {
- keepgoing=0;
- }
-
- }
- while(keepgoing);
- }
-
- if(cloudsFound) do {
- tmp1=mystrsep(&Clouds,";");
- if(tmp1)
- {
- tmp2=mystrsep(&tmp1,",");
-
- if(tmp2 && strcmp(tmp2,"")!=0)
- {
- coverage=tmp2;;
- }
- }
- }
- while(tmp1);
-
- humidity=((112.0-0.1*temp+dew)/(112.0+0.9*temp));
- z=humidity;
- for(i=0;i!=8;i++)
- humidity*=z;
- humidity*=100;
- if(humidity>100)
- humidity=100;
- if(humidity<0)
- humidity=0;
-
-
- hour=hour+timeOffset;
- if(hour<0)
- {
- hour=24+hour;
- }
- if(hour>24)
- {
- hour=hour-24;
- }
-
- if(!Metric)
- {
- temp=(temp*9)/5+32;
- }
-
- }
-
-
-
- }
-
-
- /*
- * Draw window.
- */
- if ( (dt3 > 15) || ForceUpdate){
-
- dt3 = 0;
-
-
-
- /*
- * Clear window.
- */
- copyXPMArea(0,64,56,56,4,4);
-
-
- //clouds
- if(strcmp(coverage,"FEW")==0)
- {
- copyXPMArea(0, 183, 56, 15, 4, 4);
- }
- if(strcmp(coverage,"SCT")==0)
- {
- copyXPMArea(56, 183, 56, 15, 4, 4);
- }
- if(strcmp(coverage,"BKN")==0)
- {
- copyXPMArea(112, 183, 56, 15, 4, 4);
- }
- if(strcmp(coverage,"OVC")==0 || strcmp(coverage,"VV")==0)
- {
- copyXPMArea(168, 183, 56, 15, 4, 4);
- }
-
- //obstruction
- if(strcmp(obsc,"")!=0)
- { //fog
- if(strcmp(desc,"BL")==0)
- copyXPMArea(56, 90, 56, 26, 4, 34);
- else
- if(strcmp(desc,"FZ")==0)
- copyXPMArea(112, 90, 56, 26, 4, 34);
- else
- copyXPMArea(168, 64, 56, 26, 4, 34);
- }
-
- //precipitation
- if(strcmp(precip,"DZ")==0)
- {
- copyXPMArea(112, 120, 56, 15, 4, 18);
- }
- if(strcmp(precip,"RA")==0)
- {
- if(intensity==0)
- copyXPMArea(56, 150, 56, 15, 4, 18);
- if(intensity<0)
- copyXPMArea(0, 150, 56, 15, 4, 18);
- if(intensity>0)
- copyXPMArea(112, 150, 56, 15, 4, 18);
- }
-
- if(strcmp(precip,"SN")==0 || strcmp(precip,"SG")==0)
- {
- if(intensity==0)
- copyXPMArea(56, 135, 56, 15, 4, 18);
- if(intensity>0)
- copyXPMArea(112, 135, 56, 15, 4, 18);
- if(intensity<0)
- copyXPMArea(0, 135, 56, 15, 4, 18);
- }
-
- if(strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0 || strcmp(precip,"IC")==0)
- {
- if(intensity==0)
- copyXPMArea(56, 166, 56, 16, 4, 18);
- if(intensity>0)
- copyXPMArea(112, 166, 56, 16, 4, 18);
- if(intensity<0)
- copyXPMArea(0, 166, 56, 16, 4, 18);
- }
-
- //descriptor
- if(strcmp(desc,"BL")==0 && strcmp(obsc,"")==0)
- {
- copyXPMArea(56, 64, 56, 26, 4, 34);
- }
- if(strcmp(desc,"FZ")==0 && strcmp(obsc,"")==0)
- {
- copyXPMArea(112, 64, 56, 26, 4, 34);
- }
- if(strcmp(desc,"TS")==0)
- {
- if(strcmp(precip,"")!=0)
- copyXPMArea(164, 150, 56, 15, 4, 18);
- else
- copyXPMArea(56, 120, 56, 15, 4, 18);
- }
-
- //special
- if(strcmp(misc,"")!=0)
- {
- copyXPMArea(168, 90, 56, 26, 4, 34);
- copyXPMArea(0, 120, 56, 15, 4, 18);
- copyXPMArea(168, 183, 56, 16, 4, 4);
-
- }
-
- //writtings:
-
- //clearing:
- copyXPMArea(170, 20, 25, 17, 29, 44);
- copyXPMArea(220, 0, 3, 60, 4, 4);
- copyXPMArea(220, 0, 3, 60, 57, 4);
- copyXPMArea(220, 0, 3, 60, 4, 4);
-
- //humidity
- y=(humidity*58)/100;
- copyXPMArea(60, 0, 1, y, 4, 60-y);
- copyXPMArea(60, 0, 1, y, 5, 60-y);
-
- //wind & gust
-
- y=(gust*58)/maxWind;
- copyXPMArea(62, 0, 1, y, 58, 60-y);
- copyXPMArea(62, 0, 1, y, 59, 60-y);
- y=(wind*58)/maxWind;
- copyXPMArea(61, 0, 1, y, 58, 60-y);
- copyXPMArea(61, 0, 1, y, 59, 60-y);
-
- //station name
- for(i=0;i!=4;i++)
- {
- chr = (int)Label[i] - 65;
- copyXPMArea(chr*5+89, 0, 5, 6, 31+(i*5), 45);
- }
-
- //time
- i=hour/10;
- copyXPMArea(89+(i*5), 7, 5, 6, 30, 53);
- i=hour-((hour/10)*10);
- copyXPMArea(89+(i*5), 7, 5, 6, 35, 53);
- copyXPMArea(89+(52), 7, 1, 6, 41, 53);
- i=min/10;
- copyXPMArea(89+(i*5), 7, 5, 6, 43, 53);
- i=min-((min/10)*10);
- copyXPMArea(89+(i*5), 7, 5, 6, 48, 53);
-
-
- //temp
-
- q=10;
- copyXPMArea(136, 30, 17, 9, q-1, 22);
- if(temp<0)
- {
- copyXPMArea(90, 30, 3, 7, q, 23);
- q+=5;
- }
- /*if(temp>100)
- {
- copyXPMArea(96, 20, 5, 7, q, 23);
- q+=6;
- }
-*/
- copyXPMArea(136, 30, 17, 9, (q-1), 22);
-
-
- i=temp;
- if(i<0)
- i=-i;
- if(i/100>0)
- {
- copyXPMArea(96, 20, 5, 7, q, 23);
- q+=6;
- i-=100;
- }
- if((i==0 && q>10) || i/10>0 || q > 10)
- {
- copyXPMArea(90+6*(i/10), 20, 5, 7, q, 23);
- q+=6;
- }
-
- copyXPMArea(90+6*(i-((i/10)*10)), 20, 5, 7, q, 23);
- q+=5;
- copyXPMArea(95, 29, 5, 7, q, 23);
-
- // wind dir
- if((dir>=0 && dir<=22) || (dir<=360 && dir>337))
- copyXPMArea(0, 198, 7, 7, 48, 6);
- if(dir>22 && dir<=67)
- copyXPMArea(42, 198, 7, 7, 48, 6);
- if(dir>67 && dir<=112)
- copyXPMArea(14, 198, 7, 7, 48, 6);
- if(dir>112 && dir<=157)
- copyXPMArea(28, 198, 7, 7, 48, 6);
- if(dir>157 && dir<=202)
- copyXPMArea(7, 198, 7, 7, 48, 6);
- if(dir>202 && dir<=247)
- copyXPMArea(35, 198, 7, 7, 48, 6);
- if(dir>247 && dir<=292)
- copyXPMArea(21, 198, 7, 7, 48, 6);
- if(dir>292 && dir<=337)
- copyXPMArea(49, 198, 7, 7, 48, 6);
-
- /*
- * Make changes visible
- */
- RedrawWindow();
-
-
-
-
-
-
- /*
- * Reset "force update" flag
- */
- ForceUpdate = 0;
- }
-
-
-
- /*
- * Check every 5 min if the values are not up to date...
- */
-/*
- * We still need to add a flashing LED to warn about
- * times that are out of date. Also need to determine if it is uptodate...
- */
-UpToDate = 0;
- if (((!UpToDate)&&(dt1 > UpdateDelay)) || ForceDownload){
- dt1 = 0;
+ //writtings:
+
+ //clearing:
+ copyXPMArea(170, 20, 25, 17, 29, 44);
+ copyXPMArea(220, 0, 3, 60, 4, 4);
+ copyXPMArea(220, 0, 3, 60, 57, 4);
+ copyXPMArea(220, 0, 3, 60, 4, 4);
+
+ //humidity
+ y=(humidity*58)/100;
+ copyXPMArea(60, 0, 1, y, 4, 60-y);
+ copyXPMArea(60, 0, 1, y, 5, 60-y);
+
+ //wind & gust
+
+ y=(gust*58)/maxWind;
+ copyXPMArea(62, 0, 1, y, 58, 60-y);
+ copyXPMArea(62, 0, 1, y, 59, 60-y);
+ y=(wind*58)/maxWind;
+ copyXPMArea(61, 0, 1, y, 58, 60-y);
+ copyXPMArea(61, 0, 1, y, 59, 60-y);
+
+ //station name
+ for (i=0; i!=4; i++)
+ {
+ chr = (int)Label[i] - 65;
+ copyXPMArea(chr*5+89, 0, 5, 6, 31+(i*5), 45);
+ }
- /*
- * Execute Perl script to grab the Latest METAR Report
- */
- snprintf(command, 1024, "/usr/lib/wmfrog/weather.pl %s %s &", StationID, folder);
- //printf("Retrieveing data\n");
- system(command);
- ForceDownload = 0;
- ForceUpdate = 1;
- }
+ //time
+ i=hour/10;
+ copyXPMArea(89+(i*5), 7, 5, 6, 30, 53);
+ i=hour-((hour/10)*10);
+ copyXPMArea(89+(i*5), 7, 5, 6, 35, 53);
+ copyXPMArea(89+(52), 7, 1, 6, 41, 53);
+ i=min/10;
+ copyXPMArea(89+(i*5), 7, 5, 6, 43, 53);
+ i=min-((min/10)*10);
+ copyXPMArea(89+(i*5), 7, 5, 6, 48, 53);
+
+
+ //temp
+
+ q=10;
+ copyXPMArea(136, 30, 17, 9, q-1, 22);
+ if (temp<0)
+ {
+ copyXPMArea(90, 30, 3, 7, q, 23);
+ q+=5;
+ }
+ /*if(temp>100)
+ {
+ copyXPMArea(96, 20, 5, 7, q, 23);
+ q+=6;
+ }
+ */
+ copyXPMArea(136, 30, 17, 9, (q-1), 22);
+
+ i=temp;
+ if (i<0)
+ i=-i;
+ if (i/100>0)
+ {
+ copyXPMArea(96, 20, 5, 7, q, 23);
+ q+=6;
+ i-=100;
+ }
+ if ((i==0 && q>10) || i/10>0 || q > 10)
+ {
+ copyXPMArea(90+6*(i/10), 20, 5, 7, q, 23);
+ q+=6;
+ }
+ copyXPMArea(90+6*(i-((i/10)*10)), 20, 5, 7, q, 23);
+ q+=5;
+ copyXPMArea(95, 29, 5, 7, q, 23);
+
+ // wind dir
+ if ((dir>=0 && dir<=22) || (dir<=360 && dir>337))
+ copyXPMArea(0, 198, 7, 7, 48, 6);
+ if (dir>22 && dir<=67)
+ copyXPMArea(42, 198, 7, 7, 48, 6);
+ if (dir>67 && dir<=112)
+ copyXPMArea(14, 198, 7, 7, 48, 6);
+ if (dir>112 && dir<=157)
+ copyXPMArea(28, 198, 7, 7, 48, 6);
+ if (dir>157 && dir<=202)
+ copyXPMArea(7, 198, 7, 7, 48, 6);
+ if (dir>202 && dir<=247)
+ copyXPMArea(35, 198, 7, 7, 48, 6);
+ if (dir>247 && dir<=292)
+ copyXPMArea(21, 198, 7, 7, 48, 6);
+ if (dir>292 && dir<=337)
+ copyXPMArea(49, 198, 7, 7, 48, 6);
+ /*
+ * Make changes visible
+ */
+ RedrawWindow();
- /*
- * Wait for next update
- */
- usleep(DELAY);
- }
+ /*
+ * Process any pending X events.
+ */
+ while (XPending(display))
+ {
+ XNextEvent(display, &event);
+ switch (event.type)
+ {
+ case Expose:
+ RedrawWindow();
+ break;
+ case EnterNotify:
+ XSetInputFocus(display, PointerRoot, RevertToParent, CurrentTime);
+ break;
+ case LeaveNotify:
+ XSetInputFocus(display, PointerRoot, RevertToParent, CurrentTime);
+ break;
+
+ }
+ }
+ /*
+ * Wait for next update
+ */
+ if (passes>0)
+ usleep(UpdateDelay*1000000);
+
+ passes++;
+ }
}
/*
* ParseCMDLine()
*/
-void ParseCMDLine(int argc, char *argv[]) {
+void ParseCMDLine(int argc, char *argv[])
+{
int i;
void print_usage();
-
+
StationID[0] = '\0';
UpdateDelay = DEFAULT_UPDATEDELAY;
- for (i = 1; i < argc; i++) {
-
- if ((!strcmp(argv[i], "-metric"))||(!strcmp(argv[i], "-m"))){
-
- Metric = 1;
-
- } else if (!strcmp(argv[i], "-w")){
-
- if( (i+1 >= argc)||(argv[i+1][0] == '-')) {
-
- fprintf(stderr,"You must give a max wind value with the -w option.\n");
- print_usage();
- exit(-1);
-
- } else if(sscanf(argv[i+1], "%d", &maxWind) != 1) {
-
- fprintf(stderr,"Dont understand the max wind value have entered (%s).\n", argv[i+1]);
- print_usage();
- exit(-1);
+ for (i = 1; i < argc; i++)
+ {
- }
-
- } else if (!strcmp(argv[i], "-o")){
- if( (i+1 >= argc)) {
-
- fprintf(stderr,"You must give a time offset value with the -t option.\n");
- print_usage();
- exit(-1);
-
- } else if(sscanf(argv[i+1], "%d", &timeOffset) != 1) {
-
- fprintf(stderr,"Dont understand the time offset value have entered (%s).\n", argv[i+1]);
- print_usage();
- exit(-1);
-
- }
+ if ((!strcmp(argv[i], "-metric"))||(!strcmp(argv[i], "-m")))
+ {
+ Metric = 1;
+ }
+ else if (!strcmp(argv[i], "-w"))
+ {
+ if ( (i+1 >= argc)||(argv[i+1][0] == '-'))
+ {
+
+ fprintf(stderr,"You must give a max wind value with the -w option.\n");
+ print_usage();
+ exit(-1);
+ }
+ else if (sscanf(argv[i+1], "%d", &maxWind) != 1)
+ {
+ fprintf(stderr,"Dont understand the max wind value have entered (%s).\n", argv[i+1]);
+ print_usage();
+ exit(-1);
+ }
+ }
+ else if (!strcmp(argv[i], "-o"))
+ {
+ if ( (i+1 >= argc))
+ {
+ fprintf(stderr,"You must give a time offset value with the -t option.\n");
+ print_usage();
+ exit(-1);
+ }
+ else if (sscanf(argv[i+1], "%d", &timeOffset) != 1)
+ {
+ fprintf(stderr,"Dont understand the time offset value have entered (%s).\n", argv[i+1]);
+ print_usage();
+ exit(-1);
+ }
- } else if (!strcmp(argv[i], "-tmp")){
- if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
- fprintf(stderr, "-tmp option invalid.\n");
- print_usage();
- exit(-1);
- }
+ }
+ else if (!strcmp(argv[i], "-tmp"))
+ {
+ if ((i+1 >= argc)||(argv[i+1][0] == '-'))
+ {
+ fprintf(stderr, "-tmp option invalid.\n");
+ print_usage();
+ exit(-1);
+ }
strcpy(folder, argv[++i]);
-
- } else if ((!strcmp(argv[i], "-station"))||(!strcmp(argv[i], "-s"))){
- if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
- fprintf(stderr, "No METAR station ID found\n");
- print_usage();
- exit(-1);
- }
+ }
+ else if ((!strcmp(argv[i], "-station"))||(!strcmp(argv[i], "-s")))
+ {
+ if ((i+1 >= argc)||(argv[i+1][0] == '-'))
+ {
+ fprintf(stderr, "No METAR station ID found\n");
+ print_usage();
+ exit(-1);
+ }
strcpy(StationID, StringToUpper(argv[++i]));
strcpy(Label, StationID);
-
- } else if (!strcmp(argv[i], "-delay")) {
-
- if( (i+1 >= argc)||(argv[i+1][0] == '-')) {
-
- fprintf(stderr,"You must give a time with the -delay option.\n");
- print_usage();
- exit(-1);
- }
- else if(sscanf(argv[i+1], "%ld", &UpdateDelay) != 1) {
-
- fprintf(stderr,"Dont understand the delay time you have entered (%s).\n", argv[i+1]);
- print_usage();
- exit(-1);
-
- }
- /*
- * Convert Time to seconds
- */
- UpdateDelay *= 60;
- ++i;
-
}
- else if (!strcmp(argv[i], "-l")) {
-
- if( (i+1 >= argc)||(argv[i+1][0] == '-')) {
-
- fprintf(stderr,"You must give a station label name.\n");
- print_usage();
- exit(-1);
+ else if (!strcmp(argv[i], "-delay"))
+ {
+ if ( (i+1 >= argc)||(argv[i+1][0] == '-'))
+ {
+
+ fprintf(stderr,"You must give a time with the -delay option.\n");
+ print_usage();
+ exit(-1);
+ }
+ else if (sscanf(argv[i+1], "%ld", &UpdateDelay) != 1)
+ {
- }
+ fprintf(stderr,"Dont understand the delay time you have entered (%s).\n", argv[i+1]);
+ print_usage();
+ exit(-1);
+ }
+ /*
+ * Convert Time to seconds
+ */
+ UpdateDelay *= 60;
+ ++i;
+ }
+ else if (!strcmp(argv[i], "-l"))
+ {
+ if ( (i+1 >= argc)||(argv[i+1][0] == '-'))
+ {
+ fprintf(stderr,"You must give a station label name.\n");
+ print_usage();
+ exit(-1);
+ }
strcpy(Label, StringToUpper(argv[++i]));
- }
-
+ }
}
- if (StationID[0] == '\0') {
- fprintf(stderr, "\nYou must specify a METAR station code\n\n");
- print_usage();
- exit(1);
+ if (StationID[0] == '\0')
+ {
+ fprintf(stderr, "\nYou must specify a METAR station code\n\n");
+ print_usage();
+ exit(1);
}
-
}
- void print_usage(){
+void print_usage()
+{
printf("\nwmfrog version: %s\n", VERSION);
printf("\nusage: wmfrog -s <StationID> [-h] [-w <max wind>] [-t <time offset>] [-tmp <temp folder>] [-l <label>]\n");
@@ -725,13 +648,6 @@ void ParseCMDLine(int argc, char *argv[]) {
}
-
-
-
-
-
-
-
/*
* Compute the Julian Day number for the given date.
* Julian Date is the number of days since noon of Jan 1 4713 B.C.
@@ -740,42 +656,44 @@ double jd(ny, nm, nd, UT)
int ny, nm, nd;
double UT;
{
- double A, B, C, D, JD, day;
-
- day = nd + UT/24.0;
+ double A, B, C, D, JD, day;
+ day = nd + UT/24.0;
- if ((nm == 1) || (nm == 2)){
- ny = ny - 1;
- nm = nm + 12;
- }
+ if ((nm == 1) || (nm == 2))
+ {
+ ny = ny - 1;
+ nm = nm + 12;
+ }
- if (((double)ny+nm/12.0+day/365.25)>=(1582.0+10.0/12.0+15.0/365.25)){
- A = ((int)(ny / 100.0));
- B = 2.0 - A + (int)(A/4.0);
- }
- else{
- B = 0.0;
- }
- if (ny < 0.0){
- C = (int)((365.25*(double)ny) - 0.75);
- }
- else{
- C = (int)(365.25*(double)ny);
- }
+ if (((double)ny+nm/12.0+day/365.25)>=(1582.0+10.0/12.0+15.0/365.25))
+ {
+ A = ((int)(ny / 100.0));
+ B = 2.0 - A + (int)(A/4.0);
+ }
+ else
+ {
+ B = 0.0;
+ }
+ if (ny < 0.0)
+ {
+ C = (int)((365.25*(double)ny) - 0.75);
+ }
+ else
+ {
+ C = (int)(365.25*(double)ny);
+ }
- D = (int)(30.6001*(double)(nm+1));
+ D = (int)(30.6001*(double)(nm+1));
- JD = B + C + D + day + 1720994.5;
- return(JD);
+ JD = B + C + D + day + 1720994.5;
+ return(JD);
}
-
-
/*
- * This routine handles button presses.
+ * This routine handles button presses.
*
* - Left Mouse single click toggles Deg F/C for temperatures.
* - Some other click event should display the full METAR report -- lots of
@@ -783,101 +701,85 @@ double UT;
*
*
*/
-void ButtonPressEvent(XButtonEvent *xev){
+/*void ButtonPressEvent(XButtonEvent *xev)
+{
- /*
- * Process single clicks.
- */
DblClkDelay = 0;
- if ((xev->button == Button1) && (xev->type == ButtonPress)){
-
- if (GotFirstClick1) GotDoubleClick1 = 1;
- else GotFirstClick1 = 1;
-
- } else if ((xev->button == Button2) && (xev->type == ButtonPress)){
+ if ((xev->button == Button1) && (xev->type == ButtonPress))
+ {
- if (GotFirstClick2) GotDoubleClick2 = 1;
- else GotFirstClick2 = 1;
-
- } else if ((xev->button == Button3) && (xev->type == ButtonPress)){
-
- if (GotFirstClick3) GotDoubleClick3 = 1;
- else GotFirstClick3 = 1;
+ if (GotFirstClick1) GotDoubleClick1 = 1;
+ else GotFirstClick1 = 1;
}
+ else if ((xev->button == Button2) && (xev->type == ButtonPress))
+ {
+ if (GotFirstClick2) GotDoubleClick2 = 1;
+ else GotFirstClick2 = 1;
-
-
- /*
- * We got a double click on Mouse Button1 (i.e. the left one)
- */
- if (GotDoubleClick1) {
- GotFirstClick1 = 0;
- GotDoubleClick1 = 0;
- // change from metric to us
- Metric = !Metric;
- ForceUpdate = 1;
}
+ else if ((xev->button == Button3) && (xev->type == ButtonPress))
+ {
- return;
-
-
-}
+ if (GotFirstClick3) GotDoubleClick3 = 1;
+ else GotFirstClick3 = 1;
+ }
+ if (GotDoubleClick1)
+ {
+ GotFirstClick1 = 0;
+ GotDoubleClick1 = 0;
+ // change from metric to us
+ Metric = !Metric;
+ ForceUpdate = 1;
+ }
+ return;
+}*/
-/*
- * This routine handles key presses.
- *
- */
-void KeyPressEvent(XKeyEvent *xev){
-
- return;
-
-}
-
-char *GetTempDir(char *suffix)
+char *GetTempDir(char *suffix)
{
- uid_t id;
- struct passwd *userEntry;
- static char userHome[128];
-
- id=getuid();
- userEntry=getpwuid(id);
- snprintf(userHome, 128, "%s/%s", userEntry->pw_dir, suffix);
- return userHome;
+ uid_t id;
+ struct passwd *userEntry;
+ static char userHome[128];
+
+ id=getuid();
+ userEntry=getpwuid(id);
+ snprintf(userHome, 128, "%s/%s", userEntry->pw_dir, suffix);
+ return userHome;
}
-char *StringToUpper(char *String) {
+char *StringToUpper(char *String)
+{
int i;
for (i = 0; i < strlen(String); i++)
- String[i] = toupper(String[i]);
+ String[i] = toupper(String[i]);
return String;
}
char *mystrsep(char **stringp, char *delim)
{
- char *start = *stringp;
- char *cp;
- char ch;
- if (start == NULL)
- return NULL;
- for (cp = start; (ch = *cp)!=0; cp++)
- {
- if (strchr(delim, ch))
- {
- *cp++ = 0;
- *stringp = cp;
- return start;
- }
- }
- *stringp = NULL;
- return start;
+ char *start = *stringp;
+ char *cp;
+ char ch;
+ if (start == NULL)
+ return NULL;
+ for (cp = start; (ch = *cp)!=0; cp++)
+ {
+ if (strchr(delim, ch))
+ {
+ *cp++ = 0;
+ *stringp = cp;
+ return start;
+ }
+ }
+ *stringp = NULL;
+ return start;
}
diff --git a/wmfrog/dist/weather.pl b/wmfrog/dist/weather.pl
index f6b4a7c..5ceeccd 100755
--- a/wmfrog/dist/weather.pl
+++ b/wmfrog/dist/weather.pl
@@ -5,13 +5,18 @@
#The Weather data can be retrieved through http of ftp.
#Http is faster, however this might get broken if NOAA change their webpage layout
#in wich case you should choose ftp.
+
$mode="http"; # html || ftp
+$debug = 0; # turn On/Off debugging
+
########################################
# Start:
########################################
($station,$tmpfolder)=@ARGV;
+debug("station: $station ; tmpfolder: $tmpfolder");
+
mkdir($tmpfolder);
$html="http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=${station}";
@@ -32,25 +37,25 @@ if($mode eq "http")
{
while((! ($line=~m/START BODY OF TEXT HERE/)) && !eof(DATA))
{
-#print ".";
- $line=<DATA>;
+ $line=<DATA>;
}
$i=0;
while($i!=12 && !eof(DATA))
{
-#print "*";
- $line=<DATA>;
- $i++;
+ $line=<DATA>;
+ $i++;
}
}
+
if(eof(DATA))
{
-#print "Unreadable HTML source, no point going any further, stopping\n";
-exit(0);
+ debug("Unreadable HTML source, no point going any further, stopping\n");
+ exit(0);
}
+
$line=<DATA>;
chomp $line;
-($crap,$time)=split(/\ /,$line);
+($junk,$time)=split(/\ /,$line);
($hour,$minute)=split(/:/,$time);
$line="";
if($mode eq "http")
@@ -71,14 +76,11 @@ close DATA;
chomp $line;
@args=split(/\ /,$line);
-#print "line: $line";
-#print "args: @args";
-if(debug)
-{
- #print "@args\n";
-}
-#print "line: $line";
+debug("line: $line");
+debug("args: @args");
+debug("line: $line");
+
$i=0;
$station=@args[$i];
if(($station eq 'METAR') or ($station eq 'SPECI'))
@@ -96,28 +98,28 @@ if($wind eq 'AUTO')
$wind=@args[$i+1];
$i++;
}
-#print "wind: $wind";
+debug("wind: $wind");
+
$i++;
$visibility=@args[$i];
$i++;#Visibility
-if( ! ($visibility=~m/SM/ || ($visibility eq "CAVOK")) )
-{
- #print "Visibility fraction\n";
- $i++; # visibility with fractions, ignoring
-}
-$next=@args[$i];
-if($next=~m/FT/)
-{
- #print "Visibility feet\n";
- $i++; # visibility in feet, ignoring
-}
+debug("vis: $visibility");
+
+#if( ! ($visibility=~m/SM/ || ($visibility eq "CAVOK") || ($visibility eq "9999") ))
+#{
+# $i++; # visibility with fractions, not using
+#}
+#$next=@args[$i];
+#if($next=~m/FT/)
+#{
+# $i++; # visibility in feet, not using
+#}
$tmp="";
$weather="";
$clouds="";
while((! (@args[$i]=~/\//)) && ($i<@args))
{
-
$intensity="";
$desc="";
$precip="";
@@ -125,67 +127,70 @@ while((! (@args[$i]=~/\//)) && ($i<@args))
$misc="";
$j=0;
$curent=@args[$i];
+
+ debug("cur : $curent");
+
$wasCloud="no";
if($curent=~/^CAVOK/)
- {
+ {
$clouds.="CAVOK,0;";
$wasCloud="yes";
- }
+ }
if($curent=~/^VV/)
{
- $clouds.="VV,".substr($curent,2,3).";";
- $wasNotCloud="yes";
+ $clouds.="VV,".substr($curent,2,3).";";
+ $wasNotCloud="yes";
}
if(($curent=~/^CLR/) or ($curent=~/^SCK/) or ($curent=~/^FEW/) or ($curent=~/^SCT/) or ($curent=~/^BKN/) or ($curent=~/^OVC/))
- {
+ {
$clouds.=substr($curent,0,3).",".substr($curent,3,3).";";
$wasCloud="yes";
- }
-
-if(($wasCloud ne "yes"))
-{
- if(length($curent)>0)
- {
-# Should be weather
- if($curent=~/^\-/)
- {
- $intensity="-";
- $j=1;
- }
- if($curent=~/^\+/)
- {
- $intensity="+";
- $j=1;
- }
- if($curent=~/^VC/)
- {
- $j=2;
- }
- $curent=substr($curent,$j);
- if(($curent=~/^MI/) or ($curent=~/^PR/) or ($curent=~/^BC/) or ($curent=~/^DR/) or ($curent=~/^BL/) or ($curent=~/^SH/) or ($curent=~/^TS/) or ($curent=~/^FZ/) )
- {
- $desc=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^DZ/) or ($curent=~/^RA/) or ($curent=~/^SN/) or ($curent=~/^SG/) or ($curent=~/^IC/) or ($curent=~/^PE/) or ($curent=~/^GR/) or ($curent=~/^GX/) or ($curent=~/^UP/))
- {
- $precip=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^BR/) or ($curent=~/^FG/) or ($curent=~/^FU/) or ($curent=~/^VA/) or ($curent=~/^DU/) or ($curent=~/^SA/) or ($curent=~/^HZ/) or ($curent=~/^PY/))
- {
- $obsc=substr($curent,0,2);
- $curent=substr($curent,2);
- }
- if(($curent=~/^PO/) or ($curent=~/^SQ/) or ($curent=~/^FC/) or ($curent=~/^SS/))
- {
- $misc=substr($curent,0,2);
- }
- $weather.="$intensity,$desc,$precip,$obsc,$misc;";
}
-}
+ if(($wasCloud ne "yes"))
+ {
+ if(length($curent)>0)
+ {
+ # Should be weather
+ if($curent=~/^\-/)
+ {
+ $intensity="-";
+ $j=1;
+ }
+ if($curent=~/^\+/)
+ {
+ $intensity="+";
+ $j=1;
+ }
+ if($curent=~/^VC/)
+ {
+ $j=2;
+ }
+ $curent=substr($curent,$j);
+ if(($curent=~/^MI/) or ($curent=~/^PR/) or ($curent=~/^BC/) or ($curent=~/^DR/) or ($curent=~/^BL/) or ($curent=~/^SH/) or ($curent=~/^TS/) or ($curent=~/^FZ/) )
+ {
+ $desc=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^DZ/) or ($curent=~/^RA/) or ($curent=~/^SN/) or ($curent=~/^SG/) or ($curent=~/^IC/) or ($curent=~/^PE/) or ($curent=~/^GR/) or ($curent=~/^GX/) or ($curent=~/^UP/))
+ {
+ $precip=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^BR/) or ($curent=~/^FG/) or ($curent=~/^FU/) or ($curent=~/^VA/) or ($curent=~/^DU/) or ($curent=~/^SA/) or ($curent=~/^HZ/) or ($curent=~/^PY/))
+ {
+ $obsc=substr($curent,0,2);
+ $curent=substr($curent,2);
+ }
+ if(($curent=~/^PO/) or ($curent=~/^SQ/) or ($curent=~/^FC/) or ($curent=~/^SS/))
+ {
+ $misc=substr($curent,0,2);
+ }
+ $weather.="$intensity,$desc,$precip,$obsc,$misc;";
+ }
+
+ }
$i++;
}
($temp,$dew)=split(/\//, at args[$i]);
@@ -246,6 +251,18 @@ if($dew eq "")
$station="";
}
+debug("Hour:$hour");
+debug("Minute:$minute");
+debug("Station:$station");
+debug("WindDir:$dir");
+debug("WindSpeed:$speed");
+debug("WindGust:$gust");
+debug("Weather:$weather");
+debug("Clouds:$clouds");
+debug("Temp:$temp");
+debug("Dew:$dew");
+
+
#check for ok temperature
open(GREP, "grep Temp $tmpfolder/${station} | ");
$templine=<GREP>;
@@ -268,31 +285,41 @@ $templine=~m/^Temp:(.*)$/;
}
else
{
- #invalid
- $station="";
+ $station="";
}
}
close GREP;
-#print "$$station\n";
+debug("Station: $station");
+
if(length($station)==4)
{
-#print "OK\n";
-open(FILE,"> $tmpfolder/${station}");
-print FILE "Hour:$hour\n";
-print FILE "Minute:$minute\n";
-print FILE "Station:$station\n";
-print FILE "WindDir:$dir\n";
-print FILE "WindSpeed:$speed\n";
-print FILE "WindGust:$gust\n";
-print FILE "Weather:$weather\n";
-print FILE "Clouds:$clouds\n";
-print FILE "Temp:$temp\n";
-print FILE "Dew:$dew\n";
-close FILE
+ debug("Data OK");
+ open(FILE,"> $tmpfolder/${station}");
+ print FILE "Hour:$hour\n";
+ print FILE "Minute:$minute\n";
+ print FILE "Station:$station\n";
+ print FILE "WindDir:$dir\n";
+ print FILE "WindSpeed:$speed\n";
+ print FILE "WindGust:$gust\n";
+ print FILE "Weather:$weather\n";
+ print FILE "Clouds:$clouds\n";
+ print FILE "Temp:$temp\n";
+ print FILE "Dew:$dew\n";
+ close FILE
}
else
{
-#print "Invalid data, not writing to file, stopping\n";
+ debug("Invalid data, not writing to file, stopping\n");
}
+# end main
+
+sub debug()
+{
+ my($str) = @_;
+ if($debug)
+ {
+ print "$str\n";
+ }
+}
diff --git a/wmfrog/dist/wmfrog b/wmfrog/dist/wmfrog
index 7eeefd3..b39f12e 100755
Binary files a/wmfrog/dist/wmfrog and b/wmfrog/dist/wmfrog differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmfrog.git
More information about the Pkg-wmaker-commits
mailing list