Index: src/calcpar.f90
===================================================================
--- src/calcpar.f90	(revision e200b7adb07d4dfa7bf42f7cb43e0c85b4dbf894)
+++ src/calcpar.f90	(revision 6ecb30a41fb8a07e153abadc712699a09c15f90c)
@@ -20,5 +20,5 @@
 !**********************************************************************
 
-subroutine calcpar(n,uuh,vvh,pvh)
+subroutine calcpar(n,uuh,vvh,pvh,metdata_format)
   !                   i  i   i   o
   !*****************************************************************************
@@ -37,11 +37,23 @@
   !     new variables in call to richardson                                    *
   !                                                                            *
-  !*****************************************************************************
-  !  Changes, Bernd C. Krueger, Feb. 2001:
-  !   Variables tth and qvh (on eta coordinates) in common block
+  !   CHANGE 17/11/2005 Caroline Forster NCEP GFS version                      *
+  !                                                                            *
+  !   Changes, Bernd C. Krueger, Feb. 2001:                                    *
+  !    Variables tth and qvh (on eta coordinates) in common block              *
+  !                                                                            *
+  !   Unified ECMWF and GFS builds                                             *
+  !   Marian Harustak, 12.5.2017                                               *
+  !     - Merged calcpar and calcpar_gfs into one routine using if-then        *
+  !       for meteo-type dependent code                                        *
+  !*****************************************************************************
+
   !*****************************************************************************
   !                                                                            *
   ! Variables:                                                                 *
   ! n                  temporal index for meteorological fields (1 to 3)       *
+  ! uuh                                                                        *
+  ! vvh                                                                        *
+  ! pvh                                                                        *
+  ! metdata_format     format of metdata (ecmwf/gfs)                           * 
   !                                                                            *
   ! Constants:                                                                 *
@@ -56,11 +68,13 @@
   use par_mod
   use com_mod
+  use class_gribfile
 
   implicit none
 
-  integer :: n,ix,jy,i,kz,lz,kzmin
+  integer :: metdata_format
+  integer :: n,ix,jy,i,kz,lz,kzmin,llev,loop_start
   real :: ttlev(nuvzmax),qvlev(nuvzmax),obukhov,scalev,ol,hmixplus
   real :: ulev(nuvzmax),vlev(nuvzmax),ew,rh,vd(maxspec),subsceff,ylat
-  real :: altmin,tvold,pold,zold,pint,tv,zlev(nuvzmax)
+  real :: altmin,tvold,pold,zold,pint,tv,zlev(nuvzmax),hmixdummy
   real :: uuh(0:nxmax-1,0:nymax-1,nuvzmax)
   real :: vvh(0:nxmax-1,0:nymax-1,nuvzmax)
@@ -111,6 +125,23 @@
   !***********************************************
 
+      if (metdata_format.eq.GRIBFILE_CENTRE_NCEP) then
+        ! NCEP version: find first level above ground
+        llev = 0
+        do i=1,nuvz
+          if (ps(ix,jy,1,n).lt.akz(i)) llev=i
+        end do
+        llev = llev+1
+        if (llev.gt.nuvz) llev = nuvz-1
+        ! NCEP version
+
+        ! calculate inverse Obukhov length scale with tth(llev)
       ol=obukhov(ps(ix,jy,1,n),tt2(ix,jy,1,n),td2(ix,jy,1,n), &
-           tth(ix,jy,2,n),ustar(ix,jy,1,n),sshf(ix,jy,1,n),akm,bkm)
+            tth(ix,jy,llev,n),ustar(ix,jy,1,n),sshf(ix,jy,1,n),akm,bkm,akz(llev),metdata_format)
+      else
+        llev=0
+        ol=obukhov(ps(ix,jy,1,n),tt2(ix,jy,1,n),td2(ix,jy,1,n), &
+            tth(ix,jy,2,n),ustar(ix,jy,1,n),sshf(ix,jy,1,n),akm,bkm,akz(llev),metdata_format)
+      end if
+
       if (ol.ne.0.) then
         oli(ix,jy,1,n)=1./ol
@@ -130,7 +161,14 @@
       end do
 
+      if (metdata_format.eq.GRIBFILE_CENTRE_NCEP) then
+        ! NCEP version hmix has been read in in readwind.f, is therefore not calculated here
       call richardson(ps(ix,jy,1,n),ustar(ix,jy,1,n),ttlev,qvlev, &
            ulev,vlev,nuvz,akz,bkz,sshf(ix,jy,1,n),tt2(ix,jy,1,n), &
-           td2(ix,jy,1,n),hmix(ix,jy,1,n),wstar(ix,jy,1,n),hmixplus)
+             td2(ix,jy,1,n),hmixdummy,wstar(ix,jy,1,n),hmixplus,metdata_format)
+      else
+        call richardson(ps(ix,jy,1,n),ustar(ix,jy,1,n),ttlev,qvlev, &
+             ulev,vlev,nuvz,akz,bkz,sshf(ix,jy,1,n),tt2(ix,jy,1,n), &
+             td2(ix,jy,1,n),hmix(ix,jy,1,n),wstar(ix,jy,1,n),hmixplus,metdata_format)
+      end if
 
       if(lsubgrid.eq.1) then
@@ -173,6 +211,6 @@
   !******************************************************
 
-  ! 1) Calculate altitudes of ECMWF model levels
-  !*********************************************
+  ! 1) Calculate altitudes of model levels
+  !***************************************
 
       tvold=tt2(ix,jy,1,n)*(1.+0.378*ew(td2(ix,jy,1,n))/ &
@@ -180,5 +218,10 @@
       pold=ps(ix,jy,1,n)
       zold=0.
-      do kz=2,nuvz
+      if (metdata_format.eq.GRIBFILE_CENTRE_ECMWF) then
+        loop_start=2
+      else
+        loop_start=llev
+      end if
+      do kz=loop_start,nuvz
         pint=akz(kz)+bkz(kz)*ps(ix,jy,1,n)  ! pressure on model layers
         tv=tth(ix,jy,kz,n)*(1.+0.608*qvh(ix,jy,kz,n))
@@ -199,5 +242,11 @@
   !************************************************************************
 
-      do kz=1,nuvz
+      if (metdata_format.eq.GRIBFILE_CENTRE_ECMWF) then
+        loop_start=1
+      else
+        loop_start=llev
+      end if
+
+      do kz=loop_start,nuvz
         if (zlev(kz).ge.altmin) then
           kzmin=kz
