! 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 :: ndata_tot=4300000 

integer, parameter :: year_ini=2002, month_ini=01, day_ini=01, hour_ini=00, minute_ini=00,&
                      year_fin=2010, month_fin=01, day_fin=01, hour_fin=00, minute_fin=00

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

integer, dimension(12) :: dd_mon=(/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
character :: system_command*60

 do iy=year_ini,year_fin
   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

! Seconds numbers since 00:00:00 1970-01-01 UTC 

            write (system_command,'(a,1x,i4.4,4(1X,i2.2))') &
 './date_abs_def_fortran_work.script',iy, im, id, ih, imin

           call system(system_command)
           open (11,FILE='date_abs_work.txt', status='old')
           read (11,*) idatetime_abs_val
           close (11)

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

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

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

 stop
 end
