#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      : geopotential_from_geometric_height
#                                         
# Category      : VERTICAL
#
# OneLineDesc   : Computes the geopotential from geometric height
#
# Description   : Computes the geopotential from geometric height
#
# Parameters    : h - geometric height (m)
#		 		 
# Return Value  : geopotential (J/kg)
#
# Dependencies  : none
#
#==============================================================================

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

end geopotential_from_geometric_height
