Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv.F90	(revision 2202)
@@ -36,5 +36,5 @@
 CONTAINS
 
-#include "obs_conv.h90"
+#include "obs_conv_functions.h90"
 
 END MODULE obs_conv
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv.h90	(revision 2199)
+++ 	(revision )
@@ -1,288 +1,0 @@
-   REAL(KIND=wp) FUNCTION potemp( ps, pt, pp, ppr )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION potemp  ***
-      !!          
-      !! ** Purpose : Compute potential temperature
-      !!
-      !! ** Method  : A regression formula is used. 
-      !!
-      !! ** Action  : The code is kept as close to the F77 code as possible
-      !!              Check value: potemp(35,20,2000,0) = 19.621967
-      !!
-      !! References : T. J. Mcdougall, D. R. Jackett, D. G. Wright 
-      !!              and R. Feistel
-      !!              Accurate and computationally efficient algoritms for
-      !!              potential temperatures and density of seawater
-      !!              Journal of atmospheric and oceanic technology
-      !!              Vol 20, 2003, pp 730-741
-      !!              
-      !!
-      !! History :
-      !!        !  07-05 (K. Mogensen) Original code
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-
-      REAL(KIND=wp), INTENT(IN) :: ps
-      REAL(KIND=wp), INTENT(IN) :: pt
-      REAL(KIND=wp), INTENT(IN) :: pp
-      REAL(KIND=wp), INTENT(IN) :: ppr
-
-      !! * Local declarations
-      REAL(KIND=wp) :: zpol
-      REAL(KIND=wp), PARAMETER :: a1 =  1.067610e-05
-      REAL(KIND=wp), PARAMETER :: a2 = -1.434297e-06
-      REAL(KIND=wp), PARAMETER :: a3 = -7.566349e-09
-      REAL(KIND=wp), PARAMETER :: a4 = -8.535585e-06
-      REAL(KIND=wp), PARAMETER :: a5 =  3.074672e-08
-      REAL(KIND=wp), PARAMETER :: a6 =  1.918639e-08
-      REAL(KIND=wp), PARAMETER :: a7 =  1.788718e-10
-
-      zpol = a1 + a2 * ps + a3 * ( pp + ppr ) + a4 * pt &
-         & + a5 * ps * pt + a6 * pt * pt + a7 * pt * ( pp + ppr )
-      
-      potemp = pt + ( pp - ppr ) * zpol
-      
-   END FUNCTION potemp
-
-   REAL(KIND=wp) FUNCTION fspott( pft, pfs, pfp )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION fspott  ***
-      !!          
-      !! ** Purpose : Compute potential temperature
-      !!
-      !! ** Method  : A regression formula is used. 
-      !!
-      !! ** Action  : Check value: fspott(10,25,1000) = 8.4678516
-      !!
-      !! References : A. E. Gill
-      !!              Atmosphere-Ocean Dynamics
-      !!              Volume 30 (International Geophysics)
-      !!
-      !! History :
-      !!        !  07-05 (K. Mogensen) NEMO adopting of OPAVAR code.
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-      REAL(KIND=wp) :: pft   ! in situ temperature in degrees celcius
-      REAL(KIND=wp) :: pfs   ! salinity in psu
-      REAL(KIND=wp) :: pfp   ! pressure in bars
-      
-      fspott = &
-         &  pft - pfp * (   (            3.6504e-4                     &
-         &                    + pft * (  8.3198e-5                     &
-         &                    + pft * ( -5.4065e-7                     &
-         &                    + pft *    4.0274e-9  ) ) )              &
-         &                + ( pfs - 35.0 ) * (         1.7439e-5       &
-         &                                     - pft * 2.9778e-7 )     &
-         &                + pfp * (            8.9309e-7               &
-         &                          + pft * ( -3.1628e-8               &
-         &                          + pft *    2.1987e-10 )            &
-         &                          - ( pfs - 35.0 ) *  4.1057e-9      &
-         &                          + pfp * (          -1.6056e-10     &
-         &                                    + pft * 5.0484e-12 ) ) )
-
-   END FUNCTION fspott
-
-   REAL(KIND=wp) FUNCTION atg( p_s, p_t, p_p )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION atg  ***
-      !!          
-      !! ** Purpose : Compute adiabatic temperature gradient deg c per decibar
-      !!
-      !! ** Method  : A regression formula is used
-      !!
-      !! ** Action  : The code is kept as close to the F77 code as possible
-      !!              Check value: atg(40,40,10000) = 3.255974e-4
-      !!
-      !! References : N. P. Fotonoff and R.C. Millard jr., 
-      !!              Algoritms for computation of fundamental
-      !!              properties of seawater
-      !!              Unesco technical papers in marine science 44
-      !!              Unesco 1983
-      !!
-      !! History :
-      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-
-      REAL(KIND=wp), INTENT(IN) :: p_s    ! Salinity in PSU
-      REAL(KIND=wp), INTENT(IN) :: p_t    ! Temperature in centigrades
-      REAL(KIND=wp), INTENT(IN) :: p_p    ! Pressure in decibars.
-
-      !! * Local declarations
-      
-      REAL(KIND=wp) :: z_ds
-
-      z_ds = p_s - 35.0
-      atg = ((( -2.1687e-16 * p_t + 1.8676e-14 ) * p_t - 4.6206e-13 ) * p_p      &
-         &  + (( 2.7759e-12 * p_t - 1.1351e-10 ) * z_ds + (( - 5.4481e-14 * p_t  &  
-         &  + 8.733e-12 ) * p_t - 6.7795e-10 ) * p_t  + 1.8741e-8)) * p_p        &
-         &  + ( -4.2393e-8 * p_t + 1.8932e-6 ) * z_ds                          &
-         &  + (( 6.6228e-10 * p_t - 6.836e-8 ) * p_t + 8.5258e-6 ) * p_t + 3.5803e-5
-
-   END FUNCTION atg
-      
-   REAL(KIND=wp) FUNCTION theta( p_s, p_t0, p_p0, p_pr )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION theta  ***
-      !!          
-      !! ** Purpose : Compute potential temperature
-      !!
-      !! ** Method  : A regression formula is used. 
-      !!
-      !! ** Action  : The code is kept as close to the F77 code as possible
-      !!              Check value: theta(40,40,10000,0) = 36.89073
-      !!
-      !! References : N. P. Fotonoff and R.C. Millard jr., 
-      !!              Algoritms for computation of fundamental
-      !!              properties of seawater
-      !!              Unesco technical papers in marine science 44
-      !!              Unesco 1983
-      !!
-      !! History :
-      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-      REAL(KIND=wp), INTENT(IN) :: p_s
-      REAL(KIND=wp), INTENT(IN) :: p_t0
-      REAL(KIND=wp), INTENT(IN) :: p_p0
-      REAL(KIND=wp), INTENT(IN) :: p_pr
-
-      !! * Local declarations
-      REAL(KIND=wp) :: z_p
-      REAL(KIND=wp) :: z_t
-      REAL(KIND=wp) :: z_h
-      REAL(KIND=wp) :: z_xk
-      REAL(KIND=wp) :: z_q
-
-      z_p = p_p0
-      z_t = p_t0
-      z_h = p_pr - z_p
-      z_xk = z_h * atg( p_s, z_t, z_p ) 
-      Z_t = z_t + 0.5 * z_xk
-      z_q = z_xk
-      z_p = z_p + 0.5 * z_h
-      z_xk = z_h * atg( p_s, z_t, z_p )
-      z_t = z_t + 0.29289322 * ( z_xk - z_q )
-      z_q = 0.58578644 * z_xk + 0.121320344 * z_q
-      z_xk = z_h * atg( p_s, z_t, z_p )
-      z_t = z_t + 1.707106781 * ( z_xk - z_q )
-      z_q = 3.414213562 * z_xk - 4.121320244 * z_q
-      z_p = z_p + 0.5 * z_h
-      z_xk = z_h * atg( p_s, z_t, z_p )
-      theta = z_t + ( z_xk - 2.0 * z_q ) / 6.0
-
-   END FUNCTION theta
-
-   REAL(KIND=wp) FUNCTION depth( p_p, p_lat )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION depth  ***
-      !!          
-      !! ** Purpose : Compute depth from pressure and latitudes
-      !!
-      !! ** Method  : A regression formula is used. 
-      !!
-      !! ** Action  : The code is kept as close to the F77 code as possible
-      !!              Check value: depth(10000,30) = 9712.653
-      !!
-      !! References : N. P. Fotonoff and R.C. Millard jr., 
-      !!              Algoritms for computation of fundamental
-      !!              properties of seawater
-      !!              Unesco technical papers in marine science 44
-      !!              Unesco 1983
-      !!
-      !! History :
-      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-      REAL(KIND=wp), INTENT(IN) :: p_p     ! Pressure in decibars
-      REAL(KIND=wp), INTENT(IN) :: p_lat   ! Latitude in degrees
-
-      !! * Local declarations
-      REAL(KIND=wp) :: z_x
-      REAL(KIND=wp) :: z_gr
-      
-      z_x = SIN( p_lat / 57.29578 )
-      z_x = z_x * z_x
-      z_gr = 9.780318 * ( 1.0 + ( 5.2788e-3 + 2.36e-5 * z_x ) * z_x ) + 1.092e-6 * p_p
-      depth = ((( -1.82e-15 * p_p + 2.279e-10 ) * p_p - 2.2512e-5 ) * p_p + 9.72659 ) * p_p
-      depth = depth / z_gr
-
-   END FUNCTION depth
-
-   REAL(KIND=wp) FUNCTION p_to_dep( p_p, p_lat )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION p_to_dep  ***
-      !!          
-      !! ** Purpose : Compute depth from pressure and latitudes
-      !!
-      !! ** Method  : A regression formula is used. This version is less
-      !!              accurate the "depth" but invertible.
-      !!
-      !! ** Action  : 
-      !!
-      !! References : P.M Saunders
-      !!              Pratical conversion of pressure to depth
-      !!              Journal of physical oceanography Vol 11, 1981, pp 573-574
-      !!
-      !! History :
-      !!        !  07-05  (K. Mogensen) Original code
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-      REAL(KIND=wp), INTENT(IN) :: p_p    ! Pressure in decibars
-      REAL(KIND=wp), INTENT(IN) :: p_lat  ! Latitude in degrees
-
-      !! * Local declarations
-      REAL(KIND=wp) :: z_x
-      REAL(KIND=wp) :: z_c1
-      REAL(KIND=wp) :: z_c2
-
-      z_x = SIN( p_lat / 57.29578 )
-      z_x = z_x * z_x
-      z_c1 = ( 5.92  + 5.25 * z_x ) * 1e-3 
-      z_c2 = 2.21e-6 
-      p_to_dep = (1 - z_c1)  * p_p - z_c2 * p_p * p_p
-
-   END FUNCTION p_to_dep
-
-   REAL(KIND=wp) FUNCTION dep_to_p( p_dep, p_lat )
-      !!----------------------------------------------------------------------
-      !!                    ***  FUNCTION dep_to_p  ***
-      !!          
-      !! ** Purpose : Compute depth from pressure and latitudes
-      !!
-      !! ** Method  : The expression used in p_to_dep is inverted.
-      !!
-      !! ** Action  : 
-      !!
-      !! References : P.M Saunders
-      !!              Pratical conversion of pressure to depth
-      !!              Journal of physical oceanography Vol 11, 1981, pp 573-574
-      !!
-      !! History :
-      !!        !  07-05  (K. Mogensen) Original code
-      !!----------------------------------------------------------------------
-
-      !! * Arguments
-      REAL(KIND=wp), INTENT(IN) :: p_dep    ! Depth in meters
-      REAL(KIND=wp), INTENT(IN) :: p_lat    ! Latitude in degrees
-
-      !! * Local declarations
-      REAL(KIND=wp) :: z_x
-      REAL(KIND=wp) :: z_c1
-      REAL(KIND=wp) :: z_c2
-      REAL(KIND=wp) :: z_d
-
-      z_x = SIN( p_lat / 57.29578 )
-      z_x = z_x * z_x
-      z_c1 = ( 5.92  + 5.25 * z_x ) * 1e-3 
-      z_c2 = 2.21e-6 
-      z_d = ( z_c1 - 1 ) * ( z_c1 - 1  ) - 4 * z_c2 * p_dep
-      dep_to_p = (( 1 - z_c1 ) - SQRT( z_d )) / ( 2 * z_c2 )
-
-   END FUNCTION dep_to_p
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv_functions.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv_functions.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_conv_functions.h90	(revision 2202)
@@ -0,0 +1,288 @@
+   REAL(KIND=wp) FUNCTION potemp( ps, pt, pp, ppr )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION potemp  ***
+      !!          
+      !! ** Purpose : Compute potential temperature
+      !!
+      !! ** Method  : A regression formula is used. 
+      !!
+      !! ** Action  : The code is kept as close to the F77 code as possible
+      !!              Check value: potemp(35,20,2000,0) = 19.621967
+      !!
+      !! References : T. J. Mcdougall, D. R. Jackett, D. G. Wright 
+      !!              and R. Feistel
+      !!              Accurate and computationally efficient algoritms for
+      !!              potential temperatures and density of seawater
+      !!              Journal of atmospheric and oceanic technology
+      !!              Vol 20, 2003, pp 730-741
+      !!              
+      !!
+      !! History :
+      !!        !  07-05 (K. Mogensen) Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+
+      REAL(KIND=wp), INTENT(IN) :: ps
+      REAL(KIND=wp), INTENT(IN) :: pt
+      REAL(KIND=wp), INTENT(IN) :: pp
+      REAL(KIND=wp), INTENT(IN) :: ppr
+
+      !! * Local declarations
+      REAL(KIND=wp) :: zpol
+      REAL(KIND=wp), PARAMETER :: a1 =  1.067610e-05
+      REAL(KIND=wp), PARAMETER :: a2 = -1.434297e-06
+      REAL(KIND=wp), PARAMETER :: a3 = -7.566349e-09
+      REAL(KIND=wp), PARAMETER :: a4 = -8.535585e-06
+      REAL(KIND=wp), PARAMETER :: a5 =  3.074672e-08
+      REAL(KIND=wp), PARAMETER :: a6 =  1.918639e-08
+      REAL(KIND=wp), PARAMETER :: a7 =  1.788718e-10
+
+      zpol = a1 + a2 * ps + a3 * ( pp + ppr ) + a4 * pt &
+         & + a5 * ps * pt + a6 * pt * pt + a7 * pt * ( pp + ppr )
+      
+      potemp = pt + ( pp - ppr ) * zpol
+      
+   END FUNCTION potemp
+
+   REAL(KIND=wp) FUNCTION fspott( pft, pfs, pfp )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION fspott  ***
+      !!          
+      !! ** Purpose : Compute potential temperature
+      !!
+      !! ** Method  : A regression formula is used. 
+      !!
+      !! ** Action  : Check value: fspott(10,25,1000) = 8.4678516
+      !!
+      !! References : A. E. Gill
+      !!              Atmosphere-Ocean Dynamics
+      !!              Volume 30 (International Geophysics)
+      !!
+      !! History :
+      !!        !  07-05 (K. Mogensen) NEMO adopting of OPAVAR code.
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(KIND=wp) :: pft   ! in situ temperature in degrees celcius
+      REAL(KIND=wp) :: pfs   ! salinity in psu
+      REAL(KIND=wp) :: pfp   ! pressure in bars
+      
+      fspott = &
+         &  pft - pfp * (   (            3.6504e-4                     &
+         &                    + pft * (  8.3198e-5                     &
+         &                    + pft * ( -5.4065e-7                     &
+         &                    + pft *    4.0274e-9  ) ) )              &
+         &                + ( pfs - 35.0 ) * (         1.7439e-5       &
+         &                                     - pft * 2.9778e-7 )     &
+         &                + pfp * (            8.9309e-7               &
+         &                          + pft * ( -3.1628e-8               &
+         &                          + pft *    2.1987e-10 )            &
+         &                          - ( pfs - 35.0 ) *  4.1057e-9      &
+         &                          + pfp * (          -1.6056e-10     &
+         &                                    + pft * 5.0484e-12 ) ) )
+
+   END FUNCTION fspott
+
+   REAL(KIND=wp) FUNCTION atg( p_s, p_t, p_p )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION atg  ***
+      !!          
+      !! ** Purpose : Compute adiabatic temperature gradient deg c per decibar
+      !!
+      !! ** Method  : A regression formula is used
+      !!
+      !! ** Action  : The code is kept as close to the F77 code as possible
+      !!              Check value: atg(40,40,10000) = 3.255974e-4
+      !!
+      !! References : N. P. Fotonoff and R.C. Millard jr., 
+      !!              Algoritms for computation of fundamental
+      !!              properties of seawater
+      !!              Unesco technical papers in marine science 44
+      !!              Unesco 1983
+      !!
+      !! History :
+      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+
+      REAL(KIND=wp), INTENT(IN) :: p_s    ! Salinity in PSU
+      REAL(KIND=wp), INTENT(IN) :: p_t    ! Temperature in centigrades
+      REAL(KIND=wp), INTENT(IN) :: p_p    ! Pressure in decibars.
+
+      !! * Local declarations
+      
+      REAL(KIND=wp) :: z_ds
+
+      z_ds = p_s - 35.0
+      atg = ((( -2.1687e-16 * p_t + 1.8676e-14 ) * p_t - 4.6206e-13 ) * p_p      &
+         &  + (( 2.7759e-12 * p_t - 1.1351e-10 ) * z_ds + (( - 5.4481e-14 * p_t  &  
+         &  + 8.733e-12 ) * p_t - 6.7795e-10 ) * p_t  + 1.8741e-8)) * p_p        &
+         &  + ( -4.2393e-8 * p_t + 1.8932e-6 ) * z_ds                          &
+         &  + (( 6.6228e-10 * p_t - 6.836e-8 ) * p_t + 8.5258e-6 ) * p_t + 3.5803e-5
+
+   END FUNCTION atg
+      
+   REAL(KIND=wp) FUNCTION theta( p_s, p_t0, p_p0, p_pr )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION theta  ***
+      !!          
+      !! ** Purpose : Compute potential temperature
+      !!
+      !! ** Method  : A regression formula is used. 
+      !!
+      !! ** Action  : The code is kept as close to the F77 code as possible
+      !!              Check value: theta(40,40,10000,0) = 36.89073
+      !!
+      !! References : N. P. Fotonoff and R.C. Millard jr., 
+      !!              Algoritms for computation of fundamental
+      !!              properties of seawater
+      !!              Unesco technical papers in marine science 44
+      !!              Unesco 1983
+      !!
+      !! History :
+      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(KIND=wp), INTENT(IN) :: p_s
+      REAL(KIND=wp), INTENT(IN) :: p_t0
+      REAL(KIND=wp), INTENT(IN) :: p_p0
+      REAL(KIND=wp), INTENT(IN) :: p_pr
+
+      !! * Local declarations
+      REAL(KIND=wp) :: z_p
+      REAL(KIND=wp) :: z_t
+      REAL(KIND=wp) :: z_h
+      REAL(KIND=wp) :: z_xk
+      REAL(KIND=wp) :: z_q
+
+      z_p = p_p0
+      z_t = p_t0
+      z_h = p_pr - z_p
+      z_xk = z_h * atg( p_s, z_t, z_p ) 
+      Z_t = z_t + 0.5 * z_xk
+      z_q = z_xk
+      z_p = z_p + 0.5 * z_h
+      z_xk = z_h * atg( p_s, z_t, z_p )
+      z_t = z_t + 0.29289322 * ( z_xk - z_q )
+      z_q = 0.58578644 * z_xk + 0.121320344 * z_q
+      z_xk = z_h * atg( p_s, z_t, z_p )
+      z_t = z_t + 1.707106781 * ( z_xk - z_q )
+      z_q = 3.414213562 * z_xk - 4.121320244 * z_q
+      z_p = z_p + 0.5 * z_h
+      z_xk = z_h * atg( p_s, z_t, z_p )
+      theta = z_t + ( z_xk - 2.0 * z_q ) / 6.0
+
+   END FUNCTION theta
+
+   REAL(KIND=wp) FUNCTION depth( p_p, p_lat )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION depth  ***
+      !!          
+      !! ** Purpose : Compute depth from pressure and latitudes
+      !!
+      !! ** Method  : A regression formula is used. 
+      !!
+      !! ** Action  : The code is kept as close to the F77 code as possible
+      !!              Check value: depth(10000,30) = 9712.653
+      !!
+      !! References : N. P. Fotonoff and R.C. Millard jr., 
+      !!              Algoritms for computation of fundamental
+      !!              properties of seawater
+      !!              Unesco technical papers in marine science 44
+      !!              Unesco 1983
+      !!
+      !! History :
+      !!        !  07-05 (K. Mogensen) Original code based on the F77 code.
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(KIND=wp), INTENT(IN) :: p_p     ! Pressure in decibars
+      REAL(KIND=wp), INTENT(IN) :: p_lat   ! Latitude in degrees
+
+      !! * Local declarations
+      REAL(KIND=wp) :: z_x
+      REAL(KIND=wp) :: z_gr
+      
+      z_x = SIN( p_lat / 57.29578 )
+      z_x = z_x * z_x
+      z_gr = 9.780318 * ( 1.0 + ( 5.2788e-3 + 2.36e-5 * z_x ) * z_x ) + 1.092e-6 * p_p
+      depth = ((( -1.82e-15 * p_p + 2.279e-10 ) * p_p - 2.2512e-5 ) * p_p + 9.72659 ) * p_p
+      depth = depth / z_gr
+
+   END FUNCTION depth
+
+   REAL(KIND=wp) FUNCTION p_to_dep( p_p, p_lat )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION p_to_dep  ***
+      !!          
+      !! ** Purpose : Compute depth from pressure and latitudes
+      !!
+      !! ** Method  : A regression formula is used. This version is less
+      !!              accurate the "depth" but invertible.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : P.M Saunders
+      !!              Pratical conversion of pressure to depth
+      !!              Journal of physical oceanography Vol 11, 1981, pp 573-574
+      !!
+      !! History :
+      !!        !  07-05  (K. Mogensen) Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(KIND=wp), INTENT(IN) :: p_p    ! Pressure in decibars
+      REAL(KIND=wp), INTENT(IN) :: p_lat  ! Latitude in degrees
+
+      !! * Local declarations
+      REAL(KIND=wp) :: z_x
+      REAL(KIND=wp) :: z_c1
+      REAL(KIND=wp) :: z_c2
+
+      z_x = SIN( p_lat / 57.29578 )
+      z_x = z_x * z_x
+      z_c1 = ( 5.92  + 5.25 * z_x ) * 1e-3 
+      z_c2 = 2.21e-6 
+      p_to_dep = (1 - z_c1)  * p_p - z_c2 * p_p * p_p
+
+   END FUNCTION p_to_dep
+
+   REAL(KIND=wp) FUNCTION dep_to_p( p_dep, p_lat )
+      !!----------------------------------------------------------------------
+      !!                    ***  FUNCTION dep_to_p  ***
+      !!          
+      !! ** Purpose : Compute depth from pressure and latitudes
+      !!
+      !! ** Method  : The expression used in p_to_dep is inverted.
+      !!
+      !! ** Action  : 
+      !!
+      !! References : P.M Saunders
+      !!              Pratical conversion of pressure to depth
+      !!              Journal of physical oceanography Vol 11, 1981, pp 573-574
+      !!
+      !! History :
+      !!        !  07-05  (K. Mogensen) Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      REAL(KIND=wp), INTENT(IN) :: p_dep    ! Depth in meters
+      REAL(KIND=wp), INTENT(IN) :: p_lat    ! Latitude in degrees
+
+      !! * Local declarations
+      REAL(KIND=wp) :: z_x
+      REAL(KIND=wp) :: z_c1
+      REAL(KIND=wp) :: z_c2
+      REAL(KIND=wp) :: z_d
+
+      z_x = SIN( p_lat / 57.29578 )
+      z_x = z_x * z_x
+      z_c1 = ( 5.92  + 5.25 * z_x ) * 1e-3 
+      z_c2 = 2.21e-6 
+      z_d = ( z_c1 - 1 ) * ( z_c1 - 1  ) - 4 * z_c2 * p_dep
+      dep_to_p = (( 1 - z_c1 ) - SQRT( z_d )) / ( 2 * z_c2 )
+
+   END FUNCTION dep_to_p
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_h2d.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_h2d.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_h2d.F90	(revision 2202)
@@ -46,5 +46,5 @@
 CONTAINS
  
