	SUBROUTINE COMPDATE(comp_date,days,dates,pas_time)
	IMPLICIT INTEGER(A-Z)
	INTEGER*4 bin_date(2), del_date(2), colon_pos, end_pos, beg_pos
	INTEGER*4 str$position,str$append,str$trim, run_lth
	INTEGER*4 idate(3), add_date(2), iopt, last_day, week_day, icode
	INTEGER*4 pas_hour, pas_minute, sys_hour, sys_minute
	CHARACTER char_date*11, comp_date*17, pas_time*7, sys_time*5
	CHARACTER space*1, hold_date*17, hold_time*7
	LOGICAL days(7), dates(31), found, after, delta_time

	DATA space /' '/
	delta_time = .false.
C
C	Get current date, time, and last day of the month.
C

	idate(1) = 0
	bin_date(1) = 0
	iopt     = 1
	CALL CVDATE(idate,bin_date,char_date,iopt)
	iopt     = 3
	CALL CVDATE(idate,bin_date,char_date,iopt)
	CALL ENDDATE(bin_date,last_day)
	CALL TIME(sys_time)

C
C	Check to see if a delta date/time has been requested.
C
	if((comp_date(1:1).NE.space).OR.(delta_time)) then

C
C	Check for delta date and no delta time.
C

	if((comp_date(1:1).NE.space).AND.(.NOT.delta_time)) then
	icode = SYS$BINTIM(comp_date,add_date)
	icode = LIB$SUBX(bin_date,add_date,del_date)
	icode = SYS$ASCTIM(,char_date,del_date,)
	if (pas_time(1:1).EQ.space) pas_time = sys_time
	colon_pos = str$position(pas_time(1:LEN(pas_time)),':')
	end_pos = str$position(pas_time(1:LEN(pas_time)),space)
	  if (colon_pos.EQ.0) then
	    if(end_pos.EQ.2) end_pos = 1
	    if(end_pos.EQ.3) end_pos = 2
	  pas_time = pas_time(1:end_pos) // ':00'
	  end if !Colon check in pas_time.
	  comp_date = char_date // space // pas_time
	goto 500
	end if  !+ date, no + time

C
C	Check for delta date and delta time.
C

	if((comp_date(1:1).NE.space).AND.(delta_time)) then

	colon_pos = str$position(pas_time(1:LEN(pas_time)),':')
	end_pos = str$position(pas_time(1:LEN(pas_time)),space)
	  if (colon_pos.EQ.0) then
	   if(end_pos.EQ.2) end_pos = 1
	   if(end_pos.EQ.3) end_pos = 2
	   if(end_pos.EQ.4) end_pos = 3
	   if(end_pos.EQ.5) end_pos = 4
	  pas_time = pas_time(1:end_pos) // ':00'
	  end if !Colon check.

	end_pos = str$position(comp_date(1:LEN(comp_date)),space)
	comp_date = comp_date(1:end_pos) // pas_time
	end_pos = str$position(comp_date(1:LEN(comp_date)),':')
	end_pos = end_pos + 2
	icode = SYS$BINTIM(comp_date(1:end_pos),add_date)
	icode = SYS$ASCTIM(,hold_date,,)
	icode = SYS$BINTIM(hold_date,bin_date)
	icode = LIB$SUBX(bin_date,add_date,del_date)
	icode = SYS$ASCTIM(,comp_date,del_date,)
	goto 500
	end if  !+ date, and + time

