home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / getwxmap / part01 < prev    next >
Encoding:
Text File  |  1993-01-18  |  14.3 KB  |  485 lines

  1. Newsgroups: comp.sources.misc
  2. From: rodmur@ecst.csuchico.edu (Dale Harris)
  3. Subject: v34i120: getwxmap - Retrieve and display Weather satellite maps, Part01/01
  4. Message-ID: <1993Jan18.185414.27374@sparky.imd.sterling.com>
  5. X-Md4-Signature: a7f3369e7992aabfc8197f2a364d5074
  6. Date: Mon, 18 Jan 1993 18:54:14 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: rodmur@ecst.csuchico.edu (Dale Harris)
  10. Posting-number: Volume 34, Issue 120
  11. Archive-name: getwxmap/part01
  12. Environment: X11, UNIX, xv
  13.  
  14. Getwxmap is a relatively simple untility that retrieves the most recent
  15. weather satellite maps from vmd.cso.uiuc.edu and displays them on a
  16. X-windows display. 
  17.  
  18. Special Thanks to Emma Pease <emma@Russell.Stanford.EDU> for the man page!
  19.  
  20.  USAGE: getwxmap [ -D -R -d  -b -s -r -v -u# ]
  21.    -D   if you don't want the files displayed
  22.    -R   if you don't want the files removed after displaying
  23.    -b   Display in background on root window
  24.    -d   for debugging
  25.    -s   Retrieves the current Surface Anaylsis Map (this usually gets
  26.            made a little before 15 minutes after the hour, so WXMAP
  27.            doesn't grab it until 15 minutes or later after the hour)
  28.    -r   Retrieves the most recent Infra Red Light Map
  29.    -v   Retrieves the most recent Visible Light Map
  30.    -u#  Retrieves the most recent Upper Air maps at a # * 100hPa itervals
  31.    (# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively)
  32.  
  33. Dale Harris
  34. ---------------------------------- cut here ----------------------------------
  35. #! /bin/sh
  36. # This is a shell archive.  Remove anything before this line, then feed it
  37. # into a shell via "sh file" or similar.  To overwrite existing files,
  38. # type "sh file -c".
  39. # Contents:  README Makefile getwxmap.1 getwxmap.c
  40. # Wrapped by kent@sparky on Mon Jan 18 12:44:28 1993
  41. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  42. echo If this archive is complete, you will see the following message:
  43. echo '          "shar: End of archive 1 (of 1)."'
  44. if test -f 'README' -a "${1}" != "-c" ; then 
  45.   echo shar: Will not clobber existing file \"'README'\"
  46. else
  47.   echo shar: Extracting \"'README'\" \(429 characters\)
  48.   sed "s/^X//" >'README' <<'END_OF_FILE'
  49. XCheck out the Makefile, if your on a SYSV machine you might want to
  50. X-DSYSV, check out the #define fields also in the source, be sure also to
  51. Xset the -DDOMAIN in the Makefile to your site name.  Also this has been
  52. Xconverted to ANSI Standard C, just something to keep in mind when you edit
  53. Xthe Makefile.  If you find any bugs or have any suggestions e-mail:
  54. Xrodmur@ecst.csuchico.edu
  55. X
  56. XThanx!
  57. X
  58. XDale Harris {rodmur@ecst.csuchico.edu}
  59. END_OF_FILE
  60.   if test 429 -ne `wc -c <'README'`; then
  61.     echo shar: \"'README'\" unpacked with wrong size!
  62.   fi
  63.   # end of 'README'
  64. fi
  65. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  66.   echo shar: Will not clobber existing file \"'Makefile'\"
  67. else
  68.   echo shar: Extracting \"'Makefile'\" \(640 characters\)
  69.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  70. X#
  71. X# Makefile for getwxmap.c ver 2.21
  72. X# Copyright (C) January 13, 1993 by Dale A. Harris
  73. X#                                {rodmur@ecst.csuchico.edu}
  74. X#
  75. XCC=gcc
  76. X#CC=cc
  77. X
  78. X# Remember to switch on the ANSI flag for your compiler
  79. X#AFLAG= -Aa #for hp compilers
  80. XAFLAG= -ansi # for gcc
  81. X
  82. XCFLAGS= -g  # for debugging 
  83. X#CFLAGS=-O #most machines in this world
  84. X#CFLAGS=-O2  #for gcc
  85. X#CFLAGS= +O3 # with cc on HP9000/7xx-series running HPUX 8.*
  86. X
  87. X#Be sure to set your own domain name here.
  88. XDEFINES= -DSYSV -DDOMAIN=\"ecst.csuchico.edu\"
  89. X
  90. Xgetwxmap: getwxmap.c
  91. X    $(CC) $(CFLAGS) $(AFLAG) -o getwxmap $(DEFINES) getwxmap.c
  92. X
  93. Xclean:
  94. X    rm -f getwxmap.o getwxmap core
  95. END_OF_FILE
  96.   if test 640 -ne `wc -c <'Makefile'`; then
  97.     echo shar: \"'Makefile'\" unpacked with wrong size!
  98.   fi
  99.   # end of 'Makefile'
  100. fi
  101. if test -f 'getwxmap.1' -a "${1}" != "-c" ; then 
  102.   echo shar: Will not clobber existing file \"'getwxmap.1'\"
  103. else
  104.   echo shar: Extracting \"'getwxmap.1'\" \(1109 characters\)
  105.   sed "s/^X//" >'getwxmap.1' <<'END_OF_FILE'
  106. X.TH GETWXMAP 1 "30 November 1992"
  107. X.SH NAME
  108. Xgetwxmap \- retrieve weather maps and display on X11 displays
  109. X.SH SYNOPSIS
  110. X.B getwxmap
  111. X.RB [ " \-D -R -d -b -s -r -v -u#" ]
  112. X.SH DESCRIPTION
  113. X.B getwxmap
  114. Xretrieves the most recent of any of the various weather maps at
  115. Xvmd.cso.uiuc.edu and displays them using xv.  
  116. X.SH OPTIONS
  117. X.TP
  118. X.B \-D
  119. Xdon't display file.
  120. X.TP
  121. X.B \-R
  122. Xdon't remove file when program finishes.
  123. X.TP
  124. X.B \-b
  125. Xdisplay in background on root window.
  126. X.TP
  127. X.B \-d
  128. Xdebugging.
  129. X.TP
  130. X.B \-s
  131. Xretrieves the current Surface Anaylsis Map (this usually gets
  132. Xmade a little before 15 minutes after the hour, so WXMAP
  133. Xdoesn't grab it until 15 minutes or later after the hour).
  134. X.TP
  135. X.B \-r
  136. Xretrieves the most recent Infra Red Light Map.
  137. X.TP
  138. X.B \-v
  139. Xretrieves the most recent Visible Light Map.
  140. X.TP
  141. X.B \-u#
  142. Xretrieves the most recent Upper Air maps at a (# * 100hPa) intervals
  143. X(# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively).
  144. X.SH SEE ALSO
  145. X.BR xv (1V),
  146. X.SH AUTHOR
  147. XThis program is written by Dale A. Harris (rodmur@ecst.csuchico.edu).
  148. XMany thanks to Emma Pease <emma@Russell.Stanford.EDU> for this man page!
  149. END_OF_FILE
  150.   if test 1109 -ne `wc -c <'getwxmap.1'`; then
  151.     echo shar: \"'getwxmap.1'\" unpacked with wrong size!
  152.   fi
  153.   # end of 'getwxmap.1'
  154. fi
  155. if test -f 'getwxmap.c' -a "${1}" != "-c" ; then 
  156.   echo shar: Will not clobber existing file \"'getwxmap.c'\"
  157. else
  158.   echo shar: Extracting \"'getwxmap.c'\" \(8259 characters\)
  159.   sed "s/^X//" >'getwxmap.c' <<'END_OF_FILE'
  160. X/*
  161. X @(#) getwxmap 2.21, January 15, 1993
  162. X
  163. X Copyright (C) 1993, Dale A. Harris (rodmur@ecst.csuchico.edu)
  164. X
  165. X This program may be freely re-distributed at no charge provided that
  166. X this notice is left intact.  Modified copies must preserve this notice.
  167. X It is requested that any useful changes you make be sent to the author.
  168. X
  169. X WXMAP:
  170. X Is a C program that was converted from a shell script I wrote to retrieve the
  171. X most recent of any  the various weather maps at vmd.cso.uiuc.edu and display
  172. X them using  some utility similar to xv (xv is a multi-purpose GIF, JPEG,
  173. X etc.,  displayer for X-windows, written by John Bradley
  174. X (bradley@cis.upenn.edu))
  175. X
  176. X Much thanks to Charlie Kline (cvk@uiuc.edu), and all the others I may
  177. X  not know about, for their work on publicly available satellite weather
  178. X  images
  179. X
  180. X Thanks a bunch to all with bug reports and fixes.
  181. X
  182. X Special Thanks to Emma Pease <emma@Russell.Stanford.EDU> for the man page!
  183. X
  184. X USAGE: getwxmap [ -D -R -d  -b -s -r -v -u# ]
  185. X   -D if you don't want the files displayed
  186. X   -R  if you don't want the files removed after displaying
  187. X   -b  Display in background on root window
  188. X   -d for debugging
  189. X   -s    Retrieves the current Surface Anaylsis Map (this usually gets
  190. X           made a little before 15 minutes after the hour, so WXMAP
  191. X           doesn't grab it until 15 minutes or later after the hour)
  192. X   -r    Retrieves the most recent Infra Red Light Map
  193. X   -v    Retrieves the most recent Visible Light Map
  194. X   -u#  Retrieves the most recent Upper Air maps at a # * 100hPa itervals
  195. X   (# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively)
  196. X*/
  197. X
  198. X#include <stdio.h>
  199. X#include <time.h>
  200. X#include <stdlib.h>
  201. X#ifdef SYSV
  202. X#include <malloc.h>
  203. X#endif
  204. X#include <string.h>
  205. X#include <unistd.h>
  206. X
  207. X#define SMAX 7
  208. X#define SITE "vmd.cso.uiuc.edu"
  209. X#define DIR "wx"
  210. X#define DISP "xv"
  211. X#ifndef DOMAIN
  212. X#define DOMAIN "SomewhereStupid"
  213. X#endif
  214. X#define UMAPNO 5        /* number of umaps */
  215. X#define UMAP1 2
  216. X#define UMAP2 3
  217. X#define UMAP3 5
  218. X#define UMAP4 7
  219. X#define UMAP5 8
  220. X#define UMAPHOURMADE 3
  221. X#define UMAPMINMADE  5        /* minutes past the hour that the U*.GIF's made */
  222. X#define SMAPMINMADE 15        /* Minutes past the hour that SA*.GIF made */
  223. X
  224. X
  225. X/*
  226. X   don't use the -quit option here with xv, it won't work properly if you
  227. X    want to display more than one picture
  228. X*/
  229. X#define BKGRDOPTS "-root -maxpect"
  230. X
  231. Xmain (int argc, char **argv)
  232. X{
  233. X
  234. X  time_t seconds_off;
  235. X  struct tm *tp, *otp, *tptmp, *thetime ();
  236. X  char *mnthday, *gmt, *wgifs, *dispstr, *command, *filename, *uhour, *temp;
  237. X  int background = 0, surface = 0, visible = 0, infrared = 0, nodis = 0,
  238. X    norm = 0, debug = 0, upair = 0, i, j;
  239. X  short int hpa[UMAPNO] =
  240. X  {UMAP1, UMAP2, UMAP3, UMAP4, UMAP5};    /* the pressures for the umaps */
  241. X  FILE *tosite;
  242. X  void usage ();
  243. X
  244. X
  245. X  mnthday = (char *) calloc (5, sizeof (char));
  246. X  gmt = (char *) calloc (7, sizeof (char));
  247. X  wgifs = (char *) calloc (100, sizeof (char));
  248. X  dispstr = (char *) calloc (150, sizeof (char));
  249. X  uhour = (char *) calloc (3, sizeof (char));
  250. X  command = (char *) calloc (30, sizeof (char));
  251. X  filename = (char *) calloc (30, sizeof (char));
  252. X
  253. X  if (argc == 1)
  254. X    {
  255. X      fprintf (stderr, "%s: Pick an option\n", argv[0]);
  256. X      usage ();
  257. X      exit (1);
  258. X    }
  259. X  for (i = 1; i < argc; ++i)
  260. X    for (j = (argv[i][0] == '-') ? 1 : 0; j < strlen (argv[i]); ++j)
  261. X      switch (argv[i][j])
  262. X    {
  263. X    case 's':
  264. X      ++surface;
  265. X      break;
  266. X    case 'b':
  267. X      ++background;
  268. X      break;
  269. X    case 'r':
  270. X      ++infrared;
  271. X      break;
  272. X    case 'v':
  273. X      ++visible;
  274. X      break;
  275. X    case 'u':
  276. X      switch (argv[i][++j] & 15)
  277. X        {
  278. X        case 2:
  279. X          upair |= 1;
  280. X          break;
  281. X        case 3:
  282. X          upair |= 2;
  283. X          break;
  284. X        case 5:
  285. X          upair |= 4;
  286. X          break;
  287. X        case 7:
  288. X          upair |= 8;
  289. X          break;
  290. X        case 8:
  291. X          upair |= 16;
  292. X          break;
  293. X        default:
  294. X          fprintf (stderr, "%s: Unavailable map: %i\n", argv[0], argv[i][j] & 15);
  295. X          exit (1);
  296. X        }
  297. X      break;
  298. X    case 'D':
  299. X      ++nodis;
  300. X      break;
  301. X    case 'R':
  302. X      ++norm;
  303. X      break;
  304. X    case 'd':
  305. X      ++debug;
  306. X      break;
  307. X    default:
  308. X      fprintf (stderr, "%s: Bad Option: %c\n", argv[0], argv[i][j]);
  309. X      usage ();
  310. X      exit (1);
  311. X    }
  312. X
  313. X  /* getting the time */
  314. X  otp = tp = thetime ((time_t) 0, tp, argv[0]);
  315. X  strftime (gmt, SMAX, "%m%d%H", tp);
  316. X
  317. X  if (surface)
  318. X    if (tp->tm_min >= SMAPMINMADE)
  319. X      sprintf (wgifs, " SA%s.GIF ", gmt);
  320. X    else
  321. X      {
  322. X    fprintf (stderr, "%s: SA%s.GIF not made until %d past the hour, getting last hours map.\n", argv[0], gmt, SMAPMINMADE);
  323. X    /* Take off an hour's worth of seconds if before the quarter hour */
  324. X    tp = thetime ((time_t) 3600, tp, argv[0]);
  325. X    strftime (gmt, SMAX, "%m%d%H", tp);
  326. X    sprintf (wgifs, " SA%s.GIF ", gmt);
  327. X    tptmp = tp;
  328. X    tp = otp;
  329. X    free (tptmp);
  330. X      }
  331. X  if (infrared)
  332. X    strcat (wgifs, " CIR.GIF ");
  333. X  if (visible)
  334. X    strcat (wgifs, " CVIS.GIF ");
  335. X  if (upair)
  336. X    /*
  337. XThe GMT hours of 3 to 15 was my best guess when the upperair maps
  338. Xget made, but on occasion it appears to be differant, so all I can
  339. Xsay is best of luck!
  340. X*/
  341. X    {
  342. X      if (tp->tm_hour < 3)
  343. X    {
  344. X      /* if at 0 to 2 GMT take off the (hour + 1) times an hours worth of seconds */
  345. X      seconds_off = (tp->tm_hour + 1) * 3600;
  346. X      tp = thetime (seconds_off, tp, argv[0]);
  347. X      strftime (mnthday, SMAX, "%m%d", tp);
  348. X      tptmp = tp;
  349. X      tp = otp;
  350. X      free (tptmp);
  351. X    }
  352. X      else
  353. X    strftime (mnthday, SMAX, "%m%d", tp);
  354. X
  355. X      for (i = 0; i <= (UMAPNO - 1); ++i)
  356. X    {
  357. X      if (upair & 1)
  358. X        {
  359. X
  360. X          /* attach proper hour onto the end of u*.gifs */
  361. X          strcpy (uhour, ((tp->tm_hour >= UMAPHOURMADE)
  362. X             && (tp->tm_hour < (UMAPHOURMADE + 12))) ? "00" : "12");
  363. X
  364. X          /* if it is the hours that the u*.gifs are made and if not 5 past the
  365. X      hour, then don't get them */
  366. X
  367. X          if (((tp->tm_hour == UMAPHOURMADE)
  368. X           || (tp->tm_hour == (UMAPHOURMADE + 12)))
  369. X          && (tp->tm_min < UMAPMINMADE))
  370. X        fprintf (stderr, "%s: wait until %d after the hour for U%d%s%s.GIF\n", argv[0], UMAPMINMADE, hpa[i], mnthday, uhour);
  371. X          else
  372. X        {
  373. X          temp = (char *) strdup (wgifs);
  374. X          sprintf (wgifs, " %s U%d%s%s.GIF ", temp, hpa[i], mnthday, uhour);
  375. X          free (temp);
  376. X        }
  377. X        }
  378. X      upair >>= 1;
  379. X    }
  380. X    }
  381. X
  382. X  /* Using ftp to grab the files */
  383. X
  384. X  if (strlen (wgifs) != 0)
  385. X    {
  386. X      if (debug)
  387. X    sprintf (command, "ftp -i -n -v %s", SITE);
  388. X      else
  389. X    sprintf (command, "ftp -i -n %s", SITE);
  390. X
  391. X      if ((tosite = (FILE *) popen (command, "w")) == (FILE *) NULL)
  392. X    {
  393. X      fprintf (stderr, "%s: Can't popen!?!", argv[0]);
  394. X      exit (1);
  395. X    }
  396. X      fprintf (tosite, "user anonymous %s@%s\n", getlogin (), DOMAIN);
  397. X      fputs ("bin\n", tosite);
  398. X      fprintf (tosite, "cd %s\n", DIR);
  399. X      fprintf (tosite, "mget %s\n", wgifs);
  400. X      fputs ("quit\n", tosite);
  401. X      pclose (tosite);
  402. X
  403. X      if (!nodis)
  404. X    {
  405. X      if (background)
  406. X        sprintf (dispstr, "%s %s %s", DISP, BKGRDOPTS, wgifs);
  407. X      else
  408. X        sprintf (dispstr, "%s %s", DISP, wgifs);
  409. X      system (dispstr);
  410. X    }
  411. X
  412. X      if (!norm)
  413. X    {
  414. X      filename = strtok (wgifs, " ");
  415. X      while (filename != (char *) NULL)
  416. X        {
  417. X          /* no use checking what unlink returns because I don't care */
  418. X          unlink (filename);
  419. X          filename = strtok ((char *) NULL, " ");
  420. X        }
  421. X    }
  422. X    }
  423. X  exit (0);
  424. X}
  425. X
  426. Xstruct tm *
  427. Xthetime (time_t s_off, struct tm *tp, char *name)
  428. X{
  429. X  time_t datime;
  430. X
  431. X  if ((datime = time ((time_t *) NULL)) == (time_t) - 1)
  432. X    {
  433. X      fprintf (stderr, "%s: time unavailable?!?\n", name);
  434. X      exit (1);
  435. X    }
  436. X  datime -= s_off;
  437. X  if ((tp = gmtime (&datime)) == (struct tm *) NULL)
  438. X    {
  439. X      fprintf (stderr, "%s: Coordinated Universal Time unavailable??\n", name);
  440. X      exit (1);
  441. X    }
  442. X  return (tp);
  443. X}
  444. X
  445. Xvoid
  446. Xusage ()
  447. X{
  448. X  fputs ("Usage: getwxmap [ -R -D -d -s -r -v -u# ]\n", stderr);
  449. X  fputs ("getwxmap [ -RDdsrvu# ]\n", stderr);
  450. X  fputs ("getwxmap [ RDdsrvu# ]\n", stderr);
  451. X  fputs ("-D if you don't want the files displayed\n", stderr);
  452. X  fputs ("-R if you don't want the files removed after displaying\n", stderr);
  453. X  fputs ("-b for background, root window\n", stderr);
  454. X  fputs ("-d for debugging\n", stderr);
  455. X  fputs ("-s For the Surface Anaylsis map\n", stderr);
  456. X  fputs ("-r for the Infra Red Light Map\n", stderr);
  457. X  fputs ("-v for Visible Light Map\n", stderr);
  458. X  fputs ("-u# for the Upper Air maps at a # * 100 hPa itervals\n", stderr);
  459. X  fputs ("(# = 2,3,5,7,8 for 200hPa, 300hPa, 500hPa, 700hPa, 800hPa respectively)\n", stderr);
  460. X  return;
  461. X}
  462. END_OF_FILE
  463.   if test 8259 -ne `wc -c <'getwxmap.c'`; then
  464.     echo shar: \"'getwxmap.c'\" unpacked with wrong size!
  465.   fi
  466.   # end of 'getwxmap.c'
  467. fi
  468. echo shar: End of archive 1 \(of 1\).
  469. cp /dev/null ark1isdone
  470. MISSING=""
  471. for I in 1 ; do
  472.     if test ! -f ark${I}isdone ; then
  473.     MISSING="${MISSING} ${I}"
  474.     fi
  475. done
  476. if test "${MISSING}" = "" ; then
  477.     echo You have the archive.
  478.     rm -f ark[1-9]isdone
  479. else
  480.     echo You still must unpack the following archives:
  481.     echo "        " ${MISSING}
  482. fi
  483. exit 0
  484. exit 0 # Just in case...
  485.