v01i056: xphoon: Show phase of the Moon on root window, Part01/04
Mike Wexler
mikew at wyse.wyse.com
Thu Oct 6 03:49:41 AEST 1988
Submitted-by: Jef Poskanzer <jef at helios.ee.lbl.gov>
Posting-number: Volume 1, Issue 56
Archive-name: xphoon11/part01
[Since the majority of the postings in this newsgroup are for X11,
I will only put the X version required if it is not X11. -mcw]
[Many of you may find this useful in tracking down bugs that depend
on the phase of the moon. This will allow you to quickly determine
what phase it currently is in. :-> -mcw]
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# README
# Imakefile
# Makefile
# xphoon.man
# xphoon.c
# cheapmoon.c
# bigcheapmoon.c
# phase.c
# dtime.c
# tws.h
# This archive created: Mon Oct 3 18:22:44 1988
# By: Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(2257 characters)'
if test -f 'README'
then
echo shar: will not over-write existing file "'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
X xphoon, X11 version
X Distribution of 27aug88
X
XFiles in this distribution:
X
X README this
X IMakefile guess
X Makefile just to get you bootstrapped
X main.c main routine
X cheapmoon.c wrapper for standard-sized moon bitmap
X bigcheapmoon.c wrapper for large-sized moon bitmap
X phase.c phase of moon calculations, from phoon and moontool
X dtime.c extracted from the libtws date/time library
X tws.h include file from libtws
X xphoon.man manual entry
X cheapmoon.xbm.Z.uu?? standard-sized moon bitmap (shar dist. only)
X cheapmoon.xbm standard-sized moon bitmap (tar dist. only)
X bigcheapmoon.xbm large-sized moon bitmap (tar dist. only)
X
XTo compile: If you got shar files, unpack them, and do a 'make unshar'
Xto get cheapmoon.xbm. If you got a tar file, you're ok. Then:
X
XDisplay size: if your display is a standard Sun low-res 1152x900 screen,
Xyou can use cheapmoon.xbm. If you have a Sun high-res 1600x1280 screen,
Xand you can FTP, you can fetch bigcheapmoon from expo.lcs.mit.edu, in
Xcontrib/poskbitmaptars/poskbitmaps.b.tar - the Makefile is already set
Xup to make xbigphoon out of bigcheapmoon. If you have some other size
Xdisplay, you will have to HACK. I suggest using the "pbm" portable
Xbitmap package to cut and paste. Pbm is available for FTP in the same
Xplace as above, and it has also been distributed over comp.sources.misc
Xso it will be in the various archives. Then:
X
XOnce you have the display size figured out:
X (a) Edit Makefile (not Imakefile) and change the definition of TOP to
X point to your X11 source tree.
X (b) make Makefile
X (c) make depend
X (d) make
XIf things don't work quite right, you may have to mess with the compiler
Xflags in Imakefile and go back to step (b). For instance, we like to add
X-fswitch because some of our Suns have floating point chips and others don't.
XAlso, we use the -pipe flag because many of our Suns have small /tmp's.
X
X
XFeedback is welcome - send bug reports, enhancements, checks, money orders,
Xgold bullion, drugs, etc. to the addresses below.
X
X Jef Poskanzer
X jef at rtsg.ee.lbl.gov
X {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
X
X Craig Leres
X leres at helios.ee.lbl.gov
X ucbvax!leres
SHAR_EOF
if test 2257 -ne "`wc -c < 'README'`"
then
echo shar: error transmitting "'README'" '(should have been 2257 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Imakefile'" '(2552 characters)'
if test -f 'Imakefile'
then
echo shar: will not over-write existing file "'Imakefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Imakefile'
X# @(#) $Header: Imakefile,v 1.3 88/08/26 22:29:51 jef Exp $ (LBL)
X#
X# Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
X#
X# Permission to use, copy, modify, and distribute this software and its
X# documentation for any purpose and without fee is hereby granted, provided
X# that the above copyright notice appear in all copies and that both that
X# copyright notice and this permission notice appear in supporting
X# documentation. This software is provided "as is" without express or
X# implied warranty.
X
X
X INCLUDES = -I. -I$(TOP) -I$(TOP)/X11 -I$(TOP)/X11/bitmaps
XLOCAL_LIBRARIES = $(XLIB)
X SYS_LIBRARIES = -lm
X
X# System-dependent options -- xbigphoon is a little big for many Suns
X# to compile.
X# DEFINES = -pipe
X
X SRCS1 = xphoon.c cheapmoon.c phase.c dtime.c
X OBJS1 = xphoon.o cheapmoon.o phase.o dtime.o
X
X SRCS2 = xphoon.c bigcheapmoon.c phase.c dtime.c
X OBJS2 = xphoon.o bigcheapmoon.o phase.o dtime.o
X
X PROGRAMS = xphoon xbigphoon
X
XComplexProgramTarget_1(xphoon,$(LOCAL_LIBRARIES),)
X
XComplexProgramTarget_2(xbigphoon,$(LOCAL_LIBRARIES),)
X
X
X# Make the export sharchive.
Xshar: xphoon.shar
X
Xxphoon.shar: xphoon.shar1 xphoon.shar2 xphoon.shar3 xphoon.shar4
X
Xxphoon.shar1: README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h
X shar -v -c -p X README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h >xphoon.shar1
X
Xcheapmoon.xbm.Z: cheapmoon.xbm
X compress -c cheapmoon.xbm >cheapmoon.xbm.Z
X
Xcheapmoon.xbm.Z.uu: cheapmoon.xbm.Z
X uuencode cheapmoon.xbm.Z cheapmoon.xbm.Z >cheapmoon.xbm.Z.uu
X
Xcheapmoon.xbm.Z.uuaa: cheapmoon.xbm.Z.uu
X split -550 cheapmoon.xbm.Z.uu cheapmoon.xbm.Z.uu
X
Xxphoon.shar2: cheapmoon.xbm.Z.uuaa
X shar -v -c -p X cheapmoon.xbm.Z.uuaa >xphoon.shar2
X
Xxphoon.shar3: cheapmoon.xbm.Z.uuab
X shar -v -c -p X cheapmoon.xbm.Z.uuab >xphoon.shar3
X
Xxphoon.shar4: cheapmoon.xbm.Z.uuac
X shar -v -c -p X cheapmoon.xbm.Z.uuac >xphoon.shar4
X
X# Unpack the compressed, uuencoded, shared bitmap.
Xunshar:
X cat cheapmoon.xbm.Z.uu?? > cheapmoon.xbm.Z.uu
X uudecode cheapmoon.xbm.Z.uu
X uncompress cheapmoon.xbm.Z
X
X# Make the export tarchive.
Xtar: xphoon.tar.Z
X
Xxphoon.tar.Z: xphoon.tar
X rm -f xphoon.tar.Z
X compress xphoon.tar
X
Xxphoon.tar: README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h cheapmoon.xbm bigcheapmoon.xbm
X tar chf xphoon.tar README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h cheapmoon.xbm bigcheapmoon.xbm
SHAR_EOF
if test 2552 -ne "`wc -c < 'Imakefile'`"
then
echo shar: error transmitting "'Imakefile'" '(should have been 2552 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Makefile'" '(6658 characters)'
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X#
X# Warning: the cpp used on this machine replaces
X# all newlines and multiple tabs/spaces in a macro
X# expansion with a single space. Imake tries to
X# compensate for this, but is not always
X# successful.
X#
X
X#
X# This makefile is automatically generated by imake... do not modify
X# or you may lose your changes when imake generates makefiles again.
X# Ignore this message if you are not using imake.
X#
X
X TOP = ./../..
X AS = as
X CC = cc
X CPP = /lib/cpp
X LD = ld
X LINT = lint
X INSTALL = install
X TAGS = ctags
X RM = rm -f
X MV = mv
X LN = ln -s
X RANLIB = ranlib
X AR = ar clq
X LS = ls
X LINTOPTS = -axz
X LINTLIBFLAG = -C
X MAKE = make
X STD_DEFINES =
X CDEBUGFLAGS = -O
X DESTDIR =
X
X PATHSEP = /
X DEPEND = $(DEPENDSRC)/makedepend
X IMAKE = $(IMAKESRC)/imake
X RGB = $(RGBSRC)/rgb
X CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X LDFLAGS = $(CDEBUGFLAGS) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X INSTUIDFLAGS = -m 4755
X INSTLIBFLAGS = -m 0664
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTAPPFLAGS = -m 0444
X
X USRLIBDIR = $(DESTDIR)/usr/lib
X BINDIR = $(DESTDIR)/usr/new/X11
X LIBDIR = $(DESTDIR)/usr/new/lib/X11
X LINTLIBDIR = $(USRLIBDIR)/lint
X INCDIR = $(DESTDIR)/usr/include/X11
X FONTDIR = $(LIBDIR)/fonts
X UWMDIR = $(LIBDIR)/uwm
X MANDIR = $(DESTDIR)/usr/man/mann
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X ADMDIR = $(DESTDIR)/usr/adm
X
X CLIENTSRC = $(TOP)/clients
X DEMOSRC = $(TOP)/demos
X LIBSRC = $(TOP)/lib
X FONTSRC = $(TOP)/fonts
X INCLUDESRC = $(TOP)/X11
X SERVERSRC = $(TOP)/server
X UTILSRC = $(TOP)/util
X EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/contrib
X DOCSRC = $(TOP)/doc
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(UTILSRC)/imake
X IRULESRC = $(UTILSRC)/imake.includes
X RGBSRC = $(UTILSRC)/rgb
X XLIBSRC = $(LIBSRC)/X
X TOOLKITSRC = $(LIBSRC)/Xt
X AWIDGETSRC = $(LIBSRC)/Xaw
X OLDXLIBSRC = $(LIBSRC)/oldX
X EXTENSIONSRC = $(TOP)/extensions
X XMANSRC = $(DOCSRC)/Xlib/Xman
X EXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
X XLIB = $(XLIBSRC)/libX11.a
X OLDXLIB = $(OLDXLIBSRC)/liboldX.a
X XTOOLLIB = $(TOOLKITSRC)/libXt.a
X XAWLIB = $(AWIDGETSRC)/libXaw.a
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
X INCLUDES = -I$(TOP)
X MACROFILE = Sun.macros
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl \
X -I$(NEWTOP)$(IRULESRC) \
X -s Makefile
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X tags TAGS make.log
X
X# @(#) $Header: Imakefile,v 1.3 88/08/26 22:29:51 jef Exp $ (LBL)
X#
X# Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
X#
X# Permission to use, copy, modify, and distribute this software and its
X# documentation for any purpose and without fee is hereby granted, provided
X# that the above copyright notice appear in all copies and that both that
X# copyright notice and this permission notice appear in supporting
X# documentation. This software is provided "as is" without express or
X# implied warranty.
X
X INCLUDES = -I. -I$(TOP) -I$(TOP)/X11 -I$(TOP)/X11/bitmaps
XLOCAL_LIBRARIES = $(XLIB)
X SYS_LIBRARIES = -lm
X
X# System-dependent options -- xbigphoon is a little big for many Suns
X# to compile.
X# DEFINES = -pipe
X
X SRCS1 = xphoon.c cheapmoon.c phase.c dtime.c
X OBJS1 = xphoon.o cheapmoon.o phase.o dtime.o
X
X SRCS2 = xphoon.c bigcheapmoon.c phase.c dtime.c
X OBJS2 = xphoon.o bigcheapmoon.o phase.o dtime.o
X
X PROGRAMS = xphoon xbigphoon
X
X OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
X SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
X
Xall: $(PROGRAMS)
X
Xxphoon: $(OBJS1) $(LOCAL_LIBRARIES)
X $(RM) $@
X $(CC) -o $@ $(OBJS1) $(LOCAL_LIBRARIES) $(LDFLAGS)
X
Xinstall:: xphoon
X $(INSTALL) -c $(INSTALLFLAGS) xphoon $(BINDIR)
X
Xinstall:: xphoon.man
X $(INSTALL) -c $(INSTMANFLAGS) xphoon.man $(MANDIR)/xphoon.n
Xrelink::
X $(RM) $(PROGRAMS)
X $(MAKE) $(MFLAGS) $(PROGRAMS)
X
Xdepend:: $(DEPEND)
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
X
X$(DEPEND):
X @echo "making $(DEPENDSRC)"; \
X cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X $(RM) $(PROGRAMS)
X
Xxbigphoon: $(OBJS2) $(LOCAL_LIBRARIES)
X $(RM) $@
X $(CC) -o $@ $(OBJS2) $(LOCAL_LIBRARIES) $(LDFLAGS)
X
Xinstall:: xbigphoon
X $(INSTALL) -c $(INSTALLFLAGS) xbigphoon $(BINDIR)
X
Xinstall:: xbigphoon.man
X $(INSTALL) -c $(INSTMANFLAGS) xbigphoon.man $(MANDIR)/xbigphoon.n
X
X# Make the export sharchive.
Xshar: xphoon.shar
X
Xxphoon.shar: xphoon.shar1 xphoon.shar2 xphoon.shar3 xphoon.shar4
X
Xxphoon.shar1: README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h
X shar -v -c -p X README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h >xphoon.shar1
X
Xcheapmoon.xbm.Z: cheapmoon.xbm
X compress -c cheapmoon.xbm >cheapmoon.xbm.Z
X
Xcheapmoon.xbm.Z.uu: cheapmoon.xbm.Z
X uuencode cheapmoon.xbm.Z cheapmoon.xbm.Z >cheapmoon.xbm.Z.uu
X
Xcheapmoon.xbm.Z.uuaa: cheapmoon.xbm.Z.uu
X split -550 cheapmoon.xbm.Z.uu cheapmoon.xbm.Z.uu
X
Xxphoon.shar2: cheapmoon.xbm.Z.uuaa
X shar -v -c -p X cheapmoon.xbm.Z.uuaa >xphoon.shar2
X
Xxphoon.shar3: cheapmoon.xbm.Z.uuab
X shar -v -c -p X cheapmoon.xbm.Z.uuab >xphoon.shar3
X
Xxphoon.shar4: cheapmoon.xbm.Z.uuac
X shar -v -c -p X cheapmoon.xbm.Z.uuac >xphoon.shar4
X
X# Unpack the compressed, uuencoded, shared bitmap.
Xunshar:
X cat cheapmoon.xbm.Z.uu?? > cheapmoon.xbm.Z.uu
X uudecode cheapmoon.xbm.Z.uu
X uncompress cheapmoon.xbm.Z
X
X# Make the export tarchive.
Xtar: xphoon.tar.Z
X
Xxphoon.tar.Z: xphoon.tar
X rm -f xphoon.tar.Z
X compress xphoon.tar
X
Xxphoon.tar: README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h cheapmoon.xbm bigcheapmoon.xbm
X tar chf xphoon.tar README Imakefile Makefile xphoon.man xphoon.c cheapmoon.c bigcheapmoon.c phase.c dtime.c tws.h cheapmoon.xbm bigcheapmoon.xbm
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X $(IRULESRC)/Imake.tmpl \
X $(IRULESRC)/Imake.rules \
X $(IRULESRC)/$(MACROFILE)
X -$(RM) Makefile.bak; $(MV) Makefile Makefile.bak
X $(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X @echo "making $(IMAKESRC)"; \
X cd $(IMAKESRC); $(MAKE)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
Xinstall::
X @echo "install done"
X
XMakefiles::
X
SHAR_EOF
if test 6658 -ne "`wc -c < 'Makefile'`"
then
echo shar: error transmitting "'Makefile'" '(should have been 6658 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'xphoon.man'" '(1581 characters)'
if test -f 'xphoon.man'
then
echo shar: will not over-write existing file "'xphoon.man'"
else
sed 's/^X//' << \SHAR_EOF > 'xphoon.man'
X.TH xphoon 1 "26 August 1988"
X.SH NAME
Xxphoon \- set the X root window to display the PHase of the mOON
X.SH SYNOPSIS
X.in +.5i
X.ti -.5i
Xxphoon \%[ -b ] \%[ -t <interval> ] \%[ -display <display> ]
X.in -.5i
X.SH DESCRIPTION
X.I Xphoon
Xsets the X root window to display a picture of the moon in its current phase,
Xincluding the partial lighting of the dark side by reflected earthlight.
X.LP
XThe
X.I -b
Xflag defeats the earthlight feature, forcing the dark side to be black.
XThe
X.I -t
Xflag can be used to have
X.I xphoon
Xkeep running and update the picture every
X.I <interval>
Xminutes.
X(Normally,
X.I xphoon
Xjust sets the root picture and exits.)
X.SH NOTES
XThe original motivation for this program was that xsetroot was
X.B too slow.
XLoading a full-screen bitmap took about 15 seconds.
XWe made a trivial program that had fullmoon.bitmap compiled in, and
Xit ran in less than a second.
X(And incidentally, the executable was smaller than fullmoon.bitmap.)
XThen later we came up with the cheapmoons, the phase hacking, and
Xfinally the earthlight.
X.SH "SEE\ ALSO"
X.IR phoon(1),
X.IR xsetroot(1)
X.SH AUTHORS
XCopyright (C) 1988 by Jef Poskanzer and Craig Leres.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation. This software is provided "as is" without express or
Ximplied warranty.
X
XThe moon-phase computation is from "moontool.c" by John Walker.
SHAR_EOF
if test 1581 -ne "`wc -c < 'xphoon.man'`"
then
echo shar: error transmitting "'xphoon.man'" '(should have been 1581 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'xphoon.c'" '(7858 characters)'
if test -f 'xphoon.c'
then
echo shar: will not over-write existing file "'xphoon.c'"
else
sed 's/^X//' << \SHAR_EOF > 'xphoon.c'
X#ifndef lint
Xstatic char rcsid[] =
X "@(#) $Header: xphoon.c,v 1.9 88/08/26 22:29:47 jef Exp $ (LBL)";
X#endif
X
X/*
X** Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <X11/Xos.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/Xatom.h>
X#define BitmapSize(w,h) ((((w)+7)/8)*(h))
X#include <stdio.h>
X#include <math.h>
X#include "tws.h"
X
Xchar *argv0;
Xint blackflag = 0;
Xint demoflag = 0;
XDisplay *dpy = NULL;
X
Xchar *malloc();
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X char *display = NULL;
X int w, h, cx, cy, r;
X int size;
X char *bits, *xbits;
X int delayminutes = 0;
X
X argv0 = argv[0];
X getbitmap(&w, &h, &bits, &cx, &cy, &r);
X
Xagain:
X if (argc > 1 && strcmp(argv[1], "-b") == 0) {
X argv++;
X argc--;
X blackflag = 1;
X goto again;
X }
X if (argc > 1 && strcmp(argv[1], "-d") == 0) {
X argv++;
X argc--;
X demoflag = 1;
X goto again;
X }
X if (argc > 2 && strcmp(argv[1], "-t") == 0) {
X argv++;
X argc--;
X if (sscanf(argv[1], "%d", &delayminutes) != 1)
X goto usage;
X argv++;
X argc--;
X goto again;
X }
X if (argc > 2 && strcmp(argv[1], "-x") == 0) {
X argv++;
X argc--;
X if (sscanf(argv[1], "%d", &cx) != 1)
X goto usage;
X argv++;
X argc--;
X goto again;
X }
X if (argc > 2 && strcmp(argv[1], "-y") == 0) {
X argv++;
X argc--;
X if (sscanf(argv[1], "%d", &cy) != 1)
X goto usage;
X argv++;
X argc--;
X goto again;
X }
X if (argc > 2 && strcmp(argv[1], "-display") == 0) {
X argv++;
X argc--;
X display = argv[1];
X argv++;
X argc--;
X goto again;
X }
X
X if (argc > 1) {
Xusage:
X fprintf(stderr,
X "usage: %s [-b] [-t minutes] [-display display]\n", argv0);
X exit(1);
X
X }
X
X if ((dpy = XOpenDisplay(display)) == 0) {
X fprintf(stderr, "%s: Can't open display \"%s\"\n",
X argv0, XDisplayName(display));
X exit(1);
X }
X
X if (delayminutes <= 0 && ! demoflag) {
X hackbits(dtwstime(), w, h, bits, cx, cy, r);
X setroot(w, h, bits);
X XCloseDisplay(dpy);
X exit(0);
X }
X
X size = BitmapSize(w, h);
X xbits = (char *)malloc(size);
X for (;;) {
X bcopy((char *)bits, (char *)xbits, size);
X hackbits(dtwstime(), w, h, xbits, cx, cy, r);
X setroot(w, h, xbits);
X if ( demoflag )
X sleep(1); /* continuous mode */
X else
X sleep(delayminutes * 60);
X }
X /* NOTREACHED */
X}
X
X
Xsetroot(w, h, bits)
X int w, h;
X char *bits;
X{
X Pixmap bitmap;
X Pixmap pixmap;
X GC gc;
X XGCValues gcv;
X unsigned long length, after;
X int format;
X Atom prop, type;
X unsigned char *data;
X
X bitmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, w, h);
X if (bitmap == 0) {
X fprintf(stderr, "%s: Unable to store Bitmap", argv0);
X exit(1);
X }
X
X gcv.foreground = BlackPixel(dpy,DefaultScreen(dpy));
X gcv.background = WhitePixel(dpy,DefaultScreen(dpy));
X gc = XCreateGC(
X dpy, DefaultRootWindow(dpy), GCForeground|GCBackground, &gcv);
X
X pixmap = XCreatePixmap(
X dpy, DefaultRootWindow(dpy), w, h,
X DefaultDepth(dpy, DefaultScreen(dpy)));
X if (pixmap == 0) {
X fprintf(stderr, "%s: Unable to create Pixmap", argv0);
X exit(1);
X }
X
X XCopyPlane(dpy, bitmap, pixmap, gc, 0, 0, w, h, 0, 0, 1L);
X XSetWindowBackgroundPixmap(dpy, DefaultRootWindow(dpy), pixmap);
X XFreeGC(dpy, gc);
X XFreePixmap(dpy, bitmap);
X XFreePixmap(dpy, pixmap);
X XClearWindow(dpy, DefaultRootWindow(dpy));
X XFlush(dpy);
X
X /* Not sure what this garbage does, but xsetroot has it, so... */
X prop = XInternAtom(dpy, "_XSETROOT_ID", False);
X (void) XGetWindowProperty(
X dpy, DefaultRootWindow(dpy), prop, 0L, 1L, True, AnyPropertyType,
X &type, &format, &length, &after, &data);
X if ((type == XA_PIXMAP) && (format == 32) &&
X (length == 1) && (after == 0))
X XKillClient(dpy, *((Pixmap *)data));
X else if (type != None)
X fprintf(stderr, "%s: warning: _XSETROOT_ID property is garbage\n",
X argv0);
X XFlush(dpy);
X}
X
X
X#ifdef notdef
Xshort leftmask[16] = {
X 0xffff, 0xfffe, 0xfffc, 0xfff8, 0xfff0, 0xffe0, 0xffc0, 0xff80,
X 0xff00, 0xfe00, 0xfc00, 0xf800, 0xf000, 0xe000, 0xc000, 0x8000,
X};
Xshort rightmask[16] = {
X 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f,
X 0x00ff, 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff,
X};
X#endif notdef
Xstatic char leftmask[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
Xstatic char rightmask[8] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
X
Xstatic char shade_0_bits[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
Xstatic char shade_1_bits[] = {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
Xstatic char shade_2_bits[] = {0xfe,0xff,0xfb,0xff,0xff,0xff,0xff,0xff};
Xstatic char shade_3_bits[] = {0xfe,0xff,0xfb,0xff,0x7f,0xff,0xff,0xff};
Xstatic char shade_4_bits[] = {0xfe,0xff,0xfb,0xff,0x7f,0xff,0xff,0xef};
Xstatic char shade_5_bits[] = {0xfe,0xbf,0xfb,0xff,0x7f,0xff,0xff,0xef};
Xstatic char shade_6_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7f,0xff,0xff,0xef};
Xstatic char shade_7_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7f,0xff,0xfe,0xef};
Xstatic char shade_8_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7f,0xdf,0xfe,0xef};
Xstatic char shade_9_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7d,0xdf,0xfe,0xef};
Xstatic char shade_10_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7d,0xdf,0xfa,0xef};
Xstatic char shade_11_bits[] = {0xfe,0xbf,0xfb,0xdf,0x7d,0xdf,0xfa,0xaf};
Xstatic char shade_12_bits[] = {0xfe,0xbf,0xfa,0xdf,0x7d,0xdf,0xfa,0xaf};
Xstatic char shade_13_bits[] = {0xfe,0xaf,0xfa,0xdf,0x7d,0xdf,0xfa,0xaf};
Xstatic char shade_14_bits[] = {0xfe,0xaf,0xfa,0xdf,0x75,0xdf,0xfa,0xaf};
Xstatic char shade_15_bits[] = {0xfa,0xaf,0xfa,0xdf,0x75,0xdf,0xfa,0xaf};
X
Xchar *shades[16] = {
X shade_0_bits, shade_1_bits, shade_2_bits, shade_3_bits,
X shade_4_bits, shade_5_bits, shade_6_bits, shade_7_bits,
X shade_8_bits, shade_9_bits, shade_10_bits, shade_11_bits,
X shade_12_bits, shade_13_bits, shade_14_bits, shade_15_bits };
X
X#define PI 3.14159265358979323846 /* Assume not near black hole or in
X Tennessee */
X
Xdouble jtime(), phase();
X
Xhackbits(t, w, h, bits, cx, cy, r)
X struct tws *t;
X int w, h;
X char *bits;
X int cx, cy, r;
X{
X double jd, angphase, cphase, aom, cdist, cangdia, csund, csuang;
X int i;
X register int x, y;
X int xleft, xright;
X double fxleft, fxright;
X double fy;
X int wxright, bxright, wxleft, bxleft;
X int off;
X double cap, ratio;
X int shadeindex;
X char shade;
X static double demoinc = 0.0;
X
X jd = jtime( t );
X if ( demoflag ) {
X /* Jump ahead a day each time through. */
X jd += demoinc;
X demoinc += 1.0;
X }
X
X angphase = phase( jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
X cap = cos( angphase );
X
X /* Hack to figure approximate earthlighting. */
X if ( cphase < 0.1 ) cphase = 0.1;
X if ( cphase > 0.9 ) cphase = 0.9;
X ratio = (1.0 - cphase) / cphase; /* ratio varies from 9.0 to 0.111 */
X shadeindex = (int) ( ratio / 9.0 * 15.9999 );
X
X#ifdef DEBUG
Xprintf("angphase %f, cap %f\n", angphase, cap);
X#endif
X
X for (i = 0; i < 2 * r; i++) {
X y = cy - r + i;
X fy = i - r;
X fxright = r * sqrt(1.0 - (fy * fy) / (r * r));
X fxleft = - fxright;
X if (angphase >= 0.0 && angphase < PI)
X fxright *= cap;
X else
X fxleft *= cap;
X
X xright = fxright + cx;
X xleft = fxleft + cx;
X
X wxright = xright / 8;
X bxright = xright % 8;
X
X wxleft = xleft / 8;
X bxleft = xleft % 8;
X
X off = y * ((w + 7) / 8);
X
X if ( blackflag )
X shade = 0xff;
X else
X shade = shades[shadeindex][y % 8];
X if (wxleft == wxright)
X bits[wxleft + off] |=
X leftmask[bxleft] & shade & rightmask[bxright];
X else {
X bits[wxleft + off] |= leftmask[bxleft] & shade;
X for (x = wxleft + 1; x < wxright; x++)
X bits[x + off] |= shade;
X bits[wxright + off] |= rightmask[bxright] & shade;
X }
X }
X
X}
SHAR_EOF
if test 7858 -ne "`wc -c < 'xphoon.c'`"
then
echo shar: error transmitting "'xphoon.c'" '(should have been 7858 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'cheapmoon.c'" '(784 characters)'
if test -f 'cheapmoon.c'
then
echo shar: will not over-write existing file "'cheapmoon.c'"
else
sed 's/^X//' << \SHAR_EOF > 'cheapmoon.c'
X#ifndef lint
Xstatic char rcsid[] =
X "@(#) $Header: cheapmoon.c,v 1.6 88/09/02 23:09:25 jef Exp $ (LBL)";
X#endif
X
X/*
X** Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <cheapmoon.xbm>
X
Xgetbitmap(w, h, bits, cx, cy, r)
X int *w, *h;
X char **bits;
X int *cx, *cy, *r;
X{
X *w = cheapmoon_width;
X *h = cheapmoon_height;
X *bits = cheapmoon_bits;
X *cx = 576;
X *cy = 455;
X *r = 378;
X}
SHAR_EOF
if test 784 -ne "`wc -c < 'cheapmoon.c'`"
then
echo shar: error transmitting "'cheapmoon.c'" '(should have been 784 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'bigcheapmoon.c'" '(799 characters)'
if test -f 'bigcheapmoon.c'
then
echo shar: will not over-write existing file "'bigcheapmoon.c'"
else
sed 's/^X//' << \SHAR_EOF > 'bigcheapmoon.c'
X#ifndef lint
Xstatic char rcsid[] =
X "@(#) $Header: bigcheapmoon.c,v 1.6 88/08/26 22:29:18 jef Exp $ (LBL)";
X#endif
X
X/*
X** Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <bigcheapmoon.xbm>
X
Xgetbitmap(w, h, bits, cx, cy, r)
X int *w, *h;
X char **bits;
X int *cx, *cy, *r;
X{
X *w = bigcheapmoon_width;
X *h = bigcheapmoon_height;
X *bits = bigcheapmoon_bits;
X *cx = 800;
X *cy = 645;
X *r = 378;
X}
SHAR_EOF
if test 799 -ne "`wc -c < 'bigcheapmoon.c'`"
then
echo shar: error transmitting "'bigcheapmoon.c'" '(should have been 799 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'phase.c'" '(13787 characters)'
if test -f 'phase.c'
then
echo shar: will not over-write existing file "'phase.c'"
else
sed 's/^X//' << \SHAR_EOF > 'phase.c'
X#ifndef lint
Xstatic char rcsid[] =
X "@(#) $Header: phase.c,v 1.2 88/08/26 22:29:42 jef Exp $ (LBL)";
X#endif
X
X/* phase.c - routines to calculate the phase of the moon
X**
X** Adapted from "moontool.c" by John Walker, Release 2.0.
X*/
X
X
X#include <stdio.h>
X#include <math.h>
X#include "tws.h"
X
X/* Astronomical constants. */
X
X#define epoch 2444238.5 /* 1980 January 0.0 */
X
X/* Constants defining the Sun's apparent orbit. */
X
X#define elonge 278.833540 /* ecliptic longitude of the Sun
X at epoch 1980.0 */
X#define elongp 282.596403 /* ecliptic longitude of the Sun at
X perigee */
X#define eccent 0.016718 /* eccentricity of Earth's orbit */
X#define sunsmax 1.495985e8 /* semi-major axis of Earth's orbit, km */
X#define sunangsiz 0.533128 /* sun's angular size, degrees, at
X semi-major axis distance */
X
X/* Elements of the Moon's orbit, epoch 1980.0. */
X
X#define mmlong 64.975464 /* moon's mean lonigitude at the epoch */
X#define mmlongp 349.383063 /* mean longitude of the perigee at the
X epoch */
X#define mlnode 151.950429 /* mean longitude of the node at the
X epoch */
X#define minc 5.145396 /* inclination of the Moon's orbit */
X#define mecc 0.054900 /* eccentricity of the Moon's orbit */
X#define mangsiz 0.5181 /* moon's angular size at distance a
X from Earth */
X#define msmax 384401.0 /* semi-major axis of Moon's orbit in km */
X#define mparallax 0.9507 /* parallax at distance a from Earth */
X#define synmonth 29.53058868 /* synodic month (new Moon to new Moon) */
X#define lunatbase 2423436.0 /* base date for E. W. Brown's numbered
X series of lunations (1923 January 16) */
X
X/* Properties of the Earth. */
X
X#define earthrad 6378.16 /* radius of Earth in kilometres */
X
X
X#define PI 3.14159265358979323846 /* assume not near black hole nor in
X Tennessee */
X
X/* Handy mathematical functions. */
X
X#define sgn(x) (((x) < 0) ? -1 : ((x) > 0 ? 1 : 0)) /* extract sign */
X#define abs(x) ((x) < 0 ? (-(x)) : (x)) /* absolute val */
X#define fixangle(a) ((a) - 360.0 * (floor((a) / 360.0))) /* fix angle */
X#define torad(d) ((d) * (PI / 180.0)) /* deg->rad */
X#define todeg(d) ((d) * (180.0 / PI)) /* rad->deg */
X#define dsin(x) (sin(torad((x)))) /* sin from deg */
X#define dcos(x) (cos(torad((x)))) /* cos from deg */
X
X
X/* jdate - convert internal GMT date and time to Julian day and fraction */
X
Xstatic long jdate(t)
Xstruct tws *t;
X{
X long c, m, y;
X
X y = t->tw_year + 1900;
X m = t->tw_mon + 1;
X if (m > 2)
X m = m - 3;
X else {
X m = m + 9;
X y--;
X }
X c = y / 100L; /* compute century */
X y -= 100L * c;
X return t->tw_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
X (m * 153L + 2) / 5 + 1721119L;
X}
X
X/* jtime - convert internal date and time to astronomical Julian
X** time (i.e. Julian date plus day fraction, expressed as
X** a double)
X*/
X
Xdouble jtime(t)
Xstruct tws *t;
X{
X int c;
X
X c = - t->tw_zone;
X if ( t->tw_flags & TW_DST )
X c += 60;
X
X return (jdate(t) - 0.5) +
X (t->tw_sec + 60 * (t->tw_min + c + 60 * t->tw_hour)) / 86400.0;
X}
X
X/* jyear - convert Julian date to year, month, day, which are
X** returned via integer pointers to integers
X*/
X
Xstatic void jyear(td, yy, mm, dd)
Xdouble td;
Xint *yy, *mm, *dd;
X{
X double j, d, y, m;
X
X td += 0.5; /* astronomical to civil */
X j = floor(td);
X j = j - 1721119.0;
X y = floor(((4 * j) - 1) / 146097.0);
X j = (j * 4.0) - (1.0 + (146097.0 * y));
X d = floor(j / 4.0);
X j = floor(((4.0 * d) + 3.0) / 1461.0);
X d = ((4.0 * d) + 3.0) - (1461.0 * j);
X d = floor((d + 4.0) / 4.0);
X m = floor(((5.0 * d) - 3) / 153.0);
X d = (5.0 * d) - (3.0 + (153.0 * m));
X d = floor((d + 5.0) / 5.0);
X y = (100.0 * y) + j;
X if (m < 10.0)
X m = m + 3;
X else {
X m = m - 9;
X y = y + 1;
X }
X *yy = y;
X *mm = m;
X *dd = d;
X}
X
X/* jhms - convert Julian time to hour, minutes, and seconds */
X
Xstatic void jhms(j, h, m, s)
Xdouble j;
Xint *h, *m, *s;
X{
X long ij;
X
X j += 0.5; /* astronomical to civil */
X ij = (j - floor(j)) * 86400.0;
X *h = ij / 3600L;
X *m = (ij / 60L) % 60L;
X *s = ij % 60L;
X}
X
X/* meanphase - calculates mean phase of the Moon for a given base date
X** and desired phase:
X** 0.0 New Moon
X** 0.25 First quarter
X** 0.5 Full moon
X** 0.75 Last quarter
X** Beware!!! This routine returns meaningless
X** results for any other phase arguments. Don't
X** attempt to generalise it without understanding
X** that the motion of the moon is far more complicated
X** that this calculation reveals.
X*/
X
Xstatic double meanphase(sdate, phase, usek)
Xdouble sdate, phase;
Xdouble *usek;
X{
X int yy, mm, dd;
X double k, t, t2, t3, nt1;
X
X jyear(sdate, &yy, &mm, &dd);
X
X k = (yy + ((mm - 1) * (1.0 / 12.0)) - 1900) * 12.3685;
X
X /* Time in Julian centuries from 1900 January 0.5. */
X t = (sdate - 2415020.0) / 36525;
X t2 = t * t; /* square for frequent use */
X t3 = t2 * t; /* cube for frequent use */
X
X *usek = k = floor(k) + phase;
X nt1 = 2415020.75933 + synmonth * k
X + 0.0001178 * t2
X - 0.000000155 * t3
X + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
X
X return nt1;
X}
X
X/* truephase - given a K value used to determine the mean phase of the
X** new moon, and a phase selector (0.0, 0.25, 0.5, 0.75),
X** obtain the true, corrected phase time
X*/
X
Xstatic double truephase(k, phase)
Xdouble k, phase;
X{
X double t, t2, t3, pt, m, mprime, f;
X int apcor = 0;
X
X k += phase; /* add phase to new moon time */
X t = k / 1236.85; /* time in Julian centuries from
X 1900 January 0.5 */
X t2 = t * t; /* square for frequent use */
X t3 = t2 * t; /* cube for frequent use */
X pt = 2415020.75933 /* mean time of phase */
X + synmonth * k
X + 0.0001178 * t2
X - 0.000000155 * t3
X + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
X
X m = 359.2242 /* Sun's mean anomaly */
X + 29.10535608 * k
X - 0.0000333 * t2
X - 0.00000347 * t3;
X mprime = 306.0253 /* Moon's mean anomaly */
X + 385.81691806 * k
X + 0.0107306 * t2
X + 0.00001236 * t3;
X f = 21.2964 /* Moon's argument of latitude */
X + 390.67050646 * k
X - 0.0016528 * t2
X - 0.00000239 * t3;
X if ((phase < 0.01) || (abs(phase - 0.5) < 0.01)) {
X
X /* Corrections for New and Full Moon. */
X
X pt += (0.1734 - 0.000393 * t) * dsin(m)
X + 0.0021 * dsin(2 * m)
X - 0.4068 * dsin(mprime)
X + 0.0161 * dsin(2 * mprime)
X - 0.0004 * dsin(3 * mprime)
X + 0.0104 * dsin(2 * f)
X - 0.0051 * dsin(m + mprime)
X - 0.0074 * dsin(m - mprime)
X + 0.0004 * dsin(2 * f + m)
X - 0.0004 * dsin(2 * f - m)
X - 0.0006 * dsin(2 * f + mprime)
X + 0.0010 * dsin(2 * f - mprime)
X + 0.0005 * dsin(m + 2 * mprime);
X apcor = 1;
X } else if ((abs(phase - 0.25) < 0.01 || (abs(phase - 0.75) < 0.01))) {
X pt += (0.1721 - 0.0004 * t) * dsin(m)
X + 0.0021 * dsin(2 * m)
X - 0.6280 * dsin(mprime)
X + 0.0089 * dsin(2 * mprime)
X - 0.0004 * dsin(3 * mprime)
X + 0.0079 * dsin(2 * f)
X - 0.0119 * dsin(m + mprime)
X - 0.0047 * dsin(m - mprime)
X + 0.0003 * dsin(2 * f + m)
X - 0.0004 * dsin(2 * f - m)
X - 0.0006 * dsin(2 * f + mprime)
X + 0.0021 * dsin(2 * f - mprime)
X + 0.0003 * dsin(m + 2 * mprime)
X + 0.0004 * dsin(m - 2 * mprime)
X - 0.0003 * dsin(2 * m + mprime);
X if (phase < 0.5)
X /* First quarter correction. */
X pt += 0.0028 - 0.0004 * dcos(m) + 0.0003 * dcos(mprime);
X else
X /* Last quarter correction. */
X pt += -0.0028 + 0.0004 * dcos(m) - 0.0003 * dcos(mprime);
X apcor = 1;
X }
X if (!apcor) {
X fprintf(stderr, "truephase() called with invalid phase selector.\n");
X abort();
X }
X return pt;
X}
X
X/* phasehunt5 - find time of phases of the moon which surround the current
X** date. Five phases are found, starting and ending with the
X** new moons which bound the current lunation
X*/
X
Xvoid phasehunt5(sdate, phases)
Xdouble sdate;
Xdouble phases[5];
X{
X double adate, k1, k2, nt1, nt2;
X
X adate = sdate - 45;
X nt1 = meanphase(adate, 0.0, &k1);
X for ( ; ; ) {
X adate += synmonth;
X nt2 = meanphase(adate, 0.0, &k2);
X if (nt1 <= sdate && nt2 > sdate)
X break;
X nt1 = nt2;
X k1 = k2;
X }
X phases[0] = truephase(k1, 0.0);
X phases[1] = truephase(k1, 0.25);
X phases[2] = truephase(k1, 0.5);
X phases[3] = truephase(k1, 0.75);
X phases[4] = truephase(k2, 0.0);
X}
X
X
X/* phasehunt2 - find time of phases of the moon which surround the current
X** date. Two phases are found.
X*/
X
Xvoid phasehunt2(sdate, phases, which)
Xdouble sdate;
Xdouble phases[2];
Xdouble which[2];
X{
X double adate, k1, k2, nt1, nt2;
X
X adate = sdate - 45;
X nt1 = meanphase(adate, 0.0, &k1);
X for ( ; ; ) {
X adate += synmonth;
X nt2 = meanphase(adate, 0.0, &k2);
X if (nt1 <= sdate && nt2 > sdate)
X break;
X nt1 = nt2;
X k1 = k2;
X }
X phases[0] = truephase(k1, 0.0);
X which[0] = 0.0;
X phases[1] = truephase(k1, 0.25);
X which[1] = 0.25;
X if ( phases[1] <= sdate ) {
X phases[0] = phases[1];
X which[0] = which[1];
X phases[1] = truephase(k1, 0.5);
X which[1] = 0.5;
X if ( phases[1] <= sdate ) {
X phases[0] = phases[1];
X which[0] = which[1];
X phases[1] = truephase(k1, 0.75);
X which[1] = 0.75;
X if ( phases[1] <= sdate ) {
X phases[0] = phases[1];
X which[0] = which[1];
X phases[1] = truephase(k2, 0.0);
X which[1] = 0.0;
X }
X }
X }
X}
X
X
X/* kepler - solve the equation of Kepler */
X
Xstatic double kepler(m, ecc)
Xdouble m, ecc;
X{
X double e, delta;
X#define EPSILON 1E-6
X
X e = m = torad(m);
X do {
X delta = e - ecc * sin(e) - m;
X e -= delta / (1 - ecc * cos(e));
X } while (abs(delta) > EPSILON);
X return e;
X}
X
X/* phase - calculate phase of moon as a fraction:
X**
X** The argument is the time for which the phase is requested,
X** expressed as a Julian date and fraction. Returns the terminator
X** phase angle as a percentage of a full circle (i.e., 0 to 1),
X** and stores into pointer arguments the illuminated fraction of
X** the Moon's disc, the Moon's age in days and fraction, the
X** distance of the Moon from the centre of the Earth, and the
X** angular diameter subtended by the Moon as seen by an observer
X** at the centre of the Earth.
X*/
X
Xdouble phase(pdate, pphase, mage, dist, angdia, sudist, suangdia)
Xdouble pdate;
Xdouble *pphase; /* illuminated fraction */
Xdouble *mage; /* age of moon in days */
Xdouble *dist; /* distance in kilometres */
Xdouble *angdia; /* angular diameter in degrees */
Xdouble *sudist; /* distance to Sun */
Xdouble *suangdia; /* sun's angular diameter */
X{
X
X double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
X mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM,
X MoonAge, MoonPhase,
X MoonDist, MoonDFrac, MoonAng, MoonPar,
X F, SunDist, SunAng;
X
X /* Calculation of the Sun's position. */
X
X Day = pdate - epoch; /* date within epoch */
X N = fixangle((360 / 365.2422) * Day); /* mean anomaly of the Sun */
X M = fixangle(N + elonge - elongp); /* convert from perigee
X co-ordinates to epoch 1980.0 */
X Ec = kepler(M, eccent); /* solve equation of Kepler */
X Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
X Ec = 2 * todeg(atan(Ec)); /* true anomaly */
X Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
X longitude */
X /* Orbital distance factor. */
X F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
X SunDist = sunsmax / F; /* distance to Sun in km */
X SunAng = F * sunangsiz; /* Sun's angular size in degrees */
X
X
X /* Calculation of the Moon's position. */
X
X /* Moon's mean longitude. */
X ml = fixangle(13.1763966 * Day + mmlong);
X
X /* Moon's mean anomaly. */
X MM = fixangle(ml - 0.1114041 * Day - mmlongp);
X
X /* Moon's ascending node mean longitude. */
X MN = fixangle(mlnode - 0.0529539 * Day);
X
X /* Evection. */
X Ev = 1.2739 * sin(torad(2 * (ml - Lambdasun) - MM));
X
X /* Annual equation. */
X Ae = 0.1858 * sin(torad(M));
X
X /* Correction term. */
X A3 = 0.37 * sin(torad(M));
X
X /* Corrected anomaly. */
X MmP = MM + Ev - Ae - A3;
X
X /* Correction for the equation of the centre. */
X mEc = 6.2886 * sin(torad(MmP));
X
X /* Another correction term. */
X A4 = 0.214 * sin(torad(2 * MmP));
X
X /* Corrected longitude. */
X lP = ml + Ev + mEc - Ae + A4;
X
X /* Variation. */
X V = 0.6583 * sin(torad(2 * (lP - Lambdasun)));
X
X /* True longitude. */
X lPP = lP + V;
X
X /* Corrected longitude of the node. */
X NP = MN - 0.16 * sin(torad(M));
X
X /* Y inclination coordinate. */
X y = sin(torad(lPP - NP)) * cos(torad(minc));
X
X /* X inclination coordinate. */
X x = cos(torad(lPP - NP));
X
X /* Ecliptic longitude. */
X Lambdamoon = todeg(atan2(y, x));
X Lambdamoon += NP;
X
X /* Ecliptic latitude. */
X BetaM = todeg(asin(sin(torad(lPP - NP)) * sin(torad(minc))));
X
X /* Calculation of the phase of the Moon. */
X
X /* Age of the Moon in degrees. */
X MoonAge = lPP - Lambdasun;
X
X /* Phase of the Moon. */
X MoonPhase = (1 - cos(torad(MoonAge))) / 2;
X
X /* Calculate distance of moon from the centre of the Earth. */
X
X MoonDist = (msmax * (1 - mecc * mecc)) /
X (1 + mecc * cos(torad(MmP + mEc)));
X
X /* Calculate Moon's angular diameter. */
X
X MoonDFrac = MoonDist / msmax;
X MoonAng = mangsiz / MoonDFrac;
X
X /* Calculate Moon's parallax. */
X
X MoonPar = mparallax / MoonDFrac;
X
X *pphase = MoonPhase;
X *mage = synmonth * (fixangle(MoonAge) / 360.0);
X *dist = MoonDist;
X *angdia = MoonAng;
X *sudist = SunDist;
X *suangdia = SunAng;
X return torad(fixangle(MoonAge));
X}
SHAR_EOF
if test 13787 -ne "`wc -c < 'phase.c'`"
then
echo shar: error transmitting "'phase.c'" '(should have been 13787 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'dtime.c'" '(2403 characters)'
if test -f 'dtime.c'
then
echo shar: will not over-write existing file "'dtime.c'"
else
sed 's/^X//' << \SHAR_EOF > 'dtime.c'
X#ifndef lint
Xstatic char rcsid[] =
X "@(#) $Header: dtime.c,v 1.3 88/08/26 22:29:38 jef Exp $ (LBL)";
X#endif
X
X/*
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/
X
X/* dtime.c - extracted from the phoon/libtws package
X*/
X
X
X#include "tws.h"
X#include <stdio.h>
X#include <sys/types.h>
X#include <time.h>
X#ifdef SYS5
Xextern int daylight;
Xextern long timezone;
Xextern char *tzname[];
X#else SYS5
X#include <sys/timeb.h>
X#endif SYS5
X
Xstatic struct zone
X {
X char *std;
X char *dst;
X int shift;
X }
X zones[] = {
X "GMT", "BST", 0,
X "EST", "EDT", -5,
X "CST", "CDT", -6,
X "MST", NULL, -7,
X "PST", "PDT", -8,
X "A", NULL, -1,
X "B", NULL, -2,
X "C", NULL, -3,
X "D", NULL, -4,
X "E", NULL, -5,
X "F", NULL, -6,
X "G", NULL, -7,
X "H", NULL, -8,
X "I", NULL, -9,
X "K", NULL, -10,
X "L", NULL, -11,
X "M", NULL, -12,
X "N", NULL, 1,
X#ifndef HUJI
X "O", NULL, 2,
X#else HUJI
X "JST", "JDT", 2,
X#endif HUJI
X "P", NULL, 3,
X "Q", NULL, 4,
X "R", NULL, 5,
X "S", NULL, 6,
X "T", NULL, 7,
X "U", NULL, 8,
X "V", NULL, 9,
X "W", NULL, 10,
X "X", NULL, 11,
X "Y", NULL, 12,
X NULL };
X
Xlong time( );
Xstruct tm *localtime( );
X
X
Xstruct tws *
Xdtwstime( )
X {
X long clock;
X
X (void) time( &clock );
X return ( dlocaltime( &clock ) );
X }
X
X
Xstruct tws *
Xdlocaltime( clock )
Xlong *clock;
X {
X register struct tm *tm;
X#ifndef SYS5
X struct timeb tb;
X#endif not SYS5
X static struct tws tw;
X
X if ( clock == NULL )
X return ( NULL );
X tw.tw_flags = TW_NULL;
X
X tm = localtime( clock );
X tw.tw_sec = tm -> tm_sec;
X tw.tw_min = tm -> tm_min;
X tw.tw_hour = tm -> tm_hour;
X tw.tw_mday = tm -> tm_mday;
X tw.tw_mon = tm -> tm_mon;
X tw.tw_year = tm -> tm_year;
X tw.tw_wday = tm -> tm_wday;
X tw.tw_yday = tm -> tm_yday;
X if ( tm -> tm_isdst )
X tw.tw_flags |= TW_DST;
X#ifndef SYS5
X ftime( &tb );
X tw.tw_zone = -tb.timezone;
X#else SYS5
X tzset( );
X tw.tw_zone = -(timezone / 60);
X#endif SYS5
X tw.tw_flags &= ~TW_SDAY;
X tw.tw_flags |= TW_SEXP;
X tw.tw_clock = *clock;
X
X return ( &tw );
X }
SHAR_EOF
if test 2403 -ne "`wc -c < 'dtime.c'`"
then
echo shar: error transmitting "'dtime.c'" '(should have been 2403 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'tws.h'" '(2290 characters)'
if test -f 'tws.h'
then
echo shar: will not over-write existing file "'tws.h'"
else
sed 's/^X//' << \SHAR_EOF > 'tws.h'
X/* tws.h - header file for libtws date/time library */
X
X
X/* Definition of the tws data structure. */
X
Xstruct tws {
X int tw_sec;
X int tw_min;
X int tw_hour;
X
X int tw_mday;
X int tw_mon;
X int tw_year;
X
X int tw_wday;
X int tw_yday;
X
X int tw_zone;
X
X long tw_clock;
X
X int tw_flags;
X#define TW_NULL 0x0000
X#define TW_SDAY 0x0007 /* how day-of-week was determined */
X#define TW_SNIL 0x0000 /* not given */
X#define TW_SEXP 0x0001 /* explicitly given */
X#define TW_SIMP 0x0002 /* implicitly given */
X#define TW_DST 0x0010 /* daylight savings time */
X#define TW_ZONE 0x0020 /* use numeric timezones only */
X#define TW_JUNK 0x0040 /* date string contained junk */
X};
X
X
X/* Declarations of routines. */
X
Xvoid twscopy( );
X /* twscopy( &totws, &fromtws ) copies a tws */
Xint twsort( );
X /* twsort( &tws1, &tws2 ) compares two tws's: 1 means tws1 is
X later; -1 means tws1 is earlier; 0 means they are equal */
Xlong twclock( );
X /* twclock( &tws ) turns a tws into a time(3)-style clock value */
Xlong twjuliandate( );
X /* twjuliandate( &tws ) returns the Julian day number of a tws */
Xlong twsubtract( );
X /* twsubtract( &tws1, &tws2 ) returns seconds of difference */
X
X/* These routines are functionally similar to the ctime(3) routines
X in the standard Unix library. */
Xchar *dctime( );
X /* dctime( &tws ) returns a string for the date/time passed in */
Xstruct tws *dlocaltime( );
X /* dlocaltime( &clock ) turns a time(3) clock value into a tws */
Xstruct tws *dgmtime( );
X /* dgmtime( &clock ) turns a time(3) clock value into a tws */
Xchar *dasctime( );
X /* dasctime( &tws, flags ) turns a tws into a string */
Xchar *dtimezone( );
X /* dtimezone( offset, flags ) returns the name of the time zone */
X
Xchar *dtimenow( );
X /* dtimenow( ) returns a string for the current date/time */
X
Xstruct tws *dparsetime( );
X /* dparsetime( &str ) turns a string into a tws */
X
Xstruct tws *dtwstime( );
X /* dtwstime( ) returns a tws for the current date/time */
X
X#ifdef ATZ
X#define dtime(cl) dasctime( dlocaltime( cl ), TW_NULL )
X#else ATZ
X#define dtime(cl) dasctime( dlocaltime( cl ), TW_ZONE )
X#endif ATZ
X
X#define dtwszone(tw) dtimezone( tw -> tw_zone, tw -> tw_flags )
X
X
Xextern char *tw_dotw[], *tw_ldotw[], *tw_moty[];
SHAR_EOF
if test 2290 -ne "`wc -c < 'tws.h'`"
then
echo shar: error transmitting "'tws.h'" '(should have been 2290 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
--
Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330
More information about the Comp.sources.x
mailing list