def read_z(infile, ncvar):
    """Read the z coordinate of a variable in GOTM output assuming fixed layer

    :infile: (netCDF4 Dataset) input netCDF file
    :ncvar: (netCDF variable) variable
    :returns: z coordinate (negative below the surface)

    """
    # choose veritcal coordinate
    varlist = infile.variables.keys()
    # GOTM output (fixed z)
    try:
        coord = ncvar.coordinates
    except AttributeError:
        coord = 'v4'
    if 'zi' in coord:
        z = infile.variables['zi'][0,:,0,0]
    elif 'z' in coord:
        z = infile.variables['z'][0,:,0,0]
    else:
        z = infile.variables['z'][:]
    return z