C
C	Check for no delta date and delta time.
C

	if((comp_date(1:1).EQ.space).AND.(delta_time)) then
	colon_pos = str$position(pas_time(1:LEN(pas_time)),':')
	end_pos = str$position(pas_time(1:LEN(pas_time)),space)
	end_pos = end_pos - 1
	if(end_pos.LE.0) end_pos = 2
	if(colon_pos.EQ.0) then
	read(pas_time(1:end_pos),100,err=999) pas_hour
	pas_minute = 0
	pas_time = '0 ' // pas_time(1:end_pos) // ':00'
	else
	read(pas_time(1:colon_pos-1),100,err=999) pas_hour
	read(pas_time(colon_pos+1:colon_pos+2),100,err=999) pas_minute
	pas_time = '0 ' // pas_time(1:end_pos)
	end if !Colon check.
	icode = SYS$BINTIM(pas_time,add_date)
	icode = SYS$ASCTIM(,hold_date,,)
	icode = SYS$BINTIM(hold_date,bin_date)
	icode = LIB$SUBX(bin_date,add_date,del_date)
	icode = SYS$ASCTIM(,comp_date,del_date,)
	icode = SYS$BINTIM(comp_date,bin_date)
	colon_pos = str$position(comp_date(1:LEN(comp_date)),':')
	beg_pos = colon_pos - 2
	end_pos = colon_pos + 2
	pas_time = comp_date(beg_pos:end_pos)
	idate(1) = 0
	iopt     = 1
	CALL CVDATE(idate,bin_date,char_date,iopt)

	colon_pos = str$position(sys_time(1:LEN(sys_time)),':')
	read(sys_time(1:colon_pos-1),100,err=999) sys_hour
	read(sys_time(colon_pos+1:LEN(sys_time)),100,err=999) sys_minute
	if(pas_minute+sys_minute.GT.59) pas_hour = pas_hour + 1
	if(pas_hour+sys_hour.GT.23)
     &  STOP '%COMP-F-DATE Invalid date/time combination!'

	goto 200
	end if !no + date, and + time.

	end if !Delta_time check.

C
C	Check to see if current time is before/after requested time.
C	No requested time assumes current time.
C

	comp_date = char_date
	if (pas_time(1:1).EQ.space) then
	after = .FALSE.
	goto 200
	end if !time check.

	end_pos = str$position(pas_time(1:LEN(pas_time)),space)
	end_pos = end_pos - 1
	if (delta_time) then
	beg_pos = 2
	if (end_pos.LE.0) end_pos = 6
	else
	beg_pos = 1
	if (end_pos.LE.0) end_pos = 5
	end if !Delta time check.

	colon_pos = str$position(pas_time(1:LEN(pas_time)),':')
	if (colon_pos.EQ.0) then
	read(pas_time(beg_pos:end_pos),100,err=999) pas_hour
	pas_minute = 0
	pas_time = pas_time(1:end_pos) // ':00'
	else
	read(pas_time(beg_pos:colon_pos-1),100,err=999) pas_hour
	read(pas_time(colon_pos+1:end_pos),100,err=999) pas_minute
100	format(I)
	end if !Hour/minute colon check.

	colon_pos = str$position(sys_time(1:LEN(sys_time)),':')
	read(sys_time(1:colon_pos-1),100,err=999) sys_hour
	read(sys_time(colon_pos+1:LEN(sys_time)),100,err=999) sys_minute

	if (sys_hour.GT.pas_hour) after = .TRUE.
	if ((sys_hour.EQ.pas_hour).AND.(sys_minute.GE.pas_minute))
     &     after = .TRUE.

C
C	Find out if the date requested is in this month.
C
200	continue

	do 300 J = idate(1),last_day
	if (.NOT. dates(J)) goto 250

	idate(1) = J
	iopt = 3
	bin_date(1) = 0
	CALL CVDATE(idate,bin_date,char_date,iopt)
	if (char_date.EQ.comp_date) then
	 if (after) goto 250
	end if
	CALL DAYOFWEEK(bin_date,week_day)
	if(days(week_day)) then
	found = .TRUE.
	goto 400
	end if
250	continue
	
300	continue

C
C	Try next month.
C

	if (.NOT. found) then
	idate(2) = idate(2) + 1
	   if(idate(2).EQ.13) then
	   idate(3) = idate(3) + 1
	   idate(2) = 1
	   end if !Year change check
	idate(1) = 1
	bin_date(1) = 0
	iopt = 3
	CALL CVDATE(idate,bin_date,char_date,iopt)
	CALL ENDDATE(bin_date,last_day)
	goto 200
	end if

400	continue
	bin_date(1) = 0
	iopt = 1
	CALL CVDATE(idate,bin_date,comp_date,iopt)
	icode = STR$TRIM(comp_date,comp_date,run_lth)
	if(pas_time(1:1).NE.space) then
	comp_date = comp_date(1:11) // space // pas_time
	else
	comp_date = comp_date(1:11) // space // sys_time
	end if !pas_time check.

500	continue
	goto 1000
999	continue
	STOP '%COMPDATE-F-CNVRT Invalid date/time parsed!'
1000	continue
	RETURN
	end
