#Metview Macro

#  **************************** LICENSE START ***********************************
# 
#  Copyright 2024 ECMWF. This software is distributed under the terms
#  of the Apache License version 2.0. In applying this license, ECMWF does not
#  waive the privileges and immunities granted to it by virtue of its status as
#  an Intergovernmental Organization or submit itself to any jurisdiction.
# 
#  ***************************** LICENSE END ************************************
# 

#=============================================================================
# Function      : geometric_height_from_geopotential
#                                         
# Category      : VERTICAL
#
# OneLineDesc   : Computes the geometric height from geopotential
#
# Description   : Computes the geometric height from geopotential
#
# Parameters    : z - geopotential (J/kg)
#		 		 
# Return Value  : geometric height (m)
#
# Dependencies  : none
#
#==============================================================================

function geometric_height_from_geopotential(z)
    
    _REarth=6378388 #m, radius of Earth
    _g = 9.80665 # m2/s, gravitational acceleration on the surface of Earth
    
    z = z/_g
    h = _REarth*z/(_REarth - z)
    if type(h) = "fieldset" then
        h =  grib_set_long(h, ["paramId", 3008])
    end if
    return h 

end geometric_height_from_geopotential	