-#include "obs_inter_h2d.h90"
+#include "obsinter_h2d.h90"
 
 END MODULE obs_inter_h2d
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_h2d.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_h2d.h90	(revision 2199)
+++ 	(revision )
@@ -1,1357 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!    This software is governed by the CeCILL licence (Version 2)
-   !!    (See NEMOVAR_CeCILL.txt)
-   !!----------------------------------------------------------------------
-   SUBROUTINE obs_int_h2d_init( kpk,   kpk2,  k2dint, plam,  pphi, &
-      &                         pglam, pgphi, pmask,  pweig, pobsmask, &
-      &                         iminpoints )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d  ***
-      !!
-      !! ** Purpose : Computes weights for horizontal interpolation to the 
-      !!              observation point.
-      !!
-      !! ** Method  : Horizontal interpolation to the observation point using
-      !!              model values at the corners of the surrounding grid 
-      !!              points.
-      !!
-      !!    Interpolation Schemes : 
-      !!
-      !!    1) k2dint = 0: Distance-weighted interpolation scheme 1
-      !!
-      !!       The interpolation weights are computed as a weighted 
-      !!       sum of the distance between the model grid points (A)
-      !!       and the observation point (B). Distance (s) is computed 
-      !!       using the great-circle distance formula: 
-      !!
-      !!       s(AB) = arcos(   sin( phiA ) x sin( phiB )
-      !!                      + cos( phiA ) x cos( phiB ) 
-      !!                                    x cos( lamB - lamA ) )
-      !!
-      !!    2) k2dint = 1: Distance-weighted interpolation scheme 2
-      !!
-      !!       As k2dint = 0 but with distance (ds) computed using 
-      !!       a small-angle approximation to the great-circle formula:
-      !!
-      !!       ds(AB) = sqrt(   ( phiB - phiA )^{2} 
-      !!                    + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
-      !!
-      !!    3) k2dint = 2: Bilinear interpolation on a geographical grid
-      !!
-      !!       The interpolation is split into two 1D interpolations in
-      !!       the longitude and latitude directions, respectively.
-      !!
-      !!    4) k2dint = 3: General bilinear remapping interpolation
-      !!
-      !!       An iterative scheme that involves first mapping a 
-      !!       quadrilateral cell into a cell with coordinates 
-      !!       (0,0), (1,0), (0,1) and (1,1).
-      !!
-      !!    5) k2dint = 4: Polynomial interpolation
-      !!
-      !!       The interpolation weights are computed by fitting a 
-      !!       polynomial function of the form 
-      !!              
-      !!       P(i) = a1(i) + a2(i) * phi + a3(i) * plam 
-      !!                                  + a4(i) * phi * plam
-      !!    
-      !!       through the model values at the four surrounding grid points.
-      !!
-      !! ** Action  :
-      !!                   
-      !! References : Jones, P.: A users guide for SCRIP: A Spherical 
-      !!                        Coordinate Remapping and Interpolation Package.
-      !!                        Version 1.4. Los Alomos. 
-      !!                    
-      !!       http://www.acl.lanl.gov/climate/software/SCRIP/SCRIPmain.html
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-03 (A. Vidard) NEMOVAR migration
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!        ! 07-08 (K. Mogensen) Split in two routines for easier adj.
-      !!-----------------------------------------------------------------------
-      !! * Modules used
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk,   &             ! Parameter values for automatic arrays
-         & kpk2,  &        
-         & k2dint               ! Interpolation scheme options
-                                ! = 0 distance-weighted (great circle)
-                                ! = 1 distance-weighted (small angle)
-                                ! = 2 bilinear (geographical grid)
-                                ! = 3 bilinear (quadrilateral grid)
-                                ! = 4 polynomial (quadrilateral grid)
-      REAL(KIND=wp), INTENT(INOUT) :: &
-         & plam, &
-         & pphi                 ! Geographical (lat,lon) coordinates of
-                                ! observation
-      REAL(KIND=wp), DIMENSION(2,2), INTENT(IN) :: &
-         & pglam, &             ! Model variable lat
-         & pgphi                ! Model variable lon
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmask                ! Model variable mask
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(OUT) ::  &
-         & pweig                ! Weights for interpolation
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) ::  &
-         & pobsmask             ! Vertical mask for observations
-      INTEGER, INTENT(IN), OPTIONAL :: &
-         & iminpoints           ! Reject point which is not surrounded
-                                ! by at least iminpoints sea points
-
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      INTEGER :: &
-         & ikmax, &
-         & iamb1, &
-         & iamb2
-      REAL(KIND=wp) :: &
-         & zphimm,  &
-         & zphimp,  &
-         & zphipm,  &
-         & zphipp,  &
-         & zlammm,  &
-         & zlammp,  &
-         & zlampm,  &
-         & zlampp,  &
-         & zphimin, &
-         & zphimax, &
-         & zlammin, &
-         & zlammax
-      REAL(KIND=wp), DIMENSION(kpk2) :: &
-         & z2dmm,  &
-         & z2dmp,  &
-         & z2dpm,  &
-         & z2dpp,  &
-         & z2dmmt, &
-         & z2dmpt, &
-         & z2dpmt, &
-         & z2dppt, &
-         & zsum
-      LOGICAL :: &
-         & ll_ds1, &
-         & ll_skip, &
-         & ll_fail
-       
-      !------------------------------------------------------------------------
-      ! Constants for the 360 degrees ambiguity
-      !------------------------------------------------------------------------
-      iamb1 = 10   ! dlam < iamb1 * dphi
-      iamb2 = 3    ! Special treatment if iamb2 * lam < max(lam) 
-       
-      !------------------------------------------------------------------------
-      ! Initialize number of levels
-      !------------------------------------------------------------------------
-      IF ( kpk2 == 1 ) THEN
-         ikmax = 1
-      ELSEIF ( kpk2 == kpk) THEN
-         ikmax = kpk-1
-      ENDIF
-      !------------------------------------------------------------------------
-      ! Initialize the cell corners
-      !------------------------------------------------------------------------
-      zphimm = pgphi(1,1)
-      zphimp = pgphi(1,2)
-      zphipm = pgphi(2,1)
-      zphipp = pgphi(2,2)
-      zlammm = pglam(1,1)
-      zlammp = pglam(1,2)
-      zlampm = pglam(2,1)
-      zlampp = pglam(2,2)
-       
-      !------------------------------------------------------------------------
-      ! Treat the 360 degrees ambiguity
-      !------------------------------------------------------------------------
-      DO WHILE ( ( zlammm < 0.0_wp ).OR.( zlammm > 360.0_wp )  &
-         &   .OR.( zlampm < 0.0_wp ).OR.( zlampm > 360.0_wp )  &
-         &   .OR.( zlampp < 0.0_wp ).OR.( zlampp > 360.0_wp )  &
-         &   .OR.( zlammp < 0.0_wp ).OR.( zlammp > 360.0_wp ) )
-       
-         IF ( zlammm < 0.0_wp   ) zlammm = zlammm + 360.0_wp
-         IF ( zlammm > 360.0_wp ) zlammm = zlammm - 360.0_wp
-         IF ( zlammp < 0.0_wp   ) zlammp = zlammp + 360.0_wp
-         IF ( zlammp > 360.0_wp ) zlammp = zlammp - 360.0_wp
-         IF ( zlampm < 0.0_wp   ) zlampm = zlampm + 360.0_wp
-         IF ( zlampm > 360.0_wp ) zlampm = zlampm - 360.0_wp
-         IF ( zlampp < 0.0_wp   ) zlampp = zlampp + 360.0_wp
-         IF ( zlampp > 360.0_wp ) zlampp = zlampp - 360.0_wp
-       
-      END DO
-
-      DO WHILE ( ( plam < 0.0_wp ) .OR. ( plam > 360.0_wp ) )
-         IF ( plam < 0.0_wp   ) plam = plam + 360.0_wp
-         IF ( plam > 360.0_wp ) plam = plam - 360.0_wp
-      END DO
-
-      !------------------------------------------------------------------------
-      ! Special case for observation on grid points
-      !------------------------------------------------------------------------
-      ll_skip = .FALSE.
-      IF ( ( ABS( zphimm - pphi ) < 1.0e-6_wp ) .AND. &
-         & ( ABS( zlammm - plam ) < 1.0e-6_wp ) ) THEN
-         z2dmm(:) = 1.0_wp
-         z2dpm(:) = 0.0_wp
-         z2dmp(:) = 0.0_wp
-         z2dpp(:) = 0.0_wp
-         ll_skip = .TRUE.
-      ENDIF
-      IF ( ( ABS( zphipm - pphi ) < 1.0e-6_wp ) .AND. &
-         & ( ABS( zlampm - plam ) < 1.0e-6_wp ) ) THEN
-         z2dmm(:) = 0.0_wp
-         z2dpm(:) = 1.0_wp
-         z2dmp(:) = 0.0_wp
-         z2dpp(:) = 0.0_wp
-         ll_skip = .TRUE.
-      ENDIF
-      IF ( ( ABS( zphimp - pphi ) < 1.0e-6_wp ) .AND. &
-         & ( ABS( zlammp - plam ) < 1.0e-6_wp ) ) THEN
-         z2dmm(:) = 0.0_wp
-         z2dpm(:) = 0.0_wp
-         z2dmp(:) = 1.0_wp
-         z2dpp(:) = 0.0_wp
-         ll_skip = .TRUE.
-      ENDIF
-      IF ( ( ABS( zphipp - pphi ) < 1.0e-6_wp ) .AND. &
-         & ( ABS( zlampp - plam ) < 1.0e-6_wp ) ) THEN
-         z2dmm(:) = 0.0_wp
-         z2dpm(:) = 0.0_wp
-         z2dmp(:) = 0.0_wp
-         z2dpp(:) = 1.0_wp
-         ll_skip = .TRUE.
-      ENDIF
-
-      IF ( .NOT.ll_skip ) THEN
-
-         zphimin = MIN( zphimm, zphipm, zphipp, zphimp )
-         zphimax = MAX( zphimm, zphipm, zphipp, zphimp )
-         zlammin = MIN( zlammm, zlampm, zlampp, zlammp )
-         zlammax = MAX( zlammm, zlampm, zlampp, zlammp )
-
-         IF ( ( ( zlammax - zlammin ) / ( zphimax - zphimin ) ) > iamb1 ) THEN
-            IF ( iamb2 * zlammm < zlammax ) zlammm = zlammm + 360.0_wp
-            IF ( iamb2 * zlammp < zlammax ) zlammp = zlammp + 360.0_wp
-            IF ( iamb2 * zlampm < zlammax ) zlampm = zlampm + 360.0_wp
-            IF ( iamb2 * zlampp < zlammax ) zlampp = zlampp + 360.0_wp
-         ENDIF
-
-         zlammin = MIN( zlammm, zlampm, zlampp, zlammp )
-         IF ( zlammm > ( zlammin + 180.0_wp ) ) zlammm = zlammm - 360.0_wp
-         IF ( zlammp > ( zlammin + 180.0_wp ) ) zlammp = zlammp - 360.0_wp
-         IF ( zlampm > ( zlammin + 180.0_wp ) ) zlampm = zlampm - 360.0_wp
-         IF ( zlampp > ( zlammin + 180.0_wp ) ) zlampp = zlampp - 360.0_wp
-         
-         IF ( plam < zlammin ) plam = plam + 360.0_wp
-	   z2dmm = 0.0_wp
-	   z2dmp = 0.0_wp
-	   z2dpm = 0.0_wp
-	   z2dpp = 0.0_wp
-         SELECT CASE (k2dint)
-            
-         CASE(0)
-            CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
-               &                  pphi, plam, pmask,                  &
-               &                  zphimm, zlammm, zphimp, zlammp,     & 
-               &                  zphipm, zlampm, zphipp, zlampp,     &
-               &                  z2dmm, z2dmp, z2dpm, z2dpp )
-         CASE(1)
-            CALL obs_int_h2d_ds2( kpk2, ikmax,                        &
-               &                  pphi, plam, pmask,                  &
-               &                  zphimm, zlammm, zphimp, zlammp,     &
-               &                  zphipm, zlampm, zphipp, zlampp,     &
-               &                  z2dmm, z2dmp, z2dpm, z2dpp )
-         CASE(2)
-            CALL obs_int_h2d_bil( kpk2, ikmax,                        &
-               &                  pphi, plam, pmask,                  &
-               &                                          zlammp,     &
-               &                  zphipm,         zphipp, zlampp,     &
-               &                  z2dmm, z2dmp, z2dpm, z2dpp )
-         CASE(3)
-            CALL obs_int_h2d_bir( kpk2, ikmax,                        &
-               &                  pphi, plam, pmask,                  &
-               &                  zphimm, zlammm, zphimp, zlammp,     &
-               &                  zphipm, zlampm, zphipp, zlampp,     &
-               &                  z2dmm, z2dmp, z2dpm, z2dpp, ll_fail )
-            IF (ll_fail) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*)'Bilinear weight computation failed'
-                  WRITE(numout,*)'Switching to great circle distance'
-                  WRITE(numout,*)
-               ENDIF
-               CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
-                  &                  pphi, plam, pmask,                  &
-                  &                  zphimm, zlammm, zphimp, zlammp,     & 
-                  &                  zphipm, zlampm, zphipp, zlampp,     &
-                  &                  z2dmm, z2dmp, z2dpm, z2dpp )
-            ENDIF
-         CASE(4)  
-            CALL obs_int_h2d_pol( kpk2, ikmax,                        &
-               &                  pphi, plam, pmask,                  &
-               &                  zphimm, zlammm, zphimp, zlammp,     &
-               &                  zphipm, zlampm, zphipp, zlampp,     & 
-               &                  z2dmm, z2dmp, z2dpm, z2dpp )
-         END SELECT
-
-      ENDIF
-      !------------------------------------------------------------------------
-      ! Compute weights for interpolation to the observation point
-      !------------------------------------------------------------------------
-      pobsmask(:) = 0.0_wp
-      pweig(:,:,:) = 0.0_wp
-      ! ll_ds1 is used for failed interpolations
-      ll_ds1 = .FALSE.
-      DO jk = 1, ikmax
-         IF (PRESENT(iminpoints)) THEN
-            IF (NINT(SUM(pmask(:,:,jk)))<iminpoints) CYCLE
-         ENDIF
-         zsum(jk) = z2dmm(jk) + z2dmp(jk) + z2dpm(jk) + z2dpp(jk) 
-         IF ( zsum(jk) /= 0.0_wp ) THEN
-            pweig(1,1,jk) = z2dmm(jk) 
-            pweig(1,2,jk) = z2dmp(jk)
-            pweig(2,1,jk) = z2dpm(jk)
-            pweig(2,2,jk) = z2dpp(jk)
-            ! Set the vertical mask
-            IF ( ( ( z2dmm(jk) > 0.0_wp ) .AND.       &
-               &   ( pmask(1,1,jk) == 1.0_wp ) ) .OR. &
-               & ( ( z2dmp(jk) > 0.0_wp ) .AND.       &
-               &   ( pmask(1,2,jk) == 1.0_wp ) ) .OR. &
-               & ( ( z2dpm(jk) > 0.0_wp ) .AND.       &
-               &   ( pmask(2,1,jk) == 1.0_wp ) ) .OR. &
-               & ( ( z2dpp(jk) > 0.0_wp ) .AND.       &
-               &   ( pmask(2,2,jk) == 1.0_wp ) ) ) pobsmask(jk)=1.0_wp
-         ELSE
-            ! If the interpolation has failed due to the point
-            ! being on the intersect of two land points retry with
-            ! k2dint = 0
-            IF ( ( pmask(1,1,jk) /= 0.0_wp ).OR. &
-               & ( pmask(1,2,jk) /= 0.0_wp ).OR. &
-               & ( pmask(2,1,jk) /= 0.0_wp ).OR. &
-               & ( pmask(2,2,jk) /= 0.0_wp ) ) THEN
-               ! If ll_ds1 is false compute k2dint = 0 weights
-               IF ( .NOT.ll_ds1 ) THEN
-                  CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
-                     &                  pphi, plam, pmask,                  &
-                     &                  zphimm, zlammm, zphimp, zlammp,     & 
-                     &                  zphipm, zlampm, zphipp, zlampp,     &
-                     &                  z2dmmt, z2dmpt, z2dpmt, z2dppt ) 
-                  ll_ds1 = .TRUE.
-               ENDIF
-               zsum(jk) = z2dmmt(jk) + z2dmpt(jk) + z2dpmt(jk) + z2dppt(jk) 
-               IF ( zsum(jk) /= 0.0_wp ) THEN
-                  pweig(1,1,jk) = z2dmmt(jk) 
-                  pweig(1,2,jk) = z2dmpt(jk)
-                  pweig(2,1,jk) = z2dpmt(jk)
-                  pweig(2,2,jk) = z2dppt(jk)
-                  ! Set the vertical mask
-                  IF ( ( ( z2dmmt(jk) > 0.0_wp ) .AND.      &
-                     &   ( pmask(1,1,jk) == 1.0_wp ) ) .OR. &
-                     & ( ( z2dmpt(jk) > 0.0_wp ) .AND.      &
-                     &   ( pmask(1,2,jk) == 1.0_wp ) ) .OR. &
-                     & ( ( z2dpmt(jk) > 0.0_wp) .AND.      &
-                     &   ( pmask(2,1,jk) == 1.0_wp ) ) .OR. &
-                     & ( ( z2dppt(jk) > 0.0_wp ) .AND.      &
-                     &   ( pmask(2,2,jk) == 1.0_wp ) ) )    &
-                     & pobsmask(jk)=1.0_wp
-               ENDIF
-            ENDIF
-         ENDIF
-      END DO
-  
-   END SUBROUTINE obs_int_h2d_init
-
-   SUBROUTINE obs_int_h2d( kpk, kpk2, &
-      &                    pweig, pmod, pobsk )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d  ***
-      !!
-      !! ** Purpose : Horizontal interpolation to the observation point.
-      !!
-      !! ** Method  : Horizontal interpolation to the observation point using
-      !!              model values at the corners of the surrounding grid 
-      !!              points.
-      !!
-      !! ** Action  :
-      !!                   
-      !! References : 
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-03 (A. Vidard) NEMOVAR migration
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!        ! 07-08 (K. Mogensen) Split in two routines for easier adj.
-      !!-----------------------------------------------------------------------
-      !! * Modules used
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk,   &             ! Parameter values for automatic arrays
-         & kpk2
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pweig                ! Interpolation weights
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmod                 ! Model variable to interpolate
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) ::  &
-         & pobsk                ! Model profile interpolated to obs (i,j) pt
-
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      INTEGER :: &
-         & ikmax
-      REAL(KIND=wp) :: &
-         & zsum
-      !------------------------------------------------------------------------
-      ! Initialize number of levels
-      !------------------------------------------------------------------------
-      IF ( kpk2 == 1 ) THEN
-         ikmax = 1
-      ELSEIF ( kpk2 == kpk) THEN
-         ikmax = kpk-1
-      ENDIF
-      !------------------------------------------------------------------------
-      ! Interpolate to the observation point
-      !------------------------------------------------------------------------
-      pobsk(:) = obfillflt
-      DO jk = 1, ikmax
-         zsum = pweig(1,1,jk) + pweig(1,2,jk) + pweig(2,1,jk) +  pweig(2,2,jk) 
-         IF ( zsum /= 0.0_wp ) THEN
-            pobsk(jk) = (  pweig(1,1,jk) * pmod(1,1,jk)         &
-               &         + pweig(1,2,jk) * pmod(1,2,jk)         &
-               &         + pweig(2,1,jk) * pmod(2,1,jk)         &
-               &         + pweig(2,2,jk) * pmod(2,2,jk)         &
-               &                                             ) / zsum
-         ENDIF
-      END DO
-
-   END SUBROUTINE obs_int_h2d
-  
-   SUBROUTINE obs_int_h2d_ds1( kpk2, kmax,                        &
-      &                        pphi, plam, pmask,                 &
-      &                        pphimm, plammm, pphimp, plammp,    & 
-      &                        pphipm, plampm, pphipp, plampp,    &
-      &                        p2dmm, p2dmp, p2dpm, p2dpp )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d_ds1  ***
-      !!
-      !! ** Purpose : Distance-weighted interpolation scheme (k2dint = 0)
-      !!
-      !! ** Method  : The interpolation weights are computed as a weighted 
-      !!              sum of the distance between the model grid points (A) 
-      !!              and the observation point (B). 
-      !!
-      !!    Distance (s) is computed using the great-circle distance formula:
-      !!
-      !!    s(AB) = arcos(   sin( phiA ) x sin( phiB )
-      !!                   + cos( phiA ) x cos( phiB ) x cos( lamB - lamA )
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-
-      !! * Modules used
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk2, &             ! Parameter values for automatic arrays
-         & kmax
-      REAL(KIND=wp), INTENT(IN) :: &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphimm, &           ! Geographical location of surrounding
-         & pphimp, &           ! model grid points
-         & pphipm, &
-         & pphipp, & 
-         & plammm, &
-         & plammp, &
-         & plampm, &
-         & plampp
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmask               ! Model variable mask 
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
-         & p2dmm, &            ! Interpolation weights
-         & p2dmp, &
-         & p2dpm, &
-         & p2dpp
-
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      REAL(KIND=wp) :: &
-         & zphi2,   &
-         & zlam2,   &
-         & zcola,   &
-         & za2,     &
-         & zb2,     &
-         & zc2,     &
-         & zphimm2, &
-         & zphimp2, &
-         & zphipm2, &
-         & zphipp2, &
-         & zlammm2, &
-         & zlammp2, &
-         & zlampm2, &
-         & zlampp2, &
-         & za1mm,   &
-         & za1mp,   &
-         & za1pm,   &
-         & za1pp,   &
-         & zcomm,   &
-         & zcomp,   &
-         & zcopm,   &
-         & zcopp,   &
-         & zb1mm,   &
-         & zb1mp,   &
-         & zb1pm,   &
-         & zb1pp,   &
-         & zc1mm,   &
-         & zc1mp,   &
-         & zc1pm,   &
-         & zc1pp,   &
-         & zsopmpp, &
-         & zsommmp, &
-         & zsomm,   &
-         & zsomp,   &
-         & zsopm,   &
-         & zsopp
-       
-      !------------------------------------------------------------------------
-      ! Distance-weighted interpolation using the great circle formula
-      !------------------------------------------------------------------------
-      zphi2 = pphi * rad
-      zlam2 = plam * rad
-      zcola = COS( zphi2 )
-      za2   = SIN( zphi2 )
-      zb2   = zcola * COS( zlam2 )
-      zc2   = zcola * SIN( zlam2 )
-       
-      zphimm2 = pphimm * rad
-      zphimp2 = pphimp * rad
-      zphipm2 = pphipm * rad
-      zphipp2 = pphipp * rad
-       
-      zlammm2 = plammm * rad
-      zlammp2 = plammp * rad
-      zlampm2 = plampm * rad
-      zlampp2 = plampp * rad
-       
-      za1mm = SIN( zphimm2 )
-      za1mp = SIN( zphimp2 )
-      za1pm = SIN( zphipm2 )
-      za1pp = SIN( zphipp2 )
-       
-      zcomm = COS( zphimm2 )
-      zcomp = COS( zphimp2 )
-      zcopm = COS( zphipm2 )
-      zcopp = COS( zphipp2 )
-       
-      zb1mm = zcomm * COS( zlammm2 )
-      zb1mp = zcomp * COS( zlammp2 )
-      zb1pm = zcopm * COS( zlampm2 )
-      zb1pp = zcopp * COS( zlampp2 )
-       
-      zc1mm = zcomm * SIN( zlammm2 )
-      zc1mp = zcomp * SIN( zlammp2 )
-      zc1pm = zcopm * SIN( zlampm2 )
-      zc1pp = zcopp * SIN( zlampp2 )
-       
-      ! Function for arcsin(sqrt(1-x^2) version of great-circle formula
-      zsomm = grt_cir_dis( za1mm, za2, zb1mm, zb2, zc1mm, zc2 )
-      zsomp = grt_cir_dis( za1mp, za2, zb1mp, zb2, zc1mp, zc2 )
-      zsopm = grt_cir_dis( za1pm, za2, zb1pm, zb2, zc1pm, zc2 )
-      zsopp = grt_cir_dis( za1pp, za2, zb1pp, zb2, zc1pp, zc2 )
-       
-      zsopmpp = zsopm * zsopp
-      zsommmp = zsomm * zsomp
-      DO jk = 1, kmax
-         p2dmm(jk) = zsomp * zsopmpp * pmask(1,1,jk)
-         p2dmp(jk) = zsomm * zsopmpp * pmask(1,2,jk) 
-         p2dpm(jk) = zsopp * zsommmp * pmask(2,1,jk)
-         p2dpp(jk) = zsopm * zsommmp * pmask(2,2,jk)
-      END DO
-       
-   END SUBROUTINE obs_int_h2d_ds1
-  
-   SUBROUTINE obs_int_h2d_ds2( kpk2, kmax,                        &
-      &                        pphi, plam, pmask,                 &
-      &                        pphimm, plammm, pphimp, plammp,    &
-      &                        pphipm, plampm, pphipp, plampp,    &
-      &                        p2dmm, p2dmp, p2dpm, p2dpp ) 
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d_ds2  ***
-      !!
-      !! ** Purpose : Distance-weighted interpolation scheme (k2dint = 1)
-      !!
-      !! ** Method  : As k2dint = 0 but with distance (ds) computed using a 
-      !!              small-angle approximation to the great-circle distance 
-      !!              formula:
-      !!
-      !!    ds(AB) = sqrt(   ( phiB - phiA )^{2}
-      !!                   + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-
-      !!-----------------------------------------------------------------------
-      !! * Modules used
-      !!----------------------------------------------------------------------- 
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk2, &             ! Parameter values for automatic arrays
-         & kmax
-      REAL(KIND=wp), INTENT(IN) ::        &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphimm, &           ! Geographical location of surrounding
-         & pphimp, &           ! model grid points
-         & pphipm, &
-         & pphipp, & 
-         & plammm, &
-         & plammp, &
-         & plampm, &
-         & plampp
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmask               ! Model variable mask 
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
-         & p2dmm, &            ! Interpolation weights
-         & p2dmp, &
-         & p2dpm, &
-         & p2dpp
-
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      REAL(KIND=wp) :: &
-         & zcosp,   &
-         & zdlmm,   &
-         & zdlmp,   &
-         & zdlpm,   &
-         & zdlpp,   &
-         & zdpmm,   &
-         & zdpmp,   &
-         & zdppm,   &
-         & zdppp,   &
-         & zsomm,   &
-         & zsomp,   &
-         & zsopm,   &
-         & zsopp,   &
-         & zsopmpp, &
-         & zsommmp
-       
-      !------------------------------------------------------------------------
-      ! Distance-weighted interpolation with a small angle approximation
-      !------------------------------------------------------------------------
-      zcosp = COS( pphi * rad )
-       
-      zdlmm = plammm - plam
-      zdlmp = plammp - plam
-      zdlpm = plampm - plam
-      zdlpp = plampp - plam
-       
-      zdpmm = pphimm - pphi
-      zdpmp = pphimp - pphi
-      zdppm = pphipm - pphi
-      zdppp = pphipp - pphi
-       
-      zsomm = grt_cir_dis_saa( zdlmm, zdpmm, zcosp )
-      zsomp = grt_cir_dis_saa( zdlmp, zdpmp, zcosp )
-      zsopm = grt_cir_dis_saa( zdlpm, zdppm, zcosp )
-      zsopp = grt_cir_dis_saa( zdlpp, zdppp, zcosp )
-       
-      zsopmpp = zsopm * zsopp
-      zsommmp = zsomm * zsomp
-       
-      DO jk = 1, kmax
-         p2dmm(jk) = zsomp * zsopmpp * pmask(1,1,jk)
-         p2dmp(jk) = zsomm * zsopmpp * pmask(1,2,jk)
-         p2dpm(jk) = zsopp * zsommmp * pmask(2,1,jk)
-         p2dpp(jk) = zsopm * zsommmp * pmask(2,2,jk)
-      END DO
-       
-   END SUBROUTINE obs_int_h2d_ds2
-  
-   SUBROUTINE obs_int_h2d_bil( kpk2, kmax,                        &
-      &                        pphi, plam, pmask,                 &
-      &                        plammp, pphipm, pphipp, plampp,    &
-      &                        p2dmm, p2dmp, p2dpm, p2dpp)
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d_bil  ***
-      !!
-      !! ** Purpose : Bilinear interpolation on a geographical grid (k2dint = 2)
-      !!
-      !! ** Method  : The interpolation is split into two 1D interpolations in 
-      !!              the longitude and latitude directions, respectively.
-      !!
-      !!    An iterative scheme that involves first mapping a quadrilateral
-      !!    cell into a cell with coordinates (0,0), (1,0), (0,1) and (1,1).
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk2, &             ! Parameter values for automatic arrays
-         & kmax
-      REAL(KIND=wp), INTENT(IN) :: &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphipm, &           ! Geographical location of surrounding
-         & pphipp, &           ! model grid points
-         & plammp, &
-         & plampp
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN)  :: &
-         & pmask               ! Model variable mask
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
-         & p2dmm, &            ! Interpolation weights
-         & p2dmp, &
-         & p2dpm, &
-         & p2dpp
-
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      REAL(KIND=wp) :: &
-         & zdlmp, &
-         & zdppm, &
-         & zdlpp, &
-         & zdppp
-       
-      !----------------------------------------------------------------------
-      ! Bilinear interpolation for geographical grid
-      !----------------------------------------------------------------------
-      zdlmp = ABS(plam   - plammp) 
-      zdppm = ABS(pphi   - pphipm)
-      zdlpp = ABS(plampp - plam)
-      zdppp = ABS(pphipp - pphi)
-       
-      DO jk = 1, kmax
-         p2dmm(jk) = zdlpp * zdppp * pmask(1,1,jk)
-         p2dmp(jk) = zdlpp * zdppm * pmask(1,2,jk)
-         p2dpm(jk) = zdlmp * zdppp * pmask(2,1,jk)
-         p2dpp(jk) = zdlmp * zdppm * pmask(2,2,jk)
-      END DO
-       
-   END SUBROUTINE obs_int_h2d_bil
-  
-   SUBROUTINE obs_int_h2d_bir( kpk2, kmax,                        &
-      &                        pphi, plam, pmask,                 &
-      &                        pphimm, plammm, pphimp, plammp,    &
-      &                        pphipm, plampm, pphipp, plampp,    &
-      &                        p2dmm, p2dmp, p2dpm, p2dpp, ldfail )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d_bir  ***
-      !!
-      !! ** Purpose : General bilinear remapping interpolation (k2dint = 3)
-      !!
-      !! ** Method  : An iterative scheme that involves first mapping a 
-      !!              quadrilateral cell into a cell with coordinates 
-      !!              (0,0), (1,0), (0,1) and (1,1).
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kpk2, &             ! Parameter values for automatic arrays
-         & kmax
-      REAL(KIND=wp), INTENT(IN) ::        &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphimm, &           ! Geographical location of surrounding
-         & pphimp, &           ! model grid points
-         & pphipm, &
-         & pphipp, & 
-         & plammm, &
-         & plammp, &
-         & plampm, &
-         & plampp
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmask               ! Model variable mask 
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
-         & p2dmm, &            ! Interpolation weights
-         & p2dmp, &
-         & p2dpm, &
-         & p2dpp
-      LOGICAL, INTENT(OUT) :: &
-         & ldfail
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      REAL(KIND=wp) :: &
-         & zbiwmm, &
-         & zbiwmp, &
-         & zbiwpm, &
-         & zbiwpp
-  
-      !----------------------------------------------------------------------
-      ! Bilinear remapping interpolation for general quadrilateral grid
-      !----------------------------------------------------------------------
-      CALL bil_wgt( pphimm, pphimp, pphipm, pphipp,  &
-         &          plammm, plammp, plampm, plampp,  &
-         &          zbiwmm, zbiwmp, zbiwpm, zbiwpp,  &
-         &          pphi  , plam,   ldfail           )
-
-      IF ( .NOT.ldfail ) THEN
-         DO jk = 1, kmax
-            p2dmm(jk) = zbiwmm * pmask(1,1,jk)
-            p2dmp(jk) = zbiwmp * pmask(1,2,jk)
-            p2dpm(jk) = zbiwpm * pmask(2,1,jk)
-            p2dpp(jk) = zbiwpp * pmask(2,2,jk)
-         END DO
-      ENDIF
-
-   END SUBROUTINE obs_int_h2d_bir
-
-   SUBROUTINE obs_int_h2d_pol( kpk2, kmax,                         &
-      &                        pphi, plam, pmask,                  &
-      &                        pphimm, plammm, pphimp, plammp,     &
-      &                        pphipm, plampm, pphipp, plampp,     &
-      &                        p2dmm, p2dmp, p2dpm, p2dpp )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                     ***  ROUTINE obs_int_h2d_pol  ***
-      !!
-      !! ** Purpose : Polynomial interpolation (k2dint = 4)
-      !!
-      !! ** Method  : The interpolation weights are computed by fitting a 
-      !!              polynomial function of the form
-      !!
-      !!    P(i) = a1(i) + a2(i) * phi + a3(i) * plam + a4(i) * phi * plam
-      !!
-      !!    through the model values at four surrounding grid pts (i=1,4).
-      !!    As k2dint = 0 but with distance (ds) computed using a small-
-      !!    angle approximation to the great-circle distance formula:
-      !!
-      !!    ds(AB) = sqrt(   ( phiB - phiA )^{2}
-      !!                   + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
-      !!
-      !! ** Action  :
-      !!
-      !! History :
-      !!        ! 97-11 (A. Weaver, N. Daget)
-      !!        ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &  
-         & kpk2,   &           ! Parameter values for automatic arrays 
-         & kmax
-      REAL(KIND=wp), INTENT(IN) :: &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphimm, &           ! Geographical location of surrounding
-         & pphimp, &           ! model grid points
-         & pphipm, &
-         & pphipp, &
-         & plammm, &
-         & plammp, &
-         & plampm, &
-         & plampp
-      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
-         & pmask               ! Model variable mask
-      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
-         & p2dmm,  &           ! Interpolation weights
-         & p2dmp,  &
-         & p2dpm,  &
-         & p2dpp
-  
-      !! * Local declarations
-      INTEGER :: &
-         & jk
-      REAL(KIND=wp) :: &
-         & zplp
-      REAL(KIND=wp), DIMENSION(4,4) :: &
-         & zmat,  &
-         & zmati
-       
-      !------------------------------------------------------------------------
-      ! Polynomial interpolation
-      !------------------------------------------------------------------------       
-      zmat(1,1) = 1.0_wp
-      zmat(1,2) = 1.0_wp
-      zmat(1,3) = 1.0_wp
-      zmat(1,4) = 1.0_wp
-      zmat(2,1) = plammm
-      zmat(2,2) = plammp
-      zmat(2,3) = plampm
-      zmat(2,4) = plampp
-      zmat(3,1) = pphimm
-      zmat(3,2) = pphimp
-      zmat(3,3) = pphipm
-      zmat(3,4) = pphipp
-      zmat(4,1) = plammm * pphimm
-      zmat(4,2) = plammp * pphimp
-      zmat(4,3) = plampm * pphipm
-      zmat(4,4) = plampp * pphipp
-       
-      CALL lu_invmat( zmat, 4, zmati )
-       
-      zplp = plam * pphi            
-      DO jk = 1, kmax
-         p2dmm(jk) = ABS(   zmati(1,1)        + zmati(1,2) * plam    &
-            &             + zmati(1,3) * pphi + zmati(1,4) * zplp )  &
-            &      * pmask(1,1,jk) 
-         p2dmp(jk) = ABS(   zmati(2,1)        + zmati(2,2) * plam    &
-            &             + zmati(2,3) * pphi + zmati(2,4) * zplp )  &
-            &      * pmask(1,2,jk)
-         p2dpm(jk) = ABS(   zmati(3,1)        + zmati(3,2) * plam    &
-            &             + zmati(3,3) * pphi + zmati(3,4) * zplp )  &
-            &      * pmask(2,1,jk)
-         p2dpp(jk) = ABS(   zmati(4,1)        + zmati(4,2) * plam    &
-            &             + zmati(4,3) * pphi + zmati(4,4) * zplp )  &
-            &      * pmask(2,2,jk)
-      END DO
-  
-   END SUBROUTINE obs_int_h2d_pol
-
-   SUBROUTINE bil_wgt( pphimm, pphimp, pphipm, pphipp,   &
-      &               plammm, plammp, plampm, plampp,   &
-      &               pbiwmm, pbiwmp, pbiwpm, pbiwpp,   &
-      &               pphi  , plam,   ldfail            )
-      !!-------------------------------------------------------------------
-      !!
-      !!                   ***  ROUTINE bil_wgt  ***
-      !!
-      !! ** Purpose : Compute the weights for a bilinear remapping 
-      !!              interpolation scheme.
-      !!
-      !! ** Method  : This scheme is appropriate for bilinear interpolation 
-      !!              on a general quadrilateral grid.    
-      !!              This scheme is also used in OASIS.
-      !!
-      !!              This routine is a derivative of the SCRIP software.
-      !!              Copyright 1997, 1998 the Regents of the University 
-      !!              of California. See SCRIP_Copyright.txt.
-      !!     
-      !! ** Action  :
-      !!
-      !! References : Jones, P.: A user's guide for SCRIP: A Spherical 
-      !!                Coordinate Remapping and Interpolation Package. 
-      !!                Version 1.4. Los Alamos. 
-      !!                  
-      !!         http://www.acl.lanl.gov/climate/software/SCRIP/SCRIPmain.html
-      !!
-      !! History
-      !!      ! 97-11 (A. Weaver, N. Daget)
-      !!      ! 06-03 (A. Vidard)
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
- 
-      !! * Arguments
-      REAL(KIND=wp), INTENT(IN) :: &
-         & pphi,   &           ! Geographical location of observation
-         & plam,   &
-         & pphimm, &           ! Geographical location of surrounding
-         & pphimp, &           ! model grid points
-         & pphipm, &
-         & pphipp, &
-         & plammm, &
-         & plammp, & 
-         & plampm, &
-         & plampp
-      REAL(KIND=wp), INTENT(OUT) :: &
-         & pbiwmm, &           ! Interpolation weights
-         & pbiwmp, &
-         & pbiwpm, &
-         & pbiwpp
-      LOGICAL, INTENT(out) :: &
-         & ldfail
-
-      !! * Local declarations
-      INTEGER :: &
-         & jiter
-      INTEGER :: &
-         & itermax
-      REAL(KIND=wp) :: &
-         & zphi,    &           ! Geographical location of observation
-         & zlam,    &
-         & zphimm,  &           ! Geographical location of surrounding
-         & zphimp,  &           ! model grid points
-         & zphipm,  &
-         & zphipp,  &
-         & zlammm,  &
-         & zlammp,  & 
-         & zlampm,  &
-         & zlampp,  &
-         & zdth1,   &
-         & zdth2,   &
-         & zdth3,   &
-         & zdthp,   &
-         & zdph1,   &
-         & zdph2,   &
-         & zdph3,   &
-         & zdphp,   &
-         & zmat1,   &
-         & zmat2,   &
-         & zmat3,   &
-         & zmat4,   &
-         & zdeli,   &
-         & zdelj,   &
-         & ziguess, &
-         & zjguess, &
-         & zeps,    &
-         & zdeterm, &
-         & z2pi,    &
-         & zhpi
-      
-      ! Initialization
-
-      ! Conversion to radians
-
-      zphi   = pphi   * rad
-      zlam   = plam   * rad
-      zphimm = pphimm * rad
-      zphimp = pphimp * rad
-      zphipm = pphipm * rad
-      zphipp = pphipp * rad
-      zlammm = plammm * rad
-      zlammp = plammp * rad
-      zlampm = plampm * rad
-      zlampp = plampp * rad
-
-      ldfail = .FALSE.
-
-      zdth1 = zphipm - zphimm
-      zdth2 = zphimp - zphimm
-      zdth3 = zphipp - zphipm - zdth2
-       
-      zdph1 = zlampm - zlammm
-      zdph2 = zlammp - zlammm
-      zdph3 = zlampp - zlampm
-       
-      z2pi = 2.0_wp * rpi
-       
-      IF ( zdph1 >  3.0_wp * rpi ) zdph1 = zdph1 - z2pi
-      IF ( zdph2 >  3.0_wp * rpi ) zdph2 = zdph2 - z2pi
-      IF ( zdph3 >  3.0_wp * rpi ) zdph3 = zdph3 - z2pi
-      IF ( zdph1 < -3.0_wp * rpi ) zdph1 = zdph1 + z2pi
-      IF ( zdph2 < -3.0_wp * rpi ) zdph2 = zdph2 + z2pi
-      IF ( zdph3 < -3.0_wp * rpi ) zdph3 = zdph3 + z2pi
-       
-      zdph3 = zdph3 - zdph2
-       
-      ziguess = 0.5_wp
-      zjguess = 0.5_wp
-       
-      itermax = 100
-
-#if defined key_sp
-      zeps = 1.0e-6_wp
-#else
-      zeps = 1.0e-10_wp      
-#endif
-  
-      !------------------------------------------------------------------------
-      ! Iterate to determine (i,j) in new coordinate system
-      !------------------------------------------------------------------------
-      jiter_loop: DO jiter = 1, itermax
-         
-         zdthp = zphi - zphimm - zdth1 * ziguess - zdth2 * zjguess &
-            &  - zdth3 * ziguess * zjguess
-         zdphp = zlam - zlammm
-         
-         zhpi = 0.5_wp * rpi
-         IF ( zdphp >  3.0_wp * zhpi ) zdphp = zdphp - z2pi
-         IF ( zdphp < -3.0_wp * zhpi ) zdphp = zdphp + z2pi
-         
-         zdphp = zdphp - zdph1 * ziguess - zdph2 * zjguess &
-            &  - zdph3 * ziguess * zjguess
-         
-         zmat1 = zdth1 + zdth3 * zjguess
-         zmat2 = zdth2 + zdth3 * ziguess
-         zmat3 = zdph1 + zdph3 * zjguess
-         zmat4 = zdph2 + zdph3 * ziguess
-         
-         ! Matrix determinant
-         zdeterm = zmat1 * zmat4 - zmat2 * zmat3
-         
-         zdeli = ( zdthp * zmat4 - zmat2 * zdphp) / zdeterm
-         zdelj = ( zmat1 * zdphp - zdthp * zmat3) / zdeterm
-         
-         IF ( ABS( zdeli ) < zeps .AND. ABS( zdelj ) < zeps ) EXIT jiter_loop
-         
-         ziguess = ziguess + zdeli
-         zjguess = zjguess + zdelj
-
-         ! DJL prevent ziguess and zjguess from going outside the range
-         ! 0 to 1
-         ! prevents interpolated value going wrong
-         ! for example sea ice concentration gt 1
-         
-         IF ( ziguess < 0 ) ziguess = 0.0_wp
-         IF ( zjguess < 0 ) zjguess = 0.0_wp
-         IF ( ziguess > 1 ) ziguess = 1.0_wp
-         IF ( zjguess > 1 ) zjguess = 1.0_wp
-         
-      END DO jiter_loop
-       
-      IF ( jiter <= itermax ) THEN
-           
-         ! Successfully found i,j, now compute the weights
-
-         pbiwmm = ( 1.0_wp - ziguess ) * ( 1.0_wp - zjguess )
-         pbiwmp = ( 1.0_wp - ziguess ) *            zjguess
-         pbiwpm =            ziguess   * ( 1.0_wp - zjguess )
-         pbiwpp =            ziguess   *            zjguess
-         
-      ELSEIF ( jiter > itermax ) THEN
-            
-         IF(lwp) THEN
-            
-            WRITE(numout,*)'Obs lat/lon  : ',pphi, plam
-            WRITE(numout,*)'Grid lats    : ',pphimm, pphimp, pphipm, pphipp
-            WRITE(numout,*)'Grid lons    : ',plammm, plammp, plampm, plampp
-            WRITE(numout,*)'Current i,j  : ',ziguess, zjguess
-            WRITE(numout,*)'Weights      : ',pbiwmm, pbiwmp, pbiwpm, pbiwpp
-            WRITE(numout,*)'jiter        = ',jiter
-            WRITE(numout,*)'zeps         = ',zeps
-            WRITE(numout,*)'zdeli, zdelj = ',zdeli, zdelj
-            WRITE(numout,*)' Iterations for i,j exceed max iteration count!'
-            WRITE(numout,*)
-            
-            ldfail = .TRUE.
-
-         ENDIF
-         
-      ENDIF
-    
-   END SUBROUTINE bil_wgt
-
-   SUBROUTINE lu_invmat( pmatin, kdim, pmatou )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                   ***  ROUTINE lu_invmat  ***
-      !!
-      !! ** Purpose : Invert a matrix using LU decomposition.
-      !!
-      !! ** Method  : 
-      !! 
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History
-      !!      ! 02-11 (A. Weaver, N. Daget)
-      !!      ! 06-03 (A. Vidard)
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!      ! 06-11 (NEMOVAR task force) Fix declaration of zd.
-      !!-----------------------------------------------------------------------
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kdim             ! Array dimension
-      REAL(KIND=wp), DIMENSION(kdim,kdim), INTENT(IN) :: &
-         & pmatin 
-      REAL(KIND=wp), DIMENSION(kdim,kdim), INTENT(OUT) :: &
-         & pmatou 
-  
-      !! * Local declarations
-      INTEGER :: &
-         & ji, &
-         & jj
-      INTEGER, DIMENSION(kdim) :: &
-         & indx
-      REAL(KIND=wp), DIMENSION(kdim,kdim) :: &
-         & zmat
-      REAL(KIND=wp) :: &
-         & zd
-
-      ! Invert the matrix       
-      DO jj = 1, kdim
-         DO ji = 1, kdim
-            pmatou(ji,jj) = 0.0_wp
-            zmat(ji,jj) = pmatin(ji,jj)
-         END DO
-         pmatou(jj,jj) = 1.0_wp
-      END DO
-      CALL lu_decomp( zmat, kdim, kdim, indx, zd )
-      DO jj = 1, kdim
-         CALL lu_backsb( zmat, kdim, kdim, indx, pmatou(1,jj) )
-      END DO
-      
-   END SUBROUTINE lu_invmat
-
-   SUBROUTINE lu_decomp( pmatin, kdim1, kdim2, kindex, pflt )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                   ***  ROUTINE lu_decomp  ***
-      !!
-      !! ** Purpose : Compute the LU decomposition of a matrix
-      !!
-      !! ** Method  : 
-      !! 
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History
-      !!      ! 02-11 (A. Weaver, N. Daget)
-      !!      ! 06-03 (A. Vidard)
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-       
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kdim1, &   ! Array dimensions
-         & kdim2
-      INTEGER, DIMENSION(kdim1), INTENT(OUT) :: &
-         & kindex
-      REAL(KIND=wp), INTENT(OUT) :: &
-         & pflt
-      REAL(KIND=wp), DIMENSION(kdim2,kdim2), INTENT(INOUT) :: &
-         & pmatin 
-  
-      !! * Local declarations
-      INTEGER, PARAMETER :: &
-         & jpmax = 100
-      REAL(KIND=wp), PARAMETER :: &
-         & pptiny = 1.0e-20_wp
-      REAL(KIND=wp), DIMENSION(jpmax) :: &
-         & zvv
-      INTEGER :: &
-         & ji, &
-         & jj, &
-         & jk
-      INTEGER :: &
-         & imax
-      REAL(KIND=wp) :: &
-         & zsum,  &
-         & zdum,  &
-         & zaamax
-       
-      ! Main computation
-      pflt = 1.0_wp
-      DO ji = 1, kdim1
-         zaamax = 0.0_wp
-         DO jj = 1, kdim1
-            IF ( ABS( pmatin(ji,jj) ) > zaamax ) zaamax = ABS( pmatin(ji,jj) )
-         END DO
-         IF ( zaamax == 0.0_wp ) THEN
-            CALL ctl_stop( 'singular matrix' )
-         ENDIF 
-         zvv(ji) = 1.0_wp / zaamax
-      END DO
-      DO jj = 1, kdim1
-         DO ji = 1, jj-1
-            zsum = pmatin(ji,jj)
-            DO jk = 1, ji-1
-	       zsum = zsum - pmatin(ji,jk) * pmatin(jk,jj)
-	    END DO
-            pmatin(ji,jj) = zsum
-         END DO
-         zaamax = 0.0_wp
-         DO ji = jj, kdim1
-            zsum = pmatin(ji,jj)
-            DO jk = 1, jj-1
-               zsum = zsum - pmatin(ji,jk) * pmatin(jk,jj)
-            END DO
-            pmatin(ji,jj) = zsum
-            zdum = zvv(ji) * ABS( zsum )
-            IF ( zdum >= zaamax ) THEN
-               imax = ji
-               zaamax = zdum
-            ENDIF
-	 END DO
-         IF ( jj /= imax ) THEN
-            DO jk = 1, kdim1
-               zdum = pmatin(imax,jk)
-               pmatin(imax,jk) = pmatin(jj,jk)
-               pmatin(jj,jk) = zdum
-	    END DO
-            pflt = -pflt
-            zvv(imax) = zvv(jj)
-         ENDIF
-         kindex(jj) = imax
-         IF ( pmatin(jj,jj) == 0.0_wp ) pmatin(jj,jj) = pptiny
-         IF ( jj /= kdim1 ) THEN
-            zdum = 1.0_wp / pmatin(jj,jj)
-            DO ji = jj+1, kdim1
-               pmatin(ji,jj) = pmatin(ji,jj) * zdum
-	    END DO
-         ENDIF
-      END DO
-     
-   END SUBROUTINE lu_decomp
-     
-   SUBROUTINE lu_backsb( pmat, kdim1, kdim2, kindex, pvect )
-      !!-----------------------------------------------------------------------
-      !!
-      !!                   ***  ROUTINE lu_backsb  ***
-      !!
-      !! ** Purpose : Back substitution
-      !!
-      !! ** Method  : 
-      !! 
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History
-      !!      ! 02-11 (A. Weaver, N. Daget)
-      !!      ! 06-03 (A. Vidard)
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!-----------------------------------------------------------------------
-      
-      !! * Arguments
-      INTEGER, INTENT(IN) :: &
-         & kdim1, &     ! Array dimensions
-         & kdim2
-      INTEGER, DIMENSION(kdim1), INTENT(IN) :: &
-         & kindex
-      REAL(KIND=wp), DIMENSION(kdim1), INTENT(INOUT) :: &
-         & pvect
-      REAL(KIND=wp), DIMENSION(kdim2,kdim2), INTENT(IN) :: &
-         & pmat
-  
-      !! * Local declarations
-      INTEGER :: &
-         & ji,  &
-         & jii, &
-         & jj,  &
-         & jll
-      REAL(KIND=wp) :: &
-         & zsum
-
-      ! Main computation
-      jii = 0
-      DO ji = 1, kdim1
-         jll = kindex(ji)
-         zsum = pvect(jll)
-         pvect(jll) = pvect(ji)
-         IF ( jii /= 0 ) THEN
-            DO jj = jii, ji-1
-               zsum = zsum - pmat(ji,jj) * pvect(jj)
-            END DO
-         ELSEIF ( zsum /= 0.0_wp ) THEN
-            jii = ji
-         ENDIF
-         pvect(ji) = zsum
-      END DO
-      DO ji = kdim1, 1, -1
-         zsum = pvect(ji)
-         DO jj = ji+1, kdim1
-            zsum = zsum - pmat(ji,jj) * pvect(jj)
-         END DO
-         pvect(ji) = zsum / pmat(ji,ji)
-      END DO
-     
-   END SUBROUTINE lu_backsb
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_z1d.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_z1d.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_z1d.F90	(revision 2202)
@@ -26,5 +26,5 @@
 CONTAINS
 
-#include "obs_inter_z1d.h90"
+#include "obsinter_z1d.h90"
 
 END MODULE obs_inter_z1d
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_z1d.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_inter_z1d.h90	(revision 2199)
+++ 	(revision )
@@ -1,185 +1,0 @@
-   SUBROUTINE obs_int_z1d( kpk, kkco, k1dint, kdep, &
-      &                    pobsdep, pobsk, pobs2k,  &
-      &                    pobs, pdep, pobsmask )
-      !!---------------------------------------------------------------------
-      !!
-      !!                   ***  ROUTINE obs_int_z1d ***
-      !!
-      !! ** Purpose : Vertical interpolation to the observation point.
-      !!  
-      !! ** Method  : If k1dint = 0 then use linear interpolation.
-      !!              If k1dint = 1 then use cubic spline interpolation.
-      !! 
-      !! ** Action  :
-      !!
-      !! References :
-      !!
-      !! History
-      !!      ! 97-11 (A. Weaver, S. Ricci, N. Daget)
-      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!      ! 07-01 (K. Mogensen) Use profile rather than single level
-      !!---------------------------------------------------------------------
-
-      !! * Arguments
-      INTEGER, INTENT(IN) :: kpk        ! Number of vertical levels
-      INTEGER, INTENT(IN) :: k1dint     ! 0 = linear; 1 = cubic spline interpolation 
-      INTEGER, INTENT(IN) :: kdep       ! Number of levels in profile
-      INTEGER, INTENT(IN), DIMENSION(kdep) :: &
-         & kkco                 ! Array indicies for interpolation
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kdep) :: &
-         & pobsdep              ! Depth of the observation
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
-         & pobsk,  &            ! Model profile at a given (lon,lat)
-         & pobs2k, &            ! 2nd derivative of the interpolating function
-         & pdep,   &            ! Model depth array
-         & pobsmask             ! Vertical mask
-      REAL(KIND=wp), INTENT(OUT), DIMENSION(kdep) :: &
-         & pobs                 ! Model equivalent at observation point
-  
-      !! * Local declarations
-      REAL(KIND=wp) :: z1dm       ! Distance above and below obs to model grid points
-      REAL(KIND=wp) :: z1dp         
-      REAL(KIND=wp) :: zsum       ! Dummy variables for computation
-      REAL(KIND=wp) :: zsum2
-      INTEGER :: jdep             ! Observation depths loop variable
-    
-      !------------------------------------------------------------------------
-      ! Loop over all observation depths
-      !------------------------------------------------------------------------
-
-      DO jdep = 1, kdep
-
-         !---------------------------------------------------------------------
-         ! Initialization
-         !---------------------------------------------------------------------
-         z1dm = ( pdep(kkco(jdep)) - pobsdep(jdep)      )
-         z1dp = ( pobsdep(jdep)    - pdep(kkco(jdep)-1) )
-         IF ( pobsmask(kkco(jdep)) == 0.0_wp ) z1dp = 0.0_wp
-
-         zsum = z1dm + z1dp
-         
-         IF ( k1dint == 0 ) THEN
-
-            !-----------------------------------------------------------------
-            !  Linear interpolation
-            !-----------------------------------------------------------------
-            pobs(jdep) = (   z1dm * pobsk(kkco(jdep)-1) &
-               &           + z1dp * pobsk(kkco(jdep)  ) ) / zsum
-
-         ELSEIF ( k1dint == 1 ) THEN
-
-            !-----------------------------------------------------------------
-            ! Cubic spline interpolation
-            !-----------------------------------------------------------------
-            zsum2 = zsum * zsum
-            pobs(jdep)  = (  z1dm                             * pobsk (kkco(jdep)-1) &
-               &           + z1dp                             * pobsk (kkco(jdep)  ) &
-               &           + ( z1dm * ( z1dm * z1dm - zsum2 ) * pobs2k(kkco(jdep)-1) &
-               &           +   z1dp * ( z1dp * z1dp - zsum2 ) * pobs2k(kkco(jdep)  ) &
-               &             ) / 6.0_wp                                              &
-               &          ) / zsum
-
-         ENDIF
-      END DO
-
-   END SUBROUTINE obs_int_z1d
-
-   SUBROUTINE obs_int_z1d_spl( kpk, pobsk, pobs2k, &
-      &                        pdep, pobsmask )
-      !!--------------------------------------------------------------------
-      !!
-      !!                  *** ROUTINE obs_int_z1d_spl ***
-      !!
-      !! ** Purpose : Compute the local vector of vertical second-derivatives 
-      !!              of the interpolating function used with a cubic spline.
-      !!  
-      !! ** Method  : 
-      !! 
-      !!    Top and bottom boundary conditions on the 2nd derivative are
-      !!    set to zero.
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History
-      !!      ! 01-11 (A. Weaver, S. Ricci, N. Daget)
-      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
-      !!      ! 06-10 (A. Weaver) Cleanup
-      !!----------------------------------------------------------------------
-     
-      !! * Arguments
-      INTEGER, INTENT(IN) :: kpk               ! Number of vertical levels
-      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
-         & pobsk, &          ! Model profile at a given (lon,lat)
-         & pdep,  &          ! Model depth array
-         & pobsmask          ! Vertical mask
-      REAL(KIND=wp), INTENT(OUT), DIMENSION(kpk) :: &
-         & pobs2k            ! 2nd derivative of the interpolating function
-  
-      !! * Local declarations
-      INTEGER :: jk
-      REAL(KIND=wp) :: za
-      REAL(KIND=wp) :: zb
-      REAL(KIND=wp) :: zc
-      REAL(KIND=wp) :: zpa
-      REAL(KIND=wp) :: zkm
-      REAL(KIND=wp) :: zkp
-      REAL(KIND=wp) :: zk
-      REAL(KIND=wp), DIMENSION(kpk-1) :: &
-         & zs, &
-         & zp, &
-         & zu, &
-         & zv
-
-      !-----------------------------------------------------------------------
-      ! Matrix initialisation
-      !-----------------------------------------------------------------------
-      zs(1) =  0.0_wp
-      zp(1) =  0.0_wp
-      zv(1) = -0.5_wp
-      DO jk = 2, kpk-1
-         zs(jk) =  ( pdep(jk  ) - pdep(jk-1) ) &
-            &    / ( pdep(jk+1) - pdep(jk-1) )
-         zp(jk) = zs(jk) * zv(jk-1) + 2.0_wp
-         zv(jk) = ( zs(jk) - 1.0_wp ) / zp(jk)
-      END DO
- 
-      !-----------------------------------------------------------------------
-      ! Solution of the tridiagonal system
-      !-----------------------------------------------------------------------
- 
-      ! Top boundary condition
-      zu(1) = 0.0_wp
- 
-      DO jk = 2, kpk-1
-         za = pdep(jk+1) - pdep(jk-1)
-         zb = pdep(jk+1) - pdep(jk  )
-         zc = pdep(jk  ) - pdep(jk-1)
- 
-         zpa = 6.0_wp / ( zp(jk) * za )
-         zkm = zpa / zc
-         zkp = zpa / zb
-         zk  = - ( zkm + zkp )
-  
-         zu(jk) =  pobsk(jk+1) * zkp  &
-            &    + pobsk(jk  ) * zk   &
-            &    + pobsk(jk-1) * zkm  &
-            &    + zu(jk-1) * ( -zs(jk) / zp(jk) )
-      END DO
- 
-      !-----------------------------------------------------------------------
-      ! Second derivative
-      !-----------------------------------------------------------------------
-      pobs2k(kpk) = 0.0_wp
- 
-      ! Bottom boundary condition
-      DO jk = kpk-1, 1, -1
-         pobs2k(jk) = zv(jk) * pobs2k(jk+1) + zu(jk)
-         IF ( pobsmask(jk+1) == 0.0_wp ) pobs2k(jk) = 0.0_wp
-      END DO
- 
-  END SUBROUTINE obs_int_z1d_spl
-
-
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_prof_io.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_prof_io.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_prof_io.F90	(revision 2202)
@@ -22,5 +22,5 @@
 CONTAINS
 
-#include "obs_prof_io.h90"
+#include "obsprof_io.h90"
 
 END MODULE obs_prof_io
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_prof_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_prof_io.h90	(revision 2199)
+++ 	(revision )
@@ -1,829 +1,0 @@
-
-   SUBROUTINE read_enactfile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the profile ENACT observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                      ! Number of levels
-      INTEGER :: i_file_id
-      INTEGER :: i_obs_id
-      INTEGER :: i_lev_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_pl_num_id
-      INTEGER :: i_reference_date_time_id
-      INTEGER :: i_format_version_id
-      INTEGER :: i_juld_id
-      INTEGER :: i_data_type_id
-      INTEGER :: i_wmo_inst_type_id
-      INTEGER :: i_qc_var_id
-      INTEGER :: i_dc_ref_id
-      INTEGER :: i_qc_flag_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth 
-      CHARACTER(LEN=40) :: cl_fld_var_tp
-      CHARACTER(LEN=40) :: cl_fld_var_s
-      CHARACTER(LEN=40) :: cl_fld_var_ti
-      CHARACTER(LEN=40) :: cl_fld_var_juld_qc
-      CHARACTER(LEN=40) :: cl_fld_var_pos_qc
-      CHARACTER(LEN=40) :: cl_fld_var_depth_qc 
-      CHARACTER(LEN=40) :: cl_fld_var_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_qc_s
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_t
-      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_s
-      CHARACTER(LEN=40) :: cl_fld_reference_date_time
-      CHARACTER(LEN=40) :: cl_fld_juld
-      CHARACTER(LEN=40) :: cl_fld_data_type
-      CHARACTER(LEN=40) :: cl_fld_pl_num
-      CHARACTER(LEN=40) :: cl_fld_format_version
-      CHARACTER(LEN=40) :: cl_fld_wmo_inst_type
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_profiles
-      CHARACTER(LEN=40) :: cl_fld_qc_flags_levels
-
-      CHARACTER(LEN=14), PARAMETER :: cl_name = 'read_enactfile'
-      CHARACTER(LEN=16)            :: cl_data_type = ''
-      CHARACTER(LEN=4 )            :: cl_format_version = ''
-      INTEGER, DIMENSION(1) :: istart1, icount1
-      INTEGER, DIMENSION(2) :: istart2, icount2
-      CHARACTER(len=imaxlev) :: clqc
-      CHARACTER(len=1) :: cqc
-      INTEGER :: ji, jk
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: iqc1
-      INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iqc2
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      cl_fld_lam                 = 'LONGITUDE'
-      cl_fld_phi                 = 'LATITUDE'
-      cl_fld_depth               = 'DEPH_CORRECTED'
-      cl_fld_reference_date_time = 'REFERENCE_DATE_TIME'
-      cl_fld_juld                = 'JULD'
-      cl_fld_data_type           = 'DATA_TYPE'
-      cl_fld_format_version      = 'FORMAT_VERSION'
-      cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-      cl_fld_pl_num              = 'PLATFORM_NUMBER'
-
-      cl_fld_var_qc_t            = 'POTM_CORRECTED_QC'
-      cl_fld_var_prof_qc_t       = 'PROFILE_POTM_QC'
-      cl_fld_var_tp              = 'POTM_CORRECTED'
-      cl_fld_var_qc_s            = 'PSAL_CORRECTED_QC'
-      cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-      cl_fld_var_s               = 'PSAL_CORRECTED'
-      cl_fld_var_depth_qc        = 'DEPH_CORRECTED_QC'
-      cl_fld_var_juld_qc         = 'JULD_QC'
-      cl_fld_var_pos_qc          = 'POSITION_QC'
-      cl_fld_var_ti              = 'TEMP'
-      cl_fld_qc_flags_profiles   = 'QC_FLAGS_PROFILES'
-      cl_fld_qc_flags_levels     = 'QC_FLAGS_LEVELS'
-
-      icount1(1) = 1 
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_data_type,      &
-         &         i_data_type_id ),      cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_data_type_id,        &
-         &         cl_data_type ),        cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_format_version, &
-         &         i_format_version_id ), cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_format_version_id,   &
-         &         cl_format_version ),   cl_name, __LINE__ )
-      
-      CALL str_c_to_for( cl_data_type )
-      CALL str_c_to_for( cl_format_version )
-      
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_enactfile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Data type           = ', &
-         &                TRIM( ADJUSTL( cl_data_type ) )
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ',  &
-         &                TRIM( ADJUSTL( cl_format_version ) )
-      
-      IF ( ( ( INDEX( cl_data_type,"ENACT v1.0" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.4" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENACT v1.5" ) == 1 ) .OR.   &
-         &   ( INDEX( cl_data_type,"ENSEMBLES EN3 v1" ) == 1 )      ) &
-         &   .AND.                                              &
-         &   ( INDEX( cl_format_version,"2.0"   ) == 1 ) ) THEN
-         IF(ldwp)WRITE(kunit,*)'               Valid input file'
-      ELSE
-         CALL fatal_error( 'Invalid input file', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_PROF', i_obs_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_LEVELS', i_lev_id ),     &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-
-      !---------------------------------------------------------------------
-      ! Read the QC atributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )        
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ),                         &
-         &         cl_name, __LINE__ )
-      DO ji = 1, iobs
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      ! No depth QC in files
-      DO ji = 1, iobs
-         DO jk = 1, ilev
-            inpfile%idqc(jk,ji)  = 1
-            inpfile%idqcf(:,jk,ji) = 0
-         END DO
-      END DO
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                    & 
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-!!      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_juld_qc, i_qc_var_id ),                       &
-!!         &         cl_name, __LINE__ ) 
-!!      !DO ji = 1,iobs
-!!         istart1(1) = ji
-!!         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-!!            &                         start = istart1, count = icount1),                              &
-!!            &         cl_name, __LINE__ )
-!!         inpfile%itqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-!!         inpfile%itqcf(:,ji) = 0
-!!      END DO
-      ! Since the flags are not set in the ENACT files we reset them to 0
-      inpfile%itqc(:)    = 1      
-      inpfile%itqcf(:,:) = 0
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
-         inpfile%ipqcf(:,ji) = 0
-      END DO
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_profiles, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc1(iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc1 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            inpfile%ioqcf(1,ji)   = iqc1(ji)
-            inpfile%ivqcf(1,ji,:) = iqc1(ji)
-            inpfile%ioqcf(2,ji)   = 0
-            inpfile%ivqcf(2,ji,:) = 0
-         END DO
-         DEALLOCATE( &
-            & iqc1 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC profile flags in file'
-         inpfile%ioqcf(:,:)   = 0
-         inpfile%ivqcf(:,:,:) = 0
-      ENDIF
-      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_levels, i_qc_flag_id ) == nf90_noerr ) THEN
-         ALLOCATE( &
-            & iqc2(ilev,iobs) &
-            & )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc2 ),                                &
-            &         cl_name, __LINE__ )
-         DO ji = 1,iobs
-            DO jk = 1,ilev
-               inpfile%ivlqcf(1,jk,ji,:) = iqc2(jk,ji)
-               inpfile%ivlqcf(2,jk,ji,:) = 0
-            END DO
-         END DO
-         DEALLOCATE( &
-            & iqc2 &
-            & )
-      ELSE
-         IF(ldwp) WRITE(kunit,*)'No QC level flags in file'
-         inpfile%ivlqcf(:,:,:,:) = 0
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                             &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_reference_date_time, i_reference_date_time_id ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_reference_date_time_id, inpfile%cdjuldref ),          &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_tp, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,1) ),                         &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                         &
-         &         cl_name, __LINE__ )
- 
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_ti, i_var_id ),                              &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-
-   END SUBROUTINE read_enactfile
-
-   SUBROUTINE read_coriofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_coriofile **
-      !!
-      !! ** Purpose : Read from file the profile CORIO observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output enactfile structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      INTEGER  :: &
-         & iobs, &
-         & ilev
-      !! * Local declarations
-      INTEGER :: &
-         & i_file_id,                &
-         & i_obs_id,                 &
-         & i_lev_id,                 &
-         & i_phi_id,                 & 
-         & i_lam_id,                 &
-         & i_depth_id,               &
-         & i_pres_id,                &
-         & i_var_id,                 &
-         & i_pl_num_id,              &
-         & i_format_version_id,      &
-         & i_juld_id,                &
-         & i_data_type_id,           &
-         & i_wmo_inst_type_id,       &
-         & i_qc_var_id,              &
-         & i_dc_ref_id
-      CHARACTER(LEN=40) :: & 
-         & cl_fld_lam,                 &
-         & cl_fld_phi,                 &
-         & cl_fld_depth,               & 
-         & cl_fld_depth_qc,            & 
-         & cl_fld_pres,                & 
-         & cl_fld_pres_qc,             & 
-         & cl_fld_var_t,               &
-         & cl_fld_var_s,               &
-         & cl_fld_var_ti,              &
-         & cl_fld_var_pos_qc,          &
-         & cl_fld_var_qc_t,            &
-         & cl_fld_var_qc_s,            &
-         & cl_fld_var_prof_qc_t,       &
-         & cl_fld_var_prof_qc_s,       &
-         & cl_fld_dc_ref,              &
-         & cl_fld_juld,                &
-         & cl_fld_pl_num,              &
-         & cl_fld_wmo_inst_type
-      CHARACTER(LEN=14), PARAMETER :: &
-         & cl_name = 'read_coriofile'
-      CHARACTER(LEN=4 )            :: &
-         & cl_format_version = ''
-      INTEGER, DIMENSION(1) :: &
-         & istart1, icount1
-      INTEGER, DIMENSION(2) :: &
-         & istart2, icount2
-      CHARACTER(len=imaxlev) :: &
-         & clqc
-      CHARACTER(len=1) :: &
-         & cqc
-      CHARACTER(len=256) :: &
-         & cdjulref
-      INTEGER :: &
-         & ji, jk
-      INTEGER :: &
-         & iformat
-      LOGICAL :: & 
-         & lsal
-      REAL(fbdp), DIMENSION(:,:), ALLOCATABLE :: &
-         & zpres
-      INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
-         & ipresqc
-      CHARACTER(len=256) :: &
-         & cerr
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-
-      icount1(1) = 1 
-      lsal = .TRUE.
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Check format and set variables accordingly
-      !-----------------------------------------------------------------------
-
-      IF ( ( nf90_inq_dimid( i_file_id, 'N_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'N_LEVELS', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 1
-      ELSEIF ( ( nf90_inq_dimid( i_file_id, 'mN_PROF', i_obs_id ) == nf90_noerr ) .AND. &
-         & ( nf90_inq_dimid( i_file_id, 'mN_ZLEV', i_lev_id ) == nf90_noerr ) ) THEN
-         iformat = 2
-      ELSE
-         WRITE(cerr,'(2A)')'Invalid data format in ',cl_name
-         CALL fatal_error( cerr, __LINE__ )
-      ENDIF
-      IF ( iformat == 1 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'DEPH_QC'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'PRES_QC'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
-         cl_fld_dc_ref              = 'DC_REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'TEMP_QC'
-         cl_fld_var_prof_qc_t       = 'PROFILE_TEMP_QC'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'PSAL_QC'
-         cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'POSITION_QC'
-      ELSEIF ( iformat==2 ) THEN
-         cl_fld_lam                 = 'LONGITUDE'
-         cl_fld_phi                 = 'LATITUDE'  
-         cl_fld_depth               = 'DEPH'
-         cl_fld_depth_qc            = 'QC_DEPH'
-         cl_fld_pres                = 'PRES'
-         cl_fld_pres_qc             = 'QC_PRES'
-         cl_fld_juld                = 'JULD'
-         cl_fld_wmo_inst_type       = 'INST_TYPE'
-         cl_fld_dc_ref              = 'REFERENCE'
-         cl_fld_pl_num              = 'PLATFORM_NUMBER'
-         cl_fld_var_qc_t            = 'QC_TEMP'
-         cl_fld_var_prof_qc_t       = 'Q_PROFILE_TEMP'
-         cl_fld_var_t               = 'TEMP'
-         cl_fld_var_qc_s            = 'QC_PSAL'
-         cl_fld_var_prof_qc_s       = 'Q_PROFILE_PSAL'
-         cl_fld_var_s               = 'PSAL'
-         cl_fld_var_pos_qc          = 'Q_POSITION'
-      ENDIF
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-
-      IF(ldwp)WRITE(kunit,*)
-      IF(ldwp)WRITE(kunit,*) ' read_coriofile :' 
-      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
-      IF(ldwp)WRITE(kunit,*) '               Format version      = ', iformat
-
-      !---------------------------------------------------------------------
-      ! Read the number of observations and levels to allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
-         &         cl_name, __LINE__ )
-      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-      IF (ilev > imaxlev) THEN
-         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
-      inpfile%cname(1) = 'POTM'
-      inpfile%cname(2) = 'PSAL'
-      inpfile%coblong(1) = 'Potential temperature'
-      inpfile%coblong(2) = 'Practical salinity'
-      inpfile%cobunit(1) = 'Degrees Celsius'
-      inpfile%cobunit(2) = 'PSU'
-      inpfile%cextname(1) = 'TEMP'
-      inpfile%cextlong(1) = 'Insitu temperature'
-      inpfile%cextunit(1) = 'Degrees Celsius'
-      ALLOCATE( &
-         & zpres(ilev,iobs),  &
-         & ipresqc(ilev,iobs) &
-         & )
-      !---------------------------------------------------------------------
-      ! Get julian data reference (iformat==2)
-      !---------------------------------------------------------------------
-
-      IF (iformat==2) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, nf90_global, &
-            &                        "Reference_date_time", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(7:10)//cdjulref(4:5)// &
-            & cdjulref(1:2)//cdjulref(12:13)//cdjulref(15:16)//cdjulref(18:19)
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                                &
-         &         cl_name, __LINE__ )
-      istart2(1) = 1
-      icount2(2) = 1
-      icount2(1) = ilev
-      DO ji = 1, iobs 
-         istart2(2) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
-            &                         start = istart2, count = icount2),                              &
-            &         cl_name, __LINE__ )
-         DO jk = 1, ilev
-            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-         END DO
-      END DO
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ) == nf90_noerr ) THEN
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%ivlqc(:,:,2) = 4
-         inpfile%pob(:,:,2) = fbrmdi
-         lsal = .FALSE.
-      ENDIF
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
-         &         cl_name,  __LINE__ )
-      DO ji = 1,iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      IF (lsal) THEN
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                 & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1,iobs
-            istart1(1) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                 &
-               &                         start = istart1, count = icount1),                           &
-               &         cl_name, __LINE__ )
-            inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
-         END DO
-      ELSE
-         inpfile%ivqc(:,2) = 4
-      ENDIF
-      DO ji = 1,iobs
-         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
-      END DO
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
-         &         cl_name, __LINE__ ) 
-      DO ji = 1, iobs
-         istart1(1) = ji
-         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
-            &                         start = istart1, count = icount1),                              &
-            &         cl_name, __LINE__ )
-         inpfile%ipqc(ji)  = IACHAR( cqc ) - IACHAR( '0' )
-      END DO
-      
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
-         &         cl_name, __LINE__ )
-      IF (iformat==1) THEN
-         CALL chkerr ( nf90_get_att( i_file_id, i_juld_id, &
-            &                        "units", cdjulref ), &
-            &         cl_name, __LINE__ )
-         inpfile%cdjuldref = cdjulref(12:15)//cdjulref(17:18)// &
-            & cdjulref(20:21)//cdjulref(23:24)//cdjulref(26:27)//&
-            & cdjulref(29:30)
-      ENDIF
-      
-      IF ( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                          &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth_qc, i_qc_var_id ),                      & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               inpfile%idqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         inpfile%pdep(:,:) = fbrmdi
-         inpfile%idqc(:,:) = 4
-      ENDIF
-
-      IF ( nf90_inq_varid( i_file_id, cl_fld_pres, i_pres_id ) == nf90_noerr ) THEN
-         CALL chkerr( nf90_get_var  ( i_file_id, i_pres_id, zpres ),                                  &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pres_qc, i_qc_var_id ),                       & 
-            &         cl_name, __LINE__ ) 
-         DO ji = 1, iobs
-            istart2(2) = ji
-            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
-               &                         start = istart2, count = icount2),                           &
-               &         cl_name, __LINE__ )
-            DO jk = 1, ilev
-               ipresqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
-            END DO
-         END DO
-      ELSE
-         zpres(:,:) = fbrmdi
-         ipresqc(:,:) = 4
-      ENDIF
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the platform information
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
-         &         cl_name, __LINE__ )          
-      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
-         &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
-         &         cl_name, __LINE__ )         
-
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_t, i_var_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
-         &         cl_name, __LINE__ )
-
-      IF (lsal) THEN      
-         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                            &
-            &         cl_name, __LINE__ )
-         CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                      &
-            &         cl_name, __LINE__ )
-      ENDIF
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-         
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         inpfile%kindex(ji) = ji
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Coriolis data conversion from insitu to potential temperature
-      !---------------------------------------------------------------------
-      !---------------------------------------------------------------------
-      !  Convert pressure to depth if depth not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( inpfile%pdep(jk,ji) >= 9999.0 ) THEN
-                  IF ( zpres(jk,ji) < 9999.0 ) THEN
-                     inpfile%pdep(jk,ji) = &
-                        & p_to_dep( REAL(zpres(jk,ji),wp), REAL(inpfile%pphi(ji),wp) )
-                     inpfile%idqc(jk,ji) = ipresqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert depth to pressure if pressure not present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
-            DO jk = 1, inpfile%nlev
-               IF ( zpres(jk,ji) >= 9999.0 ) THEN
-                  IF ( inpfile%pdep(jk,ji) < 9999.0 ) THEN
-                     zpres(jk,ji) = dep_to_p( REAL(inpfile%pdep(jk,ji),wp), &
-                        &                            REAL(inpfile%pphi(ji),wp) )
-                     ipresqc(jk,ji) = inpfile%idqc(jk,ji)
-                  ENDIF
-               ENDIF
-            END DO
-         ENDIF
-      END DO
-      
-      !---------------------------------------------------------------------
-      !  Convert insitu temperature to potential temperature if
-      !  salinity, insitu temperature and pressure are present
-      !---------------------------------------------------------------------
-      DO ji = 1, inpfile%nobs
-         DO jk = 1, inpfile%nlev
-            IF (( inpfile%pob(jk,ji,2) < 9999.0 ) .AND. &
-               &( inpfile%pext(jk,ji,1) < 9999.0 ) .AND. &
-               &( zpres(jk,ji) < 9999.0 ) ) THEN
-               inpfile%pob(jk,ji,1) = potemp( REAL(inpfile%pob(jk,ji,2), wp),  &
-                  &                           REAL(inpfile%pext(jk,ji,1), wp), &
-                  &                           REAL(zpres(jk,ji),wp),  &
-                  &                           0.0_wp )
-            ELSE
-               inpfile%pob(jk,ji,1) = fbrmdi
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      !  Initialize flags since they are not in the CORIOLIS input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-   END SUBROUTINE read_coriofile
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_seaice_io.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_seaice_io.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_seaice_io.F90	(revision 2202)
@@ -20,5 +20,5 @@
 CONTAINS
 
