C NCLFORTSTART
      SUBROUTINE GRADU (N_TIME,N_LAT,N_LON,Z,UGRAD)
      REAL Z(N_LON,N_LAT,N_TIME),UGRAD(N_LON,N_LAT,N_TIME)
C NCLEND
C
C  Calculate quadratic polynomial values.
C
      DO I=2,N_LON-1
      print*,'I= ',I
      DO J=2,N_LAT-1
         UGRAD(I,J,:) = Z(I,J+1,:) - Z(I,J-1,:)
      END DO
      END DO

C
      RETURN
      END



C NCLFORTSTART
      SUBROUTINE UGEO (N_T,N_LAT,LAT,N_LON,LAT_BDYN,LAT_BDYS,UGRAD,UG)
      REAL UGRAD(N_LON,N_LAT,N_T),UG(N_LON,N_LAT,N_T)
      REAL LAT(N_LAT)
      REAL F_PARAM(N_LON,N_LAT,N_T)
      REAL G_CONST, OMEGA, PI, LAT_BDYN, LAT_BDYS
C NCLEND
C
C  Calculate u-component geostrophic winds using u-component height
C  gradient
C
      print*,'computing U GEO winds' 
      G_CONST = 9.80655
      OMEGA   = 0.0000729
      PI      = 3.14159
      
      DO J=1,N_LAT

         F_PARAM(:,J,:) = 2 * OMEGA * (LAT(J) * (PI / 180.))     

      END DO

      DO J=1,N_LAT
         IF (LAT(J) > LAT_BDYN .OR. LAT(J) < LAT_BDYS) THEN  
           UG(:,J,:) = ((-1 * G_CONST) / F_PARAM(:,J,:)) * UGRAD(:,J,:) 
         END IF
      END DO

C
      RETURN
      END



