* Program to create a time template for Excel DAVERAGE function.
* Goal is to create 24 hour average data (diel averages) with 30 minute time bins.
* Written by Pat Arnott, 16 Feb 2015.
* Inputs: None.
* Outputs: File containing parameters to use the DAVERAGE function of Excel.
* Uses: None.
* Used by: None.

	Program TimeTemplate
	IMPLICIT NONE  ! Force declaration of all variables.

	CHARACTER*100 t 
	INTEGER ih,im   ! ih is hour, im is minute.
	CHARACTER*2 ch1,ch2  ! character representatin of hour.

	t='TimeIntervalStart,TimeIntervalEnd,AverageTime'

	OPEN (1,FILE='TimeTemplate.xlsx')
	WRITE(1,FMT='(a)') TRIM(ADJUSTL(t))

	DO ih=0,23  ! Hour range.
	 WRITE(UNIT=ch1,FMT=2) ih 
	 WRITE(UNIT=ch2,FMT=2) ih+1
2	 FORMAT(i2)
	 IF (ch1(1:1).EQ.'') ch1(1:1)='0' ; IF (ch2(1:1).EQ.'') ch2(1:1)='0'

	 WRITE(1,FMT="(a9)") 'Time,Time'
	 WRITE(1,1) ch1,ch1,ch1
1	 FORMAT('>=', a2, ':00,<=', a2, ':30,' ,a2,':15')
	 WRITE(1,FMT="(a9)") 'Time,Time'
	 WRITE(1,3) ch1,ch2,ch1
3	 FORMAT('>=', a2, ':30,<=', a2, ':00,' ,a2,':45')
	ENDDO 

	CLOSE(1)
	END
	   

	  
