
! Program to calculate the geostrophic wind based on mean
! sea level pressure (msl) and sea level density

SUBROUTINE geos(ic,nd,id,slat,slon,slats,slons,rlat,&
                rlon,rlats,rlons,nlat,nlon,nlats,nlons,den,pathLR,&
                ngridd,um,vm)

!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc

USE MOD_CSTS
USE MOD_FUNCS, ONLY : geostrofico,dobla,bessel      
   
      Implicit none 

      INTEGER, INTENT(IN) :: nd
      INTEGER, INTENT(IN) :: ic
      INTEGER, INTENT(IN) :: id

      INTEGER, INTENT(IN) :: nlat
      INTEGER, INTENT(IN) :: nlon
      INTEGER, INTENT(IN) :: nlats
      INTEGER, INTENT(IN) :: nlons
      DOUBLE PRECISION, INTENT(IN) :: slat
      DOUBLE PRECISION, INTENT(IN) :: slon
      DOUBLE PRECISION, INTENT(IN) :: slats
      DOUBLE PRECISION, INTENT(IN) :: slons
      DOUBLE PRECISION, INTENT(IN) :: rlat
      DOUBLE PRECISION, INTENT(IN) :: rlon
      DOUBLE PRECISION, INTENT(IN) :: rlats
      DOUBLE PRECISION, INTENT(IN) :: rlons
      REAL, INTENT(IN) :: den(nd,ic)
      CHARACTER(LEN=*), INTENT(IN) :: pathLR
      INTEGER, INTENT(IN) :: ngridd
      REAL, INTENT(OUT) :: um(nd,ic)
      REAL, INTENT(OUT) :: vm(nd,ic)

      integer anno,mes,dia,i,j
      real psl(id),umint(ic),vmint(ic)
      character for10*50

      print*,"program 2: geostrophic wind"

      write(for10,'(a,i05,a)') '(7x,i4,1x,i2,1x,i2,3x,',id,&
     '(f5.0,1x))'

! Input files
      open(3,file=trim(pathLR)//'msl.dat')

      do 1000 i=1,nd

!      Read pressure and density data
       read(3,for10) anno,mes,dia,(psl(j),j=1,id)
       psl=psl*100./g

       print*, "antes del call"
       print*,anno, mes, dia, psl(i)


        print*,"id =",id
        print*,"ic =",ic
        print*,"slat =",slat
        print*,"slon =",slon
        print*,"slats =",slats
        print*,"slons =",slons
        print*,"rlat =",rlat
        print*,"rlon =",rlon
        print*,"rlats =",rlats
        print*,"rlons =",rlons
        print*,"nlat =",nlat
        print*,"nlon =",nlon
        print*,"nlats =",nlats
        print*,"nlons =",nlons
        print*,"ngridd =",ngridd


!      Calculate the geostrophic wind components (umint,vmint)
       call geostrofico(psl,umint,vmint,id,ic,slat,slon,slats,slons,&
                   rlat,rlon,rlats,rlons,nlat,nlon,nlats,nlons,ngridd)

!       do j=1,ic
!        um(i,j)=umint(j)/den(i,j)
!        vm(i,j)=vmint(j)/den(i,j)
!       enddo

        um(i,:)=umint(:)/den(i,:)
        vm(i,:)=vmint(:)/den(i,:)

 1000 continue
      close(3)
END SUBROUTINE geos

