rem *---------------------------------------------*
rem *		JULIAN DATE SUBROUTINE		  *
rem *		----------------------		  *
rem *	WRITTEN: Edward A. Valenzuela		  *
rem *	   DATE: January 10, 1983		  *
rem *   VERSION: 1.30			  	  *
rem *---------------------------------------------*

def fn.juldate$(date$)

rem *** function takes a date in month/day/year format  ***
rem *** and returns a character string year.julian date ***

rem ......decompose the character string into three integers......
rem ......isolate the month......
rem ......find the character position for the first slash......

nc%  = len(date$)
sl1% = match("/",date$,1)
mo$  = left$(date$,sl1%-1)
month% = val(mo$)

rem .....isolate the year.....
rem .....find the character position for the second slash......

sl2% = match("/",date$,sl1%+1)
yr$ = right$(date$,nc%-sl2%)
year% = val(yr$)

rem .....now isolate the day.....

if (sl1%+1) <= 0 then dy$ = "0" else \
dy$ = mid$(date$,sl1%+1,sl2%-sl1%-1)
day% = val(dy$)

rem ......now convert the three integers to julian date......

restore
data 0,3,3,6,8,11,13,16,19,21,24,26

for ki% = 1 to month%
  read d30%
next ki%

d30% = d30% + int%(year%/4) + 1 + (month%-1)*28 + day%

rem ... example 1/5/1 = 0 + 0 + 1 + 0 + 5 = 6
if int%(year%/4) = year%/4 and month% < 3 then d30% = d30% - 1

rem ... thus 1/5/1 = 6-1 = 5
 
fn.juldate$ = str$(year%) + "." + str$(d30%)
return

fend

def fn.juldate%(date$)

jdate$  = fn.juldate$(date$)

nc%  = len(jdate$)
sl1% = match(".",jdate$,1)
yr$  = left$(jdate$,sl1%-1)
year% = val(yr$)

jd$ = right$(jdate$,nc%-sl1%)
 jd% = val(jd$)

fn.juldate% = jd% + year%*365 
rem ......example 1/5/1 = 5 + 365 = 370

RETURN
FEND

rem *----------- END julian date SUBROUTINE -------*