-#include "obs_seaice_io.h90"
+#include "obsseaice_io.h90"
 
 END MODULE obs_seaice_io
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_seaice_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_seaice_io.h90	(revision 2199)
+++ 	(revision )
@@ -1,264 +1,0 @@
-   SUBROUTINE read_seaice( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_seaice **
-      !!
-      !! ** Purpose : Read from file the SEAICE observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_seaice'
-      INTEGER :: i_file_id    ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data       ! Number of data per parameter in current file
-      INTEGER :: i_time       ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of seaice measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_seaice         ! Seaice data     
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen          ! Length of netCDF attributes
-      INTEGER :: itype          ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca      ! Scale factor
-      REAL(KIND=wp) :: zoff      ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset  ! Offset for time conversion
-      REAL(KIND=wp) :: zfill     ! Fill value in netcdf file
-      CHARACTER (len=33) ::creftime     ! Reference time of file
-      INTEGER :: i_refyear       ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_seaice        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SeaIce_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get seaice data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_ice_concentration', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_seaice), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_seaice(:,:) /=  zfill)
-         z_seaice(:,:) = (zsca * z_seaice(:,:)) + zoff
-      ELSEWHERE
-         z_seaice(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get seaice obs type
-      
-      i_type(:,:)=1
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SEAICE'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'seaice','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_seaice(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_seaice(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-   END SUBROUTINE read_seaice
-
-
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_io.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_io.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_io.F90	(revision 2202)
@@ -20,5 +20,5 @@
 CONTAINS
 
-#include "obs_sla_io.h90"
+#include "obssla_io.h90"
 
 END MODULE obs_sla_io
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_io.h90	(revision 2199)
+++ 	(revision )
@@ -1,372 +1,0 @@
-   SUBROUTINE read_avisofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_avisofile **
-      !!
-      !! ** Purpose : Read from file the AVISO SLA observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : http://www.aviso.oceanobs.com
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=14),PARAMETER :: cpname = 'read_avisofile'
-      INTEGER :: i_file_id     ! netcdf IDS
-      INTEGER :: i_tracks_id
-      INTEGER :: i_cycles_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
-      INTEGER :: iilen         ! Length of netCDF attributes
-      INTEGER :: itype         ! Typeof netCDF attributes
-      REAL(fbdp) :: zsca       ! Scale factor
-      REAL(fbdp) :: zfill      ! Fill value
-      CHARACTER(len=3) ::  cmission      ! Mission global attribute
-      INTEGER :: itracks       ! Maximum number of passes in file
-      INTEGER :: icycles       ! Maximum number of cycles for each pass
-      INTEGER :: idata         ! Number of data per parameter in current file
-      REAL(fbdp) :: zdeltat    ! Time gap getween two measurements in seconds
-      INTEGER, DIMENSION(:), POINTER :: & 
-         & iptracks,     &  ! List of passes contained in current file
-         & ipnbpoints,   &  ! Number of points per pass
-         & ipdataindexes    ! Index of data in theoretical profile
-      INTEGER, DIMENSION(:,:), POINTER :: & 
-         & ipcycles         ! List of cycles per pass
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zphi,   &        ! Latitudes
-         & zlam             ! Longitudes
-      REAL(fbdp), DIMENSION(:,:), POINTER :: &
-         & zbegindates      ! Date of point with index 0
-      REAL(fbdp) :: zbeginmiss    ! Missing data for dates
-      REAL(fbsp), DIMENSION(:,:), POINTER :: &
-         & zsla             ! SLA data
-      REAL(fbdp), DIMENSION(:), POINTER :: &
-         & zjuld            ! Julian date
-      LOGICAL, DIMENSION(:), POINTER :: &
-         & llskip           ! Skip observation
-      CHARACTER(len=14) :: cdjuldref    ! Julian data reference
-      INTEGER :: imission   ! Mission number converted from Mission global 
-                            ! netCDF atttribute.
-      CHARACTER(len=255) :: ctmp
-      INTEGER :: iobs
-      INTEGER :: jl
-      INTEGER :: jm
-      INTEGER :: jj
-      INTEGER :: ji
-      INTEGER :: jk
-      INTEGER :: jobs
-      INTEGER :: jcycle
-
-      ! Open the file
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, i_file_id ), &
-         &         cpname, __LINE__ )
-
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Tracks', i_tracks_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_tracks_id, &
-         &                                 len = itracks ),  &
-         &         cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Cycles', i_cycles_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_cycles_id, &
-         &                                 len = icycles ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'Data', i_data_id ),  &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_data_id, &
-         &                                 len = idata ),  &
-         &         cpname, __LINE__ )
-
-      ! Allocate memory for input data
-
-      ALLOCATE( &
-         & iptracks     ( itracks          ), &  
-         & ipnbpoints   ( itracks          ), &  
-         & ipcycles     ( icycles, itracks ), &
-         & zphi         ( idata            ), &   
-         & zlam         ( idata            ), &  
-         & zbegindates  ( icycles, itracks ), &
-         & ipdataindexes( idata            ), & 
-         & zsla         ( icycles, idata   ), &
-         & zjuld        ( idata*icycles    ), &
-         & llskip       ( idata*icycles    )  &
-         & )
-
-      ! Get time gap getween two measurements in seconds
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DeltaT', i_var_id ), & 
-         &         cpname, __LINE__ )
-      CALL chkdim( i_file_id, i_var_id, 0, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zdeltat), &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zdeltat = zsca * zdeltat
-         
-      ! Get List of passes contained in current file      
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Tracks', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, iptracks), &
-         &         cpname, __LINE__ )
-      
-      ! Get Number of points per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'NbPoints', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = itracks
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipnbpoints),&
-         &         cpname, __LINE__ )
-      
-      ! Get list of cycles per pass
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Cycles', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipcycles),   &
-         &         cpname, __LINE__ )
-
-      ! Get longitudes
-
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Longitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zlam),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                         == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zlam(:) = zsca * zlam(:)
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'Latitudes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zphi),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     'scale_factor',zsca), cpname,  __LINE__)
-      ENDIF
-      zphi(:) = zsca * zphi(:)
-      
-      ! Get date of point with index 0
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'BeginDates', i_var_id ), & 
-         &        cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = itracks
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zbegindates), &
-         &         cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, &
-         &                                 'units', len = iilen,  &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 255 )) THEN
-         CALL fatal_error('Error decoding BeginDates unit', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, 'units', &
-         &                       ctmp ), cpname, __LINE__ )
-      jl=1
-      DO jm = 1, LEN(TRIM(ctmp))
-         IF ((ctmp(jm:jm)>='0').AND.(ctmp(jm:jm)<='9')) THEN
-            cdjuldref(jl:jl) = ctmp(jm:jm)
-            jl=jl+1
-         ENDIF
-         IF (jl>14) EXIT
-      END DO
-      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue', &
-         &                                  xtype = itype), cpname, __LINE__ )
-      IF ( itype /= NF90_DOUBLE ) THEN
-         CALL fatal_error('Error decoding BeginDates missing data', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, i_var_id, '_FillValue', &
-         &                       zbeginmiss ), cpname, __LINE__ )
-
-      ! Get indices of data in theoretical profile
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'DataIndexes', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = idata
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipdataindexes),   &
-         &       cpname, __LINE__ )
-      
-      ! Get SLA data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'SLA', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = icycles
-      idims(2) = idata
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zsla),   &
-         &         cpname, __LINE__ )
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
-         &                        == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       'scale_factor',zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue') &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     '_FillValue',zfill), cpname,  __LINE__ )
-      ENDIF
-      WHERE(zsla(:,:) /=  zfill)
-         zsla(:,:) = zsca * zsla(:,:)
-      ELSEWHERE
-         zsla(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get the global Mission netCDF attribute
-      
-      cmission='   '
-      CALL chkerr( nf90_inquire_attribute( i_file_id, nf90_global, &
-         &                                 'Mission', len = iilen,  &
-         &                                 xtype = itype), cpname, __LINE__ )
-      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 3 )) THEN
-         CALL fatal_error('Error decoding Mission global attribute', __LINE__ )
-      ENDIF
-      CALL chkerr( nf90_get_att( i_file_id, nf90_global, 'Mission', &
-         &                       cmission ), cpname, __LINE__ )
-      
-      ! Convert it to an integer
-      imission = 0
-      DO jm = 1, imaxmissions
-         IF (cmission==cmissions(jm)) THEN
-            imission = jm
-            EXIT
-         ENDIF
-      END DO
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Compute Julian dates for all observations
-      
-      jm = 0
-      jl = 0
-      DO jj = 1, itracks
-         DO ji = 1, ipnbpoints(jj)
-            jl = jl + 1
-            DO jk = 1, icycles
-               jm = jm + 1
-               IF (zbegindates(jk,jj)==zbeginmiss) THEN
-                  llskip(jm) = .TRUE.
-                  zjuld(jm)  = fbrmdi
-               ELSE
-                  llskip(jm) = .FALSE.
-                  zjuld(jm)  = zbegindates(jk,jj) + &
-                     &         (ipdataindexes(jl) * zdeltat / 86400._wp )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Get rid of missing data
-
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (zsla(jcycle,jobs) == fbrmdi) llskip(jm) = .TRUE.
-         END DO
-      END DO
-      
-      ! Allocate obfbdata
-
-      iobs = COUNT( .NOT.llskip(:) )
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SLA'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = cdjuldref
-      iobs = 0
-      jm = 0
-      DO jobs = 1, idata
-         DO jcycle = 1, icycles
-            jm = jm + 1
-            IF (llskip(jm)) CYCLE
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A3,A5)') cmissions(imission), '     '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') imission
-            ! Real values
-            inpfile%plam(iobs)         = zlam(jobs)
-            inpfile%pphi(iobs)         = zphi(jobs)
-            inpfile%pob(1,iobs,1)      = zsla(jcycle,jobs)
-            inpfile%ptim(iobs)         = zjuld(jm)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            inpfile%ioqc(iobs)      = 1
-            inpfile%ivqc(iobs,1)    = 1
-            inpfile%ivlqc(1,iobs,1) = 1
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-
-      ! Deallocate memory for input data
-
-      DEALLOCATE( &
-         & iptracks,      &
-         & ipnbpoints,    &
-         & ipcycles,      &
-         & zphi,          &
-         & zlam,          &  
-         & zbegindates,   &
-         & ipdataindexes, &
-         & zsla,          &
-         & zjuld,         &
-         & llskip         &
-         & )
-
-   END SUBROUTINE read_avisofile
-
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_types.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_types.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_types.F90	(revision 2202)
@@ -11,5 +11,5 @@
    IMPLICIT NONE
 
