! Program for "absolute" date and time determination:
! seconds since 00:00:00 1970-01-01 UTC 
! for date range from 01/01/2002 00:00 UTC to 01/01/2010 00:00 UTC
! with time resoltuion 1 minute

integer, parameter :: year_ini=2002, month_ini=01, day_ini=01, hour_ini=00, minute_ini=00,&
                      year_fin=2009, month_fin=12, day_fin=31, hour_fin=23, minute_fin=59

integer*8 :: idatetime_abs_val
integer*8, dimension(0:59,0:23,1:31,1:12,2:10) :: idatetime_abs=-999999999, &
 idatetime_abs_work=-999999999
integer :: iy, im, id, ih, imin, iy2
integer :: idtstep=1
character (len=50) :: file_input

integer, dimension(12) :: dd_mon=(/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)

 do iy=year_ini,year_fin
   if (iy == 2002) file_input="YEAR2002/datetime_abs_2002.dat"
   if (iy == 2003) file_input="YEAR2003/datetime_abs_2003.dat"
   if (iy == 2004) file_input="YEAR2004/datetime_abs_2004.dat"
   if (iy == 2005) file_input="YEAR2005/datetime_abs_2005.dat"
   if (iy == 2006) file_input="YEAR2006/datetime_abs_2006.dat"
   if (iy == 2007) file_input="YEAR2007/datetime_abs_2007.dat"
   if (iy == 2008) file_input="YEAR2008/datetime_abs_2008.dat"
   if (iy == 2009) file_input="YEAR2009/datetime_abs_2009.dat"
   open (11, file=trim(file_input), form="formatted")
     read (11,'(10(1x,i10))') idatetime_abs_work(0:59,0:23,1:31,1:12,2:10)
   close (11)

   dd_mon(2)=28
   if (mod(iy, 4) == 0) dd_mon(2)=29
   do im=1,12
     do id=1,dd_mon(im) 
       do ih=0,23
         do imin=0,59,idtstep

           iy2=iy-2000
           idatetime_abs(imin,ih,id,im,iy2)=idatetime_abs_work(imin,ih,id,im,iy2)

         enddo ! imin
       enddo ! ih
     enddo ! id
   enddo ! im
 enddo ! iy

 open (12, file="datetime_abs_2002_2009.dat", form="formatted")
   write (12,'(10(1x,i10))') idatetime_abs(0:59,0:23,1:31,1:12,2:10)
 close (12)

 stop
 end
