SUBROUTINE assim

use params
use stat
use map
use intpar
use wind
use gridpar
use testo
use spe,only:FL1
implicit none

LOGICAL :: NOFILE, LWAVE  

REAL    :: WHME(NGX,NGY), USME(NGX,NGY), WHOI(NGX,NGY), USOI(NGX,NGY)
REAL    :: USOIB(NIBLO), WHOIB(NIBLO), ETOIB(NIBLO)
REAL    :: SIGOBS, SIGMOD
INTEGER :: IJ, IG, LMAX, NDIM1, NDIM2

! --- GET SATELLITE DATA

CALL GETDATA (WHME, USME, NOFILE)  
IF (NOFILE) THEN  
   WRITE (IU06,  * ) 'NO ASSIMILATION AT', IDTPRO, 'DUE TO LACK OF DATA'
   RETURN  
ENDIF  
LMAX = 11  
!     IF(XDELLA.LT.0.5) LMAX=22
!     IF(XDELLA.LT.0.5) LMAX=5
WRITE ( * , * ) 'LMAX IS:', LMAX  
!     SIGOBS=0.5
!     SIGMOD=0.5
SIGOBS = 0.2  
SIGMOD = 0.8  
NDIM1 = 2 * LMAX + 1  
NDIM2 = NDIM1 * NDIM1  

LWAVE = .FALSE.  
CALL OIFIELD (USME, USTARG, USOI, SIGOBS, LWAVE, SIGMOD, LMAX, NDIM2)
WRITE (IU06,  * ) '   SUB. ALTAS: OIFIELD DONE FOR WINDS'  

LWAVE = .TRUE.  
CALL OIFIELD (WHME, WHGTTG, WHOI, SIGOBS, LWAVE, SIGMOD, LMAX, NDIM2)
WRITE (IU06,  * ) '   SUB. ALTAS: OIFIELD DONE FOR WAVE HEIGHTS'  

!*    ANALYSE THE SPECTRA
DO IG = 1, IGL  
   CALL MAKEBLO (USOIB (IJS (IG) ), USOI, IJS (IG), IJL (IG), IG)
   CALL MAKEBLO (WHOIB (IJS (IG) ), WHOI, IJS (IG), IJL (IG), IG)
   DO IJ = IJS (IG), IJL (IG)  
      USNEW (IJ) = USOLD (IJ, IG)
      THWNEW (IJ) = THWOLD (IJ, IG)  
   ENDDO  
   DO IJ = IJS (IG), IJL (IG)  
      IF (WHOIB (IJ) .GT.0.) THEN  
         ETOIB (IJ) = WHOIB (IJ) **2 / 16.  
      ELSE  
         ETOIB (IJ) = - 99.  
      ENDIF  
   ENDDO  
! BE CAREFULL: THIS VERSION OF UPDATE WORKS ONLY FOR 1-BLOCK VERSION
!              OF WAM MODEL. IF NOT, FL1 HAS TO BE READ HERE FROM UNIT=1
!              AND NOT INSIDE WAMODEL WHEN ASSIMILATION IS DONE
   CALL UPDATE (FL1, ETOIB, USOIB, USNEW, THWNEW, IJS (IG),IJL (IG))
!         THE WIND FIELD CURRENTLY USED IS UPDATED.
   DO IJ = IJS (IG), IJL (IG)  
      U10OLD (IJ, IG) = USNEW (IJ) * U10OLD (IJ, IG) / USOLD (IJ, IG)  
      USOLD (IJ, IG) = USNEW (IJ)  
   ENDDO  
END DO  
RETURN  
END SUBROUTINE assim
