From:	CSBVAX::MRGATE!@KL.SRI.Com:info-vax-request@kl.sri.com@SMTP  8-AUG-1987 12:01
To:	EVERHART
Subj:	Re: Calculating Elapsed Time From DCL.

Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri 7 Aug 87 07:44:35-PDT
Received: by ucbvax.Berkeley.EDU (5.58/1.27)
	id AA08181; Fri, 7 Aug 87 07:38:04 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 7 Aug 87 06:15:16 GMT
From: uunet!munnari!murdu!u3369429@seismo.css.gov  (Michael Bednarek)
Organization: I.A.E.S.R., Melbourne University
Subject: Re: Calculating Elapsed Time From DCL.
Message-Id: <1286@murdu.OZ>
References: <870805075119.03q@VLSI.JPL.NASA.GOV>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <870805075119.03q@VLSI.JPL.NASA.GOV> xrjjm%scint.span@VLSI.JPL.NASA.GOV writes:
> [Things about F$CVTIME]
>I have a routine that wants to calculate a date 2 months back.  I take
>an Absolute time as input, Convert it to Comparison, perform a calculation
>(Month - 2)... then what ?  How do I convert it back to absolute ?  (In DCL).
>I have considered using Delta times (Subtract 60 days or something similar)
>but that doesn't fit my bill for accuracy.  I ruled out a HLL because this was 
>supposed to be a Quick and Dirty job...

Well, this might not be the precise answer to your problems, but as I didn't
feel much like doing something productive this morning, I translated two
subroutines which deal with dates from Fortran to DCL.

One, JULIAN, takes a Gregorian date (dd-MON-yyyy) and returns a) the Julian
daynumber within that year, b) a Julian day number since 1-Jan-0001.
These day numbers can then be used to perform some calculations.

Its sister (brother ?) routine, GREGOR, takes b) from JULIAN and returns
a Gregorian date.

Now, anybody interested in a routine which calculates the date of easter
(a la D. Knuth) for any year?

........................ Cut between dotted lines and save ......................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-4.03 05-Aug-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by U3369429 (Michael Bednarek)
$!      on Friday 7-AUG-1987 15:50:09.27
$!
$! It contains the following 1 file:
$! JULGREG.COM
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
		", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
	VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set (Output_File,b,o);
Position (Beginning_of(b));Loop x:=Erase_Character(1); Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;Move_Horizontal
(-Current_Offset);EndLoop;Move_Vertical(1);ExitIf Mark(None)=End_of(b)
EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="JULGREG.COM"
$ Check_Sum_is=1148729702
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ Verify='F$Verify(0)
X$! Playing around with Julian and Gregorian dates
X$ Facility_Name=	"JULGREG"
X$ Facility_Version=	"V-1.00 07-Aug-1987"
X$!
X$!Michael Bednarek		u3369429@{murdu.oz.au | ucsvc.dn.mu.oz.au}
X$!Institute of Applied Economic	-- or --
X$!  and Social Research (IAESR)	...{UUNET.UU.NET | seismo.CSS.GOV}!munnari!
X$!Melbourne University		   {murdu.oz | ucsvc.dn.mu.oz}!u3369429
X$!Parkville 3052, Phone : +61 3 344 5744
X$!AUSTRALIA
X$!
X$! Copyright (c) 1987, by Michael Bednarek
X$! The distribution of this file is unrestricted as long as this notice
X$! remains intact.
X$!
X$! Usage: @JULGREG Date1 Date2
X$!
X$ Say="Write SYS$Output"
X$ Ask="Inquire/NoPunctuation"
X$ Say Facility_Name," ",Facility_Version
X$ Say ""
X$!
X$ On Warning then Exit
X$ If P1.eqs."" then Ask P1 "Enter Date 1: "
X$ P1=F$CVTime(P1,"Absolute")
X$ If P2.eqs."" then Ask P2 "Enter Date 2: "
X$ P2=F$CVTime(P2,"Absolute")
X$ Call Julian "''P1'" YJDay1 AJDay1
X$ Call Julian "''P2'" YJDay2 AJDay2
X$ Say F$FAO("The difference is !SL day!%S",AJDay2-AJDay1)
X$! Testing Gregor:
X$ Call Gregor 'AJDay1 Date1
X$ Call Gregor 'AJDay2 Date2
X$ Say "GREGOR returns: ",Date1," and ",Date2
X$ Exit
X$Julian: Subroutine
X$ On Warning then Exit
X$! Converts Gregorian Date into Julian Day
X$! This is a straight translation from an old Fortran routine of mine.
X$ M2=" 0,31,59,90,120,151,181,212,243,273,304,334"
X$! Input:
X$! P1 = Date in absolute format as returned from F$CVTIME
X$!
X$! Output:
X$! P2 = YJDay = Julian Day in this year
X$! P3 = AJDay = Julian Day since 1-Jan-0001 A.D
X$!              (can be used as input to GREGOR)
X$!
X$ Year =F$Integer(F$CVTime(P1,,"Year"))
X$ Month=F$Integer(F$CVTime(P1,,"Month"))
X$ Day  =F$Integer(F$CVTime(P1,,"Day"))
X$!
X$! detect leap year
X$ Leap=Year-Year/400*400.eq.0 .or. -
X       Year-Year/100*100.ne.0 .and. Year-Year/4*4.eq.0
X$!
X$! Calculate this year's Julian Day
X$ 'P2==F$Integer(F$Element(Month-1,",",M2))+Day
X$ If Month.gt.2 .and. Leap then 'P2=='P2+1
X$!
X$! Calculate the Absolute Julian Day
X$ Year=Year-1
X$ 'P3==Year*365+Year/4-Year/100+Year/400+'P2
X$ EndSubroutine
X$Gregor: Subroutine
X$ On Warning then Exit
X$! Converts Julian Day into Gregorian Date
X$! Although this routine is not required in this context, I thought I'd
X$! include it anyway.
X$! Input:
X$! P1 = AJDay = Julian Day since 1-Jan-0001 A.D. (as obtained from JULIAN)
X$!
X$! Output:
X$! P2 = Date in absolute  format (dd-MON-yyyy)
X$ M1=" 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31"
X$ M3="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
X$!
X$ i=P1
X$ im=i/146097
X$ Year=im*400
X$ i=i-im*146097
X$!
X$ im=i/36524
X$ Year=Year+im*100
X$ i=i-im*36524
X$!
X$ im=i/1461
X$ Year=Year+im*4
X$ i=i-im*1461
X$!
X$ im=(i+364)/365-1
X$ Year=Year+im
X$!
X$ YJDay=P1-Year*365-Year/4+Year/100-Year/400
X$ Year=Year+1
X$!
X$ Leap=Year-Year/400*400.eq.0 .or. -
X       Year-Year/100*100.ne.0 .and. Year-Year/4*4.eq.0
X$!
X$ If Leap .and. YJDay.gt.59 then M1[5,2]:="29"
X$ n1=0
X$ Month=0
X$Loop:
X$ Month=Month+1
X$ n2=n1
X$ n1=n1+F$Integer(F$Element(Month-1,",",M1))
X$ If YJDay.le.n1 then goto Done
X$ If Month.lt.12 then goto Loop
X$Done:
X$ Day=YJDay-n2
X$ Month=F$Element(Month-1,",",M3)
X$ 'P2==F$CVTime("''Day'-''Month'-''Year'","Absolute","Date")
X$ EndSubroutine
$ GoSub Convert_File
$ Exit
