mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-20 19:04:49 +00:00
Initial revision
git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
9
pom/Makefile.bsd
Normal file
9
pom/Makefile.bsd
Normal file
@@ -0,0 +1,9 @@
|
||||
# $NetBSD: Makefile,v 1.4 1995/03/23 08:35:33 cgd Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= pom
|
||||
MAN= pom.6
|
||||
DPADD= ${LIBM}
|
||||
LDADD= -lm
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
13
pom/Makefrag
Normal file
13
pom/Makefrag
Normal file
@@ -0,0 +1,13 @@
|
||||
# Makefrag - makefile fragment for pom
|
||||
|
||||
pom_DIRS := $(GAMESDIR) $(MAN6DIR)
|
||||
|
||||
pom_all: pom/pom pom/pom.6
|
||||
|
||||
pom_install: pom_all
|
||||
$(INSTALL_BINARY) pom/pom $(INSTALL_PREFIX)$(GAMESDIR)/pom
|
||||
$(HIDE_GAME) pom
|
||||
$(INSTALL_MANUAL) pom/pom.6
|
||||
|
||||
pom_check: pom_all
|
||||
pom/pom
|
||||
61
pom/pom.6
Normal file
61
pom/pom.6
Normal file
@@ -0,0 +1,61 @@
|
||||
.\" $NetBSD: pom.6,v 1.6 1998/06/13 01:09:22 jeremy Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)pom.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.Dd May 31, 1993
|
||||
.Dt POM 6
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm pom
|
||||
.Nd display the phase of the moon
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar secs
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility displays the current phase of the moon.
|
||||
Useful for selecting software completion target dates and predicting
|
||||
managerial behavior.
|
||||
.Pp
|
||||
.Bl -tag -width secs
|
||||
.It Ar secs
|
||||
Display the phase of the moon for the date represented by
|
||||
.Ar secs
|
||||
seconds past the Epoch
|
||||
(Midnight, January 1, 1970 GMT).
|
||||
If
|
||||
.Ar secs
|
||||
is unspecified, the current time is used.
|
||||
.El
|
||||
204
pom/pom.c
Normal file
204
pom/pom.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/* $NetBSD: pom.c,v 1.11 1998/09/11 14:07:04 hubertf Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software posted to USENET.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pom.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: pom.c,v 1.11 1998/09/11 14:07:04 hubertf Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Phase of the Moon. Calculates the current phase of the moon.
|
||||
* Based on routines from `Practical Astronomy with Your Calculator',
|
||||
* by Duffett-Smith. Comments give the section from the book that
|
||||
* particular piece of code was adapted from.
|
||||
*
|
||||
* -- Keith E. Brandt VIII 1984
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <tzfile.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
#endif
|
||||
#define EPOCH 85 /* really 1985 */
|
||||
#define EPSILONg 279.611371 /* solar ecliptic long at EPOCH */
|
||||
#define RHOg 282.680403 /* solar ecliptic long of perigee at EPOCH */
|
||||
#define ECCEN 0.01671542 /* solar orbit eccentricity */
|
||||
#define lzero 18.251907 /* lunar mean long at EPOCH */
|
||||
#define Pzero 192.917585 /* lunar mean long of perigee at EPOCH */
|
||||
#define Nzero 55.204723 /* lunar mean long of node at EPOCH */
|
||||
|
||||
void adj360 __P((double *));
|
||||
double dtor __P((double));
|
||||
int main __P((int, char *[]));
|
||||
double potm __P((double));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
struct tm *GMT;
|
||||
time_t tmpt;
|
||||
double days, today, tomorrow;
|
||||
int cnt;
|
||||
|
||||
/* Revoke setgid privileges */
|
||||
setregid(getgid(), getgid());
|
||||
|
||||
if (argc > 1) {
|
||||
tp.tv_sec = atoi(argv[1]);
|
||||
tp.tv_usec = 0;
|
||||
} else {
|
||||
if (gettimeofday(&tp,&tzp))
|
||||
err(1, "gettimeofday");
|
||||
}
|
||||
tmpt = tp.tv_sec;
|
||||
GMT = gmtime(&tmpt);
|
||||
days = (GMT->tm_yday + 1) + ((GMT->tm_hour +
|
||||
(GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0);
|
||||
for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
|
||||
days += isleap(cnt + 1900) ? 366 : 365;
|
||||
today = potm(days) + .5;
|
||||
(void)printf("The Moon is ");
|
||||
if ((int)today == 100)
|
||||
(void)printf("Full\n");
|
||||
else if (!(int)today)
|
||||
(void)printf("New\n");
|
||||
else {
|
||||
tomorrow = potm(days + 1);
|
||||
if ((int)today == 50)
|
||||
(void)printf("%s\n", tomorrow > today ?
|
||||
"at the First Quarter" : "at the Last Quarter");
|
||||
else {
|
||||
(void)printf("%s ", tomorrow > today ?
|
||||
"Waxing" : "Waning");
|
||||
if (today > 50)
|
||||
(void)printf("Gibbous (%1.0f%% of Full)\n",
|
||||
today);
|
||||
else if (today < 50)
|
||||
(void)printf("Crescent (%1.0f%% of Full)\n",
|
||||
today);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* potm --
|
||||
* return phase of the moon
|
||||
*/
|
||||
double
|
||||
potm(days)
|
||||
double days;
|
||||
{
|
||||
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
|
||||
double A4, lprime, V, ldprime, D, Nm;
|
||||
|
||||
N = 360 * days / 365.2422; /* sec 42 #3 */
|
||||
adj360(&N);
|
||||
Msol = N + EPSILONg - RHOg; /* sec 42 #4 */
|
||||
adj360(&Msol);
|
||||
Ec = 360 / PI * ECCEN * sin(dtor(Msol)); /* sec 42 #5 */
|
||||
LambdaSol = N + Ec + EPSILONg; /* sec 42 #6 */
|
||||
adj360(&LambdaSol);
|
||||
l = 13.1763966 * days + lzero; /* sec 61 #4 */
|
||||
adj360(&l);
|
||||
Mm = l - (0.1114041 * days) - Pzero; /* sec 61 #5 */
|
||||
adj360(&Mm);
|
||||
Nm = Nzero - (0.0529539 * days); /* sec 61 #6 */
|
||||
adj360(&Nm);
|
||||
Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 61 #7 */
|
||||
Ac = 0.1858 * sin(dtor(Msol)); /* sec 61 #8 */
|
||||
A3 = 0.37 * sin(dtor(Msol));
|
||||
Mmprime = Mm + Ev - Ac - A3; /* sec 61 #9 */
|
||||
Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 61 #10 */
|
||||
A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 61 #11 */
|
||||
lprime = l + Ev + Ec - Ac + A4; /* sec 61 #12 */
|
||||
V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 61 #13 */
|
||||
ldprime = lprime + V; /* sec 61 #14 */
|
||||
D = ldprime - LambdaSol; /* sec 63 #2 */
|
||||
return(50 * (1 - cos(dtor(D)))); /* sec 63 #3 */
|
||||
}
|
||||
|
||||
/*
|
||||
* dtor --
|
||||
* convert degrees to radians
|
||||
*/
|
||||
double
|
||||
dtor(deg)
|
||||
double deg;
|
||||
{
|
||||
return(deg * PI / 180);
|
||||
}
|
||||
|
||||
/*
|
||||
* adj360 --
|
||||
* adjust value so 0 <= deg <= 360
|
||||
*/
|
||||
void
|
||||
adj360(deg)
|
||||
double *deg;
|
||||
{
|
||||
for (;;)
|
||||
if (*deg < 0)
|
||||
*deg += 360;
|
||||
else if (*deg > 360)
|
||||
*deg -= 360;
|
||||
else
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user