Category : C Source Code
Archive   : JULIDATE.ZIP
Filename : DOYMJD.C

 
Output of file : DOYMJD.C contained in archive : JULIDATE.ZIP
/* Program DOYMJD year month day :19870819winkler */
#include

long julday(i,j,k)
long i, j, k;
{
long j1, j2, j3;
j1 = 1461l*(i + 4800l + (j - 14l)/12l)/4l;
j2 = 367l*(j - 2l -(j - 14l)/12l*12l)/12l;
j3 = 3l*((i + 4900l + (j - 14l)/12l)/100l)/4l;
return(k - 32075l + j1 + j2 - j3);
}

main(argc, argv) /* This program will convert the date given on
the command line to the full MJD.
The algorithm is based on the Fliegel/van Flandern
paper in COMM of the ACM 11/#10 p.657 Oct. 1968
It is valid for any GREGORIAN date producing a
positive JD. The MJD is defined as JD - 2400000.5
because the JD begins at noon and the MJD at the
preceding midnight. Without regard to this, by
taking the plain date, this will make the MJD
appear to be 1 day less than the corresponding JD.
*/
int argc;
char **argv;
{
int c = 0;
int i, m, doy, wkd;
long p2, p3, p4, day, month, year, mjd;
char **p, name[25];
static char *messg[] = {
"This program will take your command line input and convert\n",
"the year, month and day integers to the MJD.\n",
"You may also have no command line input and then you will be \n",
"prompted for the date specification.\n",
"The MJD given starts at midnight UT. In contrast to this, \n",
"because the Julian day begins at noon, the JD may appear to be one\n",
"day too large compared with the MJD. However, MJD = JD - 2400000.5\n",
"Furthermore, the calendar assumed is the\n",
"GREGORIAN calendar for all dates with a +JD.\n",
"Please be aware that the order in the command line is year month day\n",
"Improper input!\n",
"Program terminated."
};
static int count[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
static char *week[] = {
"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
};
static char *mnth[] = {
"January","February","March","April","May","June","July","August",
"September","October","November","December"};
p2 = p3 = p4 = 0;
year = month = day = 0l;

if (argc > 1){
for (p=argv; argc > 0; argc--,p++){
++c;
if (c == 2){
strcpy(name,*p);
if(name[0]== '?') {
for(i=0;i<=8;i++) printf("%s",messg[i]);
exit(1);
}
else
p2 = atoi(*p);
}
if (c ==3){
p3 = atoi(*p);
}
if (c==4) {
p4 = atoi(*p);
}
}
year = p2;
month = p3;
day = p4;
}
else {
printf("Enter day, month, year: (in digits)\n");
printf(" xx xx xxxx (and return)\n");
printf(" ");
scanf ("%d%d%d",&day,&month,&year);
}
p4 = julday(year,month,day);
mjd = p4 - 2400001;
printf("\nMJD: %ld\n",mjd);
doy = 0;
m = month - 1;
for(wkd = 0;wkd doy += day;
if(year%4 == 0 && m >1 ) doy++;
wkd = (p4 + 1)%7;
printf("\nThe date is: %ld %ld %ld (%s)\n",year,month,day,mnth[m]);
printf("That is expressed as year/doy: %ld %d (%s)\n",year,doy,week[wkd]);

exit (0);
}



  3 Responses to “Category : C Source Code
Archive   : JULIDATE.ZIP
Filename : DOYMJD.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/