home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume34
/
getwxmap
/
part01
/
getwxmap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-18
|
8KB
|
303 lines
/*
@(#) getwxmap 2.21, January 15, 1993
Copyright (C) 1993, Dale A. Harris (rodmur@ecst.csuchico.edu)
This program may be freely re-distributed at no charge provided that
this notice is left intact. Modified copies must preserve this notice.
It is requested that any useful changes you make be sent to the author.
WXMAP:
Is a C program that was converted from a shell script I wrote to retrieve the
most recent of any the various weather maps at vmd.cso.uiuc.edu and display
them using some utility similar to xv (xv is a multi-purpose GIF, JPEG,
etc., displayer for X-windows, written by John Bradley
(bradley@cis.upenn.edu))
Much thanks to Charlie Kline (cvk@uiuc.edu), and all the others I may
not know about, for their work on publicly available satellite weather
images
Thanks a bunch to all with bug reports and fixes.
Special Thanks to Emma Pease <emma@Russell.Stanford.EDU> for the man page!
USAGE: getwxmap [ -D -R -d -b -s -r -v -u# ]
-D if you don't want the files displayed
-R if you don't want the files removed after displaying
-b Display in background on root window
-d for debugging
-s Retrieves the current Surface Anaylsis Map (this usually gets
made a little before 15 minutes after the hour, so WXMAP
doesn't grab it until 15 minutes or later after the hour)
-r Retrieves the most recent Infra Red Light Map
-v Retrieves the most recent Visible Light Map
-u# Retrieves the most recent Upper Air maps at a # * 100hPa itervals
(# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively)
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#ifdef SYSV
#include <malloc.h>
#endif
#include <string.h>
#include <unistd.h>
#define SMAX 7
#define SITE "vmd.cso.uiuc.edu"
#define DIR "wx"
#define DISP "xv"
#ifndef DOMAIN
#define DOMAIN "SomewhereStupid"
#endif
#define UMAPNO 5 /* number of umaps */
#define UMAP1 2
#define UMAP2 3
#define UMAP3 5
#define UMAP4 7
#define UMAP5 8
#define UMAPHOURMADE 3
#define UMAPMINMADE 5 /* minutes past the hour that the U*.GIF's made */
#define SMAPMINMADE 15 /* Minutes past the hour that SA*.GIF made */
/*
don't use the -quit option here with xv, it won't work properly if you
want to display more than one picture
*/
#define BKGRDOPTS "-root -maxpect"
main (int argc, char **argv)
{
time_t seconds_off;
struct tm *tp, *otp, *tptmp, *thetime ();
char *mnthday, *gmt, *wgifs, *dispstr, *command, *filename, *uhour, *temp;
int background = 0, surface = 0, visible = 0, infrared = 0, nodis = 0,
norm = 0, debug = 0, upair = 0, i, j;
short int hpa[UMAPNO] =
{UMAP1, UMAP2, UMAP3, UMAP4, UMAP5}; /* the pressures for the umaps */
FILE *tosite;
void usage ();
mnthday = (char *) calloc (5, sizeof (char));
gmt = (char *) calloc (7, sizeof (char));
wgifs = (char *) calloc (100, sizeof (char));
dispstr = (char *) calloc (150, sizeof (char));
uhour = (char *) calloc (3, sizeof (char));
command = (char *) calloc (30, sizeof (char));
filename = (char *) calloc (30, sizeof (char));
if (argc == 1)
{
fprintf (stderr, "%s: Pick an option\n", argv[0]);
usage ();
exit (1);
}
for (i = 1; i < argc; ++i)
for (j = (argv[i][0] == '-') ? 1 : 0; j < strlen (argv[i]); ++j)
switch (argv[i][j])
{
case 's':
++surface;
break;
case 'b':
++background;
break;
case 'r':
++infrared;
break;
case 'v':
++visible;
break;
case 'u':
switch (argv[i][++j] & 15)
{
case 2:
upair |= 1;
break;
case 3:
upair |= 2;
break;
case 5:
upair |= 4;
break;
case 7:
upair |= 8;
break;
case 8:
upair |= 16;
break;
default:
fprintf (stderr, "%s: Unavailable map: %i\n", argv[0], argv[i][j] & 15);
exit (1);
}
break;
case 'D':
++nodis;
break;
case 'R':
++norm;
break;
case 'd':
++debug;
break;
default:
fprintf (stderr, "%s: Bad Option: %c\n", argv[0], argv[i][j]);
usage ();
exit (1);
}
/* getting the time */
otp = tp = thetime ((time_t) 0, tp, argv[0]);
strftime (gmt, SMAX, "%m%d%H", tp);
if (surface)
if (tp->tm_min >= SMAPMINMADE)
sprintf (wgifs, " SA%s.GIF ", gmt);
else
{
fprintf (stderr, "%s: SA%s.GIF not made until %d past the hour, getting last hours map.\n", argv[0], gmt, SMAPMINMADE);
/* Take off an hour's worth of seconds if before the quarter hour */
tp = thetime ((time_t) 3600, tp, argv[0]);
strftime (gmt, SMAX, "%m%d%H", tp);
sprintf (wgifs, " SA%s.GIF ", gmt);
tptmp = tp;
tp = otp;
free (tptmp);
}
if (infrared)
strcat (wgifs, " CIR.GIF ");
if (visible)
strcat (wgifs, " CVIS.GIF ");
if (upair)
/*
The GMT hours of 3 to 15 was my best guess when the upperair maps
get made, but on occasion it appears to be differant, so all I can
say is best of luck!
*/
{
if (tp->tm_hour < 3)
{
/* if at 0 to 2 GMT take off the (hour + 1) times an hours worth of seconds */
seconds_off = (tp->tm_hour + 1) * 3600;
tp = thetime (seconds_off, tp, argv[0]);
strftime (mnthday, SMAX, "%m%d", tp);
tptmp = tp;
tp = otp;
free (tptmp);
}
else
strftime (mnthday, SMAX, "%m%d", tp);
for (i = 0; i <= (UMAPNO - 1); ++i)
{
if (upair & 1)
{
/* attach proper hour onto the end of u*.gifs */
strcpy (uhour, ((tp->tm_hour >= UMAPHOURMADE)
&& (tp->tm_hour < (UMAPHOURMADE + 12))) ? "00" : "12");
/* if it is the hours that the u*.gifs are made and if not 5 past the
hour, then don't get them */
if (((tp->tm_hour == UMAPHOURMADE)
|| (tp->tm_hour == (UMAPHOURMADE + 12)))
&& (tp->tm_min < UMAPMINMADE))
fprintf (stderr, "%s: wait until %d after the hour for U%d%s%s.GIF\n", argv[0], UMAPMINMADE, hpa[i], mnthday, uhour);
else
{
temp = (char *) strdup (wgifs);
sprintf (wgifs, " %s U%d%s%s.GIF ", temp, hpa[i], mnthday, uhour);
free (temp);
}
}
upair >>= 1;
}
}
/* Using ftp to grab the files */
if (strlen (wgifs) != 0)
{
if (debug)
sprintf (command, "ftp -i -n -v %s", SITE);
else
sprintf (command, "ftp -i -n %s", SITE);
if ((tosite = (FILE *) popen (command, "w")) == (FILE *) NULL)
{
fprintf (stderr, "%s: Can't popen!?!", argv[0]);
exit (1);
}
fprintf (tosite, "user anonymous %s@%s\n", getlogin (), DOMAIN);
fputs ("bin\n", tosite);
fprintf (tosite, "cd %s\n", DIR);
fprintf (tosite, "mget %s\n", wgifs);
fputs ("quit\n", tosite);
pclose (tosite);
if (!nodis)
{
if (background)
sprintf (dispstr, "%s %s %s", DISP, BKGRDOPTS, wgifs);
else
sprintf (dispstr, "%s %s", DISP, wgifs);
system (dispstr);
}
if (!norm)
{
filename = strtok (wgifs, " ");
while (filename != (char *) NULL)
{
/* no use checking what unlink returns because I don't care */
unlink (filename);
filename = strtok ((char *) NULL, " ");
}
}
}
exit (0);
}
struct tm *
thetime (time_t s_off, struct tm *tp, char *name)
{
time_t datime;
if ((datime = time ((time_t *) NULL)) == (time_t) - 1)
{
fprintf (stderr, "%s: time unavailable?!?\n", name);
exit (1);
}
datime -= s_off;
if ((tp = gmtime (&datime)) == (struct tm *) NULL)
{
fprintf (stderr, "%s: Coordinated Universal Time unavailable??\n", name);
exit (1);
}
return (tp);
}
void
usage ()
{
fputs ("Usage: getwxmap [ -R -D -d -s -r -v -u# ]\n", stderr);
fputs ("getwxmap [ -RDdsrvu# ]\n", stderr);
fputs ("getwxmap [ RDdsrvu# ]\n", stderr);
fputs ("-D if you don't want the files displayed\n", stderr);
fputs ("-R if you don't want the files removed after displaying\n", stderr);
fputs ("-b for background, root window\n", stderr);
fputs ("-d for debugging\n", stderr);
fputs ("-s For the Surface Anaylsis map\n", stderr);
fputs ("-r for the Infra Red Light Map\n", stderr);
fputs ("-v for Visible Light Map\n", stderr);
fputs ("-u# for the Upper Air maps at a # * 100 hPa itervals\n", stderr);
fputs ("(# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively)\n", stderr);
return;
}