-#include "obs_sla_types.h90"
+#include "obssla_types.h90"
 
 END MODULE obs_sla_types
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_types.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sla_types.h90	(revision 2199)
+++ 	(revision )
@@ -1,3 +1,0 @@
-   INTEGER, PARAMETER :: imaxmissions=8
-   CHARACTER(len=3) :: cmissions(0:imaxmissions) = &
-      & (/ 'XXX', 'E1 ', 'E2 ', 'TP ', 'TPM', 'G2 ', 'J1 ', 'EN ', 'J2 ' /)
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sst_io.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sst_io.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sst_io.F90	(revision 2202)
@@ -20,5 +20,5 @@
 CONTAINS
 
-#include "obs_sst_io.h90"
+#include "obssst_io.h90"
 
 END MODULE obs_sst_io
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sst_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_sst_io.h90	(revision 2199)
+++ 	(revision )
@@ -1,280 +1,0 @@
-   SUBROUTINE read_ghrsst( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_ghrsst **
-      !!
-      !! ** Purpose : Read from file the GHRSST observations.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! References : 
-      !!
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original based on old versions
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_ghrsst'
-      INTEGER :: i_file_id        ! netcdf IDS
-      INTEGER :: i_time_id
-      INTEGER :: i_ni_id
-      INTEGER :: i_data_id
-      INTEGER :: i_var_id
-      INTEGER :: i_data           ! Number of data per parameter in current file
-      INTEGER :: i_time           ! Number of reference times in file
-      INTEGER, DIMENSION(:), POINTER :: &
-         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
-      INTEGER, DIMENSION(:,:), POINTER :: &
-         & i_dtime, &       ! Offset in seconds since reference time
-         & i_qc,    &       ! Quality control flag.
-         & i_type           ! Type of SST measurement.            
-      REAL(wp), DIMENSION(:), POINTER :: &
-         & z_phi,   &       ! Latitudes
-         & z_lam            ! Longitudes
-      REAL(wp), DIMENSION(:,:), POINTER :: &
-         & z_sst            ! SST data     
-      INTEGER, PARAMETER :: imaxdim = 2      ! Assumed maximum for no. dims. in file
-      INTEGER, DIMENSION(2) :: idims         ! Dimensions in file
-      INTEGER :: iilen            ! Length of netCDF attributes
-      INTEGER :: itype            ! Typeof netCDF attributes
-      REAL(KIND=wp) :: zsca           ! Scale factor
-      REAL(KIND=wp) :: zoff           ! Offset for data in netcdf file
-      REAL(KIND=wp) :: z_offset       ! Offset for time conversion
-      REAL(KIND=wp) :: zfill          ! Fill value in netcdf file
-      CHARACTER (len=33) :: creftime  ! Reference time of file
-      INTEGER :: i_refyear            ! Integer version of reference time
-      INTEGER :: i_refmonth
-      INTEGER :: i_refday
-      INTEGER :: i_refhour
-      INTEGER :: i_refmin
-      INTEGER :: i_refsec
-      INTEGER :: ichunk
-      INTEGER :: jtim
-      INTEGER :: jobs
-      INTEGER :: iobs
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
-      
-      ! Get the netCDF dimensions
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
-         &                              len = i_time ),  &
-         &      cpname, __LINE__ )
-      
-      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
-         &       cpname, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
-         &                              len = i_data ),  &
-         &      cpname, __LINE__ )
-      
-      
-      ! Allocate NetCDF variables
-      
-      ALLOCATE( &
-         & i_reftime    ( i_time                 ), &
-         & i_dtime      ( i_data,i_time  ), &      
-         & i_qc         ( i_data,i_time  ), & 
-         & i_type       ( i_data,i_time  ), &     
-         & z_phi        ( i_data                 ), &   
-         & z_lam        ( i_data                 ), &  
-         & z_sst        ( i_data,i_time  )  &
-         & )
-      
-      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_time
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
-         &       cpname, __LINE__ )
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "units",creftime), cpname,  __LINE__ )
-      ELSE
-         creftime = "seconds since 1981-01-01 00:00:00"
-      ENDIF
-      READ(creftime(15:18),*)i_refyear
-      READ(creftime(20:21),*)i_refmonth
-      READ(creftime(23:24),*)i_refday
-      READ(creftime(26:27),*)i_refhour
-      READ(creftime(29:30),*)i_refmin
-      READ(creftime(32:33),*)i_refsec
-      !Work out offset in days between reference time and 1/1/1950.
-      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
-         &           i_refmonth, i_refyear, z_offset)
-      
-      ! Get list of times for each ob in seconds relative to reference time
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sst_dtime', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
-         &       cpname, __LINE__ )
-      zsca = 1.0      
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname,  __LINE__ )
-      ENDIF
-      zoff = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "add_offset",zoff), cpname,  __LINE__ )
-      ENDIF
-      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
-         &                 + zoff)
-      
-      ! Get longitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
-         &         cpname, __LINE__ )
-      
-      ! Get latitudes
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
-         &         cpname, __LINE__ )
-      
-      ! Get SST data
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_surface_temperature', &
-         &                         i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_sst), &
-         &       cpname, __LINE__ )
-      zoff = 0.
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                      == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                     "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zsca = 1.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "scale_factor",zsca), cpname, __LINE__ )
-      ENDIF
-      zfill = 0.0
-      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
-         &                       == nf90_noerr) THEN
-         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
-            &                       "_FillValue",zfill), cpname, __LINE__ )
-      ENDIF
-      WHERE(z_sst(:,:) /=  zfill)
-         z_sst(:,:) = (zsca * z_sst(:,:)) + zoff
-      ELSEWHERE
-         z_sst(:,:) = fbrmdi
-      END WHERE
-      
-      ! Get QC flag
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
-         &       cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
-            &       cpname, __LINE__ )
-      
-      ! Get SST obs type
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, 'data_source', i_var_id ), & 
-         &         cpname, __LINE__ )
-      idims(1) = i_data
-      idims(2) = i_time
-      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_type),   &
-         &       cpname, __LINE__ )
-      
-      ! Close the file
-      
-      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
-
-      ! Fill the obfbdata structure
-
-      ! Allocate obfbdata
-      
-      iobs = i_data * i_time
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
-      inpfile%cname(1) = 'SST'
-
-      ! Fill the obfbdata structure from input data
-
-      inpfile%cdjuldref = "19500101000000"
-      iobs = 0
-      DO jtim = 1, i_time
-         DO jobs = 1, i_data
-            iobs = iobs + 1
-            ! Characters
-            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'ghrsst','  '
-            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
-            ! Real values
-            inpfile%plam(iobs)         = z_lam(jobs)
-            inpfile%pphi(iobs)         = z_phi(jobs)
-            inpfile%pob(1,iobs,1)      = z_sst(jobs,jtim)
-            inpfile%ptim(iobs)         = &
-               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
-               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
-            inpfile%pdep(1,iobs)       = 0.0
-            ! Integers
-            inpfile%kindex(iobs)       = iobs
-            IF ( z_sst(jobs,jtim) == fbrmdi ) THEN
-               inpfile%ioqc(iobs)      = 4
-               inpfile%ivqc(iobs,1)    = 4 
-               inpfile%ivlqc(1,iobs,1) = 4
-            ELSE 
-               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
-               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
-               inpfile%ivlqc(1,iobs,1) = 1
-            ENDIF
-            inpfile%ipqc(iobs)         = 0 
-            inpfile%ipqcf(:,iobs)      = 0
-            inpfile%itqc(iobs)         = 0
-            inpfile%itqcf(:,iobs)      = 0
-            inpfile%ivqcf(:,iobs,1)    = 0
-            inpfile%ioqcf(:,iobs)      = 0
-            inpfile%idqc(1,iobs)       = 0
-            inpfile%idqcf(1,1,iobs)    = 0
-            inpfile%ivlqcf(:,1,iobs,1) = 0
-         END DO
-      END DO
-
-      DEALLOCATE( &
-         & i_reftime, &
-         & i_dtime,   &
-         & i_qc,      &
-         & i_type,    &
-         & z_phi,     &
-         & z_lam,     &
-         & z_sst      &
-         & )
-
-   END SUBROUTINE read_ghrsst
-
-
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_vel_io.F90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_vel_io.F90	(revision 2199)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_vel_io.F90	(revision 2202)
@@ -22,5 +22,5 @@
 CONTAINS
 
