mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) (05/28/89)
Submitted-by: Bill Randle <billr@saab.cna.tek.com> Posting-number: Volume 1, Issue 14 Archive-name: calentool/part05 #! /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: # init.c # month.h # month2ct.c # moon.c # moony.icon # This archive created: Sat May 27 13:12:27 1989 export PATH; PATH=/bin:$PATH echo shar: extracting "'init.c'" '(16366 characters)' if test -f 'init.c' then echo shar: will not over-write existing file "'init.c'" else sed 's/^ X//' << \SHAR_EOF > 'init.c' X/* X * $Header: init.c,v 2.1 89/05/09 14:23:19 billr Exp $ X */ X/* X * init.c X * X * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com> X * X * Original source Copyright (C) 1987, Sun Microsystems, Inc. X * All Rights Reserved X * Permission is hereby granted to use and modify this program in source X * or binary form as long as it is not sold for profit and this copyright X * notice remains intact. X * X * X * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM> X * X * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc. X * All Rights Reserved X * Permission is hereby granted to use and modify the modifications in source X * or binary form as long as they are not sold for profit and this copyright X * notice remains intact. X */ X X/*************************************************** X * * X * Initialization routines, for memory pixrects * X * and files. * X * * X ***************************************************/ X X X#include <stdio.h> X#include <suntool/sunview.h> X#include <suntool/menu.h> X#include <sunwindow/defaults.h> X#include <sys/file.h> X#include <pwd.h> X#include "ct.h" X X Xextern int dayslot_width, dayslot_height; Xextern int weekslot_width, weekslot_height; Xextern int ybox_width, ybox_height; Xextern Pixrect *daybox_pr, *timeslot_pr, *gray_pr; Xextern Pixrect *weekslot_pr, *weekarrow_pr, *smallarrow_pr; Xextern Pixrect *arrowshaft_pr, *arrowhead_pr; Xextern Pixrect *weekarrowshaft_pr, *weekarrowhead_pr; Xextern Pixrect *triangle_pr; Xextern Pixrect *ydaybox_pr, *ymonthbox_pr; Xextern Frame frame; Xextern Frame prompt_frame; Xextern int otherfile, mailto, one_based, read_only, version2; Xextern char *othername; Xextern char version[]; XPixrect *daybox_td_pr, *weekslot_td_pr, *weekarrowshaft_td_pr; XPixrect *weekarrowhead_td_pr, *ydaybox_td_pr, *timeslot_td_pr; XPixrect *leftarrow, *rightarrow; Xchar t_title[160]; Xchar apts_pathname[160], tmpapts_pathname[160]; Xchar apts_dir[128], lib_dir[128]; Xchar printer[64]; X Xstruct passwd *getpwnam(); X Xinit_pixrects() X{ X init_daybox_pr(); X init_timeslot_pr(); X init_weekslot_pr(); X init_weekarrow_pr(); X init_arrow_prs(); X init_triangle_pr(); X init_ydaybox_pr(); X init_ymonthbox_pr(); X} X X/* Concentric squares for drawing days of month calendar. */ Xinit_daybox_pr() X{ X Pixrect *pattern; X int i; X X daybox_pr = mem_create(64,64,1); X pr_vector(daybox_pr,0,0,63,0,PIX_SET,1); X pr_vector(daybox_pr,63,0,63,63,PIX_SET,1); X pr_vector(daybox_pr,63,63,0,63,PIX_SET,1); X pr_vector(daybox_pr,0,63,0,0,PIX_SET,1); X pr_vector(daybox_pr,2,2,61,2,PIX_SET,1); X pr_vector(daybox_pr,61,2,61,61,PIX_SET,1); X pr_vector(daybox_pr,61,61,2,61,PIX_SET,1); X pr_vector(daybox_pr,2,61,2,2,PIX_SET,1); X pattern = mem_create(64,2,1); X for (i=3; i<60; i+=8) X pr_put(pattern, i, 0, 1); X for (i=7; i<60; i+=8) X pr_put(pattern, i, 1, 1); X daybox_td_pr = mem_create(64,64,1); X pr_vector(daybox_td_pr,0,0,63,0,PIX_SET,1); X pr_vector(daybox_td_pr,63,0,63,63,PIX_SET,1); X pr_vector(daybox_td_pr,63,63,0,63,PIX_SET,1); X pr_vector(daybox_td_pr,0,63,0,0,PIX_SET,1); X pr_vector(daybox_td_pr,2,2,61,2,PIX_SET,1); X pr_vector(daybox_td_pr,61,2,61,61,PIX_SET,1); X pr_vector(daybox_td_pr,61,61,2,61,PIX_SET,1); X pr_vector(daybox_td_pr,2,61,2,2,PIX_SET,1); X pr_replrop(daybox_td_pr, 0, 2, 60, 60, PIX_SRC|PIX_DST, pattern, 0, 0); X pr_destroy(pattern); X X} X X/* Box for 30-minute slot in picture of day. */ Xinit_timeslot_pr() X{ X int i; X Pixrect *pattern; X X timeslot_pr = mem_create(dayslot_width, dayslot_height, 1); X timeslot_td_pr = mem_create(dayslot_width, dayslot_height, 1); X pattern = mem_create(dayslot_width, 2, 1); X for (i=1; i<dayslot_width; i+=8) X pr_put(pattern, i, 0, 1); X for (i=5; i<dayslot_width; i+=8) X pr_put(pattern, i, 1, 1); X pr_vector(timeslot_pr,0,0,0,dayslot_height-1,PIX_SET,1); X pr_vector(timeslot_pr,dayslot_width-1,0, X dayslot_width-1,dayslot_height-1,PIX_SET,1); X pr_vector(timeslot_td_pr,0,0,0,dayslot_height-1,PIX_SET,1); X pr_vector(timeslot_td_pr,dayslot_width-1,0, X dayslot_width-1,dayslot_height-1,PIX_SET,1); X for (i=0; i<dayslot_width-1; i=i+2) { X pr_put(timeslot_pr, i, 0, 1); X pr_put(timeslot_pr, i, dayslot_height-1, 1); X pr_put(timeslot_td_pr, i, 0, 1); X pr_put(timeslot_td_pr, i, dayslot_height-1, 1); X } X pr_replrop(timeslot_td_pr, 1, 2, dayslot_width-1, dayslot_height-3, PIX_SRC|PIX_DST, pattern, 0, 0); X pr_destroy(pattern); X} X X X/* Box for 30-minute slot in picture of week. */ Xinit_weekslot_pr() X{ X int i; X Pixrect *pattern; X X weekslot_pr = mem_create(weekslot_width,weekslot_height,1); X weekslot_td_pr = mem_create(weekslot_width,weekslot_height,1); X pattern = mem_create(weekslot_width, 2, 1); X for (i=1; i<weekslot_width; i+=8) X pr_put(pattern, i, 0, 1); X for (i=5; i<weekslot_width; i+=8) X pr_put(pattern, i, 1, 1); X pr_vector(weekslot_pr,0,0,0,weekslot_width-1,PIX_SET,1); X pr_vector(weekslot_pr,weekslot_width-1,0,weekslot_width-1,weekslot_height-1,PIX_SET,1); X pr_vector(weekslot_td_pr,0,0,0,weekslot_height-1,PIX_SET,1); X pr_vector(weekslot_td_pr,weekslot_width-1,0,weekslot_width-1,weekslot_height-1,PIX_SET,1); X for (i=0; i<weekslot_width-1; i=i+2) { X pr_put(weekslot_pr,i,0,1); X pr_put(weekslot_pr,i,weekslot_height-1,1); X pr_put(weekslot_td_pr,i,0,1); X pr_put(weekslot_td_pr,i,weekslot_height-1,1); X } X pr_replrop(weekslot_td_pr, 1, 2, weekslot_width-1, weekslot_height-3, PIX_SRC|PIX_DST, pattern, 0, 0); X pr_destroy(pattern); X} X X/* Arrow pointing to a week in picture of month. */ Xinit_weekarrow_pr() X{ X int i; X X weekarrow_pr = mem_create(42,29,1); X pr_vector(weekarrow_pr,0,0,27,0,PIX_SET,1); X pr_vector(weekarrow_pr,27,0,41,14,PIX_SET,1); X pr_vector(weekarrow_pr,41,14,27,28,PIX_SET,1); X pr_vector(weekarrow_pr,27,28,0,28,PIX_SET,1); X pr_vector(weekarrow_pr,0,28,0,0,PIX_SET,1); X pr_vector(weekarrow_pr,2,2,26,2,PIX_SET,1); X pr_vector(weekarrow_pr,26,2,38,14,PIX_SET,1); X pr_vector(weekarrow_pr,38,14,26,26,PIX_SET,1); X pr_vector(weekarrow_pr,26,26,2,26,PIX_SET,1); X pr_vector(weekarrow_pr,2,26,2,2,PIX_SET,1); X smallarrow_pr = mem_create(42,29,1); X pr_rop(smallarrow_pr, 3, 3, 25, 23, PIX_SET, 0, 0, 0); X for (i=0; i<14; i++) { X pr_vector(smallarrow_pr, 27, i+3, 27+i, i+3, PIX_SET,1); X pr_vector(smallarrow_pr, 27, 25-i, 27+i, 25-i, PIX_SET,1); X } X} X X Xinit_arrow_prs() X{ X int lmid, rmid; X X arrowshaft_pr = mem_create(dayslot_width-2, dayslot_height-2, 1); X arrowhead_pr = mem_create(dayslot_width-2, dayslot_height-2, 1); X weekarrowshaft_pr = mem_create(weekslot_width-2, weekslot_height-2, 1); X weekarrowhead_pr = mem_create(weekslot_width-2, weekslot_height-2, 1); X X lmid = (dayslot_width-2) / 2; X rmid = lmid + 1; X pr_vector(arrowshaft_pr, lmid-4, 0, lmid-4, dayslot_height-3, PIX_SET, 1); X pr_vector(arrowshaft_pr, lmid-3, 0, lmid-3, dayslot_height-3, PIX_SET, 1); X pr_vector(arrowshaft_pr, rmid+3, 0, rmid+3, dayslot_height-3, PIX_SET, 1); X pr_vector(arrowshaft_pr, rmid+4, 0, rmid+4, dayslot_height-3, PIX_SET, 1); X X pr_vector(arrowhead_pr, lmid, dayslot_height-3, lmid-7, dayslot_height-10, X PIX_SET, 1); X pr_vector(arrowhead_pr, lmid, dayslot_height-4, lmid-7, dayslot_height-11, X PIX_SET, 1); X pr_vector(arrowhead_pr, rmid, dayslot_height-3, rmid+7, dayslot_height-10, X PIX_SET, 1); X pr_vector(arrowhead_pr, rmid, dayslot_height-4, rmid+7, dayslot_height-11, X PIX_SET, 1); X pr_vector(arrowhead_pr, lmid-4, dayslot_height-8, lmid-4, 0, PIX_SET, 1); X pr_vector(arrowhead_pr, lmid-3, dayslot_height-7, lmid-3, 0, PIX_SET, 1); X pr_vector(arrowhead_pr, rmid+3, dayslot_height-7, rmid+3, 0, PIX_SET, 1); X pr_vector(arrowhead_pr, rmid+4, dayslot_height-8, rmid+4, 0, PIX_SET, 1); X X lmid = (weekslot_width-2) / 2; X rmid = lmid + 1; X X pr_vector(weekarrowshaft_pr, lmid-4, 0, lmid-4, weekslot_height-3, PIX_SET, 1); X pr_vector(weekarrowshaft_pr, lmid-3, 0, lmid-3, weekslot_height-3, PIX_SET, 1); X pr_vector(weekarrowshaft_pr, rmid+3, 0, rmid+3, weekslot_height-3, PIX_SET, 1); X pr_vector(weekarrowshaft_pr, rmid+4, 0, rmid+4, weekslot_height-3, PIX_SET, 1); X X pr_vector(weekarrowhead_pr, lmid, weekslot_height-3, lmid-7, weekslot_height-10, X PIX_SET, 1); X pr_vector(weekarrowhead_pr, lmid, weekslot_height-4, lmid-7, weekslot_height-11, X PIX_SET, 1); X pr_vector(weekarrowhead_pr, rmid, weekslot_height-3, rmid+7, weekslot_height-10, X PIX_SET, 1); X pr_vector(weekarrowhead_pr, rmid, weekslot_height-4, rmid+7, weekslot_height-11, X PIX_SET, 1); X pr_vector(weekarrowhead_pr, lmid-4, weekslot_height-8, lmid-4, 0, PIX_SET, 1); X pr_vector(weekarrowhead_pr, lmid-3, weekslot_height-7, lmid-3, 0, PIX_SET, 1); X pr_vector(weekarrowhead_pr, rmid+3, weekslot_height-7, rmid+3, 0, PIX_SET, 1); X pr_vector(weekarrowhead_pr, rmid+4, weekslot_height-8, rmid+4, 0, PIX_SET, 1); X X leftarrow = mem_create(19, 14, 1); X rightarrow = mem_create(19, 14, 1); X pr_vector(leftarrow, 3, 5, 16, 5, PIX_SET, 1); X pr_vector(leftarrow, 2, 6, 16, 6, PIX_SET, 1); X pr_vector(leftarrow, 3, 7, 16, 7, PIX_SET, 1); X pr_vector(leftarrow, 4, 4, 4, 8, PIX_SET, 1); X pr_vector(leftarrow, 5, 3, 5, 9, PIX_SET, 1); X pr_vector(leftarrow, 6, 2, 6, 10, PIX_SET, 1); X pr_vector(leftarrow, 0, 0, 18, 0, PIX_SET, 1); X pr_vector(leftarrow, 18, 0, 18, 13, PIX_SET, 1); X pr_vector(leftarrow, 18, 13, 0, 13, PIX_SET, 1); X pr_vector(leftarrow, 0, 13, 0, 0, PIX_SET, 1); X X pr_vector(rightarrow, 2, 5, 15, 5, PIX_SET, 1); X pr_vector(rightarrow, 2, 6, 16, 6, PIX_SET, 1); X pr_vector(rightarrow, 2, 7, 15, 7, PIX_SET, 1); X pr_vector(rightarrow, 14, 4, 14, 8, PIX_SET, 1); X pr_vector(rightarrow, 13, 3, 13, 9, PIX_SET, 1); X pr_vector(rightarrow, 12, 2, 12, 10, PIX_SET, 1); X pr_vector(rightarrow, 0, 0, 18, 0, PIX_SET, 1); X pr_vector(rightarrow, 18, 0, 18, 13, PIX_SET, 1); X pr_vector(rightarrow, 18, 13, 0, 13, PIX_SET, 1); X pr_vector(rightarrow, 0, 13, 0, 0, PIX_SET, 1); X} X X Xinit_triangle_pr() X{ X int i; X X triangle_pr = mem_create(32, 32, 1); X for (i=0; i<32; i++) X pr_vector(triangle_pr, i, i, 31, i, PIX_SET, 1); X} X X/* squares for drawing days of month on the year calendar */ Xinit_ydaybox_pr() X{ X Pixrect *pattern; X int i; X X ydaybox_pr = mem_create(ybox_width,ybox_height,1); X pr_vector(ydaybox_pr,0,0,ybox_width-1,0,PIX_SET,1); X pr_vector(ydaybox_pr,ybox_width-1,0,ybox_width-1,ybox_height-1,PIX_SET,1); X pr_vector(ydaybox_pr,ybox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1); X pr_vector(ydaybox_pr,0,ybox_height-1,0,0,PIX_SET,1); X pattern = mem_create(ybox_width,2,1); X for (i=1; i<ybox_width; i+=4) X pr_put(pattern, i, 0, 1); X for (i=3; i<ybox_width; i+=4) X pr_put(pattern, i, 1, 1); X ydaybox_td_pr = mem_create(ybox_width,ybox_height,1); X pr_vector(ydaybox_td_pr,0,0,ybox_width-1,0,PIX_SET,1); X pr_vector(ydaybox_td_pr,ybox_width-1,0,ybox_width-1,ybox_height-1,PIX_SET,1); X pr_vector(ydaybox_td_pr,ybox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1); X pr_vector(ydaybox_td_pr,0,ybox_height-1,0,0,PIX_SET,1); X pr_replrop(ydaybox_td_pr, 1, 1, ybox_width-3, ybox_height-2, PIX_SRC|PIX_DST, pattern, 0, 0); X pr_destroy(pattern); X} X X/* label box for each month on the year calendar */ Xinit_ymonthbox_pr() X{ X int ymbox_width; X X ymbox_width = 7 * ybox_width; X ymonthbox_pr = mem_create(ymbox_width,ybox_height,1); X pr_vector(ymonthbox_pr,0,0,ymbox_width-1,0,PIX_SET,1); X pr_vector(ymonthbox_pr,ymbox_width-1,0,ymbox_width-1,ybox_height-1,PIX_SET,1); X pr_vector(ymonthbox_pr,ymbox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1); X pr_vector(ymonthbox_pr,0,ybox_height-1,0,0,PIX_SET,1); X pr_vector(ymonthbox_pr,0,1,ymbox_width-1,1,PIX_SET,1); X} X Xdo_files(window_prompt) Xint window_prompt; X{ X char *strcpy(), *rindex(), *getenv(); X char *slash, *default_ptr, *envptr; X char buff[80]; X int to_slash, getpid(), fd, errflag; X struct passwd *pw; X FILE *appts; X X /* the tmp file */ X sprintf(tmpapts_pathname, "/tmp/appts%d", getpid()); X if (otherfile) { X strcpy(apts_pathname, othername); X if ((slash = rindex(apts_pathname, '/')) != NULL) { X to_slash = slash - apts_pathname; X strncpy(apts_dir, apts_pathname, to_slash); X apts_dir[to_slash] = '\0'; X } else { X strcpy(apts_dir, "."); X } X } else { X if ((default_ptr = defaults_get_string("/CalenTool/Appts", NULL, 0)) != NULL) { X if ((slash = rindex(default_ptr, '/')) != NULL) { X to_slash = slash - default_ptr; X strncpy(apts_dir, default_ptr, to_slash); X apts_dir[to_slash] = '\0'; X } else { X strcpy(apts_dir, "."); X } X } else if ((envptr = getenv("CALENTOOL_DIR")) != NULL) { X strcpy(apts_dir, envptr); X } else if (mailto) { X if ((pw = getpwnam(mailto)) == NULL) X /* no entry */ X exit(1); X envptr = pw->pw_dir; /* home directory */ X strcpy(apts_dir, envptr); X } else if ((envptr = getenv("HOME")) != NULL) { X strcpy(apts_dir, envptr); X } else { X apts_dir[0] = '\0'; X } X if (*apts_dir) { X /* prepend directory on pathnames */ X sprintf(apts_pathname, "%s/.appointments", apts_dir); X } else { X /* use current directory */ X strcpy(apts_pathname, ".appointments"); X } X } X X /* directory for date/event data files */ X if ((default_ptr = defaults_get_string("/CalenTool/LibDir", NULL, 0)) != NULL) X strcpy(lib_dir, default_ptr); X else X strcpy(lib_dir, DATELIB_DIR); X X errflag = 0; X if (access(apts_pathname, R_OK) == -1) { X if (window_prompt) { X fprintf(stderr, "nonexistant file\n"); X sprintf(buff, "Cannot access calendar file %s - create?", apts_pathname); X create_prompt_frame(buff, TRUE); X if ((int)window_loop(prompt_frame) == 0) { X /* try to create the file */ X fprintf(stderr, "creating file\n"); X if ((fd=open(apts_pathname, O_CREAT|O_RDWR, 0664)) <= 0) { X perror(apts_pathname); X errflag = 1; X fprintf(stderr, "..error\n"); X } else { X if (write(fd, HEADER, sizeof(HEADER)) != sizeof(HEADER)) { X perror("writing header"); X errflag = 1; X } X close(fd); X fprintf(stderr, "..wrote header\n"); X one_based = 1; X } X } else { X fprintf(stderr, "window_ret != 0\n"); X errflag = 1; X } X window_set(prompt_frame, WIN_SHOW, FALSE, 0); X if (errflag) X return(1); X } else { X fprintf(stderr, "Cannot access calendar file %s - create? ", apts_pathname); X fgets(buff, 80, stdin); X if (buff[0] == 'y' || buff[0] == 'Y') { X if ((fd=open(apts_pathname, O_CREAT|O_RDWR, 0664)) <= 0) { X perror(apts_pathname); X return(1); X } else { X if (write(fd, HEADER, sizeof(HEADER)) != sizeof(HEADER)) { X perror("writing header"); X close(fd); X return(1); X } X close(fd); X one_based = 1; X } X } else X return(1); X } X } X if (access(apts_pathname, W_OK) == -1) X read_only = 1; X X /* update base frame label, if the tool is running */ X if (frame) { X strcpy(t_title, version); X if (read_only) X strcat(t_title, " [Read Only]"); X strcat(t_title, " - "); X strcat(t_title, apts_pathname); X window_set(frame, FRAME_LABEL, t_title, 0); X } X X /* check first line of appts file to see if it is the new style */ X if ((appts = fopen(apts_pathname, "r")) != NULL) { X fgets(buff, 80, appts); X if (!strcmp(buff, HEADER)) { X version2 = 1; X one_based = 1; X } X fclose(appts); X } X X /* Convert from old format to new. There may some appts files X * that are one-based, but are still old style. These are X * also handled. (Note: for old-style one-based appts files X * the user MUST start calentool with the -z flag.) X */ X if (!version2) X ver1to2(); X X return(0); X} X X/* X * get/set printer variable to correspond to the command to print X * a raster or Postscript file X */ Xget_printer() X{ X#ifndef NO_PRINTER X char *ptr, *getenv(); X X strcpy(printer, "lpr -P"); X if ((ptr = defaults_get_string("/CalenTool/Printer", NULL, 0)) != NULL) X strcat(printer, ptr); X else if ((ptr = getenv("PRINTER")) != NULL) X strcat(printer, ptr); X else X strcpy(printer, PRINT_CMD); X#endif X} SHAR_EOF if test 16366 -ne "`wc -c < 'init.c'`" then echo shar: error transmitting "'init.c'" '(should have been 16366 characters)' fi fi # end of overwriting check echo shar: extracting "'month.h'" '(2119 characters)' if test -f 'month.h' then echo shar: will not over-write existing file "'month.h'" else sed 's/^ X//' << \SHAR_EOF > 'month.h' X/* X * @(#)$ month.h,v 8.4 88/04/04 10:46:35 hull Exp $ X */ X/* X * truncated from the original to only include what I need X * and appended month8.h onto the end. X * X * Bill Randle 2/22/89 X */ X X#define MAX_EVENT_STRING_LENGTH 70 /* maximum length of an event string */ X X#define READ_WRITE 0 /* open .month with read/write access */ X#define READ_ONLY 1 /* open .month with read-only access */ X Xextern char *malloc(); X X/* structure of an area */ Xstruct area_rec { X short area; X short row; X short col; X}; X X/* structure of a date */ Xstruct date_rec { X short month; X short day; X short year; X}; X X/* structure of a time */ Xstruct time_rec { X short hour; X short minute; X}; X X/* structure of an event pointer */ Xstruct eptr_rec { X struct event_rec *event; /* event */ X struct eptr_rec *prev_event; /* previous event */ X struct eptr_rec *next_event; /* next event */ X}; X X/* structure of a name */ Xstruct name_rec { X char *name; /* name */ X struct name_rec *next_name /* next name */ X}; X X/* X * @(#) month8.h,v 8.0 87/11/13 22:50:14 hull Exp X */ X X/* structure of an event */ Xstruct event_rec { X struct date_rec start_date; /* starting date of the event */ X char monthly; /* does event occur monthly? */ X char yearly; /* does event occur yearly? */ X char every; /* does event occur on every something? */ X char smtwtfs[7]; /* which days of the week are relevant? */ X char nth; /* does event occur on an nth something? */ X char last; /* does event occur on a last something? */ X char nth_is_on; /* is 'nth' selected by user, n is nth above */ X struct time_rec start_time; /* starting time of the event */ X struct time_rec duration; /* duration of the event */ X struct time_rec warning; /* warning of the event */ X struct time_rec end_time; /* ending time of the event */ X char event_string[MAX_EVENT_STRING_LENGTH]; /* description of event */ X char private; /* is event private? */ X char anti; /* is this an anti-event? */ X int event_owner; /* owner of event */ X char until; /* does event occur until some date? */ X struct date_rec until_date; /* date event goes until */ X struct event_rec *next_event; /* next event */ X}; SHAR_EOF if test 2119 -ne "`wc -c < 'month.h'`" then echo shar: error transmitting "'month.h'" '(should have been 2119 characters)' fi fi # end of overwriting check echo shar: extracting "'month2ct.c'" '(3017 characters)' if test -f 'month2ct.c' then echo shar: will not over-write existing file "'month2ct.c'" else sed 's/^ X//' << \SHAR_EOF > 'month2ct.c' X/* X * $Header: month2ct.c,v 2.1 89/05/09 14:19:14 billr Exp $ X */ X/* X * month2ct - convert month schedule files to calentool style files X * X * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM> X * X * Copyright (C) 1989 Tektronix, Inc. All Rights Reserved X * X * Permission is hereby granted to use and modify this code in source X * or binary form as long as it is not sold for profit and this copyright X * notice remains intact. X */ X X#include "month.h" X#include "ct.h" X#include <stdio.h> X Xstruct appt_entry appt; Xstruct event_rec events; XFILE *fp; Xchar filename[128]; Xchar *dir, *getenv(); X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X if (argc > 1) X dir = argv[1]; X else { X strcpy(filename, getenv("HOME")); X dir = filename; X } X X if (read_schedule(dir, READ_ONLY)) { X fprintf(stderr, "no reminders read from %s/.month\n", dir); X exit(1); X } X strcpy(filename, getenv("HOME")); X strcat(filename, "/.appointments"); X if ((fp = fopen(filename, "w")) == NULL) { X fprintf(stderr, "can't open .appointments file for writing\n"); X exit(1); X } X write_ct_file(); X} X X/* X * write out the new .appointments file X */ Xwrite_ct_file() X{ X struct event_rec *evt; X int length, oflags, i; X X evt = &events; X fputs(HEADER, fp); X /* first event is empty */ X evt = evt->next_event; X while (evt) { X fprintf(stderr,"evt struct:\n mly=%d, yly=%d, evry=%d\n nth=%d, last=%d, nthon=%d\n str=%s\n", X evt->monthly, evt->yearly, evt->every, evt->nth, evt->last, evt->nth_is_on, evt->event_string); X appt.flags = appt.repeat = appt.lookahead = 0; X appt.year = evt->start_date.year - 1900; X appt.month = evt->start_date.month - 1; X appt.day = evt->start_date.day; X strcpy(appt.str, evt->event_string); X if (evt->monthly) X appt.flags |= ALL_MONTHS; X if (evt->yearly) X appt.flags |= ALL_YEARS; X appt.hour = evt->start_time.hour; X appt.minute = evt->start_time.minute; X if (appt.hour > 23 || appt.hour < 0 || appt.minute > 59 || appt.minute < 0) X appt.flags |= A_NOTE; X if (appt.minute < 15) X appt.minute = 0; X else if (appt.minute < 45) X appt.minute = 30; X else { X appt.minute = 0; X appt.hour++; X } X length = evt->duration.hour * 60 + evt->duration.minute; X appt.arrows = length / 30 - 1; X if (appt.arrows < 0) X appt.arrows = 0; X if (evt->anti) X appt.flags |= DELETED; X if (evt->warning.hour >= 24) X appt.lookahead = evt->warning.hour / 24; X if (evt->every) { X /* event occurs on an every something */ X appt.flags |= REPEAT; X if (evt->last) X appt.repeat = LAST_WEEK; X else if (evt->nth_is_on) X appt.repeat = 1<<(evt->nth_is_on-1); X else X appt.repeat = ALL_WEEKS; X oflags = appt.flags; X for (i=0; i<7; i++) { X if (evt->smtwtfs[i]) { X appt.flags = oflags | Setday(i); X if (put_aentry(fp, &appt)) { X fprintf(stderr, "error writing .appointments file\n"); X return; X } X } X } X } else X if (put_aentry(fp, &appt)) { X fprintf(stderr, "error writing .appointments file\n"); X return; X } X fputs("\n", fp); X evt = evt->next_event; X } X} SHAR_EOF if test 3017 -ne "`wc -c < 'month2ct.c'`" then echo shar: error transmitting "'month2ct.c'" '(should have been 3017 characters)' fi fi # end of overwriting check echo shar: extracting "'moon.c'" '(23444 characters)' if test -f 'moon.c' then echo shar: will not over-write existing file "'moon.c'" else sed 's/^ X//' << \SHAR_EOF > 'moon.c' X/* X * $Header: moon.c,v 2.1 89/05/09 14:19:22 billr Exp $ X */ X/* X * moon.c X * X * Compute various interesting data about the moon. Based on the X * moontool program by John Walker (see below), and modified by X * Bill Randle, Tektronix, Inc. to interface to the calentool X * program. X */ X#include "ct.h" /* for the NO_SUN_MOON #define */ X#ifndef NO_SUN_MOON X X/* X X A Moon for the Sun X X Release 2.0 X X Designed and implemented by John Walker in December 1987, X revised and updated in February of 1988. X X cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect X X Adding appropriate floating point options to your hardware. This X program is a SunView tool which displays, as the icon for a closed X window, the current phase of the Moon. A subtitle in the icon gives X the age of the Moon in days and hours. If called with the "-t" X switch, it rapidly increments forward through time to display the X cycle of phases. X X If you open the window, additional information is displayed regarding X the Moon. The information is generally accurate to within ten X minutes. X X The algorithms used in this program to calculate the positions Sun and X Moon as seen from the Earth are given in the book "Practical Astronomy X With Your Calculator" by Peter Duffett-Smith, Second Edition, X Cambridge University Press, 1981. Ignore the word "Calculator" in the X title; this is an essential reference if you're interested in X developing software which calculates planetary positions, orbits, X eclipses, and the like. If you're interested in pursuing such X programming, you should also obtain: X X "Astronomical Formulae for Calculators" by Jean Meeus, Third Edition, X Willmann-Bell, 1985. A must-have. X X "Planetary Programs and Tables from -4000 to +2800" by Pierre X Bretagnon and Jean-Louis Simon, Willmann-Bell, 1986. If you want the X utmost (outside of JPL) accuracy for the planets, it's here. X X "Celestial BASIC" by Eric Burgess, Revised Edition, Sybex, 1985. Very X cookbook oriented, and many of the algorithms are hard to dig out of X the turgid BASIC code, but you'll probably want it anyway. X X Many of these references can be obtained from Willmann-Bell, P.O. Box X 35025, Richmond, VA 23235, USA. Phone: (804) 320-7016. In addition X to their own publications, they stock most of the standard references X for mathematical and positional astronomy. X X This program was written by: X X John Walker X Autodesk, Inc. X 2320 Marinship Way X Sausalito, CA 94965 X (415) 332-2344 Ext. 829 X X Usenet: {sun!well}!acad!kelvin X X This program is in the public domain: "Do what thou wilt shall be the X whole of the law". I'd appreciate receiving any bug fixes and/or X enhancements, which I'll incorporate in future versions of the X program. Please leave the original attribution information intact so X that credit and blame may be properly apportioned. X X*/ X X/* Astronomical constants */ X X#define epoch 2444238.5 /* 1980 January 0.0 */ X#define J1970 2440587.5 /* VAX clock Epoch 1970 Jan 1 (0h UT) */ 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#include <stdio.h> X#include <math.h> X#include <sys/time.h> X X#include <suntool/sunview.h> X#include <suntool/canvas.h> X X/* Icon definition. This is just a black field with rounded corners X that blend into the root desktop pattern. The image of the moon and X the text are added by the program later. */ X Xstatic short moon_img[64][4] = { X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 */ X 0x8FFF,0xFFFF,0xFFFF,0xFFE8,0x9FFF,0xFFFF,0xFFFF,0xFFF8, X 0x3FFF,0xFFFF,0xFFFF,0xFFFE,0x7FFF,0xFFFF,0xFFFF,0xFFFE, X 0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x7FFF,0xFFFF,0xFFFF,0xFFFE, X 0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xBFFF,0xFFFF,0xFFFF,0xFFFC, X 0x3FFF,0xFFFF,0xFFFF,0xFFFA,0x27FF,0xFFFF,0xFFFF,0xFFE2 X}; XDEFINE_ICON_FROM_IMAGE(moon_icon, moon_img); Xmpr_static(icon_mpr, 64, 64, 1, moon_img); X Xextern Canvas mcanvas; Xextern Pixfont *font; Xextern char *monthnames[]; Xstatic Pixwin *cpw; Xstatic int charhgt, charwid; 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/* Forward functions */ X Xdouble jtime(), phase(); Xvoid phasehunt(); Xvoid drawmoon(), jyear(), jhms(); X X X/* DRAWMOON -- Construct icon for moon, given phase of moon. */ X Xstatic void drawmoon(ph) Xdouble ph; X{ X int i, j, lx, rx; X int lb[4]; X double cp, xscale; X X xscale = cos(2 * PI * ph); X for (i = 0; i < 24; i++) { X lb[0] = lb[1] = lb[2] = lb[3] = 0xFFFF; X cp = 24.0 * cos(asin(i / 24.0)); X if (ph < 0.5) { X rx = 32 + cp; X lx = 32 + xscale * cp; X } else { X lx = 33 - cp; X rx = 33 - xscale * cp; X } X for (j = lx; j <= rx; j++) { X lb[j >> 4] &= (0x8000 >> (j & 0xF)) ^ 0xFFFF; X } X for (j = 0; j < 4; j++) X moon_img[28 + i][j] = moon_img[28 - i][j] = lb[j]; X } X} X X/* MOON_DATA -- print useful info about the moon */ X Xmoon_data(seconds) Xlong seconds; X{ X int lunation, wclosed; X long t; X double jd, p, aom, cphase, cdist, cangdia, csund, csuang, lptime; X double phasar[5]; X struct pr_prpos tloc; X char amsg[12], tbuf[80]; X static double faketime = 0.0; X static short moonilast[64][4] = {0}; X int yy, mm, dd, hh, mmm, ss; X Pixfont *pfont; X struct tm *gm, *ltm, *localtime(); X struct timeval tvp; X struct timezone tzp; X long clock; X char *atp, *asctime(); X X X pfont = pf_open("/usr/lib/fonts/fixedwidthfonts/screen.r.7"); X cpw = canvas_pixwin(mcanvas); X charwid = font->pf_defaultsize.x; X charhgt = font->pf_defaultsize.y; X jd = jtime((gm = gmtime(&seconds))); X gettimeofday(&tvp, &tzp); /* for timezone info */ X p = phase(jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang); X drawmoon(p); X sprintf(amsg, " %dd %dh ", X (int) aom, ((int) (24 * (aom - floor(aom))))); X tloc.pr = (Pixrect *) icon_get(&moon_icon, ICON_IMAGE); X tloc.pos.x = 2; X tloc.pos.y = 62; X pf_text(tloc, PIX_NOT(PIX_SRC), pfont, amsg); X X /* Only update icon if it changed (this eliminates gratuitous X flashing of the icon on-screen). */ X X if (bcmp(moonilast, moon_img, sizeof moon_img) != 0) X bcopy(moon_img, moonilast, sizeof moon_img); X X /* Update textual information for open window */ X X#define prt(x) pw_text(cpw, charwid, charhgt * (x), PIX_SRC, font, tbuf) X#define prtxy(x,y) pw_text(cpw,charwid*(y+1),charhgt*(x),PIX_SRC,font,tbuf) X X sprintf(tbuf, "Moon phase: %d%% [0%% = New, 100%% = Full] ", X (int) (cphase * 100)); X prt(1); X X /* Information about the Moon */ X X#define EPL(x) (x), (x) == 1 ? "" : "s" X sprintf(tbuf, X "Age of moon: %d day%s, %d hour%s, %d minute%s. ", X EPL((int) aom), EPL(((int) (24 * (aom - floor(aom))))), X EPL(((int) (1440 * (aom - floor(aom)))) % 60)); X prt(2); X sprintf(tbuf, X "Moon's distance: %ld kilometres, %.1f Earth radii. ", X (long) cdist, cdist / earthrad); X prt(3); X sprintf(tbuf, X "Moon subtends: %.4f degrees. ", cangdia); X prt(4); X /* Draw the moon icon in the text window */ X pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, X &icon_mpr, 0, 0); X X X /* Calculate times of phases of this lunation. */ X X#define APOS(x) (x + 11) X phasehunt(jd, phasar); X lptime = phasar[0]; X lunation = floor(((lptime + 7) - lunatbase) / synmonth) + 1; X /* convert to seconds local time, so we can use localtime() X to handle dst calculations */ X clock = (long)((lptime - J1970) * 24. * 3600.); X ltm = localtime(&clock); X sprintf(tbuf, X "Last new moon: %02d:%02d %s %2d %s %d ", X ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900); X prt(APOS(0)); X sprintf(tbuf, "Lunation %d ", lunation); X prtxy(APOS(0), 52); X X lptime = phasar[1]; X /* convert to seconds local time, so we can use localtime() X to handle dst calculations */ X clock = (long)((lptime - J1970) * 24. * 3600.); X ltm = localtime(&clock); X sprintf(tbuf, X "First quarter: %02d:%02d %s %2d %s %d ", X ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900); X prt(APOS(1)); X X lptime = phasar[2]; X /* convert to seconds local time, so we can use localtime() X to handle dst calculations */ X clock = (long)((lptime - J1970) * 24. * 3600.); X ltm = localtime(&clock); X sprintf(tbuf, X "Full moon: %02d:%02d %s %2d %s %d ", X ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900); X prt(APOS(2)); X X lptime = phasar[3]; X /* convert to seconds local time, so we can use localtime() X to handle dst calculations */ X clock = (long)((lptime - J1970) * 24. * 3600.); X ltm = localtime(&clock); X sprintf(tbuf, X "Last quarter: %02d:%02d %s %2d %s %d ", X ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900); X prt(APOS(3)); X X lptime = phasar[4]; X /* convert to seconds local time, so we can use localtime() X to handle dst calculations */ X clock = (long)rint((lptime - J1970) * 24. * 3600.); X ltm = localtime(&clock); X sprintf(tbuf, X "Next new moon: %02d:%02d %s %2d %s %d ", X ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900); X prt(APOS(4)); X sprintf(tbuf, "Lunation %d ", lunation + 1); X prtxy(APOS(4), 52); X#undef APOS X} X X/* JDATE -- Convert internal GMT date and time to Julian day X and fraction. */ X Xstatic long jdate(t) Xstruct tm *t; X{ X long c, m, y; X X y = t->tm_year + 1900; X m = t->tm_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->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 + X (m * 153L + 2) / 5 + 1721119L; X} X X/* JTIME -- Convert internal GMT date and time to astronomical Julian X time (i.e. Julian date plus day fraction, expressed as X a double). */ X Xstatic double jtime(t) Xstruct tm *t; X{ X return (jdate(t) - 0.5) + X (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0; X} X X/* JYEAR -- Convert Julian date to year, month, day, which are X returned via integer pointers to integers. */ 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 X base date 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 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 X mean phase of the new moon, and a phase X selector (0.0, 0.25, 0.5, 0.75), obtain X the true, corrected phase time. */ X Xstatic double truephase(k, phase) Xdouble k, phase; X{ X double t, t2, t3, pt, m, mprime, f; X int apcor = FALSE; 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 = TRUE; 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 = TRUE; X } X if (!apcor) { X fprintf(stderr, "TRUEPHASE called with invalid phase selector.\n"); X abort(); X } X return pt; X} X X/* PHASEHUNT -- Find time of phases of the moon which surround X the current date. Five phases are found, starting X and ending with the new moons which bound the X current lunation. */ X Xstatic void phasehunt(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 while (TRUE) { 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/* 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*/ X Xstatic double 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 fixangle(MoonAge) / 360.0; X} X#endif /* NO_SUN_MOON */ SHAR_EOF if test 23444 -ne "`wc -c < 'moon.c'`" then echo shar: error transmitting "'moon.c'" '(should have been 23444 characters)' fi fi # end of overwriting check echo shar: extracting "'moony.icon'" '(2593 characters)' if test -f 'moony.icon' then echo shar: will not over-write existing file "'moony.icon'" else sed 's/^ X//' << \SHAR_EOF > 'moony.icon' X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 X * X * $Header: moony.icon,v 2.1 89/05/09 14:30:43 billr Exp $ X * Copyright (C) 1989, The Regents of the University of California X * All rights Reserved X * Author: R. P. C. Rodgers, M.D. X * X * Redistribution and use in source and binary forms are permitted X * provided that this notice is preserved and that due credit is given X * to the University of California at San Francisco. The name of the University X * may not be used to endorse or promote products derived from this X * software without specific prior written permission. This software X * is provided ``as is'' without express or implied warranty. X */ X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, X 0xFFBF,0xFFFF,0xFFFF,0x7FFF,0xFF1F,0xDFF0,0x07FF,0xFFFF, X 0xFFBF,0xDF00,0x007F,0xFFDF,0xFFFF,0xFC00,0x001F,0xFFFF, X 0xFFFF,0xF000,0x0007,0xF7FF,0xF7FF,0xE000,0x0003,0xF7FF, X 0xE3CF,0x8000,0x0000,0xFFFF,0xF7FF,0x0000,0x0000,0x7FF7, X 0xFFFE,0x0000,0x0000,0x3FE3,0xFFFC,0x0000,0x0000,0x1FF7, X 0xFFF8,0x0000,0x0000,0x0FFF,0xFFF8,0x0000,0x0000,0x0FFF, X 0xFFF0,0x0000,0x0000,0x07FF,0xDFE0,0x0000,0x0000,0x03FF, X 0xDFE0,0x0080,0x0080,0x03FF,0xFFC0,0x0040,0x0100,0x01FF, X 0xFFC0,0x00A0,0x0280,0x01FF,0xFF80,0x0051,0x4500,0x00FF, X 0xFF80,0x00AA,0xAA80,0x00FF,0xFF80,0x0055,0x5500,0x00FF, X 0xFF80,0x002A,0xAA00,0x00E7,0xFF00,0x0015,0x5400,0x007F, X 0xFF00,0x002A,0xA8C0,0x007F,0xEF00,0x03D5,0x5700,0x007F, X 0xC700,0x00EA,0xABC0,0x007F,0xEF00,0x0315,0x5400,0x007F, X 0xFF00,0x002A,0xAB00,0x007F,0xFF00,0x0045,0x50C0,0x007F, X 0xFF00,0x000A,0xA800,0x007F,0xFF00,0x0005,0x5000,0x007F, X 0xFF80,0x000A,0xA800,0x00FF,0xFF80,0x0015,0x5400,0x00FF, X 0xFF80,0x000A,0xA800,0x00FF,0xFF80,0x0015,0x5400,0x00DF, X 0xFFC0,0x002A,0xAA00,0x018F,0xFBC0,0x0055,0x5500,0x01DF, X 0xFFE0,0x002A,0xAA00,0x03FF,0xFFE0,0x0055,0x5500,0x03FF, X 0xFFF0,0x00AA,0xAA80,0x07F7,0xFFF8,0x0055,0x5500,0x0FFF, X 0xFFF8,0x00AA,0xAA80,0x0FFF,0xFDFC,0x0155,0x5544,0x1FFF, X 0xFFBE,0x00AA,0xAA82,0x3FFF,0xFF1F,0x0155,0x5545,0x7FFF, X 0xFFBF,0x80AA,0xAA82,0xFBFF,0xEFFF,0xE055,0x5503,0x7FFF, X 0xEFFF,0xF0AA,0xAA86,0xFFCF,0xFFFF,0xFC55,0x551D,0x7FFF, X 0xFFFF,0xFF2A,0xAA7E,0xFFFF,0xFFFF,0xFFD5,0x55FD,0x7FFF, X 0xEAAB,0xFFFA,0xAFEA,0xAFFF,0xF557,0xD555,0x5FF5,0x57FF, X 0xEAAB,0xEAAF,0xABEA,0xAFAB,0xF557,0xD557,0x57D5,0x5757, X 0xEAAB,0xEAAF,0xAAAA,0xAFAB,0x5555,0x5555,0x5555,0x5555, X 0xAAAA,0xAAAA,0xAAAA,0xAAAA,0x5555,0x5555,0x5555,0x5555, X 0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xF557,0xD557,0x57F5,0x5757, X 0xEAAB,0xEAAF,0xABEA,0xAFAB,0xF557,0xD557,0x57F5,0x5757 SHAR_EOF if test 2593 -ne "`wc -c < 'moony.icon'`" then echo shar: error transmitting "'moony.icon'" '(should have been 2593 characters)' fi fi # end of overwriting check # End of shell archive exit 0