PROGRAM Main
  IMPLICIT NONE

  INTEGER, PARAMETER :: r4  = SELECTED_REAL_KIND(6)  ! Kind for 32-bits Real Numbers
  INTEGER, PARAMETER :: i4  = SELECTED_INT_KIND (9)   ! Kind for 32-bits Integer Numbers
  INTEGER, PARAMETER :: r8  = SELECTED_REAL_KIND(15) ! Kind for 64-bits Real Numbers
  INTEGER, PARAMETER :: i8  = SELECTED_INT_KIND (14)  ! Kind for 64-bits Integer Numbers
  INTEGER, PARAMETER :: r16 = SELECTED_REAL_KIND(31)! Kind for 128-bits Real Numbers

    INTEGER          :: iyeard 
    INTEGER          :: juliand
    INTEGER          :: jmonth
    REAL(KIND=r8)    :: frachours
    REAL(KIND=r8)    :: hours
    REAL(KIND=r8)    :: xua
    REAL(KIND=r8)    :: xta
    REAL(KIND=r8)    :: xprec
    REAL(KIND=r8)    :: xsin
    REAL(KIND=r8)    :: xlin
    REAL(KIND=r8)    :: xur,xlh,xsh
 
    CHARACTER(LEN=255) :: namec='teste.S001_flux'
    CHARACTER(LEN=255) :: namep='/stornext/online18/bam/paulo.kubota/dados_pn_era5/surface/Clim_Input.S003.txt'
    INTEGER            :: open_status
    INTEGER            :: count_line
    OPEN(1,FILE=TRIM(namep),ACCESS='SEQUENTIAL',&
         FORM='FORMATTED',STATUS='OLD',ACTION='READ', &
                IOSTAT=open_status)  
    OPEN(2,FILE=TRIM(namec),ACCESS='SEQUENTIAL',&
         FORM='FORMATTED',STATUS='UNKNOWN',ACTION='WRITE', &
                IOSTAT=open_status)  
   xlh=0.0
   xsh=0.0
   count_line=0
    DO 
       READ(1,'(3I8,9F8.3)',END=10) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
10 continue
    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=12) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+2,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
12 continue
    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=22) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+4,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
22 continue
    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=32) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+6,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
32 continue
    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=42) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+8,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
42 continue

    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=52) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+10,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
52 continue

    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=62) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+12,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
62 continue

    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=72) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+14,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
72 continue

    REWIND(1)
    DO 
       READ(1,'(3I8,9F8.3)',END=82) iyeard,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
       WRITE(2,'(3I8,9F8.3)')       iyeard+16,jmonth,juliand,hours,xua,xta,xprec,xsin,xlin,xur,xlh,xsh
!       WRITE(2,'(2I8,7F8.3)'      ) iyeard+8,juliand,hours,xua,xta,xprec,xsin,xlin,xur
       count_line=count_line+1
    END DO 
82 continue
    PRINT*,count_line
END PROGRAM Main
