PROGRAM vegeta_restrt

    INTEGER, PARAMETER :: I1KIND  =  1  ! INTEGER*1
    INTEGER, PARAMETER :: I2KIND  =  2  ! INTEGER*2
    INTEGER, PARAMETER :: I4KIND  =  4  ! INTEGER*4
    INTEGER, PARAMETER :: I8KIND  =  8  ! INTEGER*8
!
    INTEGER, PARAMETER :: L1KIND  =  1  ! LOGICAl*1
    INTEGER, PARAMETER :: L4KIND  =  4  ! LOGICAL*4
    INTEGER, PARAMETER :: L8KIND  =  8  ! LOGICAL*8
!
    INTEGER, PARAMETER :: R4KIND  =  4  ! REAL*4
    INTEGER, PARAMETER :: R8KIND  =  8  ! REAL*8

    INTEGER, PARAMETER :: NSOIL   =  8  ! REAL*8  

    INTEGER(KIND=I4KIND), PARAMETER :: IM    = 719
    INTEGER(KIND=I4KIND), PARAMETER :: JM    = 1379
    INTEGER(KIND=I4KIND), PARAMETER :: LM    = 50

    LOGICAL(KIND=L4KIND)                                                                        ::&
    & RUN     , FIRST   , RESTRT  , SIGMA   , NEST    , SINGLRST, SUBPOST
!
    INTEGER(KIND=I4KIND)                                                                        ::&
    & IHRST   , NFCST   , NBC     , LIST    , IOUT    , NTSD    , NTSTM   , NSTART  , NTDDMP  ,   &
    & NPREC   , IDTAD   , NBOCO   , NSHDE   , NCP     , NPHS    , NCNVC   , NRADS   , NRADL   ,   & 
    & INITSST , INITCO2
!
    INTEGER(KIND=I4KIND), DIMENSION(3)                                                          ::&
    & IDAT
!
    REAL   (KIND=R4KIND)                                                                        ::&
    & DT
  
    INTEGER(KIND=I4KIND), DIMENSION(IM, JM)                                                     ::&
    & ITEMP   , ITEMP2

    REAL   (KIND=R4KIND), DIMENSION(IM, JM)                                                     ::&
    & TEMP1   , TEMP2   , TEMP3   , TEMP4   , TEMP5   , TEMP6   , TEMP7   , TEMP8   , TEMP12  ,   &
    & TEMP13  , TEMP14  , TEMP15  
  
    CHARACTER(32)                                                                               ::&
    & LABEL

    REAL   (KIND=R4KIND), DIMENSION(IM, JM, NSOIL)                                              ::&
    & TEMPSOIL
    
    INTEGER(KIND=I4KIND), DIMENSION(3)                                                          ::&
    & IDATB      

    INTEGER(KIND=I4KIND)                                                                        ::&
    & I       , J       , K       , N       , IER     , IRTN    , IYR     , IMNTH   , IDAY    ,   &
    & LBM2    , IHOUR 

    REAL   (KIND=R4KIND)                                                                        ::&
    & TSTART  , PDOMG   , RESOMG  , DUMMY   , TEMP9   , TEMP10  , TEMP11     

            NFCST=10

            OPEN(UNIT=NFCST,FILE='RESTRT000001.t00s_XC50',STATUS='OLD',FORM='UNFORMATTED')
!            OPEN(UNIT=NFCST,FILE='RESTRT000420.t00s',STATUS='OLD',FORM='UNFORMATTED')

       
            READ(NFCST) RUN, IDAT, IHRST, NTSD, LABEL, IHOUR
	    WRITE(*,*) 'RESTRT (1): ',RUN,IDAT,IHRST,NTSD,LABEL,IHOUR
	    
	    READ(NFCST) PDOMG, RESOMG
	    
	    DO K=1,LM
	        READ(NFCST) TEMP1
	    END DO
	    
	    READ(NFCST) RUN, IDAT, IHRST, NTSD, LABEL, IHOUR, FIRST, IOUT, NSHDE
	    
	    READ(NFCST) TEMP1, TEMP2, TEMP3
	    
	    
	    READ(NFCST) PDB, TB, QB, UB, VB, Q2B, CWMB
	    
	    
	    DO 300 K=1,LM
	        READ(NFCST) TEMP1 ! T (I,J,K)
                READ(NFCST) TEMP2 ! Q (I,J,K)
                READ(NFCST) TEMP3 ! U (I,J,K)
                READ(NFCST) TEMP4 ! V (I,J,K)
             
	     IF (K.eq.2) THEN
             !Vento ~52.83802 hPa
	     OPEN(UNIT=20,FILE='Vento_L2_Eta_8km_000001_XC50.bin',FORM='unformatted')	     
	     WRITE(20)TEMP4(:,:)  
	     ENDIF

	     IF (K.eq.5) THEN
             !Vento ~139.8696 hPa
	     OPEN(UNIT=20,FILE='Vento_L5_Eta_8km_000001_XC50.bin',FORM='unformatted')	     
	     WRITE(20)TEMP4(:,:)   
             ENDIF
	     		
                READ(NFCST) TEMP5 ! Q2(I,J,K)
	    
                READ(NFCST)                                ! TTND(I,J,L)