-#include "obs_vel_io.h90"
+#include "obsvel_io.h90"
 
 END MODULE obs_vel_io
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_vel_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obs_vel_io.h90	(revision 2199)
+++ 	(revision )
@@ -1,354 +1,0 @@
-   SUBROUTINE read_taondbc( cdfilename, inpfile, kunit, ldwp, ldgrid )
-      !!---------------------------------------------------------------------
-      !!
-      !!                     ** ROUTINE read_enactfile **
-      !!
-      !! ** Purpose : Read from file the TAO data fro NDBC.
-      !!
-      !! ** Method  : The data file is a NetCDF file. 
-      !!
-      !! ** Action  :
-      !!
-      !! ** Reference : http://tao.noaa.gov/tao/data_deliv/deliv_ndbc.shtml
-      !! History : 
-      !!          ! 09-01 (K. Mogensen) Original version.
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      CHARACTER(LEN=*) :: cdfilename ! Input filename
-      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
-      INTEGER          :: kunit      ! Unit for output
-      LOGICAL          :: ldwp       ! Print info
-      LOGICAL          :: ldgrid     ! Save grid info in data structure
-      !! * Local declarations
-      INTEGER :: iobs                ! Number of observations
-      INTEGER :: ilev                ! Number of levels
-      INTEGER :: ilat                ! Number of latitudes
-      INTEGER :: ilon                ! Number of longtudes
-      INTEGER :: itim                ! Number of obs. times
-      INTEGER :: i_file_id
-      INTEGER :: i_dimid_id
-      INTEGER :: i_phi_id
-      INTEGER :: i_lam_id
-      INTEGER :: i_depth_id
-      INTEGER :: i_var_id
-      INTEGER :: i_time_id
-      INTEGER :: i_time2_id
-      INTEGER :: i_qc_var_id
-      CHARACTER(LEN=40) :: cl_fld_lam
-      CHARACTER(LEN=40) :: cl_fld_phi
-      CHARACTER(LEN=40) :: cl_fld_depth
-      CHARACTER(LEN=40) :: cl_fld_var_u
-      CHARACTER(LEN=40) :: cl_fld_var_v
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv1
-      CHARACTER(LEN=40) :: cl_fld_var_qc_uv2
-      CHARACTER(LEN=40) :: cl_fld_time
-      CHARACTER(LEN=40) :: cl_fld_time2
-      INTEGER :: ja
-      INTEGER :: jo
-      INTEGER :: jk
-      INTEGER :: jt
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: &
-         & zv,     &
-         & zu,     &
-         & zuv1qc, &
-         & zuv2qc
-      REAL(wp), ALLOCATABLE, DIMENSION(:) :: &
-         & zdep, &
-         & zlat, &
-         & zlon, &
-         & zjuld
-      REAL(wp) :: zl
-      INTEGER, ALLOCATABLE, DIMENSION(:) :: &
-         & itime, &
-         & itime2
-      CHARACTER(LEN=50) :: cdjulref
-      CHARACTER(LEN=12), PARAMETER :: cl_name = 'read_taondbc'
-      CHARACTER(len=1) :: cns, cew
-
-      !-----------------------------------------------------------------------
-      ! Initialization
-      !-----------------------------------------------------------------------
-      cl_fld_lam                 = 'lon'
-      cl_fld_phi                 = 'lat'
-      cl_fld_depth               = 'depth'
-      cl_fld_time                = 'time'
-      cl_fld_time2               = 'time2'
-
-      !-----------------------------------------------------------------------
-      ! Open file
-      !-----------------------------------------------------------------------
-
-      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
-            &      i_file_id ),           cl_name, __LINE__ )
-
-      !-----------------------------------------------------------------------
-      ! Read the heading of the file
-      !-----------------------------------------------------------------------
-      IF(ldwp) WRITE(kunit,*)
-      IF(ldwp) WRITE(kunit,*) ' read_taondbc :' 
-      IF(ldwp) WRITE(kunit,*) ' ~~~~~~~~~~~~'
-      
-      !---------------------------------------------------------------------
-      ! Read the number of observations and of levels to allocate array
-      !---------------------------------------------------------------------
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'time', i_dimid_id ),        &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = itim ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'depth', i_dimid_id ),       &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilev ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lat', i_dimid_id ),           &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilat ),    &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lon', i_dimid_id ),         &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilon ),    &
-         &         cl_name, __LINE__ ) 
-
-      iobs = itim * ilat * ilon
-      IF(ldwp)WRITE(kunit,*) '         No. of data records = ', iobs
-      IF(ldwp)WRITE(kunit,*) '         No. of levels       = ', ilev
-      IF(ldwp)WRITE(kunit,*) 
-
-      !---------------------------------------------------------------------
-      ! Allocate arrays
-      !---------------------------------------------------------------------
-
-      CALL init_obfbdata( inpfile )
-      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 0, ldgrid )
-      inpfile%cname(1) = 'UVEL'
-      inpfile%cname(2) = 'VVEL'
-      inpfile%coblong(1) = 'Zonal current'
-      inpfile%coblong(2) = 'Meridional current'
-      inpfile%cobunit(1) = 'Meters per second'
-      inpfile%cobunit(2) = 'Meters per second'
-
-      ALLOCATE( &
-         & zu(ilon,ilat,ilev,itim),     &
-         & zv(ilon,ilat,ilev,itim),     &
-         & zdep(ilev),                  &
-         & zuv1qc(ilon,ilat,ilev,itim), &
-         & zuv2qc(ilon,ilat,ilev,itim), &
-         & itime(itim),                 &
-         & itime2(itim),                &
-         & zlat(ilat),                  &
-         & zlon(ilon),                  &
-         & zjuld(itim)                  &
-         & )
-
-      !---------------------------------------------------------------------
-      ! Read the time/position variables 
-      !---------------------------------------------------------------------
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time, i_time_id ),                               &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time_id, itime ),                                     &
-         &         cl_name, __LINE__ )
-
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time2, i_time2_id ),                             &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_time2_id, itime2 ),                                   &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
-            &         cl_name, __LINE__ )         
-      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, zdep ),                                     &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, zlat ),                                       &
-         &         cl_name, __LINE__ )
-      
-      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
-         &         cl_name, __LINE__ )
-      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, zlon ),                                       &
-         &         cl_name, __LINE__ )
-      
-      !---------------------------------------------------------------------
-      ! Read the variables
-      !---------------------------------------------------------------------
-
-      ! ADCP format assumed
-      cl_fld_var_u = 'u_1205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_u = 'U_320'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zu ),                                         &
-         &         cl_name, __LINE__ )
-      
-      ! ADCP format assumed
-      cl_fld_var_v = 'v_1206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_v = 'V_321'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
-            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zv ),                                         &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Read the QC attributes
-      !---------------------------------------------------------------------
-      
-      ! ADCP format assumed
-      cl_fld_var_qc_uv1 = 'QU_5205'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv1 = 'QCS_5300'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv1 = 'QCU_5320'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv1qc),                                   &
-         &         cl_name, __LINE__ )
-
-      ! ADCP format assumed
-      cl_fld_var_qc_uv2 = 'QV_5206'
-      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-         ! Try again with current meter format
-         cl_fld_var_qc_uv2 = 'QCD_5310'
-         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-            ! Try again with high freq. current meter format
-            cl_fld_var_qc_uv2 = 'QCV_5321'
-            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
-               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
-            ENDIF
-         ENDIF
-      ENDIF
-      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv2qc),                                   &
-         &         cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Close file
-      !---------------------------------------------------------------------
-
-      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
-
-      !---------------------------------------------------------------------
-      ! Convert to to 19500101 based Julian date
-      !---------------------------------------------------------------------
-      DO jt = 1, itim
-         zjuld(jt) = REAL(itime(jt),wp) + REAL(itime2(jt),wp)/86400000.0_wp &
-            &           - 2433283.0_wp
-      END DO
-      inpfile%cdjuldref = '19500101000000'
-
-      !---------------------------------------------------------------------
-      ! Copy info to obfbdata structure
-      !---------------------------------------------------------------------
-
-      iobs = 0
-      DO jt = 1, itim
-         DO ja = 1, ilat
-            DO jo = 1, ilon
-               iobs = iobs + 1
-               zl = zlon(jo)
-               IF ( zl > 180.0_wp ) zl = zl - 360.0_wp
-               IF ( zl < 0 ) THEN
-                  cew = 'w'
-               ELSE
-                  cew = 'e'
-               ENDIF
-               IF ( zlat(jo) < 0 ) THEN
-                  cns = 's'
-               ELSE
-                  cns = 'n'
-               ENDIF
-               WRITE(inpfile%cdwmo(iobs),'(A1,I2.2,A1,I3.3)') &
-                  & cns, ABS(NINT(zlat(ja))), cew, ABS(NINT(zl))
-               DO jk = 1, ilev
-                  inpfile%pob(jk,iobs,1)     = zu(jo,ja,jk,jt)
-                  inpfile%pob(jk,iobs,2)     = zv(jo,ja,jk,jt)
-                  inpfile%pdep(jk,iobs)      = zdep(jk)
-                  inpfile%ivlqc(jk,iobs,1:2) = INT( MAX( zuv1qc(jo,ja,jk,jt), zuv2qc(jo,ja,jk,jt) ) )
-               END DO
-               inpfile%plam(iobs) = zlon(jo)
-               inpfile%pphi(iobs) = zlat(ja)
-               inpfile%ptim(iobs) = zjuld(jt)
-            END DO
-         END DO
-      END DO
-
-      ! No position, time, depth and variable QC in input files
-      DO jo = 1, iobs
-         inpfile%ipqc(jo) = 1
-         inpfile%itqc(jo) = 1
-         inpfile%ivqc(jo,1:2) = 1
-         DO jk = 1, ilev
-            inpfile%idqc(jk,jo) = 1
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set the platform information
-      !---------------------------------------------------------------------
-      inpfile%cdtyp(:)=' 820'
-
-      !---------------------------------------------------------------------
-      ! Set QC flags for missing data and rescale to m/s
-      !---------------------------------------------------------------------
-
-      DO jo = 1, iobs
-         DO jk = 1, ilev
-            IF ( ( ABS(inpfile%pob(jk,jo,1)) > 10000.0_wp ) .OR. &
-               & ( ABS(inpfile%pob(jk,jo,2)) > 10000.0_wp ) ) THEN
-               inpfile%ivlqc(jk,jo,:) = 4
-               inpfile%pob(jk,jo,1) = fbrmdi
-               inpfile%pob(jk,jo,2) = fbrmdi
-            ELSE
-               inpfile%pob(jk,jo,1) = 0.01 * inpfile%pob(jk,jo,1)
-               inpfile%pob(jk,jo,2) = 0.01 * inpfile%pob(jk,jo,2)
-            ENDIF
-         END DO
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Set file indexes
-      !---------------------------------------------------------------------
-
-      DO jo = 1, inpfile%nobs
-         inpfile%kindex(jo) = jo
-      END DO
-
-      !---------------------------------------------------------------------
-      ! Initialize flags since they are not in the TAO input files
-      !---------------------------------------------------------------------
-
-      inpfile%ioqcf(:,:)      = 0
-      inpfile%ipqcf(:,:)      = 0
-      inpfile%itqcf(:,:)      = 0
-      inpfile%idqcf(:,:,:)    = 0
-      inpfile%ivqcf(:,:,:)    = 0
-      inpfile%ivlqcf(:,:,:,:) = 0
-
-      !---------------------------------------------------------------------
-      ! Deallocate data
-      !---------------------------------------------------------------------
-      DEALLOCATE( &
-         & zu,     &
-         & zv,     &
-         & zdep,   &
-         & zuv1qc, &
-         & zuv2qc, &
-         & itime,  &
-         & itime2, &
-         & zlat,   &
-         & zlon,   &
-         & zjuld   &
-         & )
-
-   END SUBROUTINE read_taondbc
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_h2d.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_h2d.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_h2d.h90	(revision 2202)
@@ -0,0 +1,1357 @@
+   !!----------------------------------------------------------------------
+   !!    This software is governed by the CeCILL licence (Version 2)
+   !!    (See NEMOVAR_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   SUBROUTINE obs_int_h2d_init( kpk,   kpk2,  k2dint, plam,  pphi, &
+      &                         pglam, pgphi, pmask,  pweig, pobsmask, &
+      &                         iminpoints )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d  ***
+      !!
+      !! ** Purpose : Computes weights for horizontal interpolation to the 
+      !!              observation point.
+      !!
+      !! ** Method  : Horizontal interpolation to the observation point using
+      !!              model values at the corners of the surrounding grid 
+      !!              points.
+      !!
+      !!    Interpolation Schemes : 
+      !!
+      !!    1) k2dint = 0: Distance-weighted interpolation scheme 1
+      !!
+      !!       The interpolation weights are computed as a weighted 
+      !!       sum of the distance between the model grid points (A)
+      !!       and the observation point (B). Distance (s) is computed 
+      !!       using the great-circle distance formula: 
+      !!
+      !!       s(AB) = arcos(   sin( phiA ) x sin( phiB )
+      !!                      + cos( phiA ) x cos( phiB ) 
+      !!                                    x cos( lamB - lamA ) )
+      !!
+      !!    2) k2dint = 1: Distance-weighted interpolation scheme 2
+      !!
+      !!       As k2dint = 0 but with distance (ds) computed using 
+      !!       a small-angle approximation to the great-circle formula:
+      !!
+      !!       ds(AB) = sqrt(   ( phiB - phiA )^{2} 
+      !!                    + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
+      !!
+      !!    3) k2dint = 2: Bilinear interpolation on a geographical grid
+      !!
+      !!       The interpolation is split into two 1D interpolations in
+      !!       the longitude and latitude directions, respectively.
+      !!
+      !!    4) k2dint = 3: General bilinear remapping interpolation
+      !!
+      !!       An iterative scheme that involves first mapping a 
+      !!       quadrilateral cell into a cell with coordinates 
+      !!       (0,0), (1,0), (0,1) and (1,1).
+      !!
+      !!    5) k2dint = 4: Polynomial interpolation
+      !!
+      !!       The interpolation weights are computed by fitting a 
+      !!       polynomial function of the form 
+      !!              
+      !!       P(i) = a1(i) + a2(i) * phi + a3(i) * plam 
+      !!                                  + a4(i) * phi * plam
+      !!    
+      !!       through the model values at the four surrounding grid points.
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : Jones, P.: A users guide for SCRIP: A Spherical 
+      !!                        Coordinate Remapping and Interpolation Package.
+      !!                        Version 1.4. Los Alomos. 
+      !!                    
+      !!       http://www.acl.lanl.gov/climate/software/SCRIP/SCRIPmain.html
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-03 (A. Vidard) NEMOVAR migration
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!        ! 07-08 (K. Mogensen) Split in two routines for easier adj.
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk,   &             ! Parameter values for automatic arrays
+         & kpk2,  &        
+         & k2dint               ! Interpolation scheme options
+                                ! = 0 distance-weighted (great circle)
+                                ! = 1 distance-weighted (small angle)
+                                ! = 2 bilinear (geographical grid)
+                                ! = 3 bilinear (quadrilateral grid)
+                                ! = 4 polynomial (quadrilateral grid)
+      REAL(KIND=wp), INTENT(INOUT) :: &
+         & plam, &
+         & pphi                 ! Geographical (lat,lon) coordinates of
+                                ! observation
+      REAL(KIND=wp), DIMENSION(2,2), INTENT(IN) :: &
+         & pglam, &             ! Model variable lat
+         & pgphi                ! Model variable lon
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmask                ! Model variable mask
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(OUT) ::  &
+         & pweig                ! Weights for interpolation
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) ::  &
+         & pobsmask             ! Vertical mask for observations
+      INTEGER, INTENT(IN), OPTIONAL :: &
+         & iminpoints           ! Reject point which is not surrounded
+                                ! by at least iminpoints sea points
+
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      INTEGER :: &
+         & ikmax, &
+         & iamb1, &
+         & iamb2
+      REAL(KIND=wp) :: &
+         & zphimm,  &
+         & zphimp,  &
+         & zphipm,  &
+         & zphipp,  &
+         & zlammm,  &
+         & zlammp,  &
+         & zlampm,  &
+         & zlampp,  &
+         & zphimin, &
+         & zphimax, &
+         & zlammin, &
+         & zlammax
+      REAL(KIND=wp), DIMENSION(kpk2) :: &
+         & z2dmm,  &
+         & z2dmp,  &
+         & z2dpm,  &
+         & z2dpp,  &
+         & z2dmmt, &
+         & z2dmpt, &
+         & z2dpmt, &
+         & z2dppt, &
+         & zsum
+      LOGICAL :: &
+         & ll_ds1, &
+         & ll_skip, &
+         & ll_fail
+       
+      !------------------------------------------------------------------------
+      ! Constants for the 360 degrees ambiguity
+      !------------------------------------------------------------------------
+      iamb1 = 10   ! dlam < iamb1 * dphi
+      iamb2 = 3    ! Special treatment if iamb2 * lam < max(lam) 
+       
+      !------------------------------------------------------------------------
+      ! Initialize number of levels
+      !------------------------------------------------------------------------
+      IF ( kpk2 == 1 ) THEN
+         ikmax = 1
+      ELSEIF ( kpk2 == kpk) THEN
+         ikmax = kpk-1
+      ENDIF
+      !------------------------------------------------------------------------
+      ! Initialize the cell corners
+      !------------------------------------------------------------------------
+      zphimm = pgphi(1,1)
+      zphimp = pgphi(1,2)
+      zphipm = pgphi(2,1)
+      zphipp = pgphi(2,2)
+      zlammm = pglam(1,1)
+      zlammp = pglam(1,2)
+      zlampm = pglam(2,1)
+      zlampp = pglam(2,2)
+       
+      !------------------------------------------------------------------------
+      ! Treat the 360 degrees ambiguity
+      !------------------------------------------------------------------------
+      DO WHILE ( ( zlammm < 0.0_wp ).OR.( zlammm > 360.0_wp )  &
+         &   .OR.( zlampm < 0.0_wp ).OR.( zlampm > 360.0_wp )  &
+         &   .OR.( zlampp < 0.0_wp ).OR.( zlampp > 360.0_wp )  &
+         &   .OR.( zlammp < 0.0_wp ).OR.( zlammp > 360.0_wp ) )
+       
+         IF ( zlammm < 0.0_wp   ) zlammm = zlammm + 360.0_wp
+         IF ( zlammm > 360.0_wp ) zlammm = zlammm - 360.0_wp
+         IF ( zlammp < 0.0_wp   ) zlammp = zlammp + 360.0_wp
+         IF ( zlammp > 360.0_wp ) zlammp = zlammp - 360.0_wp
+         IF ( zlampm < 0.0_wp   ) zlampm = zlampm + 360.0_wp
+         IF ( zlampm > 360.0_wp ) zlampm = zlampm - 360.0_wp
+         IF ( zlampp < 0.0_wp   ) zlampp = zlampp + 360.0_wp
+         IF ( zlampp > 360.0_wp ) zlampp = zlampp - 360.0_wp
+       
+      END DO
+
+      DO WHILE ( ( plam < 0.0_wp ) .OR. ( plam > 360.0_wp ) )
+         IF ( plam < 0.0_wp   ) plam = plam + 360.0_wp
+         IF ( plam > 360.0_wp ) plam = plam - 360.0_wp
+      END DO
+
+      !------------------------------------------------------------------------
+      ! Special case for observation on grid points
+      !------------------------------------------------------------------------
+      ll_skip = .FALSE.
+      IF ( ( ABS( zphimm - pphi ) < 1.0e-6_wp ) .AND. &
+         & ( ABS( zlammm - plam ) < 1.0e-6_wp ) ) THEN
+         z2dmm(:) = 1.0_wp
+         z2dpm(:) = 0.0_wp
+         z2dmp(:) = 0.0_wp
+         z2dpp(:) = 0.0_wp
+         ll_skip = .TRUE.
+      ENDIF
+      IF ( ( ABS( zphipm - pphi ) < 1.0e-6_wp ) .AND. &
+         & ( ABS( zlampm - plam ) < 1.0e-6_wp ) ) THEN
+         z2dmm(:) = 0.0_wp
+         z2dpm(:) = 1.0_wp
+         z2dmp(:) = 0.0_wp
+         z2dpp(:) = 0.0_wp
+         ll_skip = .TRUE.
+      ENDIF
+      IF ( ( ABS( zphimp - pphi ) < 1.0e-6_wp ) .AND. &
+         & ( ABS( zlammp - plam ) < 1.0e-6_wp ) ) THEN
+         z2dmm(:) = 0.0_wp
+         z2dpm(:) = 0.0_wp
+         z2dmp(:) = 1.0_wp
+         z2dpp(:) = 0.0_wp
+         ll_skip = .TRUE.
+      ENDIF
+      IF ( ( ABS( zphipp - pphi ) < 1.0e-6_wp ) .AND. &
+         & ( ABS( zlampp - plam ) < 1.0e-6_wp ) ) THEN
+         z2dmm(:) = 0.0_wp
+         z2dpm(:) = 0.0_wp
+         z2dmp(:) = 0.0_wp
+         z2dpp(:) = 1.0_wp
+         ll_skip = .TRUE.
+      ENDIF
+
+      IF ( .NOT.ll_skip ) THEN
+
+         zphimin = MIN( zphimm, zphipm, zphipp, zphimp )
+         zphimax = MAX( zphimm, zphipm, zphipp, zphimp )
+         zlammin = MIN( zlammm, zlampm, zlampp, zlammp )
+         zlammax = MAX( zlammm, zlampm, zlampp, zlammp )
+
+         IF ( ( ( zlammax - zlammin ) / ( zphimax - zphimin ) ) > iamb1 ) THEN
+            IF ( iamb2 * zlammm < zlammax ) zlammm = zlammm + 360.0_wp
+            IF ( iamb2 * zlammp < zlammax ) zlammp = zlammp + 360.0_wp
+            IF ( iamb2 * zlampm < zlammax ) zlampm = zlampm + 360.0_wp
+            IF ( iamb2 * zlampp < zlammax ) zlampp = zlampp + 360.0_wp
+         ENDIF
+
+         zlammin = MIN( zlammm, zlampm, zlampp, zlammp )
+         IF ( zlammm > ( zlammin + 180.0_wp ) ) zlammm = zlammm - 360.0_wp
+         IF ( zlammp > ( zlammin + 180.0_wp ) ) zlammp = zlammp - 360.0_wp
+         IF ( zlampm > ( zlammin + 180.0_wp ) ) zlampm = zlampm - 360.0_wp
+         IF ( zlampp > ( zlammin + 180.0_wp ) ) zlampp = zlampp - 360.0_wp
+         
+         IF ( plam < zlammin ) plam = plam + 360.0_wp
+	   z2dmm = 0.0_wp
+	   z2dmp = 0.0_wp
+	   z2dpm = 0.0_wp
+	   z2dpp = 0.0_wp
+         SELECT CASE (k2dint)
+            
+         CASE(0)
+            CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
+               &                  pphi, plam, pmask,                  &
+               &                  zphimm, zlammm, zphimp, zlammp,     & 
+               &                  zphipm, zlampm, zphipp, zlampp,     &
+               &                  z2dmm, z2dmp, z2dpm, z2dpp )
+         CASE(1)
+            CALL obs_int_h2d_ds2( kpk2, ikmax,                        &
+               &                  pphi, plam, pmask,                  &
+               &                  zphimm, zlammm, zphimp, zlammp,     &
+               &                  zphipm, zlampm, zphipp, zlampp,     &
+               &                  z2dmm, z2dmp, z2dpm, z2dpp )
+         CASE(2)
+            CALL obs_int_h2d_bil( kpk2, ikmax,                        &
+               &                  pphi, plam, pmask,                  &
+               &                                          zlammp,     &
+               &                  zphipm,         zphipp, zlampp,     &
+               &                  z2dmm, z2dmp, z2dpm, z2dpp )
+         CASE(3)
+            CALL obs_int_h2d_bir( kpk2, ikmax,                        &
+               &                  pphi, plam, pmask,                  &
+               &                  zphimm, zlammm, zphimp, zlammp,     &
+               &                  zphipm, zlampm, zphipp, zlampp,     &
+               &                  z2dmm, z2dmp, z2dpm, z2dpp, ll_fail )
+            IF (ll_fail) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*)'Bilinear weight computation failed'
+                  WRITE(numout,*)'Switching to great circle distance'
+                  WRITE(numout,*)
+               ENDIF
+               CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
+                  &                  pphi, plam, pmask,                  &
+                  &                  zphimm, zlammm, zphimp, zlammp,     & 
+                  &                  zphipm, zlampm, zphipp, zlampp,     &
+                  &                  z2dmm, z2dmp, z2dpm, z2dpp )
+            ENDIF
+         CASE(4)  
+            CALL obs_int_h2d_pol( kpk2, ikmax,                        &
+               &                  pphi, plam, pmask,                  &
+               &                  zphimm, zlammm, zphimp, zlammp,     &
+               &                  zphipm, zlampm, zphipp, zlampp,     & 
+               &                  z2dmm, z2dmp, z2dpm, z2dpp )
+         END SELECT
+
+      ENDIF
+      !------------------------------------------------------------------------
+      ! Compute weights for interpolation to the observation point
+      !------------------------------------------------------------------------
+      pobsmask(:) = 0.0_wp
+      pweig(:,:,:) = 0.0_wp
+      ! ll_ds1 is used for failed interpolations
+      ll_ds1 = .FALSE.
+      DO jk = 1, ikmax
+         IF (PRESENT(iminpoints)) THEN
+            IF (NINT(SUM(pmask(:,:,jk)))<iminpoints) CYCLE
+         ENDIF
+         zsum(jk) = z2dmm(jk) + z2dmp(jk) + z2dpm(jk) + z2dpp(jk) 
+         IF ( zsum(jk) /= 0.0_wp ) THEN
+            pweig(1,1,jk) = z2dmm(jk) 
+            pweig(1,2,jk) = z2dmp(jk)
+            pweig(2,1,jk) = z2dpm(jk)
+            pweig(2,2,jk) = z2dpp(jk)
+            ! Set the vertical mask
+            IF ( ( ( z2dmm(jk) > 0.0_wp ) .AND.       &
+               &   ( pmask(1,1,jk) == 1.0_wp ) ) .OR. &
+               & ( ( z2dmp(jk) > 0.0_wp ) .AND.       &
+               &   ( pmask(1,2,jk) == 1.0_wp ) ) .OR. &
+               & ( ( z2dpm(jk) > 0.0_wp ) .AND.       &
+               &   ( pmask(2,1,jk) == 1.0_wp ) ) .OR. &
+               & ( ( z2dpp(jk) > 0.0_wp ) .AND.       &
+               &   ( pmask(2,2,jk) == 1.0_wp ) ) ) pobsmask(jk)=1.0_wp
+         ELSE
+            ! If the interpolation has failed due to the point
+            ! being on the intersect of two land points retry with
+            ! k2dint = 0
+            IF ( ( pmask(1,1,jk) /= 0.0_wp ).OR. &
+               & ( pmask(1,2,jk) /= 0.0_wp ).OR. &
+               & ( pmask(2,1,jk) /= 0.0_wp ).OR. &
+               & ( pmask(2,2,jk) /= 0.0_wp ) ) THEN
+               ! If ll_ds1 is false compute k2dint = 0 weights
+               IF ( .NOT.ll_ds1 ) THEN
+                  CALL obs_int_h2d_ds1( kpk2, ikmax,                        &
+                     &                  pphi, plam, pmask,                  &
+                     &                  zphimm, zlammm, zphimp, zlammp,     & 
+                     &                  zphipm, zlampm, zphipp, zlampp,     &
+                     &                  z2dmmt, z2dmpt, z2dpmt, z2dppt ) 
+                  ll_ds1 = .TRUE.
+               ENDIF
+               zsum(jk) = z2dmmt(jk) + z2dmpt(jk) + z2dpmt(jk) + z2dppt(jk) 
+               IF ( zsum(jk) /= 0.0_wp ) THEN
+                  pweig(1,1,jk) = z2dmmt(jk) 
+                  pweig(1,2,jk) = z2dmpt(jk)
+                  pweig(2,1,jk) = z2dpmt(jk)
+                  pweig(2,2,jk) = z2dppt(jk)
+                  ! Set the vertical mask
+                  IF ( ( ( z2dmmt(jk) > 0.0_wp ) .AND.      &
+                     &   ( pmask(1,1,jk) == 1.0_wp ) ) .OR. &
+                     & ( ( z2dmpt(jk) > 0.0_wp ) .AND.      &
+                     &   ( pmask(1,2,jk) == 1.0_wp ) ) .OR. &
+                     & ( ( z2dpmt(jk) > 0.0_wp) .AND.      &
+                     &   ( pmask(2,1,jk) == 1.0_wp ) ) .OR. &
+                     & ( ( z2dppt(jk) > 0.0_wp ) .AND.      &
+                     &   ( pmask(2,2,jk) == 1.0_wp ) ) )    &
+                     & pobsmask(jk)=1.0_wp
+               ENDIF
+            ENDIF
+         ENDIF
+      END DO
+  
+   END SUBROUTINE obs_int_h2d_init
+
+   SUBROUTINE obs_int_h2d( kpk, kpk2, &
+      &                    pweig, pmod, pobsk )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d  ***
+      !!
+      !! ** Purpose : Horizontal interpolation to the observation point.
+      !!
+      !! ** Method  : Horizontal interpolation to the observation point using
+      !!              model values at the corners of the surrounding grid 
+      !!              points.
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-03 (A. Vidard) NEMOVAR migration
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!        ! 07-08 (K. Mogensen) Split in two routines for easier adj.
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk,   &             ! Parameter values for automatic arrays
+         & kpk2
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pweig                ! Interpolation weights
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmod                 ! Model variable to interpolate
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) ::  &
+         & pobsk                ! Model profile interpolated to obs (i,j) pt
+
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      INTEGER :: &
+         & ikmax
+      REAL(KIND=wp) :: &
+         & zsum
+      !------------------------------------------------------------------------
+      ! Initialize number of levels
+      !------------------------------------------------------------------------
+      IF ( kpk2 == 1 ) THEN
+         ikmax = 1
+      ELSEIF ( kpk2 == kpk) THEN
+         ikmax = kpk-1
+      ENDIF
+      !------------------------------------------------------------------------
+      ! Interpolate to the observation point
+      !------------------------------------------------------------------------
+      pobsk(:) = obfillflt
+      DO jk = 1, ikmax
+         zsum = pweig(1,1,jk) + pweig(1,2,jk) + pweig(2,1,jk) +  pweig(2,2,jk) 
+         IF ( zsum /= 0.0_wp ) THEN
+            pobsk(jk) = (  pweig(1,1,jk) * pmod(1,1,jk)         &
+               &         + pweig(1,2,jk) * pmod(1,2,jk)         &
+               &         + pweig(2,1,jk) * pmod(2,1,jk)         &
+               &         + pweig(2,2,jk) * pmod(2,2,jk)         &
+               &                                             ) / zsum
+         ENDIF
+      END DO
+
+   END SUBROUTINE obs_int_h2d
+  
+   SUBROUTINE obs_int_h2d_ds1( kpk2, kmax,                        &
+      &                        pphi, plam, pmask,                 &
+      &                        pphimm, plammm, pphimp, plammp,    & 
+      &                        pphipm, plampm, pphipp, plampp,    &
+      &                        p2dmm, p2dmp, p2dpm, p2dpp )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d_ds1  ***
+      !!
+      !! ** Purpose : Distance-weighted interpolation scheme (k2dint = 0)
+      !!
+      !! ** Method  : The interpolation weights are computed as a weighted 
+      !!              sum of the distance between the model grid points (A) 
+      !!              and the observation point (B). 
+      !!
+      !!    Distance (s) is computed using the great-circle distance formula:
+      !!
+      !!    s(AB) = arcos(   sin( phiA ) x sin( phiB )
+      !!                   + cos( phiA ) x cos( phiB ) x cos( lamB - lamA )
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk2, &             ! Parameter values for automatic arrays
+         & kmax
+      REAL(KIND=wp), INTENT(IN) :: &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphimm, &           ! Geographical location of surrounding
+         & pphimp, &           ! model grid points
+         & pphipm, &
+         & pphipp, & 
+         & plammm, &
+         & plammp, &
+         & plampm, &
+         & plampp
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmask               ! Model variable mask 
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
+         & p2dmm, &            ! Interpolation weights
+         & p2dmp, &
+         & p2dpm, &
+         & p2dpp
+
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      REAL(KIND=wp) :: &
+         & zphi2,   &
+         & zlam2,   &
+         & zcola,   &
+         & za2,     &
+         & zb2,     &
+         & zc2,     &
+         & zphimm2, &
+         & zphimp2, &
+         & zphipm2, &
+         & zphipp2, &
+         & zlammm2, &
+         & zlammp2, &
+         & zlampm2, &
+         & zlampp2, &
+         & za1mm,   &
+         & za1mp,   &
+         & za1pm,   &
+         & za1pp,   &
+         & zcomm,   &
+         & zcomp,   &
+         & zcopm,   &
+         & zcopp,   &
+         & zb1mm,   &
+         & zb1mp,   &
+         & zb1pm,   &
+         & zb1pp,   &
+         & zc1mm,   &
+         & zc1mp,   &
+         & zc1pm,   &
+         & zc1pp,   &
+         & zsopmpp, &
+         & zsommmp, &
+         & zsomm,   &
+         & zsomp,   &
+         & zsopm,   &
+         & zsopp
+       
+      !------------------------------------------------------------------------
+      ! Distance-weighted interpolation using the great circle formula
+      !------------------------------------------------------------------------
+      zphi2 = pphi * rad
+      zlam2 = plam * rad
+      zcola = COS( zphi2 )
+      za2   = SIN( zphi2 )
+      zb2   = zcola * COS( zlam2 )
+      zc2   = zcola * SIN( zlam2 )
+       
+      zphimm2 = pphimm * rad
+      zphimp2 = pphimp * rad
+      zphipm2 = pphipm * rad
+      zphipp2 = pphipp * rad
+       
+      zlammm2 = plammm * rad
+      zlammp2 = plammp * rad
+      zlampm2 = plampm * rad
+      zlampp2 = plampp * rad
+       
+      za1mm = SIN( zphimm2 )
+      za1mp = SIN( zphimp2 )
+      za1pm = SIN( zphipm2 )
+      za1pp = SIN( zphipp2 )
+       
+      zcomm = COS( zphimm2 )
+      zcomp = COS( zphimp2 )
+      zcopm = COS( zphipm2 )
+      zcopp = COS( zphipp2 )
+       
+      zb1mm = zcomm * COS( zlammm2 )
+      zb1mp = zcomp * COS( zlammp2 )
+      zb1pm = zcopm * COS( zlampm2 )
+      zb1pp = zcopp * COS( zlampp2 )
+       
+      zc1mm = zcomm * SIN( zlammm2 )
+      zc1mp = zcomp * SIN( zlammp2 )
+      zc1pm = zcopm * SIN( zlampm2 )
+      zc1pp = zcopp * SIN( zlampp2 )
+       
+      ! Function for arcsin(sqrt(1-x^2) version of great-circle formula
+      zsomm = grt_cir_dis( za1mm, za2, zb1mm, zb2, zc1mm, zc2 )
+      zsomp = grt_cir_dis( za1mp, za2, zb1mp, zb2, zc1mp, zc2 )
+      zsopm = grt_cir_dis( za1pm, za2, zb1pm, zb2, zc1pm, zc2 )
+      zsopp = grt_cir_dis( za1pp, za2, zb1pp, zb2, zc1pp, zc2 )
+       
+      zsopmpp = zsopm * zsopp
+      zsommmp = zsomm * zsomp
+      DO jk = 1, kmax
+         p2dmm(jk) = zsomp * zsopmpp * pmask(1,1,jk)
+         p2dmp(jk) = zsomm * zsopmpp * pmask(1,2,jk) 
+         p2dpm(jk) = zsopp * zsommmp * pmask(2,1,jk)
+         p2dpp(jk) = zsopm * zsommmp * pmask(2,2,jk)
+      END DO
+       
+   END SUBROUTINE obs_int_h2d_ds1
+  
+   SUBROUTINE obs_int_h2d_ds2( kpk2, kmax,                        &
+      &                        pphi, plam, pmask,                 &
+      &                        pphimm, plammm, pphimp, plammp,    &
+      &                        pphipm, plampm, pphipp, plampp,    &
+      &                        p2dmm, p2dmp, p2dpm, p2dpp ) 
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d_ds2  ***
+      !!
+      !! ** Purpose : Distance-weighted interpolation scheme (k2dint = 1)
+      !!
+      !! ** Method  : As k2dint = 0 but with distance (ds) computed using a 
+      !!              small-angle approximation to the great-circle distance 
+      !!              formula:
+      !!
+      !!    ds(AB) = sqrt(   ( phiB - phiA )^{2}
+      !!                   + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+      !!----------------------------------------------------------------------- 
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk2, &             ! Parameter values for automatic arrays
+         & kmax
+      REAL(KIND=wp), INTENT(IN) ::        &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphimm, &           ! Geographical location of surrounding
+         & pphimp, &           ! model grid points
+         & pphipm, &
+         & pphipp, & 
+         & plammm, &
+         & plammp, &
+         & plampm, &
+         & plampp
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmask               ! Model variable mask 
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
+         & p2dmm, &            ! Interpolation weights
+         & p2dmp, &
+         & p2dpm, &
+         & p2dpp
+
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      REAL(KIND=wp) :: &
+         & zcosp,   &
+         & zdlmm,   &
+         & zdlmp,   &
+         & zdlpm,   &
+         & zdlpp,   &
+         & zdpmm,   &
+         & zdpmp,   &
+         & zdppm,   &
+         & zdppp,   &
+         & zsomm,   &
+         & zsomp,   &
+         & zsopm,   &
+         & zsopp,   &
+         & zsopmpp, &
+         & zsommmp
+       
+      !------------------------------------------------------------------------
+      ! Distance-weighted interpolation with a small angle approximation
+      !------------------------------------------------------------------------
+      zcosp = COS( pphi * rad )
+       
+      zdlmm = plammm - plam
+      zdlmp = plammp - plam
+      zdlpm = plampm - plam
+      zdlpp = plampp - plam
+       
+      zdpmm = pphimm - pphi
+      zdpmp = pphimp - pphi
+      zdppm = pphipm - pphi
+      zdppp = pphipp - pphi
+       
+      zsomm = grt_cir_dis_saa( zdlmm, zdpmm, zcosp )
+      zsomp = grt_cir_dis_saa( zdlmp, zdpmp, zcosp )
+      zsopm = grt_cir_dis_saa( zdlpm, zdppm, zcosp )
+      zsopp = grt_cir_dis_saa( zdlpp, zdppp, zcosp )
+       
+      zsopmpp = zsopm * zsopp
+      zsommmp = zsomm * zsomp
+       
+      DO jk = 1, kmax
+         p2dmm(jk) = zsomp * zsopmpp * pmask(1,1,jk)
+         p2dmp(jk) = zsomm * zsopmpp * pmask(1,2,jk)
+         p2dpm(jk) = zsopp * zsommmp * pmask(2,1,jk)
+         p2dpp(jk) = zsopm * zsommmp * pmask(2,2,jk)
+      END DO
+       
+   END SUBROUTINE obs_int_h2d_ds2
+  
+   SUBROUTINE obs_int_h2d_bil( kpk2, kmax,                        &
+      &                        pphi, plam, pmask,                 &
+      &                        plammp, pphipm, pphipp, plampp,    &
+      &                        p2dmm, p2dmp, p2dpm, p2dpp)
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d_bil  ***
+      !!
+      !! ** Purpose : Bilinear interpolation on a geographical grid (k2dint = 2)
+      !!
+      !! ** Method  : The interpolation is split into two 1D interpolations in 
+      !!              the longitude and latitude directions, respectively.
+      !!
+      !!    An iterative scheme that involves first mapping a quadrilateral
+      !!    cell into a cell with coordinates (0,0), (1,0), (0,1) and (1,1).
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk2, &             ! Parameter values for automatic arrays
+         & kmax
+      REAL(KIND=wp), INTENT(IN) :: &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphipm, &           ! Geographical location of surrounding
+         & pphipp, &           ! model grid points
+         & plammp, &
+         & plampp
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN)  :: &
+         & pmask               ! Model variable mask
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
+         & p2dmm, &            ! Interpolation weights
+         & p2dmp, &
+         & p2dpm, &
+         & p2dpp
+
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      REAL(KIND=wp) :: &
+         & zdlmp, &
+         & zdppm, &
+         & zdlpp, &
+         & zdppp
+       
+      !----------------------------------------------------------------------
+      ! Bilinear interpolation for geographical grid
+      !----------------------------------------------------------------------
+      zdlmp = ABS(plam   - plammp) 
+      zdppm = ABS(pphi   - pphipm)
+      zdlpp = ABS(plampp - plam)
+      zdppp = ABS(pphipp - pphi)
+       
+      DO jk = 1, kmax
+         p2dmm(jk) = zdlpp * zdppp * pmask(1,1,jk)
+         p2dmp(jk) = zdlpp * zdppm * pmask(1,2,jk)
+         p2dpm(jk) = zdlmp * zdppp * pmask(2,1,jk)
+         p2dpp(jk) = zdlmp * zdppm * pmask(2,2,jk)
+      END DO
+       
+   END SUBROUTINE obs_int_h2d_bil
+  
+   SUBROUTINE obs_int_h2d_bir( kpk2, kmax,                        &
+      &                        pphi, plam, pmask,                 &
+      &                        pphimm, plammm, pphimp, plammp,    &
+      &                        pphipm, plampm, pphipp, plampp,    &
+      &                        p2dmm, p2dmp, p2dpm, p2dpp, ldfail )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d_bir  ***
+      !!
+      !! ** Purpose : General bilinear remapping interpolation (k2dint = 3)
+      !!
+      !! ** Method  : An iterative scheme that involves first mapping a 
+      !!              quadrilateral cell into a cell with coordinates 
+      !!              (0,0), (1,0), (0,1) and (1,1).
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kpk2, &             ! Parameter values for automatic arrays
+         & kmax
+      REAL(KIND=wp), INTENT(IN) ::        &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphimm, &           ! Geographical location of surrounding
+         & pphimp, &           ! model grid points
+         & pphipm, &
+         & pphipp, & 
+         & plammm, &
+         & plammp, &
+         & plampm, &
+         & plampp
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmask               ! Model variable mask 
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
+         & p2dmm, &            ! Interpolation weights
+         & p2dmp, &
+         & p2dpm, &
+         & p2dpp
+      LOGICAL, INTENT(OUT) :: &
+         & ldfail
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      REAL(KIND=wp) :: &
+         & zbiwmm, &
+         & zbiwmp, &
+         & zbiwpm, &
+         & zbiwpp
+  
+      !----------------------------------------------------------------------
+      ! Bilinear remapping interpolation for general quadrilateral grid
+      !----------------------------------------------------------------------
+      CALL bil_wgt( pphimm, pphimp, pphipm, pphipp,  &
+         &          plammm, plammp, plampm, plampp,  &
+         &          zbiwmm, zbiwmp, zbiwpm, zbiwpp,  &
+         &          pphi  , plam,   ldfail           )
+
+      IF ( .NOT.ldfail ) THEN
+         DO jk = 1, kmax
+            p2dmm(jk) = zbiwmm * pmask(1,1,jk)
+            p2dmp(jk) = zbiwmp * pmask(1,2,jk)
+            p2dpm(jk) = zbiwpm * pmask(2,1,jk)
+            p2dpp(jk) = zbiwpp * pmask(2,2,jk)
+         END DO
+      ENDIF
+
+   END SUBROUTINE obs_int_h2d_bir
+
+   SUBROUTINE obs_int_h2d_pol( kpk2, kmax,                         &
+      &                        pphi, plam, pmask,                  &
+      &                        pphimm, plammm, pphimp, plammp,     &
+      &                        pphipm, plampm, pphipp, plampp,     &
+      &                        p2dmm, p2dmp, p2dpm, p2dpp )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                     ***  ROUTINE obs_int_h2d_pol  ***
+      !!
+      !! ** Purpose : Polynomial interpolation (k2dint = 4)
+      !!
+      !! ** Method  : The interpolation weights are computed by fitting a 
+      !!              polynomial function of the form
+      !!
+      !!    P(i) = a1(i) + a2(i) * phi + a3(i) * plam + a4(i) * phi * plam
+      !!
+      !!    through the model values at four surrounding grid pts (i=1,4).
+      !!    As k2dint = 0 but with distance (ds) computed using a small-
+      !!    angle approximation to the great-circle distance formula:
+      !!
+      !!    ds(AB) = sqrt(   ( phiB - phiA )^{2}
+      !!                   + ( ( lamB - lamA ) * cos( phiB ) )^{2} )
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        ! 97-11 (A. Weaver, N. Daget)
+      !!        ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &  
+         & kpk2,   &           ! Parameter values for automatic arrays 
+         & kmax
+      REAL(KIND=wp), INTENT(IN) :: &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphimm, &           ! Geographical location of surrounding
+         & pphimp, &           ! model grid points
+         & pphipm, &
+         & pphipp, &
+         & plammm, &
+         & plammp, &
+         & plampm, &
+         & plampp
+      REAL(KIND=wp), DIMENSION(2,2,kpk2), INTENT(IN) :: &
+         & pmask               ! Model variable mask
+      REAL(KIND=wp), DIMENSION(kpk2), INTENT(OUT) :: &
+         & p2dmm,  &           ! Interpolation weights
+         & p2dmp,  &
+         & p2dpm,  &
+         & p2dpp
+  
+      !! * Local declarations
+      INTEGER :: &
+         & jk
+      REAL(KIND=wp) :: &
+         & zplp
+      REAL(KIND=wp), DIMENSION(4,4) :: &
+         & zmat,  &
+         & zmati
+       
+      !------------------------------------------------------------------------
+      ! Polynomial interpolation
+      !------------------------------------------------------------------------       
+      zmat(1,1) = 1.0_wp
+      zmat(1,2) = 1.0_wp
+      zmat(1,3) = 1.0_wp
+      zmat(1,4) = 1.0_wp
+      zmat(2,1) = plammm
+      zmat(2,2) = plammp
+      zmat(2,3) = plampm
+      zmat(2,4) = plampp
+      zmat(3,1) = pphimm
+      zmat(3,2) = pphimp
+      zmat(3,3) = pphipm
+      zmat(3,4) = pphipp
+      zmat(4,1) = plammm * pphimm
+      zmat(4,2) = plammp * pphimp
+      zmat(4,3) = plampm * pphipm
+      zmat(4,4) = plampp * pphipp
+       
+      CALL lu_invmat( zmat, 4, zmati )
+       
+      zplp = plam * pphi            
+      DO jk = 1, kmax
+         p2dmm(jk) = ABS(   zmati(1,1)        + zmati(1,2) * plam    &
+            &             + zmati(1,3) * pphi + zmati(1,4) * zplp )  &
+            &      * pmask(1,1,jk) 
+         p2dmp(jk) = ABS(   zmati(2,1)        + zmati(2,2) * plam    &
+            &             + zmati(2,3) * pphi + zmati(2,4) * zplp )  &
+            &      * pmask(1,2,jk)
+         p2dpm(jk) = ABS(   zmati(3,1)        + zmati(3,2) * plam    &
+            &             + zmati(3,3) * pphi + zmati(3,4) * zplp )  &
+            &      * pmask(2,1,jk)
+         p2dpp(jk) = ABS(   zmati(4,1)        + zmati(4,2) * plam    &
+            &             + zmati(4,3) * pphi + zmati(4,4) * zplp )  &
+            &      * pmask(2,2,jk)
+      END DO
+  
+   END SUBROUTINE obs_int_h2d_pol
+
+   SUBROUTINE bil_wgt( pphimm, pphimp, pphipm, pphipp,   &
+      &               plammm, plammp, plampm, plampp,   &
+      &               pbiwmm, pbiwmp, pbiwpm, pbiwpp,   &
+      &               pphi  , plam,   ldfail            )
+      !!-------------------------------------------------------------------
+      !!
+      !!                   ***  ROUTINE bil_wgt  ***
+      !!
+      !! ** Purpose : Compute the weights for a bilinear remapping 
+      !!              interpolation scheme.
+      !!
+      !! ** Method  : This scheme is appropriate for bilinear interpolation 
+      !!              on a general quadrilateral grid.    
+      !!              This scheme is also used in OASIS.
+      !!
+      !!              This routine is a derivative of the SCRIP software.
+      !!              Copyright 1997, 1998 the Regents of the University 
+      !!              of California. See SCRIP_Copyright.txt.
+      !!     
+      !! ** Action  :
+      !!
+      !! References : Jones, P.: A user's guide for SCRIP: A Spherical 
+      !!                Coordinate Remapping and Interpolation Package. 
+      !!                Version 1.4. Los Alamos. 
+      !!                  
+      !!         http://www.acl.lanl.gov/climate/software/SCRIP/SCRIPmain.html
+      !!
+      !! History
+      !!      ! 97-11 (A. Weaver, N. Daget)
+      !!      ! 06-03 (A. Vidard)
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+ 
+      !! * Arguments
+      REAL(KIND=wp), INTENT(IN) :: &
+         & pphi,   &           ! Geographical location of observation
+         & plam,   &
+         & pphimm, &           ! Geographical location of surrounding
+         & pphimp, &           ! model grid points
+         & pphipm, &
+         & pphipp, &
+         & plammm, &
+         & plammp, & 
+         & plampm, &
+         & plampp
+      REAL(KIND=wp), INTENT(OUT) :: &
+         & pbiwmm, &           ! Interpolation weights
+         & pbiwmp, &
+         & pbiwpm, &
+         & pbiwpp
+      LOGICAL, INTENT(out) :: &
+         & ldfail
+
+      !! * Local declarations
+      INTEGER :: &
+         & jiter
+      INTEGER :: &
+         & itermax
+      REAL(KIND=wp) :: &
+         & zphi,    &           ! Geographical location of observation
+         & zlam,    &
+         & zphimm,  &           ! Geographical location of surrounding
+         & zphimp,  &           ! model grid points
+         & zphipm,  &
+         & zphipp,  &
+         & zlammm,  &
+         & zlammp,  & 
+         & zlampm,  &
+         & zlampp,  &
+         & zdth1,   &
+         & zdth2,   &
+         & zdth3,   &
+         & zdthp,   &
+         & zdph1,   &
+         & zdph2,   &
+         & zdph3,   &
+         & zdphp,   &
+         & zmat1,   &
+         & zmat2,   &
+         & zmat3,   &
+         & zmat4,   &
+         & zdeli,   &
+         & zdelj,   &
+         & ziguess, &
+         & zjguess, &
+         & zeps,    &
+         & zdeterm, &
+         & z2pi,    &
+         & zhpi
+      
+      ! Initialization
+
+      ! Conversion to radians
+
+      zphi   = pphi   * rad
+      zlam   = plam   * rad
+      zphimm = pphimm * rad
+      zphimp = pphimp * rad
+      zphipm = pphipm * rad
+      zphipp = pphipp * rad
+      zlammm = plammm * rad
+      zlammp = plammp * rad
+      zlampm = plampm * rad
+      zlampp = plampp * rad
+
+      ldfail = .FALSE.
+
+      zdth1 = zphipm - zphimm
+      zdth2 = zphimp - zphimm
+      zdth3 = zphipp - zphipm - zdth2
+       
+      zdph1 = zlampm - zlammm
+      zdph2 = zlammp - zlammm
+      zdph3 = zlampp - zlampm
+       
+      z2pi = 2.0_wp * rpi
+       
+      IF ( zdph1 >  3.0_wp * rpi ) zdph1 = zdph1 - z2pi
+      IF ( zdph2 >  3.0_wp * rpi ) zdph2 = zdph2 - z2pi
+      IF ( zdph3 >  3.0_wp * rpi ) zdph3 = zdph3 - z2pi
+      IF ( zdph1 < -3.0_wp * rpi ) zdph1 = zdph1 + z2pi
+      IF ( zdph2 < -3.0_wp * rpi ) zdph2 = zdph2 + z2pi
+      IF ( zdph3 < -3.0_wp * rpi ) zdph3 = zdph3 + z2pi
+       
+      zdph3 = zdph3 - zdph2
+       
+      ziguess = 0.5_wp
+      zjguess = 0.5_wp
+       
+      itermax = 100
+
+#if defined key_sp
+      zeps = 1.0e-6_wp
+#else
+      zeps = 1.0e-10_wp      
+#endif
+  
+      !------------------------------------------------------------------------
+      ! Iterate to determine (i,j) in new coordinate system
+      !------------------------------------------------------------------------
+      jiter_loop: DO jiter = 1, itermax
+         
+         zdthp = zphi - zphimm - zdth1 * ziguess - zdth2 * zjguess &
+            &  - zdth3 * ziguess * zjguess
+         zdphp = zlam - zlammm
+         
+         zhpi = 0.5_wp * rpi
+         IF ( zdphp >  3.0_wp * zhpi ) zdphp = zdphp - z2pi
+         IF ( zdphp < -3.0_wp * zhpi ) zdphp = zdphp + z2pi
+         
+         zdphp = zdphp - zdph1 * ziguess - zdph2 * zjguess &
+            &  - zdph3 * ziguess * zjguess
+         
+         zmat1 = zdth1 + zdth3 * zjguess
+         zmat2 = zdth2 + zdth3 * ziguess
+         zmat3 = zdph1 + zdph3 * zjguess
+         zmat4 = zdph2 + zdph3 * ziguess
+         
+         ! Matrix determinant
+         zdeterm = zmat1 * zmat4 - zmat2 * zmat3
+         
+         zdeli = ( zdthp * zmat4 - zmat2 * zdphp) / zdeterm
+         zdelj = ( zmat1 * zdphp - zdthp * zmat3) / zdeterm
+         
+         IF ( ABS( zdeli ) < zeps .AND. ABS( zdelj ) < zeps ) EXIT jiter_loop
+         
+         ziguess = ziguess + zdeli
+         zjguess = zjguess + zdelj
+
+         ! DJL prevent ziguess and zjguess from going outside the range
+         ! 0 to 1
+         ! prevents interpolated value going wrong
+         ! for example sea ice concentration gt 1
+         
+         IF ( ziguess < 0 ) ziguess = 0.0_wp
+         IF ( zjguess < 0 ) zjguess = 0.0_wp
+         IF ( ziguess > 1 ) ziguess = 1.0_wp
+         IF ( zjguess > 1 ) zjguess = 1.0_wp
+         
+      END DO jiter_loop
+       
+      IF ( jiter <= itermax ) THEN
+           
+         ! Successfully found i,j, now compute the weights
+
+         pbiwmm = ( 1.0_wp - ziguess ) * ( 1.0_wp - zjguess )
+         pbiwmp = ( 1.0_wp - ziguess ) *            zjguess
+         pbiwpm =            ziguess   * ( 1.0_wp - zjguess )
+         pbiwpp =            ziguess   *            zjguess
+         
+      ELSEIF ( jiter > itermax ) THEN
+            
+         IF(lwp) THEN
+            
+            WRITE(numout,*)'Obs lat/lon  : ',pphi, plam
+            WRITE(numout,*)'Grid lats    : ',pphimm, pphimp, pphipm, pphipp
+            WRITE(numout,*)'Grid lons    : ',plammm, plammp, plampm, plampp
+            WRITE(numout,*)'Current i,j  : ',ziguess, zjguess
+            WRITE(numout,*)'Weights      : ',pbiwmm, pbiwmp, pbiwpm, pbiwpp
+            WRITE(numout,*)'jiter        = ',jiter
+            WRITE(numout,*)'zeps         = ',zeps
+            WRITE(numout,*)'zdeli, zdelj = ',zdeli, zdelj
+            WRITE(numout,*)' Iterations for i,j exceed max iteration count!'
+            WRITE(numout,*)
+            
+            ldfail = .TRUE.
+
+         ENDIF
+         
+      ENDIF
+    
+   END SUBROUTINE bil_wgt
+
+   SUBROUTINE lu_invmat( pmatin, kdim, pmatou )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                   ***  ROUTINE lu_invmat  ***
+      !!
+      !! ** Purpose : Invert a matrix using LU decomposition.
+      !!
+      !! ** Method  : 
+      !! 
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History
+      !!      ! 02-11 (A. Weaver, N. Daget)
+      !!      ! 06-03 (A. Vidard)
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!      ! 06-11 (NEMOVAR task force) Fix declaration of zd.
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kdim             ! Array dimension
+      REAL(KIND=wp), DIMENSION(kdim,kdim), INTENT(IN) :: &
+         & pmatin 
+      REAL(KIND=wp), DIMENSION(kdim,kdim), INTENT(OUT) :: &
+         & pmatou 
+  
+      !! * Local declarations
+      INTEGER :: &
+         & ji, &
+         & jj
+      INTEGER, DIMENSION(kdim) :: &
+         & indx
+      REAL(KIND=wp), DIMENSION(kdim,kdim) :: &
+         & zmat
+      REAL(KIND=wp) :: &
+         & zd
+
+      ! Invert the matrix       
+      DO jj = 1, kdim
+         DO ji = 1, kdim
+            pmatou(ji,jj) = 0.0_wp
+            zmat(ji,jj) = pmatin(ji,jj)
+         END DO
+         pmatou(jj,jj) = 1.0_wp
+      END DO
+      CALL lu_decomp( zmat, kdim, kdim, indx, zd )
+      DO jj = 1, kdim
+         CALL lu_backsb( zmat, kdim, kdim, indx, pmatou(1,jj) )
+      END DO
+      
+   END SUBROUTINE lu_invmat
+
+   SUBROUTINE lu_decomp( pmatin, kdim1, kdim2, kindex, pflt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                   ***  ROUTINE lu_decomp  ***
+      !!
+      !! ** Purpose : Compute the LU decomposition of a matrix
+      !!
+      !! ** Method  : 
+      !! 
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History
+      !!      ! 02-11 (A. Weaver, N. Daget)
+      !!      ! 06-03 (A. Vidard)
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+       
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kdim1, &   ! Array dimensions
+         & kdim2
+      INTEGER, DIMENSION(kdim1), INTENT(OUT) :: &
+         & kindex
+      REAL(KIND=wp), INTENT(OUT) :: &
+         & pflt
+      REAL(KIND=wp), DIMENSION(kdim2,kdim2), INTENT(INOUT) :: &
+         & pmatin 
+  
+      !! * Local declarations
+      INTEGER, PARAMETER :: &
+         & jpmax = 100
+      REAL(KIND=wp), PARAMETER :: &
+         & pptiny = 1.0e-20_wp
+      REAL(KIND=wp), DIMENSION(jpmax) :: &
+         & zvv
+      INTEGER :: &
+         & ji, &
+         & jj, &
+         & jk
+      INTEGER :: &
+         & imax
+      REAL(KIND=wp) :: &
+         & zsum,  &
+         & zdum,  &
+         & zaamax
+       
+      ! Main computation
+      pflt = 1.0_wp
+      DO ji = 1, kdim1
+         zaamax = 0.0_wp
+         DO jj = 1, kdim1
+            IF ( ABS( pmatin(ji,jj) ) > zaamax ) zaamax = ABS( pmatin(ji,jj) )
+         END DO
+         IF ( zaamax == 0.0_wp ) THEN
+            CALL ctl_stop( 'singular matrix' )
+         ENDIF 
+         zvv(ji) = 1.0_wp / zaamax
+      END DO
+      DO jj = 1, kdim1
+         DO ji = 1, jj-1
+            zsum = pmatin(ji,jj)
+            DO jk = 1, ji-1
+	       zsum = zsum - pmatin(ji,jk) * pmatin(jk,jj)
+	    END DO
+            pmatin(ji,jj) = zsum
+         END DO
+         zaamax = 0.0_wp
+         DO ji = jj, kdim1
+            zsum = pmatin(ji,jj)
+            DO jk = 1, jj-1
+               zsum = zsum - pmatin(ji,jk) * pmatin(jk,jj)
+            END DO
+            pmatin(ji,jj) = zsum
+            zdum = zvv(ji) * ABS( zsum )
+            IF ( zdum >= zaamax ) THEN
+               imax = ji
+               zaamax = zdum
+            ENDIF
+	 END DO
+         IF ( jj /= imax ) THEN
+            DO jk = 1, kdim1
+               zdum = pmatin(imax,jk)
+               pmatin(imax,jk) = pmatin(jj,jk)
+               pmatin(jj,jk) = zdum
+	    END DO
+            pflt = -pflt
+            zvv(imax) = zvv(jj)
+         ENDIF
+         kindex(jj) = imax
+         IF ( pmatin(jj,jj) == 0.0_wp ) pmatin(jj,jj) = pptiny
+         IF ( jj /= kdim1 ) THEN
+            zdum = 1.0_wp / pmatin(jj,jj)
+            DO ji = jj+1, kdim1
+               pmatin(ji,jj) = pmatin(ji,jj) * zdum
+	    END DO
+         ENDIF
+      END DO
+     
+   END SUBROUTINE lu_decomp
+     
+   SUBROUTINE lu_backsb( pmat, kdim1, kdim2, kindex, pvect )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                   ***  ROUTINE lu_backsb  ***
+      !!
+      !! ** Purpose : Back substitution
+      !!
+      !! ** Method  : 
+      !! 
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History
+      !!      ! 02-11 (A. Weaver, N. Daget)
+      !!      ! 06-03 (A. Vidard)
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!-----------------------------------------------------------------------
+      
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kdim1, &     ! Array dimensions
+         & kdim2
+      INTEGER, DIMENSION(kdim1), INTENT(IN) :: &
+         & kindex
+      REAL(KIND=wp), DIMENSION(kdim1), INTENT(INOUT) :: &
+         & pvect
+      REAL(KIND=wp), DIMENSION(kdim2,kdim2), INTENT(IN) :: &
+         & pmat
+  
+      !! * Local declarations
+      INTEGER :: &
+         & ji,  &
+         & jii, &
+         & jj,  &
+         & jll
+      REAL(KIND=wp) :: &
+         & zsum
+
+      ! Main computation
+      jii = 0
+      DO ji = 1, kdim1
+         jll = kindex(ji)
+         zsum = pvect(jll)
+         pvect(jll) = pvect(ji)
+         IF ( jii /= 0 ) THEN
+            DO jj = jii, ji-1
+               zsum = zsum - pmat(ji,jj) * pvect(jj)
+            END DO
+         ELSEIF ( zsum /= 0.0_wp ) THEN
+            jii = ji
+         ENDIF
+         pvect(ji) = zsum
+      END DO
+      DO ji = kdim1, 1, -1
+         zsum = pvect(ji)
+         DO jj = ji+1, kdim1
+            zsum = zsum - pmat(ji,jj) * pvect(jj)
+         END DO
+         pvect(ji) = zsum / pmat(ji,ji)
+      END DO
+     
+   END SUBROUTINE lu_backsb
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_z1d.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_z1d.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obsinter_z1d.h90	(revision 2202)
@@ -0,0 +1,185 @@
+   SUBROUTINE obs_int_z1d( kpk, kkco, k1dint, kdep, &
+      &                    pobsdep, pobsk, pobs2k,  &
+      &                    pobs, pdep, pobsmask )
+      !!---------------------------------------------------------------------
+      !!
+      !!                   ***  ROUTINE obs_int_z1d ***
+      !!
+      !! ** Purpose : Vertical interpolation to the observation point.
+      !!  
+      !! ** Method  : If k1dint = 0 then use linear interpolation.
+      !!              If k1dint = 1 then use cubic spline interpolation.
+      !! 
+      !! ** Action  :
+      !!
+      !! References :
+      !!
+      !! History
+      !!      ! 97-11 (A. Weaver, S. Ricci, N. Daget)
+      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!      ! 07-01 (K. Mogensen) Use profile rather than single level
+      !!---------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: kpk        ! Number of vertical levels
+      INTEGER, INTENT(IN) :: k1dint     ! 0 = linear; 1 = cubic spline interpolation 
+      INTEGER, INTENT(IN) :: kdep       ! Number of levels in profile
+      INTEGER, INTENT(IN), DIMENSION(kdep) :: &
+         & kkco                 ! Array indicies for interpolation
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kdep) :: &
+         & pobsdep              ! Depth of the observation
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
+         & pobsk,  &            ! Model profile at a given (lon,lat)
+         & pobs2k, &            ! 2nd derivative of the interpolating function
+         & pdep,   &            ! Model depth array
+         & pobsmask             ! Vertical mask
+      REAL(KIND=wp), INTENT(OUT), DIMENSION(kdep) :: &
+         & pobs                 ! Model equivalent at observation point
+  
+      !! * Local declarations
+      REAL(KIND=wp) :: z1dm       ! Distance above and below obs to model grid points
+      REAL(KIND=wp) :: z1dp         
+      REAL(KIND=wp) :: zsum       ! Dummy variables for computation
+      REAL(KIND=wp) :: zsum2
+      INTEGER :: jdep             ! Observation depths loop variable
+    
+      !------------------------------------------------------------------------
+      ! Loop over all observation depths
+      !------------------------------------------------------------------------
+
+      DO jdep = 1, kdep
+
+         !---------------------------------------------------------------------
+         ! Initialization
+         !---------------------------------------------------------------------
+         z1dm = ( pdep(kkco(jdep)) - pobsdep(jdep)      )
+         z1dp = ( pobsdep(jdep)    - pdep(kkco(jdep)-1) )
+         IF ( pobsmask(kkco(jdep)) == 0.0_wp ) z1dp = 0.0_wp
+
+         zsum = z1dm + z1dp
+         
+         IF ( k1dint == 0 ) THEN
+
+            !-----------------------------------------------------------------
+            !  Linear interpolation
+            !-----------------------------------------------------------------
+            pobs(jdep) = (   z1dm * pobsk(kkco(jdep)-1) &
+               &           + z1dp * pobsk(kkco(jdep)  ) ) / zsum
+
+         ELSEIF ( k1dint == 1 ) THEN
+
+            !-----------------------------------------------------------------
+            ! Cubic spline interpolation
+            !-----------------------------------------------------------------
+            zsum2 = zsum * zsum
+            pobs(jdep)  = (  z1dm                             * pobsk (kkco(jdep)-1) &
+               &           + z1dp                             * pobsk (kkco(jdep)  ) &
+               &           + ( z1dm * ( z1dm * z1dm - zsum2 ) * pobs2k(kkco(jdep)-1) &
+               &           +   z1dp * ( z1dp * z1dp - zsum2 ) * pobs2k(kkco(jdep)  ) &
+               &             ) / 6.0_wp                                              &
+               &          ) / zsum
+
+         ENDIF
+      END DO
+
+   END SUBROUTINE obs_int_z1d
+
+   SUBROUTINE obs_int_z1d_spl( kpk, pobsk, pobs2k, &
+      &                        pdep, pobsmask )
+      !!--------------------------------------------------------------------
+      !!
+      !!                  *** ROUTINE obs_int_z1d_spl ***
+      !!
+      !! ** Purpose : Compute the local vector of vertical second-derivatives 
+      !!              of the interpolating function used with a cubic spline.
+      !!  
+      !! ** Method  : 
+      !! 
+      !!    Top and bottom boundary conditions on the 2nd derivative are
+      !!    set to zero.
+      !!
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History
+      !!      ! 01-11 (A. Weaver, S. Ricci, N. Daget)
+      !!      ! 06-03 (G. Smith) Conversion to F90 for use with NEMOVAR
+      !!      ! 06-10 (A. Weaver) Cleanup
+      !!----------------------------------------------------------------------
+     
+      !! * Arguments
+      INTEGER, INTENT(IN) :: kpk               ! Number of vertical levels
+      REAL(KIND=wp), INTENT(IN), DIMENSION(kpk) :: &
+         & pobsk, &          ! Model profile at a given (lon,lat)
+         & pdep,  &          ! Model depth array
+         & pobsmask          ! Vertical mask
+      REAL(KIND=wp), INTENT(OUT), DIMENSION(kpk) :: &
+         & pobs2k            ! 2nd derivative of the interpolating function
+  
+      !! * Local declarations
+      INTEGER :: jk
+      REAL(KIND=wp) :: za
+      REAL(KIND=wp) :: zb
+      REAL(KIND=wp) :: zc
+      REAL(KIND=wp) :: zpa
+      REAL(KIND=wp) :: zkm
+      REAL(KIND=wp) :: zkp
+      REAL(KIND=wp) :: zk
+      REAL(KIND=wp), DIMENSION(kpk-1) :: &
+         & zs, &
+         & zp, &
+         & zu, &
+         & zv
+
+      !-----------------------------------------------------------------------
+      ! Matrix initialisation
+      !-----------------------------------------------------------------------
+      zs(1) =  0.0_wp
+      zp(1) =  0.0_wp
+      zv(1) = -0.5_wp
+      DO jk = 2, kpk-1
+         zs(jk) =  ( pdep(jk  ) - pdep(jk-1) ) &
+            &    / ( pdep(jk+1) - pdep(jk-1) )
+         zp(jk) = zs(jk) * zv(jk-1) + 2.0_wp
+         zv(jk) = ( zs(jk) - 1.0_wp ) / zp(jk)
+      END DO
+ 
+      !-----------------------------------------------------------------------
+      ! Solution of the tridiagonal system
+      !-----------------------------------------------------------------------
+ 
+      ! Top boundary condition
+      zu(1) = 0.0_wp
+ 
+      DO jk = 2, kpk-1
+         za = pdep(jk+1) - pdep(jk-1)
+         zb = pdep(jk+1) - pdep(jk  )
+         zc = pdep(jk  ) - pdep(jk-1)
+ 
+         zpa = 6.0_wp / ( zp(jk) * za )
+         zkm = zpa / zc
+         zkp = zpa / zb
+         zk  = - ( zkm + zkp )
+  
+         zu(jk) =  pobsk(jk+1) * zkp  &
+            &    + pobsk(jk  ) * zk   &
+            &    + pobsk(jk-1) * zkm  &
+            &    + zu(jk-1) * ( -zs(jk) / zp(jk) )
+      END DO
+ 
+      !-----------------------------------------------------------------------
+      ! Second derivative
+      !-----------------------------------------------------------------------
+      pobs2k(kpk) = 0.0_wp
+ 
+      ! Bottom boundary condition
+      DO jk = kpk-1, 1, -1
+         pobs2k(jk) = zv(jk) * pobs2k(jk+1) + zu(jk)
+         IF ( pobsmask(jk+1) == 0.0_wp ) pobs2k(jk) = 0.0_wp
+      END DO
+ 
+  END SUBROUTINE obs_int_z1d_spl
+
+
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obsprof_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obsprof_io.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obsprof_io.h90	(revision 2202)
@@ -0,0 +1,829 @@
+
+   SUBROUTINE read_enactfile( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_enactfile **
+      !!
+      !! ** Purpose : Read from file the profile ENACT observations.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original based on old versions
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      !! * Local declarations
+      INTEGER :: iobs                ! Number of observations
+      INTEGER :: ilev                      ! Number of levels
+      INTEGER :: i_file_id
+      INTEGER :: i_obs_id
+      INTEGER :: i_lev_id
+      INTEGER :: i_phi_id
+      INTEGER :: i_lam_id
+      INTEGER :: i_depth_id
+      INTEGER :: i_var_id
+      INTEGER :: i_pl_num_id
+      INTEGER :: i_reference_date_time_id
+      INTEGER :: i_format_version_id
+      INTEGER :: i_juld_id
+      INTEGER :: i_data_type_id
+      INTEGER :: i_wmo_inst_type_id
+      INTEGER :: i_qc_var_id
+      INTEGER :: i_dc_ref_id
+      INTEGER :: i_qc_flag_id
+      CHARACTER(LEN=40) :: cl_fld_lam
+      CHARACTER(LEN=40) :: cl_fld_phi
+      CHARACTER(LEN=40) :: cl_fld_depth 
+      CHARACTER(LEN=40) :: cl_fld_var_tp
+      CHARACTER(LEN=40) :: cl_fld_var_s
+      CHARACTER(LEN=40) :: cl_fld_var_ti
+      CHARACTER(LEN=40) :: cl_fld_var_juld_qc
+      CHARACTER(LEN=40) :: cl_fld_var_pos_qc
+      CHARACTER(LEN=40) :: cl_fld_var_depth_qc 
+      CHARACTER(LEN=40) :: cl_fld_var_qc_t
+      CHARACTER(LEN=40) :: cl_fld_var_qc_s
+      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_t
+      CHARACTER(LEN=40) :: cl_fld_var_prof_qc_s
+      CHARACTER(LEN=40) :: cl_fld_reference_date_time
+      CHARACTER(LEN=40) :: cl_fld_juld
+      CHARACTER(LEN=40) :: cl_fld_data_type
+      CHARACTER(LEN=40) :: cl_fld_pl_num
+      CHARACTER(LEN=40) :: cl_fld_format_version
+      CHARACTER(LEN=40) :: cl_fld_wmo_inst_type
+      CHARACTER(LEN=40) :: cl_fld_qc_flags_profiles
+      CHARACTER(LEN=40) :: cl_fld_qc_flags_levels
+
+      CHARACTER(LEN=14), PARAMETER :: cl_name = 'read_enactfile'
+      CHARACTER(LEN=16)            :: cl_data_type = ''
+      CHARACTER(LEN=4 )            :: cl_format_version = ''
+      INTEGER, DIMENSION(1) :: istart1, icount1
+      INTEGER, DIMENSION(2) :: istart2, icount2
+      CHARACTER(len=imaxlev) :: clqc
+      CHARACTER(len=1) :: cqc
+      INTEGER :: ji, jk
+      INTEGER, ALLOCATABLE, DIMENSION(:) :: iqc1
+      INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iqc2
+
+      !-----------------------------------------------------------------------
+      ! Initialization
+      !-----------------------------------------------------------------------
+
+      cl_fld_lam                 = 'LONGITUDE'
+      cl_fld_phi                 = 'LATITUDE'
+      cl_fld_depth               = 'DEPH_CORRECTED'
+      cl_fld_reference_date_time = 'REFERENCE_DATE_TIME'
+      cl_fld_juld                = 'JULD'
+      cl_fld_data_type           = 'DATA_TYPE'
+      cl_fld_format_version      = 'FORMAT_VERSION'
+      cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
+      cl_fld_pl_num              = 'PLATFORM_NUMBER'
+
+      cl_fld_var_qc_t            = 'POTM_CORRECTED_QC'
+      cl_fld_var_prof_qc_t       = 'PROFILE_POTM_QC'
+      cl_fld_var_tp              = 'POTM_CORRECTED'
+      cl_fld_var_qc_s            = 'PSAL_CORRECTED_QC'
+      cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
+      cl_fld_var_s               = 'PSAL_CORRECTED'
+      cl_fld_var_depth_qc        = 'DEPH_CORRECTED_QC'
+      cl_fld_var_juld_qc         = 'JULD_QC'
+      cl_fld_var_pos_qc          = 'POSITION_QC'
+      cl_fld_var_ti              = 'TEMP'
+      cl_fld_qc_flags_profiles   = 'QC_FLAGS_PROFILES'
+      cl_fld_qc_flags_levels     = 'QC_FLAGS_LEVELS'
+
+      icount1(1) = 1 
+
+      !-----------------------------------------------------------------------
+      ! Open file
+      !-----------------------------------------------------------------------
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
+            &      i_file_id ),           cl_name, __LINE__ )
+
+      !-----------------------------------------------------------------------
+      ! Read the heading of the file
+      !-----------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_data_type,      &
+         &         i_data_type_id ),      cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_data_type_id,        &
+         &         cl_data_type ),        cl_name, __LINE__ )
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_format_version, &
+         &         i_format_version_id ), cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_format_version_id,   &
+         &         cl_format_version ),   cl_name, __LINE__ )
+      
+      CALL str_c_to_for( cl_data_type )
+      CALL str_c_to_for( cl_format_version )
+      
+      IF(ldwp)WRITE(kunit,*)
+      IF(ldwp)WRITE(kunit,*) ' read_enactfile :' 
+      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
+      IF(ldwp)WRITE(kunit,*) '               Data type           = ', &
+         &                TRIM( ADJUSTL( cl_data_type ) )
+      IF(ldwp)WRITE(kunit,*) '               Format version      = ',  &
+         &                TRIM( ADJUSTL( cl_format_version ) )
+      
+      IF ( ( ( INDEX( cl_data_type,"ENACT v1.0" ) == 1 ) .OR.   &
+         &   ( INDEX( cl_data_type,"ENACT v1.4" ) == 1 ) .OR.   &
+         &   ( INDEX( cl_data_type,"ENACT v1.5" ) == 1 ) .OR.   &
+         &   ( INDEX( cl_data_type,"ENSEMBLES EN3 v1" ) == 1 )      ) &
+         &   .AND.                                              &
+         &   ( INDEX( cl_format_version,"2.0"   ) == 1 ) ) THEN
+         IF(ldwp)WRITE(kunit,*)'               Valid input file'
+      ELSE
+         CALL fatal_error( 'Invalid input file', __LINE__ )
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Read the number of observations and levels to allocate arrays
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_PROF', i_obs_id ),         &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ),     &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'N_LEVELS', i_lev_id ),     &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
+         &         cl_name, __LINE__ )
+      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
+      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
+      IF(ldwp)WRITE(kunit,*) 
+      IF (ilev > imaxlev) THEN
+         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Allocate arrays
+      !---------------------------------------------------------------------
+
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
+      inpfile%cname(1) = 'POTM'
+      inpfile%cname(2) = 'PSAL'
+      inpfile%coblong(1) = 'Potential temperature'
+      inpfile%coblong(2) = 'Practical salinity'
+      inpfile%cobunit(1) = 'Degrees Celsius'
+      inpfile%cobunit(2) = 'PSU'
+      inpfile%cextname(1) = 'TEMP'
+      inpfile%cextlong(1) = 'Insitu temperature'
+      inpfile%cextunit(1) = 'Degrees Celsius'
+
+      !---------------------------------------------------------------------
+      ! Read the QC atributes
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                         &
+         &         cl_name, __LINE__ )        
+      istart2(1) = 1
+      icount2(2) = 1
+      icount2(1) = ilev
+      DO ji = 1, iobs 
+         istart2(2) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
+            &                         start = istart2, count = icount2),                              &
+            &         cl_name, __LINE__ )
+         DO jk = 1, ilev
+            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+         END DO
+      END DO
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ),                         &
+         &         cl_name, __LINE__ )
+      DO ji = 1, iobs
+         istart2(2) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
+            &                         start = istart2, count = icount2),                              &
+            &         cl_name, __LINE__ )
+         DO jk = 1, ilev
+            inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+         END DO
+      END DO
+      ! No depth QC in files
+      DO ji = 1, iobs
+         DO jk = 1, ilev
+            inpfile%idqc(jk,ji)  = 1
+            inpfile%idqcf(:,jk,ji) = 0
+         END DO
+      END DO
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
+         &         cl_name,  __LINE__ )
+      DO ji = 1,iobs
+         istart1(1) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+            &                         start = istart1, count = icount1),                              &
+            &         cl_name, __LINE__ )
+         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
+      END DO
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                    & 
+         &         cl_name, __LINE__ ) 
+      DO ji = 1,iobs
+         istart1(1) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+            &                         start = istart1, count = icount1),                              &
+            &         cl_name, __LINE__ )
+         inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
+      END DO
+!!      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_juld_qc, i_qc_var_id ),                       &
+!!         &         cl_name, __LINE__ ) 
+!!      !DO ji = 1,iobs
+!!         istart1(1) = ji
+!!         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+!!            &                         start = istart1, count = icount1),                              &
+!!            &         cl_name, __LINE__ )
+!!         inpfile%itqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
+!!         inpfile%itqcf(:,ji) = 0
+!!      END DO
+      ! Since the flags are not set in the ENACT files we reset them to 0
+      inpfile%itqc(:)    = 1      
+      inpfile%itqcf(:,:) = 0
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
+         &         cl_name, __LINE__ ) 
+      DO ji = 1,iobs
+         istart1(1) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+            &                         start = istart1, count = icount1),                              &
+            &         cl_name, __LINE__ )
+         inpfile%ipqc(ji)    = IACHAR( cqc ) - IACHAR( '0' )
+         inpfile%ipqcf(:,ji) = 0
+      END DO
+      DO ji = 1,iobs
+         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
+      END DO
+      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_profiles, i_qc_flag_id ) == nf90_noerr ) THEN
+         ALLOCATE( &
+            & iqc1(iobs) &
+            & )
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc1 ),                                &
+            &         cl_name, __LINE__ )
+         DO ji = 1,iobs
+            inpfile%ioqcf(1,ji)   = iqc1(ji)
+            inpfile%ivqcf(1,ji,:) = iqc1(ji)
+            inpfile%ioqcf(2,ji)   = 0
+            inpfile%ivqcf(2,ji,:) = 0
+         END DO
+         DEALLOCATE( &
+            & iqc1 &
+            & )
+      ELSE
+         IF(ldwp) WRITE(kunit,*)'No QC profile flags in file'
+         inpfile%ioqcf(:,:)   = 0
+         inpfile%ivqcf(:,:,:) = 0
+      ENDIF
+      IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_levels, i_qc_flag_id ) == nf90_noerr ) THEN
+         ALLOCATE( &
+            & iqc2(ilev,iobs) &
+            & )
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_flag_id, iqc2 ),                                &
+            &         cl_name, __LINE__ )
+         DO ji = 1,iobs
+            DO jk = 1,ilev
+               inpfile%ivlqcf(1,jk,ji,:) = iqc2(jk,ji)
+               inpfile%ivlqcf(2,jk,ji,:) = 0
+            END DO
+         END DO
+         DEALLOCATE( &
+            & iqc2 &
+            & )
+      ELSE
+         IF(ldwp) WRITE(kunit,*)'No QC level flags in file'
+         inpfile%ivlqcf(:,:,:,:) = 0
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Read the time/position variables 
+      !---------------------------------------------------------------------
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
+            &         cl_name, __LINE__ )         
+      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                             &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_reference_date_time, i_reference_date_time_id ), &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_reference_date_time_id, inpfile%cdjuldref ),          &
+         &         cl_name, __LINE__ )
+      
+      !---------------------------------------------------------------------
+      ! Read the platform information
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
+         &         cl_name, __LINE__ )          
+      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
+         &         cl_name, __LINE__ )         
+      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
+         &         cl_name, __LINE__ )         
+
+      !---------------------------------------------------------------------
+      ! Read the variables
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_tp, i_var_id ),                              &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,1) ),                         &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                               &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                         &
+         &         cl_name, __LINE__ )
+ 
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_ti, i_var_id ),                              &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
+         &         cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Close file
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Set file indexes
+      !---------------------------------------------------------------------
+      DO ji = 1, inpfile%nobs
+         inpfile%kindex(ji) = ji
+      END DO
+
+   END SUBROUTINE read_enactfile
+
+   SUBROUTINE read_coriofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_coriofile **
+      !!
+      !! ** Purpose : Read from file the profile CORIO observations.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original based on old versions
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output enactfile structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      INTEGER  :: &
+         & iobs, &
+         & ilev
+      !! * Local declarations
+      INTEGER :: &
+         & i_file_id,                &
+         & i_obs_id,                 &
+         & i_lev_id,                 &
+         & i_phi_id,                 & 
+         & i_lam_id,                 &
+         & i_depth_id,               &
+         & i_pres_id,                &
+         & i_var_id,                 &
+         & i_pl_num_id,              &
+         & i_format_version_id,      &
+         & i_juld_id,                &
+         & i_data_type_id,           &
+         & i_wmo_inst_type_id,       &
+         & i_qc_var_id,              &
+         & i_dc_ref_id
+      CHARACTER(LEN=40) :: & 
+         & cl_fld_lam,                 &
+         & cl_fld_phi,                 &
+         & cl_fld_depth,               & 
+         & cl_fld_depth_qc,            & 
+         & cl_fld_pres,                & 
+         & cl_fld_pres_qc,             & 
+         & cl_fld_var_t,               &
+         & cl_fld_var_s,               &
+         & cl_fld_var_ti,              &
+         & cl_fld_var_pos_qc,          &
+         & cl_fld_var_qc_t,            &
+         & cl_fld_var_qc_s,            &
+         & cl_fld_var_prof_qc_t,       &
+         & cl_fld_var_prof_qc_s,       &
+         & cl_fld_dc_ref,              &
+         & cl_fld_juld,                &
+         & cl_fld_pl_num,              &
+         & cl_fld_wmo_inst_type
+      CHARACTER(LEN=14), PARAMETER :: &
+         & cl_name = 'read_coriofile'
+      CHARACTER(LEN=4 )            :: &
+         & cl_format_version = ''
+      INTEGER, DIMENSION(1) :: &
+         & istart1, icount1
+      INTEGER, DIMENSION(2) :: &
+         & istart2, icount2
+      CHARACTER(len=imaxlev) :: &
+         & clqc
+      CHARACTER(len=1) :: &
+         & cqc
+      CHARACTER(len=256) :: &
+         & cdjulref
+      INTEGER :: &
+         & ji, jk
+      INTEGER :: &
+         & iformat
+      LOGICAL :: & 
+         & lsal
+      REAL(fbdp), DIMENSION(:,:), ALLOCATABLE :: &
+         & zpres
+      INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
+         & ipresqc
+      CHARACTER(len=256) :: &
+         & cerr
+      !-----------------------------------------------------------------------
+      ! Initialization
+      !-----------------------------------------------------------------------
+
+      icount1(1) = 1 
+      lsal = .TRUE.
+
+      !-----------------------------------------------------------------------
+      ! Open file
+      !-----------------------------------------------------------------------
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
+            &      i_file_id ),           cl_name, __LINE__ )
+
+      !-----------------------------------------------------------------------
+      ! Check format and set variables accordingly
+      !-----------------------------------------------------------------------
+
+      IF ( ( nf90_inq_dimid( i_file_id, 'N_PROF', i_obs_id ) == nf90_noerr ) .AND. &
+         & ( nf90_inq_dimid( i_file_id, 'N_LEVELS', i_lev_id ) == nf90_noerr ) ) THEN
+         iformat = 1
+      ELSEIF ( ( nf90_inq_dimid( i_file_id, 'mN_PROF', i_obs_id ) == nf90_noerr ) .AND. &
+         & ( nf90_inq_dimid( i_file_id, 'mN_ZLEV', i_lev_id ) == nf90_noerr ) ) THEN
+         iformat = 2
+      ELSE
+         WRITE(cerr,'(2A)')'Invalid data format in ',cl_name
+         CALL fatal_error( cerr, __LINE__ )
+      ENDIF
+      IF ( iformat == 1 ) THEN
+         cl_fld_lam                 = 'LONGITUDE'
+         cl_fld_phi                 = 'LATITUDE'  
+         cl_fld_depth               = 'DEPH'
+         cl_fld_depth_qc            = 'DEPH_QC'
+         cl_fld_pres                = 'PRES'
+         cl_fld_pres_qc             = 'PRES_QC'
+         cl_fld_juld                = 'JULD'
+         cl_fld_wmo_inst_type       = 'WMO_INST_TYPE'
+         cl_fld_dc_ref              = 'DC_REFERENCE'
+         cl_fld_pl_num              = 'PLATFORM_NUMBER'
+         cl_fld_var_qc_t            = 'TEMP_QC'
+         cl_fld_var_prof_qc_t       = 'PROFILE_TEMP_QC'
+         cl_fld_var_t               = 'TEMP'
+         cl_fld_var_qc_s            = 'PSAL_QC'
+         cl_fld_var_prof_qc_s       = 'PROFILE_PSAL_QC'
+         cl_fld_var_s               = 'PSAL'
+         cl_fld_var_pos_qc          = 'POSITION_QC'
+      ELSEIF ( iformat==2 ) THEN
+         cl_fld_lam                 = 'LONGITUDE'
+         cl_fld_phi                 = 'LATITUDE'  
+         cl_fld_depth               = 'DEPH'
+         cl_fld_depth_qc            = 'QC_DEPH'
+         cl_fld_pres                = 'PRES'
+         cl_fld_pres_qc             = 'QC_PRES'
+         cl_fld_juld                = 'JULD'
+         cl_fld_wmo_inst_type       = 'INST_TYPE'
+         cl_fld_dc_ref              = 'REFERENCE'
+         cl_fld_pl_num              = 'PLATFORM_NUMBER'
+         cl_fld_var_qc_t            = 'QC_TEMP'
+         cl_fld_var_prof_qc_t       = 'Q_PROFILE_TEMP'
+         cl_fld_var_t               = 'TEMP'
+         cl_fld_var_qc_s            = 'QC_PSAL'
+         cl_fld_var_prof_qc_s       = 'Q_PROFILE_PSAL'
+         cl_fld_var_s               = 'PSAL'
+         cl_fld_var_pos_qc          = 'Q_POSITION'
+      ENDIF
+
+      !-----------------------------------------------------------------------
+      ! Read the heading of the file
+      !-----------------------------------------------------------------------
+
+      IF(ldwp)WRITE(kunit,*)
+      IF(ldwp)WRITE(kunit,*) ' read_coriofile :' 
+      IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
+      IF(ldwp)WRITE(kunit,*) '               Format version      = ', iformat
+
+      !---------------------------------------------------------------------
+      ! Read the number of observations and levels to allocate arrays
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
+         &         cl_name, __LINE__ )
+      IF(ldwp)WRITE(kunit,*) '               No. of data records = ', iobs
+      IF(ldwp)WRITE(kunit,*) '               No. of levels       = ', ilev
+      IF(ldwp)WRITE(kunit,*) 
+      IF (ilev > imaxlev) THEN
+         CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Allocate arrays
+      !---------------------------------------------------------------------
+
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
+      inpfile%cname(1) = 'POTM'
+      inpfile%cname(2) = 'PSAL'
+      inpfile%coblong(1) = 'Potential temperature'
+      inpfile%coblong(2) = 'Practical salinity'
+      inpfile%cobunit(1) = 'Degrees Celsius'
+      inpfile%cobunit(2) = 'PSU'
+      inpfile%cextname(1) = 'TEMP'
+      inpfile%cextlong(1) = 'Insitu temperature'
+      inpfile%cextunit(1) = 'Degrees Celsius'
+      ALLOCATE( &
+         & zpres(ilev,iobs),  &
+         & ipresqc(ilev,iobs) &
+         & )
+      !---------------------------------------------------------------------
+      ! Get julian data reference (iformat==2)
+      !---------------------------------------------------------------------
+
+      IF (iformat==2) THEN
+         CALL chkerr ( nf90_get_att( i_file_id, nf90_global, &
+            &                        "Reference_date_time", cdjulref ), &
+            &         cl_name, __LINE__ )
+         inpfile%cdjuldref = cdjulref(7:10)//cdjulref(4:5)// &
+            & cdjulref(1:2)//cdjulref(12:13)//cdjulref(15:16)//cdjulref(18:19)
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Read the QC attributes
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ),                                &
+         &         cl_name, __LINE__ )
+      istart2(1) = 1
+      icount2(2) = 1
+      icount2(1) = ilev
+      DO ji = 1, iobs 
+         istart2(2) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                   &
+            &                         start = istart2, count = icount2),                              &
+            &         cl_name, __LINE__ )
+         DO jk = 1, ilev
+            inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+         END DO
+      END DO
+      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ) == nf90_noerr ) THEN
+         DO ji = 1, iobs
+            istart2(2) = ji
+            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
+               &                         start = istart2, count = icount2),                           &
+               &         cl_name, __LINE__ )
+            DO jk = 1, ilev
+               inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+            END DO
+         END DO
+      ELSE
+         inpfile%ivlqc(:,:,2) = 4
+         inpfile%pob(:,:,2) = fbrmdi
+         lsal = .FALSE.
+      ENDIF
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ),                    &
+         &         cl_name,  __LINE__ )
+      DO ji = 1,iobs
+         istart1(1) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+            &                         start = istart1, count = icount1),                              &
+            &         cl_name, __LINE__ )
+         inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
+      END DO
+      IF (lsal) THEN
+         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ),                 & 
+            &         cl_name, __LINE__ ) 
+         DO ji = 1,iobs
+            istart1(1) = ji
+            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                 &
+               &                         start = istart1, count = icount1),                           &
+               &         cl_name, __LINE__ )
+            inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
+         END DO
+      ELSE
+         inpfile%ivqc(:,2) = 4
+      ENDIF
+      DO ji = 1,iobs
+         inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
+      END DO
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ),                       &
+         &         cl_name, __LINE__ ) 
+      DO ji = 1, iobs
+         istart1(1) = ji
+         CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, cqc,                                    &
+            &                         start = istart1, count = icount1),                              &
+            &         cl_name, __LINE__ )
+         inpfile%ipqc(ji)  = IACHAR( cqc ) - IACHAR( '0' )
+      END DO
+      
+      !---------------------------------------------------------------------
+      ! Read the time/position variables 
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ),                               &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_juld_id, inpfile%ptim ),                              &
+         &         cl_name, __LINE__ )
+      IF (iformat==1) THEN
+         CALL chkerr ( nf90_get_att( i_file_id, i_juld_id, &
+            &                        "units", cdjulref ), &
+            &         cl_name, __LINE__ )
+         inpfile%cdjuldref = cdjulref(12:15)//cdjulref(17:18)// &
+            & cdjulref(20:21)//cdjulref(23:24)//cdjulref(26:27)//&
+            & cdjulref(29:30)
+      ENDIF
+      
+      IF ( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ) == nf90_noerr ) THEN
+         CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, inpfile%pdep ),                          &
+            &         cl_name, __LINE__ )
+         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth_qc, i_qc_var_id ),                      & 
+            &         cl_name, __LINE__ ) 
+         DO ji = 1, iobs
+            istart2(2) = ji
+            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
+               &                         start = istart2, count = icount2),                           &
+               &         cl_name, __LINE__ )
+            DO jk = 1, ilev
+               inpfile%idqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+            END DO
+         END DO
+      ELSE
+         inpfile%pdep(:,:) = fbrmdi
+         inpfile%idqc(:,:) = 4
+      ENDIF
+
+      IF ( nf90_inq_varid( i_file_id, cl_fld_pres, i_pres_id ) == nf90_noerr ) THEN
+         CALL chkerr( nf90_get_var  ( i_file_id, i_pres_id, zpres ),                                  &
+            &         cl_name, __LINE__ )
+         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pres_qc, i_qc_var_id ),                       & 
+            &         cl_name, __LINE__ ) 
+         DO ji = 1, iobs
+            istart2(2) = ji
+            CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, clqc,                                &
+               &                         start = istart2, count = icount2),                           &
+               &         cl_name, __LINE__ )
+            DO jk = 1, ilev
+               ipresqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
+            END DO
+         END DO
+      ELSE
+         zpres(:,:) = fbrmdi
+         ipresqc(:,:) = 4
+      ENDIF
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, inpfile%pphi ),                               &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, inpfile%plam ),                               &
+         &         cl_name, __LINE__ )
+      
+      !---------------------------------------------------------------------
+      ! Read the platform information
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ),             &
+         &         cl_name, __LINE__ )          
+      CALL chkerr( nf90_get_var  ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ),                    &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ),                           &
+         &         cl_name, __LINE__ )         
+      CALL chkerr( nf90_get_var  ( i_file_id, i_pl_num_id, inpfile%cdwmo ),                           &
+         &         cl_name, __LINE__ )         
+
+      
+      !---------------------------------------------------------------------
+      ! Read the variables
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_t, i_var_id ),                               &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pext(:,:,1) ),                        &
+         &         cl_name, __LINE__ )
+
+      IF (lsal) THEN      
+         CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ),                            &
+            &         cl_name, __LINE__ )
+         CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, inpfile%pob(:,:,2) ),                      &
+            &         cl_name, __LINE__ )
+      ENDIF
+
+      !---------------------------------------------------------------------
+      ! Close file
+      !---------------------------------------------------------------------
+         
+      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Set file indexes
+      !---------------------------------------------------------------------
+      DO ji = 1, inpfile%nobs
+         inpfile%kindex(ji) = ji
+      END DO
+      
+      !---------------------------------------------------------------------
+      !  Coriolis data conversion from insitu to potential temperature
+      !---------------------------------------------------------------------
+      !---------------------------------------------------------------------
+      !  Convert pressure to depth if depth not present
+      !---------------------------------------------------------------------
+      DO ji = 1, inpfile%nobs
+         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
+            DO jk = 1, inpfile%nlev
+               IF ( inpfile%pdep(jk,ji) >= 9999.0 ) THEN
+                  IF ( zpres(jk,ji) < 9999.0 ) THEN
+                     inpfile%pdep(jk,ji) = &
+                        & p_to_dep( REAL(zpres(jk,ji),wp), REAL(inpfile%pphi(ji),wp) )
+                     inpfile%idqc(jk,ji) = ipresqc(jk,ji)
+                  ENDIF
+               ENDIF
+            END DO
+         ENDIF
+      END DO
+      
+      !---------------------------------------------------------------------
+      !  Convert depth to pressure if pressure not present
+      !---------------------------------------------------------------------
+      DO ji = 1, inpfile%nobs
+         IF ( inpfile%pphi(ji) < 9999.0 ) THEN
+            DO jk = 1, inpfile%nlev
+               IF ( zpres(jk,ji) >= 9999.0 ) THEN
+                  IF ( inpfile%pdep(jk,ji) < 9999.0 ) THEN
+                     zpres(jk,ji) = dep_to_p( REAL(inpfile%pdep(jk,ji),wp), &
+                        &                            REAL(inpfile%pphi(ji),wp) )
+                     ipresqc(jk,ji) = inpfile%idqc(jk,ji)
+                  ENDIF
+               ENDIF
+            END DO
+         ENDIF
+      END DO
+      
+      !---------------------------------------------------------------------
+      !  Convert insitu temperature to potential temperature if
+      !  salinity, insitu temperature and pressure are present
+      !---------------------------------------------------------------------
+      DO ji = 1, inpfile%nobs
+         DO jk = 1, inpfile%nlev
+            IF (( inpfile%pob(jk,ji,2) < 9999.0 ) .AND. &
+               &( inpfile%pext(jk,ji,1) < 9999.0 ) .AND. &
+               &( zpres(jk,ji) < 9999.0 ) ) THEN
+               inpfile%pob(jk,ji,1) = potemp( REAL(inpfile%pob(jk,ji,2), wp),  &
+                  &                           REAL(inpfile%pext(jk,ji,1), wp), &
+                  &                           REAL(zpres(jk,ji),wp),  &
+                  &                           0.0_wp )
+            ELSE
+               inpfile%pob(jk,ji,1) = fbrmdi
+            ENDIF
+         END DO
+      END DO
+
+      !---------------------------------------------------------------------
+      !  Initialize flags since they are not in the CORIOLIS input files
+      !---------------------------------------------------------------------
+
+      inpfile%ioqcf(:,:)      = 0
+      inpfile%ipqcf(:,:)      = 0
+      inpfile%itqcf(:,:)      = 0
+      inpfile%idqcf(:,:,:)    = 0
+      inpfile%ivqcf(:,:,:)    = 0
+      inpfile%ivlqcf(:,:,:,:) = 0
+
+   END SUBROUTINE read_coriofile
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obsseaice_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obsseaice_io.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obsseaice_io.h90	(revision 2202)
@@ -0,0 +1,264 @@
+   SUBROUTINE read_seaice( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_seaice **
+      !!
+      !! ** Purpose : Read from file the SEAICE observations.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original based on old versions
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      !! * Local declarations
+      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_seaice'
+      INTEGER :: i_file_id    ! netcdf IDS
+      INTEGER :: i_time_id
+      INTEGER :: i_ni_id
+      INTEGER :: i_data_id
+      INTEGER :: i_var_id
+      INTEGER :: i_data       ! Number of data per parameter in current file
+      INTEGER :: i_time       ! Number of reference times in file
+      INTEGER, DIMENSION(:), POINTER :: &
+         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
+      INTEGER, DIMENSION(:,:), POINTER :: &
+         & i_dtime, &       ! Offset in seconds since reference time
+         & i_qc,    &       ! Quality control flag.
+         & i_type           ! Type of seaice measurement.            
+      REAL(wp), DIMENSION(:), POINTER :: &
+         & z_phi,   &       ! Latitudes
+         & z_lam            ! Longitudes
+      REAL(wp), DIMENSION(:,:), POINTER :: &
+         & z_seaice         ! Seaice data     
+      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
+      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
+      INTEGER :: iilen          ! Length of netCDF attributes
+      INTEGER :: itype          ! Typeof netCDF attributes
+      REAL(KIND=wp) :: zsca      ! Scale factor
+      REAL(KIND=wp) :: zoff      ! Offset for data in netcdf file
+      REAL(KIND=wp) :: z_offset  ! Offset for time conversion
+      REAL(KIND=wp) :: zfill     ! Fill value in netcdf file
+      CHARACTER (len=33) ::creftime     ! Reference time of file
+      INTEGER :: i_refyear       ! Integer version of reference time
+      INTEGER :: i_refmonth
+      INTEGER :: i_refday
+      INTEGER :: i_refhour
+      INTEGER :: i_refmin
+      INTEGER :: i_refsec
+      INTEGER :: ichunk
+      INTEGER :: jtim
+      INTEGER :: jobs
+      INTEGER :: iobs
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
+         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
+      
+      ! Get the netCDF dimensions
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
+         &       cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
+         &                              len = i_time ),  &
+         &      cpname, __LINE__ )
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
+         &       cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
+         &                              len = i_data ),  &
+         &      cpname, __LINE__ )
+      
+      
+      ! Allocate NetCDF variables
+      
+      ALLOCATE( &
+         & i_reftime    ( i_time                 ), &
+         & i_dtime      ( i_data,i_time  ), &      
+         & i_qc         ( i_data,i_time  ), & 
+         & i_type       ( i_data,i_time  ), &     
+         & z_phi        ( i_data                 ), &   
+         & z_lam        ( i_data                 ), &  
+         & z_seaice        ( i_data,i_time  )  &
+         & )
+      
+      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_time
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
+         &       cpname, __LINE__ )
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "units",creftime), cpname,  __LINE__ )
+      ELSE
+         creftime = "seconds since 1981-01-01 00:00:00"
+      ENDIF
+      READ(creftime(15:18),*)i_refyear
+      READ(creftime(20:21),*)i_refmonth
+      READ(creftime(23:24),*)i_refday
+      READ(creftime(26:27),*)i_refhour
+      READ(creftime(29:30),*)i_refmin
+      READ(creftime(32:33),*)i_refsec
+      !Work out offset in days between reference time and 1/1/1950.
+      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
+         &           i_refmonth, i_refyear, z_offset)
+      
+      ! Get list of times for each ob in seconds relative to reference time
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'SeaIce_dtime', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
+         &       cpname, __LINE__ )
+      zsca = 1.0      
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "scale_factor",zsca), cpname,  __LINE__ )
+      ENDIF
+      zoff = 0.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "add_offset",zoff), cpname,  __LINE__ )
+      ENDIF
+      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
+         &                 + zoff)
+      
+      ! Get longitudes
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
+         &         cpname, __LINE__ )
+      
+      ! Get latitudes
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
+         &         cpname, __LINE__ )
+      
+      ! Get seaice data
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_ice_concentration', &
+         &                         i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_seaice), &
+         &       cpname, __LINE__ )
+      zoff = 0.
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "scale_factor",zsca), cpname, __LINE__ )
+      ENDIF
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                       == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                       "scale_factor",zsca), cpname, __LINE__ )
+      ENDIF
+      zfill = 0.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
+         &                       == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                       "_FillValue",zfill), cpname, __LINE__ )
+      ENDIF
+      WHERE(z_seaice(:,:) /=  zfill)
+         z_seaice(:,:) = (zsca * z_seaice(:,:)) + zoff
+      ELSEWHERE
+         z_seaice(:,:) = fbrmdi
+      END WHERE
+      
+      ! Get QC flag
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
+            &       cpname, __LINE__ )
+      
+      ! Get seaice obs type
+      
+      i_type(:,:)=1
+      
+      ! Close the file
+      
+      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
+
+      ! Fill the obfbdata structure
+
+      ! Allocate obfbdata
+      
+      iobs = i_data * i_time
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
+      inpfile%cname(1) = 'SEAICE'
+
+      ! Fill the obfbdata structure from input data
+
+      inpfile%cdjuldref = "19500101000000"
+      iobs = 0
+      DO jtim = 1, i_time
+         DO jobs = 1, i_data
+            iobs = iobs + 1
+            ! Characters
+            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'seaice','  '
+            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
+            ! Real values
+            inpfile%plam(iobs)         = z_lam(jobs)
+            inpfile%pphi(iobs)         = z_phi(jobs)
+            inpfile%pob(1,iobs,1)      = z_seaice(jobs,jtim)
+            inpfile%ptim(iobs)         = &
+               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
+               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
+            inpfile%pdep(1,iobs)       = 0.0
+            ! Integers
+            inpfile%kindex(iobs)       = iobs
+            IF ( z_seaice(jobs,jtim) == fbrmdi ) THEN
+               inpfile%ioqc(iobs)      = 4
+               inpfile%ivqc(iobs,1)    = 4 
+               inpfile%ivlqc(1,iobs,1) = 4
+            ELSE 
+               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
+               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
+               inpfile%ivlqc(1,iobs,1) = 1
+            ENDIF
+            inpfile%ipqc(iobs)         = 0 
+            inpfile%ipqcf(:,iobs)      = 0
+            inpfile%itqc(iobs)         = 0
+            inpfile%itqcf(:,iobs)      = 0
+            inpfile%ivqcf(:,iobs,1)    = 0
+            inpfile%ioqcf(:,iobs)      = 0
+            inpfile%idqc(1,iobs)       = 0
+            inpfile%idqcf(1,1,iobs)    = 0
+            inpfile%ivlqcf(:,1,iobs,1) = 0
+         END DO
+      END DO
+
+   END SUBROUTINE read_seaice
+
+
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_io.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_io.h90	(revision 2202)
@@ -0,0 +1,372 @@
+   SUBROUTINE read_avisofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_avisofile **
+      !!
+      !! ** Purpose : Read from file the AVISO SLA observations.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! References : http://www.aviso.oceanobs.com
+      !!
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original based on old versions
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      !! * Local declarations
+      CHARACTER(LEN=14),PARAMETER :: cpname = 'read_avisofile'
+      INTEGER :: i_file_id     ! netcdf IDS
+      INTEGER :: i_tracks_id
+      INTEGER :: i_cycles_id
+      INTEGER :: i_data_id
+      INTEGER :: i_var_id
+      INTEGER, PARAMETER :: imaxdim = 2    ! Assumed maximum for no. dims. in file
+      INTEGER, DIMENSION(2) :: idims       ! Dimensions in file
+      INTEGER :: iilen         ! Length of netCDF attributes
+      INTEGER :: itype         ! Typeof netCDF attributes
+      REAL(fbdp) :: zsca       ! Scale factor
+      REAL(fbdp) :: zfill      ! Fill value
+      CHARACTER(len=3) ::  cmission      ! Mission global attribute
+      INTEGER :: itracks       ! Maximum number of passes in file
+      INTEGER :: icycles       ! Maximum number of cycles for each pass
+      INTEGER :: idata         ! Number of data per parameter in current file
+      REAL(fbdp) :: zdeltat    ! Time gap getween two measurements in seconds
+      INTEGER, DIMENSION(:), POINTER :: & 
+         & iptracks,     &  ! List of passes contained in current file
+         & ipnbpoints,   &  ! Number of points per pass
+         & ipdataindexes    ! Index of data in theoretical profile
+      INTEGER, DIMENSION(:,:), POINTER :: & 
+         & ipcycles         ! List of cycles per pass
+      REAL(fbdp), DIMENSION(:), POINTER :: &
+         & zphi,   &        ! Latitudes
+         & zlam             ! Longitudes
+      REAL(fbdp), DIMENSION(:,:), POINTER :: &
+         & zbegindates      ! Date of point with index 0
+      REAL(fbdp) :: zbeginmiss    ! Missing data for dates
+      REAL(fbsp), DIMENSION(:,:), POINTER :: &
+         & zsla             ! SLA data
+      REAL(fbdp), DIMENSION(:), POINTER :: &
+         & zjuld            ! Julian date
+      LOGICAL, DIMENSION(:), POINTER :: &
+         & llskip           ! Skip observation
+      CHARACTER(len=14) :: cdjuldref    ! Julian data reference
+      INTEGER :: imission   ! Mission number converted from Mission global 
+                            ! netCDF atttribute.
+      CHARACTER(len=255) :: ctmp
+      INTEGER :: iobs
+      INTEGER :: jl
+      INTEGER :: jm
+      INTEGER :: jj
+      INTEGER :: ji
+      INTEGER :: jk
+      INTEGER :: jobs
+      INTEGER :: jcycle
+
+      ! Open the file
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, i_file_id ), &
+         &         cpname, __LINE__ )
+
+      ! Get the netCDF dimensions
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'Tracks', i_tracks_id ),  &
+         &         cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_tracks_id, &
+         &                                 len = itracks ),  &
+         &         cpname, __LINE__ )
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'Cycles', i_cycles_id ),  &
+         &         cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_cycles_id, &
+         &                                 len = icycles ),  &
+         &      cpname, __LINE__ )
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'Data', i_data_id ),  &
+         &         cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_data_id, &
+         &                                 len = idata ),  &
+         &         cpname, __LINE__ )
+
+      ! Allocate memory for input data
+
+      ALLOCATE( &
+         & iptracks     ( itracks          ), &  
+         & ipnbpoints   ( itracks          ), &  
+         & ipcycles     ( icycles, itracks ), &
+         & zphi         ( idata            ), &   
+         & zlam         ( idata            ), &  
+         & zbegindates  ( icycles, itracks ), &
+         & ipdataindexes( idata            ), & 
+         & zsla         ( icycles, idata   ), &
+         & zjuld        ( idata*icycles    ), &
+         & llskip       ( idata*icycles    )  &
+         & )
+
+      ! Get time gap getween two measurements in seconds
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'DeltaT', i_var_id ), & 
+         &         cpname, __LINE__ )
+      CALL chkdim( i_file_id, i_var_id, 0, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zdeltat), &
+         &         cpname, __LINE__ )
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     'scale_factor',zsca), cpname,  __LINE__)
+      ENDIF
+      zdeltat = zsca * zdeltat
+         
+      ! Get List of passes contained in current file      
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'Tracks', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = itracks
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, iptracks), &
+         &         cpname, __LINE__ )
+      
+      ! Get Number of points per pass
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'NbPoints', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = itracks
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipnbpoints),&
+         &         cpname, __LINE__ )
+      
+      ! Get list of cycles per pass
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'Cycles', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = icycles
+      idims(2) = itracks
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipcycles),   &
+         &         cpname, __LINE__ )
+
+      ! Get longitudes
+
+      CALL chkerr( nf90_inq_varid( i_file_id, 'Longitudes', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = idata
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zlam),   &
+         &         cpname, __LINE__ )
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
+         &                         == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     'scale_factor',zsca), cpname,  __LINE__)
+      ENDIF
+      zlam(:) = zsca * zlam(:)
+      
+      ! Get latitudes
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'Latitudes', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = idata
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zphi),   &
+         &         cpname, __LINE__ )
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
+         &                       == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     'scale_factor',zsca), cpname,  __LINE__)
+      ENDIF
+      zphi(:) = zsca * zphi(:)
+      
+      ! Get date of point with index 0
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'BeginDates', i_var_id ), & 
+         &        cpname, __LINE__ )
+      idims(1) = icycles
+      idims(2) = itracks
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zbegindates), &
+         &         cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, &
+         &                                 'units', len = iilen,  &
+         &                                  xtype = itype), cpname, __LINE__ )
+      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 255 )) THEN
+         CALL fatal_error('Error decoding BeginDates unit', __LINE__ )
+      ENDIF
+      CALL chkerr( nf90_get_att( i_file_id, i_var_id, 'units', &
+         &                       ctmp ), cpname, __LINE__ )
+      jl=1
+      DO jm = 1, LEN(TRIM(ctmp))
+         IF ((ctmp(jm:jm)>='0').AND.(ctmp(jm:jm)<='9')) THEN
+            cdjuldref(jl:jl) = ctmp(jm:jm)
+            jl=jl+1
+         ENDIF
+         IF (jl>14) EXIT
+      END DO
+      CALL chkerr( nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue', &
+         &                                  xtype = itype), cpname, __LINE__ )
+      IF ( itype /= NF90_DOUBLE ) THEN
+         CALL fatal_error('Error decoding BeginDates missing data', __LINE__ )
+      ENDIF
+      CALL chkerr( nf90_get_att( i_file_id, i_var_id, '_FillValue', &
+         &                       zbeginmiss ), cpname, __LINE__ )
+
+      ! Get indices of data in theoretical profile
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'DataIndexes', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = idata
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, ipdataindexes),   &
+         &       cpname, __LINE__ )
+      
+      ! Get SLA data
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'SLA', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = icycles
+      idims(2) = idata
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zsla),   &
+         &         cpname, __LINE__ )
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, 'scale_factor') &
+         &                        == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                       'scale_factor',zsca), cpname, __LINE__ )
+      ENDIF
+      zfill = 0.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, '_FillValue') &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     '_FillValue',zfill), cpname,  __LINE__ )
+      ENDIF
+      WHERE(zsla(:,:) /=  zfill)
+         zsla(:,:) = zsca * zsla(:,:)
+      ELSEWHERE
+         zsla(:,:) = fbrmdi
+      END WHERE
+      
+      ! Get the global Mission netCDF attribute
+      
+      cmission='   '
+      CALL chkerr( nf90_inquire_attribute( i_file_id, nf90_global, &
+         &                                 'Mission', len = iilen,  &
+         &                                 xtype = itype), cpname, __LINE__ )
+      IF (( itype /= NF90_CHAR ) .OR. ( iilen > 3 )) THEN
+         CALL fatal_error('Error decoding Mission global attribute', __LINE__ )
+      ENDIF
+      CALL chkerr( nf90_get_att( i_file_id, nf90_global, 'Mission', &
+         &                       cmission ), cpname, __LINE__ )
+      
+      ! Convert it to an integer
+      imission = 0
+      DO jm = 1, imaxmissions
+         IF (cmission==cmissions(jm)) THEN
+            imission = jm
+            EXIT
+         ENDIF
+      END DO
+      
+      ! Close the file
+      
+      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
+
+      ! Compute Julian dates for all observations
+      
+      jm = 0
+      jl = 0
+      DO jj = 1, itracks
+         DO ji = 1, ipnbpoints(jj)
+            jl = jl + 1
+            DO jk = 1, icycles
+               jm = jm + 1
+               IF (zbegindates(jk,jj)==zbeginmiss) THEN
+                  llskip(jm) = .TRUE.
+                  zjuld(jm)  = fbrmdi
+               ELSE
+                  llskip(jm) = .FALSE.
+                  zjuld(jm)  = zbegindates(jk,jj) + &
+                     &         (ipdataindexes(jl) * zdeltat / 86400._wp )
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! Get rid of missing data
+
+      jm = 0
+      DO jobs = 1, idata
+         DO jcycle = 1, icycles
+            jm = jm + 1
+            IF (zsla(jcycle,jobs) == fbrmdi) llskip(jm) = .TRUE.
+         END DO
+      END DO
+      
+      ! Allocate obfbdata
+
+      iobs = COUNT( .NOT.llskip(:) )
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
+      inpfile%cname(1) = 'SLA'
+
+      ! Fill the obfbdata structure from input data
+
+      inpfile%cdjuldref = cdjuldref
+      iobs = 0
+      jm = 0
+      DO jobs = 1, idata
+         DO jcycle = 1, icycles
+            jm = jm + 1
+            IF (llskip(jm)) CYCLE
+            iobs = iobs + 1
+            ! Characters
+            WRITE(inpfile%cdwmo(iobs),'(A3,A5)') cmissions(imission), '     '
+            WRITE(inpfile%cdtyp(iobs),'(I4)') imission
+            ! Real values
+            inpfile%plam(iobs)         = zlam(jobs)
+            inpfile%pphi(iobs)         = zphi(jobs)
+            inpfile%pob(1,iobs,1)      = zsla(jcycle,jobs)
+            inpfile%ptim(iobs)         = zjuld(jm)
+            inpfile%pdep(1,iobs)       = 0.0
+            ! Integers
+            inpfile%kindex(iobs)       = iobs
+            inpfile%ioqc(iobs)      = 1
+            inpfile%ivqc(iobs,1)    = 1
+            inpfile%ivlqc(1,iobs,1) = 1
+            inpfile%ipqc(iobs)         = 0 
+            inpfile%ipqcf(:,iobs)      = 0
+            inpfile%itqc(iobs)         = 0
+            inpfile%itqcf(:,iobs)      = 0
+            inpfile%ivqcf(:,iobs,1)    = 0
+            inpfile%ioqcf(:,iobs)      = 0
+            inpfile%idqc(1,iobs)       = 0
+            inpfile%idqcf(1,1,iobs)    = 0
+            inpfile%ivlqcf(:,1,iobs,1) = 0
+         END DO
+      END DO
+
+
+      ! Deallocate memory for input data
+
+      DEALLOCATE( &
+         & iptracks,      &
+         & ipnbpoints,    &
+         & ipcycles,      &
+         & zphi,          &
+         & zlam,          &  
+         & zbegindates,   &
+         & ipdataindexes, &
+         & zsla,          &
+         & zjuld,         &
+         & llskip         &
+         & )
+
+   END SUBROUTINE read_avisofile
+
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_types.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_types.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obssla_types.h90	(revision 2202)
@@ -0,0 +1,3 @@
+   INTEGER, PARAMETER :: imaxmissions=8
+   CHARACTER(len=3) :: cmissions(0:imaxmissions) = &
+      & (/ 'XXX', 'E1 ', 'E2 ', 'TP ', 'TPM', 'G2 ', 'J1 ', 'EN ', 'J2 ' /)
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obssst_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obssst_io.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obssst_io.h90	(revision 2202)
@@ -0,0 +1,280 @@
+   SUBROUTINE read_ghrsst( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_ghrsst **
+      !!
+      !! ** Purpose : Read from file the GHRSST observations.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! References : 
+      !!
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original based on old versions
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      !! * Local declarations
+      CHARACTER(LEN=12),PARAMETER :: cpname = 'read_ghrsst'
+      INTEGER :: i_file_id        ! netcdf IDS
+      INTEGER :: i_time_id
+      INTEGER :: i_ni_id
+      INTEGER :: i_data_id
+      INTEGER :: i_var_id
+      INTEGER :: i_data           ! Number of data per parameter in current file
+      INTEGER :: i_time           ! Number of reference times in file
+      INTEGER, DIMENSION(:), POINTER :: &
+         & i_reftime        ! Reference time in file in seconds since 1/1/1981.
+      INTEGER, DIMENSION(:,:), POINTER :: &
+         & i_dtime, &       ! Offset in seconds since reference time
+         & i_qc,    &       ! Quality control flag.
+         & i_type           ! Type of SST measurement.            
+      REAL(wp), DIMENSION(:), POINTER :: &
+         & z_phi,   &       ! Latitudes
+         & z_lam            ! Longitudes
+      REAL(wp), DIMENSION(:,:), POINTER :: &
+         & z_sst            ! SST data     
+      INTEGER, PARAMETER :: imaxdim = 2      ! Assumed maximum for no. dims. in file
+      INTEGER, DIMENSION(2) :: idims         ! Dimensions in file
+      INTEGER :: iilen            ! Length of netCDF attributes
+      INTEGER :: itype            ! Typeof netCDF attributes
+      REAL(KIND=wp) :: zsca           ! Scale factor
+      REAL(KIND=wp) :: zoff           ! Offset for data in netcdf file
+      REAL(KIND=wp) :: z_offset       ! Offset for time conversion
+      REAL(KIND=wp) :: zfill          ! Fill value in netcdf file
+      CHARACTER (len=33) :: creftime  ! Reference time of file
+      INTEGER :: i_refyear            ! Integer version of reference time
+      INTEGER :: i_refmonth
+      INTEGER :: i_refday
+      INTEGER :: i_refhour
+      INTEGER :: i_refmin
+      INTEGER :: i_refsec
+      INTEGER :: ichunk
+      INTEGER :: jtim
+      INTEGER :: jobs
+      INTEGER :: iobs
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
+         &                i_file_id, chunksize=ichunk), cpname, __LINE__ )
+      
+      ! Get the netCDF dimensions
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'time', i_time_id ),  &
+         &       cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_time_id, &
+         &                              len = i_time ),  &
+         &      cpname, __LINE__ )
+      
+      CALL chkerr( nf90_inq_dimid( i_file_id, 'ni', i_ni_id ),  &
+         &       cpname, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_ni_id, &
+         &                              len = i_data ),  &
+         &      cpname, __LINE__ )
+      
+      
+      ! Allocate NetCDF variables
+      
+      ALLOCATE( &
+         & i_reftime    ( i_time                 ), &
+         & i_dtime      ( i_data,i_time  ), &      
+         & i_qc         ( i_data,i_time  ), & 
+         & i_type       ( i_data,i_time  ), &     
+         & z_phi        ( i_data                 ), &   
+         & z_lam        ( i_data                 ), &  
+         & z_sst        ( i_data,i_time  )  &
+         & )
+      
+      ! Get reference time of file which is in seconds since 1981/1/1 00:00. 
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'time', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_time
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_reftime),&
+         &       cpname, __LINE__ )
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "units") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "units",creftime), cpname,  __LINE__ )
+      ELSE
+         creftime = "seconds since 1981-01-01 00:00:00"
+      ENDIF
+      READ(creftime(15:18),*)i_refyear
+      READ(creftime(20:21),*)i_refmonth
+      READ(creftime(23:24),*)i_refday
+      READ(creftime(26:27),*)i_refhour
+      READ(creftime(29:30),*)i_refmin
+      READ(creftime(32:33),*)i_refsec
+      !Work out offset in days between reference time and 1/1/1950.
+      CALL greg2jul( i_refsec, i_refmin, i_refhour, i_refday, &
+         &           i_refmonth, i_refyear, z_offset)
+      
+      ! Get list of times for each ob in seconds relative to reference time
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'sst_dtime', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_dtime),&
+         &       cpname, __LINE__ )
+      zsca = 1.0      
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "scale_factor",zsca), cpname,  __LINE__ )
+      ENDIF
+      zoff = 0.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "add_offset") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "add_offset",zoff), cpname,  __LINE__ )
+      ENDIF
+      i_dtime(:,:) = NINT((zsca * FLOAT(i_dtime(:,:))) &
+         &                 + zoff)
+      
+      ! Get longitudes
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'lon', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_lam),   &
+         &         cpname, __LINE__ )
+      
+      ! Get latitudes
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'lat', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      CALL chkdim( i_file_id, i_var_id, 1, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_phi),   &
+         &         cpname, __LINE__ )
+      
+      ! Get SST data
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'sea_surface_temperature', &
+         &                         i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, z_sst), &
+         &       cpname, __LINE__ )
+      zoff = 0.
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                      == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                     "scale_factor",zsca), cpname, __LINE__ )
+      ENDIF
+      zsca = 1.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "scale_factor") &
+         &                       == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                       "scale_factor",zsca), cpname, __LINE__ )
+      ENDIF
+      zfill = 0.0
+      IF (nf90_inquire_attribute( i_file_id, i_var_id, "_FillValue") &
+         &                       == nf90_noerr) THEN
+         CALL chkerr( nf90_get_att( i_file_id, i_var_id, &
+            &                       "_FillValue",zfill), cpname, __LINE__ )
+      ENDIF
+      WHERE(z_sst(:,:) /=  zfill)
+         z_sst(:,:) = (zsca * z_sst(:,:)) + zoff
+      ELSEWHERE
+         z_sst(:,:) = fbrmdi
+      END WHERE
+      
+      ! Get QC flag
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'confidence_flag', i_var_id ), & 
+         &       cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_qc),   &
+            &       cpname, __LINE__ )
+      
+      ! Get SST obs type
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, 'data_source', i_var_id ), & 
+         &         cpname, __LINE__ )
+      idims(1) = i_data
+      idims(2) = i_time
+      CALL chkdim( i_file_id, i_var_id, 2, idims, cpname, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, i_type),   &
+         &       cpname, __LINE__ )
+      
+      ! Close the file
+      
+      CALL chkerr( nf90_close( i_file_id ), cpname, __LINE__ )
+
+      ! Fill the obfbdata structure
+
+      ! Allocate obfbdata
+      
+      iobs = i_data * i_time
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 1, iobs, 1, 0, 0, ldgrid )
+      inpfile%cname(1) = 'SST'
+
+      ! Fill the obfbdata structure from input data
+
+      inpfile%cdjuldref = "19500101000000"
+      iobs = 0
+      DO jtim = 1, i_time
+         DO jobs = 1, i_data
+            iobs = iobs + 1
+            ! Characters
+            WRITE(inpfile%cdwmo(iobs),'(A6,A2)') 'ghrsst','  '
+            WRITE(inpfile%cdtyp(iobs),'(I4)') i_type(jobs,jtim)
+            ! Real values
+            inpfile%plam(iobs)         = z_lam(jobs)
+            inpfile%pphi(iobs)         = z_phi(jobs)
+            inpfile%pob(1,iobs,1)      = z_sst(jobs,jtim)
+            inpfile%ptim(iobs)         = &
+               & REAL(i_reftime(jtim))/(60.*60.*24.) + &
+               & z_offset + REAL(i_dtime(jobs,jtim))/(60.*60.*24.)
+            inpfile%pdep(1,iobs)       = 0.0
+            ! Integers
+            inpfile%kindex(iobs)       = iobs
+            IF ( z_sst(jobs,jtim) == fbrmdi ) THEN
+               inpfile%ioqc(iobs)      = 4
+               inpfile%ivqc(iobs,1)    = 4 
+               inpfile%ivlqc(1,iobs,1) = 4
+            ELSE 
+               inpfile%ioqc(iobs)      = i_qc(jobs,jtim)
+               inpfile%ivqc(iobs,1)    = i_qc(jobs,jtim)
+               inpfile%ivlqc(1,iobs,1) = 1
+            ENDIF
+            inpfile%ipqc(iobs)         = 0 
+            inpfile%ipqcf(:,iobs)      = 0
+            inpfile%itqc(iobs)         = 0
+            inpfile%itqcf(:,iobs)      = 0
+            inpfile%ivqcf(:,iobs,1)    = 0
+            inpfile%ioqcf(:,iobs)      = 0
+            inpfile%idqc(1,iobs)       = 0
+            inpfile%idqcf(1,1,iobs)    = 0
+            inpfile%ivlqcf(:,1,iobs,1) = 0
+         END DO
+      END DO
+
+      DEALLOCATE( &
+         & i_reftime, &
+         & i_dtime,   &
+         & i_qc,      &
+         & i_type,    &
+         & z_phi,     &
+         & z_lam,     &
+         & z_sst      &
+         & )
+
+   END SUBROUTINE read_ghrsst
+
+
Index: branches/devukmo2010/NEMO/OPA_SRC/OBS/obsvel_io.h90
===================================================================
--- branches/devukmo2010/NEMO/OPA_SRC/OBS/obsvel_io.h90	(revision 2202)
+++ branches/devukmo2010/NEMO/OPA_SRC/OBS/obsvel_io.h90	(revision 2202)
@@ -0,0 +1,354 @@
+   SUBROUTINE read_taondbc( cdfilename, inpfile, kunit, ldwp, ldgrid )
+      !!---------------------------------------------------------------------
+      !!
+      !!                     ** ROUTINE read_enactfile **
+      !!
+      !! ** Purpose : Read from file the TAO data fro NDBC.
+      !!
+      !! ** Method  : The data file is a NetCDF file. 
+      !!
+      !! ** Action  :
+      !!
+      !! ** Reference : http://tao.noaa.gov/tao/data_deliv/deliv_ndbc.shtml
+      !! History : 
+      !!          ! 09-01 (K. Mogensen) Original version.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=*) :: cdfilename ! Input filename
+      TYPE(obfbdata)   :: inpfile    ! Output obfbdata structure
+      INTEGER          :: kunit      ! Unit for output
+      LOGICAL          :: ldwp       ! Print info
+      LOGICAL          :: ldgrid     ! Save grid info in data structure
+      !! * Local declarations
+      INTEGER :: iobs                ! Number of observations
+      INTEGER :: ilev                ! Number of levels
+      INTEGER :: ilat                ! Number of latitudes
+      INTEGER :: ilon                ! Number of longtudes
+      INTEGER :: itim                ! Number of obs. times
+      INTEGER :: i_file_id
+      INTEGER :: i_dimid_id
+      INTEGER :: i_phi_id
+      INTEGER :: i_lam_id
+      INTEGER :: i_depth_id
+      INTEGER :: i_var_id
+      INTEGER :: i_time_id
+      INTEGER :: i_time2_id
+      INTEGER :: i_qc_var_id
+      CHARACTER(LEN=40) :: cl_fld_lam
+      CHARACTER(LEN=40) :: cl_fld_phi
+      CHARACTER(LEN=40) :: cl_fld_depth
+      CHARACTER(LEN=40) :: cl_fld_var_u
+      CHARACTER(LEN=40) :: cl_fld_var_v
+      CHARACTER(LEN=40) :: cl_fld_var_qc_uv1
+      CHARACTER(LEN=40) :: cl_fld_var_qc_uv2
+      CHARACTER(LEN=40) :: cl_fld_time
+      CHARACTER(LEN=40) :: cl_fld_time2
+      INTEGER :: ja
+      INTEGER :: jo
+      INTEGER :: jk
+      INTEGER :: jt
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: &
+         & zv,     &
+         & zu,     &
+         & zuv1qc, &
+         & zuv2qc
+      REAL(wp), ALLOCATABLE, DIMENSION(:) :: &
+         & zdep, &
+         & zlat, &
+         & zlon, &
+         & zjuld
+      REAL(wp) :: zl
+      INTEGER, ALLOCATABLE, DIMENSION(:) :: &
+         & itime, &
+         & itime2
+      CHARACTER(LEN=50) :: cdjulref
+      CHARACTER(LEN=12), PARAMETER :: cl_name = 'read_taondbc'
+      CHARACTER(len=1) :: cns, cew
+
+      !-----------------------------------------------------------------------
+      ! Initialization
+      !-----------------------------------------------------------------------
+      cl_fld_lam                 = 'lon'
+      cl_fld_phi                 = 'lat'
+      cl_fld_depth               = 'depth'
+      cl_fld_time                = 'time'
+      cl_fld_time2               = 'time2'
+
+      !-----------------------------------------------------------------------
+      ! Open file
+      !-----------------------------------------------------------------------
+
+      CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
+            &      i_file_id ),           cl_name, __LINE__ )
+
+      !-----------------------------------------------------------------------
+      ! Read the heading of the file
+      !-----------------------------------------------------------------------
+      IF(ldwp) WRITE(kunit,*)
+      IF(ldwp) WRITE(kunit,*) ' read_taondbc :' 
+      IF(ldwp) WRITE(kunit,*) ' ~~~~~~~~~~~~'
+      
+      !---------------------------------------------------------------------
+      ! Read the number of observations and of levels to allocate array
+      !---------------------------------------------------------------------
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'time', i_dimid_id ),        &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = itim ),    &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'depth', i_dimid_id ),       &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilev ),    &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lat', i_dimid_id ),           &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilat ),    &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inq_dimid        ( i_file_id, 'lon', i_dimid_id ),         &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_inquire_dimension( i_file_id, i_dimid_id, len = ilon ),    &
+         &         cl_name, __LINE__ ) 
+
+      iobs = itim * ilat * ilon
+      IF(ldwp)WRITE(kunit,*) '         No. of data records = ', iobs
+      IF(ldwp)WRITE(kunit,*) '         No. of levels       = ', ilev
+      IF(ldwp)WRITE(kunit,*) 
+
+      !---------------------------------------------------------------------
+      ! Allocate arrays
+      !---------------------------------------------------------------------
+
+      CALL init_obfbdata( inpfile )
+      CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 0, ldgrid )
+      inpfile%cname(1) = 'UVEL'
+      inpfile%cname(2) = 'VVEL'
+      inpfile%coblong(1) = 'Zonal current'
+      inpfile%coblong(2) = 'Meridional current'
+      inpfile%cobunit(1) = 'Meters per second'
+      inpfile%cobunit(2) = 'Meters per second'
+
+      ALLOCATE( &
+         & zu(ilon,ilat,ilev,itim),     &
+         & zv(ilon,ilat,ilev,itim),     &
+         & zdep(ilev),                  &
+         & zuv1qc(ilon,ilat,ilev,itim), &
+         & zuv2qc(ilon,ilat,ilev,itim), &
+         & itime(itim),                 &
+         & itime2(itim),                &
+         & zlat(ilat),                  &
+         & zlon(ilon),                  &
+         & zjuld(itim)                  &
+         & )
+
+      !---------------------------------------------------------------------
+      ! Read the time/position variables 
+      !---------------------------------------------------------------------
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time, i_time_id ),                               &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_time_id, itime ),                                     &
+         &         cl_name, __LINE__ )
+
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_time2, i_time2_id ),                             &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_time2_id, itime2 ),                                   &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ),                             &
+            &         cl_name, __LINE__ )         
+      CALL chkerr( nf90_get_var  ( i_file_id, i_depth_id, zdep ),                                     &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_phi_id, zlat ),                                       &
+         &         cl_name, __LINE__ )
+      
+      CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ),                                 &
+         &         cl_name, __LINE__ )
+      CALL chkerr( nf90_get_var  ( i_file_id, i_lam_id, zlon ),                                       &
+         &         cl_name, __LINE__ )
+      
+      !---------------------------------------------------------------------
+      ! Read the variables
+      !---------------------------------------------------------------------
+
+      ! ADCP format assumed
+      cl_fld_var_u = 'u_1205'
+      IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
+         ! Try again with current meter format
+         cl_fld_var_u = 'U_320'
+         IF ( nf90_inq_varid( i_file_id, cl_fld_var_u, i_var_id ) /= nf90_noerr ) THEN
+            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
+         ENDIF
+      ENDIF
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zu ),                                         &
+         &         cl_name, __LINE__ )
+      
+      ! ADCP format assumed
+      cl_fld_var_v = 'v_1206'
+      IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
+         ! Try again with current meter format
+         cl_fld_var_v = 'V_321'
+         IF ( nf90_inq_varid( i_file_id, cl_fld_var_v, i_var_id ) /= nf90_noerr ) THEN
+            CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
+         ENDIF
+      ENDIF
+      CALL chkerr( nf90_get_var  ( i_file_id, i_var_id, zv ),                                         &
+         &         cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Read the QC attributes
+      !---------------------------------------------------------------------
+      
+      ! ADCP format assumed
+      cl_fld_var_qc_uv1 = 'QU_5205'
+      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
+         ! Try again with current meter format
+         cl_fld_var_qc_uv1 = 'QCS_5300'
+         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
+            ! Try again with high freq. current meter format
+            cl_fld_var_qc_uv1 = 'QCU_5320'
+            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv1, i_qc_var_id ) /= nf90_noerr ) THEN
+               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
+            ENDIF
+         ENDIF
+      ENDIF
+      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv1qc),                                   &
+         &         cl_name, __LINE__ )
+
+      ! ADCP format assumed
+      cl_fld_var_qc_uv2 = 'QV_5206'
+      IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
+         ! Try again with current meter format
+         cl_fld_var_qc_uv2 = 'QCD_5310'
+         IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
+            ! Try again with high freq. current meter format
+            cl_fld_var_qc_uv2 = 'QCV_5321'
+            IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_uv2, i_qc_var_id ) /= nf90_noerr ) THEN
+               CALL fatal_error( 'Unknown format in read_taondbc', __LINE__ )
+            ENDIF
+         ENDIF
+      ENDIF
+      CALL chkerr( nf90_get_var  ( i_file_id, i_qc_var_id, zuv2qc),                                   &
+         &         cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Close file
+      !---------------------------------------------------------------------
+
+      CALL chkerr( nf90_close( i_file_id ),           cl_name, __LINE__ )
+
+      !---------------------------------------------------------------------
+      ! Convert to to 19500101 based Julian date
+      !---------------------------------------------------------------------
+      DO jt = 1, itim
+         zjuld(jt) = REAL(itime(jt),wp) + REAL(itime2(jt),wp)/86400000.0_wp &
+            &           - 2433283.0_wp
+      END DO
+      inpfile%cdjuldref = '19500101000000'
+
+      !---------------------------------------------------------------------
+      ! Copy info to obfbdata structure
+      !---------------------------------------------------------------------
+
+      iobs = 0
+      DO jt = 1, itim
+         DO ja = 1, ilat
+            DO jo = 1, ilon
+               iobs = iobs + 1
+               zl = zlon(jo)
+               IF ( zl > 180.0_wp ) zl = zl - 360.0_wp
+               IF ( zl < 0 ) THEN
+                  cew = 'w'
+               ELSE
+                  cew = 'e'
+               ENDIF
+               IF ( zlat(jo) < 0 ) THEN
+                  cns = 's'
+               ELSE
+                  cns = 'n'
+               ENDIF
+               WRITE(inpfile%cdwmo(iobs),'(A1,I2.2,A1,I3.3)') &
+                  & cns, ABS(NINT(zlat(ja))), cew, ABS(NINT(zl))
+               DO jk = 1, ilev
+                  inpfile%pob(jk,iobs,1)     = zu(jo,ja,jk,jt)
+                  inpfile%pob(jk,iobs,2)     = zv(jo,ja,jk,jt)
+                  inpfile%pdep(jk,iobs)      = zdep(jk)
+                  inpfile%ivlqc(jk,iobs,1:2) = INT( MAX( zuv1qc(jo,ja,jk,jt), zuv2qc(jo,ja,jk,jt) ) )
+               END DO
+               inpfile%plam(iobs) = zlon(jo)
+               inpfile%pphi(iobs) = zlat(ja)
+               inpfile%ptim(iobs) = zjuld(jt)
+            END DO
+         END DO
+      END DO
+
+      ! No position, time, depth and variable QC in input files
+      DO jo = 1, iobs
+         inpfile%ipqc(jo) = 1
+         inpfile%itqc(jo) = 1
+         inpfile%ivqc(jo,1:2) = 1
+         DO jk = 1, ilev
+            inpfile%idqc(jk,jo) = 1
+         END DO
+      END DO
+
+      !---------------------------------------------------------------------
+      ! Set the platform information
+      !---------------------------------------------------------------------
+      inpfile%cdtyp(:)=' 820'
+
+      !---------------------------------------------------------------------
+      ! Set QC flags for missing data and rescale to m/s
+      !---------------------------------------------------------------------
+
+      DO jo = 1, iobs
+         DO jk = 1, ilev
+            IF ( ( ABS(inpfile%pob(jk,jo,1)) > 10000.0_wp ) .OR. &
+               & ( ABS(inpfile%pob(jk,jo,2)) > 10000.0_wp ) ) THEN
+               inpfile%ivlqc(jk,jo,:) = 4
+               inpfile%pob(jk,jo,1) = fbrmdi
+               inpfile%pob(jk,jo,2) = fbrmdi
+            ELSE
+               inpfile%pob(jk,jo,1) = 0.01 * inpfile%pob(jk,jo,1)
+               inpfile%pob(jk,jo,2) = 0.01 * inpfile%pob(jk,jo,2)
+            ENDIF
+         END DO
+      END DO
+
+      !---------------------------------------------------------------------
+      ! Set file indexes
+      !---------------------------------------------------------------------
+
+      DO jo = 1, inpfile%nobs
+         inpfile%kindex(jo) = jo
+      END DO
+
+      !---------------------------------------------------------------------
+      ! Initialize flags since they are not in the TAO input files
+      !---------------------------------------------------------------------
+
+      inpfile%ioqcf(:,:)      = 0
+      inpfile%ipqcf(:,:)      = 0
+      inpfile%itqcf(:,:)      = 0
+      inpfile%idqcf(:,:,:)    = 0
+      inpfile%ivqcf(:,:,:)    = 0
+      inpfile%ivlqcf(:,:,:,:) = 0
+
+      !---------------------------------------------------------------------
+      ! Deallocate data
+      !---------------------------------------------------------------------
+      DEALLOCATE( &
+         & zu,     &
+         & zv,     &
+         & zdep,   &
+         & zuv1qc, &
+         & zuv2qc, &
+         & itime,  &
+         & itime2, &
+         & zlat,   &
+         & zlon,   &
+         & zjuld   &
+         & )
+
+   END SUBROUTINE read_taondbc
