function users_getvogroup () {

if [ $# -ne 1 ]; then
    echo "$0: supply a VO or a VOMS FQAN as an argument"
    return 1
fi

if [ ! `echo "$1" | grep "/"` ] ; then

    # Take the groups of all entries belonging to the VO and without a specific tag.
    # Output the most numerous result - this should be the VO group.
    # For consistency with other USERS_CONF entries, the VO group may appear
    # in these formats as well: "group,group" or "group,-"

    return=`
	awk -F: '$6=="" && $5 == tolower(virtorg){print $4}' \
	    virtorg=$1 ${USERS_CONF} | sort | uniq -c |
	    sort -n -k 1,1 | tail -1 | awk '{print $2}' | sed 's/,.*//'
    `
else

    # Take the first matching line with the given VOMS FQAN ($1) from GROUPS_CONF

    unset return
    vomsfqan=`echo "x$1" | sed 's|x||;s|^/VO=[^/]*/GROUP=||'`
    myline=`
	awk -F: '$1 ~ "^\"(/VO=[^/]*/GROUP=)?" vomsfqan "\""' \
	    IGNORECASE=1 vomsfqan="$vomsfqan" ${GROUPS_CONF} |
	head -1
    `

    mygroup=`echo $myline | cut -d ":" -f 2`
    mytag=`echo $myline | cut -d ":" -f 4`

    # If group is defined then it is easy

    if [ $mygroup ]; then
	return=$mygroup

    # If not, only a tag, then determine the VO first (Field5 or /vo in Field1),
    # then the special group corresponding to the tag

    elif [ $mytag ]; then
	myvo=`echo $myline | cut -d ":" -f 5`
	if [ ! $myvo ]; then
	    myvo=`
		echo $myline | cut -d ":" -f 1 | cut -d "/" -f 2 |
		cut -d "=" -f 2 | sed 's/"//g'
	    `
	fi
	return=`users_getspecialgroup $myvo $mytag`

    # If neither group nor tag is defined, then it is a pool account:
    # determine VO first, then the pool account group belonging to the VO

    elif [ -n "$myline" ]; then
	myvo=`
	    echo $myline | cut -d ":" -f 1 | cut -d "/" -f 2 |
	    cut -d "=" -f 2 | sed 's/"//g'
	`
	return=`users_getvogroup $myvo`
    fi
fi

if [ "$return" ]; then
    echo $return
    return 0
else
    echo "$FUNCNAME: could not find group for \"$1\"." 1>&2
    return 1
fi

}