!            
                READ(NFCST)((TEMP6(I,J), I=1,IM), J=1, JM) ! CWM  (I,J,K)
                READ(NFCST)((TEMP7(I,J), I=1,IM), J=1, JM) ! TRAIN(I,J,K)
                READ(NFCST)((TEMP8(I,J), I=1,IM), J=1, JM) ! TCUCN(I,J,K)	    
	    
       300  END DO


       
       	    READ(NFCST) RUN ,IDAT, IHRST, NTSD, LABEL, IHOUR, TEMP1, TEMP2, TEMP3, TEMP4,         &
    &                   ((TEMP5(I,J),I=1,IM), J=1, JM), TEMP6
    
    
            READ(NFCST) TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6, TEMP7 
	    
	       
	    READ(NFCST) TEMP1, TEMP2, ((TEMP3(I,J),I=1,IM), J=1, JM),                             &
    &                   ((TEMP4(I,J),I=1,IM), J=1, JM), TEMP5, TEMP6, TEMP7     
	    
	    
	     READ(NFCST) TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6, TEMP7
	    
	     
	     READ(NFCST) TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6
	    
	    
	     READ(NFCST) TEMP1, ((TEMP2(I,J),I=1,IM), J=1, JM), TEMP3, TEMP4
	    
	    
             READ(NFCST) TEMP1, UL, ITEMP, TEMP3
	    	    
	    
	     READ(NFCST) RUN, IDAT, IHRST, NTSD, LABEL, IHOUR, TEMP1, TEMP2, TEMP3, TEMP4
	    
	    
	     READ(NFCST) TEMP1, ITEMP, TEMP3, ITEMP2
	    
	    
	     READ(NFCST) TEMP1, TEMP2, TEMP3, TEMP4
	    
	    
	     READ(NFCST)TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6, TEMP7
	    
	    
	     READ(NFCST)TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6
	    
	    
	     READ(NFCST) ARDSW, ARDLW, ASRFC, AVRAIN, AVCNVC
	    
	    
             READ(NFCST) TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6, TEMP7,                          &
    &                    TEMP12, TEMP13, TEMP14, TEMP15	    
	     
	    
	     READ(NFCST) TEMPSOIL

	     READ(NFCST) TEMP1

	     READ(NFCST) TEMPSOIL

             READ(NFCST) TEMPSOIL

             READ(NFCST) TEMP1
	     

             READ(NFCST) TEMP1, TEMP2, TEMP3, ACUTIM, ARATIM, APHTIM,                          & 
    &                        NHEAT, NPHS, NCNVC, NPREC, NRDSW, NRDLW,                             &
    &                        NSRFC, TPH0D, TLM0D, RESTRT	     
	     

             DO K=1,LM	     
	          READ(NFCST)TEMP1 ! RSWTT
                  READ(NFCST)TEMP2 ! RLWTT	     
             END DO
	    
	    
             READ(NFCST)TEMP2 ! CNVBOT (USED TO BE HBOT)
             READ(NFCST)TEMP3 ! CNVTOP (USED TO BE HTOP)
             READ(NFCST)TEMP4 ! RSWTOA
             READ(NFCST)TEMP5 ! RLWTOA	   
	     
	     
!            READ(NFCST)TEMP1 ! VEGETATION TYPE 	     
!	     OPEN(UNIT=20,FILE='Veg_eta_inicial.bin',FORM='unformatted')


	    	     
END PROGRAM 	     
	     
	     
	     
	     
